Bug 465510 - random failures on test_database_sync_after_addVisit.js, r=sdwilsh

This commit is contained in:
Marco Bonardo 2008-12-09 21:39:32 +01:00
Родитель 28e377dc8d
Коммит 6ad8f55fc3
2 изменённых файлов: 39 добавлений и 15 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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();
}