Bug 677423 - Add togglePrivateBrowsing() to head.js; r=dao
authorTim Taubert <tim.taubert@gmx.de>
Tue, 09 Aug 2011 19:13:53 +0200
changeset 75218 3a90c075243624a98d33e20b4ffc7e87c6c001e4
parent 75170 8f9746b88447b8990ef45da38791ba5369cec945
child 75219 7840c41b49432f4f454247f634edbb403ba73ffd
push idunknown
push userunknown
push dateunknown
reviewersdao
bugs677423
milestone8.0a1
Bug 677423 - Add togglePrivateBrowsing() to head.js; r=dao
browser/base/content/test/tabview/browser_tabview_bug624265.js
browser/base/content/test/tabview/browser_tabview_bug624727.js
browser/base/content/test/tabview/browser_tabview_privatebrowsing.js
browser/base/content/test/tabview/head.js
--- a/browser/base/content/test/tabview/browser_tabview_bug624265.js
+++ b/browser/base/content/test/tabview/browser_tabview_bug624265.js
@@ -148,24 +148,8 @@ function loadTabView(callback) {
 }
 
 // ----------
 function enterAndLeavePrivateBrowsing(callback) {
   togglePrivateBrowsing(function () {
     togglePrivateBrowsing(callback);
   });
 }
-
-// ----------
-function togglePrivateBrowsing(callback) {
-  let topic = "private-browsing-transition-complete";
-
-  function pbObserver(aSubject, aTopic, aData) {
-    if (aTopic != topic)
-      return;
-
-    Services.obs.removeObserver(pbObserver, topic, false);
-    afterAllTabsLoaded(callback);
-  }
-
-  Services.obs.addObserver(pbObserver, topic, false);
-  pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
-}
--- a/browser/base/content/test/tabview/browser_tabview_bug624727.js
+++ b/browser/base/content/test/tabview/browser_tabview_bug624727.js
@@ -58,18 +58,17 @@ function test() {
     assertOneTabInGroup(prefix, group1);
     assertOneTabInGroup(prefix, group2);
   }
 
   let testStateAfterEnteringPB = function () {
     let prefix = 'enter';
     ok(!pb.privateBrowsingEnabled, prefix + ': private browsing is disabled');
     registerCleanupFunction(function () {
-      if (pb.privateBrowsingEnabled)
-        pb.privateBrowsingEnabled = false
+      pb.privateBrowsingEnabled = false;
     });
 
     togglePrivateBrowsing(function () {
       assertTabViewIsHidden(prefix);
 
       showTabView(function () {
         assertNumberOfGroups(prefix, 1);
         assertNumberOfTabs(prefix, 1);
@@ -124,24 +123,8 @@ function test() {
       gBrowser.pinTab(tabItem1.tab);
       gBrowser.pinTab(tabItem2.tab);
 
       assertValidSetup('setup');
       hideTabView(testStateAfterEnteringPB);
     });
   });
 }
-
-// ----------
-function togglePrivateBrowsing(callback) {
-  let topic = 'private-browsing-transition-complete';
-
-  function pbObserver(aSubject, aTopic, aData) {
-    if (aTopic != topic)
-      return;
-
-    Services.obs.removeObserver(pbObserver, topic);
-    afterAllTabsLoaded(callback);
-  }
-
-  Services.obs.addObserver(pbObserver, topic, false);
-  pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
-}
--- a/browser/base/content/test/tabview/browser_tabview_privatebrowsing.js
+++ b/browser/base/content/test/tabview/browser_tabview_privatebrowsing.js
@@ -60,23 +60,23 @@ function onTabViewLoadedAndShown() {
     // Get normal tab urls
     for (let a = 0; a < gBrowser.tabs.length; a++)
       normalURLs.push(gBrowser.tabs[a].linkedBrowser.currentURI.spec);
 
     // verify that we're all set up for our test
     verifyNormal();
 
     // go into private browsing and make sure Tab View becomes hidden
-    togglePBAndThen(function() {
+    togglePrivateBrowsing(function() {
       whenTabViewIsHidden(function() {
         ok(!TabView.isVisible(), "Tab View is no longer visible");
         verifyPB();
 
         // exit private browsing and make sure Tab View is shown again
-        togglePBAndThen(function() {
+        togglePrivateBrowsing(function() {
           whenTabViewIsShown(function() {
             ok(TabView.isVisible(), "Tab View is visible again");
             verifyNormal();
 
             hideTabView(onTabViewHidden);
           });
         });
       });
@@ -84,22 +84,22 @@ function onTabViewLoadedAndShown() {
   });
 }
 
 // -----------
 function onTabViewHidden() {
   ok(!TabView.isVisible(), "Tab View is not visible");
   
   // go into private browsing and make sure Tab View remains hidden
-  togglePBAndThen(function() {
+  togglePrivateBrowsing(function() {
     ok(!TabView.isVisible(), "Tab View is still not visible");
     verifyPB();
     
     // turn private browsing back off
-    togglePBAndThen(function() {
+    togglePrivateBrowsing(function() {
       verifyNormal();
       
       // end game
       ok(!TabView.isVisible(), "we finish with Tab View not visible");
       registerCleanupFunction(verifyCleanState); // verify after all cleanups
 
       gBrowser.selectedTab = gBrowser.tabs[0];
       finish();
@@ -148,22 +148,8 @@ function verifyNormal() {
 
     let groupItem = contentWindow.GroupItems.groupItems[a];
     is(groupItem.getTitle(), groupTitles[a], prefix + "correct group title");
     
     ok(tab._tabViewTabItem.parent == groupItem,
         prefix + "tab " + a + " is in group " + a);
   }
 }
-
-// ----------
-function togglePBAndThen(callback) {
-  function pbObserver(aSubject, aTopic, aData) {
-    if (aTopic != "private-browsing-transition-complete")
-      return;
-
-    Services.obs.removeObserver(pbObserver, "private-browsing-transition-complete");
-    afterAllTabsLoaded(callback);
-  }
-
-  Services.obs.addObserver(pbObserver, "private-browsing-transition-complete", false);
-  pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
-}
--- a/browser/base/content/test/tabview/head.js
+++ b/browser/base/content/test/tabview/head.js
@@ -347,8 +347,23 @@ function restoreTab(callback, index, win
     return;
   }
 
   tab._tabViewTabItem.addSubscriber("reconnected", function onReconnected() {
     tab._tabViewTabItem.removeSubscriber("reconnected", onReconnected);
     finalize();
   });
 }
+
+// ----------
+function togglePrivateBrowsing(callback) {
+  let topic = "private-browsing-transition-complete";
+
+  Services.obs.addObserver(function observe() {
+    Services.obs.removeObserver(observe, topic);
+    afterAllTabsLoaded(callback);
+  }, topic, false);
+
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+
+  pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
+}