browser_pluginnotification.js
Go to the documentation of this file.
1 const gTestRoot = "chrome://mochikit/content/browser/browser/base/content/test/";
2 
4 var gNextTest = null;
5 
6 function get_test_plugin() {
7  var ph = Components.classes["@mozilla.org/plugin/host;1"]
8  .getService(Components.interfaces.nsIPluginHost);
9  var tags = ph.getPluginTags({});
10 
11  // Find the test plugin
12  for (var i = 0; i < tags.length; i++) {
13  if (tags[i].name == "Test Plug-in")
14  return tags[i];
15  }
16 }
17 
18 // This listens for the next opened window and checks it is of the right url.
19 // opencallback is called when the new window is fully loaded
20 // closecallback is called when the window is closed
21 function WindowOpenListener(url, opencallback, closecallback) {
22  this.url = url;
23  this.opencallback = opencallback;
24  this.closecallback = closecallback;
25 
26  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
27  .getService(Components.interfaces.nsIWindowMediator);
28  wm.addListener(this);
29 }
30 
31 WindowOpenListener.prototype = {
32  url: null,
33  opencallback: null,
34  closecallback: null,
35  window: null,
36  domwindow: null,
37 
38  handleEvent: function(event) {
39  is(this.domwindow.document.location.href, this.url, "Should have opened the correct window");
40 
41  this.domwindow.removeEventListener("load", this, false);
42  // Allow any other load handlers to execute
43  var self = this;
44  executeSoon(function() { self.opencallback(self.domwindow); } );
45  },
46 
47  onWindowTitleChange: function(window, title) {
48  },
49 
50  onOpenWindow: function(window) {
51  if (this.window)
52  return;
53 
54  this.window = window;
55  this.domwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
56  .getInterface(Components.interfaces.nsIDOMWindowInternal);
57  this.domwindow.addEventListener("load", this, false);
58  },
59 
60  onCloseWindow: function(window) {
61  if (this.window != window)
62  return;
63 
64  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
65  .getService(Components.interfaces.nsIWindowMediator);
66  wm.removeListener(this);
67  this.opencallback = null;
68  this.window = null;
69  this.domwindow = null;
70 
71  // Let the window close complete
72  executeSoon(this.closecallback);
73  this.closecallback = null;
74  }
75 };
76 
77 function test() {
79 
80  var newTab = gBrowser.addTab();
81  gBrowser.selectedTab = newTab;
82  gTestBrowser = gBrowser.selectedBrowser;
83  gTestBrowser.addEventListener("load", pageLoad, true);
84  prepareTest(test1, gTestRoot + "plugin_unknown.html");
85 }
86 
87 function finishTest() {
88  gTestBrowser.removeEventListener("load", pageLoad, true);
89  gBrowser.removeCurrentTab();
90  window.focus();
91  finish();
92 }
93 
94 function pageLoad() {
95  // The plugin events are async dispatched and can come after the load event
96  // This just allows the events to fire before we then go on to test the states
97  executeSoon(gNextTest);
98 }
99 
102  gTestBrowser.contentWindow.location = url;
103 }
104 
105 // Tests a page with an unknown plugin in it.
106 function test1() {
107  var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
108  ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 1, Should have displayed the missing plugin notification");
109  ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 1, Should not have displayed the blocked plugin notification");
110  ok(gTestBrowser.missingPlugins, "Test 1, Should be a missing plugin list");
111  ok("application/x-unknown" in gTestBrowser.missingPlugins, "Test 1, Should know about application/x-unknown");
112  ok(!("application/x-test" in gTestBrowser.missingPlugins), "Test 1, Should not know about application/x-test");
113 
114  var plugin = get_test_plugin();
115  ok(plugin, "Should have a test plugin");
116  plugin.disabled = false;
117  plugin.blocklisted = false;
118  prepareTest(test2, gTestRoot + "plugin_test.html");
119 }
120 
121 // Tests a page with a working plugin in it.
122 function test2() {
123  var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
124  ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 2, Should not have displayed the missing plugin notification");
125  ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 2, Should not have displayed the blocked plugin notification");
126  ok(!gTestBrowser.missingPlugins, "Test 2, Should not be a missing plugin list");
127 
128  var plugin = get_test_plugin();
129  ok(plugin, "Should have a test plugin");
130  plugin.disabled = true;
131  prepareTest(test3, gTestRoot + "plugin_test.html");
132 }
133 
134 // Tests a page with a disabled plugin in it.
135 function test3() {
136  var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
137  ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 3, Should not have displayed the missing plugin notification");
138  ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 3, Should not have displayed the blocked plugin notification");
139  ok(!gTestBrowser.missingPlugins, "Test 3, Should not be a missing plugin list");
140 
141  new WindowOpenListener("chrome://mozapps/content/extensions/extensions.xul", test4, prepareTest5);
142 
143  EventUtils.synthesizeMouse(gTestBrowser.contentDocument.getElementById("test"),
144  0, 0, {}, gTestBrowser.contentWindow);
145 }
146 
147 function test4(win) {
148  is(win.gView, "plugins", "Should have displayed the plugins pane");
149  win.close();
150 }
151 
152 function prepareTest5() {
153  var plugin = get_test_plugin();
154  plugin.disabled = false;
155  plugin.blocklisted = true;
156  prepareTest(test5, gTestRoot + "plugin_test.html");
157 }
158 
159 // Tests a page with a blocked plugin in it.
160 function test5() {
161  var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
162  ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 5, Should not have displayed the missing plugin notification");
163  ok(notificationBox.getNotificationWithValue("blocked-plugins"), "Test 5, Should have displayed the blocked plugin notification");
164  ok(gTestBrowser.missingPlugins, "Test 5, Should be a missing plugin list");
165  ok("application/x-test" in gTestBrowser.missingPlugins, "Test 5, Should know about application/x-test");
166  ok(!("application/x-unknown" in gTestBrowser.missingPlugins), "Test 5, Should not know about application/x-unknown");
167 
168  prepareTest(test6, gTestRoot + "plugin_both.html");
169 }
170 
171 // Tests a page with a blocked and unknown plugin in it.
172 function test6() {
173  var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
174  ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 6, Should have displayed the missing plugin notification");
175  ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 6, Should not have displayed the blocked plugin notification");
176  ok(gTestBrowser.missingPlugins, "Test 6, Should be a missing plugin list");
177  ok("application/x-unknown" in gTestBrowser.missingPlugins, "Test 6, Should know about application/x-unknown");
178  ok("application/x-test" in gTestBrowser.missingPlugins, "Test 6, Should know about application/x-test");
179 
180  prepareTest(test7, gTestRoot + "plugin_both2.html");
181 }
182 
183 // Tests a page with a blocked and unknown plugin in it (alternate order to above).
184 function test7() {
185  var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
186  ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 7, Should have displayed the missing plugin notification");
187  ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 7, Should not have displayed the blocked plugin notification");
188  ok(gTestBrowser.missingPlugins, "Test 7, Should be a missing plugin list");
189  ok("application/x-unknown" in gTestBrowser.missingPlugins, "Test 7, Should know about application/x-unknown");
190  ok("application/x-test" in gTestBrowser.missingPlugins, "Test 7, Should know about application/x-test");
191 
192  var plugin = get_test_plugin();
193  plugin.disabled = false;
194  plugin.blocklisted = false;
195  finishTest();
196 }
function finishTest()
function get_test_plugin()
function test4(win)
function prepareTest5()
function pageLoad()
function test2()
var event
function prepareTest(nextTest, url)
function test1()
let window
const gTestRoot
function test6()
function test3()
function test5()
waitForExplicitFinish()
function test()
function test7()
function WindowOpenListener(url, opencallback, closecallback)
return null
Definition: FeedWriter.js:1143
function url(spec)
_getSelectedPageStyle s i