michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); michael@0: michael@0: let gNextTest = null; michael@0: let gNewWindow = null; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: registerCleanupFunction(function() { michael@0: clearAllPluginPermissions(); michael@0: Services.prefs.clearUserPref("plugins.click_to_play"); michael@0: }); michael@0: Services.prefs.setBoolPref("plugins.click_to_play", true); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true); michael@0: gNextTest = part1; michael@0: gBrowser.selectedBrowser.contentDocument.location = gHttpTestRoot + "plugin_test.html"; michael@0: } michael@0: michael@0: function handleEvent() { michael@0: gNextTest(); michael@0: } michael@0: michael@0: function part1() { michael@0: gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); michael@0: michael@0: gNextTest = part2; michael@0: gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); michael@0: gNewWindow.addEventListener("load", handleEvent, true); michael@0: } michael@0: michael@0: function part2() { michael@0: gNewWindow.removeEventListener("load", handleEvent); michael@0: let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); michael@0: waitForCondition(condition, part3, "Waited too long for click-to-play notification"); michael@0: } michael@0: michael@0: function part3() { michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser), "Should have a click-to-play notification in the tab in the new window"); michael@0: ok(!PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should not have a click-to-play notification in the old window now"); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, gNewWindow.gBrowser.selectedTab); michael@0: let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser); michael@0: waitForCondition(condition, part4, "Waited too long for click-to-play notification"); michael@0: } michael@0: michael@0: function part4() { michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab again"); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true); michael@0: gNextTest = part5; michael@0: gBrowser.selectedBrowser.contentDocument.location = gHttpTestRoot + "plugin_test.html"; michael@0: } michael@0: michael@0: function part5() { michael@0: gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); michael@0: michael@0: gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); michael@0: waitForFocus(part6, gNewWindow); michael@0: } michael@0: michael@0: function part6() { michael@0: let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); michael@0: waitForCondition(condition, part7, "Waited too long for click-to-play notification"); michael@0: } michael@0: michael@0: function part7() { michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser), "Should have a click-to-play notification in the tab in the new window"); michael@0: ok(!PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should not have a click-to-play notification in the old window now"); michael@0: michael@0: let plugin = gNewWindow.gBrowser.selectedBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "plugin should not be activated"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(plugin, {}, gNewWindow.gBrowser.selectedBrowser.contentWindow); michael@0: let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser).dismissed && gNewWindow.PopupNotifications.panel.firstChild; michael@0: waitForCondition(condition, part8, "waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function part8() { michael@0: // Click the activate button on doorhanger to make sure it works michael@0: gNewWindow.PopupNotifications.panel.firstChild._primaryButton.click(); michael@0: michael@0: let plugin = gNewWindow.gBrowser.selectedBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "plugin should be activated now"); michael@0: michael@0: gNewWindow.close(); michael@0: gNewWindow = null; michael@0: finish(); michael@0: }