Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 var rootDir = getRootDirectory(gTestPath);
2 const gTestRoot = rootDir;
3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
5 var gTestBrowser = null;
6 var gNextTest = null;
8 Components.utils.import("resource://gre/modules/Services.jsm");
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);
18 var newTab = gBrowser.addTab();
19 gBrowser.selectedTab = newTab;
20 gTestBrowser = gBrowser.selectedBrowser;
21 gTestBrowser.addEventListener("load", pageLoad, true);
23 Services.prefs.setBoolPref("plugins.click_to_play", true);
24 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
26 prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_small.html");
27 }
29 function finishTest() {
30 gTestBrowser.removeEventListener("load", pageLoad, true);
31 gBrowser.removeCurrentTab();
32 window.focus();
33 finish();
34 }
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 }
42 function prepareTest(nextTest, url) {
43 gNextTest = nextTest;
44 gTestBrowser.contentWindow.location = url;
45 }
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 }
63 // Tests for the notification bar for hidden plugins.
65 function test1() {
66 let notification = PopupNotifications.getNotification("click-to-play-plugins");
67 ok(notification, "Test 1: There should be a plugin notification");
69 let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
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 }
81 function test2() {
82 let notification = PopupNotifications.getNotification("click-to-play-plugins");
83 ok(notification, "Test 2: There should be a plugin notification");
85 let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
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 }
95 function test3() {
96 let notification = PopupNotifications.getNotification("click-to-play-plugins");
97 ok(notification, "Test 3: There should be a plugin notification");
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 }
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");
117 prepareTest(test4, gTestRoot + "plugin_positioned.html");
118 }
120 function test4() {
121 let notification = PopupNotifications.getNotification("click-to-play-plugins");
122 ok(notification, "Test 4: There should be a plugin notification");
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 }
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");
141 prepareTest(runAfterPluginBindingAttached(test5), gHttpTestRoot + "plugin_small.html");
142 }
144 // Test that the notification bar is getting dismissed when directly activating plugins
145 // via the doorhanger.
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 }
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");
163 // simulate "always allow"
164 notification.reshow();
165 PopupNotifications.panel.firstChild._primaryButton.click();
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 }
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 }