1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/chrome/test_bug391728.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,201 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=391728 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 391728</title> 1.11 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=391728">Mozilla Bug 391728</a> 1.17 +<p id="display"></p> 1.18 +<div id="content"> 1.19 + <iframe id="testframe" width="150" height="250" src="about:blank"></iframe> 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script class="testbody" type="text/javascript"> 1.23 +const gHttpTestRoot = location.toString().replace("chrome://mochitests/content/", "http://127.0.0.1:8888/").split(/\//).slice(0, -1).join('/') + '/'; 1.24 + 1.25 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.26 + 1.27 +/** Test for Bug 391728 **/ 1.28 +// Plugins that should dispatch error events and have the pseudo classes set 1.29 +const PLUGIN_COUNT = 11; 1.30 +// Plugins that should neither dispatch error events or have the pseudo classes set 1.31 +const FALLBACK_COUNT = 5; 1.32 +const OBJLC = Components.interfaces.nsIObjectLoadingContent; 1.33 + 1.34 +var gNextTest = null; 1.35 +var gUnknown = []; 1.36 +var gBlocked = []; 1.37 +var gDisabled = []; 1.38 + 1.39 +function plugin_binding_attached(event) { 1.40 + var plugin = event.target; 1.41 + plugin instanceof OBJLC; 1.42 + switch (SpecialPowers.wrap(plugin).pluginFallbackType) { 1.43 + case OBJLC.PLUGIN_DISABLED: 1.44 + gDisabled.push(plugin.id); 1.45 + break; 1.46 + case OBJLC.PLUGIN_BLOCKLISTED: 1.47 + gBlocked.push(plugin.id); 1.48 + break; 1.49 + case OBJLC.PLUGIN_UNSUPPORTED: 1.50 + gUnknown.push(plugin.id); 1.51 + break; 1.52 + } 1.53 +} 1.54 + 1.55 +function init_test() { 1.56 + if (!PluginUtils.withTestPlugin(start_test)) 1.57 + SimpleTest.finish(); 1.58 +} 1.59 + 1.60 +function updateBlocklist(aCallback) { 1.61 + var blocklistNotifier = Components.classes["@mozilla.org/extensions/blocklist;1"] 1.62 + .getService(Components.interfaces.nsITimerCallback); 1.63 + var observer = function() { 1.64 + Services.obs.removeObserver(observer, "blocklist-updated"); 1.65 + SimpleTest.executeSoon(aCallback); 1.66 + }; 1.67 + Services.obs.addObserver(observer, "blocklist-updated", false); 1.68 + blocklistNotifier.notify(null); 1.69 +} 1.70 + 1.71 +var _originalBlocklistURL = null; 1.72 +function setAndUpdateBlocklist(aURL, aCallback) { 1.73 + info("Setting blocklist to " + aURL); 1.74 + if (!_originalBlocklistURL) { 1.75 + _originalBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url"); 1.76 + } 1.77 + Services.prefs.setCharPref("extensions.blocklist.url", aURL); 1.78 + updateBlocklist(aCallback); 1.79 +} 1.80 + 1.81 +function resetBlocklist() { 1.82 + info("resetting blocklist URL to " + _originalBlocklistURL); 1.83 + Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL); 1.84 +} 1.85 + 1.86 +function start_test(plugin) { 1.87 + Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); 1.88 + 1.89 + is(plugin.description, "Plug-in for testing purposes.\u2122 " + 1.90 + "(\u0939\u093f\u0928\u094d\u0926\u0940 " + 1.91 + "\u4e2d\u6587 " + 1.92 + "\u0627\u0644\u0639\u0631\u0628\u064a\u0629)", 1.93 + "Test plugin had an incorrect description"); 1.94 + is(plugin.version, "1.0.0.0", "Test plugin had an incorrect version"); 1.95 + ok(!plugin.disabled, "Test plugin should not be disabled"); 1.96 + ok(!plugin.blocklisted, "Test plugin should not be blocklisted"); 1.97 + 1.98 + var frame = document.getElementById("testframe"); 1.99 + frame.addEventListener("load", frame_loaded, true); 1.100 + load_frame(test_normal, "file_bug391728"); 1.101 +} 1.102 + 1.103 +function finish_test(plugin) { 1.104 + Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); 1.105 + resetBlocklist(); 1.106 + plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED; 1.107 + SimpleTest.finish(); 1.108 +} 1.109 + 1.110 +function load_frame(nextTest, file) { 1.111 + gNextTest = nextTest; 1.112 + gDisabled = []; 1.113 + gUnknown = []; 1.114 + gBlocked = []; 1.115 + var frame = document.getElementById("testframe"); 1.116 + frame.src = file + ".html?" + Math.random(); 1.117 +} 1.118 + 1.119 +function next_text() { 1.120 + PluginUtils.withTestPlugin(gNextTest); 1.121 +} 1.122 + 1.123 +function frame_loaded() { 1.124 + // We must delay to wait for the plugin sources to be loaded :( 1.125 + setTimeout(next_text, 500); 1.126 +} 1.127 + 1.128 +function test_style(expected) { 1.129 + var frame = document.getElementById("testframe"); 1.130 + for (var i = 1; i <= PLUGIN_COUNT; i++) { 1.131 + var tag = frame.contentDocument.getElementById("plugin" + i); 1.132 + ok(tag, "Plugin " + i + " did not exist"); 1.133 + var style = frame.contentWindow.getComputedStyle(tag, null); 1.134 + is(style.borderTopStyle, expected, "Plugin " + i + " had an incorrect border style"); 1.135 + } 1.136 + for (i = 1; i <= FALLBACK_COUNT; i++) { 1.137 + var tag = frame.contentDocument.getElementById("fallback" + i); 1.138 + ok(tag, "Fallback plugin " + i + " did not exist"); 1.139 + var style = frame.contentWindow.getComputedStyle(tag, null); 1.140 + is(style.borderTopStyle, "solid", "Fallback plugin " + i + " had an incorrect border style"); 1.141 + } 1.142 +} 1.143 + 1.144 +function test_list(list) { 1.145 + for (var i = 1; i <= PLUGIN_COUNT; i++) { 1.146 + ok(list.indexOf("plugin" + i) >= 0, "Plugin " + i + " did not send the event"); 1.147 + } 1.148 + for (i = 1; i <= FALLBACK_COUNT; i++) { 1.149 + ok(list.indexOf("fallback" + i) < 0, "Fallback plugin " + i + " should not have sent the event"); 1.150 + } 1.151 +} 1.152 + 1.153 +function test_normal(plugin) { 1.154 + is(gUnknown.length, 0, "Should not have been any unknown plugins"); 1.155 + is(gDisabled.length, 0, "Should not have been any disabled plugins"); 1.156 + is(gBlocked.length, 0, "Should not have been any blocked plugins"); 1.157 + test_style("solid"); 1.158 + plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_DISABLED; 1.159 + load_frame(test_disabled, "file_bug391728"); 1.160 +} 1.161 + 1.162 +function test_disabled(plugin) { 1.163 + is(gUnknown.length, 0, "Should not have been any unknown plugins"); 1.164 + is(gDisabled.length, PLUGIN_COUNT, "Should have been disabled plugins"); 1.165 + test_list(gDisabled); 1.166 + is(gBlocked.length, 0, "Should not have been any blocked plugins"); 1.167 + test_style("dotted"); 1.168 + ok(plugin.disabled, "Plugin lost its disabled status"); 1.169 + plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED; 1.170 + 1.171 + setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml", 1.172 + function() { 1.173 + load_frame(test_blocked, "file_bug391728"); 1.174 + }); 1.175 +} 1.176 + 1.177 +function test_blocked(plugin) { 1.178 + is(gUnknown.length, 0, "Should not have been any unknown plugins"); 1.179 + is(gDisabled.length, 0, "Should not have been any disabled plugins"); 1.180 + is(gBlocked.length, PLUGIN_COUNT, "Should have been blocked plugins"); 1.181 + test_list(gBlocked); 1.182 + test_style("dashed"); 1.183 + ok(plugin.blocklisted, "Plugin lost its blocklist status"); 1.184 + load_frame(test_unknown, "file_bug391728_2"); 1.185 +} 1.186 + 1.187 +function test_unknown(plugin) { 1.188 + is(gUnknown.length, PLUGIN_COUNT, "Should have been unknown plugins"); 1.189 + test_list(gUnknown); 1.190 + is(gDisabled.length, 0, "Should not have been any disabled plugins"); 1.191 + is(gBlocked.length, 0, "Should not have been any blocked plugins"); 1.192 + test_style("none"); 1.193 + setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() { 1.194 + ok(!plugin.blocklisted, "Plugin shouldn't remain blocklisted"); 1.195 + finish_test(plugin); 1.196 + }); 1.197 +} 1.198 + 1.199 +SimpleTest.waitForExplicitFinish(); 1.200 +window.addEventListener("load", init_test, false); 1.201 +</script> 1.202 +</pre> 1.203 +</body> 1.204 +</html>