|
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 var gRunNextTestAfterPluginRemoved = false; |
|
9 |
|
10 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
11 |
|
12 function test() { |
|
13 waitForExplicitFinish(); |
|
14 registerCleanupFunction(function() { |
|
15 clearAllPluginPermissions(); |
|
16 Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); |
|
17 gTestBrowser.removeEventListener("PluginRemoved", handlePluginRemoved, true, true); |
|
18 }); |
|
19 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); |
|
20 |
|
21 var newTab = gBrowser.addTab(); |
|
22 gBrowser.selectedTab = newTab; |
|
23 gTestBrowser = gBrowser.selectedBrowser; |
|
24 gTestBrowser.addEventListener("load", pageLoad, true); |
|
25 gTestBrowser.addEventListener("PluginRemoved", handlePluginRemoved, true, true); |
|
26 |
|
27 Services.prefs.setBoolPref("plugins.click_to_play", true); |
|
28 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
|
29 |
|
30 prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_two_types.html"); |
|
31 } |
|
32 |
|
33 function finishTest() { |
|
34 clearAllPluginPermissions(); |
|
35 gTestBrowser.removeEventListener("load", pageLoad, true); |
|
36 gBrowser.removeCurrentTab(); |
|
37 window.focus(); |
|
38 finish(); |
|
39 } |
|
40 |
|
41 function pageLoad() { |
|
42 // The plugin events are async dispatched and can come after the load event |
|
43 // This just allows the events to fire before we then go on to test the states |
|
44 executeSoon(gNextTest); |
|
45 } |
|
46 |
|
47 function prepareTest(nextTest, url) { |
|
48 gNextTest = nextTest; |
|
49 gTestBrowser.contentWindow.location = url; |
|
50 } |
|
51 |
|
52 // Due to layout being async, "PluginBindAttached" may trigger later. |
|
53 // This wraps a function to force a layout flush, thus triggering it, |
|
54 // and schedules the function execution so they're definitely executed |
|
55 // afterwards. |
|
56 function runAfterPluginBindingAttached(func) { |
|
57 return function() { |
|
58 let doc = gTestBrowser.contentDocument; |
|
59 let elems = doc.getElementsByTagName('embed'); |
|
60 if (elems.length < 1) { |
|
61 elems = doc.getElementsByTagName('object'); |
|
62 } |
|
63 elems[0].clientTop; |
|
64 executeSoon(func); |
|
65 }; |
|
66 } |
|
67 |
|
68 function handlePluginRemoved() { |
|
69 if (gRunNextTestAfterPluginRemoved) { |
|
70 executeSoon(gNextTest); |
|
71 gRunNextTestAfterPluginRemoved = false; |
|
72 } |
|
73 } |
|
74 |
|
75 function runAfterPluginRemoved(func) { |
|
76 gNextTest = func; |
|
77 gRunNextTestAfterPluginRemoved = true; |
|
78 } |
|
79 |
|
80 // Test that the click-to-play notification is not shown for non-plugin object elements |
|
81 |
|
82 function test1() { |
|
83 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
84 ok(popupNotification, "Test 1, Should have a click-to-play notification"); |
|
85 |
|
86 let plugin = gTestBrowser.contentDocument.getElementById("secondtestA"); |
|
87 plugin.parentNode.removeChild(plugin); |
|
88 plugin = gTestBrowser.contentDocument.getElementById("secondtestB"); |
|
89 plugin.parentNode.removeChild(plugin); |
|
90 |
|
91 let image = gTestBrowser.contentDocument.createElement("object"); |
|
92 image.type = "image/png"; |
|
93 image.data = "moz.png"; |
|
94 gTestBrowser.contentDocument.body.appendChild(image); |
|
95 |
|
96 runAfterPluginRemoved(test2); |
|
97 } |
|
98 |
|
99 function test2() { |
|
100 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
101 ok(popupNotification, "Test 2, Should have a click-to-play notification"); |
|
102 |
|
103 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
104 plugin.parentNode.removeChild(plugin); |
|
105 |
|
106 executeSoon(test3); |
|
107 } |
|
108 |
|
109 function test3() { |
|
110 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
111 ok(popupNotification, "Test 3, Should still have a click-to-play notification"); |
|
112 |
|
113 finishTest(); |
|
114 } |