1 const gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
2 const EXPECTED_PLUGINSCRIPTED_EVENT_COUNT = 7;
4 var gTestBrowser = null;
5 var gNextTestList = [];
7 var gPluginScriptedFired = false;
8 var gPluginScriptedFiredCount = 0;
10 Components.utils.import("resource://gre/modules/Services.jsm");
13 waitForExplicitFinish();
14 registerCleanupFunction(function() {
15 Services.prefs.clearUserPref("plugins.click_to_play");
16 gTestBrowser.removeEventListener("load", pageLoad, true);
17 gTestBrowser.removeEventListener("PluginScripted", pluginScripted, true);
19 Services.prefs.setBoolPref("plugins.click_to_play", true);
21 gBrowser.selectedTab = gBrowser.addTab();
22 gTestBrowser = gBrowser.selectedBrowser;
23 gTestBrowser.addEventListener("load", pageLoad, true);
24 gTestBrowser.addEventListener("PluginScripted", pluginScripted, true);
26 // This list is iterated in reverse order, since it uses Array.pop to get the next test.
28 // Doesn't show a popup since not the first instance of a small plugin
29 { func: testExpectNoPopupPart1,
30 url: gHttpTestRoot + "plugin_test_scriptedPopup1.html" },
31 // Doesn't show a popup since not the first instance of a small plugin
32 { func: testExpectNoPopupPart1,
33 url: gHttpTestRoot + "plugin_test_scriptedPopup2.html" },
34 // Shows a popup since it is the first instance of a small plugin
35 { func: testExpectPopupPart1,
36 url: gHttpTestRoot + "plugin_test_scriptedPopup3.html" },
37 { func: testExpectNoPopupPart1,
38 url: gHttpTestRoot + "plugin_test_scriptedNoPopup1.html" },
39 { func: testExpectNoPopupPart1,
40 url: gHttpTestRoot + "plugin_test_scriptedNoPopup2.html" },
41 { func: testExpectNoPopupPart1,
42 url: gHttpTestRoot + "plugin_test_scriptedNoPopup3.html" }
45 prepareTest(testNoEventFired, gHttpTestRoot + "plugin_test_noScriptNoPopup.html");
48 function getCurrentTestLocation() {
49 var loc = gTestBrowser.contentWindow.location.toString();
50 return loc.replace(gHttpTestRoot, "");
53 function runNextTest() {
54 var nextTest = gNextTestList.pop();
56 gPluginScriptedFired = false;
57 prepareTest(nextTest.func, nextTest.url);
64 function finishTest() {
65 is(gPluginScriptedFiredCount, EXPECTED_PLUGINSCRIPTED_EVENT_COUNT, "PluginScripted event count is correct");
66 gBrowser.removeCurrentTab();
71 function pluginScripted() {
72 gPluginScriptedFired = true;
73 gPluginScriptedFiredCount++;
77 // The plugin events are async dispatched and can come after the load event
78 // This just allows the events to fire before we then go on to test the states
79 executeSoon(gNextTest);
82 function prepareTest(nextTest, url) {
84 gTestBrowser.contentWindow.location = url;
87 function testNoEventFired() {
88 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
89 ok(notification, "should have a click-to-play notification (" + getCurrentTestLocation() + ")");
90 ok(notification.dismissed, "notification should not be showing (" + getCurrentTestLocation() + ")");
91 ok(!gPluginScriptedFired, "PluginScripted should not have fired (" + getCurrentTestLocation() + ")");
93 prepareTest(testDenyPermissionPart1, gHttpTestRoot + "plugin_test_noScriptNoPopup.html");
96 function testDenyPermissionPart1() {
97 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
98 ok(notification, "test deny permission: should have a click-to-play notification");
99 // Simulate clicking the "Deny Always" button.
100 notification.secondaryActions[1].callback();
101 gPluginScriptedFired = false;
102 prepareTest(testDenyPermissionPart2, gHttpTestRoot + "plugin_test_scriptedPopup1.html");
105 function testDenyPermissionPart2() {
106 var condition = function() gPluginScriptedFired;
107 waitForCondition(condition, testDenyPermissionPart3, "test deny permission: waited too long for PluginScripted event");
110 function testDenyPermissionPart3() {
111 var condition = function() gTestBrowser._pluginScriptedState == gPluginHandler.PLUGIN_SCRIPTED_STATE_DONE;
112 waitForCondition(condition, testDenyPermissionPart4, "test deny permission: waited too long for PluginScripted event handling");
115 function testDenyPermissionPart4() {
116 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
117 ok(!notification, "test deny permission: should not have a click-to-play notification");
119 var pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
120 Services.perms.remove("127.0.0.1:8888", pluginHost.getPermissionStringForType("application/x-test"));
125 function testExpectNoPopupPart1() {
126 var condition = function() gPluginScriptedFired;
127 waitForCondition(condition, testExpectNoPopupPart2, "waited too long for PluginScripted event (" + getCurrentTestLocation() + ")");
130 function testExpectNoPopupPart2() {
131 var condition = function() gTestBrowser._pluginScriptedState == gPluginHandler.PLUGIN_SCRIPTED_STATE_DONE;
132 waitForCondition(condition, testExpectNoPopupPart3, "waited too long for PluginScripted event handling (" + getCurrentTestLocation() + ")");
135 function testExpectNoPopupPart3() {
136 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
137 ok(notification, "should have a click-to-play notification (" + getCurrentTestLocation() + ")");
138 ok(notification.dismissed, "notification should not be showing (" + getCurrentTestLocation() + ")");
143 function testExpectPopupPart1() {
144 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
145 ok(notification, "should have a click-to-play notification (" + getCurrentTestLocation() + ")");
147 var condition = function() !notification.dismissed;
148 waitForCondition(condition, testExpectPopupPart2, "waited too long for popup notification to show (" + getCurrentTestLocation() + ")");
151 function testExpectPopupPart2() {
152 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
153 ok(!notification.dismissed, "notification should be showing (" + getCurrentTestLocation() + ")");