[Fetch API] Memory cache should not bypass redirect mode
[WebKit-https.git] / LayoutTests / http / tests / fetch / redirectmode-and-preload.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>Fetch: retrieve response's body progressively</title>
6     <meta name="help" href="https://fetch.spec.whatwg.org/#main-fetch">
7     <meta name="help" href="https://fetch.spec.whatwg.org/#http-fetch">
8     <meta name="author" title="Canon Research France" href="https://www.crf.canon.fr">
9     <script src="/js-test-resources/testharness.js"></script>
10     <script src="/js-test-resources/testharnessreport.js"></script>
11     <script>
12 if (window.internals)
13     internals.setLinkPreloadSupport(true);
14     </script>
15     <link rel=preload onload="startTests()" href="./resources/redirect-with-cache.php?enableCaching&url=http://localhost:8000/security/resources/allow-if-origin.php?allowCache&origin=http%3A%2F%2F127.0.0.1%3A8000&name=alert-fail.js&contentType=text/ascii">
16   </head>
17   <body>
18     <script>
19 function startTests()
20 {
21     var preloadUrl = "./resources/redirect-with-cache.php?enableCaching&url=http://localhost:8000/security/resources/allow-if-origin.php?allowCache&origin=http%3A%2F%2F127.0.0.1%3A8000&name=alert-fail.js&contentType=text/ascii";
22     promise_test(function(test) {
23         return fetch(preloadUrl, {redirect: "manual", mode: "no-cors", credentials: "include"}).then((response) => {
24             assert_equals(response.type, "opaqueredirect", "Response's type should be opaqueRedirect");
25             return response.text();
26         }).then((text) => {
27             assert_equals(text, "");
28         });
29     }, "Fetch should check for redirections even if resource is preloaded (same fetch options except for redirect mode)");
30
31     promise_test(function(test) {
32         return fetch(preloadUrl, {redirect: "manual", mode: "cors", credentials: "include"}).then((response) => {
33             assert_equals(response.type, "opaqueredirect", "Response's type should be opaqueRedirect");
34             return response.text();
35         }).then((text) => {
36             assert_equals(text, "");
37         });
38     }, "Fetch should check for redirections even if resource is preloaded (different fetch mode, different redirect mode)");
39
40     promise_test(function(test) {
41         return promise_rejects(test, new TypeError(), fetch(preloadUrl, {redirect: "error", mode: "no-cors", credentials: "include"}));
42     }, "Fetch should check for redirections even if resource is preloaded (same fetch options except for redirect mode)");
43
44     promise_test(function(test) {
45         return promise_rejects(test, new TypeError(), fetch(preloadUrl, {redirect: "error", mode: "cors", credentials: "include"}));
46     }, "Fetch should check for redirections even if resource is preloaded (different fetch mode, different redirect mode)");
47 }
48     </script>
49   </body>
50 </html>