2 // Test single mark addition
4 ok(true, "Running mark addition test");
5 performance.mark("test");
6 var marks = performance.getEntriesByType("mark");
7 is(marks.length, 1, "Number of marks should be 1");
9 is(mark.name, "test", "mark name should be 'test'");
10 is(mark.entryType, "mark", "mark type should be 'mark'");
11 isnot(mark.startTime, 0, "mark start time should not be 0");
12 is(mark.duration, 0, "mark duration should be 0");
14 // Test multiple mark addition
16 ok(true, "Running multiple mark with same name addition test");
17 performance.mark("test");
18 performance.mark("test");
19 performance.mark("test");
20 var marks_type = performance.getEntriesByType("mark");
21 is(marks_type.length, 3, "Number of marks by type should be 3");
22 var marks_name = performance.getEntriesByName("test");
23 is(marks_name.length, 3, "Number of marks by name should be 3");
24 var mark = marks_name[0];
25 is(mark.name, "test", "mark name should be 'test'");
26 is(mark.entryType, "mark", "mark type should be 'mark'");
27 isnot(mark.startTime, 0, "mark start time should not be 0");
28 is(mark.duration, 0, "mark duration should be 0");
30 // This also tests the chronological ordering specified as
31 // required for getEntries in the performance timeline spec.
32 marks_name.forEach(function (s) {
33 times.forEach(function (time) {
35 s.startTime >= time.startTime,
36 "Times should be equal or increasing between similarly named marks: " +
45 // Test all marks removal
47 ok(true, "Running all mark removal test");
48 performance.mark("test");
49 performance.mark("test2");
50 var marks = performance.getEntriesByType("mark");
51 is(marks.length, 2, "number of marks before all removal");
52 performance.clearMarks();
53 marks = performance.getEntriesByType("mark");
54 is(marks.length, 0, "number of marks after all removal");
56 // Test single mark removal
58 ok(true, "Running removal test (0 'test' marks with other marks)");
59 performance.mark("test2");
60 var marks = performance.getEntriesByType("mark");
61 is(marks.length, 1, "number of marks before all removal");
62 performance.clearMarks("test");
63 marks = performance.getEntriesByType("mark");
64 is(marks.length, 1, "number of marks after all removal");
66 // Test single mark removal
68 ok(true, "Running removal test (0 'test' marks with no other marks)");
69 var marks = performance.getEntriesByType("mark");
70 is(marks.length, 0, "number of marks before all removal");
71 performance.clearMarks("test");
72 marks = performance.getEntriesByType("mark");
73 is(marks.length, 0, "number of marks after all removal");
76 ok(true, "Running removal test (1 'test' mark with other marks)");
77 performance.mark("test");
78 performance.mark("test2");
79 var marks = performance.getEntriesByType("mark");
80 is(marks.length, 2, "number of marks before all removal");
81 performance.clearMarks("test");
82 marks = performance.getEntriesByType("mark");
83 is(marks.length, 1, "number of marks after all removal");
86 ok(true, "Running removal test (1 'test' mark with no other marks)");
87 performance.mark("test");
88 var marks = performance.getEntriesByType("mark");
89 is(marks.length, 1, "number of marks before all removal");
90 performance.clearMarks("test");
91 marks = performance.getEntriesByType("mark");
92 is(marks.length, 0, "number of marks after all removal");
95 ok(true, "Running removal test (2 'test' marks with other marks)");
96 performance.mark("test");
97 performance.mark("test");
98 performance.mark("test2");
99 var marks = performance.getEntriesByType("mark");
100 is(marks.length, 3, "number of marks before all removal");
101 performance.clearMarks("test");
102 marks = performance.getEntriesByType("mark");
103 is(marks.length, 1, "number of marks after all removal");
106 ok(true, "Running removal test (2 'test' marks with no other marks)");
107 performance.mark("test");
108 performance.mark("test");
109 var marks = performance.getEntriesByType("mark");
110 is(marks.length, 2, "number of marks before all removal");
111 performance.clearMarks("test");
112 marks = performance.getEntriesByType("mark");
113 is(marks.length, 0, "number of marks after all removal");
115 // Test mark name being same as navigation timing parameter
117 ok(true, "Running mark name collision test");
118 for (n in performance.timing) {
121 ok(true, "Skipping toJSON entry in collision test");
127 "Mark name collision test failed for name " +
129 ", shouldn't make it here!"
133 e instanceof DOMException,
134 "DOM exception thrown for mark named " + n
139 "DOM exception for name collision is syntax error"
146 ok(true, "Running measure addition with no start/end time test");
147 performance.measure("test");
148 var measures = performance.getEntriesByType("measure");
149 is(measures.length, 1, "number of measures should be 1");
150 var measure = measures[0];
151 is(measure.name, "test", "measure name should be 'test'");
152 is(measure.entryType, "measure", "measure type should be 'measure'");
153 is(measure.startTime, 0, "measure start time should be zero");
154 ok(measure.duration >= 0, "measure duration should not be negative");
157 ok(true, "Running measure addition with only start time test");
158 performance.mark("test1");
159 performance.measure("test", "test1", undefined);
160 var measures = performance.getEntriesByName("test", "measure");
161 var marks = performance.getEntriesByName("test1", "mark");
162 var measure = measures[0];
167 "measure start time should be equal to the mark startTime"
169 ok(measure.duration >= 0, "measure duration should not be negative");
172 ok(true, "Running measure addition with only end time test");
173 performance.mark("test1");
174 performance.measure("test", undefined, "test1");
175 var measures = performance.getEntriesByName("test", "measure");
176 var marks = performance.getEntriesByName("test1", "mark");
177 var measure = measures[0];
179 ok(measure.duration >= 0, "measure duration should not be negative");
181 // Test measure picking latest version of similarly named tags
183 ok(true, "Running multiple mark with same name addition test");
184 performance.mark("test");
185 performance.mark("test");
186 performance.mark("test");
187 performance.mark("test2");
188 var marks_name = performance.getEntriesByName("test");
189 is(marks_name.length, 3, "Number of marks by name should be 3");
190 var marks_name2 = performance.getEntriesByName("test2");
191 is(marks_name2.length, 1, "Number of marks by name should be 1");
192 var test_mark = marks_name2[0];
193 performance.measure("test", "test", "test2");
194 var measures_type = performance.getEntriesByType("measure");
195 var last_mark = marks_name[marks_name.length - 1];
196 is(measures_type.length, 1, "Number of measures by type should be 1");
197 var measure = measures_type[0];
201 "Measure start time should be the start time of the latest 'test' mark"
203 // Tolerance testing to avoid oranges, since we're doing double math across two different languages.
205 measure.duration - (test_mark.startTime - last_mark.startTime) < 0.00001,
206 "Measure duration ( " +
208 ") should be difference between two marks"
212 // We don't have navigationStart in workers.
213 if ("window" in self) {
214 ok(true, "Running measure addition with no start/end time test");
215 performance.measure("test", "navigationStart");
216 var measures = performance.getEntriesByType("measure");
217 is(measures.length, 1, "number of measures should be 1");
218 var measure = measures[0];
219 is(measure.name, "test", "measure name should be 'test'");
220 is(measure.entryType, "measure", "measure type should be 'measure'");
221 is(measure.startTime, 0, "measure start time should be zero");
222 ok(measure.duration >= 0, "measure duration should not be negative");
225 // Test all measure removal
227 ok(true, "Running all measure removal test");
228 performance.measure("test");
229 performance.measure("test2");
230 var measures = performance.getEntriesByType("measure");
231 is(measures.length, 2, "measure entries should be length 2");
232 performance.clearMeasures();
233 measures = performance.getEntriesByType("measure");
234 is(measures.length, 0, "measure entries should be length 0");
236 // Test single measure removal
238 ok(true, "Running all measure removal test");
239 performance.measure("test");
240 performance.measure("test2");
241 var measures = performance.getEntriesByType("measure");
242 is(measures.length, 2, "measure entries should be length 2");
243 performance.clearMeasures("test");
244 measures = performance.getEntriesByType("measure");
245 is(measures.length, 1, "measure entries should be length 1");
247 // Test measure with invalid start time mark name
249 ok(true, "Running measure invalid start test");
251 performance.measure("test", "notamark");
252 ok(false, "invalid measure start time exception not thrown!");
254 ok(e instanceof DOMException, "DOM exception thrown for invalid measure");
258 "DOM exception for invalid time is syntax error"
262 // Test measure with invalid end time mark name
264 ok(true, "Running measure invalid end test");
266 performance.measure("test", undefined, "notamark");
267 ok(false, "invalid measure end time exception not thrown!");
269 ok(e instanceof DOMException, "DOM exception thrown for invalid measure");
273 "DOM exception for invalid time is syntax error"
277 // Test measure name being same as navigation timing parameter
279 ok(true, "Running measure name collision test");
280 for (n in performance.timing) {
282 ok(true, "Skipping toJSON entry in collision test");
285 performance.measure(n);
286 ok(true, "Measure name supports name collisions: " + n);
289 // Test measure mark being a reserved name
291 ok(true, "Create measures using all reserved names");
292 for (n in performance.timing) {
295 ok(true, "Skipping toJSON entry in collision test");
298 performance.measure("test", n);
299 ok(true, "Measure created from reserved name as starting time: " + n);
308 "secureConnectionStart",
310 "Measure created from reserved name as starting time: " +
312 " and threw expected error"
317 // TODO: Test measure picking latest version of similarly named tags