summaryrefslogtreecommitdiffstats
path: root/dom/websocket/tests/iframe_websocket_wss.html
blob: 71945a30d9f292debc9e0b34933c13b97772d70a (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
<html><body>
Creating WebSocket
<script type="application/javascript">
onmessage = function(e) {
  parent.postMessage(e.data, '*');
}

try{
    let socket;
    if (location.search == '?insecure') {
      socket = new WebSocket('ws://mochi.test:8888/tests/dom/websocket/tests/file_websocket_hello');
    }
    else {
      socket = new WebSocket('wss://example.com/tests/dom/websocket/tests/file_websocket_hello');
    }
    socket.onerror = function(e) {
      parent.postMessage('WS onerror', '*');
      close();
    };
    socket.onopen = function(event) {
      socket.close();
      parent.postMessage('WS onopen', '*');
      close();
    };
  } catch(e) {
    if (e.name == 'SecurityError') {
      parent.postMessage('SecurityError', '*');
    } else {
      parent.postMessage('WS Throws something else!', '*');
    }
    close();
  }

</script>
</body></html>