b0b1dd600cf2fde72c74fd93eb379be622cd7b51
[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     <link rel=preload as=fetch 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">
12   </head>
13   <body>
14     <script>
15 function startTests()
16 {
17     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";
18     promise_test(function(test) {
19         return fetch(preloadUrl, {redirect: "manual", mode: "no-cors", credentials: "include"}).then((response) => {
20             assert_equals(response.type, "opaqueredirect", "Response's type should be opaqueRedirect");
21             return response.text();
22         }).then((text) => {
23             assert_equals(text, "");
24         });
25     }, "Fetch should check for redirections even if resource is preloaded (same fetch options except for redirect mode)");
26
27     promise_test(function(test) {
28         return fetch(preloadUrl, {redirect: "manual", mode: "cors", credentials: "include"}).then((response) => {
29             assert_equals(response.type, "opaqueredirect", "Response's type should be opaqueRedirect");
30             return response.text();
31         }).then((text) => {
32             assert_equals(text, "");
33         });
34     }, "Fetch should check for redirections even if resource is preloaded (different fetch mode, different redirect mode)");
35
36     promise_test(function(test) {
37         return promise_rejects(test, new TypeError(), fetch(preloadUrl, {redirect: "error", mode: "no-cors", credentials: "include"}));
38     }, "Fetch should check for redirections even if resource is preloaded (same fetch options except for redirect mode)");
39
40     promise_test(function(test) {
41         return promise_rejects(test, new TypeError(), fetch(preloadUrl, {redirect: "error", mode: "cors", credentials: "include"}));
42     }, "Fetch should check for redirections even if resource is preloaded (different fetch mode, different redirect mode)");
43 }
44     </script>
45   </body>
46 </html>