gecko/content/base/test/chrome/test_bug391728.html

166 lines
5.7 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=391728
-->
<head>
<title>Test for Bug 391728</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/PluginUtils.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
</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">
/** Test for Bug 391728 **/
// Plugins that should dispatch error events and have the pseudo classes set
const PLUGIN_COUNT = 14;
// Plugins that should neither dispatch error events or have the pseudo classes set
const FALLBACK_COUNT = 4;
var gNextTest = null;
var gUnknown = [];
var gBlocked = [];
var gDisabled = [];
function disabled_plugin_detected(event) {
gDisabled.push(event.target.id);
}
function blocked_plugin_detected(event) {
gBlocked.push(event.target.id);
}
function unknown_plugin_detected(event) {
gUnknown.push(event.target.id);
}
function init_test() {
// Make sure the blocklist is off for the duration of this test
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref("extensions.blocklist.enabled", false);
if (!PluginUtils.withTestPlugin(start_test))
SimpleTest.finish();
}
function start_test(plugin) {
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");
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");
var frame = document.getElementById("testframe");
frame.addEventListener("load", frame_loaded, true);
load_frame(test_normal, "file_bug391728");
}
function finish_test(plugin) {
plugin.disabled = false;
plugin.blocklisted = false;
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.clearUserPref("extensions.blocklist.enabled");
SimpleTest.finish();
}
function load_frame(nextTest, file) {
gNextTest = nextTest;
gDisabled = [];
gUnknown = [];
gBlocked = [];
var frame = document.getElementById("testframe");
frame.src = file + ".html?" + Math.random();
}
function next_text() {
PluginUtils.withTestPlugin(gNextTest);
}
function frame_loaded() {
// We must delay to wait for the plugin sources to be loaded :(
setTimeout(next_text, 500);
}
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");
}
}
function test_normal(plugin) {
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");
plugin.disabled = true;
load_frame(test_disabled, "file_bug391728");
}
function test_disabled(plugin) {
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");
plugin.disabled = false;
plugin.blocklisted = true;
load_frame(test_blocked, "file_bug391728");
}
function test_blocked(plugin) {
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");
}
function test_unknown(plugin) {
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");
finish_test(plugin);
}
SimpleTest.waitForExplicitFinish();
window.addEventListener("load", init_test, false);
</script>
</pre>
</body>
</html>