bug 549697 - add click-to-play plugin UI to the addon manager r=unfocused r=jaws

--HG--
rename : browser/base/content/test/test_bug787619.html => browser/base/content/test/browser_bug787619.js
rename : browser/base/content/test/test_bug787619.html => browser/base/content/test/plugin_bug787619.html
This commit is contained in:
David Keeler 2013-04-23 16:21:22 -07:00
parent b00ebc0531
commit 006291280a
34 changed files with 703 additions and 98 deletions

View File

@ -36,7 +36,6 @@ MOCHITEST_FILES = \
gZipOfflineChild.html^headers^ \
gZipOfflineChild.cacheManifest \
gZipOfflineChild.cacheManifest^headers^ \
test_bug787619.html \
$(NULL)
# test_contextmenu.html is disabled on Linux due to bug 513558
@ -275,6 +274,7 @@ _BROWSER_FILES = \
plugin_clickToPlayDeny.html \
plugin_bug744745.html \
plugin_bug749455.html \
plugin_bug787619.html \
plugin_bug797677.html \
plugin_bug818009.html \
plugin_bug820497.html \
@ -304,6 +304,7 @@ _BROWSER_FILES = \
browser_lastAccessedTab.js \
browser_bug734076.js \
browser_bug744745.js \
browser_bug787619.js \
browser_bug812562.js \
browser_bug818009.js \
browser_bug818118.js \

View File

@ -13,10 +13,14 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
gTestBrowser.removeEventListener("load", pageLoad, true);
gTestBrowser.removeEventListener("PluginScripted", pluginScripted, true);
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gTestBrowser = gBrowser.selectedBrowser;

View File

@ -10,8 +10,14 @@ Components.utils.import("resource://gre/modules/Services.jsm");
function test() {
waitForExplicitFinish();
registerCleanupFunction(function() { Services.prefs.clearUserPref("plugins.click_to_play"); });
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
let plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
let plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true);

View File

@ -8,8 +8,14 @@ Components.utils.import("resource://gre/modules/Services.jsm");
function test() {
waitForExplicitFinish();
registerCleanupFunction(function() { Services.prefs.clearUserPref("plugins.click_to_play"); });
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
var newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;

View File

@ -11,12 +11,16 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
gTestBrowser.removeEventListener("PluginBindingAttached", pluginBindingAttached, true, true);
gBrowser.removeCurrentTab();
window.focus();
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gTestBrowser = gBrowser.selectedBrowser;

View File

@ -0,0 +1,47 @@
const gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
let gTestBrowser = null;
let gWrapperClickCount = 0;
function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
let plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
let plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gTestBrowser = gBrowser.selectedBrowser;
gTestBrowser.addEventListener("load", pageLoad, true);
gTestBrowser.contentWindow.location = gHttpTestRoot + "plugin_bug787619.html";
}
function pageLoad() {
executeSoon(part1);
}
function part1() {
let wrapper = gTestBrowser.contentDocument.getElementById('wrapper');
wrapper.addEventListener('click', function() ++gWrapperClickCount, false);
let plugin = gTestBrowser.contentDocument.getElementById('plugin');
ok(plugin, 'got plugin element');
let objLC = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(!objLC.activated, 'plugin should not be activated');
EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow);
waitForCondition(function() objLC.activated, part2,
'waited too long for plugin to activate');
}
function part2() {
is(gWrapperClickCount, 0, 'wrapper should not have received any clicks');
gTestBrowser.removeEventListener("load", pageLoad, true);
gBrowser.removeCurrentTab();
window.focus();
finish();
}

View File

@ -8,9 +8,13 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
Services.prefs.setBoolPref("plugins.click_to_play", false);
var newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;
gTestBrowser = gBrowser.selectedBrowser;

View File

@ -7,9 +7,13 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
gTestBrowser.removeEventListener("load", pageLoad, true);
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gTestBrowser = gBrowser.selectedBrowser;

View File

@ -7,10 +7,15 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
gTestBrowser.removeEventListener("load", pageLoad, true);
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gTestBrowser = gBrowser.selectedBrowser;
gTestBrowser.addEventListener("load", pageLoad, true);

View File

@ -11,12 +11,16 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_ENABLED;
gTestBrowser.removeEventListener("PluginBindingAttached", pluginBindingAttached, true, true);
gBrowser.removeCurrentTab();
window.focus();
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gTestBrowser = gBrowser.selectedBrowser;

View File

@ -41,6 +41,8 @@ function finishTest() {
gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString);
gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString);
Services.prefs.clearUserPref("plugins.click_to_play");
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_ENABLED;
gBrowser.removeCurrentTab();
finish();
}
@ -48,6 +50,8 @@ function finishTest() {
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("plugins.click_to_play", true);
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
gBrowser.selectedTab = gBrowser.addTab();
gTestBrowser = gBrowser.selectedBrowser;
doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart1a);

View File

