| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <link rel="import" href="/base/units/size_in_bytes_span.html"> |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| |
| test('instantiate', function() { |
| var timeSpan = document.createElement('tr-b-u-size-in-bytes-span'); |
| timeSpan.numBytes = 5 * 1024; |
| assert.equal(timeSpan.numBytes, 5 * 1024); |
| this.addHTMLOutput(timeSpan); |
| }); |
| |
| test('instantiateWithObject', function() { |
| var timeSpan = document.createElement('tr-b-u-size-in-bytes-span'); |
| timeSpan.numBytes = new tr.b.units.SizeInBytes(5 * 1024); |
| assert.equal(timeSpan.numBytes, 5 * 1024); |
| this.addHTMLOutput(timeSpan); |
| }); |
| |
| test('sizeStrings', function() { |
| var el = document.createElement('tr-b-u-size-in-bytes-span'); |
| |
| el.numBytes = 0; |
| assert.equal(el.stringContent, '0.0 B'); |
| |
| el.numBytes = 1; |
| assert.equal(el.stringContent, '1.0 B'); |
| |
| el.numBytes = 1536; |
| assert.equal(el.stringContent, '1.5 KiB'); |
| |
| el.numBytes = 424.2 * 1024 * 1024; |
| assert.equal(el.stringContent, '424.2 MiB'); |
| |
| el.numBytes = 5 * 1024 * 1024 * 1024; |
| assert.equal(el.stringContent, '5.0 GiB'); |
| |
| el.numBytes = 1025 * 1024 * 1024 * 1024 * 1024; |
| assert.equal(el.stringContent, '1025.0 TiB'); |
| this.addHTMLOutput(el); |
| |
| el.numBytes = -2.5 * 1024 * 1024; |
| assert.equal(el.stringContent, '-2.5 MiB'); |
| }); |
| |
| }); |
| </script> |