Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: http3 OR http2 OR os == 'android'
- Manifest: dom/websocket/tests/mochitest.toml
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
<title>WebSocket mixed content opener tests - load secure and insecure websockets in secure and insecure iframes through secure and insecure opened windows</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>
<script class="testbody" type="text/javascript">
function runTest({ name, url, expect, httpsFirst = false }) {
return new Promise((resolve) => {
SpecialPowers.pushPrefEnv({
set: [["dom.security.https_first", httpsFirst]],
}).then(() => {
let win = window.open(
url,
"_blank",
"location=yes,height=570,width=520,scrollbars=yes,status=yes"
);
onmessage = function (e) {
is(e.data, expect, `${name} - Unexpected message`);
win.close();
SpecialPowers.flushPrefEnv().then(() => {
resolve();
});
};
});
});
}
async function testWebSockets() {
await runTest({
name: "testSecureWindowWSS",
expect: "WS onopen",
});
await runTest({
name: "testInsecureWindowWSS",
expect: "WS onopen",
});
await runTest({
name: "testSecureWindowWS",
expect: "SecurityError",
});
await runTest({
name: "testInsecureWindowWS",
expect: "WS onopen",
});
await runTest({
name: "testUpgradedWindowWS",
httpsFirst: true,
expect: "SecurityError",
});
await runTest({
name: "testSecureWindowSecureIframeWSS",
expect: "WS onopen",
});
await runTest({
name: "testSecureWindowSecureIframeWS",
expect: "SecurityError",
});
// http iframe cannot be loaded in secure context (mixed content)
await runTest({
name: "testSecureWindowInsecureIframeWSS",
expect: "Error - iframe not loaded",
});
// http iframe cannot be loaded in secure context (mixed content)
await runTest({
name: "testSecureWindowInsecureIframeWS",
expect: "Error - iframe not loaded",
});
await runTest({
name: "testInsecureWindowSecureIframeWSS",
expect: "WS onopen",
});
await runTest({
name: "testInsecureWindowSecureIframeWS",
expect: "SecurityError",
});
await runTest({
name: "testInsecureWindowInsecureIframeWSS",
expect: "WS onopen",
});
await runTest({
name: "testInsecureWindowInsecureIframeWS",
expect: "WS onopen",
});
await runTest({
name: "testUpgradedWindowSecureIframeWSS",
httpsFirst: true,
expect: "WS onopen",
});
await runTest({
name: "testUpgradedWindowSecureIframeWS",
httpsFirst: true,
expect: "SecurityError",
});
// http iframe cannot be loaded in secure context (mixed content)
await runTest({
name: "testUpgradedWindowInsecureIframeWSS",
httpsFirst: true,
expect: "Error - iframe not loaded",
});
// http iframe cannot be loaded in secure context (mixed content)
await runTest({
name: "testUpgradedWindowInsecureIframeWS",
httpsFirst: true,
expect: "Error - iframe not loaded",
});
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
testWebSockets();
</script>
</body>
</html>