2011-02-08 14:16:09 -08:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
2012-10-08 08:55:41 -07:00
|
|
|
Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm");
|
2012-10-03 08:29:10 -07:00
|
|
|
|
2012-10-08 13:48:11 -07:00
|
|
|
// Test clearing plugin data by domain using ForgetAboutSite.
|
|
|
|
const testURL = "http://mochi.test:8888/browser/toolkit/forgetaboutsite/test/browser/browser_clearplugindata.html";
|
2011-02-08 14:16:09 -08:00
|
|
|
|
2011-04-11 13:00:30 -07:00
|
|
|
const pluginHostIface = Ci.nsIPluginHost;
|
2011-02-08 14:16:09 -08:00
|
|
|
var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
|
|
|
pluginHost.QueryInterface(pluginHostIface);
|
|
|
|
|
|
|
|
var pluginTag;
|
|
|
|
|
|
|
|
function stored(needles) {
|
|
|
|
var something = pluginHost.siteHasData(this.pluginTag, null);
|
|
|
|
if (!needles)
|
|
|
|
return something;
|
|
|
|
|
|
|
|
if (!something)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (var i = 0; i < needles.length; ++i) {
|
|
|
|
if (!pluginHost.siteHasData(this.pluginTag, needles[i]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-19 14:47:43 -08:00
|
|
|
function setTestPluginEnabledState(newEnabledState, plugin) {
|
|
|
|
var oldEnabledState = plugin.enabledState;
|
|
|
|
plugin.enabledState = newEnabledState;
|
|
|
|
SimpleTest.registerCleanupFunction(function() {
|
|
|
|
plugin.enabledState = oldEnabledState;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-02-08 14:16:09 -08:00
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
var tags = pluginHost.getPluginTags();
|
|
|
|
|
|
|
|
// Find the test plugin
|
|
|
|
for (var i = 0; i < tags.length; i++)
|
|
|
|
{
|
|
|
|
if (tags[i].name == "Test Plug-in")
|
|
|
|
{
|
|
|
|
pluginTag = tags[i];
|
|
|
|
}
|
|
|
|
}
|
2013-11-19 14:47:43 -08:00
|
|
|
if (!pluginTag) {
|
|
|
|
ok(false, "Test Plug-in not available, can't run test");
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, pluginTag);
|
2011-02-08 14:16:09 -08:00
|
|
|
|
|
|
|
executeSoon(do_test);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setFinishedCallback(callback)
|
|
|
|
{
|
|
|
|
let testPage = gBrowser.selectedBrowser.contentWindow.wrappedJSObject;
|
|
|
|
testPage.testFinishedCallback = function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
info("got finished callback");
|
|
|
|
callback();
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_test()
|
|
|
|
{
|
|
|
|
// Load page to set data for the plugin.
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab();
|
|
|
|
gBrowser.selectedBrowser.addEventListener("load", function () {
|
|
|
|
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
|
|
|
|
setFinishedCallback(function() {
|
|
|
|
ok(stored(["192.168.1.1","foo.com","nonexistent.foo.com","bar.com","localhost"]),
|
|
|
|
"Data stored for sites");
|
|
|
|
|
|
|
|
// Clear data for "foo.com" and its subdomains.
|
2012-10-08 08:55:41 -07:00
|
|
|
ForgetAboutSite.removeDataFromDomain("foo.com");
|
2011-02-08 14:16:09 -08:00
|
|
|
ok(stored(["bar.com","192.168.1.1","localhost"]), "Data stored for sites");
|
|
|
|
ok(!stored(["foo.com"]), "Data cleared for foo.com");
|
|
|
|
ok(!stored(["bar.foo.com"]), "Data cleared for subdomains of foo.com");
|
|
|
|
|
|
|
|
// Clear data for "bar.com" using a subdomain.
|
2012-10-08 08:55:41 -07:00
|
|
|
ForgetAboutSite.removeDataFromDomain("foo.bar.com");
|
2011-02-08 14:16:09 -08:00
|
|
|
ok(!stored(["bar.com"]), "Data cleared for bar.com");
|
|
|
|
|
|
|
|
// Clear data for "192.168.1.1".
|
2012-10-08 08:55:41 -07:00
|
|
|
ForgetAboutSite.removeDataFromDomain("192.168.1.1");
|
2011-02-08 14:16:09 -08:00
|
|
|
ok(!stored(["192.168.1.1"]), "Data cleared for 192.168.1.1");
|
|
|
|
|
|
|
|
// Clear data for "localhost".
|
2012-10-08 08:55:41 -07:00
|
|
|
ForgetAboutSite.removeDataFromDomain("localhost");
|
2011-02-08 14:16:09 -08:00
|
|
|
ok(!stored(null), "All data cleared");
|
|
|
|
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
|
|
|
|
executeSoon(finish);
|
|
|
|
});
|
|
|
|
}, true);
|
|
|
|
content.location = testURL;
|
|
|
|
}
|
|
|
|
|