| <!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, "", ""); |
| t.add_cleanup(_ => child_window.close()); |
| child_window.onload = t.step_func_done(_ => { |
| assert_equals(child_window.location.href, "" + url); |
| }); |
| } |
| |
| function testWindowThrows(t, url, win, nb) { |
| let p = createURL_policy(window, nb); |
| assert_throws(new TypeError(), _ => { |
| let child_window = win.open(url, "", ""); |
| }); |
| } |
| |
| function testWindowDoesntThrow(t, url, expected, win) { |
| let child_window = win.open(url, "", ""); |
| t.add_cleanup(_ => child_window.close()); |
| child_window.onload = t.step_func_done(_ => { |
| assert_equals(child_window.location.href, expected); |
| }); |
| } |
| |
| // 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> |