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