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

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

Issue 712303002: [ServiceWorker] Add LayoutTests for the fallback behavior of FetchEvent. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/resources/fetch-request-fallback-iframe.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..4287a03435b965bbebcca3e9291b58211d28b008
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/fetch-request-fallback.html
@@ -0,0 +1,113 @@
+<!DOCTYPE html>
+<title>Service Worker: the fallback behavior of FetchEvent</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.js?pipe=sub"></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(msg + ' should fail.');
+ })
+ .catch(function(){
+ resolve();
+ });
+ });
+}
+
+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(msg + ' should succeed.');
+ });
+ });
+}
+
+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 OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] +
+ '/serviceworker/resources/fetch-access-control.php?';
+ var REDIRECT_URL = host_info['HTTP_ORIGIN'] +
+ '/serviceworker/resources/redirect.php?Redirect=';
+ var frame;
+ var worker;
+ service_worker_unregister_and_register(t, SCRIPT, SCOPE)
+ .then(function(registration) {
+ return wait_for_update(t, registration);
+ })
+ .then(function(sw) {
+ worker = sw;
+ return wait_for_state(t, sw, '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));
+ })
+ .then(function() {
+ return xhr_fail_test(
+ frame,
+ REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL));
+ })
+ .then(function() {
+ return xhr_succeed_test(
+ frame,
+ REDIRECT_URL + encodeURIComponent(BASE_URL + 'ACAOrigin=*'));
nhiroki 2014/11/11 07:58:04 "OTHER_BASE_URL + 'ACAOrigin=*'" seems correct.
horo 2014/11/11 08:28:31 Yes! Done
+ })
+ .then(function() {
+ return new Promise(function(resolve) {
+ var channel = new MessageChannel();
+ channel.port1.onmessage = t.step_func(function(msg) {
+ unload_iframe(frame);
+ 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.');
+ }
+ service_worker_unregister_and_done(t, SCOPE);
+ })
+ .catch(unreached_rejection(t));
+ }, 'Verify the fallback behavior of FetchEvent');
+</script>
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/resources/fetch-request-fallback-iframe.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698