forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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, 602051 R=falken@chromium.org Review-Url: https://codereview.chromium.org/2907443002 Cr-Commit-Position: refs/heads/master@{#476324}
- Loading branch information
1 parent
1704aff
commit 7fdac9f
Showing
10 changed files
with
77 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...sts/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This is a testharness.js-based test. | ||
FAIL Verify SyncXHR is intercepted assert_equals: HTTP response status code for intercepted request expected 200 but got 404 | ||
Harness: the test ran to completion. | ||
|
53 changes: 53 additions & 0 deletions
53
...LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<title>Service Worker: Synchronous XHR is intercepted</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/test-helpers.sub.js"></script> | ||
<script> | ||
'use strict'; | ||
|
||
promise_test(function(t) { | ||
var url = 'resources/fetch-request-xhr-sync-worker.js'; | ||
var scope = 'resources/fetch-request-xhr-sync-iframe.html'; | ||
var non_existent_file = 'non-existent-file.txt'; | ||
|
||
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() { | ||
var xhr; | ||
try { | ||
xhr = frame.contentWindow.performSyncXHR(non_existent_file); | ||
resolve(xhr); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}, 0); | ||
}) | ||
}) | ||
.then(function(xhr) { | ||
assert_equals( | ||
xhr.status, | ||
200, | ||
'HTTP response status code for intercepted request' | ||
); | ||
assert_equals( | ||
xhr.responseText, | ||
'Response from service worker', | ||
'HTTP response text for intercepted request' | ||
); | ||
}); | ||
}, 'Verify SyncXHR is intercepted'); | ||
</script> |
13 changes: 13 additions & 0 deletions
13
.../external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-iframe.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<title>Service Worker: Synchronous XHR is intercepted iframe</title> | ||
<script> | ||
'use strict'; | ||
|
||
function performSyncXHR(url) { | ||
var syncXhr = new XMLHttpRequest(); | ||
syncXhr.open('GET', url, false); | ||
syncXhr.send(); | ||
|
||
return syncXhr; | ||
} | ||
</script> |
7 changes: 7 additions & 0 deletions
7
...ts/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
self.onfetch = function(event) { | ||
if (event.request.url.indexOf('non-existent-file.txt') !== -1) { | ||
event.respondWith(new Response('Response from service worker')); | ||
} | ||
}; |
12 changes: 0 additions & 12 deletions
12
...ebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock-iframe.html
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.data
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...d_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.js
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
...d_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock-expected.txt
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock.html
This file was deleted.
Oops, something went wrong.