• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// test data
2var testThreshold = 20;
3
4var expectedTimes = new Array();
5
6function match_entries(entries, index)
7{
8    var entry = entries[index];
9    var match = self.performance.getEntriesByName("mark")[index];
10    assert_equals(entry.name, match.name, "entry.name");
11    assert_equals(entry.startTime, match.startTime, "entry.startTime");
12    assert_equals(entry.entryType, match.entryType, "entry.entryType");
13    assert_equals(entry.duration, match.duration, "entry.duration");
14}
15
16function filter_entries_by_type(entryList, entryType)
17{
18    var testEntries = new Array();
19
20    // filter entryList
21    for (var i in entryList)
22    {
23        if (entryList[i].entryType == entryType)
24        {
25            testEntries.push(entryList[i]);
26        }
27    }
28
29    return testEntries;
30}
31
32test(function () {
33  // create first mark
34  self.performance.mark("mark");
35
36  expectedTimes[0] = self.performance.now();
37
38  const entries = self.performance.getEntriesByName("mark");
39  assert_equals(entries.length, 1);
40}, "Entry 0 is properly created");
41
42test(function () {
43    // create second, duplicate mark
44    self.performance.mark("mark");
45
46    expectedTimes[1] = self.performance.now();
47
48    const entries = self.performance.getEntriesByName("mark");
49    assert_equals(entries.length, 2);
50
51}, "Entry 1 is properly created");
52
53function test_mark(index) {
54   test(function () {
55       const entries = self.performance.getEntriesByName("mark");
56       assert_equals(entries[index].name, "mark", "Entry has the proper name");
57   }, "Entry " + index + " has the proper name");
58
59   test(function () {
60       const entries = self.performance.getEntriesByName("mark");
61       assert_approx_equals(entries[index].startTime, expectedTimes[index], testThreshold);
62   }, "Entry " + index + " startTime is approximately correct (up to " + testThreshold +
63              "ms difference allowed)");
64
65   test(function () {
66       const entries = self.performance.getEntriesByName("mark");
67       assert_equals(entries[index].entryType, "mark");
68   }, "Entry " + index + " has the proper entryType");
69
70   test(function () {
71       const entries = self.performance.getEntriesByName("mark");
72       assert_equals(entries[index].duration, 0);
73   }, "Entry " + index +  " duration == 0");
74
75   test(function () {
76    const entries = self.performance.getEntriesByName("mark", "mark");
77    assert_equals(entries[index].name, "mark");
78   }, "getEntriesByName(\"mark\", \"mark\")[" + index + "] returns an " +
79                "object containing a \"mark\" mark");
80
81   test(function () {
82    const entries = self.performance.getEntriesByName("mark", "mark");
83    match_entries(entries, index);
84   }, "The mark returned by getEntriesByName(\"mark\", \"mark\")[" + index
85      + "] matches the mark returned by " +
86              "getEntriesByName(\"mark\")[" + index + "]");
87
88   test(function () {
89    const entries = filter_entries_by_type(self.performance.getEntries(), "mark");
90    assert_equals(entries[index].name, "mark");
91   }, "getEntries()[" + index + "] returns an " +
92                "object containing a \"mark\" mark");
93
94   test(function () {
95    const entries = filter_entries_by_type(self.performance.getEntries(), "mark");
96    match_entries(entries, index);
97   }, "The mark returned by getEntries()[" + index
98      + "] matches the mark returned by " +
99              "getEntriesByName(\"mark\")[" + index + "]");
100
101   test(function () {
102    const entries = self.performance.getEntriesByType("mark");
103    assert_equals(entries[index].name, "mark");
104   }, "getEntriesByType(\"mark\")[" + index + "] returns an " +
105                "object containing a \"mark\" mark");
106
107   test(function () {
108    const entries = self.performance.getEntriesByType("mark");
109    match_entries(entries, index);
110   }, "The mark returned by getEntriesByType(\"mark\")[" + index
111      + "] matches the mark returned by " +
112              "getEntriesByName(\"mark\")[" + index + "]");
113
114}
115
116for (var i = 0; i < expectedTimes.length; i++) {
117  test_mark(i);
118}
119