| OLD | NEW |
| 1 function assert_no_csp_event_for_url(test, url) { | 1 function assert_no_csp_event_for_url(test, url) { |
| 2 self.addEventListener("securitypolicyviolation", test.step_func(e => { | 2 self.addEventListener("securitypolicyviolation", test.step_func(e => { |
| 3 if (e.blockedURI !== url) | 3 if (e.blockedURI !== url) |
| 4 return; | 4 return; |
| 5 assert_unreached("SecurityPolicyViolation event fired for " + url); | 5 assert_unreached("SecurityPolicyViolation event fired for " + url); |
| 6 })); | 6 })); |
| 7 } | 7 } |
| 8 | 8 |
| 9 function assert_no_event(test, obj, name) { | 9 function assert_no_event(test, obj, name) { |
| 10 obj.addEventListener(name, test.unreached_func("The '" + name + "' event shoul
d not have fired.")); | 10 obj.addEventListener(name, test.unreached_func("The '" + name + "' event shoul
d not have fired.")); |
| 11 } | 11 } |
| 12 | 12 |
| 13 function waitUntilCSPEventForURL(test, url) { | 13 function waitUntilCSPEventForURL(test, url) { |
| 14 return new Promise((resolve, reject) => { | 14 return new Promise((resolve, reject) => { |
| 15 self.addEventListener("securitypolicyviolation", test.step_func(e => { | 15 self.addEventListener("securitypolicyviolation", test.step_func(e => { |
| 16 if (e.blockedURI == url) | 16 if (e.blockedURI == url) |
| 17 resolve(e); | 17 resolve(e); |
| 18 })); | 18 })); |
| 19 }); | 19 }); |
| 20 } | 20 } |
| 21 | 21 |
| 22 function waitUntilCSPEventForEval(test, line) { |
| 23 return new Promise((resolve, reject) => { |
| 24 self.addEventListener("securitypolicyviolation", test.step_func(e => { |
| 25 if (e.blockedURI == "eval" && e.lineNumber == line) |
| 26 resolve(e); |
| 27 })); |
| 28 }); |
| 29 } |
| 30 |
| 22 function waitUntilEvent(obj, name) { | 31 function waitUntilEvent(obj, name) { |
| 23 return new Promise((resolve, reject) => { | 32 return new Promise((resolve, reject) => { |
| 24 obj.addEventListener(name, resolve); | 33 obj.addEventListener(name, resolve); |
| 25 }); | 34 }); |
| 26 } | 35 } |
| 27 | 36 |
| 28 // Given the URL of a worker that pings its opener upon load, this | 37 // Given the URL of a worker that pings its opener upon load, this |
| 29 // function builds a test that asserts that the ping is received, | 38 // function builds a test that asserts that the ping is received, |
| 30 // and that no CSP event fires. | 39 // and that no CSP event fires. |
| 31 function assert_worker_is_loaded(url, description) { | 40 function assert_worker_is_loaded(url, description) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 waitUntilCSPEventForURL(t, reportedURL) | 130 waitUntilCSPEventForURL(t, reportedURL) |
| 122 .then(t.step_func_done(e => { | 131 .then(t.step_func_done(e => { |
| 123 assert_equals(e.blockedURI, reportedURL); | 132 assert_equals(e.blockedURI, reportedURL); |
| 124 assert_equals(e.violatedDirective, "worker-src"); | 133 assert_equals(e.violatedDirective, "worker-src"); |
| 125 assert_equals(e.effectiveDirective, "worker-src"); | 134 assert_equals(e.effectiveDirective, "worker-src"); |
| 126 })), | 135 })), |
| 127 promise_rejects(t, "SecurityError", navigator.serviceWorker.register(url,
{ scope: url })) | 136 promise_rejects(t, "SecurityError", navigator.serviceWorker.register(url,
{ scope: url })) |
| 128 ]); | 137 ]); |
| 129 }, description); | 138 }, description); |
| 130 } | 139 } |
| OLD | NEW |