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