| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script src="support/helper.js"></script> |
| |
| <meta http-equiv="Content-Security-Policy" content="require-trusted-types"> |
| |
| <script> |
| //helper function for the tests |
| function testHref(str, url) { |
| var base = document.createElement('base'); |
| base.href = url; |
| assert_equals(base.href, str); |
| } |
| |
| //URL assignments do not throw. |
| test(t => { |
| testHref(URLS.safe, TrustedURL.create(URLS.safe)); |
| }, "base.href = URLS.safe, TrustedURL.create"); |
| |
| test(t => { |
| testHref(URLS.safe, TrustedURL.unsafelyCreate(URLS.safe)); |
| }, "base.href = URLS.safe, TrustedURL.unsafelyCreate"); |
| |
| // String assignments throw. |
| test(t => { |
| var base = document.createElement('base'); |
| assert_throws(new TypeError(), _ => { |
| base.href = "A string"; |
| }); |
| }, "`base.href = string` throws"); |
| |
| //Null assignment throws. |
| test(t => { |
| var base = document.createElement('base'); |
| assert_throws(new TypeError(), _ => { |
| base.href = null; |
| }); |
| }, "`base.href = null` throws"); |
| </script> |
| </head> |