Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=391728 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 391728</title> |
michael@0 | 8 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=391728">Mozilla Bug 391728</a> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content"> |
michael@0 | 16 | <iframe id="testframe" width="150" height="250" src="about:blank"></iframe> |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script class="testbody" type="text/javascript"> |
michael@0 | 20 | const gHttpTestRoot = location.toString().replace("chrome://mochitests/content/", "http://127.0.0.1:8888/").split(/\//).slice(0, -1).join('/') + '/'; |
michael@0 | 21 | |
michael@0 | 22 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 23 | |
michael@0 | 24 | /** Test for Bug 391728 **/ |
michael@0 | 25 | // Plugins that should dispatch error events and have the pseudo classes set |
michael@0 | 26 | const PLUGIN_COUNT = 11; |
michael@0 | 27 | // Plugins that should neither dispatch error events or have the pseudo classes set |
michael@0 | 28 | const FALLBACK_COUNT = 5; |
michael@0 | 29 | const OBJLC = Components.interfaces.nsIObjectLoadingContent; |
michael@0 | 30 | |
michael@0 | 31 | var gNextTest = null; |
michael@0 | 32 | var gUnknown = []; |
michael@0 | 33 | var gBlocked = []; |
michael@0 | 34 | var gDisabled = []; |
michael@0 | 35 | |
michael@0 | 36 | function plugin_binding_attached(event) { |
michael@0 | 37 | var plugin = event.target; |
michael@0 | 38 | plugin instanceof OBJLC; |
michael@0 | 39 | switch (SpecialPowers.wrap(plugin).pluginFallbackType) { |
michael@0 | 40 | case OBJLC.PLUGIN_DISABLED: |
michael@0 | 41 | gDisabled.push(plugin.id); |
michael@0 | 42 | break; |
michael@0 | 43 | case OBJLC.PLUGIN_BLOCKLISTED: |
michael@0 | 44 | gBlocked.push(plugin.id); |
michael@0 | 45 | break; |
michael@0 | 46 | case OBJLC.PLUGIN_UNSUPPORTED: |
michael@0 | 47 | gUnknown.push(plugin.id); |
michael@0 | 48 | break; |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function init_test() { |
michael@0 | 53 | if (!PluginUtils.withTestPlugin(start_test)) |
michael@0 | 54 | SimpleTest.finish(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function updateBlocklist(aCallback) { |
michael@0 | 58 | var blocklistNotifier = Components.classes["@mozilla.org/extensions/blocklist;1"] |
michael@0 | 59 | .getService(Components.interfaces.nsITimerCallback); |
michael@0 | 60 | var observer = function() { |
michael@0 | 61 | Services.obs.removeObserver(observer, "blocklist-updated"); |
michael@0 | 62 | SimpleTest.executeSoon(aCallback); |
michael@0 | 63 | }; |
michael@0 | 64 | Services.obs.addObserver(observer, "blocklist-updated", false); |
michael@0 | 65 | blocklistNotifier.notify(null); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | var _originalBlocklistURL = null; |
michael@0 | 69 | function setAndUpdateBlocklist(aURL, aCallback) { |
michael@0 | 70 | info("Setting blocklist to " + aURL); |
michael@0 | 71 | if (!_originalBlocklistURL) { |
michael@0 | 72 | _originalBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url"); |
michael@0 | 73 | } |
michael@0 | 74 | Services.prefs.setCharPref("extensions.blocklist.url", aURL); |
michael@0 | 75 | updateBlocklist(aCallback); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function resetBlocklist() { |
michael@0 | 79 | info("resetting blocklist URL to " + _originalBlocklistURL); |
michael@0 | 80 | Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function start_test(plugin) { |
michael@0 | 84 | Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); |
michael@0 | 85 | |
michael@0 | 86 | is(plugin.description, "Plug-in for testing purposes.\u2122 " + |
michael@0 | 87 | "(\u0939\u093f\u0928\u094d\u0926\u0940 " + |
michael@0 | 88 | "\u4e2d\u6587 " + |
michael@0 | 89 | "\u0627\u0644\u0639\u0631\u0628\u064a\u0629)", |
michael@0 | 90 | "Test plugin had an incorrect description"); |
michael@0 | 91 | is(plugin.version, "1.0.0.0", "Test plugin had an incorrect version"); |
michael@0 | 92 | ok(!plugin.disabled, "Test plugin should not be disabled"); |
michael@0 | 93 | ok(!plugin.blocklisted, "Test plugin should not be blocklisted"); |
michael@0 | 94 | |
michael@0 | 95 | var frame = document.getElementById("testframe"); |
michael@0 | 96 | frame.addEventListener("load", frame_loaded, true); |
michael@0 | 97 | load_frame(test_normal, "file_bug391728"); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function finish_test(plugin) { |
michael@0 | 101 | Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); |
michael@0 | 102 | resetBlocklist(); |
michael@0 | 103 | plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED; |
michael@0 | 104 | SimpleTest.finish(); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function load_frame(nextTest, file) { |
michael@0 | 108 | gNextTest = nextTest; |
michael@0 | 109 | gDisabled = []; |
michael@0 | 110 | gUnknown = []; |
michael@0 | 111 | gBlocked = []; |
michael@0 | 112 | var frame = document.getElementById("testframe"); |
michael@0 | 113 | frame.src = file + ".html?" + Math.random(); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function next_text() { |
michael@0 | 117 | PluginUtils.withTestPlugin(gNextTest); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function frame_loaded() { |
michael@0 | 121 | // We must delay to wait for the plugin sources to be loaded :( |
michael@0 | 122 | setTimeout(next_text, 500); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function test_style(expected) { |
michael@0 | 126 | var frame = document.getElementById("testframe"); |
michael@0 | 127 | for (var i = 1; i <= PLUGIN_COUNT; i++) { |
michael@0 | 128 | var tag = frame.contentDocument.getElementById("plugin" + i); |
michael@0 | 129 | ok(tag, "Plugin " + i + " did not exist"); |
michael@0 | 130 | var style = frame.contentWindow.getComputedStyle(tag, null); |
michael@0 | 131 | is(style.borderTopStyle, expected, "Plugin " + i + " had an incorrect border style"); |
michael@0 | 132 | } |
michael@0 | 133 | for (i = 1; i <= FALLBACK_COUNT; i++) { |
michael@0 | 134 | var tag = frame.contentDocument.getElementById("fallback" + i); |
michael@0 | 135 | ok(tag, "Fallback plugin " + i + " did not exist"); |
michael@0 | 136 | var style = frame.contentWindow.getComputedStyle(tag, null); |
michael@0 | 137 | is(style.borderTopStyle, "solid", "Fallback plugin " + i + " had an incorrect border style"); |
michael@0 | 138 | } |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | function test_list(list) { |
michael@0 | 142 | for (var i = 1; i <= PLUGIN_COUNT; i++) { |
michael@0 | 143 | ok(list.indexOf("plugin" + i) >= 0, "Plugin " + i + " did not send the event"); |
michael@0 | 144 | } |
michael@0 | 145 | for (i = 1; i <= FALLBACK_COUNT; i++) { |
michael@0 | 146 | ok(list.indexOf("fallback" + i) < 0, "Fallback plugin " + i + " should not have sent the event"); |
michael@0 | 147 | } |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | function test_normal(plugin) { |
michael@0 | 151 | is(gUnknown.length, 0, "Should not have been any unknown plugins"); |
michael@0 | 152 | is(gDisabled.length, 0, "Should not have been any disabled plugins"); |
michael@0 | 153 | is(gBlocked.length, 0, "Should not have been any blocked plugins"); |
michael@0 | 154 | test_style("solid"); |
michael@0 | 155 | plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_DISABLED; |
michael@0 | 156 | load_frame(test_disabled, "file_bug391728"); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | function test_disabled(plugin) { |
michael@0 | 160 | is(gUnknown.length, 0, "Should not have been any unknown plugins"); |
michael@0 | 161 | is(gDisabled.length, PLUGIN_COUNT, "Should have been disabled plugins"); |
michael@0 | 162 | test_list(gDisabled); |
michael@0 | 163 | is(gBlocked.length, 0, "Should not have been any blocked plugins"); |
michael@0 | 164 | test_style("dotted"); |
michael@0 | 165 | ok(plugin.disabled, "Plugin lost its disabled status"); |
michael@0 | 166 | plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED; |
michael@0 | 167 | |
michael@0 | 168 | setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml", |
michael@0 | 169 | function() { |
michael@0 | 170 | load_frame(test_blocked, "file_bug391728"); |
michael@0 | 171 | }); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | function test_blocked(plugin) { |
michael@0 | 175 | is(gUnknown.length, 0, "Should not have been any unknown plugins"); |
michael@0 | 176 | is(gDisabled.length, 0, "Should not have been any disabled plugins"); |
michael@0 | 177 | is(gBlocked.length, PLUGIN_COUNT, "Should have been blocked plugins"); |
michael@0 | 178 | test_list(gBlocked); |
michael@0 | 179 | test_style("dashed"); |
michael@0 | 180 | ok(plugin.blocklisted, "Plugin lost its blocklist status"); |
michael@0 | 181 | load_frame(test_unknown, "file_bug391728_2"); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | function test_unknown(plugin) { |
michael@0 | 185 | is(gUnknown.length, PLUGIN_COUNT, "Should have been unknown plugins"); |
michael@0 | 186 | test_list(gUnknown); |
michael@0 | 187 | is(gDisabled.length, 0, "Should not have been any disabled plugins"); |
michael@0 | 188 | is(gBlocked.length, 0, "Should not have been any blocked plugins"); |
michael@0 | 189 | test_style("none"); |
michael@0 | 190 | setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() { |
michael@0 | 191 | ok(!plugin.blocklisted, "Plugin shouldn't remain blocklisted"); |
michael@0 | 192 | finish_test(plugin); |
michael@0 | 193 | }); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 197 | window.addEventListener("load", init_test, false); |
michael@0 | 198 | </script> |
michael@0 | 199 | </pre> |
michael@0 | 200 | </body> |
michael@0 | 201 | </html> |