xref: /aosp_15_r20/external/cronet/net/data/websocket/connect_check.html (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1<!DOCTYPE html>
2<html>
3<head>
4<title>test ws connection</title>
5<script type="text/javascript">
6
7var pageConnection = new Promise((resolve, reject) => {
8  var protocol = location.protocol.replace('http', 'ws');
9  var url = protocol + '//' + location.host + '/echo-with-no-extension';
10  var ws = new WebSocket(url);
11
12  ws.onopen = resolve;
13  ws.onclose = reject;
14});
15
16var workerConnection = new Promise((resolve, reject) => {
17  let worker = new Worker('./connect_check_worker.js');
18  worker.onmessage = event => {
19    if (event.data === 'PASS') {
20      resolve();
21    } else if (event.data === 'FAIL') {
22      reject();
23    }
24  };
25  worker.onerror = reject;
26
27  // Start the worker.
28  worker.postMessage('');
29});
30
31Promise.all([pageConnection, workerConnection]).then(() => {
32  // Set document title to 'PASS'. The test observer catches this title changes
33  // to know the result.
34  document.title = 'PASS';
35}, () => {
36  // Set document title to 'FAIL'.
37  document.title = 'FAIL';
38});
39
40</script>
41</head>
42</html>
43