@ -58,8 +58,14 @@ TabOpenListener.prototype = {
function test() {
waitForExplicitFinish();
registerCleanupFunction(function() { Services.prefs.clearUserPref("plugins.click_to_play"); });
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
Services.prefs.setBoolPref("plugins.click_to_play", false);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
var newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;
@ -196,10 +202,11 @@ function test7() {
ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 7, Should know about application/x-unknown");
ok(gTestBrowser.missingPlugins.has("application/x-test"), "Test 7, Should know about application/x-test");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
plugin.blocklisted = false;
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.blocklisted = false;
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
prepareTest(test8, gTestRoot + "plugin_test.html");
}
@ -513,6 +520,8 @@ function test13e() {
Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-test"));
Services.prefs.setBoolPref("plugins.click_to_play", false);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
prepareTest(test14, gTestRoot + "plugin_test2.html");
}
@ -522,10 +531,11 @@ function test14() {
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(objLoadingContent.activated, "Test 14, Plugin should be activated");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
plugin.blocklisted = false;
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.blocklisted = false;
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
prepareTest(test15, gTestRoot + "plugin_alternate_content.html");
}
@ -964,6 +974,8 @@ function test21e() {
}
Services.prefs.setBoolPref("plugins.click_to_play", true);
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
prepareTest(test22, gTestRoot + "plugin_test.html");
}

View File

@ -139,6 +139,8 @@ function test() {
if (gPlayPreviewRegistration)
gPlayPreviewRegistration.unregister();
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
var newTab = gBrowser.addTab();
@ -253,6 +255,8 @@ function test3() {
registerPlayPreview('application/x-test', 'about:');
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
prepareTest(test4a, gTestRoot + "plugin_test.html", 1);
}

View File

@ -39,6 +39,8 @@ function test() {
if (gPlayPreviewRegistration)
gPlayPreviewRegistration.unregister();
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
var newTab = gBrowser.addTab();
@ -48,6 +50,8 @@ function test() {
gTestBrowser.addEventListener("PluginBindingAttached", handleBindingAttached, true, true);
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
registerPlayPreview('application/x-test', 'about:');
prepareTest(test1a, gTestRoot + "plugin_test.html", 1);

View File

@ -10,8 +10,12 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
Services.prefs.clearUserPref("plugins.click_to_play");
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
let newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;

View File

@ -97,13 +97,14 @@ function waitForCondition(condition, nextTest, errorMsg) {
var moveOn = function() { clearInterval(interval); nextTest(); };
}
function getTestPlugin() {
function getTestPlugin(aName) {
var pluginName = aName || "Test Plug-in";
var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
var tags = ph.getPluginTags();
// Find the test plugin
for (var i = 0; i < tags.length; i++) {
if (tags[i].name == "Test Plug-in")
if (tags[i].name == pluginName)
return tags[i];
}
ok(false, "Unable to find plugin");

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"/></head>
<body>
<a id="wrapper">
<embed id="plugin" style="width: 200px; height: 200px" type="application/x-test">
</a>
</body>
</html>

View File

@ -1,46 +0,0 @@
<html>
<head>
<title>Test for Bug 787619</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript;version=1.7" src="head_plain.js"></script>
<script>
SpecialPowers.setBoolPref('plugins.click_to_play', true);
</script>
</head>
<body>
<a id="wrapper">
<embed id="plugin" style="width: 200px; height: 200px" type="application/x-test">
</a>
<script class="testbody" type="application/javascript;version=1.7">
SimpleTest.waitForExplicitFinish();
const Ci = SpecialPowers.Ci;
let wrapperClickCount = 0;
function test1() {
let plugin = document.getElementById('plugin');
ok(plugin, 'got plugin element');
let objLC = SpecialPowers.wrap(plugin);
ok(!objLC.activated, 'plugin should not be activated');
synthesizeMouseAtCenter(plugin, {});
waitForCondition(function() objLC.activated, test2,
'waited too long for plugin to activate');
}
function test2() {
is(wrapperClickCount, 0, 'wrapper should not have received any clicks');
SpecialPowers.clearUserPref('plugins.click_to_play');
SimpleTest.finish();
}
let wrapper = document.getElementById('wrapper');
wrapper.addEventListener('click', function() ++wrapperClickCount, false);
SimpleTest.waitForFocus(test1);
</script>
</body>
</html>

View File

@ -929,6 +929,14 @@ function runTest(testNum) {
].concat(inspectItems));
closeContextMenu();
SpecialPowers.clearUserPref("plugins.click_to_play");
var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
.getService(SpecialPowers.Ci.nsIPluginHost);
var tags = ph.getPluginTags();
for (var tag of tags) {
if (tag.name == "Test Plug-in") {
tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;
}
}
// finish test
subwindow.close();
@ -1037,6 +1045,14 @@ if (isOSXMtnLion) {
todo(false, "Mountain Lion doesn't like this test (bug 792304)");
} else {
SpecialPowers.setBoolPref("plugins.click_to_play", true);
var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
.getService(SpecialPowers.Ci.nsIPluginHost);
var tags = ph.getPluginTags();
for (var tag of tags) {
if (tag.name == "Test Plug-in") {
tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_CLICKTOPLAY;
}
}
var subwindow = window.open("./subtst_contextmenu.html", "contextmenu-subtext", "width=600,height=800");
subwindow.addEventListener("MozAfterPaint", waitForEvents, false);

View File

@ -1078,7 +1078,7 @@ nsPluginHost::IsPluginClickToPlayForType(const nsACString &aMimeType, bool *aRes
nsresult rv = GetBlocklistStateForType(aMimeType.Data(), &blocklistState);
NS_ENSURE_SUCCESS(rv, rv);
if (mPluginsClickToPlay ||
if ((mPluginsClickToPlay && plugin->IsClicktoplay()) ||
blocklistState == nsIBlocklistService::STATE_VULNERABLE_NO_UPDATE ||
blocklistState == nsIBlocklistService::STATE_VULNERABLE_UPDATE_AVAILABLE) {
*aResult = true;

View File

@ -64,7 +64,6 @@ MOCHITEST_FILES = \
test_bug771202.html \
file_bug771202.html \
test_bug777098.html \
test_bug751809.html \
test_bug813906.html \
test_bug784131.html \
test_bug854082.html \
@ -106,7 +105,9 @@ MOCHITEST_CHROME_FILES = \
test_npruntime.xul \
test_wmode.xul \
test_bug479979.xul \
test_bug751809.html \
test_refresh_navigator_plugins.html \
test_plugin_tag_clicktoplay.html \
privatemode_perwindowpb.xul \
test_privatemode_perwindowpb.xul \
$(NULL)

View File

@ -1,19 +1,35 @@
<html>
<head>
<title>Bug 751809</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript">
SpecialPowers.setBoolPref("plugins.click_to_play", true);
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/paint_listener.js"></script>
<script type="application/javascript;version=1.7">
function getTestPlugin() {
let ph = Components.classes["@mozilla.org/plugin/host;1"]
.getService(Components.interfaces.nsIPluginHost);
let tags = ph.getPluginTags();
// Find the test plugin
for (let i = 0; i < tags.length; i++) {
if (tags[i].name == "Test Plug-in")
return tags[i];
}
ok(false, "Unable to find plugin");
return null;
}
Components.utils.import("resource://gre/modules/Services.jsm");
Services.prefs.setBoolPref("plugins.click_to_play", true);
let plugin = getTestPlugin();
plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_CLICKTOPLAY;
</script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="go();">
<embed id="plugin" type="application/x-test" width="400" height="400" drawmode="solid" color="FF00FFFF"></embed>
<script type="application/javascript">
<script type="application/javascript;version=1.7">
SimpleTest.waitForExplicitFinish();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
@ -86,7 +102,9 @@
ok(false, "plugin.getMouseUpEventCount() shouldn't throw");
}
SpecialPowers.clearUserPref("plugins.click_to_play");
Services.prefs.clearUserPref("plugins.click_to_play");
let plugin = getTestPlugin();
plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
SimpleTest.finish();
}

View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta><charset="utf-8"/>
<title>Test Modifying Plugin click-to-play Flag</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
</head>
<body>
<script class="testbody" type="application/javascript">
Components.utils.import("resource://gre/modules/Services.jsm");
var pluginHost = Components.classes["@mozilla.org/plugin/host;1"]
.getService(Components.interfaces.nsIPluginHost);
ok(!pluginHost.isPluginClickToPlayForType("application/x-test"), "click-to-play should be off to begin with");
Services.prefs.setBoolPref("plugins.click_to_play", true);
var pluginTags = pluginHost.getPluginTags();
var testPlugin = null;
for (var plugin of pluginTags) {
if (plugin.name == "Test Plug-in") {
testPlugin = plugin;
break;
}
}
ok(testPlugin, "Should have Test Plug-in");
testPlugin.enabledState = Components.interfaces.nsIPluginTag.STATE_CLICKTOPLAY;
ok(pluginHost.isPluginClickToPlayForType("application/x-test"), "click-to-play should be on for Test Plug-in now");
ok(!pluginHost.isPluginClickToPlayForType("application/x-second-test"), "click-to-play should still be off for the Second Test Plug-in");
testPlugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
ok(!pluginHost.isPluginClickToPlayForType("application/x-test"), "click-to-play should be off for Test Plug-in now");
Services.prefs.clearUserPref("plugins.click_to_play");
</script>
</body>
</html>

View File

@ -90,6 +90,13 @@
<!ENTITY cmd.enableTheme.accesskey "W">
<!ENTITY cmd.disableTheme.label "Stop Wearing Theme">
<!ENTITY cmd.disableTheme.accesskey "W">
<!ENTITY cmd.askToActivate.label "Ask to Activate">
<!ENTITY cmd.askToActivate.tooltip "Ask to use this add-on each time">
<!ENTITY cmd.alwaysActivate.label "Always Activate">
<!ENTITY cmd.alwaysActivate.tooltip "Always use this add-on">
<!ENTITY cmd.neverActivate.label "Never Activate">
<!ENTITY cmd.neverActivate.tooltip "Never use this add-on">
<!ENTITY cmd.tristateMenu.tooltip "Change when this add-on runs">
<!ENTITY cmd.installAddon.label "Install">
<!ENTITY cmd.installAddon.accesskey "I">
<!ENTITY cmd.uninstallAddon.label "Remove">

View File

@ -2200,6 +2200,9 @@ this.AddonManager = {
PERM_CAN_DISABLE: 4,
// Indicates that the Addon can be upgraded.
PERM_CAN_UPGRADE: 8,
// Indicates that the Addon can be set to be optionally enabled
// on a case-by-case basis.
PERM_CAN_ASK_TO_ACTIVATE: 16,
// General descriptions of where items are installed.
// Installed in this profile.
@ -2217,6 +2220,10 @@ this.AddonManager = {
VIEW_TYPE_LIST: "list",
TYPE_UI_HIDE_EMPTY: 16,
// Indicates that this add-on type supports the ask-to-activate state.
// That is, add-ons of this type can be set to be optionally enabled
// on a case-by-case basis.
TYPE_SUPPORTS_ASK_TO_ACTIVATE: 32,
// Constants for Addon.applyBackgroundUpdates.
// Indicates that the Addon should not update automatically.
@ -2264,6 +2271,12 @@ this.AddonManager = {
// add-ons that were pending being enabled the last time the application ran.
STARTUP_CHANGE_ENABLED: "enabled",
// Constants for the Addon.userDisabled property
// Indicates that the userDisabled state of this add-on is currently
// ask-to-activate. That is, it can be conditionally enabled on a
// case-by-case basis.
STATE_ASK_TO_ACTIVATE: "askToActivate",
#ifdef MOZ_EM_DEBUG
get __AddonManagerInternal__() {
return AddonManagerInternal;

View File

@ -295,22 +295,58 @@ function PluginWrapper(aId, aName, aDescription, aTags) {
this.__defineGetter__("isActive", function() !aTags[0].blocklisted && !aTags[0].disabled);
this.__defineGetter__("appDisabled", function() aTags[0].blocklisted);
this.__defineGetter__("userDisabled", function() aTags[0].disabled);
this.__defineGetter__("userDisabled", function() {
if (aTags[0].disabled)
return true;
if ((Services.prefs.getBoolPref("plugins.click_to_play") && aTags[0].clicktoplay) ||
this.blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE ||
this.blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE)
return AddonManager.STATE_ASK_TO_ACTIVATE;
return false;
});
this.__defineSetter__("userDisabled", function(aVal) {
if (aTags[0].disabled == aVal)
return;
let previousVal = this.userDisabled;
if (aVal === previousVal)
return aVal;
for (let tag of aTags) {
if (aVal === true)
tag.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
else
else if (aVal === false)
tag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
else if (aVal == AddonManager.STATE_ASK_TO_ACTIVATE)
tag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
}
AddonManagerPrivate.callAddonListeners(aVal ? "onDisabling" : "onEnabling", this, false);
AddonManagerPrivate.callAddonListeners(aVal ? "onDisabled" : "onEnabled", this);
// If 'userDisabled' was 'true' and we're going to a state that's not
// that, we're enabling, so call those listeners.
if (previousVal === true && aVal !== true) {
AddonManagerPrivate.callAddonListeners("onEnabling", this, false);
AddonManagerPrivate.callAddonListeners("onEnabled", this);
}
// If 'userDisabled' was not 'true' and we're going to a state where
// it is, we're disabling, so call those listeners.
if (previousVal !== true && aVal === true) {
AddonManagerPrivate.callAddonListeners("onDisabling", this, false);
AddonManagerPrivate.callAddonListeners("onDisabled", this);
}
// If the 'userDisabled' value involved AddonManager.STATE_ASK_TO_ACTIVATE,
// call the onPropertyChanged listeners.
if (previousVal == AddonManager.STATE_ASK_TO_ACTIVATE ||
aVal == AddonManager.STATE_ASK_TO_ACTIVATE) {
AddonManagerPrivate.callAddonListeners("onPropertyChanged", this, ["userDisabled"]);
}
return aVal;
});
this.__defineGetter__("blocklistState", function() {
let bs = Cc["@mozilla.org/extensions/blocklist;1"].
getService(Ci.nsIBlocklistService);
@ -414,10 +450,24 @@ function PluginWrapper(aId, aName, aDescription, aTags) {
this.__defineGetter__("permissions", function() {
let permissions = 0;
if (!this.appDisabled) {
if (this.userDisabled)
permissions |= AddonManager.PERM_CAN_ENABLE;
else
if (this.userDisabled !== true)
permissions |= AddonManager.PERM_CAN_DISABLE;
let blocklistState = this.blocklistState;
let isCTPBlocklisted =
(blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE ||
blocklistState == Ci.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE);
if (this.userDisabled !== AddonManager.STATE_ASK_TO_ACTIVATE &&
(Services.prefs.getBoolPref("plugins.click_to_play") ||
isCTPBlocklisted)) {
permissions |= AddonManager.PERM_CAN_ASK_TO_ACTIVATE;
}
if (this.userDisabled !== false && !isCTPBlocklisted) {
permissions |= AddonManager.PERM_CAN_ENABLE;
}
}
return permissions;
});
@ -464,5 +514,6 @@ PluginWrapper.prototype = {
AddonManagerPrivate.registerProvider(PluginProvider, [
new AddonManagerPrivate.AddonType("plugin", URI_EXTENSION_STRINGS,
STRING_TYPE_NAME,
AddonManager.VIEW_TYPE_LIST, 6000)
AddonManager.VIEW_TYPE_LIST, 6000,
AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE)
]);

View File

@ -962,7 +962,9 @@ var gViewController = {
isEnabled: function cmd_enableItem_isEnabled(aAddon) {
if (!aAddon)
return false;
return hasPermission(aAddon, "enable");
let addonType = AddonManager.addonTypes[aAddon.type];
return (!(addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE) &&
hasPermission(aAddon, "enable"));
},
doCommand: function cmd_enableItem_doCommand(aAddon) {
aAddon.userDisabled = false;
@ -980,7 +982,9 @@ var gViewController = {
isEnabled: function cmd_disableItem_isEnabled(aAddon) {
if (!aAddon)
return false;
return hasPermission(aAddon, "disable");
let addonType = AddonManager.addonTypes[aAddon.type];
return (!(addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE) &&
hasPermission(aAddon, "disable"));
},
doCommand: function cmd_disableItem_doCommand(aAddon) {
aAddon.userDisabled = true;
@ -1131,7 +1135,46 @@ var gViewController = {
doCommand: function cmd_contribute_doCommand(aAddon) {
openURL(aAddon.contributionURL);
}
}
},
cmd_askToActivateItem: {
isEnabled: function cmd_askToActivateItem_isEnabled(aAddon) {
if (!aAddon)
return false;
let addonType = AddonManager.addonTypes[aAddon.type];
return ((addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE) &&
hasPermission(aAddon, "ask_to_activate"));
},
doCommand: function cmd_askToActivateItem_doCommand(aAddon) {
aAddon.userDisabled = AddonManager.STATE_ASK_TO_ACTIVATE;
}
},
cmd_alwaysActivateItem: {
isEnabled: function cmd_alwaysActivateItem_isEnabled(aAddon) {
if (!aAddon)
return false;
let addonType = AddonManager.addonTypes[aAddon.type];
return ((addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE) &&
hasPermission(aAddon, "enable"));
},
doCommand: function cmd_alwaysActivateItem_doCommand(aAddon) {
aAddon.userDisabled = false;
}
},
cmd_neverActivateItem: {
isEnabled: function cmd_neverActivateItem_isEnabled(aAddon) {
if (!aAddon)
return false;
let addonType = AddonManager.addonTypes[aAddon.type];
return ((addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE) &&
hasPermission(aAddon, "disable"));
},
doCommand: function cmd_neverActivateItem_doCommand(aAddon) {
aAddon.userDisabled = true;
}
},
},
supportsCommand: function gVC_supportsCommand(aCommand) {
@ -2854,6 +2897,27 @@ var gDetailView = {
}
}
let menulist = document.getElementById("detail-tristate-menulist");
let addonType = AddonManager.addonTypes[this._addon.type];
if (addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE &&
(hasPermission(this._addon, "ask_to_activate") ||
hasPermission(this._addon, "enable") ||
hasPermission(this._addon, "disable"))) {
let askItem = document.getElementById("detail-ask-to-activate-menuitem");
let alwaysItem = document.getElementById("detail-always-activate-menuitem");
let neverItem = document.getElementById("detail-never-activate-menuitem");
if (this._addon.userDisabled === true) {
menulist.selectedItem = neverItem;
} else if (this._addon.userDisabled == AddonManager.STATE_ASK_TO_ACTIVATE) {
menulist.selectedItem = askItem;
} else {
menulist.selectedItem = alwaysItem;
}
menulist.hidden = false;
} else {
menulist.hidden = true;
}
this.node.setAttribute("active", this._addon.isActive);
},
@ -3027,7 +3091,8 @@ var gDetailView = {
document.getElementById("detail-findUpdates-btn").hidden = hideFindUpdates;
}
if (aProperties.indexOf("appDisabled") != -1)
if (aProperties.indexOf("appDisabled") != -1 ||
aProperties.indexOf("userDisabled") != -1)
this.updateState();
},

View File

@ -876,6 +876,27 @@
<xul:button anonid="remove-btn" class="addon-control remove"
label="&cmd.uninstallAddon.label;"
oncommand="document.getBindingParent(this).uninstall();"/>
<xul:menulist anonid="tristate-menulist"
class="addon-control"
tooltiptext="&cmd.tristateMenu.tooltip;">
<xul:menupopup>
<xul:menuitem anonid="ask-to-activate-menuitem"
class="addon-control"
label="&cmd.askToActivate.label;"
tooltiptext="&cmd.askToActivate.tooltip;"
oncommand="document.getBindingParent(this).userDisabled = AddonManager.STATE_ASK_TO_ACTIVATE;"/>
<xul:menuitem anonid="always-activate-menuitem"
class="addon-control"
label="&cmd.alwaysActivate.label;"
tooltiptext="&cmd.alwaysActivate.tooltip;"
oncommand="document.getBindingParent(this).userDisabled = false;"/>
<xul:menuitem anonid="never-activate-menuitem"
class="addon-control"
label="&cmd.neverActivate.label;"
tooltiptext="&cmd.neverActivate.tooltip;"
oncommand="document.getBindingParent(this).userDisabled = true;"/>
</xul:menupopup>
</xul:menulist>
</xul:hbox>
</xul:vbox>
</xul:hbox>
@ -958,6 +979,22 @@
document.getAnonymousElementByAttribute(this, "anonid",
"description");
</field>
<field name="_tristateMenulist">
document.getAnonymousElementByAttribute(this, "anonid",
"tristate-menulist");
</field>
<field name="_askToActivateMenuitem">
document.getAnonymousElementByAttribute(this, "anonid",
"ask-to-activate-menuitem");
</field>
<field name="_alwaysActivateMenuitem">
document.getAnonymousElementByAttribute(this, "anonid",
"always-activate-menuitem");
</field>
<field name="_neverActivateMenuitem">
document.getAnonymousElementByAttribute(this, "anonid",
"never-activate-menuitem");
</field>
<field name="_preferencesBtn">
document.getAnonymousElementByAttribute(this, "anonid",
"preferences-btn");
@ -1240,22 +1277,43 @@
this._preferencesBtn.hidden = (!this.mAddon.optionsURL) ||
this.mAddon.optionsType == AddonManager.OPTIONS_TYPE_INLINE_INFO;
if (this.hasPermission("enable")) {
this._enableBtn.hidden = false;
let tooltip = gViewController.commands["cmd_enableItem"]
.getTooltip(this.mAddon);
this._enableBtn.setAttribute("tooltiptext", tooltip);
let addonType = AddonManager.addonTypes[this.mAddon.type];
if (addonType.flags & AddonManager.TYPE_SUPPORTS_ASK_TO_ACTIVATE &&
(this.hasPermission("ask_to_activate") ||
this.hasPermission("enable") ||
this.hasPermission("disable"))) {
this._enableBtn.disabled = true;
this._disableBtn.disabled = true;
this._askToActivateMenuitem.disabled = !this.hasPermission("ask_to_activate");
this._alwaysActivateMenuitem.disabled = !this.hasPermission("enable");
this._neverActivateMenuitem.disabled = !this.hasPermission("disable");
if (this.mAddon.userDisabled === true) {
this._tristateMenulist.selectedItem = this._neverActivateMenuitem;
} else if (this.mAddon.userDisabled == AddonManager.STATE_ASK_TO_ACTIVATE) {
this._tristateMenulist.selectedItem = this._askToActivateMenuitem;
} else {
this._tristateMenulist.selectedItem = this._alwaysActivateMenuitem;
}
this._tristateMenulist.disabled = false;
} else {
this._enableBtn.hidden = true;
}
this._tristateMenulist.disabled = true;
if (this.hasPermission("enable")) {
this._enableBtn.hidden = false;
let tooltip = gViewController.commands["cmd_enableItem"]
.getTooltip(this.mAddon);
this._enableBtn.setAttribute("tooltiptext", tooltip);
} else {
this._enableBtn.hidden = true;
}
if (this.hasPermission("disable")) {
this._disableBtn.hidden = false;
let tooltip = gViewController.commands["cmd_disableItem"]
.getTooltip(this.mAddon);
this._disableBtn.setAttribute("tooltiptext", tooltip);
} else {
this._disableBtn.hidden = true;
if (this.hasPermission("disable")) {
this._disableBtn.hidden = false;
let tooltip = gViewController.commands["cmd_disableItem"]
.getTooltip(this.mAddon);
this._disableBtn.setAttribute("tooltiptext", tooltip);
} else {
this._disableBtn.hidden = true;
}
}
if (this.hasPermission("uninstall")) {
@ -1513,7 +1571,8 @@
<method name="onPropertyChanged">
<parameter name="aProperties"/>
<body><![CDATA[
if (aProperties.indexOf("appDisabled") != -1)
if (aProperties.indexOf("appDisabled") != -1 ||
aProperties.indexOf("userDisabled") != -1)
this._updateState();
]]></body>
</method>

View File

@ -110,6 +110,9 @@
<command id="cmd_cancelUninstallItem"/>
<command id="cmd_cancelOperation"/>
<command id="cmd_contribute"/>
<command id="cmd_askToActivateItem"/>
<command id="cmd_alwaysActivateItem"/>
<command id="cmd_neverActivateItem"/>
</commandset>
<keyset>
@ -619,6 +622,27 @@
label="&cmd.installAddon.label;"
accesskey="&cmd.installAddon.accesskey;"
command="cmd_installItem"/>
<menulist id="detail-tristate-menulist"
crop="none" sizetopopup="always"
tooltiptext="&cmd.tristateMenu.tooltip;">
<menupopup>
<menuitem id="detail-ask-to-activate-menuitem"
class="addon-control"
label="&cmd.askToActivate.label;"
tooltiptext="&cmd.askToActivate.tooltip;"
command="cmd_askToActivateItem"/>
<menuitem id="detail-always-activate-menuitem"
class="addon-control"
label="&cmd.alwaysActivate.label;"
tooltiptext="&cmd.alwaysActivate.tooltip;"
command="cmd_alwaysActivateItem"/>
<menuitem id="detail-never-activate-menuitem"
class="addon-control"
label="&cmd.neverActivate.label;"
tooltiptext="&cmd.neverActivate.tooltip;"
command="cmd_neverActivateItem"/>
</menupopup>
</menulist>
</hbox>
</vbox>
</hbox>

View File

@ -61,6 +61,7 @@ MOCHITEST_BROWSER_MAIN = \
browser_inlinesettings_info.js \
browser_tabsettings.js \
browser_pluginprefs.js \
browser_CTP_plugins.js \
$(NULL)
MOCHITEST_BROWSER_SECONDARY = \
@ -106,6 +107,7 @@ MOCHITEST_BROWSER_RESOURCES = \
unsigned_hotfix.xpi \
more_options.xul \
options.xul \
plugin_test.html \
redirect.sjs \
releaseNotes.xhtml \
$(NULL)

View File

@ -0,0 +1,197 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const gHttpTestRoot = "http://127.0.0.1:8888/" + RELATIVE_DIR + "/";
let gManagerWindow;
let gTestPluginId;
let gPluginBrowser;
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("plugins.click_to_play", true);
let pluginTag = getTestPluginTag();
pluginTag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
open_manager("addons://list/plugin", part1);
}
function part1(aWindow) {
gManagerWindow = aWindow;
AddonManager.getAddonsByTypes(["plugin"], part2);
}
function part2(aPlugins) {
for (let plugin of aPlugins) {
if (plugin.name == "Test Plug-in") {
gTestPluginId = plugin.id;
break;
}
}
ok(gTestPluginId, "part2: Test Plug-in should exist");
AddonManager.getAddonByID(gTestPluginId, part3);
}
function part3(aTestPlugin) {
let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
pluginEl.parentNode.ensureElementIsVisible(pluginEl);
let enableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn");
is_element_hidden(enableButton, "part3: enable button should not be visible");
let disableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn");
is_element_hidden(disableButton, "part3: disable button should not be visible");
let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "tristate-menulist");
is_element_visible(menu, "part3: tristate menu should be visible");
let askToActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "ask-to-activate-menuitem");
is(menu.selectedItem, askToActivateItem, "part3: tristate menu should have 'Ask To Activate' selected");
gBrowser.selectedTab = gBrowser.addTab();
gPluginBrowser = gBrowser.selectedBrowser;
gPluginBrowser.addEventListener("PluginBindingAttached", part4, true, true);
gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
}
function part4() {
ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part4: should have a click-to-play notification");
gPluginBrowser.removeEventListener("PluginBindingAttached", part4);
gBrowser.removeCurrentTab();
let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "tristate-menulist");
let alwaysActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "always-activate-menuitem");
menu.selectedItem = alwaysActivateItem;
alwaysActivateItem.doCommand();
gBrowser.selectedTab = gBrowser.addTab();
gPluginBrowser = gBrowser.selectedBrowser;
gPluginBrowser.addEventListener("load", part5, true);
gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
}
function part5() {
let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
ok(testPlugin, "part5: should have a plugin element in the page");
let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
let condition = function() objLoadingContent.activated;
waitForCondition(condition, part6, "part5: waited too long for plugin to activate");
}
function part6() {
let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
ok(testPlugin, "part6: should have a plugin element in the page");
let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(objLoadingContent.activated, "part6: plugin should be activated");
gPluginBrowser.removeEventListener("load", part5);
gBrowser.removeCurrentTab();
let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "tristate-menulist");
let neverActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "never-activate-menuitem");
menu.selectedItem = neverActivateItem;
neverActivateItem.doCommand();
gBrowser.selectedTab = gBrowser.addTab();
gPluginBrowser = gBrowser.selectedBrowser;
gPluginBrowser.addEventListener("PluginBindingAttached", part7, true, true);
gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
}
function part7() {
ok(!PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part7: should not have a click-to-play notification");
let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
ok(testPlugin, "part7: should have a plugin element in the page");
let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(!objLoadingContent.activated, "part7: plugin should not be activated");
gPluginBrowser.removeEventListener("PluginBindingAttached", part7);
gBrowser.removeCurrentTab();
let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn");
is_element_visible(details, "part7: details link should be visible");
EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow);
wait_for_view_load(gManagerWindow, part8);
}
function part8() {
let enableButton = gManagerWindow.document.getElementById("detail-enable-btn");
is_element_hidden(enableButton, "part8: detail enable button should be hidden");
let disableButton = gManagerWindow.document.getElementById("detail-disable-btn");
is_element_hidden(disableButton, "part8: detail disable button should be hidden");
let menu = gManagerWindow.document.getElementById("detail-tristate-menulist");
is_element_visible(menu, "part8: detail tristate menu should be visible");
let neverActivateItem = gManagerWindow.document.getElementById("detail-never-activate-menuitem")
is(menu.selectedItem, neverActivateItem, "part8: tristate menu should have 'Never Activate' selected");
let alwaysActivateItem = gManagerWindow.document.getElementById("detail-always-activate-menuitem");
menu.selectedItem = alwaysActivateItem;
alwaysActivateItem.doCommand();
gBrowser.selectedTab = gBrowser.addTab();
gPluginBrowser = gBrowser.selectedBrowser;
gPluginBrowser.addEventListener("load", part9, true);
gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
}
function part9() {
let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
ok(testPlugin, "part9: should have a plugin element in the page");
let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
let condition = function() objLoadingContent.activated;
waitForCondition(condition, part10, "part9: waited too long for plugin to activate");
}
function part10() {
let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
ok(testPlugin, "part10: should have a plugin element in the page");
let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(objLoadingContent.activated, "part10: plugin should be activated");
gPluginBrowser.removeEventListener("load", part9);
gBrowser.removeCurrentTab();
let menu = gManagerWindow.document.getElementById("detail-tristate-menulist");
let askToActivateItem = gManagerWindow.document.getElementById("detail-ask-to-activate-menuitem")
menu.selectedItem = askToActivateItem;
askToActivateItem.doCommand();
gBrowser.selectedTab = gBrowser.addTab();
gPluginBrowser = gBrowser.selectedBrowser;
gPluginBrowser.addEventListener("PluginBindingAttached", part11, true, true);
gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
}
function part11() {
ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part11: should have a click-to-play notification");
gPluginBrowser.removeEventListener("PluginBindingAttached", part11);
gBrowser.removeCurrentTab();
let pluginTag = getTestPluginTag();
pluginTag.blocklisted = true; // causes appDisabled to be set
close_manager(gManagerWindow, function() {
open_manager("addons://list/plugin", part12);
});
}
function part12(aWindow) {
gManagerWindow = aWindow;
let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
pluginEl.parentNode.ensureElementIsVisible(pluginEl);
let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "tristate-menulist");
is_element_hidden(menu, "part12: tristate menu should be hidden");
let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn");
EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow);
wait_for_view_load(gManagerWindow, part13);
}
function part13() {
let menu = gManagerWindow.document.getElementById("detail-tristate-menulist");
is_element_hidden(menu, "part13: detail tristate menu should be hidden");
let pluginTag = getTestPluginTag();
pluginTag.blocklisted = false;
run_next_test();
}
function end_test() {
Services.prefs.clearUserPref("plugins.click_to_play");
let pluginTag = getTestPluginTag();
pluginTag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
close_manager(gManagerWindow, function() {
finish();
});
}

View File

@ -1234,3 +1234,30 @@ MockInstall.prototype = {
}
};
function waitForCondition(condition, nextTest, errorMsg) {
let tries = 0;
let interval = setInterval(function() {
if (tries >= 30) {
ok(false, errorMsg);
moveOn();
}
if (condition()) {
moveOn();
}
tries++;
}, 100);
let moveOn = function() { clearInterval(interval); nextTest(); };
}
function getTestPluginTag() {
let ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
let tags = ph.getPluginTags();
// Find the test plugin
for (let i = 0; i < tags.length; i++) {
if (tags[i].name == "Test Plug-in")
return tags[i];
}
ok(false, "Unable to find plugin");
return null;
}

View File

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body>
<object id="test" width=200 height=200 type="application/x-test"></object>
</body>
</html>

View File

@ -140,8 +140,13 @@ function test_disable_blocklist() {
do_check_false(gPluginHost.isPluginClickToPlayForType("application/x-test"));
// it should still be possible to make a plugin click-to-play via the pref
// and setting that plugin's enabled state to click-to-play
Services.prefs.setBoolPref("plugins.click_to_play", true);
let previousEnabledState = plugin.enabledState;
plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_CLICKTOPLAY;
do_check_true(gPluginHost.isPluginClickToPlayForType("application/x-test"));
// clean up plugin state
plugin.enabledState = previousEnabledState;
gServer.stop(do_test_finished);
}