summaryrefslogtreecommitdiffstats
path: root/devtools/client/animationinspector/test/unit/test_formatStopwatchTime.js
blob: 12584a2a48149ec39dec3dfb99f54798db75ad80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

var Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {formatStopwatchTime} = require("devtools/client/animationinspector/utils");

const TEST_DATA = [{
  desc: "Formatting 0",
  time: 0,
  expected: "00:00.000"
}, {
  desc: "Formatting null",
  time: null,
  expected: "00:00.000"
}, {
  desc: "Formatting undefined",
  time: undefined,
  expected: "00:00.000"
}, {
  desc: "Formatting a small number of ms",
  time: 13,
  expected: "00:00.013"
}, {
  desc: "Formatting a slightly larger number of ms",
  time: 500,
  expected: "00:00.500"
}, {
  desc: "Formatting 1 second",
  time: 1000,
  expected: "00:01.000"
}, {
  desc: "Formatting a number of seconds",
  time: 1532,
  expected: "00:01.532"
}, {
  desc: "Formatting a big number of seconds",
  time: 58450,
  expected: "00:58.450"
}, {
  desc: "Formatting 1 minute",
  time: 60000,
  expected: "01:00.000"
}, {
  desc: "Formatting a number of minutes",
  time: 263567,
  expected: "04:23.567"
}, {
  desc: "Formatting a large number of minutes",
  time: 1000 * 60 * 60 * 3,
  expected: "180:00.000"
}];

function run_test() {
  for (let {desc, time, expected} of TEST_DATA) {
    equal(formatStopwatchTime(time), expected, desc);
  }
}