1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_clearplugindata.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,133 @@ 1.4 +/** 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +var rootDir = getRootDirectory(gTestPath); 1.10 +const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/"); 1.11 + 1.12 +// Test clearing plugin data using sanitize.js. 1.13 +const testURL1 = gHttpTestRoot + "browser_clearplugindata.html"; 1.14 +const testURL2 = gHttpTestRoot + "browser_clearplugindata_noage.html"; 1.15 + 1.16 +let tempScope = {}; 1.17 +Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader) 1.18 + .loadSubScript("chrome://browser/content/sanitize.js", tempScope); 1.19 +let Sanitizer = tempScope.Sanitizer; 1.20 + 1.21 +const pluginHostIface = Ci.nsIPluginHost; 1.22 +var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); 1.23 +pluginHost.QueryInterface(pluginHostIface); 1.24 + 1.25 +var pluginTag = getTestPlugin(); 1.26 +var s; 1.27 + 1.28 +function stored(needles) { 1.29 + var something = pluginHost.siteHasData(this.pluginTag, null); 1.30 + if (!needles) 1.31 + return something; 1.32 + 1.33 + if (!something) 1.34 + return false; 1.35 + 1.36 + for (var i = 0; i < needles.length; ++i) { 1.37 + if (!pluginHost.siteHasData(this.pluginTag, needles[i])) 1.38 + return false; 1.39 + } 1.40 + return true; 1.41 +} 1.42 + 1.43 +function test() { 1.44 + waitForExplicitFinish(); 1.45 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED); 1.46 + 1.47 + s = new Sanitizer(); 1.48 + s.ignoreTimespan = false; 1.49 + s.prefDomain = "privacy.cpd."; 1.50 + var itemPrefs = gPrefService.getBranch(s.prefDomain); 1.51 + itemPrefs.setBoolPref("history", false); 1.52 + itemPrefs.setBoolPref("downloads", false); 1.53 + itemPrefs.setBoolPref("cache", false); 1.54 + itemPrefs.setBoolPref("cookies", true); // plugin data 1.55 + itemPrefs.setBoolPref("formdata", false); 1.56 + itemPrefs.setBoolPref("offlineApps", false); 1.57 + itemPrefs.setBoolPref("passwords", false); 1.58 + itemPrefs.setBoolPref("sessions", false); 1.59 + itemPrefs.setBoolPref("siteSettings", false); 1.60 + 1.61 + executeSoon(test_with_age); 1.62 +} 1.63 + 1.64 +function setFinishedCallback(callback) 1.65 +{ 1.66 + let testPage = gBrowser.selectedBrowser.contentWindow.wrappedJSObject; 1.67 + testPage.testFinishedCallback = function() { 1.68 + setTimeout(function() { 1.69 + info("got finished callback"); 1.70 + callback(); 1.71 + }, 0); 1.72 + } 1.73 +} 1.74 + 1.75 +function test_with_age() 1.76 +{ 1.77 + // Load page to set data for the plugin. 1.78 + gBrowser.selectedTab = gBrowser.addTab(); 1.79 + gBrowser.selectedBrowser.addEventListener("load", function () { 1.80 + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); 1.81 + 1.82 + setFinishedCallback(function() { 1.83 + ok(stored(["foo.com","bar.com","baz.com","qux.com"]), 1.84 + "Data stored for sites"); 1.85 + 1.86 + // Clear 20 seconds ago 1.87 + var now_uSec = Date.now() * 1000; 1.88 + s.range = [now_uSec - 20*1000000, now_uSec]; 1.89 + s.sanitize(); 1.90 + 1.91 + ok(stored(["bar.com","qux.com"]), "Data stored for sites"); 1.92 + ok(!stored(["foo.com"]), "Data cleared for foo.com"); 1.93 + ok(!stored(["baz.com"]), "Data cleared for baz.com"); 1.94 + 1.95 + // Clear everything 1.96 + s.range = null; 1.97 + s.sanitize(); 1.98 + 1.99 + ok(!stored(null), "All data cleared"); 1.100 + 1.101 + gBrowser.removeCurrentTab(); 1.102 + 1.103 + executeSoon(test_without_age); 1.104 + }); 1.105 + }, true); 1.106 + content.location = testURL1; 1.107 +} 1.108 + 1.109 +function test_without_age() 1.110 +{ 1.111 + // Load page to set data for the plugin. 1.112 + gBrowser.selectedTab = gBrowser.addTab(); 1.113 + gBrowser.selectedBrowser.addEventListener("load", function () { 1.114 + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); 1.115 + 1.116 + setFinishedCallback(function() { 1.117 + ok(stored(["foo.com","bar.com","baz.com","qux.com"]), 1.118 + "Data stored for sites"); 1.119 + 1.120 + // Attempt to clear 20 seconds ago. The plugin will throw 1.121 + // NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED, which should result in us 1.122 + // clearing all data regardless of age. 1.123 + var now_uSec = Date.now() * 1000; 1.124 + s.range = [now_uSec - 20*1000000, now_uSec]; 1.125 + s.sanitize(); 1.126 + 1.127 + ok(!stored(null), "All data cleared"); 1.128 + 1.129 + gBrowser.removeCurrentTab(); 1.130 + 1.131 + executeSoon(finish); 1.132 + }); 1.133 + }, true); 1.134 + content.location = testURL2; 1.135 +} 1.136 +