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