summaryrefslogtreecommitdiffstats
path: root/dom/websocket/tests/test_websocket_mixed_content.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/websocket/tests/test_websocket_mixed_content.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/websocket/tests/test_websocket_mixed_content.html')
-rw-r--r--dom/websocket/tests/test_websocket_mixed_content.html96
1 files changed, 96 insertions, 0 deletions
diff --git a/dom/websocket/tests/test_websocket_mixed_content.html b/dom/websocket/tests/test_websocket_mixed_content.html
new file mode 100644
index 0000000000..bc2ac40188
--- /dev/null
+++ b/dom/websocket/tests/test_websocket_mixed_content.html
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
+ <title>WebSocket mixed content tests - load secure and insecure websockets</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+
+ <script type="text/javascript" src="websocket_helpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<div id="container"></div>
+<iframe id="frame" sandbox="allow-scripts"></iframe>
+<script class="testbody" type="text/javascript">
+
+let iFrameTests = [testWebSocketSecure, testWebSocketInsecure, testSameOriginSandboxInsecure, testSameOriginSandboxSecure, testCrossOriginSandboxInsecure, testCrossOriginSandboxSecure];
+
+function nextIFrameTest() {
+ if(!iFrameTests.length) {
+ document.getElementById("frame").removeAttribute("src");
+ document.getElementById("frame").remove();
+ SimpleTest.finish();
+ }
+ else {
+ let test = iFrameTests.shift();
+ test();
+ }
+}
+
+function testWebSockets () {
+ nextIFrameTest();
+}
+
+function testWebSocketSecure () {
+ let ws = CreateTestWS("wss://example.com/tests/dom/websocket/tests/file_websocket_hello");
+ ws.onopen = function(e) {
+ ws.send("data");
+ }
+ ws.onmessage = function(e) {
+ is(e.data, "Hello world!", "Wrong data");
+ ws.close();
+ nextIFrameTest();
+ }
+}
+
+// Negative test: this should fail as the page was loaded over https
+function testWebSocketInsecure () {
+ try {
+ let ws = new WebSocket("ws://mochi.test:8888/tests/dom/websocket/tests/file_websocket_hello");
+ ok(false, "Should throw DOMException");
+ } catch (e) {
+ ok(e instanceof DOMException, "DOMException thrown ");
+ nextIFrameTest();
+ }
+}
+
+// Negative test: this should fail as the page was loaded over https
+function testSameOriginSandboxInsecure() {
+ document.getElementById("frame").src = "https://example.com/tests/dom/websocket/tests/iframe_websocket_wss.html?insecure";
+ onmessage = function(e) {
+ is(e.data, "SecurityError", "ws://URI cannot be used when loaded over https");
+ nextIFrameTest();
+ }
+}
+
+function testSameOriginSandboxSecure() {
+ document.getElementById("frame").src = "https://example.com/tests/dom/websocket/tests/iframe_websocket_wss.html"
+ onmessage = function(e) {
+ is(e.data, "WS onopen", "wss://URI opened");
+ nextIFrameTest();
+ }
+}
+
+// Negative test: this should fail as the page was loaded over https
+function testCrossOriginSandboxInsecure() {
+ document.getElementById("frame").src = "https://example.org/tests/dom/websocket/tests/iframe_websocket_wss.html?insecure";
+ onmessage = function(e) {
+ is(e.data, "SecurityError", "ws://URI cannot be used when loaded over https");
+ nextIFrameTest();
+ }
+}
+
+function testCrossOriginSandboxSecure() {
+ document.getElementById("frame").src = "https://example.org/tests/dom/websocket/tests/iframe_websocket_wss.html"
+
+ onmessage = function(e) {
+ is(e.data, "WS onopen", "wss://URI opened");
+ nextIFrameTest();
+ }
+}
+
+SimpleTest.waitForExplicitFinish();
+testWebSockets();
+</script>
+</body>
+</html>