diff --git a/parser/xml/test/unit/test_sanitizer_style.js b/parser/xml/test/unit/test_sanitizer_style.js new file mode 100644 index 000000000000..0d855d8a41b3 --- /dev/null +++ b/parser/xml/test/unit/test_sanitizer_style.js @@ -0,0 +1,105 @@ +const { AppConstants } = ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" +); + +if (AppConstants.platform != "android") { + // We load HTML documents, which try to track link state, which requires + // the history service, which requires a profile. + do_get_profile(); +} + +const kTestCases = [ + { + // bug 1602843 + data: `@font-face { font-family: 'ab<\\/style>'}`, + sanitized: `@font-face { font-family: 'ab<\\/style>'}`, + }, + { + // bug 1680084 + data: ``, + sanitized: `@font-face + {font-family:"Cambria Math"; + panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face + {font-family:"Yu Gothic"; + panose-1:2 11 4 0 0 0 0 0 0 0;}@font-face + {font-family:"Yu Gothic"; + panose-1:2 11 4 0 0 0 0 0 0 0;}p.MsoNormal, li.MsoNormal, div.MsoNormal + {margin:0mm; + text-align:justify; + text-justify:inter-ideograph; + font-size:10.5pt; + font-family:"Yu Gothic";}.MsoChpDefault + {mso-style-type:export-only; + font-family:"Yu Gothic";}div.WordSection1 + {page:WordSection1}`, + }, +]; + +function run_test() { + if (AppConstants.platform != "android") { + // xpcshell tests are weird. They fake shutdown after the test finishes. This upsets this test + // because it will try to create the history service to check for visited state on the links + // we're parsing. + // Creating the history service midway through shutdown breaks. + // We can't catch this in the history component because we're not *actually* shutting down, + // and so the app startup's service's `shuttingDown` bool is false, even though normally that + // is set to true *before* profile-change-teardown notifications are fired. + // To work around this, just force the history service to be created earlier: + + let { PlacesUtils } = ChromeUtils.import( + "resource://gre/modules/PlacesUtils.jsm" + ); + Assert.ok( + PlacesUtils.history.databaseStatus <= 1, + "ensure places database is successfully initialized." + ); + } + + var ParserUtils = Cc["@mozilla.org/parserutils;1"].getService( + Ci.nsIParserUtils + ); + var sanitizeFlags = + ParserUtils.SanitizerDropForms | + ParserUtils.SanitizerDropNonCSSPresentation | + ParserUtils.SanitizerAllowStyle; + + for (let { data, sanitized } of kTestCases) { + let out = ParserUtils.sanitize(``, sanitizeFlags); + info(out); + Assert.equal( + ``, + out + ); + } +} diff --git a/parser/xml/test/unit/xpcshell.ini b/parser/xml/test/unit/xpcshell.ini index 51055c02c42f..4ae9918864ed 100644 --- a/parser/xml/test/unit/xpcshell.ini +++ b/parser/xml/test/unit/xpcshell.ini @@ -3,3 +3,4 @@ head = support-files = results.js [test_sanitizer.js] +[test_sanitizer_style.js]