Bug 1409771 - Switch tests from promiseBookmarksNotification to PlacesTestUtils.waitForNotification so that skipDescendantsOnItemRemoval/skipTags are handled correctly. r=mak

MozReview-Commit-ID: 2dg44HRdD00

--HG--
extra : rebase_source : ea833baa47e5cd9f75831f339c87a771580881e1
This commit is contained in:
Mark Banner 2017-10-18 16:20:43 +01:00
Родитель 652f0a41d5
Коммит 1d50512637
8 изменённых файлов: 11 добавлений и 56 удалений

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

@ -30,7 +30,7 @@ add_task(async function() {
tree.controller.doCommand("placesCmd_new:folder");
},
async function test(dialogWin) {
let promiseTitleChangeNotification = promiseBookmarksNotification(
let promiseTitleChangeNotification = PlacesTestUtils.waitForNotification(
"onItemChanged", (itemId, prop, isAnno, val) => prop == "title" && val == "n");
fillBookmarkTextField("editBMPanel_namePicker", "n", dialogWin, false);

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

@ -14,7 +14,7 @@ add_task(async function() {
"livemark", "description");
},
async function test(dialogWin) {
let promiseTitleChangeNotification = promiseBookmarksNotification(
let promiseTitleChangeNotification = PlacesTestUtils.waitForNotification(
"onItemChanged", (unused, prop, isAnno, val) => prop == "title" && val == "modified");
fillBookmarkTextField("editBMPanel_namePicker", "modified", dialogWin);

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

@ -29,7 +29,7 @@ add_task(async function() {
let folderName = dialog.document.getElementById("stringBundle").getString("bookmarkAllTabsDefault");
Assert.equal(namepicker.value, folderName, "Name field is correct.");
let promiseTitleChange = promiseBookmarksNotification(
let promiseTitleChange = PlacesTestUtils.waitForNotification(
"onItemChanged", (id, prop, isAnno, val) => prop == "title" && val == "folder");
fillBookmarkTextField("editBMPanel_namePicker", "folder", dialog);
await promiseTitleChange;

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

@ -99,7 +99,7 @@ add_task(async function test_cancel_with_changes() {
await BrowserTestUtils.waitForCondition(() => !acceptButton.disabled,
"The accept button should be enabled");
let promiseTitleChangeNotification = promiseBookmarksNotification(
let promiseTitleChangeNotification = PlacesTestUtils.waitForNotification(
"onItemChanged", (itemId, prop, isAnno, val) => prop == "title" && val == "n");
fillBookmarkTextField("editBMPanel_namePicker", "n", dialogWin);

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

@ -57,7 +57,7 @@ add_task(async function test_create_and_batch_remove_bookmarks() {
Assert.equal(PO._places.selectedNode.title, "deleteme", "Folder node selected");
Assert.ok(PO._places.controller.isCommandEnabled("cmd_delete"),
"Delete command is enabled");
let promiseItemRemovedNotification = promiseBookmarksNotification(
let promiseItemRemovedNotification = PlacesTestUtils.waitForNotification(
"onItemRemoved", (itemId, parentId, index, type, uri, guid) => guid == folderNode.bookmarkGuid);
// Execute the delete command and check bookmark has been removed.
PO._places.controller.doCommand("cmd_delete");

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

@ -59,8 +59,8 @@ add_task(async function test_date_container() {
"Delete command is enabled");
// Execute the delete command and check visit has been removed.
let promiseURIRemoved = promiseHistoryNotification("onDeleteURI",
v => TEST_URI.equals(v));
let promiseURIRemoved = PlacesTestUtils.waitForNotification(
"onDeleteURI", v => TEST_URI.equals(v), "history");
PO._places.controller.doCommand("cmd_delete");
await promiseURIRemoved;
@ -124,8 +124,8 @@ add_task(async function test_query_on_toolbar() {
"Delete command is enabled");
// Execute the delete command and check bookmark has been removed.
let promiseItemRemoved = promiseBookmarksNotification("onItemRemoved",
(...args) => query.guid == args[5]);
let promiseItemRemoved = PlacesTestUtils.waitForNotification(
"onItemRemoved", (...args) => query.guid == args[5]);
PO._places.controller.doCommand("cmd_delete");
await promiseItemRemoved;

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

@ -33,7 +33,7 @@ add_task(async function test() {
*/
let simulateDragDrop = async function(aEffect, aMimeType) {
const url = "http://www.mozilla.org/D1995729-A152-4e30-8329-469B01F30AA7";
let promiseItemAddedNotification = promiseBookmarksNotification(
let promiseItemAddedNotification = PlacesTestUtils.waitForNotification(
"onItemAdded", (itemId, parentId, index, type, uri, guid) => uri.spec == url);
// We use the toolbar as the drag source, as we just need almost any node
@ -79,7 +79,7 @@ add_task(async function test() {
else
data = urls.join("\n");
let promiseItemAddedNotification = promiseBookmarksNotification(
let promiseItemAddedNotification = PlacesTestUtils.waitForNotification(
"onItemAdded", (itemId, parentId, index, type, uri, guid) => uri.spec == urls[2]);
// See notes for EventUtils.synthesizeDrop in simulateDragDrop().

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

@ -160,51 +160,6 @@ function promiseIsURIVisited(aURI) {
});
}
function promiseBookmarksNotification(notification, conditionFn) {
info(`promiseBookmarksNotification: waiting for ${notification}`);
return new Promise((resolve) => {
let proxifiedObserver = new Proxy({}, {
get: (target, name) => {
if (name == "QueryInterface")
return XPCOMUtils.generateQI([ Ci.nsINavBookmarkObserver ]);
info(`promiseBookmarksNotification: got ${name} notification`);
if (name == notification)
return (...args) => {
if (conditionFn.apply(this, args)) {
PlacesUtils.bookmarks.removeObserver(proxifiedObserver, false);
executeSoon(resolve);
} else {
info(`promiseBookmarksNotification: skip cause condition doesn't apply to ${JSON.stringify(args)}`);
}
};
return () => {};
}
});
PlacesUtils.bookmarks.addObserver(proxifiedObserver);
});
}
function promiseHistoryNotification(notification, conditionFn) {
info(`Waiting for ${notification}`);
return new Promise((resolve) => {
let proxifiedObserver = new Proxy({}, {
get: (target, name) => {
if (name == "QueryInterface")
return XPCOMUtils.generateQI([ Ci.nsINavHistoryObserver ]);
if (name == notification)
return (...args) => {
if (conditionFn.apply(this, args)) {
PlacesUtils.history.removeObserver(proxifiedObserver, false);
executeSoon(resolve);
}
};
return () => {};
}
});
PlacesUtils.history.addObserver(proxifiedObserver);
});
}
/**
* Makes the specified toolbar visible or invisible and returns a Promise object
* that is resolved when the toolbar has completed any animations associated