/testing/web-platform/tests/service-workers/service-worker/fetch-event-redirect.https.html

https://github.com/rillian/firefox · HTML · 1102 lines · 1036 code · 66 blank · 0 comment · 0 complexity · 63de7a537a9d210542e7b27db36cdc44 MD5 · raw file

  1. <!DOCTYPE html>
  2. <title>Service Worker: Fetch Event Redirect Handling</title>
  3. <meta name=timeout content=long>
  4. <script src="/resources/testharness.js"></script>
  5. <script src="resources/testharness-helpers.js"></script>
  6. <script src="/resources/testharnessreport.js"></script>
  7. <script src="resources/get-host-info.sub.js"></script>
  8. <script src="resources/test-helpers.sub.js"></script>
  9. <body>
  10. <script>
  11. // ------------------------
  12. // Utilities for testing non-navigation requests that are intercepted with
  13. // a redirect.
  14. var host_info = get_host_info();
  15. var worker = 'resources/fetch-rewrite-worker.js';
  16. var frameURL = host_info['HTTPS_ORIGIN'] + base_path() +
  17. 'resources/fetch-event-redirect-iframe.html';
  18. var baseScope = 'resources/';
  19. var redirect = 'redirect.py';
  20. var success = base_path() + 'resources/success.py';
  21. function redirect_fetch_test(t, test) {
  22. var scope = baseScope + test.name;
  23. service_worker_unregister_and_register(t, worker, scope).then(function(reg) {
  24. return wait_for_state(t, reg.installing, 'activated');
  25. }).then(function() {
  26. return with_iframe(scope + '?url=' + encodeURIComponent(frameURL));
  27. }).then(function(frame) {
  28. var hostKeySuffix = test['url_credentials'] ? '_WITH_CREDS' : '';
  29. var acaorigin = '';
  30. var host = host_info['HTTPS_ORIGIN' + hostKeySuffix];
  31. if (test['redirect_dest'] === 'no-cors') {
  32. host = host_info['HTTPS_REMOTE_ORIGIN' + hostKeySuffix]
  33. } else if (test['redirect_dest'] === 'cors') {
  34. acaorigin = '?ACAOrigin=' + encodeURIComponent(host_info['HTTPS_ORIGIN']);
  35. host = host_info['HTTPS_REMOTE_ORIGIN' + hostKeySuffix]
  36. }
  37. var dest = '?Redirect=' + encodeURIComponent(host + success + acaorigin);
  38. var expectedTypeParam = test['expected_type']
  39. ? '&expected_type=' + test['expected_type']
  40. : '';
  41. var expectedRedirectedParam = test['expected_redirected']
  42. ? '&expected_redirected=' + test['expected_redirected']
  43. : '';
  44. var url = scope +
  45. '?url=' + encodeURIComponent(redirect + dest) +
  46. expectedTypeParam + expectedRedirectedParam
  47. var p = new Promise(function(resolve, reject) {
  48. var channel = new MessageChannel();
  49. channel.port1.onmessage = function(e) {
  50. frame.remove();
  51. if (e.data.result === 'reject') {
  52. reject(e.data.detail);
  53. } else if (e.data.result === 'success') {
  54. resolve(e.data.result);
  55. } else {
  56. resolve(e.data.detail);
  57. }
  58. };
  59. frame.contentWindow.postMessage({
  60. url: url,
  61. request_init: test.request_init,
  62. redirect_dest: test.redirect_dest,
  63. expected_type: test.expected_type,
  64. expected_redirected: test.expected_redirected,
  65. }, '*', [channel.port2]);
  66. });
  67. if (test.should_reject) {
  68. return assert_promise_rejects(p);
  69. }
  70. return p.then(function(result) {
  71. if (result !== 'success') {
  72. throw(new Error(result));
  73. }
  74. });
  75. }).then(function() {
  76. return service_worker_unregister_and_done(t, scope);
  77. }).catch(unreached_rejection(t));
  78. }
  79. // ------------------------
  80. // Test every combination of:
  81. // - RequestMode (same-origin, cors, no-cors)
  82. // - RequestRedirect (manual, follow, error)
  83. // - redirect destination origin (same-origin, cors, no-cors)
  84. // - redirect destination credentials (no user/pass, user/pass)
  85. //
  86. // TODO: add navigation requests
  87. // TODO: add redirects to data URI and verify same-origin data-URL flag behavior
  88. // TODO: add test where original redirect URI is cross-origin
  89. // TODO: verify final method is correct for 301, 302, and 303
  90. // TODO: verify CORS redirect results in all further redirects being
  91. // considered cross origin
  92. async_test(function(t) {
  93. redirect_fetch_test(t, {
  94. name: 'nonav-manual-cors-redirects-to-sameorigin-nocreds',
  95. redirect_dest: 'same-origin',
  96. url_credentials: false,
  97. expected_type: 'opaqueredirect',
  98. expected_redirected: false,
  99. request_init: {
  100. redirect: 'manual',
  101. mode: 'cors'
  102. },
  103. // should reject because only navigations can be intercepted with
  104. // opaqueredirect responses
  105. should_reject: true
  106. });
  107. }, 'Non-navigation, manual redirect, cors mode Request redirected to ' +
  108. 'same-origin without credentials should fail opaqueredirect interception ' +
  109. 'and response should not be redirected');
  110. async_test(function(t) {
  111. redirect_fetch_test(t, {
  112. name: 'nonav-manual-cors-redirects-to-nocors-nocreds',
  113. redirect_dest: 'no-cors',
  114. url_credentials: false,
  115. expected_type: 'opaqueredirect',
  116. expected_redirected: false,
  117. request_init: {
  118. redirect: 'manual',
  119. mode: 'cors'
  120. },
  121. // should reject because only navigations can be intercepted with
  122. // opaqueredirect responses
  123. should_reject: true
  124. });
  125. }, 'Non-navigation, manual redirect, cors mode Request redirected to ' +
  126. 'no-cors without credentials should fail opaqueredirect interception ' +
  127. 'and response should not be redirected');
  128. async_test(function(t) {
  129. redirect_fetch_test(t, {
  130. name: 'nonav-manual-cors-redirects-to-cors-nocreds',
  131. redirect_dest: 'cors',
  132. url_credentials: false,
  133. expected_type: 'opaqueredirect',
  134. expected_redirected: false,
  135. request_init: {
  136. redirect: 'manual',
  137. mode: 'cors'
  138. },
  139. // should reject because only navigations can be intercepted with
  140. // opaqueredirect responses
  141. should_reject: true
  142. });
  143. }, 'Non-navigation, manual redirect, cors mode Request redirected to ' +
  144. 'cors without credentials should fail opaqueredirect interception ' +
  145. 'and response should not be redirected');
  146. async_test(function(t) {
  147. redirect_fetch_test(t, {
  148. name: 'nonav-manual-sameorigin-redirects-to-sameorigin-nocreds',
  149. redirect_dest: 'same-origin',
  150. url_credentials: false,
  151. expected_type: 'opaqueredirect',
  152. expected_redirected: false,
  153. request_init: {
  154. redirect: 'manual',
  155. mode: 'same-origin'
  156. },
  157. // should reject because only navigations can be intercepted with
  158. // opaqueredirect responses
  159. should_reject: true
  160. });
  161. }, 'Non-navigation, manual redirect, same-origin mode Request redirected to ' +
  162. 'same-origin without credentials should fail opaqueredirect interception ' +
  163. 'and response should not be redirected');
  164. async_test(function(t) {
  165. redirect_fetch_test(t, {
  166. name: 'nonav-manual-sameorigin-redirects-to-nocors-nocreds',
  167. redirect_dest: 'no-cors',
  168. url_credentials: false,
  169. expected_type: 'opaqueredirect',
  170. expected_redirected: false,
  171. request_init: {
  172. redirect: 'manual',
  173. mode: 'same-origin'
  174. },
  175. // should reject because only navigations can be intercepted with
  176. // opaqueredirect responses
  177. should_reject: true
  178. });
  179. }, 'Non-navigation, manual redirect, same-origin mode Request redirected to ' +
  180. 'no-cors without credentials should fail opaqueredirect interception ' +
  181. 'and response should not be redirected');
  182. async_test(function(t) {
  183. redirect_fetch_test(t, {
  184. name: 'nonav-manual-sameorigin-redirects-to-cors-nocreds',
  185. redirect_dest: 'cors',
  186. url_credentials: false,
  187. expected_type: 'opaqueredirect',
  188. expected_redirected: false,
  189. request_init: {
  190. redirect: 'manual',
  191. mode: 'same-origin'
  192. },
  193. // should reject because only navigations can be intercepted with
  194. // opaqueredirect responses
  195. should_reject: true
  196. });
  197. }, 'Non-navigation, manual redirect, same-origin mode Request redirected to ' +
  198. 'cors without credentials should fail opaqueredirect interception ' +
  199. 'and response should not be redirected');
  200. async_test(function(t) {
  201. redirect_fetch_test(t, {
  202. name: 'nonav-manual-nocors-redirects-to-sameorigin-nocreds',
  203. redirect_dest: 'same-origin',
  204. url_credentials: false,
  205. expected_type: 'opaqueredirect',
  206. expected_redirected: false,
  207. request_init: {
  208. redirect: 'manual',
  209. mode: 'no-cors'
  210. },
  211. // should reject because only navigations can be intercepted with
  212. // opaqueredirect responses
  213. should_reject: true
  214. });
  215. }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
  216. 'same-origin without credentials should fail opaqueredirect interception ' +
  217. 'and response should not be redirected');
  218. async_test(function(t) {
  219. redirect_fetch_test(t, {
  220. name: 'nonav-manual-nocors-redirects-to-nocors-nocreds',
  221. redirect_dest: 'no-cors',
  222. url_credentials: false,
  223. expected_type: 'opaqueredirect',
  224. expected_redirected: false,
  225. request_init: {
  226. redirect: 'manual',
  227. mode: 'no-cors'
  228. },
  229. should_reject: false
  230. });
  231. }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
  232. 'no-cors without credentials should succeed interception ' +
  233. 'and response should not be redirected');
  234. async_test(function(t) {
  235. redirect_fetch_test(t, {
  236. name: 'nonav-manual-nocors-redirects-to-cors-nocreds',
  237. redirect_dest: 'cors',
  238. url_credentials: false,
  239. expected_type: 'opaqueredirect',
  240. expected_redirected: false,
  241. request_init: {
  242. redirect: 'manual',
  243. mode: 'no-cors'
  244. },
  245. should_reject: false
  246. });
  247. }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
  248. 'cors without credentials should succeed interception ' +
  249. 'and response should not be redirected');
  250. async_test(function(t) {
  251. redirect_fetch_test(t, {
  252. name: 'nonav-manual-cors-redirects-to-sameorigin-creds',
  253. redirect_dest: 'same-origin',
  254. url_credentials: true,
  255. expected_type: 'opaqueredirect',
  256. expected_redirected: false,
  257. request_init: {
  258. redirect: 'manual',
  259. mode: 'cors'
  260. },
  261. // should reject because only navigations can be intercepted with
  262. // opaqueredirect responses
  263. should_reject: true
  264. });
  265. }, 'Non-navigation, manual redirect, cors mode Request redirected to ' +
  266. 'same-origin with credentials should fail opaqueredirect interception ' +
  267. 'and response should not be redirected');
  268. async_test(function(t) {
  269. redirect_fetch_test(t, {
  270. name: 'nonav-manual-cors-redirects-to-nocors-creds',
  271. redirect_dest: 'no-cors',
  272. url_credentials: true,
  273. expected_type: 'opaqueredirect',
  274. expected_redirected: false,
  275. request_init: {
  276. redirect: 'manual',
  277. mode: 'cors'
  278. },
  279. // should reject because only navigations can be intercepted with
  280. // opaqueredirect responses
  281. should_reject: true
  282. });
  283. }, 'Non-navigation, manual redirect, cors mode Request redirected to ' +
  284. 'no-cors with credentials should fail opaqueredirect interception ' +
  285. 'and response should not be redirected');
  286. async_test(function(t) {
  287. redirect_fetch_test(t, {
  288. name: 'nonav-manual-cors-redirects-to-cors-creds',
  289. redirect_dest: 'cors',
  290. url_credentials: true,
  291. expected_type: 'opaqueredirect',
  292. expected_redirected: false,
  293. request_init: {
  294. redirect: 'manual',
  295. mode: 'cors'
  296. },
  297. // should reject because only navigations can be intercepted with
  298. // opaqueredirect responses
  299. should_reject: true
  300. });
  301. }, 'Non-navigation, manual redirect, cors mode Request redirected to ' +
  302. 'cors with credentials should fail opaqueredirect interception ' +
  303. 'and response should not be redirected');
  304. async_test(function(t) {
  305. redirect_fetch_test(t, {
  306. name: 'nonav-manual-sameorigin-redirects-to-sameorigin-creds',
  307. redirect_dest: 'same-origin',
  308. url_credentials: true,
  309. expected_type: 'opaqueredirect',
  310. expected_redirected: false,
  311. request_init: {
  312. redirect: 'manual',
  313. mode: 'same-origin'
  314. },
  315. // should reject because only navigations can be intercepted with
  316. // opaqueredirect responses
  317. should_reject: true
  318. });
  319. }, 'Non-navigation, manual redirect, same-origin mode Request redirected to ' +
  320. 'same-origin with credentials should fail opaqueredirect interception ' +
  321. 'and response should not be redirected');
  322. async_test(function(t) {
  323. redirect_fetch_test(t, {
  324. name: 'nonav-manual-sameorigin-redirects-to-nocors-creds',
  325. redirect_dest: 'no-cors',
  326. url_credentials: true,
  327. expected_type: 'opaqueredirect',
  328. expected_redirected: false,
  329. request_init: {
  330. redirect: 'manual',
  331. mode: 'same-origin'
  332. },
  333. // should reject because only navigations can be intercepted with
  334. // opaqueredirect responses
  335. should_reject: true
  336. });
  337. }, 'Non-navigation, manual redirect, same-origin mode Request redirected to ' +
  338. 'no-cors with credentials should fail opaqueredirect interception ' +
  339. 'and response should not be redirected');
  340. async_test(function(t) {
  341. redirect_fetch_test(t, {
  342. name: 'nonav-manual-sameorigin-redirects-to-cors-creds',
  343. redirect_dest: 'cors',
  344. url_credentials: true,
  345. expected_type: 'opaqueredirect',
  346. expected_redirected: false,
  347. request_init: {
  348. redirect: 'manual',
  349. mode: 'same-origin'
  350. },
  351. // should reject because only navigations can be intercepted with
  352. // opaqueredirect responses
  353. should_reject: true
  354. });
  355. }, 'Non-navigation, manual redirect, same-origin mode Request redirected to ' +
  356. 'cors with credentials should fail opaqueredirect interception ' +
  357. 'and response should not be redirected');
  358. async_test(function(t) {
  359. redirect_fetch_test(t, {
  360. name: 'nonav-manual-nocors-redirects-to-sameorigin-creds',
  361. redirect_dest: 'same-origin',
  362. url_credentials: true,
  363. expected_type: 'opaqueredirect',
  364. expected_redirected: false,
  365. request_init: {
  366. redirect: 'manual',
  367. mode: 'no-cors'
  368. },
  369. // should reject because only navigations can be intercepted with
  370. // opaqueredirect responses
  371. should_reject: true
  372. });
  373. }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
  374. 'same-origin with credentials should fail opaqueredirect interception ' +
  375. 'and response should not be redirected');
  376. async_test(function(t) {
  377. redirect_fetch_test(t, {
  378. name: 'nonav-manual-nocors-redirects-to-nocors-creds',
  379. redirect_dest: 'no-cors',
  380. url_credentials: true,
  381. expected_type: 'opaqueredirect',
  382. expected_redirected: false,
  383. request_init: {
  384. redirect: 'manual',
  385. mode: 'no-cors'
  386. },
  387. should_reject: false
  388. });
  389. }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
  390. 'no-cors with credentials should succeed interception ' +
  391. 'and response should not be redirected');
  392. async_test(function(t) {
  393. redirect_fetch_test(t, {
  394. name: 'nonav-manual-nocors-redirects-to-cors-creds',
  395. redirect_dest: 'cors',
  396. url_credentials: true,
  397. expected_type: 'opaqueredirect',
  398. expected_redirected: false,
  399. request_init: {
  400. redirect: 'manual',
  401. mode: 'no-cors'
  402. },
  403. should_reject: false
  404. });
  405. }, 'Non-navigation, manual redirect, no-cors mode Request redirected to ' +
  406. 'cors with credentials should succeed interception ' +
  407. 'and response should not be redirected');
  408. async_test(function(t) {
  409. redirect_fetch_test(t, {
  410. name: 'nonav-follow-cors-redirects-to-sameorigin-nocreds',
  411. redirect_dest: 'same-origin',
  412. url_credentials: false,
  413. expected_type: 'basic',
  414. expected_redirected: true,
  415. request_init: {
  416. redirect: 'follow',
  417. mode: 'cors'
  418. },
  419. should_reject: false
  420. });
  421. }, 'Non-navigation, follow redirect, cors mode Request redirected to ' +
  422. 'same-origin without credentials should succeed interception ' +
  423. 'and response should be redirected');
  424. async_test(function(t) {
  425. redirect_fetch_test(t, {
  426. name: 'nonav-follow-cors-redirects-to-nocors-nocreds',
  427. redirect_dest: 'no-cors',
  428. url_credentials: false,
  429. expected_type: 'should-not-get-a-response',
  430. expected_redirected: false,
  431. request_init: {
  432. redirect: 'follow',
  433. mode: 'cors'
  434. },
  435. // should reject because CORS requests require CORS headers on cross-origin
  436. // resources
  437. should_reject: true
  438. });
  439. }, 'Non-navigation, follow redirect, cors mode Request redirected to ' +
  440. 'no-cors without credentials should fail interception ' +
  441. 'and response should not be redirected');
  442. async_test(function(t) {
  443. redirect_fetch_test(t, {
  444. name: 'nonav-follow-cors-redirects-to-cors-nocreds',
  445. redirect_dest: 'cors',
  446. url_credentials: false,
  447. expected_type: 'cors',
  448. expected_redirected: true,
  449. request_init: {
  450. redirect: 'follow',
  451. mode: 'cors'
  452. },
  453. should_reject: false
  454. });
  455. }, 'Non-navigation, follow redirect, cors mode Request redirected to ' +
  456. 'cors without credentials should succeed interception ' +
  457. 'and response should be redirected');
  458. async_test(function(t) {
  459. redirect_fetch_test(t, {
  460. name: 'nonav-follow-sameorigin-redirects-to-sameorigin-nocreds',
  461. redirect_dest: 'same-origin',
  462. url_credentials: false,
  463. expected_type: 'basic',
  464. expected_redirected: true,
  465. request_init: {
  466. redirect: 'follow',
  467. mode: 'same-origin'
  468. },
  469. should_reject: false
  470. });
  471. }, 'Non-navigation, follow redirect, same-origin mode Request redirected to ' +
  472. 'same-origin without credentials should succeed interception ' +
  473. 'and response should be redirected');
  474. async_test(function(t) {
  475. redirect_fetch_test(t, {
  476. name: 'nonav-follow-sameorigin-redirects-to-nocors-nocreds',
  477. redirect_dest: 'no-cors',
  478. url_credentials: false,
  479. expected_type: 'should-not-get-a-response',
  480. expected_redirected: false,
  481. request_init: {
  482. redirect: 'follow',
  483. mode: 'same-origin'
  484. },
  485. // should reject because same-origin requests cannot load cross-origin
  486. // resources
  487. should_reject: true
  488. });
  489. }, 'Non-navigation, follow redirect, same-origin mode Request redirected to ' +
  490. 'no-cors without credentials should fail interception ' +
  491. 'and response should not be redirected');
  492. async_test(function(t) {
  493. redirect_fetch_test(t, {
  494. name: 'nonav-follow-sameorigin-redirects-to-cors-nocreds',
  495. redirect_dest: 'cors',
  496. url_credentials: false,
  497. expected_type: 'should-not-get-a-response',
  498. expected_redirected: false,
  499. request_init: {
  500. redirect: 'follow',
  501. mode: 'same-origin'
  502. },
  503. // should reject because same-origin requests cannot load cross-origin
  504. // resources
  505. should_reject: true
  506. });
  507. }, 'Non-navigation, follow redirect, same-origin mode Request redirected to ' +
  508. 'cors without credentials should fail interception ' +
  509. 'and response should not be redirected');
  510. async_test(function(t) {
  511. redirect_fetch_test(t, {
  512. name: 'nonav-follow-nocors-redirects-to-sameorigin-nocreds',
  513. redirect_dest: 'same-origin',
  514. url_credentials: false,
  515. expected_type: 'basic',
  516. expected_redirected: true,
  517. request_init: {
  518. redirect: 'follow',
  519. mode: 'no-cors'
  520. },
  521. should_reject: false
  522. });
  523. }, 'Non-navigation, follow redirect, no-cors mode Request redirected to ' +
  524. 'same-origin without credentials should succeed interception ' +
  525. 'and response should be redirected');
  526. async_test(function(t) {
  527. redirect_fetch_test(t, {
  528. name: 'nonav-follow-nocors-redirects-to-nocors-nocreds',
  529. redirect_dest: 'no-cors',
  530. url_credentials: false,
  531. expected_type: 'opaque',
  532. expected_redirected: false,
  533. request_init: {
  534. redirect: 'follow',
  535. mode: 'no-cors'
  536. },
  537. should_reject: false
  538. });
  539. }, 'Non-navigation, follow redirect, no-cors mode Request redirected to ' +
  540. 'no-cors without credentials should succeed interception ' +
  541. 'and response should not be redirected');
  542. async_test(function(t) {
  543. redirect_fetch_test(t, {
  544. name: 'nonav-follow-nocors-redirects-to-cors-nocreds',
  545. redirect_dest: 'cors',
  546. url_credentials: false,
  547. expected_type: 'opaque',
  548. expected_redirected: false,
  549. request_init: {
  550. redirect: 'follow',
  551. mode: 'no-cors'
  552. },
  553. should_reject: false
  554. });
  555. }, 'Non-navigation, follow redirect, no-cors mode Request redirected to ' +
  556. 'cors without credentials should succeed interception ' +
  557. 'and response should not be redirected');
  558. async_test(function(t) {
  559. redirect_fetch_test(t, {
  560. name: 'nonav-follow-cors-redirects-to-sameorigin-creds',
  561. redirect_dest: 'same-origin',
  562. url_credentials: true,
  563. expected_type: 'basic',
  564. expected_redirected: true,
  565. request_init: {
  566. redirect: 'follow',
  567. mode: 'cors'
  568. },
  569. should_reject: false
  570. });
  571. }, 'Non-navigation, follow redirect, cors mode Request redirected to ' +
  572. 'same-origin with credentials should succeed interception ' +
  573. 'and response should be redirected');
  574. async_test(function(t) {
  575. redirect_fetch_test(t, {
  576. name: 'nonav-follow-cors-redirects-to-nocors-creds',
  577. redirect_dest: 'no-cors',
  578. url_credentials: true,
  579. expected_type: 'should-not-get-a-response',
  580. expected_redirected: false,
  581. request_init: {
  582. redirect: 'follow',
  583. mode: 'cors'
  584. },
  585. // should reject because CORS requests require CORS headers on cross-origin
  586. // resources
  587. should_reject: true
  588. });
  589. }, 'Non-navigation, follow redirect, cors mode Request redirected to ' +
  590. 'no-cors with credentials should fail interception ' +
  591. 'and response should not be redirected');
  592. async_test(function(t) {
  593. redirect_fetch_test(t, {
  594. name: 'nonav-follow-cors-redirects-to-cors-creds',
  595. redirect_dest: 'cors',
  596. url_credentials: true,
  597. expected_type: 'cors',
  598. expected_redirected: true,
  599. request_init: {
  600. redirect: 'follow',
  601. mode: 'cors'
  602. },
  603. // should reject because CORS requests do not allow user/pass entries in
  604. // cross-origin URLs
  605. // NOTE: https://github.com/whatwg/fetch/issues/112
  606. should_reject: true
  607. });
  608. }, 'Non-navigation, follow redirect, cors mode Request redirected to ' +
  609. 'cors with credentials should fail interception ' +
  610. 'and response should be redirected');
  611. async_test(function(t) {
  612. redirect_fetch_test(t, {
  613. name: 'nonav-follow-sameorigin-redirects-to-sameorigin-creds',
  614. redirect_dest: 'same-origin',
  615. url_credentials: true,
  616. expected_type: 'basic',
  617. expected_redirected: true,
  618. request_init: {
  619. redirect: 'follow',
  620. mode: 'same-origin'
  621. },
  622. should_reject: false
  623. });
  624. }, 'Non-navigation, follow redirect, same-origin mode Request redirected to ' +
  625. 'same-origin with credentials should succeed interception ' +
  626. 'and response should be redirected');
  627. async_test(function(t) {
  628. redirect_fetch_test(t, {
  629. name: 'nonav-follow-sameorigin-redirects-to-nocors-creds',
  630. redirect_dest: 'no-cors',
  631. url_credentials: true,
  632. expected_type: 'should-not-get-a-response',
  633. expected_redirected: false,
  634. request_init: {
  635. redirect: 'follow',
  636. mode: 'same-origin'
  637. },
  638. // should reject because same-origin requests cannot load cross-origin
  639. // resources
  640. should_reject: true
  641. });
  642. }, 'Non-navigation, follow redirect, same-origin mode Request redirected to ' +
  643. 'no-cors with credentials should fail interception ' +
  644. 'and response should not be redirected');
  645. async_test(function(t) {
  646. redirect_fetch_test(t, {
  647. name: 'nonav-follow-sameorigin-redirects-to-cors-creds',
  648. redirect_dest: 'cors',
  649. url_credentials: true,
  650. expected_type: 'should-not-get-a-response',
  651. expected_redirected: false,
  652. request_init: {
  653. redirect: 'follow',
  654. mode: 'same-origin'
  655. },
  656. // should reject because same-origin requests cannot load cross-origin
  657. // resources
  658. should_reject: true
  659. });
  660. }, 'Non-navigation, follow redirect, same-origin mode Request redirected to ' +
  661. 'cors with credentials should fail interception ' +
  662. 'and response should not be redirected');
  663. async_test(function(t) {
  664. redirect_fetch_test(t, {
  665. name: 'nonav-follow-nocors-redirects-to-sameorigin-creds',
  666. redirect_dest: 'same-origin',
  667. url_credentials: true,
  668. expected_type: 'basic',
  669. expected_redirected: true,
  670. request_init: {
  671. redirect: 'follow',
  672. mode: 'no-cors'
  673. },
  674. should_reject: false
  675. });
  676. }, 'Non-navigation, follow redirect, no-cors mode Request redirected to ' +
  677. 'same-origin with credentials should succeed interception ' +
  678. 'and response should be redirected');
  679. async_test(function(t) {
  680. redirect_fetch_test(t, {
  681. name: 'nonav-follow-nocors-redirects-to-nocors-creds',
  682. redirect_dest: 'no-cors',
  683. url_credentials: true,
  684. expected_type: 'opaque',
  685. expected_redirected: false,
  686. request_init: {
  687. redirect: 'follow',
  688. mode: 'no-cors'
  689. },
  690. should_reject: false
  691. });
  692. }, 'Non-navigation, follow redirect, no-cors mode Request redirected to ' +
  693. 'no-cors with credentials should succeed interception ' +
  694. 'and response should not be redirected');
  695. async_test(function(t) {
  696. redirect_fetch_test(t, {
  697. name: 'nonav-follow-nocors-redirects-to-cors-creds',
  698. redirect_dest: 'cors',
  699. url_credentials: true,
  700. expected_type: 'opaque',
  701. expected_redirected: false,
  702. request_init: {
  703. redirect: 'follow',
  704. mode: 'no-cors'
  705. },
  706. should_reject: false
  707. });
  708. }, 'Non-navigation, follow redirect, no-cors mode Request redirected to ' +
  709. 'cors with credentials should succeed interception ' +
  710. 'and response should not be redirected');
  711. async_test(function(t) {
  712. redirect_fetch_test(t, {
  713. name: 'nonav-error-cors-redirects-to-sameorigin-nocreds',
  714. redirect_dest: 'same-origin',
  715. url_credentials: false,
  716. expected_type: 'error',
  717. expected_redirected: false,
  718. request_init: {
  719. redirect: 'error',
  720. mode: 'cors'
  721. },
  722. // should reject because requests with 'error' RequestRedirect cannot be
  723. // redirected.
  724. should_reject: true
  725. });
  726. }, 'Non-navigation, error redirect, cors mode Request redirected to ' +
  727. 'same-origin without credentials should fail interception ' +
  728. 'and response should not be redirected');
  729. async_test(function(t) {
  730. redirect_fetch_test(t, {
  731. name: 'nonav-error-cors-redirects-to-nocors-nocreds',
  732. redirect_dest: 'no-cors',
  733. url_credentials: false,
  734. expected_type: 'error',
  735. expected_redirected: false,
  736. request_init: {
  737. redirect: 'error',
  738. mode: 'cors'
  739. },
  740. // should reject because requests with 'error' RequestRedirect cannot be
  741. // redirected.
  742. should_reject: true
  743. });
  744. }, 'Non-navigation, error redirect, cors mode Request redirected to ' +
  745. 'no-cors without credentials should fail interception ' +
  746. 'and response should not be redirected');
  747. async_test(function(t) {
  748. redirect_fetch_test(t, {
  749. name: 'nonav-error-cors-redirects-to-cors-nocreds',
  750. redirect_dest: 'cors',
  751. url_credentials: false,
  752. expected_type: 'error',
  753. expected_redirected: false,
  754. request_init: {
  755. redirect: 'error',
  756. mode: 'cors'
  757. },
  758. // should reject because requests with 'error' RequestRedirect cannot be
  759. // redirected.
  760. should_reject: true
  761. });
  762. }, 'Non-navigation, error redirect, cors mode Request redirected to ' +
  763. 'cors without credentials should fail interception ' +
  764. 'and response should not be redirected');
  765. async_test(function(t) {
  766. redirect_fetch_test(t, {
  767. name: 'nonav-error-sameorigin-redirects-to-sameorigin-nocreds',
  768. redirect_dest: 'same-origin',
  769. url_credentials: false,
  770. expected_type: 'error',
  771. expected_redirected: false,
  772. request_init: {
  773. redirect: 'error',
  774. mode: 'same-origin'
  775. },
  776. // should reject because requests with 'error' RequestRedirect cannot be
  777. // redirected.
  778. should_reject: true
  779. });
  780. }, 'Non-navigation, error redirect, same-origin mode Request redirected to ' +
  781. 'same-origin without credentials should fail interception ' +
  782. 'and response should not be redirected');
  783. async_test(function(t) {
  784. redirect_fetch_test(t, {
  785. name: 'nonav-error-sameorigin-redirects-to-nocors-nocreds',
  786. redirect_dest: 'no-cors',
  787. url_credentials: false,
  788. expected_type: 'error',
  789. expected_redirected: false,
  790. request_init: {
  791. redirect: 'error',
  792. mode: 'same-origin'
  793. },
  794. // should reject because requests with 'error' RequestRedirect cannot be
  795. // redirected.
  796. should_reject: true
  797. });
  798. }, 'Non-navigation, error redirect, same-origin mode Request redirected to ' +
  799. 'no-cors without credentials should fail interception ' +
  800. 'and response should not be redirected');
  801. async_test(function(t) {
  802. redirect_fetch_test(t, {
  803. name: 'nonav-error-sameorigin-redirects-to-cors-nocreds',
  804. redirect_dest: 'cors',
  805. url_credentials: false,
  806. expected_type: 'error',
  807. expected_redirected: false,
  808. request_init: {
  809. redirect: 'error',
  810. mode: 'same-origin'
  811. },
  812. // should reject because requests with 'error' RequestRedirect cannot be
  813. // redirected.
  814. should_reject: true
  815. });
  816. }, 'Non-navigation, error redirect, same-origin mode Request redirected to ' +
  817. 'cors without credentials should fail interception ' +
  818. 'and response should not be redirected');
  819. async_test(function(t) {
  820. redirect_fetch_test(t, {
  821. name: 'nonav-error-nocors-redirects-to-sameorigin-nocreds',
  822. redirect_dest: 'same-origin',
  823. url_credentials: false,
  824. expected_type: 'error',
  825. expected_redirected: false,
  826. request_init: {
  827. redirect: 'error',
  828. mode: 'no-cors'
  829. },
  830. // should reject because requests with 'error' RequestRedirect cannot be
  831. // redirected.
  832. should_reject: true
  833. });
  834. }, 'Non-navigation, error redirect, no-cors mode Request redirected to ' +
  835. 'same-origin without credentials should fail interception ' +
  836. 'and response should not be redirected');
  837. async_test(function(t) {
  838. redirect_fetch_test(t, {
  839. name: 'nonav-error-nocors-redirects-to-nocors-nocreds',
  840. redirect_dest: 'no-cors',
  841. url_credentials: false,
  842. expected_type: 'error',
  843. expected_redirected: false,
  844. request_init: {
  845. redirect: 'error',
  846. mode: 'no-cors'
  847. },
  848. // should reject because requests with 'error' RequestRedirect cannot be
  849. // redirected.
  850. should_reject: true
  851. });
  852. }, 'Non-navigation, error redirect, no-cors mode Request redirected to ' +
  853. 'no-cors without credentials should fail interception ' +
  854. 'and response should not be redirected');
  855. async_test(function(t) {
  856. redirect_fetch_test(t, {
  857. name: 'nonav-error-nocors-redirects-to-cors-nocreds',
  858. redirect_dest: 'cors',
  859. url_credentials: false,
  860. expected_type: 'error',
  861. expected_redirected: false,
  862. request_init: {
  863. redirect: 'error',
  864. mode: 'no-cors'
  865. },
  866. // should reject because requests with 'error' RequestRedirect cannot be
  867. // redirected.
  868. should_reject: true
  869. });
  870. }, 'Non-navigation, error redirect, no-cors mode Request redirected to ' +
  871. 'cors without credentials should fail interception ' +
  872. 'and response should not be redirected');
  873. async_test(function(t) {
  874. redirect_fetch_test(t, {
  875. name: 'nonav-error-cors-redirects-to-sameorigin-creds',
  876. redirect_dest: 'same-origin',
  877. url_credentials: true,
  878. expected_type: 'error',
  879. expected_redirected: false,
  880. request_init: {
  881. redirect: 'error',
  882. mode: 'cors'
  883. },
  884. // should reject because requests with 'error' RequestRedirect cannot be
  885. // redirected.
  886. should_reject: true
  887. });
  888. }, 'Non-navigation, error redirect, cors mode Request redirected to ' +
  889. 'same-origin with credentials should fail interception ' +
  890. 'and response should not be redirected');
  891. async_test(function(t) {
  892. redirect_fetch_test(t, {
  893. name: 'nonav-error-cors-redirects-to-nocors-creds',
  894. redirect_dest: 'no-cors',
  895. url_credentials: true,
  896. expected_type: 'error',
  897. expected_redirected: false,
  898. request_init: {
  899. redirect: 'error',
  900. mode: 'cors'
  901. },
  902. // should reject because requests with 'error' RequestRedirect cannot be
  903. // redirected.
  904. should_reject: true
  905. });
  906. }, 'Non-navigation, error redirect, cors mode Request redirected to ' +
  907. 'no-cors with credentials should fail interception ' +
  908. 'and response should not be redirected');
  909. async_test(function(t) {
  910. redirect_fetch_test(t, {
  911. name: 'nonav-error-cors-redirects-to-cors-creds',
  912. redirect_dest: 'cors',
  913. url_credentials: true,
  914. expected_type: 'error',
  915. expected_redirected: false,
  916. request_init: {
  917. redirect: 'error',
  918. mode: 'cors'
  919. },
  920. // should reject because requests with 'error' RequestRedirect cannot be
  921. // redirected.
  922. should_reject: true
  923. });
  924. }, 'Non-navigation, error redirect, cors mode Request redirected to ' +
  925. 'cors with credentials should fail interception ' +
  926. 'and response should not be redirected');
  927. async_test(function(t) {
  928. redirect_fetch_test(t, {
  929. name: 'nonav-error-sameorigin-redirects-to-sameorigin-creds',
  930. redirect_dest: 'same-origin',
  931. url_credentials: true,
  932. expected_type: 'error',
  933. expected_redirected: false,
  934. request_init: {
  935. redirect: 'error',
  936. mode: 'same-origin'
  937. },
  938. // should reject because requests with 'error' RequestRedirect cannot be
  939. // redirected.
  940. should_reject: true
  941. });
  942. }, 'Non-navigation, error redirect, same-origin mode Request redirected to ' +
  943. 'same-origin with credentials should fail interception ' +
  944. 'and response should not be redirected');
  945. async_test(function(t) {
  946. redirect_fetch_test(t, {
  947. name: 'nonav-error-sameorigin-redirects-to-nocors-creds',
  948. redirect_dest: 'no-cors',
  949. url_credentials: true,
  950. expected_type: 'error',
  951. expected_redirected: false,
  952. request_init: {
  953. redirect: 'error',
  954. mode: 'same-origin'
  955. },
  956. // should reject because requests with 'error' RequestRedirect cannot be
  957. // redirected.
  958. should_reject: true
  959. });
  960. }, 'Non-navigation, error redirect, same-origin mode Request redirected to ' +
  961. 'no-cors with credentials should fail interception ' +
  962. 'and response should not be redirected');
  963. async_test(function(t) {
  964. redirect_fetch_test(t, {
  965. name: 'nonav-error-sameorigin-redirects-to-cors-creds',
  966. redirect_dest: 'cors',
  967. url_credentials: true,
  968. expected_type: 'error',
  969. expected_redirected: false,
  970. request_init: {
  971. redirect: 'error',
  972. mode: 'same-origin'
  973. },
  974. // should reject because requests with 'error' RequestRedirect cannot be
  975. // redirected.
  976. should_reject: true
  977. });
  978. }, 'Non-navigation, error redirect, same-origin mode Request redirected to ' +
  979. 'cors with credentials should fail interception ' +
  980. 'and response should not be redirected');
  981. async_test(function(t) {
  982. redirect_fetch_test(t, {
  983. name: 'nonav-error-nocors-redirects-to-sameorigin-creds',
  984. redirect_dest: 'same-origin',
  985. url_credentials: true,
  986. expected_type: 'error',
  987. expected_redirected: false,
  988. request_init: {
  989. redirect: 'error',
  990. mode: 'no-cors'
  991. },
  992. // should reject because requests with 'error' RequestRedirect cannot be
  993. // redirected.
  994. should_reject: true
  995. });
  996. }, 'Non-navigation, error redirect, no-cors mode Request redirected to ' +
  997. 'same-origin with credentials should fail interception ' +
  998. 'and response should not be redirected');
  999. async_test(function(t) {
  1000. redirect_fetch_test(t, {
  1001. name: 'nonav-error-nocors-redirects-to-nocors-creds',
  1002. redirect_dest: 'no-cors',
  1003. url_credentials: true,
  1004. expected_type: 'error',
  1005. expected_redirected: false,
  1006. request_init: {
  1007. redirect: 'error',
  1008. mode: 'no-cors'
  1009. },
  1010. // should reject because requests with 'error' RequestRedirect cannot be
  1011. // redirected.
  1012. should_reject: true
  1013. });
  1014. }, 'Non-navigation, error redirect, no-cors mode Request redirected to ' +
  1015. 'no-cors with credentials should fail interception ' +
  1016. 'and response should not be redirected');
  1017. async_test(function(t) {
  1018. redirect_fetch_test(t, {
  1019. name: 'nonav-error-nocors-redirects-to-cors-creds',
  1020. redirect_dest: 'cors',
  1021. url_credentials: true,
  1022. expected_type: 'error',
  1023. expected_redirected: false,
  1024. request_init: {
  1025. redirect: 'error',
  1026. mode: 'no-cors'
  1027. },
  1028. // should reject because requests with 'error' RequestRedirect cannot be
  1029. // redirected.
  1030. should_reject: true
  1031. });
  1032. }, 'Non-navigation, error redirect, no-cors mode Request redirected to ' +
  1033. 'cors with credentials should fail interception and response should not ' +
  1034. 'be redirected');
  1035. </script>
  1036. </body>