Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); |
michael@0 | 5 | |
michael@0 | 6 | let gNextTest = null; |
michael@0 | 7 | let gNewWindow = null; |
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("plugins.click_to_play"); |
michael@0 | 16 | }); |
michael@0 | 17 | Services.prefs.setBoolPref("plugins.click_to_play", true); |
michael@0 | 18 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
michael@0 | 19 | |
michael@0 | 20 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 21 | gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true); |
michael@0 | 22 | gNextTest = part1; |
michael@0 | 23 | gBrowser.selectedBrowser.contentDocument.location = gHttpTestRoot + "plugin_test.html"; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function handleEvent() { |
michael@0 | 27 | gNextTest(); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function part1() { |
michael@0 | 31 | gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); |
michael@0 | 32 | ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); |
michael@0 | 33 | |
michael@0 | 34 | gNextTest = part2; |
michael@0 | 35 | gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); |
michael@0 | 36 | gNewWindow.addEventListener("load", handleEvent, true); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function part2() { |
michael@0 | 40 | gNewWindow.removeEventListener("load", handleEvent); |
michael@0 | 41 | let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); |
michael@0 | 42 | waitForCondition(condition, part3, "Waited too long for click-to-play notification"); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function part3() { |
michael@0 | 46 | 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 | 47 | ok(!PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should not have a click-to-play notification in the old window now"); |
michael@0 | 48 | |
michael@0 | 49 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 50 | gBrowser.swapBrowsersAndCloseOther(gBrowser.selectedTab, gNewWindow.gBrowser.selectedTab); |
michael@0 | 51 | let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser); |
michael@0 | 52 | waitForCondition(condition, part4, "Waited too long for click-to-play notification"); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function part4() { |
michael@0 | 56 | ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab again"); |
michael@0 | 57 | |
michael@0 | 58 | gBrowser.selectedBrowser.addEventListener("PluginBindingAttached", handleEvent, true, true); |
michael@0 | 59 | gNextTest = part5; |
michael@0 | 60 | gBrowser.selectedBrowser.contentDocument.location = gHttpTestRoot + "plugin_test.html"; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function part5() { |
michael@0 | 64 | gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); |
michael@0 | 65 | ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); |
michael@0 | 66 | |
michael@0 | 67 | gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); |
michael@0 | 68 | waitForFocus(part6, gNewWindow); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function part6() { |
michael@0 | 72 | let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); |
michael@0 | 73 | waitForCondition(condition, part7, "Waited too long for click-to-play notification"); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function part7() { |
michael@0 | 77 | 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 | 78 | ok(!PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should not have a click-to-play notification in the old window now"); |
michael@0 | 79 | |
michael@0 | 80 | let plugin = gNewWindow.gBrowser.selectedBrowser.contentDocument.getElementById("test"); |
michael@0 | 81 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 82 | ok(!objLoadingContent.activated, "plugin should not be activated"); |
michael@0 | 83 | |
michael@0 | 84 | EventUtils.synthesizeMouseAtCenter(plugin, {}, gNewWindow.gBrowser.selectedBrowser.contentWindow); |
michael@0 | 85 | let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser).dismissed && gNewWindow.PopupNotifications.panel.firstChild; |
michael@0 | 86 | waitForCondition(condition, part8, "waited too long for plugin to activate"); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function part8() { |
michael@0 | 90 | // Click the activate button on doorhanger to make sure it works |
michael@0 | 91 | gNewWindow.PopupNotifications.panel.firstChild._primaryButton.click(); |
michael@0 | 92 | |
michael@0 | 93 | let plugin = gNewWindow.gBrowser.selectedBrowser.contentDocument.getElementById("test"); |
michael@0 | 94 | let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 95 | ok(objLoadingContent.activated, "plugin should be activated now"); |
michael@0 | 96 | |
michael@0 | 97 | gNewWindow.close(); |
michael@0 | 98 | gNewWindow = null; |
michael@0 | 99 | finish(); |
michael@0 | 100 | } |