toolkit/forgetaboutsite/test/browser/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 Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm");
michael@0 7
michael@0 8 // Test clearing plugin data by domain using ForgetAboutSite.
michael@0 9 const testURL = "http://mochi.test:8888/browser/toolkit/forgetaboutsite/test/browser/browser_clearplugindata.html";
michael@0 10
michael@0 11 const pluginHostIface = Ci.nsIPluginHost;
michael@0 12 var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
michael@0 13 pluginHost.QueryInterface(pluginHostIface);
michael@0 14
michael@0 15 var pluginTag;
michael@0 16
michael@0 17 function stored(needles) {
michael@0 18 var something = pluginHost.siteHasData(this.pluginTag, null);
michael@0 19 if (!needles)
michael@0 20 return something;
michael@0 21
michael@0 22 if (!something)
michael@0 23 return false;
michael@0 24
michael@0 25 for (var i = 0; i < needles.length; ++i) {
michael@0 26 if (!pluginHost.siteHasData(this.pluginTag, needles[i]))
michael@0 27 return false;
michael@0 28 }
michael@0 29 return true;
michael@0 30 }
michael@0 31
michael@0 32 function setTestPluginEnabledState(newEnabledState, plugin) {
michael@0 33 var oldEnabledState = plugin.enabledState;
michael@0 34 plugin.enabledState = newEnabledState;
michael@0 35 SimpleTest.registerCleanupFunction(function() {
michael@0 36 plugin.enabledState = oldEnabledState;
michael@0 37 });
michael@0 38 }
michael@0 39
michael@0 40 function test() {
michael@0 41 waitForExplicitFinish();
michael@0 42
michael@0 43 var tags = pluginHost.getPluginTags();
michael@0 44
michael@0 45 // Find the test plugin
michael@0 46 for (var i = 0; i < tags.length; i++)
michael@0 47 {
michael@0 48 if (tags[i].name == "Test Plug-in")
michael@0 49 {
michael@0 50 pluginTag = tags[i];
michael@0 51 }
michael@0 52 }
michael@0 53 if (!pluginTag) {
michael@0 54 ok(false, "Test Plug-in not available, can't run test");
michael@0 55 finish();
michael@0 56 }
michael@0 57 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, pluginTag);
michael@0 58
michael@0 59 executeSoon(do_test);
michael@0 60 }
michael@0 61
michael@0 62 function setFinishedCallback(callback)
michael@0 63 {
michael@0 64 let testPage = gBrowser.selectedBrowser.contentWindow.wrappedJSObject;
michael@0 65 testPage.testFinishedCallback = function() {
michael@0 66 setTimeout(function() {
michael@0 67 info("got finished callback");
michael@0 68 callback();
michael@0 69 }, 0);
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 function do_test()
michael@0 74 {
michael@0 75 // Load page to set data for the plugin.
michael@0 76 gBrowser.selectedTab = gBrowser.addTab();
michael@0 77 gBrowser.selectedBrowser.addEventListener("load", function () {
michael@0 78 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
michael@0 79
michael@0 80 setFinishedCallback(function() {
michael@0 81 ok(stored(["192.168.1.1","foo.com","nonexistent.foo.com","bar.com","localhost"]),
michael@0 82 "Data stored for sites");
michael@0 83
michael@0 84 // Clear data for "foo.com" and its subdomains.
michael@0 85 ForgetAboutSite.removeDataFromDomain("foo.com");
michael@0 86 ok(stored(["bar.com","192.168.1.1","localhost"]), "Data stored for sites");
michael@0 87 ok(!stored(["foo.com"]), "Data cleared for foo.com");
michael@0 88 ok(!stored(["bar.foo.com"]), "Data cleared for subdomains of foo.com");
michael@0 89
michael@0 90 // Clear data for "bar.com" using a subdomain.
michael@0 91 ForgetAboutSite.removeDataFromDomain("foo.bar.com");
michael@0 92 ok(!stored(["bar.com"]), "Data cleared for bar.com");
michael@0 93
michael@0 94 // Clear data for "192.168.1.1".
michael@0 95 ForgetAboutSite.removeDataFromDomain("192.168.1.1");
michael@0 96 ok(!stored(["192.168.1.1"]), "Data cleared for 192.168.1.1");
michael@0 97
michael@0 98 // Clear data for "localhost".
michael@0 99 ForgetAboutSite.removeDataFromDomain("localhost");
michael@0 100 ok(!stored(null), "All data cleared");
michael@0 101
michael@0 102 gBrowser.removeCurrentTab();
michael@0 103
michael@0 104 executeSoon(finish);
michael@0 105 });
michael@0 106 }, true);
michael@0 107 content.location = testURL;
michael@0 108 }
michael@0 109

mercurial