From 4560d160453d9cb8f8c7eee6fc3f58b1a8d7731f Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Tue, 9 Dec 2008 21:39:32 +0100 Subject: [PATCH] Bug 465510 - random failures on test_database_sync_after_addVisit.js, r=sdwilsh --- .../components/places/src/nsPlacesDBFlush.js | 9 ++-- .../sync/test_database_sync_after_addVisit.js | 45 ++++++++++++++----- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/toolkit/components/places/src/nsPlacesDBFlush.js b/toolkit/components/places/src/nsPlacesDBFlush.js index 9ae5fd13501..1f9ae4f3546 100644 --- a/toolkit/components/places/src/nsPlacesDBFlush.js +++ b/toolkit/components/places/src/nsPlacesDBFlush.js @@ -46,6 +46,7 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); const Cc = Components.classes; const Ci = Components.interfaces; const Cr = Components.results; +const Cu = Components.utils; const kQuitApplication = "quit-application"; const kSyncFinished = "places-sync-finished"; @@ -59,8 +60,8 @@ const kDefaultSyncInterval = 120; function nsPlacesDBFlush() { this._prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); + getService(Ci.nsIPrefService). + getBranch("places."); // Get our sync interval try { @@ -187,8 +188,8 @@ nsPlacesDBFlush.prototype = { handleError: function DBFlush_handleError(aError) { - Components.utils.reportError("Async statement execution returned with '" + - aError.result + "', '" + aError.message + "'"); + Cu.reportError("Async statement execution returned with '" + + aError.result + "', '" + aError.message + "'"); }, handleCompletion: function DBFlush_handleCompletion(aReason) diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js b/toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js index 431324cf46a..a100df86ef0 100644 --- a/toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js +++ b/toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js @@ -45,11 +45,43 @@ var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. var prefs = Cc["@mozilla.org/preferences-service;1"]. getService(Ci.nsIPrefService). getBranch("places."); +var os = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); const TEST_URI = "http://test.com/"; const kSyncPrefName = "syncDBTableIntervalInSecs"; const SYNC_INTERVAL = 1; +const kSyncFinished = "places-sync-finished"; + +var observer = { + visitId: -1, + observe: function(aSubject, aTopic, aData) { + if (aTopic == kSyncFinished && this.visitId != -1) { + // sanity check: visitId set by history observer should be the same we + // have added + do_check_eq(this.visitId, visitId); + // remove the observer, we don't need to observe sync on quit + os.removeObserver(this, kSyncFinished); + // Check the visit + new_test_visit_uri_event(this.visitId, TEST_URI, true, true); + } + } +} +os.addObserver(observer, kSyncFinished, false); + +// Used to update observer visitId +var historyObserver = { + onVisit: function(aURI, aVisitId, aTime, aSessionId, aReferringId, + aTransitionType, aAdded) { + observer.visitId = aVisitId; + hs.removeObserver(this, false); + } +} +hs.addObserver(historyObserver, false); + +// used for sanity check +var visitId = -1; function run_test() { @@ -57,17 +89,8 @@ function run_test() prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); // Now add the visit - let id = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); + visitId = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, + hs.TRANSITION_TYPED, false, 0); - // Check the visit, but after enough time has passed for the DB flush service - // to have fired it's timer. - let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.initWithCallback({ - notify: function(aTimer) - { - new_test_visit_uri_event(id, TEST_URI, true, true); - } - }, (SYNC_INTERVAL * 1000) * 2, Ci.nsITimer.TYPE_ONE_SHOT); do_test_pending(); }