test_sanitizer.js (2109B)
1 const { AppConstants } = ChromeUtils.importESModule( 2 "resource://gre/modules/AppConstants.sys.mjs" 3 ); 4 if (AppConstants.platform != "android") { 5 // We load HTML documents, which try to track link state, which requires 6 // the history service, which requires a profile. 7 do_get_profile(); 8 } 9 10 function run_test() { 11 // vectors by the html5security project (https://code.google.com/p/html5security/ & Creative Commons 3.0 BY), see CC-BY-LICENSE for the full license 12 load("results.js"); // gives us a `vectors' array 13 /* import-globals-from ./results.js */ 14 15 if (AppConstants.platform != "android") { 16 // xpcshell tests are weird. They fake shutdown after the test finishes. This upsets this test 17 // because it will try to create the history service to check for visited state on the links 18 // we're parsing. 19 // Creating the history service midway through shutdown breaks. 20 // We can't catch this in the history component because we're not *actually* shutting down, 21 // and so the app startup's service's `shuttingDown` bool is false, even though normally that 22 // is set to true *before* profile-change-teardown notifications are fired. 23 // To work around this, just force the history service to be created earlier: 24 25 let { PlacesUtils } = ChromeUtils.importESModule( 26 "resource://gre/modules/PlacesUtils.sys.mjs" 27 ); 28 Assert.lessOrEqual( 29 PlacesUtils.history.databaseStatus, 30 1, 31 "ensure places database is successfully initialized." 32 ); 33 } 34 35 var ParserUtils = Cc["@mozilla.org/parserutils;1"].getService( 36 Ci.nsIParserUtils 37 ); 38 var sanitizeFlags = 39 ParserUtils.SanitizerCidEmbedsOnly | 40 ParserUtils.SanitizerDropForms | 41 ParserUtils.SanitizerDropNonCSSPresentation; 42 // flags according to 43 // http://mxr.mozilla.org/comm-central/source/mailnews/mime/src/mimemoz2.cpp#2218 44 // and default settings 45 46 for (var item in vectors) { 47 let { data, sanitized, flags } = vectors[item]; 48 if (!flags) { 49 flags = sanitizeFlags; 50 } 51 var out = ParserUtils.sanitize(data, flags); 52 Assert.equal(sanitized, out); 53 } 54 }