Skip to content

Commit

Permalink
Add test that mutation observers receive the default policy value whe…
Browse files Browse the repository at this point in the history
…n `setAttribute` is called

As requested in
<w3c/trusted-types#425 (comment)>.
  • Loading branch information
mbrodesser-Igalia committed Feb 20, 2024
1 parent 3a15f9f commit b523d7b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions trusted-types/block-string-assignment-to-Element-setAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@
}, c[0] + "." + c[1] + " accepts string and null after default policy was created.");
});

scriptURLTestCases.concat(HTMLTestCases).concat(ScriptTestCases).forEach(c => {
async_test(t => {
const testElement = document.createElement(c[0]);

const observer = new MutationObserver(t.step_func_done((aMutations, aObserver) => {
assert_equals(aMutations.length, 1);
const newValue = aMutations[0].target.getAttribute(c[1]);
assert_equals(newValue, c[3]);
}));

observer.observe(testElement, { attributes: true});

testElement.setAttribute(c[1], c[2]);
}, c[0] + "." + c[1] + "'s mutationobservers receive the default policy's value.");
});

HTMLTestCases.forEach(c => {
test(t => {
assert_element_accepts_trusted_type(c[0], c[1], c[2], c[3]);
Expand Down

0 comments on commit b523d7b

Please sign in to comment.