From 65c079cf1a5154a20250511309abd9193b68569f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Fri, 3 Jan 2025 21:18:47 +0000 Subject: [PATCH] Remove commented out tests from GlobalEventHandlers-onclick.html and minor tweaks. See https://github.com/w3c/trusted-types/issues/571#issuecomment-2569517456 Differential Revision: https://phabricator.services.mozilla.com/D233186 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1939893 gecko-commit: e058dd4b64b841edcbd3e5b5dfefd4f8a0ee96af gecko-reviewers: smaug --- .../GlobalEventHandlers-onclick.html | 59 +++---------------- 1 file changed, 7 insertions(+), 52 deletions(-) diff --git a/trusted-types/GlobalEventHandlers-onclick.html b/trusted-types/GlobalEventHandlers-onclick.html index 0fdde778cc8863..83b957256bee93 100644 --- a/trusted-types/GlobalEventHandlers-onclick.html +++ b/trusted-types/GlobalEventHandlers-onclick.html @@ -19,74 +19,29 @@ el.setAttribute('onclick', script); container.appendChild(el); el.click(); -}, "a.setAttribte('onclick') sets a trusted script."); +}, "a.setAttribute('onclick') sets a trusted script."); // Unsuitable TrustedType assignments do throw. -async_test(t => { +test(t => { window.onclickFail1 = t.unreached_func(); let script = policy_html.createHTML("window.onclickFail1();"); let el = document.createElement('a'); - try { + assert_throws_js(TypeError, () => { el.setAttribute('onclick', script); container.appendChild(el); el.click(); - } catch (e) { - t.done(); - } - assert_unreached(); + }); }, "a.setAttribute('onclick') sets an unsuitable trusted type."); // So do plain test assignments. -async_test(t => { +test(t => { window.onclickFail2 = t.unreached_func(); let el = document.createElement('a'); - try { + assert_throws_js(TypeError, () => { el.setAttribute("onclick", "window.onclickFail2();"); container.appendChild(el); el.click(); - } catch (e) { - t.done(); - } - assert_unreached(); + }); }, "a.setAttribute('click') sets a test string."); -/* -// Trusted Type assignments via property access does not throw. -async_test(t => { - window.onclickDone2 = t.step_func_done(); - let script = policy.createScript("window.onclickDone2();"); - let el = document.createElement('a'); - el.onclick = script; - container.appendChild(el); - el.click(); -}, "a.onclick assigned via policy (successful Script transformation)."); -// Unsuitable TrustedType assignments do throw. -async_test(t => { - window.onclickFail3 = t.unreached_func(); - let script = policy_html.createHTML("window.onclickFail3();"); - let el = document.createElement('a'); - try { - el.onclick = script; - container.appendChild(el); - el.click(); - } catch (e) { - t.done(); - } - assert_unreached(); -}, "a.onclick assigned via an unsuitable policy."); - -// So do plain test assignments. -async_test(t => { - window.onclickFail4 = t.unreached_func(); - let el = document.createElement('a'); - try { - el.onclick = window.onclickFail4(); - container.appendChild(el); - el.click(); - } catch (e) { - t.done(); - } - assert_unreached(); -}, "a.onclick assigned a test string."); -*/