4 <meta http-equiv=
"Content-Type" content=
"text/html;charset=UTF-8"></meta>
5 <title>WebSocket mixed content tests - load secure and insecure websockets
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
8 <script type=
"text/javascript" src=
"websocket_helpers.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
12 <div id=
"container"></div>
13 <iframe id=
"frame" sandbox=
"allow-scripts"></iframe>
14 <script class=
"testbody" type=
"text/javascript">
16 let iFrameTests = [testWebSocketSecure, testWebSocketInsecure, testWebSocketInsecureDataURI, testSameOriginSandboxInsecure, testSameOriginSandboxSecure, testCrossOriginSandboxInsecure, testCrossOriginSandboxSecure];
18 function nextIFrameTest() {
19 if(!iFrameTests.length) {
20 document.getElementById(
"frame").removeAttribute(
"src");
21 document.getElementById(
"frame").remove();
25 let test = iFrameTests.shift();
30 function testWebSockets () {
34 function testWebSocketSecure () {
35 let ws = CreateTestWS(
"wss://example.com/tests/dom/websocket/tests/file_websocket_hello");
36 ws.onopen = function(e) {
39 ws.onmessage = function(e) {
40 is(e.data,
"Hello world!",
"Wrong data");
46 // Negative test: this should fail as the page was loaded over https
47 function testWebSocketInsecure () {
49 let ws = new WebSocket(
"ws://mochi.test:8888/tests/dom/websocket/tests/file_websocket_hello");
50 ok(false,
"Should throw DOMException");
52 ok(e instanceof DOMException,
"DOMException thrown ");
57 // Negative test: this should fail as the page was loaded over https
58 function testWebSocketInsecureDataURI() {
59 document.getElementById(
"frame").src =
"https://example.com/tests/dom/websocket/tests/iframe_webworker_wss.html";
60 onmessage = function(e) {
61 is(e.data,
"SecurityError: The operation is insecure.",
"SecurityError received");
66 // Negative test: this should fail as the page was loaded over https
67 function testSameOriginSandboxInsecure() {
68 document.getElementById(
"frame").src =
"https://example.com/tests/dom/websocket/tests/iframe_websocket_wss.html?insecure";
69 onmessage = function(e) {
70 is(e.data,
"SecurityError",
"ws://URI cannot be used when loaded over https");
75 function testSameOriginSandboxSecure() {
76 document.getElementById(
"frame").src =
"https://example.com/tests/dom/websocket/tests/iframe_websocket_wss.html"
77 onmessage = function(e) {
78 is(e.data,
"WS onopen",
"wss://URI opened");
83 // Negative test: this should fail as the page was loaded over https
84 function testCrossOriginSandboxInsecure() {
85 document.getElementById(
"frame").src =
"https://example.org/tests/dom/websocket/tests/iframe_websocket_wss.html?insecure";
86 onmessage = function(e) {
87 is(e.data,
"SecurityError",
"ws://URI cannot be used when loaded over https");
92 function testCrossOriginSandboxSecure() {
93 document.getElementById(
"frame").src =
"https://example.org/tests/dom/websocket/tests/iframe_websocket_wss.html"
95 onmessage = function(e) {
96 is(e.data,
"WS onopen",
"wss://URI opened");
101 SimpleTest.waitForExplicitFinish();