|
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 let 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 |
|
27 prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_test.html"); |
|
28 } |
|
29 |
|
30 function finishTest() { |
|
31 clearAllPluginPermissions(); |
|
32 gTestBrowser.removeEventListener("load", pageLoad, true); |
|
33 gBrowser.removeCurrentTab(); |
|
34 window.focus(); |
|
35 finish(); |
|
36 } |
|
37 |
|
38 function pageLoad() { |
|
39 // The plugin events are async dispatched and can come after the load event |
|
40 // This just allows the events to fire before we then go on to test the states |
|
41 executeSoon(gNextTest); |
|
42 } |
|
43 |
|
44 function prepareTest(nextTest, url) { |
|
45 gNextTest = nextTest; |
|
46 gTestBrowser.contentWindow.location = url; |
|
47 } |
|
48 |
|
49 // Due to layout being async, "PluginBindAttached" may trigger later. |
|
50 // This wraps a function to force a layout flush, thus triggering it, |
|
51 // and schedules the function execution so they're definitely executed |
|
52 // afterwards. |
|
53 function runAfterPluginBindingAttached(func) { |
|
54 return function() { |
|
55 let doc = gTestBrowser.contentDocument; |
|
56 let elems = doc.getElementsByTagName('embed'); |
|
57 if (elems.length < 1) { |
|
58 elems = doc.getElementsByTagName('object'); |
|
59 } |
|
60 elems[0].clientTop; |
|
61 executeSoon(func); |
|
62 }; |
|
63 } |
|
64 |
|
65 // Test that the activate action in content menus for CTP plugins works |
|
66 function test1() { |
|
67 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
68 ok(popupNotification, "Test 1, Should have a click-to-play notification"); |
|
69 |
|
70 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
71 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
72 ok(!objLoadingContent.activated, "Test 1, Plugin should not be activated"); |
|
73 |
|
74 // When the popupshown DOM event is fired, the actual showing of the popup |
|
75 // may still be pending. Clear the event loop before continuing so that |
|
76 // subsequently-opened popups aren't cancelled by accident. |
|
77 let goToNext = function() { |
|
78 window.document.removeEventListener("popupshown", goToNext, false); |
|
79 executeSoon(test2); |
|
80 }; |
|
81 window.document.addEventListener("popupshown", goToNext, false); |
|
82 EventUtils.synthesizeMouseAtCenter(plugin, |
|
83 { type: "contextmenu", button: 2 }, |
|
84 gTestBrowser.contentWindow); |
|
85 } |
|
86 |
|
87 function test2() { |
|
88 let activate = window.document.getElementById("context-ctp-play"); |
|
89 ok(activate, "Test 2, Should have a context menu entry for activating the plugin"); |
|
90 |
|
91 let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
92 ok(notification, "Test 2, Should have a click-to-play notification"); |
|
93 ok(notification.dismissed, "Test 2, notification should be dismissed"); |
|
94 |
|
95 // Trigger the click-to-play popup |
|
96 activate.doCommand(); |
|
97 |
|
98 waitForCondition(() => !notification.dismissed, |
|
99 test3, "Test 2, waited too long for context activation"); |
|
100 } |
|
101 |
|
102 function test3() { |
|
103 // Activate the plugin |
|
104 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
105 |
|
106 let plugin = gTestBrowser.contentDocument.getElementById("test"); |
|
107 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
108 waitForCondition(() => objLoadingContent.activated, test4, "Waited too long for plugin to activate"); |
|
109 } |
|
110 |
|
111 function test4() { |
|
112 finishTest(); |
|
113 } |