From b523d7b24c0c1e43dee459c6a5637680452e1f70 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Mon, 19 Feb 2024 17:28:08 +0100 Subject: [PATCH] Add test that mutation observers receive the default policy value when `setAttribute` is called As requested in . --- ...tring-assignment-to-Element-setAttribute.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/trusted-types/block-string-assignment-to-Element-setAttribute.html b/trusted-types/block-string-assignment-to-Element-setAttribute.html index d04ab753770fad..295890f319a482 100644 --- a/trusted-types/block-string-assignment-to-Element-setAttribute.html +++ b/trusted-types/block-string-assignment-to-Element-setAttribute.html @@ -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]);