summaryrefslogtreecommitdiffstats
path: root/dom/websocket/tests/test_websocket_mixed_content_opener.html
blob: 3d2f8d3b3e36482ddcc1fd2fb8e3c723fe622946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!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",
    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html",
    expect: "WS onopen",
  });

  await runTest({
    name: "testInsecureWindowWSS",
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html",
    expect: "WS onopen",
  });

  // ws://URI cannot be used when loaded over https
  await runTest({
    name: "testSecureWindowWS",
    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure",
    expect: "SecurityError",
  });

  await runTest({
    name: "testInsecureWindowWS",
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure",
    expect: "WS onopen",
  });

  // ws://URI cannot be used when loaded over https
  await runTest({
    name: "testUpgradedWindowWS",
    httpsFirst: true,
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure",
    expect: "SecurityError",
  });

  await runTest({
    name: "testSecureWindowSecureIframeWSS",
    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss",
    expect: "WS onopen",
  });

  // ws://URI cannot be used when loaded over https
  await runTest({
    name: "testSecureWindowSecureIframeWS",
    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws",
    expect: "SecurityError",
  });

  // http iframe cannot be loaded in secure context (mixed content)
  await runTest({
    name: "testSecureWindowInsecureIframeWSS",
    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss",
    expect: "Error - iframe not loaded",
  });

  // http iframe cannot be loaded in secure context (mixed content)
  await runTest({
    name: "testSecureWindowInsecureIframeWS",
    url: "https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws",
    expect: "Error - iframe not loaded",
  });

  await runTest({
    name: "testInsecureWindowSecureIframeWSS",
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss",
    expect: "WS onopen",
  });

  // ws://URI cannot be used when loaded from an https iframe
  await runTest({
    name: "testInsecureWindowSecureIframeWS",
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws",
    expect: "SecurityError",
  });

  await runTest({
    name: "testInsecureWindowInsecureIframeWSS",
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss",
    expect: "WS onopen",
  });

  await runTest({
    name: "testInsecureWindowInsecureIframeWS",
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws",
    expect: "WS onopen",
  });

  await runTest({
    name: "testUpgradedWindowSecureIframeWSS",
    httpsFirst: true,
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss",
    expect: "WS onopen",
  });

  // ws://URI cannot be used when loaded from an https iframe
  await runTest({
    name: "testUpgradedWindowSecureIframeWS",
    httpsFirst: true,
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws",
    expect: "SecurityError",
  });

  // http iframe cannot be loaded in secure context (mixed content)
  await runTest({
    name: "testUpgradedWindowInsecureIframeWSS",
    httpsFirst: true,
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss",
    expect: "Error - iframe not loaded",
  });

  // http iframe cannot be loaded in secure context (mixed content)
  await runTest({
    name: "testUpgradedWindowInsecureIframeWS",
    httpsFirst: true,
    url: "http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws",
    expect: "Error - iframe not loaded",
  });

  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
testWebSockets();
</script>
</body>
</html>