testing/web-platform/tests/trusted-types/trusted-types-navigation.tentative.html
author Razvan Maries <rmaries@mozilla.com>
Thu, 26 Nov 2020 07:56:23 +0200
changeset 558457 7184fb5a42fbdd37b1d4863045bea812223ffd41
parent 531924 e07cf3d4936f99965d8d52afab0560b7cbfd7975
permissions -rw-r--r--
Backed out changeset 646459eb4a35 (bug 1459118) as per Henrik's request. CLOSED TREE

<!DOCTYPE html>
<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
  function expectMessage(filter) {
    return new Promise(resolve => {
      window.addEventListener("message", e => { if (filter(e)) resolve(); });
    });
  }

  function expectViolationAsMessage(sample) {
    const filter = e => ((e.data.effectiveDirective == "require-trusted-types-for" ||
                          e.data.effectiveDirective == "trusted-types") &&
                         (!sample || e.data.sample.startsWith(sample)));
    return new expectMessage(filter);
  }

  function expectLoadedAsMessage(uri) {
    const filter = e => (e.data.type == "DOMContentLoaded" &&
                        (!uri || e.data.uri.endsWith(uri)));
    return new expectMessage(filter);
  }

  function openWindow(test, uri) {
    const win = window.open(uri);
    test.add_cleanup(_ => win.close());
  }

  promise_test(t => {
    openWindow(t, "support/navigation-support.html");
    return Promise.all([
      expectLoadedAsMessage("navigation-support.html"),
      expectViolationAsMessage("Location href"),
    ]);
  }, "Navigate a window with javascript:-urls in enforcing mode.");

  promise_test(t => {
    openWindow(t, "support/navigation-support.html?defaultpolicy");
    return Promise.all([
      expectLoadedAsMessage("navigation-support.html?defaultpolicy"),
      expectLoadedAsMessage("navigation-support.html?defaultpolicy&defaultpolicywashere"),
    ]);
  }, "Navigate a window with javascript:-urls w/ default policy in enforcing mode.");

  promise_test(t => {
    const page = "navigation-report-only-support.html"
    openWindow(t, `support/${page}`);
    return Promise.all([
      expectLoadedAsMessage(page),
      expectLoadedAsMessage("navigation-support.html#continue"),
    ]);
  }, "Navigate a window with javascript:-urls in report-only mode.");

  promise_test(t => {
    const page = "navigation-report-only-support.html?defaultpolicy";
    openWindow(t, `support/${page}`);
    return Promise.all([
      expectLoadedAsMessage(page),
      expectLoadedAsMessage("navigation-support.html?defaultpolicy#defaultpolicywashere"),
    ]);
  }, "Navigate a window with javascript:-urls w/ default policy in report-only mode.");
</script>
</body>