Implement W3C Secure Contexts Draft Specification
[WebKit.git] / LayoutTests / imported / w3c / web-platform-tests / secure-contexts / basic-shared-worker.https.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset=utf-8>
5     <title>Test SharedWorkerGlobalScope.isSecureContext for HTTP creator</title>
6     <meta name="help" href="https://w3c.github.io/webappsec-secure-contexts/#monkey-patching-global-object">
7     <script src=/resources/testharness.js></script>
8     <script src=/resources/testharnessreport.js></script>
9     <script src="server-locations.sub.js"></script>
10   </head>
11   <body>
12     <script>
13       var t1 = async_test("Shared worker");
14       var t2 = async_test("Nested worker in shared worker");
15       var t3 = async_test("Shared worker from https subframe");
16       var t4 = async_test("Nested worker from shared worker from https subframe");
17
18       t1.step(function() {
19         var w = new SharedWorker("support/shared-worker-script.js");
20         w.port.onmessage = t1.step_func_done(function(e) {
21           assert_true(e.data);
22         });
23         w.port.start();
24       });
25
26       t2.step(function() {
27         var w = new SharedWorker("support/parent-shared-worker-script.js");
28         w.port.onmessage = t2.step_func_done(function(e) {
29           assert_true(e.data);
30         });
31         w.port.start();
32       });
33
34       onmessage = function(e) {
35         var data = e.data;
36         if (data.type == "shared") {
37           t3.step(function() {
38             assert_false(data.exception);
39             assert_false(data.error);
40             assert_true(data.isSecureContext);
41           });
42           t3.done();
43         } else if (data.type == "nested") {
44           t4.step(function() {
45             assert_false(data.exception);
46             assert_false(data.error);
47             assert_true(data.isSecureContext);
48           });
49           t4.done();
50         } else {
51           t3.step(function() {
52             assert_unreached("Unknown message");
53           });
54           t3.done();
55           t4.step(function() {
56             assert_unreached("Unknown message");
57           });
58           t4.done();
59         }
60       }
61
62       var ifr = document.createElement("iframe");
63       ifr.src = https_dir3 + "support/https-subframe-shared.html";
64       document.body.appendChild(ifr);
65     </script>
66   </body>
67 </html>