| <!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> |
| // TrustedURL assignments do not throw. |
| test(t => { |
| let p = createURL_policy(window, 1); |
| let url = p.createURL(location.href + "#xxx"); |
| location.assign(url); |
| assert_equals("" + url, location.href, "location href"); |
| }, "location.assign via policy (successful URL transformation)."); |
| |
| // String assignments throw. |
| test(t => { |
| assert_throws(new TypeError(), _ => { |
| location.assign("A string"); |
| }); |
| }, "`location.assign = string` throws"); |
| |
| // Null assignment throws. |
| test(t => { |
| assert_throws(new TypeError(), _ => { |
| location.assign(null); |
| }); |
| }, "`location.assign = null` throws"); |
| |
| // Create default policy. Applies to all subsequent tests. |
| let p = window.TrustedTypes.createPolicy("default", |
| { createURL: createLocationURLJS }, true); |
| |
| // After default policy creation string assignment implicitly calls createURL. |
| test(t => { |
| location.assign("abcdefg"); |
| assert_true(location.href.endsWith("#abcdefg")); |
| }, "`location.assign = string` via default policy (successful URL transformation)."); |
| |
| // After default policy creation null assignment implicitly calls createURL. |
| test(t => { |
| location.assign(null); |
| assert_true(location.href.endsWith("#null")); |
| }, "`location.assign = null` via default policy does not throw."); |
| </script> |