fetch redirect is incompatible with "no-cors" 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     <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 promise_rejects(test,new TypeError(), fetch(preloadUrl, {redirect: "manual", mode: "no-cors", credentials: "include"}));
20     }, "Fetch should check for redirections even if resource is preloaded (same fetch options except for redirect mode)");
21
22     promise_test(function(test) {
23         return fetch(preloadUrl, {redirect: "manual", mode: "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 (different fetch mode, different redirect mode)");
30
31     promise_test(function(test) {
32         return promise_rejects(test, new TypeError(), fetch(preloadUrl, {redirect: "error", mode: "no-cors", credentials: "include"}));
33     }, "Fetch should check for redirections even if resource is preloaded (same fetch options except for redirect mode)");
34
35     promise_test(function(test) {
36         return promise_rejects(test, new TypeError(), fetch(preloadUrl, {redirect: "error", mode: "cors", credentials: "include"}));
37     }, "Fetch should check for redirections even if resource is preloaded (different fetch mode, different redirect mode)");
38 }
39     </script>
40   </body>
41 </html>