browser_privatebrowsing_pageinfo.js cleanup
authorDão Gottwald <dao@mozilla.com>
Tue, 03 Nov 2009 17:06:01 +0100
changeset 34494 6bca9886361431e584a1e8fba3ce3bdc313ac59c
parent 34493 bbbc9c83cdf762de7e970675f2209eeb5579314f
child 34495 0ce342530e0b0e7a4d1b948c0798b1b2b29a105c
push id10082
push userdgottwald@mozilla.com
push dateTue, 03 Nov 2009 16:06:24 +0000
treeherdermozilla-central@6bca98863614 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.3a1pre
browser_privatebrowsing_pageinfo.js cleanup
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_pageinfo.js
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_pageinfo.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_pageinfo.js
@@ -37,78 +37,57 @@
 
 // This test makes sure that the page info dialogs will close when entering or
 // exiting the private browsing mode.
 
 function test() {
   // initialization
   let pb = Cc["@mozilla.org/privatebrowsing;1"].
            getService(Ci.nsIPrivateBrowsingService);
-  let obs = Cc["@mozilla.org/observer-service;1"].
-            getService(Ci.nsIObserverService);
-  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
-           getService(Ci.nsIWindowWatcher);
 
   function runTest(aPBMode, aCallBack) {
-    const kTestURL1 = "data:text/html,Test Page 1";
     let tab1 = gBrowser.addTab();
     gBrowser.selectedTab = tab1;
     let browser1 = gBrowser.getBrowserForTab(tab1);
-    browser1.addEventListener("load", function() {
+    browser1.addEventListener("load", function () {
       browser1.removeEventListener("load", arguments.callee, true);
 
       let pageInfo1 = BrowserPageInfo();
-      obs.addObserver({
-        observe: function (aSubject, aTopic, aData) {
-          obs.removeObserver(this, "page-info-dialog-loaded");
+      pageInfo1.addEventListener("load", function () {
 
-          const kTestURL2 = "data:text/plain,Test Page 2";
-          let tab2 = gBrowser.addTab();
-          gBrowser.selectedTab = tab2;
-          let browser2 = gBrowser.getBrowserForTab(tab2);
-          browser2.addEventListener("load", function () {
-            browser2.removeEventListener("load", arguments.callee, true);
+        let tab2 = gBrowser.addTab();
+        gBrowser.selectedTab = tab2;
+        let browser2 = gBrowser.getBrowserForTab(tab2);
+        browser2.addEventListener("load", function () {
+          browser2.removeEventListener("load", arguments.callee, true);
 
-            let pageInfo2 = BrowserPageInfo();
-            obs.addObserver({
-              observe: function (aSubject, aTopic, aData) {
-                obs.removeObserver(this, "page-info-dialog-loaded");
+          let pageInfo2 = BrowserPageInfo();
+          pageInfo2.addEventListener("load", function () {
 
-                ww.registerNotification({
-                  observe: function (aSubject, aTopic, aData) {
-                    is(aTopic, "domwindowclosed", "We should only receive window closed notifications");
-                    let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
-                    if (win == pageInfo1) {
-                      ok(true, "Page info 1 being closed as expected");
-                      pageInfo1 = null;
-                    }
-                    else if (win == pageInfo2) {
-                      ok(true, "Page info 2 being closed as expected");
-                      pageInfo2 = null;
-                    }
-                    else
-                      ok(false, "The closed window should be one of the two page info windows");
+            pageInfo1.addEventListener("unload", function () {
+              pageInfo1 = null;
+              ok(true, "Page info 1 being closed as expected");
+              if (!pageInfo2)
+                aCallBack();
+            }, false);
 
-                    if (!pageInfo1 && !pageInfo2) {
-                      ww.unregisterNotification(this);
-
-                      aCallBack();
-                    }
-                  }
-                });
+            pageInfo2.addEventListener("unload", function () {
+              pageInfo2 = null;
+              ok(true, "Page info 2 being closed as expected");
+              if (!pageInfo1)
+                aCallBack();
+            }, false);
 
-                pb.privateBrowsingEnabled = aPBMode;
-              }
-            }, "page-info-dialog-loaded", false);
-          }, true);
-          browser2.loadURI(kTestURL2);
-        }
-      }, "page-info-dialog-loaded", false);
+            pb.privateBrowsingEnabled = aPBMode;
+          }, false);
+        }, true);
+        browser2.loadURI("data:text/plain,Test Page 2");
+      }, false);
     }, true);
-    browser1.loadURI(kTestURL1);
+    browser1.loadURI("data:text/html,Test Page 1");
   }
 
   runTest(true, function() {
     runTest(false, function() {
       gBrowser.removeCurrentTab();
       gBrowser.removeCurrentTab();
 
       finish();