Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | var rootDir = getRootDirectory(gTestPath); |
michael@0 | 2 | const gTestRoot = rootDir; |
michael@0 | 3 | const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); |
michael@0 | 4 | |
michael@0 | 5 | var gTestBrowser = null; |
michael@0 | 6 | var gNextTest = null; |
michael@0 | 7 | var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost); |
michael@0 | 8 | |
michael@0 | 9 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | waitForExplicitFinish(); |
michael@0 | 13 | registerCleanupFunction(function() { |
michael@0 | 14 | clearAllPluginPermissions(); |
michael@0 | 15 | Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); |
michael@0 | 16 | }); |
michael@0 | 17 | Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); |
michael@0 | 18 | |
michael@0 | 19 | var newTab = gBrowser.addTab(); |
michael@0 | 20 | gBrowser.selectedTab = newTab; |
michael@0 | 21 | gTestBrowser = gBrowser.selectedBrowser; |
michael@0 | 22 | gTestBrowser.addEventListener("load", pageLoad, true); |
michael@0 | 23 | |
michael@0 | 24 | Services.prefs.setBoolPref("plugins.click_to_play", true); |
michael@0 | 25 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
michael@0 | 26 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in"); |
michael@0 | 27 | |
michael@0 | 28 | prepareTest(test1a, gHttpTestRoot + "plugin_data_url.html"); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function finishTest() { |
michael@0 | 32 | clearAllPluginPermissions(); |
michael@0 | 33 | gTestBrowser.removeEventListener("load", pageLoad, true); |
michael@0 | 34 | gBrowser.removeCurrentTab(); |
michael@0 | 35 | window.focus(); |
michael@0 | 36 | finish(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function pageLoad() { |
michael@0 | 40 | // The plugin events are async dispatched and can come after the load event |
michael@0 | 41 | // This just allows the events to fire before we then go on to test the states |
michael@0 | 42 | executeSoon(gNextTest); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function prepareTest(nextTest, url) { |
michael@0 | 46 | gNextTest = nextTest; |
michael@0 | 47 | gTestBrowser.contentWindow.location = url; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | // Due to layout being async, "PluginBindAttached" may trigger later. |
michael@0 | 51 | // This wraps a function to force a layout flush, thus triggering it, |
michael@0 | 52 | // and schedules the function execution so they're definitely executed |
michael@0 | 53 | // afterwards. |
michael@0 | 54 | function runAfterPluginBindingAttached(func) { |
michael@0 | 55 | return function() { |
michael@0 | 56 | let doc = gTestBrowser.contentDocument; |
michael@0 | 57 | let elems = doc.getElementsByTagName('embed'); |
michael@0 | 58 | if (elems.length < 1) { |
michael@0 | 59 | elems = doc.getElementsByTagName('object'); |
michael@0 | 60 | } |
michael@0 | 61 | elems[0].clientTop; |
michael@0 | 62 | executeSoon(func); |
michael@0 | 63 | }; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | // Test that the click-to-play doorhanger still works when navigating to data URLs |
michael@0 | 67 | function test1a() { |
michael@0 | 68 | let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 69 | ok(popupNotification, "Test 1a, Should have a click-to-play notification"); |
michael@0 | 70 | |
michael@0 | 71 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 72 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 73 | ok(!objLoadingContent.activated, "Test 1a, Plugin should not be activated"); |
michael@0 | 74 | |
michael@0 | 75 | gNextTest = runAfterPluginBindingAttached(test1b); |
michael@0 | 76 | gTestBrowser.contentDocument.getElementById("data-link-1").click(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | function test1b() { |
michael@0 | 80 | let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 81 | ok(popupNotification, "Test 1b, Should have a click-to-play notification"); |
michael@0 | 82 | |
michael@0 | 83 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 84 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 85 | ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated"); |
michael@0 | 86 | |
michael@0 | 87 | // Simulate clicking the "Allow Always" button. |
michael@0 | 88 | popupNotification.reshow(); |
michael@0 | 89 | PopupNotifications.panel.firstChild._primaryButton.click(); |
michael@0 | 90 | |
michael@0 | 91 | let condition = function() objLoadingContent.activated; |
michael@0 | 92 | waitForCondition(condition, test1c, "Test 1b, Waited too long for plugin to activate"); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | function test1c() { |
michael@0 | 96 | clearAllPluginPermissions(); |
michael@0 | 97 | prepareTest(runAfterPluginBindingAttached(test2a), gHttpTestRoot + "plugin_data_url.html"); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | // Test that the click-to-play notification doesn't break when navigating to data URLs with multiple plugins |
michael@0 | 101 | function test2a() { |
michael@0 | 102 | let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 103 | ok(popupNotification, "Test 2a, Should have a click-to-play notification"); |
michael@0 | 104 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 105 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 106 | ok(!objLoadingContent.activated, "Test 2a, Plugin should not be activated"); |
michael@0 | 107 | |
michael@0 | 108 | gNextTest = runAfterPluginBindingAttached(test2b); |
michael@0 | 109 | gTestBrowser.contentDocument.getElementById("data-link-2").click(); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | function test2b() { |
michael@0 | 113 | let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 114 | ok(notification, "Test 2b, Should have a click-to-play notification"); |
michael@0 | 115 | |
michael@0 | 116 | // Simulate choosing "Allow now" for the test plugin |
michael@0 | 117 | notification.reshow(); |
michael@0 | 118 | is(notification.options.pluginData.size, 2, "Test 2b, Should have two types of plugin in the notification"); |
michael@0 | 119 | |
michael@0 | 120 | var centerAction = null; |
michael@0 | 121 | for (var action of notification.options.pluginData.values()) { |
michael@0 | 122 | if (action.pluginName == "Test") { |
michael@0 | 123 | centerAction = action; |
michael@0 | 124 | break; |
michael@0 | 125 | } |
michael@0 | 126 | } |
michael@0 | 127 | ok(centerAction, "Test 2b, found center action for the Test plugin"); |
michael@0 | 128 | |
michael@0 | 129 | var centerItem = null; |
michael@0 | 130 | for (var item of PopupNotifications.panel.firstChild.childNodes) { |
michael@0 | 131 | is(item.value, "block", "Test 2b, all plugins should start out blocked"); |
michael@0 | 132 | if (item.action == centerAction) { |
michael@0 | 133 | centerItem = item; |
michael@0 | 134 | break; |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | ok(centerItem, "Test 2b, found center item for the Test plugin"); |
michael@0 | 138 | |
michael@0 | 139 | // "click" the button to activate the Test plugin |
michael@0 | 140 | centerItem.value = "allownow"; |
michael@0 | 141 | PopupNotifications.panel.firstChild._primaryButton.click(); |
michael@0 | 142 | |
michael@0 | 143 | let plugin = gTestBrowser.contentDocument.getElementById("test1"); |
michael@0 | 144 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 145 | let condition = function() objLoadingContent.activated; |
michael@0 | 146 | waitForCondition(condition, test2c, "Test 2b, Waited too long for plugin to activate"); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | function test2c() { |
michael@0 | 150 | let plugin = gTestBrowser.contentDocument.getElementById("test1"); |
michael@0 | 151 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 152 | ok(objLoadingContent.activated, "Test 2c, Plugin should be activated"); |
michael@0 | 153 | |
michael@0 | 154 | clearAllPluginPermissions(); |
michael@0 | 155 | prepareTest(runAfterPluginBindingAttached(test3a), gHttpTestRoot + "plugin_data_url.html"); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | // Test that when navigating to a data url, the plugin permission is inherited |
michael@0 | 159 | function test3a() { |
michael@0 | 160 | let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 161 | ok(popupNotification, "Test 3a, Should have a click-to-play notification"); |
michael@0 | 162 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 163 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 164 | ok(!objLoadingContent.activated, "Test 3a, Plugin should not be activated"); |
michael@0 | 165 | |
michael@0 | 166 | // Simulate clicking the "Allow Always" button. |
michael@0 | 167 | popupNotification.reshow(); |
michael@0 | 168 | PopupNotifications.panel.firstChild._primaryButton.click(); |
michael@0 | 169 | |
michael@0 | 170 | let condition = function() objLoadingContent.activated; |
michael@0 | 171 | waitForCondition(condition, test3b, "Test 3a, Waited too long for plugin to activate"); |
michael@0 | 172 | } |
michael@0 | 173 | |
michael@0 | 174 | function test3b() { |
michael@0 | 175 | gNextTest = test3c; |
michael@0 | 176 | gTestBrowser.contentDocument.getElementById("data-link-1").click(); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | function test3c() { |
michael@0 | 180 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 181 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 182 | ok(objLoadingContent.activated, "Test 3c, Plugin should be activated"); |
michael@0 | 183 | |
michael@0 | 184 | clearAllPluginPermissions(); |
michael@0 | 185 | prepareTest(runAfterPluginBindingAttached(test4b), |
michael@0 | 186 | 'data:text/html,<embed id="test" style="width: 200px; height: 200px" type="application/x-test"/>'); |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | // Test that the click-to-play doorhanger still works when directly navigating to data URLs |
michael@0 | 190 | function test4a() { |
michael@0 | 191 | let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 192 | ok(popupNotification, "Test 4a, Should have a click-to-play notification"); |
michael@0 | 193 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 194 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 195 | ok(!objLoadingContent.activated, "Test 4a, Plugin should not be activated"); |
michael@0 | 196 | |
michael@0 | 197 | // Simulate clicking the "Allow Always" button. |
michael@0 | 198 | popupNotification.reshow(); |
michael@0 | 199 | PopupNotifications.panel.firstChild._primaryButton.click(); |
michael@0 | 200 | |
michael@0 | 201 | let condition = function() objLoadingContent.activated; |
michael@0 | 202 | waitForCondition(condition, test4b, "Test 4a, Waited too long for plugin to activate"); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | function test4b() { |
michael@0 | 206 | clearAllPluginPermissions(); |
michael@0 | 207 | finishTest(); |
michael@0 | 208 | } |