summaryrefslogtreecommitdiffstats
path: root/parser/xml/test/unit/test_sanitizer.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /parser/xml/test/unit/test_sanitizer.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'parser/xml/test/unit/test_sanitizer.js')
-rw-r--r--parser/xml/test/unit/test_sanitizer.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/parser/xml/test/unit/test_sanitizer.js b/parser/xml/test/unit/test_sanitizer.js
new file mode 100644
index 0000000000..814940578d
--- /dev/null
+++ b/parser/xml/test/unit/test_sanitizer.js
@@ -0,0 +1,53 @@
+const { AppConstants } = ChromeUtils.importESModule(
+ "resource://gre/modules/AppConstants.sys.mjs"
+);
+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();
+}
+
+function run_test() {
+ // vectors by the html5security project (https://code.google.com/p/html5security/ & Creative Commons 3.0 BY), see CC-BY-LICENSE for the full license
+ load("results.js"); // gives us a `vectors' array
+ /* import-globals-from ./results.js */
+
+ 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.importESModule(
+ "resource://gre/modules/PlacesUtils.sys.mjs"
+ );
+ 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.SanitizerCidEmbedsOnly |
+ ParserUtils.SanitizerDropForms |
+ ParserUtils.SanitizerDropNonCSSPresentation;
+ // flags according to
+ // http://mxr.mozilla.org/comm-central/source/mailnews/mime/src/mimemoz2.cpp#2218
+ // and default settings
+
+ for (var item in vectors) {
+ let { data, sanitized, flags } = vectors[item];
+ if (!flags) {
+ flags = sanitizeFlags;
+ }
+ var out = ParserUtils.sanitize(data, flags);
+ Assert.equal(sanitized, out);
+ }
+}