| <!DOCTYPE html> |
| <!-- |
| Copyright 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="/tracing/base/units/units.html"> |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| var Units = tr.b.u.Units; |
| |
| test('Units.display-mode-changed', function() { |
| var Units = tr.b.u.Units; |
| var TimeDisplayModes = tr.b.u.TimeDisplayModes; |
| |
| var listenerWasCalled = false; |
| function listener(e) { |
| listenerWasCalled = true; |
| } |
| |
| try { |
| Units.currentTimeDisplayMode = TimeDisplayModes.ms; |
| Units.addEventListener('display-mode-changed', listener); |
| |
| listenerWasCalled = false; |
| Units.currentTimeDisplayMode = TimeDisplayModes.ns; |
| assert.isTrue(listenerWasCalled); |
| assert.equal(Units.currentTimeDisplayMode, TimeDisplayModes.ns); |
| } finally { |
| Units.removeEventListener('display-mode-changed', listener); |
| Units.reset(); |
| } |
| }); |
| |
| test('sizeInBytes', function() { |
| function checkFormat(value, expectation) { |
| assert.equal(Units.sizeInBytes.format(value), expectation); |
| } |
| checkFormat(0, '0.0 B'); |
| checkFormat(1, '1.0 B'); |
| checkFormat(1536, '1.5 KiB'); |
| checkFormat(424.2 * 1024 * 1024, '424.2 MiB'); |
| checkFormat(5 * 1024 * 1024 * 1024, '5.0 GiB'); |
| checkFormat(1025 * 1024 * 1024 * 1024 * 1024, '1025.0 TiB'); |
| checkFormat(-2.5 * 1024 * 1024, '-2.5 MiB'); |
| }); |
| |
| test('energyInJoules', function() { |
| assert.equal(Units.energyInJoules.format(1000), '1,000.000 J'); |
| assert.equal(Units.energyInJoules.format(1), '1.000 J'); |
| assert.equal(Units.energyInJoules.format(.005), '0.005 J'); |
| assert.equal(Units.energyInJoules.format(.0005), '0.001 J'); |
| assert.equal(Units.energyInJoules.format(.0004), '0.000 J'); |
| }); |
| |
| test('powerInWatts', function() { |
| assert.equal(Units.powerInWatts.format(1000), '1,000,000.000 mW'); |
| assert.equal(Units.powerInWatts.format(1), '1,000.000 mW'); |
| assert.equal(Units.powerInWatts.format(.001), '1.000 mW'); |
| assert.equal(Units.powerInWatts.format(.001005), '1.005 mW'); |
| assert.equal(Units.powerInWatts.format(.0010005), '1.001 mW'); |
| assert.equal(Units.powerInWatts.format(.0010004), '1.000 mW'); |
| }); |
| }); |
| </script> |