summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/websockets/resources/websockets-test-helpers.sub.js
blob: 2680670cc691b14c25721d2dd474a2a4c15bac3f (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
// The file including this must also include `/websockets/constants.sub.js to
// pick up the necessary constants.

// Opens a new WebSocket connection.
async function openWebSocket(remoteContextHelper) {
  let return_value = await remoteContextHelper.executeScript((domain) => {
    return new Promise((resolve) => {
      var webSocketInNotRestoredReasonsTests = new WebSocket(domain + '/echo');
      webSocketInNotRestoredReasonsTests.onopen = () => { resolve(42); };
    });
  }, [SCHEME_DOMAIN_PORT]);
  assert_equals(return_value, 42);
}

// Opens a new WebSocket connection and then close it.
async function openThenCloseWebSocket(remoteContextHelper) {
  let return_value = await remoteContextHelper.executeScript((domain) => {
    return new Promise((resolve) => {
      var testWebSocket = new WebSocket(domain + '/echo');
      testWebSocket.onopen = () => { testWebSocket.close() };
      testWebSocket.onclose = () => { resolve(42) };
    });
  }, [SCHEME_DOMAIN_PORT]);
  assert_equals(return_value, 42);
}