Bug 1036440 - Fix tests and consumers for rewritten `PlacesDBUtils`, r=mak

This includes 2 things:
1. Replacing the parts which test the logs for the presence of prefixes by testing
the returned map for `suceeded`.
2. We don't need to wait to observe the topic anymore, we can simply await methods
from `PlacesDBUtils` to know when they are done.

MozReview-Commit-ID: Ct9l9pzUW5x

--HG--
extra : rebase_source : 657e4ac53f8b3785740a5b732d483fad9600f73d
This commit is contained in:
milindl 2017-05-24 11:00:47 +05:30
Родитель b03686f5f1
Коммит fc8d285e3d
7 изменённых файлов: 37 добавлений и 89 удалений

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

@ -230,10 +230,7 @@ add_task(async function test_filter_hidden() {
_(`Framed link visit GUID: ${embedGUID}`);
_("Run Places maintenance to mark redirect visit as hidden");
let maintenanceFinishedPromise =
promiseOneObserver("places-maintenance-finished");
PlacesDBUtils.maintenanceOnIdle();
await maintenanceFinishedPromise;
await PlacesDBUtils.maintenanceOnIdle();
await verifyTrackedItems([trackedGUID]);

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

@ -1,4 +1,4 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@ -83,10 +83,7 @@ add_task(async function maintenance_foreign_count_test() {
// Run maintenance
Components.utils.import("resource://gre/modules/PlacesDBUtils.jsm");
let promiseMaintenanceFinished =
promiseTopicObserved("places-maintenance-finished");
PlacesDBUtils.maintenanceOnIdle();
await promiseMaintenanceFinished;
await PlacesDBUtils.maintenanceOnIdle();
// Check if the foreign_count has been adjusted to the correct value
Assert.equal((await getForeignCountForURL(conn, T_URI)), 0);

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

@ -1312,13 +1312,8 @@ add_task(async function test_preventive_maintenance() {
dump("\nExecuting test: " + test.name + "\n*** " + test.desc + "\n");
await test.setup();
let promiseMaintenanceFinished =
promiseTopicObserved(FINISHED_MAINTENANCE_NOTIFICATION_TOPIC);
Services.prefs.clearUserPref("places.database.lastMaintenance");
let callbackInvoked = false;
PlacesDBUtils.maintenanceOnIdle(() => callbackInvoked = true);
await promiseMaintenanceFinished;
do_check_true(callbackInvoked);
await PlacesDBUtils.maintenanceOnIdle();
// Check the lastMaintenance time has been saved.
do_check_neq(Services.prefs.getIntPref("places.database.lastMaintenance"), null);

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

@ -11,40 +11,19 @@
// Include PlacesDBUtils module.
Components.utils.import("resource://gre/modules/PlacesDBUtils.jsm");
function run_test() {
do_test_pending();
PlacesDBUtils.checkAndFixDatabase(function(aLog) {
let sections = [];
let positives = [];
let negatives = [];
let infos = [];
aLog.forEach(function(aMsg) {
print(aMsg);
switch (aMsg.substr(0, 1)) {
case "+":
positives.push(aMsg);
break;
case "-":
negatives.push(aMsg);
break;
case ">":
sections.push(aMsg);
break;
default:
infos.push(aMsg);
add_task(async function() {
let tasksStatusMap = await PlacesDBUtils.checkAndFixDatabase();
let numberOfTasksRun = tasksStatusMap.size;
let successfulTasks = [];
let failedTasks = [];
tasksStatusMap.forEach(val => {
if (val.succeeded) {
successfulTasks.push(val);
} else {
failedTasks.push(val);
}
});
print("Check that we have run all sections.");
do_check_eq(sections.length, 5);
print("Check that we have no negatives.");
do_check_false(!!negatives.length);
print("Check that we have positives.");
do_check_true(!!positives.length);
print("Check that we have info.");
do_check_true(!!infos.length);
do_test_finished();
});
}
Assert.equal(numberOfTasksRun, 6, "Check that we have run all tasks.");
Assert.equal(successfulTasks.length, 6, "Check that we have run all tasks successfully");
Assert.equal(failedTasks.length, 0, "Check that no task is failing");
});

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

@ -9,38 +9,20 @@
// Include PlacesDBUtils module.
Components.utils.import("resource://gre/modules/PlacesDBUtils.jsm");
function run_test() {
do_test_pending();
PlacesDBUtils.runTasks([PlacesDBUtils.reindex], function(aLog) {
let sections = [];
let positives = [];
let negatives = [];
let infos = [];
aLog.forEach(function(aMsg) {
print(aMsg);
switch (aMsg.substr(0, 1)) {
case "+":
positives.push(aMsg);
break;
case "-":
negatives.push(aMsg);
break;
case ">":
sections.push(aMsg);
break;
default:
infos.push(aMsg);
}
});
print("Check that we have run all sections.");
do_check_eq(sections.length, 1);
print("Check that we have no negatives.");
do_check_false(!!negatives.length);
print("Check that we have positives.");
do_check_true(!!positives.length);
do_test_finished();
add_task(async function() {
let tasksStatusMap = await PlacesDBUtils.runTasks([PlacesDBUtils.reindex]);
let numberOfTasksRun = tasksStatusMap.size;
let successfulTasks = [];
let failedTasks = [];
tasksStatusMap.forEach(val => {
if (val.succeeded) {
successfulTasks.push(val);
} else {
failedTasks.push(val);
}
});
}
Assert.equal(numberOfTasksRun, 1, "Check that we have run all tasks.");
Assert.equal(successfulTasks.length, 1, "Check that we have run all tasks successfully");
Assert.equal(failedTasks.length, 0, "Check that no task is failing");
});

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

@ -151,9 +151,7 @@ add_task(async function test_execute() {
// Test idle probes.
PlacesUtils.history.QueryInterface(Ci.nsIObserver)
.observe(null, "idle-daily", null);
PlacesDBUtils.maintenanceOnIdle();
await promiseTopicObserved("places-maintenance-finished");
await PlacesDBUtils.maintenanceOnIdle();
for (let histogramId in histograms) {
do_print("checking histogram " + histogramId);

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

@ -1035,8 +1035,8 @@ function setupEventListeners() {
}
});
$("verify-place-integrity-button").addEventListener("click", function(event) {
PlacesDBUtils.checkAndFixDatabase(function(aLog) {
let msg = aLog.join("\n");
PlacesDBUtils.checkAndFixDatabase().then((tasksStatusMap) => {
let msg = PlacesDBUtils.getLegacyLog(tasksStatusMap).join("\n");
$("verify-place-result").style.display = "block";
$("verify-place-result").classList.remove("no-copy");
$("verify-place-result").textContent = msg;