Implement dynamic-import for WebCore
[WebKit-https.git] / LayoutTests / http / tests / security / contentSecurityPolicy / 1.1 / import-scriptnonce.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <meta http-equiv="Content-Security-Policy" content="script-src 'nonce-noncynonce' 'nonce-noncy+/=nonce'">
5     </head>
6     <body>
7         <script nonce="noncynonce">
8         if (window.testRunner) {
9             testRunner.dumpAsText();
10             testRunner.waitUntilDone();
11         }
12
13         var modules = new Set([
14             'allow1',
15             'allow2',
16             'allow3',
17         ]);
18
19         var array = [];
20         var count = 0;
21         function ok(num)
22         {
23             // load should be done for module tags before calling the result of import.
24             if (modules.has(`allow${num}`))
25                 error(num);
26             array.push(num);
27             if (array.length === 6) {
28                 alert(array.sort().toString());
29                 done("PASS");
30             }
31         }
32
33         document.body.addEventListener('load', function (ev) {
34             let id = ev.target.id;
35             if (modules.has(id))
36                 modules.delete(id);
37             else if (id)
38                 error(id);
39         }, /* capture */ true);
40
41         document.body.addEventListener('error', function (ev) {
42             error(ev.target.id);
43         }, /* capture */ true);
44
45
46         function error(num)
47         {
48             alert(`FAIL (${num})`);
49         }
50
51         function done(msg) {
52             document.querySelector("pre").innerHTML = msg;
53             if (window.testRunner)
54                 testRunner.notifyDone();
55         }
56         </script>
57
58         <script type="module" nonce="noncynonce" id="allow1">
59             import("./resources/import-scriptnonce-allowed1.js");
60         </script>
61         <script type="module" nonce="noncynonce noncynonce" id="block1">
62             import("./resources/import-scriptnonce-blocked1.js");
63         </script>
64         <script type="module" nonce="noncynonce" id="allow2">
65             import("./resources/import-scriptnonce-allowed2.js");
66         </script>
67         <script type="module" id="block2">
68             import("./resources/import-scriptnonce-blocked2.js");
69         </script>
70         <script type="module" nonce="noncy+/=nonce" id="allow3">
71             import("./resources/import-scriptnonce-allowed3.js");
72         </script>
73         <script type="module" nonce="noncynonceno?" id="block3">
74             import("./resources/import-scriptnonce-blocked3.js");
75         </script>
76         <script nonce="noncynonce" id="allow4">
77             import("./resources/import-scriptnonce-allowed4.js");
78         </script>
79         <script nonce="noncynonce noncynonce" id="block4">
80             import("./resources/import-scriptnonce-blocked4.js");
81         </script>
82         <script nonce="noncynonce" id="allow5">
83             import("./resources/import-scriptnonce-allowed5.js");
84         </script>
85         <script id="block5">
86             import("./resources/import-scriptnonce-blocked5.js");
87         </script>
88         <script nonce="noncy+/=nonce" id="allow6">
89             import("./resources/import-scriptnonce-allowed6.js");
90         </script>
91         <script nonce="noncynonceno?" id="block6">
92             import("./resources/import-scriptnonce-blocked6.js");
93         </script>
94         <p>
95             This tests the effect of a script-nonce value.
96         </p>
97         <pre></pre>
98     </body>
99 </html>