OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta http-equiv="Content-Security-Policy" content="connect-src 'self'"> |
| 3 <script src="/resources/testharness.js"></script> |
| 4 <script src="/resources/testharnessreport.js"></script> |
| 5 <script> |
| 6 async_test(t => { |
| 7 var errorEvent = false; |
| 8 var cspEvent = false; |
| 9 |
| 10 var ws = new WebSocket("ws://{{domains[www]}}:{{ports[ws][0]}}/echo"); |
| 11 ws.onopen = t.unreached_func("open should not fire."); |
| 12 ws.onerror = t.step_func(e => { |
| 13 assert_equals(ws.readyState, WebSocket.CLOSED); |
| 14 |
| 15 assert_false(errorEvent); |
| 16 errorEvent = true; |
| 17 if (cspEvent) |
| 18 t.done(); |
| 19 }); |
| 20 |
| 21 document.addEventListener("securitypolicyviolation", t.step_func(e => { |
| 22 if (e.blockedURI != "ws://{{domains[www]}}:{{ports[ws][0]}}") |
| 23 return; |
| 24 |
| 25 assert_equals(ws.readyState, WebSocket.CLOSED); |
| 26 assert_equals(e.violatedDirective, "connect-src"); |
| 27 |
| 28 assert_false(cspEvent); |
| 29 cspEvent = true; |
| 30 if (errorEvent) |
| 31 t.done(); |
| 32 })); |
| 33 }, "WebSocket should fire error event."); |
| 34 </script> |
OLD | NEW |