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