2008-09-09 08:43:21 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=391728
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 391728</title>
|
2011-07-28 09:04:00 -07:00
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
2011-10-19 02:35:05 -07:00
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
|
2011-07-28 09:04:00 -07:00
|
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
2008-09-09 08:43:21 -07:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=391728">Mozilla Bug 391728</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
|
|
<iframe id="testframe" width="150" height="250" src="about:blank"></iframe>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
2013-06-11 07:58:42 -07:00
|
|
|
const gHttpTestRoot = location.toString().replace("chrome://mochitests/content/", "http://127.0.0.1:8888/").split(/\//).slice(0, -1).join('/') + '/';
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
2008-09-09 08:43:21 -07:00
|
|
|
/** Test for Bug 391728 **/
|
|
|
|
// Plugins that should dispatch error events and have the pseudo classes set
|
2013-06-11 07:58:42 -07:00
|
|
|
const PLUGIN_COUNT = 11;
|
2008-09-09 08:43:21 -07:00
|
|
|
// Plugins that should neither dispatch error events or have the pseudo classes set
|
2012-08-20 16:16:02 -07:00
|
|
|
const FALLBACK_COUNT = 5;
|
2012-11-07 17:24:39 -08:00
|
|
|
const OBJLC = Components.interfaces.nsIObjectLoadingContent;
|
2008-09-09 08:43:21 -07:00
|
|
|
|
|
|
|
var gNextTest = null;
|
|
|
|
var gUnknown = [];
|
|
|
|
var gBlocked = [];
|
|
|
|
var gDisabled = [];
|
|
|
|
|
2012-11-07 17:24:39 -08:00
|
|
|
function plugin_binding_attached(event) {
|
|
|
|
var plugin = event.target;
|
|
|
|
plugin instanceof OBJLC;
|
|
|
|
switch (SpecialPowers.wrap(plugin).pluginFallbackType) {
|
|
|
|
case OBJLC.PLUGIN_DISABLED:
|
|
|
|
gDisabled.push(plugin.id);
|
|
|
|
break;
|
|
|
|
case OBJLC.PLUGIN_BLOCKLISTED:
|
|
|
|
gBlocked.push(plugin.id);
|
|
|
|
break;
|
|
|
|
case OBJLC.PLUGIN_UNSUPPORTED:
|
|
|
|
gUnknown.push(plugin.id);
|
|
|
|
break;
|
|
|
|
}
|
2008-09-09 08:43:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function init_test() {
|
2009-04-22 23:27:04 -07:00
|
|
|
if (!PluginUtils.withTestPlugin(start_test))
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
2013-06-11 07:58:42 -07:00
|
|
|
function updateBlocklist(aCallback) {
|
|
|
|
var blocklistNotifier = Components.classes["@mozilla.org/extensions/blocklist;1"]
|
|
|
|
.getService(Components.interfaces.nsITimerCallback);
|
|
|
|
var observer = function() {
|
|
|
|
Services.obs.removeObserver(observer, "blocklist-updated");
|
2013-06-19 08:07:28 -07:00
|
|
|
SimpleTest.executeSoon(aCallback);
|
2013-06-11 07:58:42 -07:00
|
|
|
};
|
|
|
|
Services.obs.addObserver(observer, "blocklist-updated", false);
|
|
|
|
blocklistNotifier.notify(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
var _originalBlocklistURL = null;
|
|
|
|
function setAndUpdateBlocklist(aURL, aCallback) {
|
|
|
|
info("Setting blocklist to " + aURL);
|
|
|
|
if (!_originalBlocklistURL) {
|
|
|
|
_originalBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
|
|
|
|
}
|
|
|
|
Services.prefs.setCharPref("extensions.blocklist.url", aURL);
|
|
|
|
updateBlocklist(aCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetBlocklist() {
|
|
|
|
info("resetting blocklist URL to " + _originalBlocklistURL);
|
|
|
|
Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL);
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:27:04 -07:00
|
|
|
function start_test(plugin) {
|
2013-06-11 07:58:42 -07:00
|
|
|
Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
|
|
|
|
|
2011-01-18 10:27:26 -08:00
|
|
|
is(plugin.description, "Plug-in for testing purposes.\u2122 " +
|
|
|
|
"(\u0939\u093f\u0928\u094d\u0926\u0940 " +
|
|
|
|
"\u4e2d\u6587 " +
|
|
|
|
"\u0627\u0644\u0639\u0631\u0628\u064a\u0629)",
|
|
|
|
"Test plugin had an incorrect description");
|
2008-09-09 08:43:21 -07:00
|
|
|
is(plugin.version, "1.0.0.0", "Test plugin had an incorrect version");
|
|
|
|
ok(!plugin.disabled, "Test plugin should not be disabled");
|
|
|
|
ok(!plugin.blocklisted, "Test plugin should not be blocklisted");
|
2009-04-22 23:27:04 -07:00
|
|
|
|
2008-09-09 08:43:21 -07:00
|
|
|
var frame = document.getElementById("testframe");
|
|
|
|
frame.addEventListener("load", frame_loaded, true);
|
|
|
|
load_frame(test_normal, "file_bug391728");
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:27:04 -07:00
|
|
|
function finish_test(plugin) {
|
2013-06-11 07:58:42 -07:00
|
|
|
Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
|
|
|
|
resetBlocklist();
|
2013-03-27 14:06:43 -07:00
|
|
|
plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
|
2008-09-09 08:43:21 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_frame(nextTest, file) {
|
|
|
|
gNextTest = nextTest;
|
|
|
|
gDisabled = [];
|
|
|
|
gUnknown = [];
|
|
|
|
gBlocked = [];
|
|
|
|
var frame = document.getElementById("testframe");
|
|
|
|
frame.src = file + ".html?" + Math.random();
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:27:04 -07:00
|
|
|
function next_text() {
|
|
|
|
PluginUtils.withTestPlugin(gNextTest);
|
|
|
|
}
|
|
|
|
|
2008-09-09 08:43:21 -07:00
|
|
|
function frame_loaded() {
|
|
|
|
// We must delay to wait for the plugin sources to be loaded :(
|
2009-04-22 23:27:04 -07:00
|
|
|
setTimeout(next_text, 500);
|
2008-09-09 08:43:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_style(expected) {
|
|
|
|
var frame = document.getElementById("testframe");
|
|
|
|
for (var i = 1; i <= PLUGIN_COUNT; i++) {
|
|
|
|
var tag = frame.contentDocument.getElementById("plugin" + i);
|
|
|
|
ok(tag, "Plugin " + i + " did not exist");
|
|
|
|
var style = frame.contentWindow.getComputedStyle(tag, null);
|
|
|
|
is(style.borderTopStyle, expected, "Plugin " + i + " had an incorrect border style");
|
|
|
|
}
|
|
|
|
for (i = 1; i <= FALLBACK_COUNT; i++) {
|
|
|
|
var tag = frame.contentDocument.getElementById("fallback" + i);
|
|
|
|
ok(tag, "Fallback plugin " + i + " did not exist");
|
|
|
|
var style = frame.contentWindow.getComputedStyle(tag, null);
|
|
|
|
is(style.borderTopStyle, "solid", "Fallback plugin " + i + " had an incorrect border style");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_list(list) {
|
|
|
|
for (var i = 1; i <= PLUGIN_COUNT; i++) {
|
|
|
|
ok(list.indexOf("plugin" + i) >= 0, "Plugin " + i + " did not send the event");
|
|
|
|
}
|
|
|
|
for (i = 1; i <= FALLBACK_COUNT; i++) {
|
|
|
|
ok(list.indexOf("fallback" + i) < 0, "Fallback plugin " + i + " should not have sent the event");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:27:04 -07:00
|
|
|
function test_normal(plugin) {
|
2008-09-09 08:43:21 -07:00
|
|
|
is(gUnknown.length, 0, "Should not have been any unknown plugins");
|
|
|
|
is(gDisabled.length, 0, "Should not have been any disabled plugins");
|
|
|
|
is(gBlocked.length, 0, "Should not have been any blocked plugins");
|
|
|
|
test_style("solid");
|
2013-03-27 14:06:43 -07:00
|
|
|
plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_DISABLED;
|
2008-09-09 08:43:21 -07:00
|
|
|
load_frame(test_disabled, "file_bug391728");
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:27:04 -07:00
|
|
|
function test_disabled(plugin) {
|
2008-09-09 08:43:21 -07:00
|
|
|
is(gUnknown.length, 0, "Should not have been any unknown plugins");
|
|
|
|
is(gDisabled.length, PLUGIN_COUNT, "Should have been disabled plugins");
|
|
|
|
test_list(gDisabled);
|
|
|
|
is(gBlocked.length, 0, "Should not have been any blocked plugins");
|
|
|
|
test_style("dotted");
|
|
|
|
ok(plugin.disabled, "Plugin lost its disabled status");
|
2013-03-27 14:06:43 -07:00
|
|
|
plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
|
2013-06-11 07:58:42 -07:00
|
|
|
|
|
|
|
setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml",
|
|
|
|
function() {
|
|
|
|
load_frame(test_blocked, "file_bug391728");
|
|
|
|
});
|
2008-09-09 08:43:21 -07:00
|
|
|
}
|
|
|
|
|
2009-04-22 23:27:04 -07:00
|
|
|
function test_blocked(plugin) {
|
2008-09-09 08:43:21 -07:00
|
|
|
is(gUnknown.length, 0, "Should not have been any unknown plugins");
|
|
|
|
is(gDisabled.length, 0, "Should not have been any disabled plugins");
|
|
|
|
is(gBlocked.length, PLUGIN_COUNT, "Should have been blocked plugins");
|
|
|
|
test_list(gBlocked);
|
|
|
|
test_style("dashed");
|
|
|
|
ok(plugin.blocklisted, "Plugin lost its blocklist status");
|
|
|
|
load_frame(test_unknown, "file_bug391728_2");
|
|
|
|
}
|
|
|
|
|
2009-04-22 23:27:04 -07:00
|
|
|
function test_unknown(plugin) {
|
2008-09-09 08:43:21 -07:00
|
|
|
is(gUnknown.length, PLUGIN_COUNT, "Should have been unknown plugins");
|
|
|
|
test_list(gUnknown);
|
|
|
|
is(gDisabled.length, 0, "Should not have been any disabled plugins");
|
|
|
|
is(gBlocked.length, 0, "Should not have been any blocked plugins");
|
|
|
|
test_style("none");
|
2013-06-11 07:58:42 -07:00
|
|
|
setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() {
|
|
|
|
ok(!plugin.blocklisted, "Plugin shouldn't remain blocklisted");
|
|
|
|
finish_test(plugin);
|
|
|
|
});
|
2008-09-09 08:43:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
window.addEventListener("load", init_test, false);
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|