| <!DOCTYPE html> |
| <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 *"> |
| <body> |
| <script> |
| // setTimeout tests |
| // TrustedScript assignments do not throw. |
| async_test(t => { |
| window.timeoutTest = t; |
| let policy = createScript_policy(window, 'timeout'); |
| let script = policy.createScript("window.timeoutTest.done();"); |
| setTimeout(script); |
| }, "window.setTimeout assigned via policy (successful Script transformation)."); |
| |
| // String assignments throw. |
| test(t => { |
| window.timeoutTestString = t.unreached_func(); |
| assert_throws(new TypeError(), _ => { |
| setTimeout("window.timeoutTestString();"); |
| }); |
| }, "`window.setTimeout(string)` throws."); |
| |
| // Null assignment throws. |
| test(t => { |
| assert_throws(new TypeError(), _ => { |
| setTimeout(null); |
| }); |
| }, "`window.setTimeout(null)` throws."); |
| |
| // setInterval tests |
| // TrustedScript assignments do not throw. |
| async_test(t => { |
| window.intervalTest = t; |
| let policy = createScript_policy(window, 'script'); |
| let script = policy.createScript("window.intervalTest.done();"); |
| setInterval(script); |
| }, "window.setInterval assigned via policy (successful Script transformation)."); |
| |
| // String assignments throw. |
| test(t => { |
| window.intervalTestString = t.unreached_func(); |
| assert_throws(new TypeError(), _ => { |
| setInterval("window.intervalTestString()"); |
| }); |
| }, "`window.setInterval(string)` throws."); |
| |
| // Null assignment throws. |
| test(t => { |
| assert_throws(new TypeError(), _ => { |
| setInterval(null); |
| }); |
| }, "`window.setInterval(null)` throws."); |
| |
| // After default policy creation string assignment implicitly calls createScript. |
| test(t => { |
| let policy = window.TrustedTypes.createPolicy("default", { createScript: createScriptJS }, true); |
| setTimeout(INPUTS.SCRIPT); |
| setInterval(INPUTS.SCRIPT); |
| }, "`setTimeout(string)`, `setInterval(string)` via default policy (successful Script transformation)."); |
| |
| // After default policy creation null assignment implicitly calls createScript. |
| test(t => { |
| setTimeout(null); |
| setInterval(null); |
| }, "`setTimeout(null)`, `setInterval(null)` via default policy (successful Script transformation)."); |
| </script> |