https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 64bd43ee19cc4667e4a3020c5894af7dbe68f5cc authored by Yuki Shiino on 25 December 2018, 07:52:23 UTC
v8binding: Add lexical scope test of event handlers in WPT
Tip revision: 64bd43e
WorkerGlobalScope-importScripts.https.html
<!doctype html>
<html>
<head>
  <meta http-equiv="Content-Security-Policy" content="trusted-types *">
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id=log></div>

<script>

// To test workers, we need to importScripts source files in the workers.
// Since the point of this test is to test blocking of importScripts, we need
// to set up one policy that will blindly pass through URLs for use in the test
// setup, and then have additional policies for the actual test cases.
//
// For the same reason we cannot use the otherwise preferred 'META: workers'
// tag, since the test setup that uses would be blocked as soon trusted types
// enforcement is enabled.
const test_setup_policy = TrustedTypes.createPolicy("hurrayanythinggoes", {
  createScriptURL: x => new URL(x, location.href)
});
const test_url =
  test_setup_policy.createScriptURL("WorkerGlobalScope-importScripts.https.js");

fetch_tests_from_worker(new Worker(test_url));

fetch_tests_from_worker(new SharedWorker(test_url));

// Cargo-culted from code generated from "META: worker".
if ('serviceWorker' in navigator) {
  (async function() {
      const scope = 'some/scope/for/this/test';
      let reg = await navigator.serviceWorker.getRegistration(scope);
      if (reg) await reg.unregister();
      reg = await navigator.serviceWorker.register(test_url, {scope});
      fetch_tests_from_worker(reg.installing);
  })();
}
</script>
</body>
back to top