|
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_data_url.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 still works when navigating to data URLs |
|
67 function test1a() { |
|
68 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
69 ok(popupNotification, "Test 1a, Should have a click-to-play notification"); |
|
70 |
|
71 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
72 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
73 ok(!objLoadingContent.activated, "Test 1a, Plugin should not be activated"); |
|
74 |
|
75 gNextTest = runAfterPluginBindingAttached(test1b); |
|
76 gTestBrowser.contentDocument.getElementById("data-link-1").click(); |
|
77 } |
|
78 |
|
79 function test1b() { |
|
80 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
81 ok(popupNotification, "Test 1b, Should have a click-to-play notification"); |
|
82 |
|
83 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
84 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
85 ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated"); |
|
86 |
|
87 // Simulate clicking the "Allow Always" button. |
|
88 popupNotification.reshow(); |
|
89 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
90 |
|
91 let condition = function() objLoadingContent.activated; |
|
92 waitForCondition(condition, test1c, "Test 1b, Waited too long for plugin to activate"); |
|
93 } |
|
94 |
|
95 function test1c() { |
|
96 clearAllPluginPermissions(); |
|
97 prepareTest(runAfterPluginBindingAttached(test2a), gHttpTestRoot + "plugin_data_url.html"); |
|
98 } |
|
99 |
|
100 // Test that the click-to-play notification doesn't break when navigating to data URLs with multiple plugins |
|
101 function test2a() { |
|
102 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
103 ok(popupNotification, "Test 2a, Should have a click-to-play notification"); |
|
104 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
105 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
106 ok(!objLoadingContent.activated, "Test 2a, Plugin should not be activated"); |
|
107 |
|
108 gNextTest = runAfterPluginBindingAttached(test2b); |
|
109 gTestBrowser.contentDocument.getElementById("data-link-2").click(); |
|
110 } |
|
111 |
|
112 function test2b() { |
|
113 let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
114 ok(notification, "Test 2b, Should have a click-to-play notification"); |
|
115 |
|
116 // Simulate choosing "Allow now" for the test plugin |
|
117 notification.reshow(); |
|
118 is(notification.options.pluginData.size, 2, "Test 2b, Should have two types of plugin in the notification"); |
|
119 |
|
120 var centerAction = null; |
|
121 for (var action of notification.options.pluginData.values()) { |
|
122 if (action.pluginName == "Test") { |
|
123 centerAction = action; |
|
124 break; |
|
125 } |
|
126 } |
|
127 ok(centerAction, "Test 2b, found center action for the Test plugin"); |
|
128 |
|
129 var centerItem = null; |
|
130 for (var item of PopupNotifications.panel.firstChild.childNodes) { |
|
131 is(item.value, "block", "Test 2b, all plugins should start out blocked"); |
|
132 if (item.action == centerAction) { |
|
133 centerItem = item; |
|
134 break; |
|
135 } |
|
136 } |
|
137 ok(centerItem, "Test 2b, found center item for the Test plugin"); |
|
138 |
|
139 // "click" the button to activate the Test plugin |
|
140 centerItem.value = "allownow"; |
|
141 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
142 |
|
143 let plugin = gTestBrowser.contentDocument.getElementById("test1"); |
|
144 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
145 let condition = function() objLoadingContent.activated; |
|
146 waitForCondition(condition, test2c, "Test 2b, Waited too long for plugin to activate"); |
|
147 } |
|
148 |
|
149 function test2c() { |
|
150 let plugin = gTestBrowser.contentDocument.getElementById("test1"); |
|
151 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
152 ok(objLoadingContent.activated, "Test 2c, Plugin should be activated"); |
|
153 |
|
154 clearAllPluginPermissions(); |
|
155 prepareTest(runAfterPluginBindingAttached(test3a), gHttpTestRoot + "plugin_data_url.html"); |
|
156 } |
|
157 |
|
158 // Test that when navigating to a data url, the plugin permission is inherited |
|
159 function test3a() { |
|
160 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
161 ok(popupNotification, "Test 3a, Should have a click-to-play notification"); |
|
162 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
163 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
164 ok(!objLoadingContent.activated, "Test 3a, Plugin should not be activated"); |
|
165 |
|
166 // Simulate clicking the "Allow Always" button. |
|
167 popupNotification.reshow(); |
|
168 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
169 |
|
170 let condition = function() objLoadingContent.activated; |
|
171 waitForCondition(condition, test3b, "Test 3a, Waited too long for plugin to activate"); |
|
172 } |
|
173 |
|
174 function test3b() { |
|
175 gNextTest = test3c; |
|
176 gTestBrowser.contentDocument.getElementById("data-link-1").click(); |
|
177 } |
|
178 |
|
179 function test3c() { |
|
180 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
181 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
182 ok(objLoadingContent.activated, "Test 3c, Plugin should be activated"); |
|
183 |
|
184 clearAllPluginPermissions(); |
|
185 prepareTest(runAfterPluginBindingAttached(test4b), |
|
186 'data:text/html,<embed id="test" style="width: 200px; height: 200px" type="application/x-test"/>'); |
|
187 } |
|
188 |
|
189 // Test that the click-to-play doorhanger still works when directly navigating to data URLs |
|
190 function test4a() { |
|
191 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
192 ok(popupNotification, "Test 4a, Should have a click-to-play notification"); |
|
193 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
194 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
195 ok(!objLoadingContent.activated, "Test 4a, Plugin should not be activated"); |
|
196 |
|
197 // Simulate clicking the "Allow Always" button. |
|
198 popupNotification.reshow(); |
|
199 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
200 |
|
201 let condition = function() objLoadingContent.activated; |
|
202 waitForCondition(condition, test4b, "Test 4a, Waited too long for plugin to activate"); |
|
203 } |
|
204 |
|
205 function test4b() { |
|
206 clearAllPluginPermissions(); |
|
207 finishTest(); |
|
208 } |