From 849409539e0d2f7cee6eb1b8542a705399b7d55a Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 7 Jan 2025 12:10:39 +0000 Subject: [PATCH] WebKit export of https://bugs.webkit.org/show_bug.cgi?id=285510 --- .../trusted-types-svg-script-set-href.html | 108 ++++++++++++++---- 1 file changed, 88 insertions(+), 20 deletions(-) diff --git a/trusted-types/trusted-types-svg-script-set-href.html b/trusted-types/trusted-types-svg-script-set-href.html index 9b8a528fca44e8..d94b0fb95b45d7 100644 --- a/trusted-types/trusted-types-svg-script-set-href.html +++ b/trusted-types/trusted-types-svg-script-set-href.html @@ -3,6 +3,7 @@ + @@ -14,8 +15,7 @@ createScript: x => x, createHTML: x => x, createScriptURL: x => x }); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); assert_throws_js(TypeError, _ => { elem.href.baseVal = "about:blank"; }); @@ -24,16 +24,16 @@ }, "Assign string to SVGScriptElement.href.baseVal."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); elem.href.baseVal = policy.createScriptURL("about:blank"); + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); document.getElementById("svg").appendChild(elem); return Promise.resolve(); }, "Assign TrustedScriptURL to SVGScriptElement.href.baseVal."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); assert_throws_js(TypeError, _ => { elem.setAttribute("href", "about:blank"); }); @@ -42,16 +42,16 @@ }, "Assign string to non-attached SVGScriptElement.href via setAttribute."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); elem.setAttribute("href", policy.createScriptURL("about:blank")); + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); document.getElementById("svg").appendChild(elem); return Promise.resolve(); }, "Assign TrustedScriptURL to non-attached SVGScriptElement.href via setAttribute."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); document.getElementById("svg").appendChild(elem); assert_throws_js(TypeError, _ => { elem.setAttribute("href", "about:blank"); @@ -60,15 +60,48 @@ }, "Assign string to attached SVGScriptElement.href via setAttribute."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); document.getElementById("svg").appendChild(elem); elem.setAttribute("href", policy.createScriptURL("about:blank")); + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); return Promise.resolve(); }, "Assign TrustedScriptURL to attached SVGScriptElement.href via setAttribute."); - // Default policy test: We repate the string assignment tests above, - // but now expect all of them to pass. + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "script"); + elem.className.baseVal = "myClass"; + assert_equals(elem.className.baseVal, "myClass"); + assert_equals(elem.getAttribute("class"), "myClass"); + return Promise.resolve(); + }, "Assign string to SVGScriptElement.className.baseVal."); + + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "script"); + elem.className.baseVal = policy.createScriptURL("myClass"); + assert_equals(elem.className.baseVal, "myClass"); + assert_equals(elem.getAttribute("class"), "myClass"); + return Promise.resolve(); + }, "Assign TrustedScriptURL to SVGScriptElement.className.baseVal."); + + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "use"); + elem.href.baseVal = "about:blank"; + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); + return Promise.resolve(); + }, "Assign string to SVGUseElement.href.baseVal."); + + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "use"); + elem.href.baseVal = policy.createScriptURL("about:blank"); + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); + return Promise.resolve(); + }, "Assign TrustedScriptURL to SVGUseElement.href.baseVal."); + + // Default policy test: We repeat the string assignment tests above, + // but now expect all assignments to succeed. promise_test(t => { trustedTypes.createPolicy("default", { createScript: (x, _, sink) => { @@ -93,27 +126,62 @@ }, "Assign String to SVGScriptElement.innerHTML w/ default policy."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); elem.href.baseVal = "about:blank"; + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); document.getElementById("svg").appendChild(elem); return Promise.resolve(); }, "Assign string to SVGScriptElement.href.baseVal w/ default policy."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); elem.setAttribute("href", "about:blank"); + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); document.getElementById("svg").appendChild(elem); return Promise.resolve(); }, "Assign string to non-attached SVGScriptElement.href via setAttribute w/ default policy."); promise_test(t => { - const elem = document.createElementNS( - "http://www.w3.org/2000/svg", "script"); + const elem = document.createElementNS(NSURI_SVG, "script"); document.getElementById("svg").appendChild(elem); elem.setAttribute("href", "about:blank"); + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); return Promise.resolve(); }, "Assign string to attached SVGScriptElement.href via setAttribute w/ default policy."); + + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "script"); + elem.className.baseVal = "myClass"; + assert_equals(elem.className.baseVal, "myClass"); + assert_equals(elem.getAttribute("class"), "myClass"); + return Promise.resolve(); + }, "Assign string to SVGScriptElement.className.baseVal w/ default policy."); + + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "script"); + elem.className.baseVal = policy.createScriptURL("myClass"); + assert_equals(elem.className.baseVal, "myClass"); + assert_equals(elem.getAttribute("class"), "myClass"); + return Promise.resolve(); + }, "Assign TrustedScriptURL to SVGScriptElement.className.baseVal w/ default policy."); + + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "use"); + elem.href.baseVal = "about:blank"; + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); + return Promise.resolve(); + }, "Assign string to SVGUseElement.href.baseVal w/ default policy."); + + promise_test(t => { + const elem = document.createElementNS(NSURI_SVG, "use"); + elem.href.baseVal = policy.createScriptURL("about:blank"); + assert_equals(elem.href.baseVal, "about:blank"); + assert_equals(elem.getAttribute("href"), "about:blank"); + return Promise.resolve(); + }, "Assign TrustedScriptURL to SVGUseElement.href.baseVal w/ default policy.");