1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/forgetaboutsite/test/browser/browser_clearplugindata.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 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 +Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm"); 1.10 + 1.11 +// Test clearing plugin data by domain using ForgetAboutSite. 1.12 +const testURL = "http://mochi.test:8888/browser/toolkit/forgetaboutsite/test/browser/browser_clearplugindata.html"; 1.13 + 1.14 +const pluginHostIface = Ci.nsIPluginHost; 1.15 +var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); 1.16 +pluginHost.QueryInterface(pluginHostIface); 1.17 + 1.18 +var pluginTag; 1.19 + 1.20 +function stored(needles) { 1.21 + var something = pluginHost.siteHasData(this.pluginTag, null); 1.22 + if (!needles) 1.23 + return something; 1.24 + 1.25 + if (!something) 1.26 + return false; 1.27 + 1.28 + for (var i = 0; i < needles.length; ++i) { 1.29 + if (!pluginHost.siteHasData(this.pluginTag, needles[i])) 1.30 + return false; 1.31 + } 1.32 + return true; 1.33 +} 1.34 + 1.35 +function setTestPluginEnabledState(newEnabledState, plugin) { 1.36 + var oldEnabledState = plugin.enabledState; 1.37 + plugin.enabledState = newEnabledState; 1.38 + SimpleTest.registerCleanupFunction(function() { 1.39 + plugin.enabledState = oldEnabledState; 1.40 + }); 1.41 +} 1.42 + 1.43 +function test() { 1.44 + waitForExplicitFinish(); 1.45 + 1.46 + var tags = pluginHost.getPluginTags(); 1.47 + 1.48 + // Find the test plugin 1.49 + for (var i = 0; i < tags.length; i++) 1.50 + { 1.51 + if (tags[i].name == "Test Plug-in") 1.52 + { 1.53 + pluginTag = tags[i]; 1.54 + } 1.55 + } 1.56 + if (!pluginTag) { 1.57 + ok(false, "Test Plug-in not available, can't run test"); 1.58 + finish(); 1.59 + } 1.60 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, pluginTag); 1.61 + 1.62 + executeSoon(do_test); 1.63 +} 1.64 + 1.65 +function setFinishedCallback(callback) 1.66 +{ 1.67 + let testPage = gBrowser.selectedBrowser.contentWindow.wrappedJSObject; 1.68 + testPage.testFinishedCallback = function() { 1.69 + setTimeout(function() { 1.70 + info("got finished callback"); 1.71 + callback(); 1.72 + }, 0); 1.73 + } 1.74 +} 1.75 + 1.76 +function do_test() 1.77 +{ 1.78 + // Load page to set data for the plugin. 1.79 + gBrowser.selectedTab = gBrowser.addTab(); 1.80 + gBrowser.selectedBrowser.addEventListener("load", function () { 1.81 + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); 1.82 + 1.83 + setFinishedCallback(function() { 1.84 + ok(stored(["192.168.1.1","foo.com","nonexistent.foo.com","bar.com","localhost"]), 1.85 + "Data stored for sites"); 1.86 + 1.87 + // Clear data for "foo.com" and its subdomains. 1.88 + ForgetAboutSite.removeDataFromDomain("foo.com"); 1.89 + ok(stored(["bar.com","192.168.1.1","localhost"]), "Data stored for sites"); 1.90 + ok(!stored(["foo.com"]), "Data cleared for foo.com"); 1.91 + ok(!stored(["bar.foo.com"]), "Data cleared for subdomains of foo.com"); 1.92 + 1.93 + // Clear data for "bar.com" using a subdomain. 1.94 + ForgetAboutSite.removeDataFromDomain("foo.bar.com"); 1.95 + ok(!stored(["bar.com"]), "Data cleared for bar.com"); 1.96 + 1.97 + // Clear data for "192.168.1.1". 1.98 + ForgetAboutSite.removeDataFromDomain("192.168.1.1"); 1.99 + ok(!stored(["192.168.1.1"]), "Data cleared for 192.168.1.1"); 1.100 + 1.101 + // Clear data for "localhost". 1.102 + ForgetAboutSite.removeDataFromDomain("localhost"); 1.103 + ok(!stored(null), "All data cleared"); 1.104 + 1.105 + gBrowser.removeCurrentTab(); 1.106 + 1.107 + executeSoon(finish); 1.108 + }); 1.109 + }, true); 1.110 + content.location = testURL; 1.111 +} 1.112 +