connect_check.html 1009 B

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