basic-shared-worker.html (2726B)
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 var t5 = async_test("Shared worker from data URL"); 18 // Tests for SharedWorkers used from other workers (not supported right 19 // now) would go here. 20 21 t1.step(function() { 22 var w = new SharedWorker("support/shared-worker-script.js"); 23 w.port.onmessage = t1.step_func_done(function(e) { 24 assert_false(e.data); 25 }); 26 w.port.start(); 27 }); 28 29 t2.step(function() { 30 var w = new SharedWorker("support/parent-shared-worker-script.js"); 31 w.port.onmessage = t2.step_func_done(function(e) { 32 assert_false(e.data); 33 }); 34 w.port.start(); 35 }); 36 37 onmessage = function(e) { 38 var data = e.data; 39 if (data.type == "shared") { 40 t3.step(function() { 41 assert_false(data.exception); 42 assert_false(data.error); 43 assert_false(data.isSecureContext); 44 }); 45 t3.done(); 46 } else if (data.type == "nested") { 47 t4.step(function() { 48 assert_false(data.exception); 49 assert_false(data.error); 50 assert_false(data.isSecureContext); 51 }); 52 t4.done(); 53 } else { 54 t3.step(function() { 55 assert_unreached("Unknown message"); 56 }); 57 t3.done(); 58 t4.step(function() { 59 assert_unreached("Unknown message"); 60 }); 61 t4.done(); 62 } 63 } 64 65 var ifr = document.createElement("iframe"); 66 ifr.src = https_dir2 + "support/https-subframe-shared.html"; 67 document.body.appendChild(ifr); 68 69 t5.step(function() { 70 var w = new SharedWorker( 71 `data:text/javascript,addEventListener("connect", function (e) { 72 var port = e.ports[0]; 73 port.start(); 74 port.postMessage(isSecureContext); 75 });` 76 ); 77 w.port.onmessage = t5.step_func_done(function(e) { 78 assert_false(e.data); 79 }); 80 w.port.start(); 81 }); 82 </script> 83 </body> 84 </html>