Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created May 24, 2017 21:41
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/f74f42c59bb7601018b919e0f227c98a to your computer and use it in GitHub Desktop.
Save jugglinmike/f74f42c59bb7601018b919e0f227c98a to your computer and use it in GitHub Desktop.
sw-migration-xhr-sync.diff (as generated via `git show -M10 -w`)
$ git show -M10 -w
commit aeacdac997289880303f91b28afb8fb8c4254690
Author: Mike Pennisi <mike@mikepennisi.com>
Date: Wed May 24 16:11:22 2017 -0400
Upstream service worker 'XHR' test to WPT
The original version of this test would only pass if the service worker
did *not* intercept the XHR request. That behavior conflicted with the
Fetch and Service Worker specification and with the test's documentation
itself. Update the test to pass only if the service worker intercepts
the request.
In addition:
- Update URLs to suitable values for the Web Platform Tests project
- Add "use strict" directives to script bodies
- Increase precision of "cleanup" logic scheduling
- Re-name files to adhere to precent set by existing WPT tests
- Catch and report errors within Promise chain rather than relying on
implicit reporting of uncaught errors.
BUG=688116
R=falken@chromium.org
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock-expected.txt b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https-expected.txt
similarity index 23%
rename from third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock-expected.txt
rename to third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https-expected.txt
index 322df76..d730f3c 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock-expected.txt
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https-expected.txt
@@ -1,5 +1,4 @@
-CONSOLE WARNING: line 7: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
This is a testharness.js-based test.
-PASS Verify SyncXHR does not deadlock
+FAIL Verify SyncXHR does not deadlock promise_test: Unhandled rejection with value: "FAIL"
Harness: the test ran to completion.
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https.html
similarity index 22%
rename from third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock.html
rename to third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https.html
index 6fe82d7..f3b693c 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https.html
@@ -1,25 +1,39 @@
<!DOCTYPE html>
-<title>Service Worker: SyncXHR doesn't deadlock</title>
-<script src="../resources/testharness.js"></script>
-<script src="../resources/testharnessreport.js"></script>
-<script src="resources/test-helpers.js"></script>
+<title>Service Worker: Synchronous XHR doesn't deadlock</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
<script>
+'use strict';
-async_test(function(t) {
- var url = 'resources/sync-xhr-doesnt-deadlock.js';
- var scope = 'resources/sync-xhr-doesnt-deadlock-iframe.html';
+promise_test(function(t) {
+ var url = 'resources/fetch-request-xhr-sync-worker.js';
+ var scope = 'resources/fetch-request-xhr-sync-iframe.html';
- service_worker_unregister_and_register(t, url, scope)
+ return service_worker_unregister_and_register(t, url, scope)
.then(function(registration) {
+ t.add_cleanup(function() {
+ registration.unregister();
+ });
+
return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_iframe(scope); })
.then(function(frame) {
+ t.add_cleanup(function() {
+ frame.remove();
+ });
+
+ return new Promise(function(resolve, reject) {
setTimeout(function() {
+ try {
frame.contentWindow.performSyncXHR();
- service_worker_unregister_and_done(t, scope);
+ resolve();
+ } catch (err) {
+ reject(err);
+ }
}, 0);
- })
- .catch(unreached_rejection(t));
+ });
+ });
}, 'Verify SyncXHR does not deadlock');
</script>
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock-iframe.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-iframe.html
similarity index 36%
rename from third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock-iframe.html
rename to third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-iframe.html
index 0fa7291..657596e 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock-iframe.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-iframe.html
@@ -1,12 +1,16 @@
<!DOCTYPE html>
-<title>Service Worker: SyncXHR doesn't deadlock iframe</title>
+<title>Service Worker: Synchronous XHR doesn't deadlock iframe</title>
<script>
+'use strict';
+
function performSyncXHR() {
- var url = 'sync-xhr-doesnt-deadlock.data?bustcache=' + Date.now();
+ var url = 'fetch-request-xhr-sync-data.txt?bustcache=' + Date.now();
var syncXhr = new XMLHttpRequest();
- syncXhr.open("GET", url, false);
+ syncXhr.open('GET', url, false);
syncXhr.send();
- if (syncXhr.responseText != 'hello')
+
+ if (syncXhr.responseText != 'hello') {
throw 'FAIL';
}
+}
</script>
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.js b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-worker.js
similarity index 19%
rename from third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.js
rename to third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-worker.js
index 3e9093d..77042cd 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.js
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-worker.js
@@ -1,5 +1,7 @@
+'use strict';
+
self.onfetch = function(event) {
- if (event.request.url.indexOf('sync-xhr-doesnt-deadlock.data') == -1)
- return;
- event.respondWith(fetch('404resource?bustcache=' + Date.now()));
+ if (event.request.url.indexOf('fetch-request-xhr-sync-data.txt') !== -1) {
+ event.respondWith(new Response('hello'));
+ }
};
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.data b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.data
deleted file mode 100644
index b6fc4c6..0000000
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.data
+++ /dev/null
@@ -1 +0,0 @@
-hello
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment