/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ const { QuoteSanitizer } = ChromeUtils.importESModule( "resource:///modules/QuoteSanitizer.sys.mjs" ); function makeDoc(html) { return new DOMParser().parseFromString(html, "text/html"); } // Phase 1: Body attribute stripping. add_task(function test_bodyColorAttributesRemoved() { const doc = makeDoc( '
' + "" ); QuoteSanitizer.sanitize(doc, false); for (const attr of [ "bgcolor", "text", "background", "link", "vlink", "alink", ]) { Assert.ok( !doc.body.hasAttribute(attr), `Body attribute "${attr}" should be removed` ); } Assert.equal( doc.body.getAttribute("class"), "keep-me", "Non-color body attributes should be preserved" ); }); add_task(function test_bodyInlineColorStylesRemoved() { const doc = makeDoc( '' ); QuoteSanitizer.sanitize(doc, false); Assert.equal( doc.body.style.getPropertyValue("background-color"), "", "background-color should be removed" ); Assert.equal( doc.body.style.getPropertyValue("background"), "", "background should be removed" ); Assert.equal( doc.body.style.getPropertyValue("color"), "", "color should be removed" ); Assert.equal( doc.body.style.getPropertyValue("font-size"), "14px", "Non-color styles should be preserved" ); }); // Phase 2: ' + "Quoted text