|
| 1 | +// load the HTTPS Everywhere component |
| 2 | +var HTTPSEverywhere = null; |
| 3 | +try { |
| 4 | + HTTPSEverywhere = Components.classes["@eff.org/https-everywhere;1"] |
| 5 | + .getService(Components.interfaces.nsISupports) |
| 6 | + .wrappedJSObject; |
| 7 | +} catch(e) { |
| 8 | + // HTTPS Everywhere doesn't seem to be installed |
| 9 | +} |
| 10 | + |
| 11 | +// attach testRunner to the HTTPS Everywhere component so that status.js can run it |
| 12 | +if(HTTPSEverywhere) { |
| 13 | + HTTPSEverywhere.httpseRulesetTests = { |
| 14 | + testRunner: testRunner |
| 15 | + }; |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | +function openStatus() { |
| 20 | + // make sure mixed content blocking preferences are correct |
| 21 | + Services.prefs.setBoolPref("security.mixed_content.block_display_content", false); |
| 22 | + Services.prefs.setBoolPref("security.mixed_content.block_active_content", true); |
| 23 | + |
| 24 | + // open the status tab |
| 25 | + var statusTab = gBrowser.addTab('chrome://https-everywhere/content/ruleset-tests-status.xul'); |
| 26 | + gBrowser.selectedTab = statusTab; |
| 27 | +} |
| 28 | + |
| 29 | +function testRunner() { |
| 30 | + Components.utils.import("resource://gre/modules/PopupNotifications.jsm"); |
| 31 | + |
| 32 | + const numTabs = 6; |
| 33 | + var finished = false; |
| 34 | + var output = []; |
| 35 | + var urls = []; |
| 36 | + var num = 0; |
| 37 | + |
| 38 | + for(var target in HTTPSEverywhere.https_rules.targets) { |
| 39 | + if(!target.contains("*")) { |
| 40 | + urls.push({ |
| 41 | + url: 'https://'+target, |
| 42 | + target: target, |
| 43 | + ruleset_names: HTTPSEverywhere.https_rules.targets[target] |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + function test() { |
| 49 | + var i; |
| 50 | + |
| 51 | + HTTPSEverywhere.httpseRulesetTests.updateStatusBar(num, urls.length); |
| 52 | + |
| 53 | + // start loading all the tabs |
| 54 | + window.focus |
| 55 | + for(i=0; i<numTabs; i++) { |
| 56 | + newTab(num); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + function newTab(number) { |
| 61 | + num +=1; |
| 62 | + // start a test in this tab |
| 63 | + if(urls.length) { |
| 64 | + |
| 65 | + // open a new tab |
| 66 | + var tab = gBrowser.addTab(urls[number].url); |
| 67 | + |
| 68 | + // wait for the page to load |
| 69 | + var intervalId = window.setTimeout(function(){ |
| 70 | + |
| 71 | + // detect mixed content blocker |
| 72 | + if(PopupNotifications.getNotification("mixed-content-blocked", gBrowser.getBrowserForTab(tab))) { |
| 73 | + // build output to log |
| 74 | + ruleset_xmls = ''; |
| 75 | + for(let i=0; i<urls[number].ruleset_names.length; i++) { |
| 76 | + ruleset_xmls += urls[number].ruleset_names[i].xmlName + ', '; |
| 77 | + } |
| 78 | + if(ruleset_xmls != '') |
| 79 | + ruleset_xmls = ruleset_xmls.substring(ruleset_xmls.length-2, 2); |
| 80 | + var output = 'MCB triggered: '+urls[number].url+' ('+ruleset_xmls+')'; |
| 81 | + |
| 82 | + HTTPSEverywhere.httpseRulesetTests.updateLog(output); |
| 83 | + } |
| 84 | + |
| 85 | + // close this tab, and open another |
| 86 | + closeTab(tab); |
| 87 | + |
| 88 | + }, 10000); |
| 89 | + |
| 90 | + } else { |
| 91 | + |
| 92 | + //to run if urls is empty |
| 93 | + if (!finished) { |
| 94 | + finished = true; |
| 95 | + window.setTimeout(function(){ |
| 96 | + gBrowser.removeCurrentTab(); |
| 97 | + }, 10000); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + //closes tab |
| 103 | + function closeTab(tab) { |
| 104 | + HTTPSEverywhere.httpseRulesetTests.updateStatusBar(num, urls.length); |
| 105 | + |
| 106 | + gBrowser.selectedTab = tab; |
| 107 | + gBrowser.removeCurrentTab(); |
| 108 | + |
| 109 | + // open a new tab, if the tests haven't been canceled |
| 110 | + if(!HTTPSEverywhere.httpseRulesetTests.cancel) { |
| 111 | + newTab(num); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + //manages write out of output mochilog.txt, which contains sites that trigger mcb |
| 116 | + function writeout(weburl) { |
| 117 | + |
| 118 | + //initialize file |
| 119 | + var file = Components.classes["@mozilla.org/file/directory_service;1"]. |
| 120 | + getService(Components.interfaces.nsIProperties). |
| 121 | + get("Home", Components.interfaces.nsIFile); |
| 122 | + writeoutfile = "mochilog.txt"; |
| 123 | + file.append(writeoutfile); |
| 124 | + |
| 125 | + //create file if it does not already exist |
| 126 | + if(!file.exists()) { |
| 127 | + file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420); |
| 128 | + } |
| 129 | + |
| 130 | + //initialize output stream |
| 131 | + var stream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
| 132 | + .createInstance(Components.interfaces.nsIFileOutputStream); |
| 133 | + |
| 134 | + //permissions are set to append (will not delete existing contents) |
| 135 | + stream.init(file, 0x02 | 0x08 | 0x10, 0666, 0); |
| 136 | + |
| 137 | + var content = weburl + "\n"; |
| 138 | + |
| 139 | + //Deal with ascii text and write out |
| 140 | + var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"]. |
| 141 | + createInstance(Components.interfaces.nsIConverterOutputStream); |
| 142 | + converter.init(stream, "UTF-8", 0, 0); |
| 143 | + converter.writeString(content); |
| 144 | + converter.close(); |
| 145 | + |
| 146 | + //alternative write out if ascii is not a concern |
| 147 | + //stream.write(content,content.length); |
| 148 | + //stream.close(); |
| 149 | + |
| 150 | + } |
| 151 | + test(); |
| 152 | +} |
| 153 | + |
| 154 | + |
| 155 | + |
0 commit comments