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 | 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 | |
michael@0 | 8 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 9 | |
michael@0 | 10 | function test() { |
michael@0 | 11 | waitForExplicitFinish(); |
michael@0 | 12 | registerCleanupFunction(function() { |
michael@0 | 13 | clearAllPluginPermissions(); |
michael@0 | 14 | Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); |
michael@0 | 15 | }); |
michael@0 | 16 | Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); |
michael@0 | 17 | |
michael@0 | 18 | var newTab = gBrowser.addTab(); |
michael@0 | 19 | gBrowser.selectedTab = newTab; |
michael@0 | 20 | gTestBrowser = gBrowser.selectedBrowser; |
michael@0 | 21 | gTestBrowser.addEventListener("load", pageLoad, true); |
michael@0 | 22 | |
michael@0 | 23 | Services.prefs.setBoolPref("plugins.click_to_play", true); |
michael@0 | 24 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
michael@0 | 25 | |
michael@0 | 26 | prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_small.html"); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function finishTest() { |
michael@0 | 30 | gTestBrowser.removeEventListener("load", pageLoad, true); |
michael@0 | 31 | gBrowser.removeCurrentTab(); |
michael@0 | 32 | window.focus(); |
michael@0 | 33 | finish(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function pageLoad() { |
michael@0 | 37 | // The plugin events are async dispatched and can come after the load event |
michael@0 | 38 | // This just allows the events to fire before we then go on to test the states |
michael@0 | 39 | executeSoon(gNextTest); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function prepareTest(nextTest, url) { |
michael@0 | 43 | gNextTest = nextTest; |
michael@0 | 44 | gTestBrowser.contentWindow.location = url; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | // Due to layout being async, "PluginBindAttached" may trigger later. |
michael@0 | 48 | // This wraps a function to force a layout flush, thus triggering it, |
michael@0 | 49 | // and schedules the function execution so they're definitely executed |
michael@0 | 50 | // afterwards. |
michael@0 | 51 | function runAfterPluginBindingAttached(func) { |
michael@0 | 52 | return function() { |
michael@0 | 53 | let doc = gTestBrowser.contentDocument; |
michael@0 | 54 | let elems = doc.getElementsByTagName('embed'); |
michael@0 | 55 | if (elems.length < 1) { |
michael@0 | 56 | elems = doc.getElementsByTagName('object'); |
michael@0 | 57 | } |
michael@0 | 58 | elems[0].clientTop; |
michael@0 | 59 | executeSoon(func); |
michael@0 | 60 | }; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | // Tests for the notification bar for hidden plugins. |
michael@0 | 64 | |
michael@0 | 65 | function test1() { |
michael@0 | 66 | let notification = PopupNotifications.getNotification("click-to-play-plugins"); |
michael@0 | 67 | ok(notification, "Test 1: There should be a plugin notification"); |
michael@0 | 68 | |
michael@0 | 69 | let notificationBox = gBrowser.getNotificationBox(gTestBrowser); |
michael@0 | 70 | |
michael@0 | 71 | waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, |
michael@0 | 72 | () => { |
michael@0 | 73 | // Don't use setTestPluginEnabledState here because we already saved the |
michael@0 | 74 | // prior value |
michael@0 | 75 | getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED; |
michael@0 | 76 | prepareTest(test2, gTestRoot + "plugin_small.html"); |
michael@0 | 77 | }, |
michael@0 | 78 | "Test 1, expected to have a plugin notification bar"); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function test2() { |
michael@0 | 82 | let notification = PopupNotifications.getNotification("click-to-play-plugins"); |
michael@0 | 83 | ok(notification, "Test 2: There should be a plugin notification"); |
michael@0 | 84 | |
michael@0 | 85 | let notificationBox = gBrowser.getNotificationBox(gTestBrowser); |
michael@0 | 86 | |
michael@0 | 87 | waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, |
michael@0 | 88 | () => { |
michael@0 | 89 | getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; |
michael@0 | 90 | prepareTest(test3, gTestRoot + "plugin_overlayed.html"); |
michael@0 | 91 | }, |
michael@0 | 92 | "Test 2, expected to not have a plugin notification bar"); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | function test3() { |
michael@0 | 96 | let notification = PopupNotifications.getNotification("click-to-play-plugins"); |
michael@0 | 97 | ok(notification, "Test 3: There should be a plugin notification"); |
michael@0 | 98 | |
michael@0 | 99 | let notificationBox = gBrowser.getNotificationBox(gTestBrowser); |
michael@0 | 100 | waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, |
michael@0 | 101 | test3b, |
michael@0 | 102 | "Test 3, expected the plugin infobar to be triggered when plugin was overlayed"); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | function test3b() |
michael@0 | 106 | { |
michael@0 | 107 | let doc = gTestBrowser.contentDocument; |
michael@0 | 108 | let plugin = doc.getElementById("test"); |
michael@0 | 109 | ok(plugin, "Test 3b, Found plugin in page"); |
michael@0 | 110 | plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 111 | is(plugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, |
michael@0 | 112 | "Test 3b, plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); |
michael@0 | 113 | ok(!plugin.activated, "Test 3b, Plugin should not be activated"); |
michael@0 | 114 | let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); |
michael@0 | 115 | ok(!overlay.classList.contains("visible"), "Test 3b, Plugin overlay should be hidden"); |
michael@0 | 116 | |
michael@0 | 117 | prepareTest(test4, gTestRoot + "plugin_positioned.html"); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function test4() { |
michael@0 | 121 | let notification = PopupNotifications.getNotification("click-to-play-plugins"); |
michael@0 | 122 | ok(notification, "Test 4: There should be a plugin notification"); |
michael@0 | 123 | |
michael@0 | 124 | let notificationBox = gBrowser.getNotificationBox(gTestBrowser); |
michael@0 | 125 | waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, |
michael@0 | 126 | test4b, |
michael@0 | 127 | "Test 4, expected the plugin infobar to be triggered when plugin was overlayed"); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function test4b() { |
michael@0 | 131 | let doc = gTestBrowser.contentDocument; |
michael@0 | 132 | let plugin = doc.getElementById("test"); |
michael@0 | 133 | ok(plugin, "Test 4b, Found plugin in page"); |
michael@0 | 134 | plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 135 | is(plugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, |
michael@0 | 136 | "Test 4b, plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); |
michael@0 | 137 | ok(!plugin.activated, "Test 4b, Plugin should not be activated"); |
michael@0 | 138 | let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); |
michael@0 | 139 | ok(!overlay.classList.contains("visible"), "Test 4b, Plugin overlay should be hidden"); |
michael@0 | 140 | |
michael@0 | 141 | prepareTest(runAfterPluginBindingAttached(test5), gHttpTestRoot + "plugin_small.html"); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | // Test that the notification bar is getting dismissed when directly activating plugins |
michael@0 | 145 | // via the doorhanger. |
michael@0 | 146 | |
michael@0 | 147 | function test5() { |
michael@0 | 148 | let notificationBox = gBrowser.getNotificationBox(gTestBrowser); |
michael@0 | 149 | waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, |
michael@0 | 150 | test6, |
michael@0 | 151 | "Test 5, expected a notification bar for hidden plugins"); |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | function test6() { |
michael@0 | 155 | let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 156 | ok(notification, "Test 6, Should have a click-to-play notification"); |
michael@0 | 157 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 158 | ok(plugin, "Test 6, Found plugin in page"); |
michael@0 | 159 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 160 | is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, |
michael@0 | 161 | "Test 6, Plugin should be click-to-play"); |
michael@0 | 162 | |
michael@0 | 163 | // simulate "always allow" |
michael@0 | 164 | notification.reshow(); |
michael@0 | 165 | PopupNotifications.panel.firstChild._primaryButton.click(); |
michael@0 | 166 | |
michael@0 | 167 | let notificationBox = gBrowser.getNotificationBox(gTestBrowser); |
michael@0 | 168 | waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, |
michael@0 | 169 | test7, |
michael@0 | 170 | "Test 6, expected the notification bar for hidden plugins to get dismissed"); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | function test7() { |
michael@0 | 174 | let plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 175 | ok(plugin, "Test 7, Found plugin in page"); |
michael@0 | 176 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 177 | waitForCondition(() => objLoadingContent.activated, finishTest, |
michael@0 | 178 | "Test 7, Waited too long for plugin to activate"); |
michael@0 | 179 | } |