Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-fallback.https.html

Issue 2858933003: Upstream service worker `fetch` test to WPT (Closed)
Patch Set: Resolve conflict in `enable-blink-features=LayoutNG` Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-fallback.https.html
diff --git a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-fallback.https.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-fallback.https.html
index 57934d535ada97b263bcc1a19b2a9e1f3101f38a..400d83a9d3701138497dc5ad785684a518e8f4e7 100644
--- a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-fallback.https.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-fallback.https.html
@@ -3,111 +3,280 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
-<script src="resources/test-helpers.sub.js?pipe=sub"></script>
+<script src="resources/test-helpers.sub.js"></script>
<script>
-var expected_urls = [];
-
-function xhr_fail_test(frame, url) {
- expected_urls.push(url);
- return new Promise(function(resolve, reject) {
- frame.contentWindow.xhr(url)
- .then(function(){
- reject(url + ' should fail.');
- })
- .catch(function(){
- resolve();
- });
+function get_fetched_urls(worker) {
+ return new Promise(function(resolve) {
+ var channel = new MessageChannel();
+ channel.port1.onmessage = function(msg) { resolve(msg); };
+ worker.postMessage({port: channel.port2}, [channel.port2]);
});
}
-function xhr_succeed_test(frame, url) {
- expected_urls.push(url);
- return new Promise(function(resolve, reject) {
- frame.contentWindow.xhr(url)
- .then(function(){
- resolve();
- })
- .catch(function(){
- reject(url + ' should succeed.');
- });
+function check_urls(worker, expected_requests) {
+ return get_fetched_urls(worker)
+ .then(function(msg) {
+ var requests = msg.data.requests;
+ assert_object_equals(requests, expected_requests);
});
}
-async_test(function(t) {
- var path = new URL(".", window.location).pathname;
- var SCOPE = 'resources/fetch-request-fallback-iframe.html';
- var SCRIPT = 'resources/fetch-request-fallback-worker.js';
- var host_info = get_host_info();
- var BASE_URL = host_info['HTTPS_ORIGIN'] +
- path + 'resources/fetch-access-control.py?';
- var OTHER_BASE_URL = host_info['HTTPS_REMOTE_ORIGIN'] +
- path + 'resources/fetch-access-control.py?';
- var REDIRECT_URL = host_info['HTTPS_ORIGIN'] +
- path + 'resources/redirect.py?Redirect=';
- var frame;
- var worker;
- service_worker_unregister_and_register(t, SCRIPT, SCOPE)
- .then(function(registration) {
- worker = registration.installing;
- return wait_for_state(t, worker, 'activated');
- })
- .then(function() { return with_iframe(SCOPE); })
- .then(function(f) {
- frame = f;
- return xhr_succeed_test(frame, BASE_URL);
- })
- .then(function(f) {
- return xhr_fail_test(frame, OTHER_BASE_URL);
- })
- .then(function(f) {
- return xhr_succeed_test(frame, OTHER_BASE_URL + 'ACAOrigin=*');
- })
- .then(function(f) {
- return xhr_succeed_test(frame,
- REDIRECT_URL + encodeURIComponent(BASE_URL));
+var path = new URL(".", window.location).pathname;
+var SCOPE = 'resources/fetch-request-fallback-iframe.html';
+var SCRIPT = 'resources/fetch-request-fallback-worker.js';
+var host_info = get_host_info();
+var BASE_URL = host_info['HTTPS_ORIGIN'] +
+ path + 'resources/fetch-access-control.py?';
+var BASE_PNG_URL = BASE_URL + 'PNGIMAGE&';
+var OTHER_BASE_URL = host_info['HTTPS_REMOTE_ORIGIN'] +
+ path + 'resources/fetch-access-control.py?';
+var OTHER_BASE_PNG_URL = OTHER_BASE_URL + 'PNGIMAGE&';
+var REDIRECT_URL = host_info['HTTPS_ORIGIN'] +
+ path + 'resources/redirect.py?Redirect=';
+var register;
+
+promise_test(function(t) {
+ var registration;
+ var worker;
+
+ register = service_worker_unregister_and_register(t, SCRIPT, SCOPE)
+ .then(function(r) {
+ registration = r;
+ worker = registration.installing;
+ return wait_for_state(t, worker, 'activated');
+ })
+ .then(function() { return with_iframe(SCOPE); })
+ .then(function(frame) {
+ // This test should not be considered complete until after the service
+ // worker has been unregistered. Currently, `testharness.js` does not
+ // support asynchronous global "tear down" logic, so this must be
+ // expressed using a dedicated `promise_test`. Because the other
+ // sub-tests in this file are declared synchronously, this test will be
+ // the final test executed.
+ promise_test(function(t) {
+ t.add_cleanup(function() {
+ frame.remove();
+ });
+ return registration.unregister();
+ }, 'restore global state');
+
+ return {frame: frame, worker: worker};
+ });
+
+ return register;
+ }, 'initialize global state');
+
+function promise_frame_test(body, desc) {
+ promise_test(function(test) {
+ return register.then(function(result) {
+ return body(test, result.frame, result.worker);
+ });
+ }, desc);
+}
+
+promise_frame_test(function(t, frame, worker) {
+ return check_urls(
+ worker,
+ [{
+ url: host_info['HTTPS_ORIGIN'] + path + SCOPE,
+ mode: 'navigate'
+ }]);
+ }, 'The SW must intercept the request for a main resource.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.xhr(BASE_URL)
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: BASE_URL, mode: 'cors' }]);
+ });
+ }, 'The SW must intercept the request of same origin XHR.');
+
+promise_frame_test(function(t, frame, worker) {
+ return promise_rejects(
+ t,
+ null,
+ frame.contentWindow.xhr(OTHER_BASE_URL),
+ 'SW fallbacked CORS-unsupported other origin XHR should fail.')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_URL, mode: 'cors' }]);
+ });
+ }, 'The SW must intercept the request of CORS-unsupported other origin XHR.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.xhr(OTHER_BASE_URL + 'ACAOrigin=*')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_URL + 'ACAOrigin=*', mode: 'cors' }]);
})
+ }, 'The SW must intercept the request of CORS-supported other origin XHR.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.xhr(
+ REDIRECT_URL + encodeURIComponent(BASE_URL))
.then(function() {
- return xhr_fail_test(
- frame,
- REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL));
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL + encodeURIComponent(BASE_URL),
+ mode: 'cors'
+ }]);
+ });
+ }, 'The SW must intercept only the first request of redirected XHR.');
+
+promise_frame_test(function(t, frame, worker) {
+ return promise_rejects(
+ t,
+ null,
Marijn Kruisselbrink 2017/05/09 18:09:09 my mistake, but as this landed, annevk landed a ch
+ frame.contentWindow.xhr(
+ REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL)),
+ 'SW fallbacked XHR which is redirected to CORS-unsupported ' +
+ 'other origin should fail.')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL),
+ mode: 'cors'
+ }]);
+ });
+ }, 'The SW must intercept only the first request for XHR which is' +
+ ' redirected to CORS-unsupported other origin.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.xhr(
+ REDIRECT_URL +
+ encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'))
+ .then(function() {
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL +
+ encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
+ mode: 'cors'
+ }]);
+ });
+ }, 'The SW must intercept only the first request for XHR which is ' +
+ 'redirected to CORS-supported other origin.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.load_image(BASE_PNG_URL, '')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: BASE_PNG_URL, mode: 'no-cors' }]);
+ });
+ }, 'The SW must intercept the request for image.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.load_image(OTHER_BASE_PNG_URL, '')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_PNG_URL, mode: 'no-cors' }]);
+ });
+ }, 'The SW must intercept the request for other origin image.');
+
+promise_frame_test(function(t, frame, worker) {
+ return promise_rejects(
+ t,
+ null,
+ frame.contentWindow.load_image(OTHER_BASE_PNG_URL, 'anonymous'),
+ 'SW fallbacked CORS-unsupported other origin image request ' +
+ 'should fail.')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_PNG_URL, mode: 'cors' }]);
})
+ }, 'The SW must intercept the request for CORS-unsupported other ' +
+ 'origin image.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.load_image(
+ OTHER_BASE_PNG_URL + 'ACAOrigin=*', 'anonymous')
.then(function() {
- return xhr_succeed_test(
- frame,
- REDIRECT_URL +
- encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'));
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_PNG_URL + 'ACAOrigin=*', mode: 'cors' }]);
+ });
+ }, 'The SW must intercept the request for CORS-supported other ' +
+ 'origin image.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.load_image(
+ REDIRECT_URL + encodeURIComponent(BASE_PNG_URL), '')
+ .catch(function() {
+ assert_unreached(
+ 'SW fallbacked redirected image request should succeed.');
})
.then(function() {
- return new Promise(function(resolve) {
- var channel = new MessageChannel();
- channel.port1.onmessage = t.step_func(function(msg) {
- frame.remove();
- resolve(msg);
- });
- worker.postMessage({port: channel.port2}, [channel.port2]);
- });
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL + encodeURIComponent(BASE_PNG_URL),
+ mode: 'no-cors'
+ }]);
+ });
+ }, 'The SW must intercept only the first request for redirected ' +
+ 'image resource.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.load_image(
+ REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL), '')
+ .catch(function() {
+ assert_unreached(
+ 'SW fallbacked image request which is redirected to ' +
+ 'other origin should succeed.');
})
- .then(function(msg) {
- var requests = msg.data.requests;
- assert_equals(requests.length, expected_urls.length + 1,
- 'The count of the requests which are passed to the ' +
- 'ServiceWorker must be correct.');
- assert_equals(requests[0].url, new URL(SCOPE, location).toString(),
- 'The first request to the SW must be the request for ' +
- 'the page.');
- assert_equals(requests[0].mode, 'navigate',
- 'The mode of the first request to the SW must be ' +
- 'navigate');
- for (var i = 0; i < expected_urls.length; ++i) {
- assert_equals(requests[i + 1].url, expected_urls[i],
- 'The URL of the request which was passed from XHR ' +
- 'to the ServiceWorker must be correct.');
- assert_equals(requests[i + 1].mode, 'cors',
- 'The mode of the request which was passed from XHR ' +
- 'to the ServiceWorker must be cors.');
- }
- service_worker_unregister_and_done(t, SCOPE);
+ .then(function() {
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL),
+ mode: 'no-cors'
+ }]);
})
- .catch(unreached_rejection(t));
- }, 'Verify the fallback behavior of FetchEvent');
+ }, 'The SW must intercept only the first request for image ' +
+ 'resource which is redirected to other origin.');
+
+promise_frame_test(function(t, frame, worker) {
+ return promise_rejects(
+ t,
+ null,
+ frame.contentWindow.load_image(
+ REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL),
+ 'anonymous'),
+ 'SW fallbacked image request which is redirected to ' +
+ 'CORS-unsupported other origin should fail.')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL),
+ mode: 'cors'
+ }]);
+ });
+ }, 'The SW must intercept only the first request for image ' +
+ 'resource which is redirected to CORS-unsupported other origin.');
+
+promise_frame_test(function(t, frame, worker) {
+ return frame.contentWindow.load_image(
+ REDIRECT_URL +
+ encodeURIComponent(OTHER_BASE_PNG_URL + 'ACAOrigin=*'),
+ 'anonymous')
+ .then(function() {
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL +
+ encodeURIComponent(OTHER_BASE_PNG_URL + 'ACAOrigin=*'),
+ mode: 'cors'
+ }]);
+ });
+ }, 'The SW must intercept only the first request for image ' +
+ 'resource which is redirected to CORS-supported other origin.');
</script>

Powered by Google App Engine
This is Rietveld 408576698