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