Bug 823739 - Port browser_favicon_privatebrowsing.js to the new per-window PB APIs. r=jdm
authorAndres Hernandez <andres@appcoast.com>
Fri, 28 Dec 2012 13:10:33 -0600
changeset 126324 dd6590eb7e4ff1f63d0489688a4fe0cea1932651
parent 126323 0b34087f3e7d55ee2cfe2968703357a70a2f8656
child 126325 a6ae2af96c8bf1ede4b05743d2cc91a8840df1bd
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs823739
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 823739 - Port browser_favicon_privatebrowsing.js to the new per-window PB APIs. r=jdm
toolkit/components/places/tests/browser/Makefile.in
toolkit/components/places/tests/browser/browser_favicon_privatebrowsing_perwindowpb.js
--- a/toolkit/components/places/tests/browser/Makefile.in
+++ b/toolkit/components/places/tests/browser/Makefile.in
@@ -29,16 +29,17 @@ MOCHITEST_BROWSER_FILES = \
 	$(NULL)
 
 ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
 MOCHITEST_BROWSER_FILES += \
 	browser_bug248970.js \
 	browser_favicon_setAndFetchFaviconForPage.js \
 	browser_favicon_setAndFetchFaviconForPage_failures.js \
 	browser_visituri_privatebrowsing_perwindowpb.js \
+	browser_favicon_privatebrowsing_perwindowpb.js \
 	$(NULL)
 else
 MOCHITEST_BROWSER_FILES += \
 	browser_favicon_privatebrowsing.js \
 	browser_visituri_privatebrowsing.js \
 	$(NULL)
 endif
 
copy from toolkit/components/places/tests/browser/browser_favicon_privatebrowsing.js
copy to toolkit/components/places/tests/browser/browser_favicon_privatebrowsing_perwindowpb.js
--- a/toolkit/components/places/tests/browser/browser_favicon_privatebrowsing.js
+++ b/toolkit/components/places/tests/browser/browser_favicon_privatebrowsing_perwindowpb.js
@@ -1,49 +1,43 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/**
- * One-time DOMContentLoaded callback.
- */
-function waitForLoad(callback)
-{
-  gTab.linkedBrowser.addEventListener("load", function()
-  {
-    gTab.linkedBrowser.removeEventListener("load", arguments.callee, true);
-    callback();
-  }, true);
-}
+function test() {
+  waitForExplicitFinish();
+
+  const pageURI =
+   "http://example.org/tests/toolkit/components/places/tests/browser/favicon.html";
+  let windowsToClose = [];
+
+  registerCleanupFunction(function() {
+    windowsToClose.forEach(function(aWin) {
+      aWin.close();
+    });
+  });
 
-let gTab;
-function test()
-{
-  if (!("@mozilla.org/privatebrowsing;1" in Cc)) {
-    todo(false, "PB service is not available, bail out");
-    return;
+  function testOnWindow(aIsPrivate, aCallback) {
+    whenNewWindowLoaded({private: aIsPrivate}, function(aWin) {
+      windowsToClose.push(aWin);
+      executeSoon(function() aCallback(aWin));
+    });
+  };
+
+  function waitForTabLoad(aWin, aCallback) {
+    aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
+      aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
+      aCallback();
+    }, true);
+    aWin.gBrowser.selectedBrowser.loadURI(pageURI);
   }
 
-  gTab = gBrowser.selectedTab = gBrowser.addTab();
-
-  waitForExplicitFinish();
-
-  Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
-  let pb = Cc["@mozilla.org/privatebrowsing;1"].
-           getService(Ci.nsIPrivateBrowsingService);
-  pb.privateBrowsingEnabled = true;
-
-  const pageURI ="http://example.org/tests/toolkit/components/places/tests/browser/favicon.html";
-  content.location.href = pageURI;
-  waitForLoad(function()
-  {
-    PlacesUtils.favicons.getFaviconURLForPage(
-      NetUtil.newURI(pageURI),
-      function(uri, dataLen, data, mimeType) {
-        is(uri, null, "no result should be found");
-        gBrowser.removeCurrentTab();
-        pb.privateBrowsingEnabled = false;
-        Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
-        finish();
-      });
+  testOnWindow(true, function(win) {
+    waitForTabLoad(win, function() {
+      PlacesUtils.favicons.getFaviconURLForPage(NetUtil.newURI(pageURI),
+        function(uri, dataLen, data, mimeType) {
+          is(uri, null, "No result should be found");
+          finish();
+        }
+      );
+    });
   });
 }
-