summaryrefslogtreecommitdiffstats
path: root/dom/websocket/tests/test_websocket_mixed_content_opener.html
blob: 7db0325825da6ee3605c77b58223134890990dad (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
<!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">

let tests = [ testSecureWindowWSS, testSecureWindowWS, testInsecureWindowWSS, testInsecureWindowWS,
              testSecureWindowSecureIframeWSS, testSecureWindowSecureIframeWS, testSecureWindowInsecureIframeWSS, testSecureWindowInsecureIframeWS,
              testInsecureWindowSecureIframeWSS, testInsecureWindowSecureIframeWS, testInsecureWindowInsecureIframeWSS, testInsecureWindowInsecureIframeWS]

function nextTest() {
  if(!tests.length) {
    SimpleTest.finish();
  }
  else {
    let test = tests.shift();
    test();
  }
}

function testWebSockets () {
  SimpleTest.waitForExplicitFinish();
  nextTest();
}

function cleanupAndLaunchNextTest(win) {
    win.close();
    nextTest();
}

function testSecureWindowWSS() {
  let win = window.open("https://example.com/tests/dom/websocket/tests/window_websocket_wss.html", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "WS onopen", "wss://URI opened");
    cleanupAndLaunchNextTest(win);
   }
}

function testSecureWindowWS() {
  let win = window.open("https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "SecurityError", "ws://URI cannot be used when loaded over https");
    cleanupAndLaunchNextTest(win);
  }
}

function testInsecureWindowWSS() {
    let win = window.open("http://example.com/tests/dom/websocket/tests/window_websocket_wss.html", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
    onmessage = function(e) {
      is(e.data, "WS onopen", "wss://URI opened");
      cleanupAndLaunchNextTest(win);
    }
}

function testInsecureWindowWS() {
  let win = window.open("http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?insecure", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "WS onopen", "ws://URI opened");
    cleanupAndLaunchNextTest(win);
  }
}

function testSecureWindowSecureIframeWSS() {
  let win = window.open("https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "WS onopen", "ws://URI opened");
    cleanupAndLaunchNextTest(win);
  }
}

function testSecureWindowSecureIframeWS() {
  let win = window.open("https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "SecurityError", "ws://URI cannot be used when loaded over https");
    cleanupAndLaunchNextTest(win);
  }
}

function testSecureWindowInsecureIframeWSS() {
  let win = window.open("https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "Error - iframe not loaded", "http iframe cannot be loaded in secure context (mixed content)");
    cleanupAndLaunchNextTest(win);
  }
}

function testSecureWindowInsecureIframeWS() {
  let win = window.open("https://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "Error - iframe not loaded", "http iframe cannot be loaded in secure context (mixed content)");
    cleanupAndLaunchNextTest(win);
  }
}

function testInsecureWindowSecureIframeWSS() {
  let win = window.open("http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_wss", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "WS onopen", "ws://URI opened");
    cleanupAndLaunchNextTest(win);
  }
}

function testInsecureWindowSecureIframeWS() {
  let win = window.open("http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?https_iframe_ws", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "SecurityError", "ws://URI cannot be used when loaded from an https iframe");
    cleanupAndLaunchNextTest(win);
  }
}

function testInsecureWindowInsecureIframeWSS() {
  let win = window.open("http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_wss", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "WS onopen", "ws://URI opened");
    cleanupAndLaunchNextTest(win);
  }
}

function testInsecureWindowInsecureIframeWS() {
  let win = window.open("http://example.com/tests/dom/websocket/tests/window_websocket_wss.html?http_iframe_ws", '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
  onmessage = function(e) {
    is(e.data, "WS onopen", "ws://URI opened");
    cleanupAndLaunchNextTest(win);
  }
}

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