Fix browser_pluginnotification.js
authorBlair McBride <bmcbride@mozilla.com>
Tue, 20 Apr 2010 17:00:49 +1200
changeset 41223 ab92e7f5f657d760e105fc3ca477510c4877c6e8
parent 41222 1319aa17d576d50735b65785fbccbd1547258d24
child 41225 ff12ff29356945a4d0e0664754f165731b2c6f40
push id119
push userbmcbride@mozilla.com
push dateTue, 20 Apr 2010 05:03:21 +0000
milestone1.9.3a5pre
Fix browser_pluginnotification.js
browser/base/content/test/browser_pluginnotification.js
--- a/browser/base/content/test/browser_pluginnotification.js
+++ b/browser/base/content/test/browser_pluginnotification.js
@@ -1,76 +1,67 @@
 const gTestRoot = "chrome://mochikit/content/browser/browser/base/content/test/";
 
 var gTestBrowser = null;
 var gNextTest = null;
 
 function get_test_plugin() {
   var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
   var tags = ph.getPluginTags();
-  
+
   // Find the test plugin
   for (var i = 0; i < tags.length; i++) {
     if (tags[i].name == "Test Plug-in")
       return tags[i];
   }
 }
 
-// This listens for the next opened window and checks it is of the right url.
-// opencallback is called when the new window is fully loaded
-// closecallback is called when the window is closed
-function WindowOpenListener(url, opencallback, closecallback) {
+// This listens for the next opened tab and checks it is of the right url.
+// opencallback is called when the new tab is fully loaded
+// closecallback is called when the tab is closed
+function TabOpenListener(url, opencallback, closecallback) {
   this.url = url;
   this.opencallback = opencallback;
   this.closecallback = closecallback;
 
-  Services.wm.addListener(this);
+  gBrowser.tabContainer.addEventListener("TabOpen", this, false);
 }
 
-WindowOpenListener.prototype = {
+TabOpenListener.prototype = {
   url: null,
   opencallback: null,
   closecallback: null,
-  window: null,
-  domwindow: null,
+  tab: null,
+  browser: null,
 
   handleEvent: function(event) {
-    is(this.domwindow.document.location.href, this.url, "Should have opened the correct window");
-
-    this.domwindow.removeEventListener("load", this, false);
-    // Allow any other load handlers to execute
-    var self = this;
-    executeSoon(function() { self.opencallback(self.domwindow); } );
-  },
-
-  onWindowTitleChange: function(window, title) {
-  },
-
-  onOpenWindow: function(window) {
-    if (this.window)
-      return;
-
-    this.window = window;
-    this.domwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                           .getInterface(Components.interfaces.nsIDOMWindowInternal);
-    this.domwindow.addEventListener("load", this, false);
-  },
-
-  onCloseWindow: function(window) {
-    if (this.window != window)
-      return;
-
-    Services.wm.removeListener(this);
-    this.opencallback = null;
-    this.window = null;
-    this.domwindow = null;
-
-    // Let the window close complete
-    executeSoon(this.closecallback);
-    this.closecallback = null;
+    if (event.type == "TabOpen") {
+      gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
+      this.tab = event.originalTarget;
+      this.browser = this.tab.linkedBrowser;
+      gBrowser.addEventListener("load", this, true);
+    } else if (event.type == "load") {
+      gBrowser.removeEventListener("load", this, true);
+      this.tab.addEventListener("TabClose", this, false);
+      var url = this.browser.contentDocument.location.href;
+      is(url, this.url, "Should have opened the correct tab");
+      // Allow any other load handlers to execute
+      var self = this;
+      executeSoon(function() { self.opencallback(self.tab, self.browser.contentWindow); } );
+    } else if (event.type == "TabClose") {
+      if (event.originalTarget != this.tab)
+        return;
+      this.tab.removeEventListener("TabClose", this, false);
+      this.opencallback = null;
+      this.tab = null;
+      this.browser = null;
+      // Let the window close complete
+      executeSoon(this.closecallback);
+      this.closecallback = null;
+    }
   }
 };
 
 function test() {
   waitForExplicitFinish();
 
   var newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
@@ -128,25 +119,25 @@ function test2() {
 
 // Tests a page with a disabled plugin in it.
 function test3() {
   var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
   ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 3, Should not have displayed the missing plugin notification");
   ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 3, Should not have displayed the blocked plugin notification");
   ok(!gTestBrowser.missingPlugins, "Test 3, Should not be a missing plugin list");
 
-  new WindowOpenListener("chrome://mozapps/content/extensions/extensions.xul", test4, prepareTest5);
+  new TabOpenListener("about:addons", test4, prepareTest5);
 
   EventUtils.synthesizeMouse(gTestBrowser.contentDocument.getElementById("test"),
                              0, 0, {}, gTestBrowser.contentWindow);
 }
 
-function test4(win) {
-  is(win.gView, "plugins", "Should have displayed the plugins pane");
-  win.close();
+function test4(tab, win) {
+  todo_is(win.gView, "plugins", "Should have displayed the plugins pane");
+  gBrowser.removeTab(tab);
 }
 
 function prepareTest5() {
   var plugin = get_test_plugin();
   plugin.disabled = false;
   plugin.blocklisted = true;
   prepareTest(test5, gTestRoot + "plugin_test.html");
 }