Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / security / script-crossorigin-redirect-no-cors.html
1 <!DOCTYPE HTML>
2 <script src="/js-test-resources/js-test.js"></script>
3 <script>
4 description("Testing the handling of CORS-enabled <script> fetch in the presence of 'No CORS' redirects.");
5
6 // Explain the short form descriptions ('=>' representing the redirect.)
7 debug("PASS/FAIL descriptions are of the form, 'CORS request type': 'redirect CORS type' => 'resource'");
8 debug("");
9
10 var redirect_cors = "no";
11
12 window.jsTestIsAsync = true;
13 if (window.testRunner)
14     testRunner.dumpAsText();
15
16 function finish() {
17     if (window.testRunner)
18         finishJSTest();
19 }
20
21 function fail() {
22     debug("FAIL: " + this.description);
23     runNextTest();
24 }
25
26 function pass() {
27     debug("PASS: " + this.description);
28     runNextTest();
29 }
30
31 // All redirects are non-CORS, no fetches expected to complete.
32 var tests = [
33     { description: "Anonymous request: no-CORS => no-CORS script resource.",
34       url: "http://localhost:8000/security/resources/localScript.js",
35       success: false,
36       access: "anonymous"},
37     { description: "Anonymous request: no-CORS => anonymous-CORS script resource.",
38       url: "http://localhost:8000/security/resources/script-allow-star.php",
39       success: false,
40       access: "anonymous"},
41     { description: "Credentialled request: no-CORS => credential-CORS script resource (same origin.)",
42       url: "http://localhost:8000/security/resources/script-allow-credentials.php",
43       success: false,
44       access: "use-credentials"},
45     { description: "Credentialled request: no-CORS => credential-CORS script resource (cross origin.)",
46       url: "http://127.0.0.1:8000/security/resources/script-allow-credentials.php",
47       success: false,
48       access: "use-credentials"},
49     ];
50
51 function runNextTest() {
52     if (!tests.length) {
53         finish();
54         return;
55     }
56     var test = tests.shift();
57     var script = document.createElement("script");
58     script.onload = test.success ? pass : fail;
59     script.onerror = test.success ? fail : pass;
60     script.crossOrigin = test.access;
61     script.description = test.description;
62     var args = [ "mode=" + redirect_cors,
63                  "url=" + test.url];
64     script.src = "http://localhost:8000/security/resources/cors-redirect.php?" + args.join("&");
65     document.body.appendChild(script);
66 }
67 window.onload = runNextTest;
68 </script>