1<!DOCTYPE html> 2<!-- 3Copyright 2015 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/base/units/time.html"> 9<link rel="import" href="/base/units/time_stamp.html"> 10 11<script> 12'use strict'; 13 14tr.b.unittest.testSuite(function() { 15 var Time = tr.b.units.Time; 16 var TimeStamp = tr.b.units.TimeStamp; 17 18 function checkFormat(timestamp, expectedString) { 19 assert.equal(TimeStamp.format(timestamp), expectedString); 20 assert.equal(new TimeStamp(timestamp).toString(), expectedString); 21 } 22 23 test('format', function() { 24 try { 25 // Use milliseconds to display time (default behavior). 26 Time.currentDisplayUnit = Time.supportedUnits.ms; 27 28 checkFormat(0, '0.000 ms'); 29 checkFormat(0.02, '0.020 ms'); 30 checkFormat(0.001, '0.001 ms'); 31 checkFormat(0.0005, '0.001 ms'); 32 checkFormat(0.00049, '0.000 ms'); 33 checkFormat(999.999, '999.999 ms'); 34 checkFormat(1000.001, '1,000.001 ms'); 35 checkFormat(123456789, '123,456,789.000 ms'); 36 checkFormat(-0.00051, '-0.001 ms'); 37 checkFormat(-123456789, '-123,456,789.000 ms'); 38 39 // Change the unit to nanoseconds. 40 Time.currentDisplayUnit = Time.supportedUnits.ns; 41 42 checkFormat(0, '0 ns'); 43 checkFormat(1, '1,000,000 ns'); 44 checkFormat(0.000042, '42 ns'); 45 checkFormat(0.000001, '1 ns'); 46 checkFormat(0.0000005, '1 ns'); 47 checkFormat(0.00000049, '0 ns'); 48 checkFormat(123.456, '123,456,000 ns'); 49 checkFormat(-0.07, '-70,000 ns'); 50 } finally { 51 Time.reset(); 52 } 53 }); 54}); 55</script> 56