OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: fetch()</title> |
| 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="resources/test-helpers.js"></script> |
| 6 <script> |
| 7 var test = async_test('Verify access control of fetch() in a Service Worker'); |
| 8 test.step(function() { |
| 9 window.addEventListener('message', test.step_func(onMessage), false); |
| 10 var scope = 'resources/fetch-access-control-iframe.html'; |
| 11 service_worker_unregister_and_register( |
| 12 test, 'resources/fetch-access-control-worker.js', scope).then(test.step_fu
nc(onRegister)); |
| 13 |
| 14 var kBaseUrl = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-con
trol.php?'; |
| 15 var kCorsBaseUrl = 'http://localhost:8000/serviceworker/resources/fetch-access
-control.php?'; |
| 16 var kBaseRedirectUrl = 'http://127.0.0.1:8000/serviceworker/resources/redirect
.php?Redirect='; |
| 17 var kIframeUrl = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-c
ontrol-iframe.html'; |
| 18 var kWorkerUrl = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-c
ontrol-worker.js'; |
| 19 |
| 20 var checkFetchResult = function (expected, url, data) { |
| 21 assert_equals(data.fetchResult, expected, url + ' should be ' + expected); |
| 22 }; |
| 23 var checkFetchResponseBody = function (hasBody, url, data) { |
| 24 assert_equals(data.fetchResult, 'resolved', 'fetchResult must be resolved. u
rl = ' + url); |
| 25 assert_equals(data.hasBody, hasBody, 'hasBody must match. url = ' + url); |
| 26 }; |
| 27 var checkFetchResponseHeader = function (name, expected, url, data) { |
| 28 assert_equals(data.fetchResult, 'resolved', 'fetchResult must be resolved. u
rl = ' + url); |
| 29 var exist = false; |
| 30 for (var i = 0; i < data.headers.length; ++i) { |
| 31 if (data.headers[i][0] == name) { |
| 32 exist = true; |
| 33 } |
| 34 } |
| 35 assert_equals(exist, expected, 'checkFetchResponseHeader failed url:' + url
+ ' name:' + name); |
| 36 }; |
| 37 var checkFetchResponseType = function (type, url, data) { |
| 38 assert_equals(data.fetchResult, 'resolved', 'fetchResult must be resolved. u
rl = ' + url); |
| 39 assert_equals(data.type, type, 'type must match. url = ' + url); |
| 40 }; |
| 41 var fetchResolved = checkFetchResult.bind(this, 'resolved'); |
| 42 var fetchRejected = checkFetchResult.bind(this, 'rejected'); |
| 43 var fetchError = checkFetchResult.bind(this, 'error'); |
| 44 var hasBody = checkFetchResponseBody.bind(this, true); |
| 45 var noBody = checkFetchResponseBody.bind(this, false); |
| 46 var hasContentLength = checkFetchResponseHeader.bind(this, 'content-length', t
rue); |
| 47 var noContentLength = checkFetchResponseHeader.bind(this, 'content-length', fa
lse); |
| 48 var hasCustomServerHeader = checkFetchResponseHeader.bind(this, 'x-servicework
er-serverheader', true); |
| 49 var noCustomServerHeader = checkFetchResponseHeader.bind(this, 'x-serviceworke
r-serverheader', false); |
| 50 var typeBasic = checkFetchResponseType.bind(this, 'basic'); |
| 51 var typeCors = checkFetchResponseType.bind(this, 'cors'); |
| 52 var typeDefault = checkFetchResponseType.bind(this, 'default'); |
| 53 var typeError = checkFetchResponseType.bind(this, 'error'); |
| 54 var typeOpaque = checkFetchResponseType.bind(this, 'opaque'); |
| 55 |
| 56 var checkJsonpResult = function (expected, url, data) { |
| 57 assert_equals(data.jsonpResult, expected, url + ' jsonpResult should match')
; |
| 58 }; |
| 59 var checkJsonpHeader = function (name, value, url, data) { |
| 60 assert_equals(data.jsonpResult, 'success', url + ' jsonpResult must be succe
ss'); |
| 61 assert_equals(data.headers[name], value, |
| 62 'Request header to ' + url + ' which name is ' + name + ' shou
ld be ' + value); |
| 63 }; |
| 64 var checkJsonpMethod = function (method, url, data) { |
| 65 assert_equals(data.jsonpResult, 'success', url + ' jsonpResult must be succe
ss'); |
| 66 assert_equals(data.method, method, 'Method must match url:' + url); |
| 67 }; |
| 68 var checkJsonpAuth = function (username, password, url, data) { |
| 69 assert_equals(data.jsonpResult, 'success', url + ' jsonpResult must be succe
ss'); |
| 70 assert_equals(data.username, username, 'Username must match. url = ' + url); |
| 71 assert_equals(data.password, password, 'Password must match. url = ' + url); |
| 72 }; |
| 73 var checkJsonpError = checkJsonpResult.bind(this, 'error'); |
| 74 var checkJsonpSuccess = checkJsonpResult.bind(this, 'success'); |
| 75 var hasCustomHeader = checkJsonpHeader.bind(this, 'x-serviceworker-test', 'tes
t'); |
| 76 var noCustomHeader = checkJsonpHeader.bind(this, 'x-serviceworker-test', undef
ined); |
| 77 var methodIsGET = checkJsonpMethod.bind(this, 'GET'); |
| 78 var methodIsPOST = checkJsonpMethod.bind(this, 'POST'); |
| 79 var methodIsPUT = checkJsonpMethod.bind(this, 'PUT'); |
| 80 var methodIsXXX = checkJsonpMethod.bind(this, 'XXX'); |
| 81 var authCheck1 = checkJsonpAuth.bind(this, 'username1', 'password1'); |
| 82 var authCheck2 = checkJsonpAuth.bind(this, 'username2', 'password2'); |
| 83 |
| 84 var testTargets = []; |
| 85 testTargets.push([kBaseUrl + 'method=GET', |
| 86 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 87 [methodIsGET]]); |
| 88 testTargets.push([kBaseUrl + 'method=GET&headers={}', |
| 89 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 90 [methodIsGET]]); |
| 91 testTargets.push([kBaseUrl + 'method=GET&headers=CUSTOM', |
| 92 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 93 [methodIsGET, noCustomHeader]]); |
| 94 testTargets.push([kBaseUrl + 'method=POST&headers=CUSTOM', |
| 95 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 96 [methodIsPOST, noCustomHeader]]); |
| 97 testTargets.push([kBaseUrl + 'method=PUT', |
| 98 [fetchError]]); |
| 99 testTargets.push([kBaseUrl + 'method=XXX', |
| 100 [fetchError]]); |
| 101 |
| 102 testTargets.push([kBaseUrl + 'mode=same-origin&method=GET', |
| 103 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 104 [methodIsGET]]); |
| 105 testTargets.push([kBaseUrl + 'mode=same-origin&method=GET&headers={}', |
| 106 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 107 [methodIsGET]]); |
| 108 testTargets.push([kBaseUrl + 'mode=same-origin&method=GET&headers=CUSTOM', |
| 109 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 110 [methodIsGET, hasCustomHeader]]); |
| 111 testTargets.push([kBaseUrl + 'mode=same-origin&method=POST&headers=CUSTOM', |
| 112 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 113 [methodIsPOST, hasCustomHeader]]); |
| 114 testTargets.push([kBaseUrl + 'mode=same-origin&method=PUT&headers=CUSTOM', |
| 115 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 116 [methodIsPUT, hasCustomHeader]]); |
| 117 testTargets.push([kBaseUrl + 'mode=same-origin&method=XXX&headers=CUSTOM', |
| 118 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 119 [methodIsXXX, hasCustomHeader]]); |
| 120 |
| 121 testTargets.push([kBaseUrl + 'mode=no-cors&method=GET', |
| 122 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 123 [methodIsGET]]); |
| 124 testTargets.push([kBaseUrl + 'mode=no-cors&method=GET&headers={}', |
| 125 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 126 [methodIsGET]]); |
| 127 testTargets.push([kBaseUrl + 'mode=no-cors&method=GET&headers=CUSTOM', |
| 128 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 129 [methodIsGET, noCustomHeader]]); |
| 130 testTargets.push([kBaseUrl + 'mode=no-cors&method=POST&headers=CUSTOM', |
| 131 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 132 [methodIsPOST, noCustomHeader]]); |
| 133 testTargets.push([kBaseUrl + 'mode=no-cors&method=PUT', |
| 134 [fetchError]]); |
| 135 testTargets.push([kBaseUrl + 'mode=no-cors&method=XXX', |
| 136 [fetchError]]); |
| 137 |
| 138 testTargets.push([kBaseUrl + 'mode=cors&method=GET', |
| 139 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 140 [methodIsGET]]); |
| 141 testTargets.push([kBaseUrl + 'mode=cors&method=GET&headers={}', |
| 142 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 143 [methodIsGET]]); |
| 144 testTargets.push([kBaseUrl + 'mode=cors&method=GET&headers=CUSTOM', |
| 145 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 146 [methodIsGET, hasCustomHeader]]); |
| 147 testTargets.push([kBaseUrl + 'mode=cors&method=POST&headers=CUSTOM', |
| 148 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 149 [methodIsPOST, hasCustomHeader]]); |
| 150 testTargets.push([kBaseUrl + 'mode=cors&method=PUT&headers=CUSTOM', |
| 151 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 152 [methodIsPUT, hasCustomHeader]]); |
| 153 testTargets.push([kBaseUrl + 'mode=cors&method=XXX&headers=CUSTOM', |
| 154 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeBasic], |
| 155 [methodIsXXX, hasCustomHeader]]); |
| 156 |
| 157 // CORS test |
| 158 testTargets.push([kCorsBaseUrl + 'method=GET&headers=CUSTOM', |
| 159 [fetchResolved, noContentLength, noCustomServerHeader, noBod
y, typeOpaque], |
| 160 [methodIsGET, noCustomHeader]]); |
| 161 testTargets.push([kCorsBaseUrl + 'method=POST&headers=CUSTOM', |
| 162 [fetchResolved, noContentLength, noCustomServerHeader, noBod
y, typeOpaque], |
| 163 [methodIsPOST, noCustomHeader]]); |
| 164 testTargets.push([kCorsBaseUrl + 'method=PUT&headers=CUSTOM', |
| 165 [fetchError]]); |
| 166 testTargets.push([kCorsBaseUrl + 'method=XXX&headers=CUSTOM', |
| 167 [fetchError]]); |
| 168 |
| 169 testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=GET', [fetchRejected
]]); |
| 170 testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=POST', [fetchRejecte
d]]); |
| 171 testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=PUT', [fetchRejected
]]); |
| 172 testTargets.push([kCorsBaseUrl + 'mode=same-origin&method=XXX', [fetchRejected
]]); |
| 173 |
| 174 testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=GET&headers=CUSTOM', |
| 175 [fetchResolved, noContentLength, noCustomServerHeader, noBod
y, typeOpaque], |
| 176 [methodIsGET, noCustomHeader]]); |
| 177 testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=POST&headers=CUSTOM', |
| 178 [fetchResolved, noContentLength, noCustomServerHeader, noBod
y, typeOpaque], |
| 179 [methodIsPOST, noCustomHeader]]); |
| 180 testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=PUT&headers=CUSTOM', |
| 181 [fetchError]]); |
| 182 testTargets.push([kCorsBaseUrl + 'mode=no-cors&method=XXX&headers=CUSTOM', |
| 183 [fetchError]]); |
| 184 |
| 185 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET', |
| 186 [fetchRejected]]); |
| 187 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=*', |
| 188 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 189 [methodIsGET]]); |
| 190 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.
0.1:8000', |
| 191 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 192 [methodIsGET]]); |
| 193 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.
0.1:8000,http://www.example.com', |
| 194 [fetchRejected]]); |
| 195 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://www.ex
ample.com', |
| 196 [fetchRejected]]); |
| 197 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=
X-ServiceWorker-ServerHeader', |
| 198 [fetchResolved, noContentLength, hasCustomServerHeader, hasB
ody, typeCors], |
| 199 [methodIsGET]]); |
| 200 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.
0.1:8000&ACEHeaders=X-ServiceWorker-ServerHeader', |
| 201 [fetchResolved, noContentLength, hasCustomServerHeader, hasB
ody, typeCors], |
| 202 [methodIsGET]]); |
| 203 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=
Content-Length, X-ServiceWorker-ServerHeader', |
| 204 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 205 [methodIsGET]]); |
| 206 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&ACAOrigin=http://127.0.
0.1:8000&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
| 207 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 208 [methodIsGET]]); |
| 209 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM', |
| 210 [fetchRejected]]); |
| 211 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigi
n=*', |
| 212 [fetchRejected]]); |
| 213 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigi
n=http://127.0.0.1:8000', |
| 214 [fetchRejected]]); |
| 215 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigi
n=*&ACAHeaders=x-serviceworker-test', |
| 216 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 217 [methodIsGET, hasCustomHeader]]); |
| 218 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigi
n=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test', |
| 219 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 220 [methodIsGET, hasCustomHeader]]); |
| 221 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigi
n=*&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-S
erverHeader', |
| 222 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 223 [methodIsGET, hasCustomHeader]]); |
| 224 testTargets.push([kCorsBaseUrl + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigi
n=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Lengt
h, X-ServiceWorker-ServerHeader', |
| 225 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 226 [methodIsGET, hasCustomHeader]]); |
| 227 |
| 228 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST', |
| 229 [fetchRejected]]); |
| 230 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=*', |
| 231 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 232 [methodIsPOST]]); |
| 233 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0
.0.1:8000', |
| 234 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 235 [methodIsPOST]]); |
| 236 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0
.0.1:8000,http://www.example.com', |
| 237 [fetchRejected]]); |
| 238 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://www.e
xample.com', |
| 239 [fetchRejected]]); |
| 240 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders
=X-ServiceWorker-ServerHeader', |
| 241 [fetchResolved, noContentLength, hasCustomServerHeader, hasB
ody, typeCors], |
| 242 [methodIsPOST]]); |
| 243 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0
.0.1:8000&ACEHeaders=X-ServiceWorker-ServerHeader', |
| 244 [fetchResolved, noContentLength, hasCustomServerHeader, hasB
ody, typeCors], |
| 245 [methodIsPOST]]); |
| 246 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders
=Content-Length, X-ServiceWorker-ServerHeader', |
| 247 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 248 [methodIsPOST]]); |
| 249 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&ACAOrigin=http://127.0
.0.1:8000&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
| 250 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 251 [methodIsPOST]]); |
| 252 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM', |
| 253 [fetchRejected]]); |
| 254 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrig
in=*', |
| 255 [fetchRejected]]); |
| 256 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrig
in=*&ACAHeaders=x-serviceworker-test', |
| 257 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 258 [methodIsPOST, hasCustomHeader]]); |
| 259 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrig
in=*&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-
ServerHeader', |
| 260 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 261 [methodIsPOST, hasCustomHeader]]); |
| 262 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrig
in=http://127.0.0.1:8000', |
| 263 [fetchRejected]]); |
| 264 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrig
in=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test', |
| 265 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 266 [methodIsPOST, hasCustomHeader]]); |
| 267 testTargets.push([kCorsBaseUrl + 'mode=cors&method=POST&headers=CUSTOM&ACAOrig
in=http://127.0.0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Leng
th, X-ServiceWorker-ServerHeader', |
| 268 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 269 [methodIsPOST, hasCustomHeader]]); |
| 270 |
| 271 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT', |
| 272 [fetchRejected]]); |
| 273 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAMethods=PUT', |
| 274 [fetchRejected]]); |
| 275 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*', |
| 276 [fetchRejected]]); |
| 277 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&ACAMethods=
PUT', |
| 278 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 279 [methodIsPUT]]); |
| 280 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT', |
| 281 [fetchRejected]]); |
| 282 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test', |
| 283 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 284 [methodIsPUT, hasCustomHeader]]); |
| 285 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-
ServiceWorker-ServerHeader', |
| 286 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 287 [methodIsPUT, hasCustomHeader]]); |
| 288 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT, XXX', |
| 289 [fetchRejected]]); |
| 290 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 291 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 292 [methodIsPUT, hasCustomHeader]]); |
| 293 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Lengt
h, X-ServiceWorker-ServerHeader', |
| 294 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 295 [methodIsPUT, hasCustomHeader]]); |
| 296 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000', |
| 297 [fetchRejected]]); |
| 298 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000&ACAMethods=PUT', |
| 299 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 300 [methodIsPUT]]); |
| 301 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT', |
| 302 [fetchRejected]]); |
| 303 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test', |
| 304 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 305 [methodIsPUT, hasCustomHeader]]); |
| 306 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test&ACEHeader
s=Content-Length, X-ServiceWorker-ServerHeader', |
| 307 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 308 [methodIsPUT, hasCustomHeader]]); |
| 309 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX', |
| 310 [fetchRejected]]); |
| 311 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 312 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 313 [methodIsPUT, hasCustomHeader]]); |
| 314 testTargets.push([kCorsBaseUrl + 'mode=cors&method=PUT&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEH
eaders=Content-Length, X-ServiceWorker-ServerHeader', |
| 315 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 316 [methodIsPUT, hasCustomHeader]]); |
| 317 |
| 318 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX', |
| 319 [fetchRejected]]); |
| 320 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAMethods=XXX', |
| 321 [fetchRejected]]); |
| 322 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*', |
| 323 [fetchRejected]]); |
| 324 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&ACAMethods=
XXX', |
| 325 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 326 [methodIsXXX]]); |
| 327 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUS
TOM&ACAMethods=XXX', |
| 328 [fetchRejected]]); |
| 329 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUS
TOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test', |
| 330 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 331 [methodIsXXX, hasCustomHeader]]); |
| 332 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUS
TOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-
ServiceWorker-ServerHeader', |
| 333 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 334 [methodIsXXX, hasCustomHeader]]); |
| 335 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT, XXX', |
| 336 [fetchRejected]]); |
| 337 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 338 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 339 [methodIsXXX, hasCustomHeader]]); |
| 340 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUS
TOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Lengt
h, X-ServiceWorker-ServerHeader', |
| 341 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 342 [methodIsXXX, hasCustomHeader]]); |
| 343 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000', |
| 344 [fetchRejected]]); |
| 345 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000&ACAMethods=XXX', |
| 346 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 347 [methodIsXXX]]); |
| 348 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=XXX', |
| 349 [fetchRejected]]); |
| 350 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test', |
| 351 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 352 [methodIsXXX, hasCustomHeader]]); |
| 353 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test&ACEHeader
s=Content-Length, X-ServiceWorker-ServerHeader', |
| 354 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 355 [methodIsXXX, hasCustomHeader]]); |
| 356 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX', |
| 357 [fetchRejected]]); |
| 358 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 359 [fetchResolved, noContentLength, noCustomServerHeader, hasBo
dy, typeCors], |
| 360 [methodIsXXX, hasCustomHeader]]); |
| 361 testTargets.push([kCorsBaseUrl + 'mode=cors&method=XXX&ACAOrigin=http://127.0.
0.1:8000&headers=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEH
eaders=Content-Length, X-ServiceWorker-ServerHeader', |
| 362 [fetchResolved, hasContentLength, hasCustomServerHeader, has
Body, typeCors], |
| 363 [methodIsXXX, hasCustomHeader]]); |
| 364 |
| 365 // Referer check |
| 366 testTargets.push([kBaseUrl + 'ignore=true', |
| 367 [], |
| 368 [checkJsonpHeader.bind(this, 'Referer', kIframeUrl)]]); |
| 369 testTargets.push([kBaseUrl + 'noChange=true', |
| 370 [fetchResolved], |
| 371 [checkJsonpHeader.bind(this, 'Referer', kWorkerUrl)]]); |
| 372 testTargets.push([kBaseUrl , |
| 373 [fetchResolved], |
| 374 [checkJsonpHeader.bind(this, 'Referer', kWorkerUrl)]]); |
| 375 |
| 376 // Auth check |
| 377 testTargets.push([kBaseUrl + 'Auth', |
| 378 [fetchResolved, hasBody], [checkJsonpError]]); |
| 379 testTargets.push([kBaseUrl + 'Auth&credentials=ommit', |
| 380 [fetchResolved, hasBody], [checkJsonpError]]); |
| 381 testTargets.push([kBaseUrl + 'Auth&credentials=include', |
| 382 [fetchResolved, hasBody], [authCheck1]]); |
| 383 testTargets.push([kBaseUrl + 'Auth&credentials=same-origin', |
| 384 [fetchResolved, hasBody], [authCheck1]]); |
| 385 |
| 386 testTargets.push([kBaseUrl + 'Auth&mode=no-cors&credentials=ommit', |
| 387 [fetchResolved, hasBody], [checkJsonpError]]); |
| 388 testTargets.push([kBaseUrl + 'Auth&mode=no-cors&credentials=include', |
| 389 [fetchResolved, hasBody], [authCheck1]]); |
| 390 testTargets.push([kBaseUrl + 'Auth&mode=no-cors&credentials=same-origin', |
| 391 [fetchResolved, hasBody], [authCheck1]]); |
| 392 |
| 393 testTargets.push([kBaseUrl + 'Auth&mode=same-origin&credentials=ommit', |
| 394 [fetchResolved, hasBody], [checkJsonpError]]); |
| 395 testTargets.push([kBaseUrl + 'Auth&mode=same-origin&credentials=include', |
| 396 [fetchResolved, hasBody], [authCheck1]]); |
| 397 testTargets.push([kBaseUrl + 'Auth&mode=same-origin&credentials=same-origin', |
| 398 [fetchResolved, hasBody], [authCheck1]]); |
| 399 |
| 400 testTargets.push([kBaseUrl + 'Auth&mode=cors&credentials=ommit', |
| 401 [fetchResolved, hasBody], [checkJsonpError]]); |
| 402 testTargets.push([kBaseUrl + 'Auth&mode=cors&credentials=include', |
| 403 [fetchResolved, hasBody], [authCheck1]]); |
| 404 testTargets.push([kBaseUrl + 'Auth&mode=cors&credentials=same-origin', |
| 405 [fetchResolved, hasBody], [authCheck1]]); |
| 406 |
| 407 testTargets.push([kCorsBaseUrl + 'Auth', |
| 408 [fetchResolved, noBody], [checkJsonpError]]); |
| 409 testTargets.push([kCorsBaseUrl + 'Auth&credentials=ommit', |
| 410 [fetchResolved, noBody], [checkJsonpError]]); |
| 411 testTargets.push([kCorsBaseUrl + 'Auth&credentials=include', |
| 412 [fetchResolved, noBody], [authCheck2]]); |
| 413 testTargets.push([kCorsBaseUrl + 'Auth&credentials=same-origin', |
| 414 [fetchResolved, noBody], [authCheck2]]); |
| 415 |
| 416 testTargets.push([kCorsBaseUrl + 'Auth&mode=no-cors&credentials=ommit', |
| 417 [fetchResolved, noBody], [checkJsonpError]]); |
| 418 testTargets.push([kCorsBaseUrl + 'Auth&mode=no-cors&credentials=include', |
| 419 [fetchResolved, noBody], [authCheck2]]); |
| 420 testTargets.push([kCorsBaseUrl + 'Auth&mode=no-cors&credentials=same-origin', |
| 421 [fetchResolved, noBody], [authCheck2]]); |
| 422 |
| 423 testTargets.push([kCorsBaseUrl + 'Auth&mode=same-origin&credentials=ommit', |
| 424 [fetchRejected]]); |
| 425 testTargets.push([kCorsBaseUrl + 'Auth&mode=same-origin&credentials=include', |
| 426 [fetchRejected]]); |
| 427 testTargets.push([kCorsBaseUrl + 'Auth&mode=same-origin&credentials=same-origi
n', |
| 428 [fetchRejected]]); |
| 429 |
| 430 testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=ommit', |
| 431 [fetchRejected]]); |
| 432 testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include', |
| 433 [fetchRejected]]); |
| 434 testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=same-origin', |
| 435 [fetchRejected]]); |
| 436 testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin
=*', |
| 437 [fetchRejected]]); |
| 438 testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin
=http://127.0.0.1:8000', |
| 439 [fetchRejected]]); |
| 440 testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin
=*&ACACredentials=true', |
| 441 [fetchRejected]]); |
| 442 testTargets.push([kCorsBaseUrl + 'Auth&mode=cors&credentials=include&ACAOrigin
=http://127.0.0.1:8000&ACACredentials=true', |
| 443 [fetchResolved, hasBody], [authCheck2]]); |
| 444 |
| 445 |
| 446 |
| 447 // Redirect |
| 448 testTargets.push([kBaseRedirectUrl + encodeURIComponent(kBaseUrl), |
| 449 [fetchRejected]]); |
| 450 testTargets.push([kBaseRedirectUrl + encodeURIComponent(kCorsBaseUrl), |
| 451 [fetchRejected]]); |
| 452 |
| 453 function onRegister(worker) { |
| 454 worker.addEventListener('statechange', test.step_func(onStateChange)); |
| 455 var messageChannel = new MessageChannel(); |
| 456 messageChannel.port1.onmessage = test.step_func(onWorkerMessage); |
| 457 worker.postMessage({port: messageChannel.port2}, [messageChannel.port2]); |
| 458 } |
| 459 |
| 460 var jsonpResultCount = 0; |
| 461 |
| 462 function onWorkerMessage(e) { |
| 463 var message = e.data; |
| 464 if (message.fetchResult == "resolved" && message.originalURL != testTargets[
jsonpResultCount][0]) { |
| 465 // Ignored redirected fetch. |
| 466 return; |
| 467 } |
| 468 testTargets[jsonpResultCount][1].forEach(function(checkFunc){ |
| 469 checkFunc.call(this, testTargets[jsonpResultCount][0], message); |
| 470 }); |
| 471 } |
| 472 |
| 473 function onMessage(e) { |
| 474 if (e.origin == 'http://localhost:8000') { |
| 475 loadNext(); |
| 476 return; |
| 477 } |
| 478 var message = e.data; |
| 479 if (testTargets[jsonpResultCount][2]) { |
| 480 testTargets[jsonpResultCount][2].forEach(function(checkFunc){ |
| 481 checkFunc.call(this, testTargets[jsonpResultCount][0], message); |
| 482 }); |
| 483 } |
| 484 ++jsonpResultCount; |
| 485 if (jsonpResultCount == testTargets.length) { |
| 486 service_worker_unregister_and_done(test, scope); |
| 487 } else { |
| 488 loadNext(); |
| 489 } |
| 490 } |
| 491 var frameWindow = {}; |
| 492 function loadNext() { |
| 493 frameWindow.postMessage( |
| 494 {url: testTargets[jsonpResultCount][0]}, |
| 495 kIframeUrl); |
| 496 } |
| 497 function onStateChange(event) { |
| 498 if (event.target.state != 'activated') |
| 499 return; |
| 500 with_iframe('resources/fetch-access-control-iframe.html') |
| 501 .then(function(frame) { |
| 502 frameWindow = frame.contentWindow; |
| 503 login1(); |
| 504 }); |
| 505 } |
| 506 function login1() { |
| 507 var xhr = new XMLHttpRequest(); |
| 508 xhr.addEventListener('load', test.step_func(login2), false); |
| 509 xhr.open('GET', |
| 510 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-control
.php?Auth', |
| 511 true, 'username1', 'password1'); |
| 512 xhr.send(); |
| 513 } |
| 514 function login2() { |
| 515 with_iframe('http://localhost:8000/serviceworker/resources/fetch-access-cont
rol-login.html') |
| 516 } |
| 517 }); |
| 518 </script> |
OLD | NEW |