|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 var gTestBrowser = null; |
|
6 var gNumPluginBindingsAttached = 0; |
|
7 |
|
8 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
9 |
|
10 function test() { |
|
11 waitForExplicitFinish(); |
|
12 registerCleanupFunction(function() { |
|
13 Services.prefs.clearUserPref("plugins.click_to_play"); |
|
14 gTestBrowser.removeEventListener("PluginBindingAttached", pluginBindingAttached, true, true); |
|
15 gBrowser.removeCurrentTab(); |
|
16 window.focus(); |
|
17 }); |
|
18 |
|
19 Services.prefs.setBoolPref("plugins.click_to_play", true); |
|
20 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
|
21 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in"); |
|
22 |
|
23 gBrowser.selectedTab = gBrowser.addTab(); |
|
24 gTestBrowser = gBrowser.selectedBrowser; |
|
25 gTestBrowser.addEventListener("PluginBindingAttached", pluginBindingAttached, true, true); |
|
26 var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); |
|
27 gTestBrowser.contentWindow.location = gHttpTestRoot + "plugin_bug820497.html"; |
|
28 } |
|
29 |
|
30 function pluginBindingAttached() { |
|
31 gNumPluginBindingsAttached++; |
|
32 |
|
33 if (gNumPluginBindingsAttached == 1) { |
|
34 var doc = gTestBrowser.contentDocument; |
|
35 var testplugin = doc.getElementById("test"); |
|
36 ok(testplugin, "should have test plugin"); |
|
37 var secondtestplugin = doc.getElementById("secondtest"); |
|
38 ok(!secondtestplugin, "should not yet have second test plugin"); |
|
39 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
40 ok(notification, "should have popup notification"); |
|
41 // We don't set up the action list until the notification is shown |
|
42 notification.reshow(); |
|
43 is(notification.options.pluginData.size, 1, "should be 1 type of plugin in the popup notification"); |
|
44 XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addSecondPlugin(); |
|
45 } else if (gNumPluginBindingsAttached == 2) { |
|
46 var doc = gTestBrowser.contentDocument; |
|
47 var testplugin = doc.getElementById("test"); |
|
48 ok(testplugin, "should have test plugin"); |
|
49 var secondtestplugin = doc.getElementById("secondtest"); |
|
50 ok(secondtestplugin, "should have second test plugin"); |
|
51 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
52 ok(notification, "should have popup notification"); |
|
53 notification.reshow(); |
|
54 is(notification.options.pluginData.size, 2, "should be 2 types of plugin in the popup notification"); |
|
55 finish(); |
|
56 } else { |
|
57 ok(false, "if we've gotten here, something is quite wrong"); |
|
58 } |
|
59 } |