From dd643517abb6d339b650e1effc97f25166502bd5 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 14 Oct 2010 15:38:56 -0400 Subject: [PATCH] Bug 551540 followup - Wait for the Organizer window to be closed before proceeding; r=dolske a=orange-fix --- .../browser/browser_forgetthissite_single.js | 37 ++++++++++++++++--- .../browser_privatebrowsing_forgetthissite.js | 37 ++++++++++++++++--- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/browser/components/places/tests/browser/browser_forgetthissite_single.js b/browser/components/places/tests/browser/browser_forgetthissite_single.js index c593ae68b742..b9be4d89f3df 100644 --- a/browser/components/places/tests/browser/browser_forgetthissite_single.js +++ b/browser/components/places/tests/browser/browser_forgetthissite_single.js @@ -38,6 +38,24 @@ // This test makes sure that the Forget This Site command is hidden for multiple // selections. +/** + * Clears history invoking callback when done. + */ +function waitForClearHistory(aCallback) { + const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished"; + let observer = { + observe: function(aSubject, aTopic, aData) { + Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED); + aCallback(); + } + }; + Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false); + + let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. + getService(Ci.nsINavHistoryService); + hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages(); +} + function test() { // initialization let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. @@ -61,6 +79,7 @@ function test() { ww.unregisterNotification(observer); let organizer = aSubject.QueryInterface(Ci.nsIDOMWindow); SimpleTest.waitForFocus(function() { + executeSoon(function() { // Select History in the left pane. organizer.PlacesOrganizer.selectLeftPaneQuery('History'); let PO = organizer.PlacesOrganizer; @@ -86,10 +105,19 @@ function test() { "be hidden with " + selectionCount + " items selected"); // Close the context menu contextmenu.hidePopup(); + // Wait for the Organizer window to actually be closed + function closeObserver(aSubject, aTopic, aData) { + if (aTopic != "domwindowclosed") + return; + ww.unregisterNotification(closeObserver); + SimpleTest.waitForFocus(function() { + // Proceed + funcNext(); + }); + } + ww.registerNotification(closeObserver); // Close Library window. organizer.close(); - // Proceed - funcNext(); }, false); // Get cell coordinates var x = {}, y = {}, width = {}, height = {}; @@ -97,6 +125,7 @@ function test() { x, y, width, height); // Initiate a context menu for the selected cell EventUtils.synthesizeMouse(tree.body, x + 4, y + 4, {type: "contextmenu"}, organizer); + }); }, organizer); } @@ -111,9 +140,7 @@ function test() { testForgetThisSiteVisibility(1, function() { testForgetThisSiteVisibility(2, function() { // Cleanup - history.QueryInterface(Ci.nsIBrowserHistory) - .removeAllPages(); - finish(); + waitForClearHistory(finish); }); }); } diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_forgetthissite.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_forgetthissite.js index 838202470f07..147b0ae8756b 100644 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_forgetthissite.js +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_forgetthissite.js @@ -38,6 +38,24 @@ // This test makes sure that the Forget This Site command is hidden in private // browsing mode. +/** + * Clears history invoking callback when done. + */ +function waitForClearHistory(aCallback) { + const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished"; + let observer = { + observe: function(aSubject, aTopic, aData) { + Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED); + aCallback(); + } + }; + Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false); + + let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. + getService(Ci.nsINavHistoryService); + hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages(); +} + function test() { // initialization let pb = Cc["@mozilla.org/privatebrowsing;1"]. @@ -60,6 +78,7 @@ function test() { Services.ww.unregisterNotification(observer); let organizer = aSubject.QueryInterface(Ci.nsIDOMWindow); SimpleTest.waitForFocus(function() { + executeSoon(function() { // Select History in the left pane. let PO = organizer.PlacesOrganizer; PO.selectLeftPaneQuery('History'); @@ -85,10 +104,19 @@ function test() { "The Forget This Site command should " + (expected ? "not " : "") + "be disabled"); // Close the context menu contextmenu.hidePopup(); + // Wait for the Organizer window to actually be closed + function closeObserver(aSubject, aTopic, aData) { + if (aTopic != "domwindowclosed") + return; + Services.ww.unregisterNotification(closeObserver); + SimpleTest.waitForFocus(function() { + // Proceed + funcNext(); + }); + } + Services.ww.registerNotification(closeObserver); // Close Library window. organizer.close(); - // Proceed - funcNext(); }, false); // Get cell coordinates var x = {}, y = {}, width = {}, height = {}; @@ -96,6 +124,7 @@ function test() { x, y, width, height); // Initiate a context menu for the selected cell EventUtils.synthesizeMouse(tree.body, x + 4, y + 4, {type: "contextmenu"}, organizer); + }); }, organizer); } @@ -115,9 +144,7 @@ function test() { pb.privateBrowsingEnabled = false; testForgetThisSiteVisibility(true, function() { // Cleanup - history.QueryInterface(Ci.nsIBrowserHistory) - .removeAllPages(); - finish(); + waitForClearHistory(finish); }); }); });