https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 8409a38ef8d57d6fdad447adef206f17d1ecf9fb authored by James Graham on 14 August 2018, 18:17:53 UTC
WIP
Tip revision: 8409a38
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="require-trusted-types">
</head>
<body>
<script>
  //helper functions for the tests
  function testWindowOpen(t, url, win) {
    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) {
    let child_window = win.open(TrustedURL.create(URLS.safe), "", "");
    child_window.onload = t.step_func_done(_ => {
      assert_throws(new TypeError(), _ => {
        child_window = win.open(url, "", "");
        child_window.close();
      });
    });
  }

  //TrustedURL assignments do not throw
  async_test(t => {
    testWindowOpen(t, TrustedURL.create(URLS.safe), window);
  }, "window.open: safe URL, safe construction.");

  async_test(t => {
    testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), window);
  }, "window.open: safe URL, unsafe construction.");

  async_test(t => {
    testWindowOpen(t, TrustedURL.create(URLS.safe), document);
  }, "document.open: safe URL, safe construction.");

  async_test(t => {
    testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), document);
  }, "document.open: safe URL, unsafe construction.");

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

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

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

  //Null assignment throws
  async_test(t => {
    testWindowThrows(t, null, document);
  }, "`document.open(null)` throws.");
</script>
</body>
</html>
back to top