From 6147cfffcc20e2a7e07d1dedc1fcce9c2a5e7b66 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Tue, 12 Apr 2011 16:07:44 -0400 Subject: [PATCH] ts in browser/components/sessionstore/test/browser should use utility functions in head.js; r=zpao --- .../browser_586068-cascaded_restore.js | 3 -- .../test/browser/browser_590268.js | 5 -- .../test/browser/browser_600545.js | 50 +------------------ .../test/browser/browser_607016.js | 4 -- .../test/browser/browser_618151.js | 13 ----- 5 files changed, 2 insertions(+), 73 deletions(-) diff --git a/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js b/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js index ef6122bd1c2..52037cb388c 100644 --- a/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js +++ b/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js @@ -760,6 +760,3 @@ function countTabs() { return [needsRestore, isRestoring, wasRestored]; } -function r() { - return "" + Date.now() + Math.random(); -} diff --git a/browser/components/sessionstore/test/browser/browser_590268.js b/browser/components/sessionstore/test/browser/browser_590268.js index a44666c49a9..2ab3de50530 100644 --- a/browser/components/sessionstore/test/browser/browser_590268.js +++ b/browser/components/sessionstore/test/browser/browser_590268.js @@ -170,8 +170,3 @@ function test() { // Restore state ss.setBrowserState(JSON.stringify(state)); } - -// Helper function to create a random value -function r() { - return "" + Date.now() + Math.random(); -} diff --git a/browser/components/sessionstore/test/browser/browser_600545.js b/browser/components/sessionstore/test/browser/browser_600545.js index 780f1b5f556..43b59a8879d 100644 --- a/browser/components/sessionstore/test/browser/browser_600545.js +++ b/browser/components/sessionstore/test/browser/browser_600545.js @@ -50,54 +50,6 @@ function testBug600545() { // Set the pref to false to cause non-app tabs to be stripped out on a save Services.prefs.setBoolPref("browser.sessionstore.resume_from_crash", false); - // Need to wait for SessionStore's saveState function to be called - // so that non-pinned tabs will be stripped from non-active window - function waitForSaveState(aSaveStateCallback) { - let topic = "sessionstore-state-write"; - Services.obs.addObserver(function() { - Services.obs.removeObserver(arguments.callee, topic, false); - executeSoon(aSaveStateCallback); - }, topic, false); - }; - - // Need to wait for all tabs to be restored before reading browser state - function waitForBrowserState(aState, aSetStateCallback) { - let tabsRestored = 0; - let expectedTabs = getStateTabCount(aState); - - // We know that there are only 2 windows total, so just be specific - let newWin; - - // Used to determine when tabs have been restored - function onTabRestored(aEvent) { - if (++tabsRestored == expectedTabs) { - gBrowser.tabContainer.removeEventListener("SSTabRestored", onTabRestored, true); - newWin.gBrowser.tabContainer.removeEventListener("SSTabRestored", onTabRestored, true); - executeSoon(aSetStateCallback); - } - } - - // We also want to catch the 2nd window, so we need to observe domwindowopened - function windowObserver(aSubject, aTopic, aData) { - let theWin = aSubject.QueryInterface(Ci.nsIDOMWindow); - if (aTopic == "domwindowopened") { - theWin.addEventListener("load", function() { - theWin.removeEventListener("load", arguments.callee, false); - - // So we can remove the event listener in onTabRestored - newWin = theWin; - - Services.ww.unregisterNotification(windowObserver); - theWin.gBrowser.tabContainer.addEventListener("SSTabRestored", onTabRestored, true); - }, false); - } - } - - Services.ww.registerNotification(windowObserver); - gBrowser.tabContainer.addEventListener("SSTabRestored", onTabRestored, true); - ss.setBrowserState(JSON.stringify(aState)); - } - // This tests the following use case: // When multiple windows are open and browser.sessionstore.resume_from_crash // preference is false, tab session data for non-active window is stripped for @@ -124,6 +76,8 @@ function testBug600545() { ] }; waitForBrowserState(state, function() { + // Need to wait for SessionStore's saveState function to be called + // so that non-pinned tabs will be stripped from non-active window waitForSaveState(function () { let expectedNumberOfTabs = getStateTabCount(state); let retrievedState = JSON.parse(ss.getBrowserState()); diff --git a/browser/components/sessionstore/test/browser/browser_607016.js b/browser/components/sessionstore/test/browser/browser_607016.js index 7b2e93c0288..e2c77d51b90 100644 --- a/browser/components/sessionstore/test/browser/browser_607016.js +++ b/browser/components/sessionstore/test/browser/browser_607016.js @@ -148,7 +148,3 @@ function test() { ss.setBrowserState(JSON.stringify(state)); } -// Helper function to create a random value -function r() { - return "" + Date.now() + Math.random(); -} diff --git a/browser/components/sessionstore/test/browser/browser_618151.js b/browser/components/sessionstore/test/browser/browser_618151.js index 8aa27e307d7..a6df99b495c 100644 --- a/browser/components/sessionstore/test/browser/browser_618151.js +++ b/browser/components/sessionstore/test/browser/browser_618151.js @@ -80,19 +80,6 @@ function runNextTest() { } } -// helper, works only for single window -function waitForBrowserState(aState, aSetStateCallback) { - let tabsRestored = 0; - gBrowser.tabContainer.addEventListener("SSTabRestored", function() { - if (++tabsRestored == aState.windows[0].tabs.length) { - gBrowser.tabContainer.removeEventListener("SSTabRestored", arguments.callee, true); - executeSoon(aSetStateCallback); - } - }, true); - ss.setBrowserState(JSON.stringify(aState)); -} - - function test_setup() { function onSSTabRestored(aEvent) { gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false);