Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 var rootDir = getRootDirectory(gTestPath);
2 const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/");
4 let gTestBrowser = null;
5 let gNextTest = null;
6 let gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
8 Components.utils.import("resource://gre/modules/Services.jsm");
10 // Let's do the XPCNativeWrapper dance!
11 function addPlugin(browser, type) {
12 let contentWindow = XPCNativeWrapper.unwrap(browser.contentWindow);
13 contentWindow.addPlugin(type);
14 }
16 function test() {
17 waitForExplicitFinish();
18 registerCleanupFunction(function() {
19 clearAllPluginPermissions();
20 Services.prefs.clearUserPref("plugins.click_to_play");
21 });
22 Services.prefs.setBoolPref("plugins.click_to_play", true);
23 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
24 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in");
26 let newTab = gBrowser.addTab();
27 gBrowser.selectedTab = newTab;
28 gTestBrowser = gBrowser.selectedBrowser;
29 gTestBrowser.addEventListener("load", pageLoad, true);
30 prepareTest(testActivateAddSameTypePart1, gTestRoot + "plugin_add_dynamically.html");
31 }
33 function finishTest() {
34 gTestBrowser.removeEventListener("load", pageLoad, true);
35 gBrowser.removeCurrentTab();
36 window.focus();
37 finish();
38 }
40 function pageLoad() {
41 // The plugin events are async dispatched and can come after the load event
42 // This just allows the events to fire before we then go on to test the states
43 executeSoon(gNextTest);
44 }
46 function prepareTest(nextTest, url) {
47 gNextTest = nextTest;
48 gTestBrowser.contentWindow.location = url;
49 }
51 // "Activate" of a given type -> plugins of that type dynamically added should
52 // automatically play.
53 function testActivateAddSameTypePart1() {
54 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
55 ok(!popupNotification, "testActivateAddSameTypePart1: should not have a click-to-play notification");
56 addPlugin(gTestBrowser);
57 let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
58 waitForCondition(condition, testActivateAddSameTypePart2, "testActivateAddSameTypePart1: waited too long for click-to-play-plugin notification");
59 }
61 function testActivateAddSameTypePart2() {
62 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
63 ok(popupNotification, "testActivateAddSameTypePart2: should have a click-to-play notification");
65 popupNotification.reshow();
66 testActivateAddSameTypePart3();
67 }
69 function testActivateAddSameTypePart3() {
70 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
71 let centerAction = null;
72 for (let action of popupNotification.options.pluginData.values()) {
73 if (action.pluginName == "Test") {
74 centerAction = action;
75 break;
76 }
77 }
78 ok(centerAction, "testActivateAddSameTypePart3: found center action for the Test plugin");
80 let centerItem = null;
81 for (let item of PopupNotifications.panel.firstChild.childNodes) {
82 if (item.action && item.action == centerAction) {
83 centerItem = item;
84 break;
85 }
86 }
87 ok(centerItem, "testActivateAddSameTypePart3: found center item for the Test plugin");
89 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
90 ok(!plugin.activated, "testActivateAddSameTypePart3: plugin should not be activated");
92 // Change the state and click the ok button to activate the Test plugin
93 centerItem.value = "allownow";
94 PopupNotifications.panel.firstChild._primaryButton.click();
96 let condition = function() plugin.activated;
97 waitForCondition(condition, testActivateAddSameTypePart4, "testActivateAddSameTypePart3: waited too long for plugin to activate");
98 }
100 function testActivateAddSameTypePart4() {
101 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
102 ok(plugin.activated, "testActivateAddSameTypePart4: plugin should be activated");
104 addPlugin(gTestBrowser);
105 let condition = function() {
106 let embeds = gTestBrowser.contentDocument.getElementsByTagName("embed");
107 let allActivated = true;
108 for (let embed of embeds) {
109 if (!embed.activated)
110 allActivated = false;
111 }
112 return allActivated && embeds.length == 2;
113 };
114 waitForCondition(condition, testActivateAddSameTypePart5, "testActivateAddSameTypePart4: waited too long for second plugin to activate"); }
116 function testActivateAddSameTypePart5() {
117 let embeds = gTestBrowser.contentDocument.getElementsByTagName("embed");
118 for (let embed of embeds) {
119 ok(embed.activated, "testActivateAddSameTypePart5: all plugins should be activated");
120 }
121 clearAllPluginPermissions();
122 prepareTest(testActivateAddDifferentTypePart1, gTestRoot + "plugin_add_dynamically.html");
123 }
125 // "Activate" of a given type -> plugins of other types dynamically added
126 // should not automatically play.
127 function testActivateAddDifferentTypePart1() {
128 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
129 ok(!popupNotification, "testActivateAddDifferentTypePart1: should not have a click-to-play notification");
130 addPlugin(gTestBrowser);
131 let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
132 waitForCondition(condition, testActivateAddDifferentTypePart2, "testActivateAddDifferentTypePart1: waited too long for click-to-play-plugin notification");
133 }
135 function testActivateAddDifferentTypePart2() {
136 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
137 ok(popupNotification, "testActivateAddDifferentTypePart2: should have a click-to-play notification");
139 // we have to actually show the panel to get the bindings to instantiate
140 popupNotification.reshow();
141 testActivateAddDifferentTypePart3();
142 }
144 function testActivateAddDifferentTypePart3() {
145 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
146 is(popupNotification.options.pluginData.size, 1, "Should be one plugin action");
148 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
149 ok(!plugin.activated, "testActivateAddDifferentTypePart3: plugin should not be activated");
151 // "click" the button to activate the Test plugin
152 PopupNotifications.panel.firstChild._primaryButton.click();
154 let condition = function() plugin.activated;
155 waitForCondition(condition, testActivateAddDifferentTypePart4, "testActivateAddDifferentTypePart3: waited too long for plugin to activate");
156 }
158 function testActivateAddDifferentTypePart4() {
159 let plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
160 ok(plugin.activated, "testActivateAddDifferentTypePart4: plugin should be activated");
162 addPlugin(gTestBrowser);
163 let condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
164 waitForCondition(condition, testActivateAddDifferentTypePart5, "testActivateAddDifferentTypePart5: waited too long for popup notification");
165 }
167 function testActivateAddDifferentTypePart5() {
168 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "testActivateAddDifferentTypePart5: should have popup notification");
169 let embeds = gTestBrowser.contentDocument.getElementsByTagName("embed");
170 for (let embed of embeds) {
171 if (embed.type == "application/x-test")
172 ok(embed.activated, "testActivateAddDifferentTypePart5: Test plugin should be activated");
173 else if (embed.type == "application/x-second-test")
174 ok(!embed.activated, "testActivateAddDifferentTypePart5: Second Test plugin should not be activated");
175 }
177 finishTest();
178 }