Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Service Worker: the fallback behavior of FetchEvent</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="resources/test-helpers.js?pipe=sub"></script> | |
| 6 <script> | |
| 7 var expected_urls = []; | |
| 8 | |
| 9 function xhr_fail_test(frame, url) { | |
| 10 expected_urls.push(url); | |
| 11 return new Promise(function(resolve, reject) { | |
| 12 frame.contentWindow.xhr(url) | |
| 13 .then(function(){ | |
| 14 reject(msg + ' should fail.'); | |
| 15 }) | |
| 16 .catch(function(){ | |
| 17 resolve(); | |
| 18 }); | |
| 19 }); | |
| 20 } | |
| 21 | |
| 22 function xhr_succeed_test(frame, url) { | |
| 23 expected_urls.push(url); | |
| 24 return new Promise(function(resolve, reject) { | |
| 25 frame.contentWindow.xhr(url) | |
| 26 .then(function(){ | |
| 27 resolve(); | |
| 28 }) | |
| 29 .catch(function(){ | |
| 30 reject(msg + ' should succeed.'); | |
| 31 }); | |
| 32 }); | |
| 33 } | |
| 34 | |
| 35 async_test(function(t) { | |
| 36 var SCOPE = 'resources/fetch-request-fallback-iframe.html'; | |
| 37 var SCRIPT = 'resources/fetch-request-fallback-worker.js'; | |
| 38 var host_info = get_host_info(); | |
| 39 var BASE_URL = host_info['HTTP_ORIGIN'] + | |
| 40 '/serviceworker/resources/fetch-access-control.php?'; | |
| 41 var OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] + | |
| 42 '/serviceworker/resources/fetch-access-control.php?'; | |
| 43 var REDIRECT_URL = host_info['HTTP_ORIGIN'] + | |
| 44 '/serviceworker/resources/redirect.php?Redirect='; | |
| 45 var frame; | |
| 46 var worker; | |
| 47 service_worker_unregister_and_register(t, SCRIPT, SCOPE) | |
| 48 .then(function(registration) { | |
| 49 return wait_for_update(t, registration); | |
| 50 }) | |
| 51 .then(function(sw) { | |
| 52 worker = sw; | |
| 53 return wait_for_state(t, sw, 'activated'); | |
| 54 }) | |
| 55 .then(function() { return with_iframe(SCOPE); }) | |
| 56 .then(function(f) { | |
| 57 frame = f; | |
| 58 return xhr_succeed_test(frame, BASE_URL); | |
| 59 }) | |
| 60 .then(function(f) { | |
| 61 return xhr_fail_test(frame, OTHER_BASE_URL); | |
| 62 }) | |
| 63 .then(function(f) { | |
| 64 return xhr_succeed_test(frame, OTHER_BASE_URL + 'ACAOrigin=*'); | |
| 65 }) | |
| 66 .then(function(f) { | |
| 67 return xhr_succeed_test(frame, | |
| 68 REDIRECT_URL + encodeURIComponent(BASE_URL)); | |
| 69 }) | |
| 70 .then(function() { | |
| 71 return xhr_fail_test( | |
| 72 frame, | |
| 73 REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL)); | |
| 74 }) | |
| 75 .then(function() { | |
| 76 return xhr_succeed_test( | |
| 77 frame, | |
| 78 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
| |
| 79 }) | |
| 80 .then(function() { | |
| 81 return new Promise(function(resolve) { | |
| 82 var channel = new MessageChannel(); | |
| 83 channel.port1.onmessage = t.step_func(function(msg) { | |
| 84 unload_iframe(frame); | |
| 85 resolve(msg); | |
| 86 }); | |
| 87 worker.postMessage({port: channel.port2}, [channel.port2]); | |
| 88 }); | |
| 89 }) | |
| 90 .then(function(msg) { | |
| 91 var requests = msg.data.requests; | |
| 92 assert_equals(requests.length, expected_urls.length + 1, | |
| 93 'The count of the requests which are passed to the ' + | |
| 94 'ServiceWorker must be correct.'); | |
| 95 assert_equals(requests[0].url, new URL(SCOPE, location).toString(), | |
| 96 'The first request to the SW must be the request for ' + | |
| 97 'the page.'); | |
| 98 assert_equals(requests[0].mode, 'no-cors', | |
| 99 'The mode of the first request to the SW must be ' + | |
| 100 'no-cors.'); | |
| 101 for (var i = 0; i < expected_urls.length; ++i) { | |
| 102 assert_equals(requests[i + 1].url, expected_urls[i], | |
| 103 'The URL of the request which was passed from XHR ' + | |
| 104 'to the ServiceWorker must be correct.'); | |
| 105 assert_equals(requests[i + 1].mode, 'cors', | |
| 106 'The mode of the request which was passed from XHR ' + | |
| 107 'to the ServiceWorker must be cors.'); | |
| 108 } | |
| 109 service_worker_unregister_and_done(t, SCOPE); | |
| 110 }) | |
| 111 .catch(unreached_rejection(t)); | |
| 112 }, 'Verify the fallback behavior of FetchEvent'); | |
| 113 </script> | |
| OLD | NEW |