diff --git a/toolkit/components/places/PlacesDBUtils.jsm b/toolkit/components/places/PlacesDBUtils.jsm index b8f4e1affc1..d759f226460 100644 --- a/toolkit/components/places/PlacesDBUtils.jsm +++ b/toolkit/components/places/PlacesDBUtils.jsm @@ -67,7 +67,6 @@ this.PlacesDBUtils = { } // Notify observers that maintenance finished. - Services.prefs.setIntPref("places.database.lastMaintenance", parseInt(Date.now() / 1000)); Services.obs.notifyObservers(null, FINISHED_MAINTENANCE_TOPIC, null); } }, @@ -94,7 +93,12 @@ this.PlacesDBUtils = { , this._refreshUI ]); tasks._telemetryStart = Date.now(); - tasks.callback = aCallback; + tasks.callback = function() { + Services.prefs.setIntPref("places.database.lastMaintenance", + parseInt(Date.now() / 1000)); + if (aCallback) + aCallback(); + } tasks.scope = aScope; this._executeTasks(tasks); }, diff --git a/toolkit/components/places/tests/unit/test_preventive_maintenance.js b/toolkit/components/places/tests/unit/test_preventive_maintenance.js index 1f4a616432f..bc87e6bad98 100644 --- a/toolkit/components/places/tests/unit/test_preventive_maintenance.js +++ b/toolkit/components/places/tests/unit/test_preventive_maintenance.js @@ -1279,14 +1279,17 @@ add_task(function test_preventive_maintenance() stmt.finalize(); do_check_true(defaultBookmarksMaxId > 0); - for ([, test] in Iterator(tests)) { + for (let [, test] in Iterator(tests)) { dump("\nExecuting test: " + test.name + "\n" + "*** " + test.desc + "\n"); yield test.setup(); let promiseMaintenanceFinished = promiseTopicObserved(FINISHED_MAINTENANCE_NOTIFICATION_TOPIC); - PlacesDBUtils.maintenanceOnIdle(); + Services.prefs.clearUserPref("places.database.lastMaintenance"); + let callbackInvoked = false; + PlacesDBUtils.maintenanceOnIdle(() => callbackInvoked = true); yield promiseMaintenanceFinished; + do_check_true(callbackInvoked); // Check the lastMaintenance time has been saved. do_check_neq(Services.prefs.getIntPref("places.database.lastMaintenance"), null); diff --git a/toolkit/components/places/tests/unit/test_telemetry.js b/toolkit/components/places/tests/unit/test_telemetry.js index 7c6ddae2e7b..2853c9e47ff 100644 --- a/toolkit/components/places/tests/unit/test_telemetry.js +++ b/toolkit/components/places/tests/unit/test_telemetry.js @@ -126,6 +126,7 @@ add_task(function test_execute() }); add_test(function test_healthreport_callback() { + Services.prefs.clearUserPref("places.database.lastMaintenance"); PlacesDBUtils.telemetry(null, function onResult(data) { do_check_neq(data, null); @@ -133,6 +134,7 @@ add_test(function test_healthreport_callback() { do_check_eq(data.PLACES_PAGES_COUNT, 1); do_check_eq(data.PLACES_BOOKMARKS_COUNT, 1); + do_check_true(!Services.prefs.prefHasUserValue("places.database.lastMaintenance")); run_next_test(); }); });