Skip to content

Commit

Permalink
Remove unrelated checks from trusted-types-svg-script-set-href.html (#…
Browse files Browse the repository at this point in the history
…50043)

* Remove unrelated checks from trusted-types-svg-script-set-href.html

This test is intended to cover setting href [1] [2] but it also
currently verifies some (currently not specified) unrelated behavior
when setting the text of the script via innerHTML. A similar test exist
in block-text-node-insertion-into-svg-script-element.html, but for a
disconnected script. This PR just move the unrelated test to
trusted-types-svg-script.html instead.

[1] w3c/svgwg#934
[2] whatwg/dom#1268
  • Loading branch information
fred-wang authored and sadym-chromium committed Jan 14, 2025
1 parent 44d5bcf commit 144843d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
19 changes: 3 additions & 16 deletions trusted-types/trusted-types-svg-script-set-href.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<svg id="svg"><script id="script">"some script text";</script></svg>
<script>
const policy = trustedTypes.createPolicy("policy", {
createScript: x => x, createHTML: x => x, createScriptURL: x => x });
createScriptURL: script_url => script_url });

promise_test(t => {
const elem = document.createElementNS(NSURI_SVG, "script");
Expand Down Expand Up @@ -104,27 +104,14 @@
// but now expect all assignments to succeed.
promise_test(t => {
trustedTypes.createPolicy("default", {
createScript: (x, _, sink) => {
assert_equals(sink, 'SVGScriptElement text');
return x;
},
createHTML: (x, _, sink) => {
assert_equals(sink, 'Element innerHTML');
return x;
},
createScriptURL: (x, _, sink) => {
createScriptURL: (script_url, _, sink) => {
assert_equals(sink, 'SVGScriptElement href');
return x;
return script_url;
}});

return Promise.resolve();
}, "Setup default policy");

promise_test(t => {
document.getElementById("script").innerHTML = "'modified via innerHTML';";
return Promise.resolve();
}, "Assign String to SVGScriptElement.innerHTML w/ default policy.");

promise_test(t => {
const elem = document.createElementNS(NSURI_SVG, "script");
elem.href.baseVal = "about:blank";
Expand Down
15 changes: 15 additions & 0 deletions trusted-types/trusted-types-svg-script.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@
document.getElementById("svg").appendChild(elem);
return promise_spv();
}, "Modify SVGScriptElement via DOM manipulation.");

promise_test(t => {
trustedTypes.createPolicy("default", {
createScript: (input, _, sink) => {
assert_equals(sink, 'SVGScriptElement text');
return input;
},
createHTML: (input, _, sink) => {
assert_equals(sink, 'Element innerHTML');
return input;
},
});
document.getElementById("script").innerHTML = "'modified via innerHTML';";
return Promise.resolve();
}, "Assign String to SVGScriptElement.innerHTML w/ default policy.");
</script>
</body>

0 comments on commit 144843d

Please sign in to comment.