browser/base/content/test/plugins/browser_clearplugindata.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /**
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5
michael@0 6 var rootDir = getRootDirectory(gTestPath);
michael@0 7 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/");
michael@0 8
michael@0 9 // Test clearing plugin data using sanitize.js.
michael@0 10 const testURL1 = gHttpTestRoot + "browser_clearplugindata.html";
michael@0 11 const testURL2 = gHttpTestRoot + "browser_clearplugindata_noage.html";
michael@0 12
michael@0 13 let tempScope = {};
michael@0 14 Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
michael@0 15 .loadSubScript("chrome://browser/content/sanitize.js", tempScope);
michael@0 16 let Sanitizer = tempScope.Sanitizer;
michael@0 17
michael@0 18 const pluginHostIface = Ci.nsIPluginHost;
michael@0 19 var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
michael@0 20 pluginHost.QueryInterface(pluginHostIface);
michael@0 21
michael@0 22 var pluginTag = getTestPlugin();
michael@0 23 var s;
michael@0 24
michael@0 25 function stored(needles) {
michael@0 26 var something = pluginHost.siteHasData(this.pluginTag, null);
michael@0 27 if (!needles)
michael@0 28 return something;
michael@0 29
michael@0 30 if (!something)
michael@0 31 return false;
michael@0 32
michael@0 33 for (var i = 0; i < needles.length; ++i) {
michael@0 34 if (!pluginHost.siteHasData(this.pluginTag, needles[i]))
michael@0 35 return false;
michael@0 36 }
michael@0 37 return true;
michael@0 38 }
michael@0 39
michael@0 40 function test() {
michael@0 41 waitForExplicitFinish();
michael@0 42 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED);
michael@0 43
michael@0 44 s = new Sanitizer();
michael@0 45 s.ignoreTimespan = false;
michael@0 46 s.prefDomain = "privacy.cpd.";
michael@0 47 var itemPrefs = gPrefService.getBranch(s.prefDomain);
michael@0 48 itemPrefs.setBoolPref("history", false);
michael@0 49 itemPrefs.setBoolPref("downloads", false);
michael@0 50 itemPrefs.setBoolPref("cache", false);
michael@0 51 itemPrefs.setBoolPref("cookies", true); // plugin data
michael@0 52 itemPrefs.setBoolPref("formdata", false);
michael@0 53 itemPrefs.setBoolPref("offlineApps", false);
michael@0 54 itemPrefs.setBoolPref("passwords", false);
michael@0 55 itemPrefs.setBoolPref("sessions", false);
michael@0 56 itemPrefs.setBoolPref("siteSettings", false);
michael@0 57
michael@0 58 executeSoon(test_with_age);
michael@0 59 }
michael@0 60
michael@0 61 function setFinishedCallback(callback)
michael@0 62 {
michael@0 63 let testPage = gBrowser.selectedBrowser.contentWindow.wrappedJSObject;
michael@0 64 testPage.testFinishedCallback = function() {
michael@0 65 setTimeout(function() {
michael@0 66 info("got finished callback");
michael@0 67 callback();
michael@0 68 }, 0);
michael@0 69 }
michael@0 70 }
michael@0 71
michael@0 72 function test_with_age()
michael@0 73 {
michael@0 74 // Load page to set data for the plugin.
michael@0 75 gBrowser.selectedTab = gBrowser.addTab();
michael@0 76 gBrowser.selectedBrowser.addEventListener("load", function () {
michael@0 77 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 78
michael@0 79 setFinishedCallback(function() {
michael@0 80 ok(stored(["foo.com","bar.com","baz.com","qux.com"]),
michael@0 81 "Data stored for sites");
michael@0 82
michael@0 83 // Clear 20 seconds ago
michael@0 84 var now_uSec = Date.now() * 1000;
michael@0 85 s.range = [now_uSec - 20*1000000, now_uSec];
michael@0 86 s.sanitize();
michael@0 87
michael@0 88 ok(stored(["bar.com","qux.com"]), "Data stored for sites");
michael@0 89 ok(!stored(["foo.com"]), "Data cleared for foo.com");
michael@0 90 ok(!stored(["baz.com"]), "Data cleared for baz.com");
michael@0 91
michael@0 92 // Clear everything
michael@0 93 s.range = null;
michael@0 94 s.sanitize();
michael@0 95
michael@0 96 ok(!stored(null), "All data cleared");
michael@0 97
michael@0 98 gBrowser.removeCurrentTab();
michael@0 99
michael@0 100 executeSoon(test_without_age);
michael@0 101 });
michael@0 102 }, true);
michael@0 103 content.location = testURL1;
michael@0 104 }
michael@0 105
michael@0 106 function test_without_age()
michael@0 107 {
michael@0 108 // Load page to set data for the plugin.
michael@0 109 gBrowser.selectedTab = gBrowser.addTab();
michael@0 110 gBrowser.selectedBrowser.addEventListener("load", function () {
michael@0 111 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 112
michael@0 113 setFinishedCallback(function() {
michael@0 114 ok(stored(["foo.com","bar.com","baz.com","qux.com"]),
michael@0 115 "Data stored for sites");
michael@0 116
michael@0 117 // Attempt to clear 20 seconds ago. The plugin will throw
michael@0 118 // NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED, which should result in us
michael@0 119 // clearing all data regardless of age.
michael@0 120 var now_uSec = Date.now() * 1000;
michael@0 121 s.range = [now_uSec - 20*1000000, now_uSec];
michael@0 122 s.sanitize();
michael@0 123
michael@0 124 ok(!stored(null), "All data cleared");
michael@0 125
michael@0 126 gBrowser.removeCurrentTab();
michael@0 127
michael@0 128 executeSoon(finish);
michael@0 129 });
michael@0 130 }, true);
michael@0 131 content.location = testURL2;
michael@0 132 }
michael@0 133

mercurial