Index: LayoutTests/http/tests/serviceworker/fetch-access-control.html |
diff --git a/LayoutTests/http/tests/serviceworker/fetch-access-control.html b/LayoutTests/http/tests/serviceworker/fetch-access-control.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..64d1fbc41017c73e1cdbd6e7694bc1c28ce6ded5 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/fetch-access-control.html |
@@ -0,0 +1,518 @@ |
+<!DOCTYPE html> |
+<title>Service Worker: fetch()</title> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="resources/test-helpers.js"></script> |
+<script> |
+var test = async_test('Verify access control of fetch() in a Service Worker'); |
+test.step(function() { |
+ window.addEventListener('message', test.step_func(onMessage), false); |
+ var scope = 'resources/fetch-access-control-iframe.html'; |
+ service_worker_unregister_and_register( |
+ test, 'resources/fetch-access-control-worker.js', scope).then(test.step_func(onRegister)); |
+ |
+ var kBaseUrl = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-control.php?'; |
+ var kCorsBaseUrl = 'http://localhost:8000/serviceworker/resources/fetch-access-control.php?'; |
+ var kBaseRedirectUrl = 'http://127.0.0.1:8000/serviceworker/resources/redirect.php?Redirect='; |
+ var kIframeUrl = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-control-iframe.html'; |
+ var kWorkerUrl = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-control-worker.js'; |
+ |
+ var checkFetchResult = function (expected, url, data) { |
+ assert_equals(data.fetchResult, expected, url + ' should be ' + expected); |
+ }; |
+ var checkFetchResponseBody = function (hasBody, url, data) { |
+ assert_equals(data.fetchResult, 'resolved', 'fetchResult must be resolved. url = ' + url); |
+ assert_equals(data.hasBody, hasBody, 'hasBody must match. url = ' + url); |
+ }; |
+ var checkFetchResponseHeader = function (name, expected, url, data) { |
+ assert_equals(data.fetchResult, 'resolved', 'fetchResult must be resolved. url = ' + url); |
+ var exist = false; |
+ for (var i = 0; i < data.headers.length; ++i) { |
+ if (data.headers[i][0] == name) { |
+ exist = true; |
+ } |
+ } |
+ assert_equals(exist, expected, 'checkFetchResponseHeader failed url:' + url + ' name:' + name); |
+ }; |
+ var checkFetchResponseType = function (type, url, data) { |
+ assert_equals(data.fetchResult, 'resolved', 'fetchResult must be resolved. url = ' + url); |
+ assert_equals(data.type, type, 'type must match. url = ' + url); |
+ }; |
+ var fetchResolved = checkFetchResult.bind(this, 'resolved'); |
+ var fetchRejected = checkFetchResult.bind(this, 'rejected'); |
+ var fetchError = checkFetchResult.bind(this, 'error'); |
+ var hasBody = checkFetchResponseBody.bind(this, true); |
+ var noBody = checkFetchResponseBody.bind(this, false); |
+ var hasContentLength = checkFetchResponseHeader.bind(this, 'content-length', true); |
+ var noContentLength = checkFetchResponseHeader.bind(this, 'content-length', false); |
+ var hasCustomServerHeader = checkFetchResponseHeader.bind(this, 'x-serviceworker-serverheader', true); |
+ var noCustomServerHeader = checkFetchResponseHeader.bind(this, 'x-serviceworker-serverheader', false); |
+ var typeBasic = checkFetchResponseType.bind(this, 'basic'); |
+ var typeCors = checkFetchResponseType.bind(this, 'cors'); |
+ var typeDefault = checkFetchResponseType.bind(this, 'default'); |
+ var typeError = checkFetchResponseType.bind(this, 'error'); |
+ var typeOpaque = checkFetchResponseType.bind(this, 'opaque'); |
+ |
+ var checkJsonpResult = function (expected, url, data) { |
+ assert_equals(data.jsonpResult, expected, url + ' jsonpResult should match'); |
+ }; |
+ var checkJsonpHeader = function (name, value, url, data) { |
+ assert_equals(data.jsonpResult, 'success', url + ' jsonpResult must be success'); |
+ assert_equals(data.headers[name], value, |
+ 'Request header to ' + url + ' which name is ' + name + ' should be ' + value); |
+ }; |
+ var checkJsonpMethod = function (method, url, data) { |
+ assert_equals(data.jsonpResult, 'success', url + ' jsonpResult must be success'); |
+ assert_equals(data.method, method, 'Method must match url:' + url); |
+ }; |
+ var checkJsonpAuth = function (username, password, url, data) { |
+ assert_equals(data.jsonpResult, 'success', url + ' jsonpResult must be success'); |
+ assert_equals(data.username, username, 'Username must match. url = ' + url); |
+ assert_equals(data.password, password, 'Password must match. url = ' + url); |
+ }; |
+ var checkJsonpError = checkJsonpResult.bind(this, 'error'); |
+ var checkJsonpSuccess = checkJsonpResult.bind(this, 'success'); |
+ var hasCustomHeader = checkJsonpHeader.bind(this, 'x-serviceworker-test', 'test'); |
+ var noCustomHeader = checkJsonpHeader.bind(this, 'x-serviceworker-test', undefined); |
+ var methodIsGET = checkJsonpMethod.bind(this, 'GET'); |
+ var methodIsPOST = checkJsonpMethod.bind(this, 'POST'); |
+ var methodIsPUT = checkJsonpMethod.bind(this, 'PUT'); |
+ var methodIsXXX = checkJsonpMethod.bind(this, 'XXX'); |
+ var authCheck1 = checkJsonpAuth.bind(this, 'username1', 'password1'); |
+ var authCheck2 = checkJsonpAuth.bind(this, 'username2', 'password2'); |
+ |
+ var testTargets = []; |
+ testTargets.push([kBaseUrl + 'method=GET', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'method=GET&headers={}', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'method=GET&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET, noCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'method=POST&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsPOST, noCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'method=PUT', |
+ [fetchError]]); |
+ testTargets.push([kBaseUrl + 'method=XXX', |
+ [fetchError]]); |
+ |
+ testTargets.push([kBaseUrl + 'mode=same-origin&method=GET', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'mode=same-origin&method=GET&headers={}', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'mode=same-origin&method=GET&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET, hasCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=same-origin&method=POST&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsPOST, hasCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=same-origin&method=PUT&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=same-origin&method=XXX&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsXXX, hasCustomHeader]]); |
+ |
+ testTargets.push([kBaseUrl + 'mode=no-cors&method=GET', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'mode=no-cors&method=GET&headers={}', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'mode=no-cors&method=GET&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET, noCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=no-cors&method=POST&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsPOST, noCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=no-cors&method=PUT', |
+ [fetchError]]); |
+ testTargets.push([kBaseUrl + 'mode=no-cors&method=XXX', |
+ [fetchError]]); |
+ |
+ testTargets.push([kBaseUrl + 'mode=cors&method=GET', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'mode=cors&method=GET&headers={}', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET]]); |
+ testTargets.push([kBaseUrl + 'mode=cors&method=GET&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsGET, hasCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=cors&method=POST&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsPOST, hasCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=cors&method=PUT&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kBaseUrl + 'mode=cors&method=XXX&headers=CUSTOM', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeBasic], |
+ [methodIsXXX, hasCustomHeader]]); |
+ |
+ // CORS test |
+ testTargets.push([kCorsBaseUrl + 'method=GET&headers=CUSTOM', |
+ [fetchResolved, noContentLength, noCustomServerHeader, noBody, typeOpaque], |
+ [methodIsGET, noCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'method=POST&headers=CUSTOM', |
+ [fetchResolved, noContentLength, noCustomServerHeader, noBody, typeOpaque], |
+ [methodIsPOST, noCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'method=PUT&headers=CUSTOM', |
+ [fetchError]]); |
+ testTargets.push([kCorsBaseUrl + 'method=XXX&headers=CUSTOM', |
+ [fetchError]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=GET', [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=POST', [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=PUT', [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=XXX', [fetchRejected]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=GET&headers=CUSTOM', |
+ [fetchResolved, noContentLength, noCustomServerHeader, noBody, typeOpaque], |
+ [methodIsGET, noCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=POST&headers=CUSTOM', |
+ [fetchResolved, noContentLength, noCustomServerHeader, noBody, typeOpaque], |
+ [methodIsPOST, noCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=PUT&headers=CUSTOM', |
+ [fetchError]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=XXX&headers=CUSTOM', |
+ [fetchError]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=*', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000,http://www.example.com', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://www.example.com', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=X-ServiceWorker-ServerHeader', |
+ [fetchResolved, noContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000&ACEHeaders=X-ServiceWorker-ServerHeader', |
+ [fetchResolved, noContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127.0.0.1:8000', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsGET, hasCustomHeader]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=*', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000,http://www.example.com', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://www.example.com', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=X-ServiceWorker-ServerHeader', |
+ [fetchResolved, noContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000&ACEHeaders=X-ServiceWorker-ServerHeader', |
+ [fetchResolved, noContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127.0.0.1:8000', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPOST, hasCustomHeader]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAMethods=PUT', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&ACAMethods=PUT', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT, XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&ACAMethods=PUT', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsPUT, hasCustomHeader]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAMethods=XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&ACAMethods=XXX', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT, XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&ACAMethods=XXX', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
+ [fetchResolved, noContentLength, noCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
+ [fetchResolved, hasContentLength, hasCustomServerHeader, hasBody, typeCors], |
+ [methodIsXXX, hasCustomHeader]]); |
+ |
+ // Referer check |
+ testTargets.push([kBaseUrl + 'ignore=true', |
+ [], |
+ [checkJsonpHeader.bind(this, 'Referer', kIframeUrl)]]); |
+ testTargets.push([kBaseUrl + 'noChange=true', |
+ [fetchResolved], |
+ [checkJsonpHeader.bind(this, 'Referer', kWorkerUrl)]]); |
+ testTargets.push([kBaseUrl , |
+ [fetchResolved], |
+ [checkJsonpHeader.bind(this, 'Referer', kWorkerUrl)]]); |
+ |
+ // Auth check |
+ testTargets.push([kBaseUrl + 'Auth', |
+ [fetchResolved, hasBody], [checkJsonpError]]); |
+ testTargets.push([kBaseUrl + 'Auth&credentials=ommit', |
+ [fetchResolved, hasBody], [checkJsonpError]]); |
+ testTargets.push([kBaseUrl + 'Auth&credentials=include', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ testTargets.push([kBaseUrl + 'Auth&credentials=same-origin', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ |
+ testTargets.push([kBaseUrl + 'Auth&mode=no-cors&credentials=ommit', |
+ [fetchResolved, hasBody], [checkJsonpError]]); |
+ testTargets.push([kBaseUrl + 'Auth&mode=no-cors&credentials=include', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ testTargets.push([kBaseUrl + 'Auth&mode=no-cors&credentials=same-origin', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ |
+ testTargets.push([kBaseUrl + 'Auth&mode=same-origin&credentials=ommit', |
+ [fetchResolved, hasBody], [checkJsonpError]]); |
+ testTargets.push([kBaseUrl + 'Auth&mode=same-origin&credentials=include', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ testTargets.push([kBaseUrl + 'Auth&mode=same-origin&credentials=same-origin', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ |
+ testTargets.push([kBaseUrl + 'Auth&mode=cors&credentials=ommit', |
+ [fetchResolved, hasBody], [checkJsonpError]]); |
+ testTargets.push([kBaseUrl + 'Auth&mode=cors&credentials=include', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ testTargets.push([kBaseUrl + 'Auth&mode=cors&credentials=same-origin', |
+ [fetchResolved, hasBody], [authCheck1]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'Auth', |
+ [fetchResolved, noBody], [checkJsonpError]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&credentials=ommit', |
+ [fetchResolved, noBody], [checkJsonpError]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&credentials=include', |
+ [fetchResolved, noBody], [authCheck2]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&credentials=same-origin', |
+ [fetchResolved, noBody], [authCheck2]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=no-cors&credentials=ommit', |
+ [fetchResolved, noBody], [checkJsonpError]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=no-cors&credentials=include', |
+ [fetchResolved, noBody], [authCheck2]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=no-cors&credentials=same-origin', |
+ [fetchResolved, noBody], [authCheck2]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=same-origin&credentials=ommit', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=same-origin&credentials=include', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=same-origin&credentials=same-origin', |
+ [fetchRejected]]); |
+ |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=ommit', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=same-origin', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin=*', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0.0.1:8000', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin=*&ACACredentials=true', |
+ [fetchRejected]]); |
+ testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0.0.1:8000&ACACredentials=true', |
+ [fetchResolved, hasBody], [authCheck2]]); |
+ |
+ |
+ |
+ // Redirect |
+ testTargets.push([kBaseRedirectUrl + encodeURIComponent(kBaseUrl), |
+ [fetchRejected]]); |
+ testTargets.push([kBaseRedirectUrl + encodeURIComponent(kCorsBaseUrl), |
+ [fetchRejected]]); |
+ |
+ function onRegister(worker) { |
+ worker.addEventListener('statechange', test.step_func(onStateChange)); |
+ var messageChannel = new MessageChannel(); |
+ messageChannel.port1.onmessage = test.step_func(onWorkerMessage); |
+ worker.postMessage({port: messageChannel.port2}, [messageChannel.port2]); |
+ } |
+ |
+ var jsonpResultCount = 0; |
+ |
+ function onWorkerMessage(e) { |
+ var message = e.data; |
+ if (message.fetchResult == "resolved" && message.originalURL != testTargets[jsonpResultCount][0]) { |
+ // Ignored redirected fetch. |
+ return; |
+ } |
+ testTargets[jsonpResultCount][1].forEach(function(checkFunc){ |
+ checkFunc.call(this, testTargets[jsonpResultCount][0], message); |
+ }); |
+ } |
+ |
+ function onMessage(e) { |
+ if (e.origin == 'http://localhost:8000') { |
+ loadNext(); |
+ return; |
+ } |
+ var message = e.data; |
+ if (testTargets[jsonpResultCount][2]) { |
+ testTargets[jsonpResultCount][2].forEach(function(checkFunc){ |
+ checkFunc.call(this, testTargets[jsonpResultCount][0], message); |
+ }); |
+ } |
+ ++jsonpResultCount; |
+ if (jsonpResultCount == testTargets.length) { |
+ service_worker_unregister_and_done(test, scope); |
+ } else { |
+ loadNext(); |
+ } |
+ } |
+ var frameWindow = {}; |
+ function loadNext() { |
+ frameWindow.postMessage( |
+ {url: testTargets[jsonpResultCount][0]}, |
+ kIframeUrl); |
+ } |
+ function onStateChange(event) { |
+ if (event.target.state != 'activated') |
+ return; |
+ with_iframe('resources/fetch-access-control-iframe.html') |
+ .then(function(frame) { |
+ frameWindow = frame.contentWindow; |
+ login1(); |
+ }); |
+ } |
+ function login1() { |
+ var xhr = new XMLHttpRequest(); |
+ xhr.addEventListener('load', test.step_func(login2), false); |
+ xhr.open('GET', |
+ 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-control.php?Auth', |
+ true, 'username1', 'password1'); |
+ xhr.send(); |
+ } |
+ function login2() { |
+ with_iframe('http://localhost:8000/serviceworker/resources/fetch-access-control-login.html') |
+ } |
+}); |
+</script> |