Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created May 11, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugglinmike/34768d1d2c44fad49c766b740d209547 to your computer and use it in GitHub Desktop.
Save jugglinmike/34768d1d2c44fad49c766b740d209547 to your computer and use it in GitHub Desktop.
sw-migration-perf-timeline.diff
diff --git a/third_party/WebKit/LayoutTests/http/tests/workers/resources/performance-timeline-worker.js b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/performance-timeline-worker.js
index 1075d5b..6f7df75 100644
--- a/third_party/WebKit/LayoutTests/http/tests/workers/resources/performance-timeline-worker.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/performance-timeline-worker.js
@@ -1,24 +1,25 @@
-importScripts('../../resources/testharness.js');
+importScripts('/resources/testharness.js');
promise_test(function(test) {
var durationMsec = 100;
-
+ // There are limits to our accuracy here. Timers may fire up to a
+ // millisecond early due to platform-dependent rounding. In addition
+ // the performance API introduces some rounding as well to prevent
+ // timing attacks.
+ var accuracy = 1.5;
return new Promise(function(resolve) {
performance.mark('startMark');
setTimeout(resolve, durationMsec);
}).then(function() {
performance.mark('endMark');
performance.measure('measure', 'startMark', 'endMark');
-
var startMark = performance.getEntriesByName('startMark')[0];
var endMark = performance.getEntriesByName('endMark')[0];
var measure = performance.getEntriesByType('measure')[0];
-
assert_equals(measure.startTime, startMark.startTime);
assert_approx_equals(endMark.startTime - startMark.startTime,
measure.duration, 0.001);
- assert_greater_than(measure.duration, durationMsec);
-
+ assert_greater_than(measure.duration, durationMsec - accuracy);
assert_equals(performance.getEntriesByType('mark').length, 2);
assert_equals(performance.getEntriesByType('measure').length, 1);
performance.clearMarks('startMark');
@@ -29,21 +30,12 @@ promise_test(function(test) {
}, 'User Timing');
promise_test(function(test) {
- return fetch('../../resources/dummy.txt')
+ return fetch('dummy.txt')
.then(function(resp) {
return resp.text();
})
- .then(function(t) {
- // TODO(hiroshige): The resource timing entry for dummy.txt is added
- // about at the same time as, but not necessarily before,
- // |resp.text()| is resolved. https://crbug.com/507169
- // We add setTimeout() here as temporary fix.
- return new Promise(function(resolve, reject) {
- setTimeout(function() { resolve(t); }, 100);
- });
- })
- .then(function(t) {
- var expectedResources = ['/resources/testharness.js', '/resources/dummy.txt'];
+ .then(function(text) {
+ var expectedResources = ['testharness.js', 'dummy.txt'];
assert_equals(performance.getEntriesByType('resource').length, expectedResources.length);
for (var i = 0; i < expectedResources.length; i++) {
var entry = performance.getEntriesByType('resource')[i];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment