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 <body> |
| 7 <script> |
| 8 var SCOPE = 'resources/fetch-access-control-iframe.html'; |
| 9 var BASE_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-contr
ol.php?'; |
| 10 var OTHER_BASE_URL = 'http://localhost:8000/serviceworker/resources/fetch-access
-control.php?'; |
| 11 var REDIRECT_URL = 'http://127.0.0.1:8000/serviceworker/resources/redirect.php?R
edirect='; |
| 12 var IFRAME_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-con
trol-iframe.html'; |
| 13 var WORKER_URL = 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-con
trol-worker.js'; |
| 14 var IFRAME_ORIGIN = 'http://127.0.0.1:8000'; |
| 15 |
| 16 // Functions to check the result from the ServiceWorker. |
| 17 var checkFetchResult = function (expected, url, data) { |
| 18 assert_equals(data.fetchResult, expected, url + ' should be ' + expected); |
| 19 }; |
| 20 var checkFetchResponseBody = function (hasBody, url, data) { |
| 21 assert_equals(data.fetchResult, |
| 22 'resolved', |
| 23 'fetchResult must be resolved. url: ' + url); |
| 24 assert_equals(data.hasBody, |
| 25 hasBody, |
| 26 'hasBody must match. url: ' + url); |
| 27 }; |
| 28 var checkFetchResponseHeader = function (name, expected, url, data) { |
| 29 assert_equals(data.fetchResult, |
| 30 'resolved', |
| 31 'fetchResult must be resolved. url: ' + url); |
| 32 var exist = false; |
| 33 for (var i = 0; i < data.headers.length; ++i) { |
| 34 if (data.headers[i][0] === name) { |
| 35 exist = true; |
| 36 } |
| 37 } |
| 38 assert_equals(exist, |
| 39 expected, |
| 40 'header check failed url: ' + url + ' name: ' + name); |
| 41 }; |
| 42 var checkFetchResponseType = function (type, url, data) { |
| 43 assert_equals(data.fetchResult, |
| 44 'resolved', |
| 45 'fetchResult must be resolved. url = ' + url); |
| 46 assert_equals(data.type, |
| 47 type, |
| 48 'type must match. url: ' + url); |
| 49 }; |
| 50 var fetchIgnored = checkFetchResult.bind(this, 'ignored'); |
| 51 var fetchResolved = checkFetchResult.bind(this, 'resolved'); |
| 52 var fetchRejected = checkFetchResult.bind(this, 'rejected'); |
| 53 var fetchError = checkFetchResult.bind(this, 'error'); |
| 54 var hasBody = checkFetchResponseBody.bind(this, true); |
| 55 var noBody = checkFetchResponseBody.bind(this, false); |
| 56 var hasContentLength = |
| 57 checkFetchResponseHeader.bind(this, 'content-length', true); |
| 58 var noContentLength = |
| 59 checkFetchResponseHeader.bind(this, 'content-length', false); |
| 60 var hasServerHeader = |
| 61 checkFetchResponseHeader.bind(this, 'x-serviceworker-serverheader', true); |
| 62 var noServerHeader = |
| 63 checkFetchResponseHeader.bind(this, 'x-serviceworker-serverheader', false); |
| 64 var typeBasic = checkFetchResponseType.bind(this, 'basic'); |
| 65 var typeCors = checkFetchResponseType.bind(this, 'cors'); |
| 66 var typeOpaque = checkFetchResponseType.bind(this, 'opaque'); |
| 67 |
| 68 // Functions to check the result of JSONP which is evaluated in |
| 69 // fetch-access-control-iframe.html by appending <script> element. |
| 70 var checkJsonpResult = function (expected, url, data) { |
| 71 assert_equals(data.jsonpResult, |
| 72 expected, |
| 73 url + ' jsonpResult should match'); |
| 74 }; |
| 75 var checkJsonpHeader = function (name, value, url, data) { |
| 76 assert_equals(data.jsonpResult, |
| 77 'success', |
| 78 url + ' jsonpResult must be success'); |
| 79 assert_equals(data.headers[name], |
| 80 value, |
| 81 'Request header check failed url:' + url + ' name:' + name); |
| 82 }; |
| 83 var checkJsonpMethod = function (method, url, data) { |
| 84 assert_equals(data.jsonpResult, |
| 85 'success', |
| 86 url + ' jsonpResult must be success'); |
| 87 assert_equals(data.method, |
| 88 method, |
| 89 'Method must match url:' + url); |
| 90 }; |
| 91 var checkJsonpAuth = function (username, password, url, data) { |
| 92 assert_equals(data.jsonpResult, |
| 93 'success', |
| 94 url + ' jsonpResult must be success'); |
| 95 assert_equals(data.username, |
| 96 username, |
| 97 'Username must match. url: ' + url); |
| 98 assert_equals(data.password, |
| 99 password, |
| 100 'Password must match. url: ' + url); |
| 101 }; |
| 102 var checkJsonpError = checkJsonpResult.bind(this, 'error'); |
| 103 var checkJsonpSuccess = checkJsonpResult.bind(this, 'success'); |
| 104 var hasCustomHeader = |
| 105 checkJsonpHeader.bind(this, 'x-serviceworker-test', 'test'); |
| 106 var noCustomHeader = |
| 107 checkJsonpHeader.bind(this, 'x-serviceworker-test', undefined); |
| 108 var methodIsGET = checkJsonpMethod.bind(this, 'GET'); |
| 109 var methodIsPOST = checkJsonpMethod.bind(this, 'POST'); |
| 110 var methodIsPUT = checkJsonpMethod.bind(this, 'PUT'); |
| 111 var methodIsXXX = checkJsonpMethod.bind(this, 'XXX'); |
| 112 var authCheck1 = checkJsonpAuth.bind(this, 'username1', 'password1'); |
| 113 var authCheck2 = checkJsonpAuth.bind(this, 'username2', 'password2'); |
| 114 |
| 115 var TEST_TARGETS = [ |
| 116 [BASE_URL + 'method=GET', |
| 117 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 118 [methodIsGET]], |
| 119 [BASE_URL + 'method=GET&headers={}', |
| 120 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 121 [methodIsGET]], |
| 122 [BASE_URL + 'method=GET&headers=CUSTOM', |
| 123 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 124 [methodIsGET, noCustomHeader]], |
| 125 [BASE_URL + 'method=POST&headers=CUSTOM', |
| 126 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 127 [methodIsPOST, noCustomHeader]], |
| 128 [BASE_URL + 'method=PUT', |
| 129 [fetchError]], |
| 130 [BASE_URL + 'method=XXX', |
| 131 [fetchError]], |
| 132 |
| 133 [BASE_URL + 'mode=same-origin&method=GET', |
| 134 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 135 [methodIsGET]], |
| 136 [BASE_URL + 'mode=same-origin&method=GET&headers={}', |
| 137 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 138 [methodIsGET]], |
| 139 [BASE_URL + 'mode=same-origin&method=GET&headers=CUSTOM', |
| 140 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 141 [methodIsGET, hasCustomHeader]], |
| 142 [BASE_URL + 'mode=same-origin&method=POST&headers=CUSTOM', |
| 143 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 144 [methodIsPOST, hasCustomHeader]], |
| 145 [BASE_URL + 'mode=same-origin&method=PUT&headers=CUSTOM', |
| 146 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 147 [methodIsPUT, hasCustomHeader]], |
| 148 [BASE_URL + 'mode=same-origin&method=XXX&headers=CUSTOM', |
| 149 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 150 [methodIsXXX, hasCustomHeader]], |
| 151 |
| 152 [BASE_URL + 'mode=no-cors&method=GET', |
| 153 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 154 [methodIsGET]], |
| 155 [BASE_URL + 'mode=no-cors&method=GET&headers={}', |
| 156 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 157 [methodIsGET]], |
| 158 [BASE_URL + 'mode=no-cors&method=GET&headers=CUSTOM', |
| 159 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 160 [methodIsGET, noCustomHeader]], |
| 161 [BASE_URL + 'mode=no-cors&method=POST&headers=CUSTOM', |
| 162 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 163 [methodIsPOST, noCustomHeader]], |
| 164 [BASE_URL + 'mode=no-cors&method=PUT', |
| 165 [fetchError]], |
| 166 [BASE_URL + 'mode=no-cors&method=XXX', |
| 167 [fetchError]], |
| 168 |
| 169 [BASE_URL + 'mode=cors&method=GET', |
| 170 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 171 [methodIsGET]], |
| 172 [BASE_URL + 'mode=cors&method=GET&headers={}', |
| 173 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 174 [methodIsGET]], |
| 175 [BASE_URL + 'mode=cors&method=GET&headers=CUSTOM', |
| 176 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 177 [methodIsGET, hasCustomHeader]], |
| 178 [BASE_URL + 'mode=cors&method=POST&headers=CUSTOM', |
| 179 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 180 [methodIsPOST, hasCustomHeader]], |
| 181 [BASE_URL + 'mode=cors&method=PUT&headers=CUSTOM', |
| 182 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 183 [methodIsPUT, hasCustomHeader]], |
| 184 [BASE_URL + 'mode=cors&method=XXX&headers=CUSTOM', |
| 185 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeBasic], |
| 186 [methodIsXXX, hasCustomHeader]], |
| 187 |
| 188 // CORS test |
| 189 [OTHER_BASE_URL + 'method=GET&headers=CUSTOM', |
| 190 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], |
| 191 [methodIsGET, noCustomHeader]], |
| 192 [OTHER_BASE_URL + 'method=POST&headers=CUSTOM', |
| 193 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], |
| 194 [methodIsPOST, noCustomHeader]], |
| 195 [OTHER_BASE_URL + 'method=PUT&headers=CUSTOM', |
| 196 [fetchError]], |
| 197 [OTHER_BASE_URL + 'method=XXX&headers=CUSTOM', |
| 198 [fetchError]], |
| 199 |
| 200 [OTHER_BASE_URL + 'mode=same-origin&method=GET', [fetchRejected]], |
| 201 [OTHER_BASE_URL + 'mode=same-origin&method=POST', [fetchRejected]], |
| 202 [OTHER_BASE_URL + 'mode=same-origin&method=PUT', [fetchRejected]], |
| 203 [OTHER_BASE_URL + 'mode=same-origin&method=XXX', [fetchRejected]], |
| 204 |
| 205 [OTHER_BASE_URL + 'mode=no-cors&method=GET&headers=CUSTOM', |
| 206 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], |
| 207 [methodIsGET, noCustomHeader]], |
| 208 [OTHER_BASE_URL + 'mode=no-cors&method=POST&headers=CUSTOM', |
| 209 [fetchResolved, noContentLength, noServerHeader, noBody, typeOpaque], |
| 210 [methodIsPOST, noCustomHeader]], |
| 211 [OTHER_BASE_URL + 'mode=no-cors&method=PUT&headers=CUSTOM', |
| 212 [fetchError]], |
| 213 [OTHER_BASE_URL + 'mode=no-cors&method=XXX&headers=CUSTOM', |
| 214 [fetchError]], |
| 215 |
| 216 [OTHER_BASE_URL + 'mode=cors&method=GET', |
| 217 [fetchRejected]], |
| 218 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*', |
| 219 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 220 [methodIsGET]], |
| 221 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000', |
| 222 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 223 [methodIsGET]], |
| 224 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000,http:/
/www.example.com', |
| 225 [fetchRejected]], |
| 226 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://www.example.com', |
| 227 [fetchRejected]], |
| 228 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=X-ServiceWorker
-ServerHeader', |
| 229 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], |
| 230 [methodIsGET]], |
| 231 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000&ACEHea
ders=X-ServiceWorker-ServerHeader', |
| 232 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], |
| 233 [methodIsGET]], |
| 234 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=*&ACEHeaders=Content-Length,
X-ServiceWorker-ServerHeader', |
| 235 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 236 [methodIsGET]], |
| 237 [OTHER_BASE_URL + 'mode=cors&method=GET&ACAOrigin=http://127.0.0.1:8000&ACEHea
ders=Content-Length, X-ServiceWorker-ServerHeader', |
| 238 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 239 [methodIsGET]], |
| 240 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM', |
| 241 [fetchRejected]], |
| 242 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*', |
| 243 [fetchRejected]], |
| 244 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127.0.
0.1:8000', |
| 245 [fetchRejected]], |
| 246 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeaders=
x-serviceworker-test', |
| 247 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 248 [methodIsGET, hasCustomHeader]], |
| 249 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127.0.
0.1:8000&ACAHeaders=x-serviceworker-test', |
| 250 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 251 [methodIsGET, hasCustomHeader]], |
| 252 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=*&ACAHeaders=
x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
| 253 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 254 [methodIsGET, hasCustomHeader]], |
| 255 [OTHER_BASE_URL + 'mode=cors&method=GET&headers=CUSTOM&ACAOrigin=http://127.0.
0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWor
ker-ServerHeader', |
| 256 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 257 [methodIsGET, hasCustomHeader]], |
| 258 |
| 259 [OTHER_BASE_URL + 'mode=cors&method=POST', |
| 260 [fetchRejected]], |
| 261 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*', |
| 262 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 263 [methodIsPOST]], |
| 264 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000', |
| 265 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 266 [methodIsPOST]], |
| 267 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000,http:
//www.example.com', |
| 268 [fetchRejected]], |
| 269 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://www.example.com', |
| 270 [fetchRejected]], |
| 271 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=X-ServiceWorke
r-ServerHeader', |
| 272 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], |
| 273 [methodIsPOST]], |
| 274 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000&ACEHe
aders=X-ServiceWorker-ServerHeader', |
| 275 [fetchResolved, noContentLength, hasServerHeader, hasBody, typeCors], |
| 276 [methodIsPOST]], |
| 277 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=*&ACEHeaders=Content-Length
, X-ServiceWorker-ServerHeader', |
| 278 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 279 [methodIsPOST]], |
| 280 [OTHER_BASE_URL + 'mode=cors&method=POST&ACAOrigin=http://127.0.0.1:8000&ACEHe
aders=Content-Length, X-ServiceWorker-ServerHeader', |
| 281 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 282 [methodIsPOST]], |
| 283 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM', |
| 284 [fetchRejected]], |
| 285 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*', |
| 286 [fetchRejected]], |
| 287 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders
=x-serviceworker-test', |
| 288 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 289 [methodIsPOST, hasCustomHeader]], |
| 290 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=*&ACAHeaders
=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-ServerHeader', |
| 291 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 292 [methodIsPOST, hasCustomHeader]], |
| 293 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127.0
.0.1:8000', |
| 294 [fetchRejected]], |
| 295 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127.0
.0.1:8000&ACAHeaders=x-serviceworker-test', |
| 296 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 297 [methodIsPOST, hasCustomHeader]], |
| 298 [OTHER_BASE_URL + 'mode=cors&method=POST&headers=CUSTOM&ACAOrigin=http://127.0
.0.1:8000&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWo
rker-ServerHeader', |
| 299 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 300 [methodIsPOST, hasCustomHeader]], |
| 301 |
| 302 [OTHER_BASE_URL + 'mode=cors&method=PUT', |
| 303 [fetchRejected]], |
| 304 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAMethods=PUT', |
| 305 [fetchRejected]], |
| 306 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*', |
| 307 [fetchRejected]], |
| 308 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&ACAMethods=PUT', |
| 309 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 310 [methodIsPUT]], |
| 311 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT', |
| 312 [fetchRejected]], |
| 313 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT&ACAHeaders=x-serviceworker-test', |
| 314 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 315 [methodIsPUT, hasCustomHeader]], |
| 316 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-S
erverHeader', |
| 317 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 318 [methodIsPUT, hasCustomHeader]], |
| 319 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT, XXX', |
| 320 [fetchRejected]], |
| 321 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 322 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 323 [methodIsPUT, hasCustomHeader]], |
| 324 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWor
ker-ServerHeader', |
| 325 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 326 [methodIsPUT, hasCustomHeader]], |
| 327 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000', |
| 328 [fetchRejected]], |
| 329 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&ACAMet
hods=PUT', |
| 330 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 331 [methodIsPUT]], |
| 332 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT', |
| 333 [fetchRejected]], |
| 334 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test', |
| 335 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 336 [methodIsPUT, hasCustomHeader]], |
| 337 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Lengt
h, X-ServiceWorker-ServerHeader', |
| 338 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 339 [methodIsPUT, hasCustomHeader]], |
| 340 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT, XXX', |
| 341 [fetchRejected]], |
| 342 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 343 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 344 [methodIsPUT, hasCustomHeader]], |
| 345 [OTHER_BASE_URL + 'mode=cors&method=PUT&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-
Length, X-ServiceWorker-ServerHeader', |
| 346 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 347 [methodIsPUT, hasCustomHeader]], |
| 348 |
| 349 [OTHER_BASE_URL + 'mode=cors&method=XXX', |
| 350 [fetchRejected]], |
| 351 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAMethods=XXX', |
| 352 [fetchRejected]], |
| 353 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*', |
| 354 [fetchRejected]], |
| 355 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&ACAMethods=XXX', |
| 356 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 357 [methodIsXXX]], |
| 358 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=
XXX', |
| 359 [fetchRejected]], |
| 360 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=
XXX&ACAHeaders=x-serviceworker-test', |
| 361 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 362 [methodIsXXX, hasCustomHeader]], |
| 363 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=
XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWorker-S
erverHeader', |
| 364 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 365 [methodIsXXX, hasCustomHeader]], |
| 366 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT, XXX', |
| 367 [fetchRejected]], |
| 368 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 369 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 370 [methodIsXXX, hasCustomHeader]], |
| 371 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=*&headers=CUSTOM&ACAMethods=
PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Length, X-ServiceWor
ker-ServerHeader', |
| 372 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 373 [methodIsXXX, hasCustomHeader]], |
| 374 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000', |
| 375 [fetchRejected]], |
| 376 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&ACAMet
hods=XXX', |
| 377 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 378 [methodIsXXX]], |
| 379 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=XXX', |
| 380 [fetchRejected]], |
| 381 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test', |
| 382 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 383 [methodIsXXX, hasCustomHeader]], |
| 384 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-Lengt
h, X-ServiceWorker-ServerHeader', |
| 385 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 386 [methodIsXXX, hasCustomHeader]], |
| 387 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT, XXX', |
| 388 [fetchRejected]], |
| 389 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test', |
| 390 [fetchResolved, noContentLength, noServerHeader, hasBody, typeCors], |
| 391 [methodIsXXX, hasCustomHeader]], |
| 392 [OTHER_BASE_URL + 'mode=cors&method=XXX&ACAOrigin=http://127.0.0.1:8000&header
s=CUSTOM&ACAMethods=PUT, XXX&ACAHeaders=x-serviceworker-test&ACEHeaders=Content-
Length, X-ServiceWorker-ServerHeader', |
| 393 [fetchResolved, hasContentLength, hasServerHeader, hasBody, typeCors], |
| 394 [methodIsXXX, hasCustomHeader]], |
| 395 |
| 396 // Referer check |
| 397 [BASE_URL + 'ignore=true', |
| 398 [fetchIgnored], |
| 399 [checkJsonpHeader.bind(this, 'Referer', IFRAME_URL)]], |
| 400 [BASE_URL + 'noChange=true', |
| 401 [fetchResolved], |
| 402 [checkJsonpHeader.bind(this, 'Referer', WORKER_URL)]], |
| 403 [BASE_URL , |
| 404 [fetchResolved], |
| 405 [checkJsonpHeader.bind(this, 'Referer', WORKER_URL)]], |
| 406 |
| 407 // Auth check |
| 408 [BASE_URL + 'Auth', |
| 409 [fetchResolved, hasBody], [checkJsonpError]], |
| 410 [BASE_URL + 'Auth&credentials=omit', |
| 411 [fetchResolved, hasBody], [checkJsonpError]], |
| 412 [BASE_URL + 'Auth&credentials=include', |
| 413 [fetchResolved, hasBody], [authCheck1]], |
| 414 [BASE_URL + 'Auth&credentials=same-origin', |
| 415 [fetchResolved, hasBody], [authCheck1]], |
| 416 |
| 417 [BASE_URL + 'Auth&mode=no-cors&credentials=omit', |
| 418 [fetchResolved, hasBody], [checkJsonpError]], |
| 419 [BASE_URL + 'Auth&mode=no-cors&credentials=include', |
| 420 [fetchResolved, hasBody], [authCheck1]], |
| 421 [BASE_URL + 'Auth&mode=no-cors&credentials=same-origin', |
| 422 [fetchResolved, hasBody], [authCheck1]], |
| 423 |
| 424 [BASE_URL + 'Auth&mode=same-origin&credentials=omit', |
| 425 [fetchResolved, hasBody], [checkJsonpError]], |
| 426 [BASE_URL + 'Auth&mode=same-origin&credentials=include', |
| 427 [fetchResolved, hasBody], [authCheck1]], |
| 428 [BASE_URL + 'Auth&mode=same-origin&credentials=same-origin', |
| 429 [fetchResolved, hasBody], [authCheck1]], |
| 430 |
| 431 [BASE_URL + 'Auth&mode=cors&credentials=omit', |
| 432 [fetchResolved, hasBody], [checkJsonpError]], |
| 433 [BASE_URL + 'Auth&mode=cors&credentials=include', |
| 434 [fetchResolved, hasBody], [authCheck1]], |
| 435 [BASE_URL + 'Auth&mode=cors&credentials=same-origin', |
| 436 [fetchResolved, hasBody], [authCheck1]], |
| 437 |
| 438 [OTHER_BASE_URL + 'Auth', |
| 439 [fetchResolved, noBody], [checkJsonpError]], |
| 440 [OTHER_BASE_URL + 'Auth&credentials=omit', |
| 441 [fetchResolved, noBody], [checkJsonpError]], |
| 442 [OTHER_BASE_URL + 'Auth&credentials=include', |
| 443 [fetchResolved, noBody], [authCheck2]], |
| 444 [OTHER_BASE_URL + 'Auth&credentials=same-origin', |
| 445 [fetchResolved, noBody], [authCheck2]], |
| 446 |
| 447 [OTHER_BASE_URL + 'Auth&mode=no-cors&credentials=omit', |
| 448 [fetchResolved, noBody], [checkJsonpError]], |
| 449 [OTHER_BASE_URL + 'Auth&mode=no-cors&credentials=include', |
| 450 [fetchResolved, noBody], [authCheck2]], |
| 451 [OTHER_BASE_URL + 'Auth&mode=no-cors&credentials=same-origin', |
| 452 [fetchResolved, noBody], [authCheck2]], |
| 453 |
| 454 [OTHER_BASE_URL + 'Auth&mode=same-origin&credentials=omit', |
| 455 [fetchRejected]], |
| 456 [OTHER_BASE_URL + 'Auth&mode=same-origin&credentials=include', |
| 457 [fetchRejected]], |
| 458 [OTHER_BASE_URL + 'Auth&mode=same-origin&credentials=same-origin', |
| 459 [fetchRejected]], |
| 460 |
| 461 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=omit', |
| 462 [fetchRejected]], |
| 463 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include', |
| 464 [fetchRejected]], |
| 465 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=same-origin', |
| 466 [fetchRejected]], |
| 467 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=*', |
| 468 [fetchRejected]], |
| 469 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0.0
.1:8000', |
| 470 [fetchRejected]], |
| 471 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=*&ACACredentia
ls=true', |
| 472 [fetchRejected]], |
| 473 [OTHER_BASE_URL + 'Auth&mode=cors&credentials=include&ACAOrigin=http://127.0.0
.1:8000&ACACredentials=true', |
| 474 [fetchResolved, hasBody], [authCheck2]], |
| 475 |
| 476 // Redirect |
| 477 // FIXME: Currently we don't support redirect in Fech() API. |
| 478 [REDIRECT_URL + encodeURIComponent(BASE_URL), |
| 479 [fetchRejected]], |
| 480 [REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL), |
| 481 [fetchRejected]] |
| 482 ]; |
| 483 |
| 484 function login(test, origin, username, password) { |
| 485 return new Promise(function(resolve, reject) { |
| 486 with_iframe( |
| 487 origin + |
| 488 '/serviceworker/resources/fetch-access-control-login.html') |
| 489 .then(test.step_func(function(frame) { |
| 490 var channel = new MessageChannel(); |
| 491 channel.port1.onmessage = test.step_func(function() { |
| 492 resolve(); |
| 493 }); |
| 494 frame.contentWindow.postMessage( |
| 495 {username: username, password: password}, |
| 496 [channel.port2], origin); |
| 497 })); |
| 498 }); |
| 499 } |
| 500 |
| 501 var test = async_test('Verify access control of fetch() in a Service Worker'); |
| 502 test.step(function() { |
| 503 var login1 = login(test, 'http://127.0.0.1:8000', 'username1', 'password1'); |
| 504 var login2 = login(test, 'http://localhost:8000', 'username2', 'password2'); |
| 505 var workerScript = 'resources/fetch-access-control-worker.js'; |
| 506 var worker = undefined; |
| 507 var frameWindow = {}; |
| 508 var counter = 0; |
| 509 window.addEventListener('message', test.step_func(onMessage), false); |
| 510 |
| 511 Promise.all([login1, login2]) |
| 512 .then(function() { |
| 513 return service_worker_unregister_and_register(test, |
| 514 workerScript, |
| 515 SCOPE); |
| 516 }) |
| 517 .then(function(sw) { |
| 518 worker = sw; |
| 519 var messageChannel = new MessageChannel(); |
| 520 messageChannel.port1.onmessage = test.step_func(onWorkerMessage); |
| 521 sw.postMessage( |
| 522 {port: messageChannel.port2}, [messageChannel.port2]); |
| 523 return wait_for_state(test, sw, 'activated'); |
| 524 }) |
| 525 .then(function() { return with_iframe(SCOPE); }) |
| 526 .then(function(frame) { |
| 527 frameWindow = frame.contentWindow; |
| 528 // Start tests. |
| 529 loadNext(); |
| 530 }) |
| 531 .catch(unreached_rejection(test)); |
| 532 |
| 533 var readyFromWorkerReceived = undefined; |
| 534 var resultFromWorkerReceived = undefined; |
| 535 var resultFromIframeReceived = undefined; |
| 536 |
| 537 function onMessage(e) { |
| 538 // The message is sent from fetch-access-control-iframe.html in report() |
| 539 // which is called by appending <script> element which source code is |
| 540 // generated by fetch-access-control.php. |
| 541 if (TEST_TARGETS[counter][2]) { |
| 542 TEST_TARGETS[counter][2].forEach(function(checkFunc) { |
| 543 checkFunc.call(this, |
| 544 TEST_TARGETS[counter][0], |
| 545 e.data); |
| 546 }); |
| 547 } |
| 548 resultFromIframeReceived(); |
| 549 } |
| 550 |
| 551 function onWorkerMessage(e) { |
| 552 // The message is sent from the ServiceWorker. |
| 553 var message = e.data; |
| 554 if (message.msg === 'READY') { |
| 555 readyFromWorkerReceived(); |
| 556 return; |
| 557 } |
| 558 TEST_TARGETS[counter][1].forEach(function(checkFunc) { |
| 559 checkFunc.call(this, |
| 560 TEST_TARGETS[counter][0], |
| 561 message); |
| 562 }); |
| 563 resultFromWorkerReceived(); |
| 564 } |
| 565 |
| 566 function loadNext() { |
| 567 var workerPromise = new Promise(function(resolve, reject) { |
| 568 resultFromWorkerReceived = resolve; |
| 569 }); |
| 570 var iframePromise = new Promise(function(resolve, reject) { |
| 571 resultFromIframeReceived = resolve; |
| 572 }); |
| 573 Promise.all([workerPromise, iframePromise]) |
| 574 .then(test.step_func(function() { |
| 575 ++counter; |
| 576 if (counter === TEST_TARGETS.length) { |
| 577 service_worker_unregister_and_done(test, SCOPE); |
| 578 } else { |
| 579 loadNext(); |
| 580 } |
| 581 })); |
| 582 (new Promise(function(resolve, reject) { |
| 583 readyFromWorkerReceived = resolve; |
| 584 worker.postMessage({msg: 'START TEST CASE'}); |
| 585 })) |
| 586 .then(test.step_func(function() { |
| 587 frameWindow.postMessage( |
| 588 {url: TEST_TARGETS[counter][0]}, |
| 589 IFRAME_ORIGIN); |
| 590 })); |
| 591 } |
| 592 }); |
| 593 </script> |
| 594 </body> |
OLD | NEW |