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