OLD | NEW |
1 importScripts('../../resources/testharness.js'); | 1 importScripts('/resources/testharness.js'); |
2 | 2 |
3 promise_test(function(test) { | 3 promise_test(function(test) { |
4 var durationMsec = 100; | 4 var durationMsec = 100; |
5 | 5 // There are limits to our accuracy here. Timers may fire up to a |
| 6 // millisecond early due to platform-dependent rounding. In addition |
| 7 // the performance API introduces some rounding as well to prevent |
| 8 // timing attacks. |
| 9 var accuracy = 1.5; |
6 return new Promise(function(resolve) { | 10 return new Promise(function(resolve) { |
7 performance.mark('startMark'); | 11 performance.mark('startMark'); |
8 setTimeout(resolve, durationMsec); | 12 setTimeout(resolve, durationMsec); |
9 }).then(function() { | 13 }).then(function() { |
10 performance.mark('endMark'); | 14 performance.mark('endMark'); |
11 performance.measure('measure', 'startMark', 'endMark'); | 15 performance.measure('measure', 'startMark', 'endMark'); |
12 | |
13 var startMark = performance.getEntriesByName('startMark')[0]; | 16 var startMark = performance.getEntriesByName('startMark')[0]; |
14 var endMark = performance.getEntriesByName('endMark')[0]; | 17 var endMark = performance.getEntriesByName('endMark')[0]; |
15 var measure = performance.getEntriesByType('measure')[0]; | 18 var measure = performance.getEntriesByType('measure')[0]; |
16 | |
17 assert_equals(measure.startTime, startMark.startTime); | 19 assert_equals(measure.startTime, startMark.startTime); |
18 assert_approx_equals(endMark.startTime - startMark.startTime, | 20 assert_approx_equals(endMark.startTime - startMark.startTime, |
19 measure.duration, 0.001); | 21 measure.duration, 0.001); |
20 assert_greater_than(measure.duration, durationMsec); | 22 assert_greater_than(measure.duration, durationMsec - accuracy); |
21 | |
22 assert_equals(performance.getEntriesByType('mark').length, 2); | 23 assert_equals(performance.getEntriesByType('mark').length, 2); |
23 assert_equals(performance.getEntriesByType('measure').length, 1); | 24 assert_equals(performance.getEntriesByType('measure').length, 1); |
24 performance.clearMarks('startMark'); | 25 performance.clearMarks('startMark'); |
25 performance.clearMeasures('measure'); | 26 performance.clearMeasures('measure'); |
26 assert_equals(performance.getEntriesByType('mark').length, 1); | 27 assert_equals(performance.getEntriesByType('mark').length, 1); |
27 assert_equals(performance.getEntriesByType('measure').length, 0); | 28 assert_equals(performance.getEntriesByType('measure').length, 0); |
28 }); | 29 }); |
29 }, 'User Timing'); | 30 }, 'User Timing'); |
30 | 31 |
31 promise_test(function(test) { | 32 promise_test(function(test) { |
32 return fetch('../../resources/dummy.txt') | 33 return fetch('dummy.txt') |
33 .then(function(resp) { | 34 .then(function(resp) { |
34 return resp.text(); | 35 return resp.text(); |
35 }) | 36 }) |
36 .then(function(t) { | 37 .then(function(text) { |
37 // TODO(hiroshige): The resource timing entry for dummy.txt is added | 38 var expectedResources = ['testharness.js', 'dummy.txt']; |
38 // about at the same time as, but not necessarily before, | |
39 // |resp.text()| is resolved. https://crbug.com/507169 | |
40 // We add setTimeout() here as temporary fix. | |
41 return new Promise(function(resolve, reject) { | |
42 setTimeout(function() { resolve(t); }, 100); | |
43 }); | |
44 }) | |
45 .then(function(t) { | |
46 var expectedResources = ['/resources/testharness.js', '/resources/dumm
y.txt']; | |
47 assert_equals(performance.getEntriesByType('resource').length, expecte
dResources.length); | 39 assert_equals(performance.getEntriesByType('resource').length, expecte
dResources.length); |
48 for (var i = 0; i < expectedResources.length; i++) { | 40 for (var i = 0; i < expectedResources.length; i++) { |
49 var entry = performance.getEntriesByType('resource')[i]; | 41 var entry = performance.getEntriesByType('resource')[i]; |
50 assert_true(entry.name.endsWith(expectedResources[i])); | 42 assert_true(entry.name.endsWith(expectedResources[i])); |
51 assert_equals(entry.workerStart, 0); | 43 assert_equals(entry.workerStart, 0); |
52 assert_greater_than(entry.startTime, 0); | 44 assert_greater_than(entry.startTime, 0); |
53 assert_greater_than(entry.responseEnd, entry.startTime); | 45 assert_greater_than(entry.responseEnd, entry.startTime); |
54 } | 46 } |
55 return new Promise(function(resolve) { | 47 return new Promise(function(resolve) { |
56 performance.onresourcetimingbufferfull = resolve; | 48 performance.onresourcetimingbufferfull = resolve; |
57 performance.setResourceTimingBufferSize(expectedResources.length); | 49 performance.setResourceTimingBufferSize(expectedResources.length); |
58 }); | 50 }); |
59 }) | 51 }) |
60 .then(function() { | 52 .then(function() { |
61 performance.clearResourceTimings(); | 53 performance.clearResourceTimings(); |
62 assert_equals(performance.getEntriesByType('resource').length, 0); | 54 assert_equals(performance.getEntriesByType('resource').length, 0); |
63 }) | 55 }) |
64 }, 'Resource Timing'); | 56 }, 'Resource Timing'); |
65 | 57 |
66 done(); | 58 done(); |
OLD | NEW |