https://github.com/web-platform-tests/wpt
Raw File
Tip revision: fe38104efc1fefb450302f42f157855f579d174c authored by Lan Wei on 15 December 2018, 01:20:34 UTC
Support multiple mouse pointers inputs
Tip revision: fe38104
block-string-assignment-to-Window-open.tentative.html
<!DOCTYPE html>
<html>
<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="support/helper.sub.js"></script>

  <meta http-equiv="Content-Security-Policy" content="trusted-types *">
</head>
<body>
<script>
  var testnb = 0;
  // helper functions for the tests
  function testWindowOpen(t, win, nb) {
    let p = createURL_policy(window, nb);
    let url = p.createURL(INPUTS.URL);
    let child_window = win.open(url, "", "");
    child_window.onload = t.step_func_done(_ => {
      assert_equals(child_window.location.href, "" + url);
      child_window.close();
    });
  }

  function testWindowThrows(t, url, win, nb) {
    let p = createURL_policy(window, nb);
    assert_throws(new TypeError(), _ => {
      let child_window = win.open(url, "", "");
      child_window.close();
    });
  }

  function testWindowDoesntThrow(t, url, expected, win) {
    let child_window = win.open(url, "", "");
    child_window.onload = t.step_func_done(_ => {
      assert_equals(child_window.location.href, expected);
      child_window.close();
    });
  }

  // TrustedURL assignments do not throw.
  test(t => {
    testWindowOpen(t, window, ++testnb);
  }, "window.open via policy (successful URL transformation).");

  test(t => {
    testWindowOpen(t, document, ++testnb);
  }, "document.open via policy (successful URL transformation).");

  // String assignments throw.
  test(t => {
    testWindowThrows(t, 'A string', window, ++testnb);
  }, "`window.open(string)` throws.");

  test(t => {
    testWindowThrows(t, 'A string', document, ++testnb);
  }, "`document.open(string)` throws.");

  // Null assignment throws.
  test(t => {
    testWindowThrows(t, null, window, ++testnb);
  }, "`window.open(null)` throws.");

  test(t => {
    testWindowThrows(t, null, document, ++testnb);
  }, "`document.open(null)` throws.");

  // After default policy creation string assignment implicitly calls createURL.
  let p = window.TrustedTypes.createPolicy("default", { createURL: createURLJS }, true);
  test(t => {
    testWindowDoesntThrow(t, INPUTS.URL, RESULTS.URL, window);
  }, "'window.open(string)' assigned via default policy (successful URL transformation).");

  test(t => {
    testWindowDoesntThrow(t, INPUTS.URL, RESULTS.URL, document);
  }, "'document.open(string)' assigned via default policy (successful URL transformation).");

  test(t => {
    testWindowDoesntThrow(t, null, "null", window);
  }, "'window.open(null)' assigned via default policy does not throw.");

  test(t => {
    testWindowDoesntThrow(t, null, "null", document);
  }, "'document.open(null)' assigned via default policy does not throw.");
</script>
</body>
</html>
back to top