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 es = new EventSource("http://{{domains[www]}}:{{ports[http][0]}}/commo
n/text-plain.txt"); |
| 11 es.onerror = t.step_func(e => { |
| 12 assert_equals(es.readyState, EventSource.CLOSED); |
| 13 |
| 14 assert_false(errorEvent); |
| 15 errorEvent = true; |
| 16 if (cspEvent) |
| 17 t.done(); |
| 18 }); |
| 19 |
| 20 document.addEventListener("securitypolicyviolation", t.step_func(e => { |
| 21 if (e.blockedURI != "http://{{domains[www]}}:{{ports[http][0]}}/common/t
ext-plain.txt") |
| 22 return; |
| 23 |
| 24 assert_equals(es.readyState, EventSource.CLOSED); |
| 25 assert_equals(e.violatedDirective, "connect-src"); |
| 26 |
| 27 assert_false(cspEvent); |
| 28 cspEvent = true; |
| 29 if (errorEvent) |
| 30 t.done(); |
| 31 })); |
| 32 }, "EventSource should fire onerror."); |
| 33 |
| 34 async_test(t => { |
| 35 var errorEvent = false; |
| 36 var cspEvent = false; |
| 37 |
| 38 var es = new EventSource("/common/redirect-opt-in.py?status=307&location=h
ttp://{{domains[www]}}:{{ports[http][0]}}/common/text-plain.txt"); |
| 39 es.onerror = t.step_func(e => { |
| 40 assert_equals(es.readyState, EventSource.CLOSED); |
| 41 |
| 42 assert_false(errorEvent); |
| 43 errorEvent = true; |
| 44 if (cspEvent) |
| 45 t.done(); |
| 46 }); |
| 47 |
| 48 document.addEventListener("securitypolicyviolation", t.step_func(e => { |
| 49 if (e.blockedURI != "http://{{domains[www]}}:{{ports[http][0]}}") |
| 50 return; |
| 51 |
| 52 assert_equals(es.readyState, EventSource.CLOSED); |
| 53 assert_equals(e.violatedDirective, "connect-src"); |
| 54 |
| 55 assert_false(cspEvent); |
| 56 cspEvent = true; |
| 57 if (errorEvent) |
| 58 t.done(); |
| 59 })); |
| 60 }, "EventSource should fire onerror after a redirect."); |
| 61 </script> |
OLD | NEW |