Chromium Code Reviews| Index: LayoutTests/http/tests/serviceworker/fetch-request-redirect.html |
| diff --git a/LayoutTests/http/tests/serviceworker/fetch-request-redirect.html b/LayoutTests/http/tests/serviceworker/fetch-request-redirect.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c5a623126a9ba6357fb6fcc428a0a8be8648b89b |
| --- /dev/null |
| +++ b/LayoutTests/http/tests/serviceworker/fetch-request-redirect.html |
| @@ -0,0 +1,181 @@ |
| +<!DOCTYPE html> |
| +<title>Service Worker: FetchEvent for resources</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="../resources/get-host-info.js"></script> |
| +<script src="resources/test-helpers.js?pipe=sub"></script> |
|
falken
2015/08/13 06:42:30
pipe-sub should be on get-host-info
horo
2015/08/13 10:46:36
Done.
|
| +<script> |
| + |
| +function assert_resolves(promise, description) { |
| + return new Promise(function(resolve, reject) { |
| + promise |
| + .then( |
| + function() { resolve(); }, |
| + function() { reject(description); }); |
| + }); |
| +} |
| + |
| +function assert_rejects(promise, description) { |
| + return new Promise(function(resolve, reject) { |
| + promise |
| + .then( |
| + function() { reject(description); }, |
| + function() { resolve(); }); |
| + }); |
| +} |
| + |
| +function iframe_test(url) { |
| + return new Promise(function(resolve, reject) { |
| + var frame = document.createElement('iframe'); |
| + // We can't catch the network error on iframe. So we use the timer. |
| + var timer = setTimeout(function() { |
| + reject(); |
| + frame.remove(); |
| + }, 500); |
| + frame.src = url; |
| + frame.onload = function() { |
| + clearTimeout(timer); |
| + if (frame.contentDocument.body.textContent == 'Hello world\n') |
| + resolve(); |
| + else |
| + reject(); |
| + frame.remove(); |
| + }; |
| + document.body.appendChild(frame); |
| + }); |
| +} |
| + |
| +async_test(function(t) { |
| + var SCOPE = 'resources/fetch-request-redirect-iframe.html'; |
| + var SCRIPT = 'resources/fetch-rewrite-worker.js'; |
| + var host_info = get_host_info(); |
| + var REDIRECT_URL = host_info['HTTP_ORIGIN'] + |
| + '/serviceworker/resources/redirect.php?Redirect='; |
| + var IMAGE_URL = host_info['HTTP_ORIGIN'] + '/resources/square.png'; |
| + var AUDIO_URL = |
| + host_info['HTTP_ORIGIN'] + '/media/resources/load-video.php?' + |
| + 'name=../../../../media/content/silence.oga&type=audio/ogg'; |
| + var XHR_URL = host_info['HTTP_ORIGIN'] + |
| + '/serviceworker/resources/simple.txt'; |
| + var HTML_URL = host_info['HTTP_ORIGIN'] + '/resources/dummy.html'; |
| + |
| + var REDIRECT_TO_IMAGE_URL = REDIRECT_URL + encodeURIComponent(IMAGE_URL); |
| + var REDIRECT_TO_AUDIO_URL = REDIRECT_URL + encodeURIComponent(AUDIO_URL); |
| + var REDIRECT_TO_XHR_URL = REDIRECT_URL + encodeURIComponent(XHR_URL); |
| + var REDIRECT_TO_HTML_URL = REDIRECT_URL + encodeURIComponent(HTML_URL); |
| + |
| + var worker; |
| + var frame; |
| + 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 Promise.all([ |
| + // XMLHttpRequest tests. |
| + assert_resolves(frame.contentWindow.xhr(XHR_URL), |
| + 'Normal XHR should succeed.'), |
| + assert_resolves(frame.contentWindow.xhr(REDIRECT_TO_XHR_URL), |
| + 'Redirected XHR should succeed.'), |
| + assert_resolves( |
| + frame.contentWindow.xhr( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_XHR_URL) + |
| + '&redirect-mode=follow'), |
| + 'Redirected XHR with Request.redirect=follow should succeed.'), |
| + assert_rejects( |
| + frame.contentWindow.xhr( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_XHR_URL) + |
| + '&redirect-mode=error'), |
| + 'Redirected XHR with Request.redirect=error should fail.'), |
| + assert_rejects( |
| + frame.contentWindow.xhr( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_XHR_URL) + |
| + '&redirect-mode=error'), |
|
falken
2015/08/13 06:42:30
manual
horo
2015/08/13 10:46:36
Done.
|
| + 'Redirected XHR with Request.redirect=manual should fail.'), |
| + |
| + // Image loading tests. |
| + assert_resolves(frame.contentWindow.load_image(IMAGE_URL), |
| + 'Normal image resource should be loaded.'), |
| + assert_resolves( |
| + frame.contentWindow.load_image(REDIRECT_TO_IMAGE_URL), |
| + 'Redirected image resource should be loaded.'), |
| + assert_resolves( |
| + frame.contentWindow.load_image( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_IMAGE_URL) + |
| + '&redirect-mode=follow'), |
| + 'Loading redirected image with Request.redirect=follow should' + |
| + ' succeed.'), |
| + assert_rejects( |
| + frame.contentWindow.load_image( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_IMAGE_URL) + |
| + '&redirect-mode=error'), |
| + 'Loading redirected image with Request.redirect=error should ' + |
| + 'fail.'), |
| + assert_rejects( |
| + frame.contentWindow.load_image( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_IMAGE_URL) + |
| + '&redirect-mode=manual'), |
| + 'Loading redirected image with Request.redirect=manual should' + |
| + ' fail.'), |
| + |
| + // Audio loading tests. |
| + assert_resolves(frame.contentWindow.load_audio(AUDIO_URL), |
| + 'Normal audio resource should be loaded.'), |
| + assert_resolves( |
| + frame.contentWindow.load_audio(REDIRECT_TO_AUDIO_URL), |
| + 'Redirected audio resource should be loaded.'), |
| + assert_resolves( |
| + frame.contentWindow.load_audio( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_AUDIO_URL) + |
| + '&redirect-mode=follow'), |
| + 'Loading redirected audio with Request.redirect=follow should' + |
| + ' succeed.'), |
| + assert_rejects( |
| + frame.contentWindow.load_audio( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_AUDIO_URL) + |
| + '&redirect-mode=error'), |
| + 'Loading redirected audio with Request.redirect=error should ' + |
| + 'fail.'), |
| + assert_rejects( |
| + frame.contentWindow.load_audio( |
| + './?url=' + encodeURIComponent(REDIRECT_TO_AUDIO_URL) + |
| + '&redirect-mode=manual'), |
| + 'Loading redirected audio with Request.redirect=manual should' + |
| + ' fail.'), |
| + |
| + // Iframe tests. |
| + assert_resolves(iframe_test(HTML_URL), |
| + 'Normal iframe loading should succeed.'), |
| + assert_resolves( |
| + iframe_test(REDIRECT_TO_HTML_URL), |
| + 'Normal redirected iframe loading should succeed.'), |
| + assert_resolves( |
| + iframe_test(SCOPE + '?url=' + |
| + encodeURIComponent(REDIRECT_TO_HTML_URL) + |
| + '&redirect-mode=follow'), |
| + 'Redirected iframe loading with with Request.redirect=follow '+ |
|
falken
2015/08/13 06:42:30
with with (and below)
horo
2015/08/13 10:46:36
Done.
|
| + 'should succeed.'), |
| + assert_rejects( |
| + iframe_test(SCOPE + '?url=' + |
| + encodeURIComponent(REDIRECT_TO_HTML_URL) + |
| + '&redirect-mode=error'), |
| + 'Redirected iframe loading with with Request.redirect=error '+ |
| + 'should fail.'), |
| + assert_resolves( |
| + iframe_test(SCOPE + '?url=' + |
| + encodeURIComponent(REDIRECT_TO_HTML_URL) + |
| + '&redirect-mode=manual'), |
| + 'Redirected iframe loading with with Request.redirect=follow '+ |
|
falken
2015/08/13 06:42:30
redirect=manual
horo
2015/08/13 10:46:36
Done.
|
| + 'should succeed.'), |
| + ]); |
| + }) |
| + .then(function() { |
| + frame.remove(); |
| + service_worker_unregister_and_done(t, SCOPE); |
| + }) |
| + .catch(unreached_rejection(t)); |
| + }, 'Verify redirect mode of Fetch API and ServiceWorker FetchEvent.'); |
| +</script> |