|
| 1 | +const policy = trustedTypes.createPolicy("dummy", { createScriptURL: x => x }); |
| 2 | +let worker_url = "worker.https.js"; |
| 3 | +let scope = `scope1/`; |
| 4 | + |
| 5 | +if (getGlobalThisStr().includes("Window")) { |
| 6 | + worker_url = `support/${worker_url}`; |
| 7 | + scope = `support/${scope}`; |
| 8 | +} |
| 9 | + |
| 10 | +promise_test(async t => { |
| 11 | + await no_trusted_type_violation_for(async _ => { |
| 12 | + let reg = await self.navigator.serviceWorker.getRegistration(scope); |
| 13 | + if (reg) await reg.unregister(); |
| 14 | + reg = await self.navigator.serviceWorker.register(policy.createScriptURL(worker_url), {scope}); |
| 15 | + await new Promise(r => reg.addEventListener("updatefound", r)); |
| 16 | + }); |
| 17 | +}, "No violation reported for ServiceWorkerContainer register with TrustedScriptURL."); |
| 18 | + |
| 19 | +promise_test(async t => { |
| 20 | + let violation = await trusted_type_violation_for(TypeError, async _ => { |
| 21 | + let reg = await self.navigator.serviceWorker.getRegistration(scope); |
| 22 | + if (reg) await reg.unregister(); |
| 23 | + await self.navigator.serviceWorker.register(worker_url, {scope}); |
| 24 | + }); |
| 25 | + assert_equals(violation.blockedURI, "trusted-types-sink"); |
| 26 | + assert_equals(violation.sample, `ServiceWorkerContainer register|${clipSampleIfNeeded(worker_url)}`); |
| 27 | +}, "Violation report for ServiceWorkerContainer register with plain string."); |
0 commit comments