|
1 var rootDir = getRootDirectory(gTestPath); |
|
2 const gTestRoot = rootDir; |
|
3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); |
|
4 |
|
5 var gTestBrowser = null; |
|
6 var gNextTest = null; |
|
7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost); |
|
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("extensions.blocklist.suppressUI"); |
|
16 }); |
|
17 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); |
|
18 |
|
19 var newTab = gBrowser.addTab(); |
|
20 gBrowser.selectedTab = newTab; |
|
21 gTestBrowser = gBrowser.selectedBrowser; |
|
22 gTestBrowser.addEventListener("load", pageLoad, true); |
|
23 |
|
24 Services.prefs.setBoolPref("plugins.click_to_play", true); |
|
25 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
|
26 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in"); |
|
27 |
|
28 prepareTest(test1a, gHttpTestRoot + "plugin_two_types.html"); |
|
29 } |
|
30 |
|
31 function finishTest() { |
|
32 clearAllPluginPermissions(); |
|
33 gTestBrowser.removeEventListener("load", pageLoad, true); |
|
34 gBrowser.removeCurrentTab(); |
|
35 window.focus(); |
|
36 finish(); |
|
37 } |
|
38 |
|
39 function pageLoad() { |
|
40 // The plugin events are async dispatched and can come after the load event |
|
41 // This just allows the events to fire before we then go on to test the states |
|
42 executeSoon(gNextTest); |
|
43 } |
|
44 |
|
45 function prepareTest(nextTest, url) { |
|
46 gNextTest = nextTest; |
|
47 gTestBrowser.contentWindow.location = url; |
|
48 } |
|
49 |
|
50 // Due to layout being async, "PluginBindAttached" may trigger later. |
|
51 // This wraps a function to force a layout flush, thus triggering it, |
|
52 // and schedules the function execution so they're definitely executed |
|
53 // afterwards. |
|
54 function runAfterPluginBindingAttached(func) { |
|
55 return function() { |
|
56 let doc = gTestBrowser.contentDocument; |
|
57 let elems = doc.getElementsByTagName('embed'); |
|
58 if (elems.length < 1) { |
|
59 elems = doc.getElementsByTagName('object'); |
|
60 } |
|
61 elems[0].clientTop; |
|
62 executeSoon(func); |
|
63 }; |
|
64 } |
|
65 |
|
66 // Test that the click-to-play doorhanger for multiple plugins shows the correct |
|
67 // state when re-opening without reloads or navigation. |
|
68 |
|
69 function test1a() { |
|
70 let doc = gTestBrowser.contentDocument; |
|
71 let plugin = doc.getElementById("test"); |
|
72 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
73 ok(!objLoadingContent.activated, "Test1a, Plugin should not be activated"); |
|
74 |
|
75 let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
76 ok(notification, "Test 1a, Should have a click-to-play notification"); |
|
77 notification.reshow(); |
|
78 |
|
79 is(notification.options.pluginData.size, 2, |
|
80 "Test 1a, Should have two types of plugin in the notification"); |
|
81 |
|
82 let pluginItem = null; |
|
83 for (let item of PopupNotifications.panel.firstChild.childNodes) { |
|
84 is(item.value, "block", "Test 1a, all plugins should start out blocked"); |
|
85 if (item.action.pluginName == "Test") { |
|
86 pluginItem = item; |
|
87 } |
|
88 } |
|
89 |
|
90 // Choose "Allow now" for the test plugin |
|
91 pluginItem.value = "allownow"; |
|
92 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
93 |
|
94 waitForCondition(() => objLoadingContent.activated, test1b, |
|
95 "Test 1a, Waited too long for plugin to activate"); |
|
96 } |
|
97 |
|
98 function test1b() { |
|
99 let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
100 ok(notification, "Test 1b, Should have a click-to-play notification"); |
|
101 notification.reshow(); |
|
102 |
|
103 let pluginItem = null; |
|
104 for (let item of PopupNotifications.panel.firstChild.childNodes) { |
|
105 if (item.action.pluginName == "Test") { |
|
106 is(item.value, "allownow", "Test 1b, Test plugin should now be set to 'Allow now'"); |
|
107 } else { |
|
108 is(item.value, "block", "Test 1b, Second Test plugin should still be blocked"); |
|
109 pluginItem = item; |
|
110 } |
|
111 } |
|
112 |
|
113 // Choose "Allow and remember" for the Second Test plugin |
|
114 pluginItem.value = "allowalways"; |
|
115 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
116 |
|
117 let doc = gTestBrowser.contentDocument; |
|
118 let plugin = doc.getElementById("secondtestA"); |
|
119 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
120 waitForCondition(() => objLoadingContent.activated, test1c, |
|
121 "Test 1b, Waited too long for plugin to activate"); |
|
122 } |
|
123 |
|
124 function test1c() { |
|
125 let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
126 ok(notification, "Test 1c, Should have a click-to-play notification"); |
|
127 notification.reshow(); |
|
128 |
|
129 for (let item of PopupNotifications.panel.firstChild.childNodes) { |
|
130 if (item.action.pluginName == "Test") { |
|
131 is(item.value, "allownow", "Test 1c, Test plugin should be set to 'Allow now'"); |
|
132 } else { |
|
133 is(item.value, "allowalways", "Test 1c, Second Test plugin should be set to 'Allow always'"); |
|
134 } |
|
135 } |
|
136 |
|
137 finishTest(); |
|
138 } |