From 2e2d6c1b4f4b8352acd17a5623f9ab378baadb3e Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 28 Mar 2024 12:06:45 -0700 Subject: [PATCH] Re-sync trusted types WPT tests https://bugs.webkit.org/show_bug.cgi?id=271316 Reviewed by Anne van Kesteren. Upstream commit: https://github.com/web-platform-tests/wpt/commit/577d22542f1321249653d695626f05aa42320ff7 * LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.tentative-expected.txt: Renamed from LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking-expected.txt. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.tentative.html: Renamed from LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.html. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe.html: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute.html: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS.html: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe.html: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe.html: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.html: Added. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.js: Renamed from LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.tentative.window.js.html. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/support/helper.sub.js: * LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.tentative-expected.txt: Renamed from LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal-expected.txt. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.tentative.html: Renamed from LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.html. * LayoutTests/imported/w3c/web-platform-tests/trusted-types/w3c-import.log: Canonical link: https://commits.webkit.org/276793@main --- ...cyFactory-blocking.tentative-expected.txt} | 0 ...TypePolicyFactory-blocking.tentative.html} | 0 ...t-to-Document-parseHTMLUnsafe-expected.txt | 9 ++ ...ssignment-to-Document-parseHTMLUnsafe.html | 48 +++++++++ ...nment-to-Element-setAttribute-expected.txt | 6 ++ ...ng-assignment-to-Element-setAttribute.html | 38 +++++-- ...ent-to-Element-setAttributeNS-expected.txt | 9 +- ...-assignment-to-Element-setAttributeNS.html | 45 ++++++-- ...ment-to-Element-setHTMLUnsafe-expected.txt | 9 ++ ...g-assignment-to-Element-setHTMLUnsafe.html | 79 ++++++++++++++ ...t-to-ShadowRoot-setHTMLUnsafe-expected.txt | 9 ++ ...ssignment-to-ShadowRoot-setHTMLUnsafe.html | 84 +++++++++++++++ .../idlharness.window-expected.txt | 102 ++++++++++++++++++ .../trusted-types/idlharness.window.html | 1 + ...ve.window.js.html => idlharness.window.js} | 0 .../trusted-types/support/helper.sub.js | 11 +- ...types-from-literal.tentative-expected.txt} | 0 ...trusted-types-from-literal.tentative.html} | 0 .../trusted-types/w3c-import.log | 10 +- 19 files changed, 430 insertions(+), 30 deletions(-) rename LayoutTests/imported/w3c/web-platform-tests/trusted-types/{TrustedTypePolicyFactory-blocking-expected.txt => TrustedTypePolicyFactory-blocking.tentative-expected.txt} (100%) rename LayoutTests/imported/w3c/web-platform-tests/trusted-types/{TrustedTypePolicyFactory-blocking.html => TrustedTypePolicyFactory-blocking.tentative.html} (100%) create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe.html create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe.html create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe.html create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.html rename LayoutTests/imported/w3c/web-platform-tests/trusted-types/{idlharness.tentative.window.js.html => idlharness.window.js} (100%) rename LayoutTests/imported/w3c/web-platform-tests/trusted-types/{trusted-types-from-literal-expected.txt => trusted-types-from-literal.tentative-expected.txt} (100%) rename LayoutTests/imported/w3c/web-platform-tests/trusted-types/{trusted-types-from-literal.html => trusted-types-from-literal.tentative.html} (100%) diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.tentative-expected.txt similarity index 100% rename from LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking-expected.txt rename to LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.tentative-expected.txt diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.tentative.html similarity index 100% rename from LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.html rename to LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.tentative.html diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe-expected.txt new file mode 100644 index 000000000000..7a325b3c1c4f --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe-expected.txt @@ -0,0 +1,9 @@ +CONSOLE MESSAGE: This requires a TrustedHTML value else it violates the following Content Security Policy directive: "require-trusted-types-for 'script'" +CONSOLE MESSAGE: This requires a TrustedHTML value else it violates the following Content Security Policy directive: "require-trusted-types-for 'script'" + +PASS Document.parseHTMLUnsafe assigned via policy (successful HTML transformation). +PASS `Document.parseHTMLUnsafe(string)` throws. +PASS 'Document.parseHTMLUnsafe(null)' throws +PASS 'Document.parseHTMLUnsafe(string)' assigned via default policy (successful HTML transformation). +PASS 'Document.parseHTMLUnsafe(null)' assigned via default policy does not throw + diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe.html new file mode 100644 index 000000000000..83dfcda5d921 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe.html @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute-expected.txt index 203518c9c262..b9dbc24d4c20 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute-expected.txt @@ -24,6 +24,12 @@ PASS embed.src accepts string and null after default policy was created. PASS object.data accepts string and null after default policy was created. PASS object.codeBase accepts string and null after default policy was created. PASS script.src accepts string and null after default policy was created. +FAIL embed.src's mutationobservers receive the default policy's value. assert_equals: expected "http://this.is.a.successful.test/" but got "http://this.is.a.scripturl.test/" +FAIL object.data's mutationobservers receive the default policy's value. assert_equals: expected "http://this.is.a.successful.test/" but got "http://this.is.a.scripturl.test/" +FAIL object.codeBase's mutationobservers receive the default policy's value. assert_equals: expected "http://this.is.a.successful.test/" but got "http://this.is.a.scripturl.test/" +FAIL script.src's mutationobservers receive the default policy's value. assert_equals: expected "http://this.is.a.successful.test/" but got "http://this.is.a.scripturl.test/" +FAIL iframe.srcdoc's mutationobservers receive the default policy's value. assert_equals: expected "Quack, I want to be a duck!" but got "Hi, I want to be transformed!" +FAIL div.onclick's mutationobservers receive the default policy's value. assert_equals: expected "Meow, I want to be a cat!" but got "Hi, I want to be transformed!" PASS iframe.srcdoc accepts string and null after default policy was created. FAIL div.onclick accepts string and null after default policy was created. assert_equals: expected "Meow, I want to be a cat!" but got "Hi, I want to be transformed!" PASS a.rel accepts strings diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute.html index 1d39a804f39c..295890f319a4 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute.html +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute.html @@ -13,10 +13,10 @@ // TrustedScriptURL Assignments const scriptURLTestCases = [ - [ 'embed', 'src' ], - [ 'object', 'data' ], - [ 'object', 'codeBase' ], - [ 'script', 'src' ] + [ 'embed', 'src', INPUTS.SCRIPTURL, RESULTS.SCRIPTURL], + [ 'object', 'data', INPUTS.SCRIPTURL, RESULTS.SCRIPTURL ], + [ 'object', 'codeBase', INPUTS.SCRIPTURL, RESULTS.SCRIPTURL ], + [ 'script', 'src', INPUTS.SCRIPTURL, RESULTS.SCRIPTURL ] ]; scriptURLTestCases.forEach(c => { @@ -31,12 +31,12 @@ // TrustedHTML Assignments const HTMLTestCases = [ - [ 'iframe', 'srcdoc' ] + [ 'iframe', 'srcdoc' , INPUTS.HTML, RESULTS.HTML] ]; HTMLTestCases.forEach(c => { test(t => { - assert_element_accepts_trusted_html_explicit_set(window, c[0] + "-" + c[1], t, c[0], c[1], RESULTS.HTML); + assert_element_accepts_trusted_html_explicit_set(window, c[0] + "-" + c[1], t, c[0], c[1], c[3]); assert_throws_no_trusted_type_explicit_set(c[0], c[1], 'A string'); assert_throws_no_trusted_type_explicit_set(c[0], c[1], null); assert_throws_no_trusted_type_explicit_set(c[0], c[1], nullPolicy.createScript('script')); @@ -45,12 +45,12 @@ // TrustedScript Assignments const ScriptTestCases = [ - [ 'div', 'onclick' ] + [ 'div', 'onclick' , INPUTS.SCRIPT, RESULTS.SCRIPT] ]; ScriptTestCases.forEach(c => { test(t => { - assert_element_accepts_trusted_script_explicit_set(window, c[0] + "-" + c[1], t, c[0], c[1], RESULTS.SCRIPT); + assert_element_accepts_trusted_script_explicit_set(window, c[0] + "-" + c[1], t, c[0], c[1], c[3]); assert_throws_no_trusted_type_explicit_set(c[0], c[1], 'A string'); assert_throws_no_trusted_type_explicit_set(c[0], c[1], null); }, c[0] + "." + c[1] + " accepts only TrustedScript"); @@ -70,21 +70,37 @@ let p = window.trustedTypes.createPolicy("default", { createScriptURL: createScriptURLJS, createHTML: createHTMLJS, createScript: createScriptJS }, true); scriptURLTestCases.forEach(c => { test(t => { - assert_element_accepts_trusted_type(c[0], c[1], INPUTS.SCRIPTURL, RESULTS.SCRIPTURL); + assert_element_accepts_trusted_type(c[0], c[1], c[2], c[3]); assert_element_accepts_trusted_type(c[0], c[1], null, window.location.toString().replace(/[^\/]*$/, "null")); }, 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], INPUTS.HTML, RESULTS.HTML); + assert_element_accepts_trusted_type(c[0], c[1], c[2], c[3]); assert_element_accepts_trusted_type(c[0], c[1], null, "null"); }, c[0] + "." + c[1] + " accepts string and null after default policy was created."); }); ScriptTestCases.forEach(c => { test(t => { - assert_element_accepts_trusted_type_explicit_set(c[0], c[1], INPUTS.SCRIPT, RESULTS.SCRIPT); + assert_element_accepts_trusted_type_explicit_set(c[0], c[1], c[2], c[3]); assert_element_accepts_trusted_type_explicit_set(c[0], c[1], null, "null"); }, c[0] + "." + c[1] + " accepts string and null after default policy was created."); }); diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS-expected.txt index c79cb6afcdf2..a343b791bcdf 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS-expected.txt @@ -6,6 +6,13 @@ PASS Element.setAttributeNS accepts untrusted string for non-specced accessor PASS Element.setAttributeNS accepts null for non-specced accessor PASS Assigning TrustedScriptURL to works FAIL Blocking non-TrustedScriptURL assignment to works assert_throws_js: function "_ => { - elem.setAttributeNS(xlink, "href", v); + elem.setAttributeNS(xlinkNamespace, "href", v); }" did not throw +PASS Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute "SRCDOC" (ns=null) for "iframe" element (ns=http://www.w3.org/1999/xhtml). +PASS Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute "SRC" (ns=null) for "embed" element (ns=http://www.w3.org/1999/xhtml). +PASS Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute "SRC" (ns=null) for "script" element (ns=http://www.w3.org/1999/xhtml). +PASS Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute "DATA" (ns=null) for "object" element (ns=http://www.w3.org/1999/xhtml). +PASS Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute "CODEBASE" (ns=null) for "object" element (ns=http://www.w3.org/1999/xhtml). +PASS Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute "HREF" (ns=null) for "script" element (ns=http://www.w3.org/2000/svg). +PASS Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute "HREF" (ns=http://www.w3.org/1999/xlink) for "script" element (ns=http://www.w3.org/2000/svg). diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS.html index 346e077a6665..b7f74be6b7dd 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS.html +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS.html @@ -21,13 +21,15 @@ assert_element_accepts_trusted_script_url_set_ns(window, '2', t, 'a', 'b', RESULTS.SCRIPTURL); }, "Element.setAttributeNS assigned via policy (successful ScriptURL transformation)"); - // Unknown, namespaced attributes should not be TT checked: + const htmlNamespace = "http://www.w3.org/1999/xhtml"; + + // Unknown attributes should not be TT checked: test(t => { - assert_element_accepts_non_trusted_type_set_ns('a', 'b', 'A string', 'A string'); + assert_element_accepts_non_trusted_type_set_ns('a', 'b', 'A string', 'A string', htmlNamespace, null); }, "Element.setAttributeNS accepts untrusted string for non-specced accessor"); test(t => { - assert_element_accepts_non_trusted_type_set_ns('a', 'b', null, 'null'); + assert_element_accepts_non_trusted_type_set_ns('a', 'b', null, 'null', htmlNamespace, null); }, "Element.setAttributeNS accepts null for non-specced accessor"); // Setup trusted values for use in subsequent tests. @@ -35,26 +37,49 @@ const html = createHTML_policy(window, '6').createHTML(INPUTS.HTML); const script = createScript_policy(window, '7').createScript(INPUTS.Script); - const xlink = "http://www.w3.org/1999/xlink"; - const svg = "http://www.w3.org/2000/svg"; + const xlinkNamespace = "http://www.w3.org/1999/xlink"; + const svgNamespace = "http://www.w3.org/2000/svg"; // svg:script xlink:href=... expects a TrustedScriptURL. // Assigning a TrustedScriptURL works. test(t => { - let elem = document.createElementNS(svg, "script"); - elem.setAttributeNS(xlink, "href", script_url); + let elem = document.createElementNS(svgNamespace, "script"); + elem.setAttributeNS(xlinkNamespace, "href", script_url); assert_equals("" + RESULTS.ScriptURL, - elem.getAttributeNodeNS(xlink, "href").value); + elem.getAttributeNodeNS(xlinkNamespace, "href").value); }, "Assigning TrustedScriptURL to works"); // Assigning things that ought to not work. test(t => { - let elem = document.createElementNS(svg, "script"); + let elem = document.createElementNS(svgNamespace, "script"); const values = [ "abc", null, html, script ]; for (const v of values) { assert_throws_js(TypeError, _ => { - elem.setAttributeNS(xlink, "href", v); + elem.setAttributeNS(xlinkNamespace, "href", v); }); } }, "Blocking non-TrustedScriptURL assignment to works"); + + // . + const nonLowerCaseTests = [ + { element: "iframe", attribute: "SRCDOC", elementNamespace: htmlNamespace }, + { element: "embed", attribute: "SRC", elementNamespace: htmlNamespace }, + { element: "script", attribute: "SRC", elementNamespace: htmlNamespace }, + { element: "object", attribute: "DATA", elementNamespace: htmlNamespace }, + { element: "object", attribute: "CODEBASE", elementNamespace: htmlNamespace }, + { element: "script", attribute: "HREF", elementNamespace: svgNamespace }, + { element: "script", attribute: "HREF", elementNamespace: svgNamespace, + attributeNamespace: xlinkNamespace }, + ]; + + for (const testData of nonLowerCaseTests) { + const attributeNamespace = testData.attributeNamespace ?? null; + + test(t => { + assert_element_accepts_non_trusted_type_set_ns(testData.element, testData.attribute, "v", + "v", testData.elementNamespace, attributeNamespace); + }, "Check `setAttributeNS` allows setting non-trusted string for non-lowercase attribute \"" + + testData.attribute + "\" (ns=" + attributeNamespace + ") for \"" + testData.element + + "\" element (ns=" + testData.elementNamespace + ")."); + } diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe-expected.txt new file mode 100644 index 000000000000..09cfa7e58811 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe-expected.txt @@ -0,0 +1,9 @@ +CONSOLE MESSAGE: This requires a TrustedHTML value else it violates the following Content Security Policy directive: "require-trusted-types-for 'script'" +CONSOLE MESSAGE: This requires a TrustedHTML value else it violates the following Content Security Policy directive: "require-trusted-types-for 'script'" + +PASS element.setHTMLUnsafe(html) assigned via policy (successful HTML transformation). +PASS `element.setHTMLUnsafe(string)` throws. +PASS `element.setHTMLUnsafe(null)` throws. +PASS `element.setHTMLUnsafe(string)` assigned via default policy (successful HTML transformation). +PASS `element.setHTMLUnsafe(string)` assigned via default policy does not throw + diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe.html new file mode 100644 index 000000000000..34975f9d6883 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe.html @@ -0,0 +1,79 @@ + + + + + + + + + + + +
+ + + diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe-expected.txt new file mode 100644 index 000000000000..a000a249d13b --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe-expected.txt @@ -0,0 +1,9 @@ +CONSOLE MESSAGE: This requires a TrustedHTML value else it violates the following Content Security Policy directive: "require-trusted-types-for 'script'" +CONSOLE MESSAGE: This requires a TrustedHTML value else it violates the following Content Security Policy directive: "require-trusted-types-for 'script'" + +PASS shadowRoot.setHTMLUnsafe(html) assigned via policy (successful HTML transformation). +PASS `shadowRoot.setHTMLUnsafe(string)` throws. +PASS `shadowRoot.setHTMLUnsafe(null)` throws. +PASS `shadowRoot.setHTMLUnsafe(string)` assigned via default policy (successful HTML transformation). +PASS `shadowRoot.setHTMLUnsafe(string)` assigned via default policy does not throw + diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe.html new file mode 100644 index 000000000000..a76543b3f68c --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe.html @@ -0,0 +1,84 @@ + + + + + + + + + + + +
+ + + diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window-expected.txt new file mode 100644 index 000000000000..7054636d0692 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window-expected.txt @@ -0,0 +1,102 @@ + +PASS idl_test setup +PASS idl_test validation +PASS Partial interface mixin WindowOrWorkerGlobalScope: original interface mixin defined +PASS Partial interface mixin WindowOrWorkerGlobalScope: member names are unique +PASS Partial interface Window: member names are unique +PASS Window includes GlobalEventHandlers: member names are unique +PASS Window includes WindowEventHandlers: member names are unique +PASS Window includes WindowOrWorkerGlobalScope: member names are unique +PASS WorkerGlobalScope includes WindowOrWorkerGlobalScope: member names are unique +PASS Window includes AnimationFrameProvider: member names are unique +PASS Window includes WindowSessionStorage: member names are unique +PASS Window includes WindowLocalStorage: member names are unique +PASS TrustedHTML interface: existence and properties of interface object +PASS TrustedHTML interface object length +PASS TrustedHTML interface object name +PASS TrustedHTML interface: existence and properties of interface prototype object +PASS TrustedHTML interface: existence and properties of interface prototype object's "constructor" property +PASS TrustedHTML interface: existence and properties of interface prototype object's @@unscopables property +PASS TrustedHTML interface: stringifier +PASS TrustedHTML interface: operation toJSON() +PASS TrustedHTML must be primary interface of window.trustedTypes.createPolicy("SomeName1", { createHTML: s => s }).createHTML("A string") +PASS Stringification of window.trustedTypes.createPolicy("SomeName1", { createHTML: s => s }).createHTML("A string") +PASS TrustedHTML interface: window.trustedTypes.createPolicy("SomeName1", { createHTML: s => s }).createHTML("A string") must inherit property "toJSON()" with the proper type +PASS TrustedHTML interface: toJSON operation on window.trustedTypes.createPolicy("SomeName1", { createHTML: s => s }).createHTML("A string") +PASS TrustedScript interface: existence and properties of interface object +PASS TrustedScript interface object length +PASS TrustedScript interface object name +PASS TrustedScript interface: existence and properties of interface prototype object +PASS TrustedScript interface: existence and properties of interface prototype object's "constructor" property +PASS TrustedScript interface: existence and properties of interface prototype object's @@unscopables property +PASS TrustedScript interface: stringifier +PASS TrustedScript interface: operation toJSON() +PASS TrustedScript must be primary interface of window.trustedTypes.createPolicy("SomeName2", { createScript: s => s }).createScript("A string") +PASS Stringification of window.trustedTypes.createPolicy("SomeName2", { createScript: s => s }).createScript("A string") +PASS TrustedScript interface: window.trustedTypes.createPolicy("SomeName2", { createScript: s => s }).createScript("A string") must inherit property "toJSON()" with the proper type +PASS TrustedScript interface: toJSON operation on window.trustedTypes.createPolicy("SomeName2", { createScript: s => s }).createScript("A string") +PASS TrustedScriptURL interface: existence and properties of interface object +PASS TrustedScriptURL interface object length +PASS TrustedScriptURL interface object name +PASS TrustedScriptURL interface: existence and properties of interface prototype object +PASS TrustedScriptURL interface: existence and properties of interface prototype object's "constructor" property +PASS TrustedScriptURL interface: existence and properties of interface prototype object's @@unscopables property +PASS TrustedScriptURL interface: stringifier +PASS TrustedScriptURL interface: operation toJSON() +PASS TrustedScriptURL must be primary interface of window.trustedTypes.createPolicy("SomeName3", { createScriptURL: s => s }).createScriptURL("A string") +PASS Stringification of window.trustedTypes.createPolicy("SomeName3", { createScriptURL: s => s }).createScriptURL("A string") +PASS TrustedScriptURL interface: window.trustedTypes.createPolicy("SomeName3", { createScriptURL: s => s }).createScriptURL("A string") must inherit property "toJSON()" with the proper type +PASS TrustedScriptURL interface: toJSON operation on window.trustedTypes.createPolicy("SomeName3", { createScriptURL: s => s }).createScriptURL("A string") +PASS TrustedTypePolicyFactory interface: existence and properties of interface object +PASS TrustedTypePolicyFactory interface object length +PASS TrustedTypePolicyFactory interface object name +PASS TrustedTypePolicyFactory interface: existence and properties of interface prototype object +PASS TrustedTypePolicyFactory interface: existence and properties of interface prototype object's "constructor" property +PASS TrustedTypePolicyFactory interface: existence and properties of interface prototype object's @@unscopables property +PASS TrustedTypePolicyFactory interface: operation createPolicy(DOMString, optional TrustedTypePolicyOptions) +PASS TrustedTypePolicyFactory interface: operation isHTML(any) +PASS TrustedTypePolicyFactory interface: operation isScript(any) +PASS TrustedTypePolicyFactory interface: operation isScriptURL(any) +PASS TrustedTypePolicyFactory interface: attribute emptyHTML +PASS TrustedTypePolicyFactory interface: attribute emptyScript +PASS TrustedTypePolicyFactory interface: operation getAttributeType(DOMString, DOMString, optional DOMString, optional DOMString) +PASS TrustedTypePolicyFactory interface: operation getPropertyType(DOMString, DOMString, optional DOMString) +PASS TrustedTypePolicyFactory interface: attribute defaultPolicy +PASS TrustedTypePolicyFactory must be primary interface of window.trustedTypes +PASS Stringification of window.trustedTypes +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "createPolicy(DOMString, optional TrustedTypePolicyOptions)" with the proper type +PASS TrustedTypePolicyFactory interface: calling createPolicy(DOMString, optional TrustedTypePolicyOptions) on window.trustedTypes with too few arguments must throw TypeError +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "isHTML(any)" with the proper type +PASS TrustedTypePolicyFactory interface: calling isHTML(any) on window.trustedTypes with too few arguments must throw TypeError +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "isScript(any)" with the proper type +PASS TrustedTypePolicyFactory interface: calling isScript(any) on window.trustedTypes with too few arguments must throw TypeError +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "isScriptURL(any)" with the proper type +PASS TrustedTypePolicyFactory interface: calling isScriptURL(any) on window.trustedTypes with too few arguments must throw TypeError +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "emptyHTML" with the proper type +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "emptyScript" with the proper type +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "getAttributeType(DOMString, DOMString, optional DOMString, optional DOMString)" with the proper type +PASS TrustedTypePolicyFactory interface: calling getAttributeType(DOMString, DOMString, optional DOMString, optional DOMString) on window.trustedTypes with too few arguments must throw TypeError +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "getPropertyType(DOMString, DOMString, optional DOMString)" with the proper type +PASS TrustedTypePolicyFactory interface: calling getPropertyType(DOMString, DOMString, optional DOMString) on window.trustedTypes with too few arguments must throw TypeError +PASS TrustedTypePolicyFactory interface: window.trustedTypes must inherit property "defaultPolicy" with the proper type +PASS TrustedTypePolicy interface: existence and properties of interface object +PASS TrustedTypePolicy interface object length +PASS TrustedTypePolicy interface object name +PASS TrustedTypePolicy interface: existence and properties of interface prototype object +PASS TrustedTypePolicy interface: existence and properties of interface prototype object's "constructor" property +PASS TrustedTypePolicy interface: existence and properties of interface prototype object's @@unscopables property +PASS TrustedTypePolicy interface: attribute name +PASS TrustedTypePolicy interface: operation createHTML(DOMString, any...) +PASS TrustedTypePolicy interface: operation createScript(DOMString, any...) +PASS TrustedTypePolicy interface: operation createScriptURL(DOMString, any...) +PASS TrustedTypePolicy must be primary interface of window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) +PASS Stringification of window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) +PASS TrustedTypePolicy interface: window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) must inherit property "name" with the proper type +PASS TrustedTypePolicy interface: window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) must inherit property "createHTML(DOMString, any...)" with the proper type +PASS TrustedTypePolicy interface: calling createHTML(DOMString, any...) on window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) with too few arguments must throw TypeError +PASS TrustedTypePolicy interface: window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) must inherit property "createScript(DOMString, any...)" with the proper type +PASS TrustedTypePolicy interface: calling createScript(DOMString, any...) on window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) with too few arguments must throw TypeError +PASS TrustedTypePolicy interface: window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) must inherit property "createScriptURL(DOMString, any...)" with the proper type +PASS TrustedTypePolicy interface: calling createScriptURL(DOMString, any...) on window.trustedTypes.createPolicy("SomeName", { createHTML: s => s }) with too few arguments must throw TypeError +PASS Window interface: attribute trustedTypes + diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.html new file mode 100644 index 000000000000..2382913528e6 --- /dev/null +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.tentative.window.js.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.js similarity index 100% rename from LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.tentative.window.js.html rename to LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.js diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/support/helper.sub.js b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/support/helper.sub.js index 2d1bd436bdf3..1775cd985c24 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/support/helper.sub.js +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/support/helper.sub.js @@ -125,7 +125,7 @@ function assert_element_accepts_non_trusted_type_explicit_set(tag, attribute, va assert_equals(elem.getAttribute(attribute), expected); } -let namespace = 'http://www.w3.org/1999/xhtml'; +let namespace = null; function assert_element_accepts_trusted_html_set_ns(win, c, t, tag, attribute, expected) { let p = createHTML_policy(win, c); let html = p.createHTML(INPUTS.HTML); @@ -158,9 +158,10 @@ function assert_throws_no_trusted_type_set_ns(tag, attribute, value) { }); } -function assert_element_accepts_non_trusted_type_set_ns(tag, attribute, value, expected) { - let elem = document.createElement(tag); - elem.setAttributeNS(namespace, attribute, value); - let attr_node = elem.getAttributeNodeNS(namespace, attribute); +function assert_element_accepts_non_trusted_type_set_ns(tag, attribute, value, expected, + elementNamespace, attributeNamespace) { + let elem = document.createElementNS(elementNamespace, tag); + elem.setAttributeNS(attributeNamespace, attribute, value); + let attr_node = elem.getAttributeNodeNS(attributeNamespace, attribute); assert_equals(attr_node.value + "", expected); } diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.tentative-expected.txt similarity index 100% rename from LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal-expected.txt rename to LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.tentative-expected.txt diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.html b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.tentative.html similarity index 100% rename from LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.html rename to LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.tentative.html diff --git a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/w3c-import.log b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/w3c-import.log index 4c4ec73bb808..c348f017794d 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/trusted-types/w3c-import.log +++ b/LayoutTests/imported/w3c/web-platform-tests/trusted-types/w3c-import.log @@ -35,7 +35,7 @@ List of files: /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicy-CSP-no-name.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicy-CSP-wildcard.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicy-createXXX.html -/LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.html +/LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-blocking.tentative.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-constants.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-createPolicy-createXYZTests.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-createPolicy-cspTests-noNamesGiven.html @@ -47,6 +47,7 @@ List of files: /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-createPolicy-unenforced.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-defaultPolicy.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-getAttributeType-namespace.html +/LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-getAttributeType-svg.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-getPropertyType.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-isXXX.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/TrustedTypePolicyFactory-metadata.html @@ -57,13 +58,16 @@ List of files: /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-Node-multiple-arguments.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-DOMParser-parseFromString.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-DOMWindowTimers-setTimeout-setInterval.html +/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-parseHTMLUnsafe.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Document-write.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-outerHTML.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttribute.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setAttributeNS.html +/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Element-setHTMLUnsafe.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-HTMLElement-generic.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-Range-createContextualFragment.html +/LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-ShadowRoot-setHTMLUnsafe.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-string-assignment-to-attribute-via-attribute-node.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/block-text-node-insertion-into-script-element.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/csp-block-eval.html @@ -83,7 +87,7 @@ List of files: /LayoutTests/imported/w3c/web-platform-tests/trusted-types/eval-no-csp-no-tt-default-policy.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/eval-no-csp-no-tt.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/eval-with-permissive-csp.html -/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.tentative.window.js.html +/LayoutTests/imported/w3c/web-platform-tests/trusted-types/idlharness.window.js /LayoutTests/imported/w3c/web-platform-tests/trusted-types/no-require-trusted-types-for-report-only.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/no-require-trusted-types-for-report-only.html.headers /LayoutTests/imported/w3c/web-platform-tests/trusted-types/no-require-trusted-types-for.html @@ -103,7 +107,7 @@ List of files: /LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-eval-reporting.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-eval-reporting.html.headers /LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-event-handlers.html -/LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.html +/LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-from-literal.tentative.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-navigation.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-report-only.html /LayoutTests/imported/w3c/web-platform-tests/trusted-types/trusted-types-report-only.html.headers