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

Unified Diff: LayoutTests/http/tests/serviceworker/fetch-request-fallback.html

Issue 1280243002: Add layout tests for Service Worker fallbacked subresource requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 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: LayoutTests/http/tests/serviceworker/fetch-request-fallback.html
diff --git a/LayoutTests/http/tests/serviceworker/fetch-request-fallback.html b/LayoutTests/http/tests/serviceworker/fetch-request-fallback.html
index 814479b1ceff64331233e3b654bd6536d9562141..0ce87f2e4e77dafe4c025eded0014198047c8a72 100644
--- a/LayoutTests/http/tests/serviceworker/fetch-request-fallback.html
+++ b/LayoutTests/http/tests/serviceworker/fetch-request-fallback.html
@@ -5,42 +5,68 @@
<script src="../resources/get-host-info.js"></script>
<script src="resources/test-helpers.js?pipe=sub"></script>
falken 2015/08/11 09:15:33 should we do ?pipe=sub on all our layout tests? I'
horo 2015/08/12 11:28:10 It was intended to get the port number with get_ho
falken 2015/08/13 06:22:03 Oops :) So I guess all get-host-info.js should use
<script>
-var expected_urls = [];
-
-function xhr_fail_test(frame, url) {
- expected_urls.push(url);
+function xhr_test(frame, url, expect_success) {
return new Promise(function(resolve, reject) {
frame.contentWindow.xhr(url)
.then(function(){
falken 2015/08/11 09:15:33 nit: space before {
horo 2015/08/12 11:28:10 removed.
- reject(url + ' should fail.');
+ if (expect_success)
+ resolve();
+ else
+ reject(url + ' should fail.');
})
.catch(function(){
falken 2015/08/11 09:15:33 ditto
horo 2015/08/12 11:28:10 removed.
- resolve();
+ if (expect_success)
+ reject(url + ' should succeed.');
+ else
+ resolve();
});
falken 2015/08/11 09:15:33 This pattern seems dangerous, if you have: f(x) {
horo 2015/08/12 11:28:10 assert_resolves/assert_rejects looks good. I rewro
});
}
-function xhr_succeed_test(frame, url) {
- expected_urls.push(url);
+function img_test(frame, url, cross_origin, expect_success) {
return new Promise(function(resolve, reject) {
- frame.contentWindow.xhr(url)
+ frame.contentWindow.load_image(url, cross_origin)
.then(function(){
- resolve();
+ if (expect_success)
+ resolve();
+ else
+ reject(url + ' should fail.');
})
.catch(function(){
- reject(url + ' should succeed.');
+ if (expect_success)
+ reject(url + ' should succeed.');
+ else
+ 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]);
+ })
falken 2015/08/11 09:15:32 nit: semicolon
horo 2015/08/12 11:28:10 Done.
+}
+
+function check_urls(worker, expected_requests, description) {
+ return get_fetched_urls(worker)
+ .then(function(msg) {
+ var requests = msg.data.requests;
+ assert_object_equals(requests, expected_requests, description);
+ })
falken 2015/08/11 09:15:32 semicolon
horo 2015/08/12 11:28:10 Done.
+}
+
async_test(function(t) {
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['HTTP_ORIGIN'] +
'/serviceworker/resources/fetch-access-control.php?';
+ var BASE_PNG_URL = BASE_URL + 'PNGIMAGE&';
var OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] +
'/serviceworker/resources/fetch-access-control.php?';
+ var OTHER_BASE_PNG_URL = OTHER_BASE_URL + 'PNGIMAGE&';
var REDIRECT_URL = host_info['HTTP_ORIGIN'] +
'/serviceworker/resources/redirect.php?Redirect=';
var frame;
@@ -53,58 +79,160 @@ async_test(function(t) {
.then(function() { return with_iframe(SCOPE); })
.then(function(f) {
frame = f;
- return xhr_succeed_test(frame, BASE_URL);
+ return check_urls(
+ worker,
+ [{
+ url: host_info['HTTP_ORIGIN'] + '/serviceworker/' + SCOPE,
+ mode: 'no-cors'
+ }],
+ "The SW must catch the request of page load.");
falken 2015/08/11 09:15:32 s/catch/intercept/ throughout "the request of pag
horo 2015/08/12 11:28:10 Done.
})
- .then(function(f) {
- return xhr_fail_test(frame, OTHER_BASE_URL);
+ .then(function() {
+ return xhr_test(frame, BASE_URL, true);
})
- .then(function(f) {
- return xhr_succeed_test(frame, OTHER_BASE_URL + 'ACAOrigin=*');
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: BASE_URL, mode: 'cors' }],
+ "The SW must catch the request of same origin XHR.");
})
- .then(function(f) {
- return xhr_succeed_test(frame,
- REDIRECT_URL + encodeURIComponent(BASE_URL));
+ .then(function() {
+ return xhr_test(frame, OTHER_BASE_URL, false);
})
.then(function() {
- return xhr_fail_test(
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_URL, mode: 'cors' }],
+ "The SW must catch the request of CORS unsupported other origin XHR.");
falken 2015/08/11 09:15:33 "CORS-unsupported" is easier to read All theses d
horo 2015/08/12 11:28:10 Done.
+ })
+ .then(function() {
+ return xhr_test(frame, OTHER_BASE_URL + 'ACAOrigin=*', true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_URL + 'ACAOrigin=*', mode: 'cors' }],
+ "The SW must catch the request of CORS supported other origin XHR.");
falken 2015/08/11 09:15:33 CORS-supported
horo 2015/08/12 11:28:10 Done.
+ })
+ .then(function() {
+ return xhr_test(frame,
+ REDIRECT_URL + encodeURIComponent(BASE_URL),
+ true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL + encodeURIComponent(BASE_URL),
+ mode: 'cors'
+ }],
+ "The SW must catch only the first request of redirected XHR.");
+ })
+ .then(function() {
+ return xhr_test(
frame,
- REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL));
+ REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL),
+ false);
})
.then(function() {
- return xhr_succeed_test(
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL),
+ mode: 'cors'
+ }],
+ "The SW must catch only the first request for XHR which is redirected to CORS unsupported other origin.");
+ })
+ .then(function() {
+ return xhr_test(
frame,
REDIRECT_URL +
- encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'));
- })
- .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]);
- });
- })
- .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, 'no-cors',
- 'The mode of the first request to the SW must be ' +
- 'no-cors.');
- 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.');
- }
+ encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
+ true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{
+ url: REDIRECT_URL +
+ encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
+ mode: 'cors'
+ }],
+ "The SW must catch only the first request for XHR which is redirected to CORS supported other origin.");
+ })
+ .then(function() { return img_test(frame, BASE_PNG_URL, "", true); })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: BASE_PNG_URL, mode: 'no-cors' }],
+ "The SW must catch the request for image.")
+ })
+ .then(function() {
+ return img_test(frame, OTHER_BASE_PNG_URL, "", true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_PNG_URL, mode: 'no-cors' }],
+ "The SW must catch the request for other origin image.")
+ })
+ .then(function() {
+ return img_test(frame, OTHER_BASE_PNG_URL, "anonymous", false);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_PNG_URL, mode: 'cors' }],
+ "The SW must catch the request for CORS unsupported other origin image.")
+ })
+ .then(function() {
+ return img_test(
+ frame, OTHER_BASE_PNG_URL + 'ACAOrigin=*', "anonymous", true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: OTHER_BASE_PNG_URL + 'ACAOrigin=*', mode: 'cors' }],
+ "The SW must catch the request for CORS supported other origin image.")
+ })
+ .then(function() {
+ return img_test(frame, REDIRECT_URL + encodeURIComponent(BASE_PNG_URL), "", true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: REDIRECT_URL + encodeURIComponent(BASE_PNG_URL), mode: 'no-cors' }],
+ "The SW must catch only the first request for redirected image resource.");
+ })
+ .then(function() {
+ return img_test(frame, REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL), "", true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL), mode: 'no-cors' }],
+ "The SW must catch only the first request for image resource which is redirected to othre origin.");
falken 2015/08/11 09:15:33 other
horo 2015/08/12 11:28:10 Done.
+ })
+ .then(function() {
+ return img_test(frame, REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL), "anonymous", false);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL), mode: 'cors' }],
+ "The SW must catch only the first request for image resource which is redirected to CORS unsupported other origin.");
+ })
+ .then(function() {
+ return img_test(frame, REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL + 'ACAOrigin=*'), "anonymous", true);
+ })
+ .then(function() {
+ return check_urls(
+ worker,
+ [{ url: REDIRECT_URL + encodeURIComponent(OTHER_BASE_PNG_URL + 'ACAOrigin=*'), mode: 'cors' }],
+ "The SW must catch only the first request for image resource which is redirected to CORS supported other origin.");
+ })
+ .then(function() {
+ frame.remove();
service_worker_unregister_and_done(t, SCOPE);
})
.catch(unreached_rejection(t));

Powered by Google App Engine
This is Rietveld 408576698