Bug 1409771 - Switch tests from promiseBookmarksNotification to PlacesTestUtils.waitForNotification so that skipDescendantsOnItemRemoval/skipTags are handled correctly. r?mak
MozReview-Commit-ID: 2dg44HRdD00
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_addFolderDefaultButton.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_addFolderDefaultButton.js
@@ -25,17 +25,17 @@ add_task(async function() {
// are inserted at the index of the currently selected item, the new folder
// will be inserted at index 0.
await withBookmarksDialog(
false,
function openDialog() {
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);
// Confirm and close the dialog.
EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
await promiseTitleChangeNotification;
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_addLivemark.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_addLivemark.js
@@ -9,17 +9,17 @@ add_task(async function() {
await withBookmarksDialog(
true,
function openDialog() {
PlacesCommandHook.addLiveBookmark("http://livemark.com/",
"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);
await promiseTitleChangeNotification;
let bookmark = await PlacesUtils.bookmarks.fetch({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_bookmarkAllTabs.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_bookmarkAllTabs.js
@@ -24,17 +24,17 @@ add_task(async function() {
let acceptBtn = dialog.document.documentElement.getButton("accept");
ok(!acceptBtn.disabled, "Accept button is enabled");
let namepicker = dialog.document.getElementById("editBMPanel_namePicker");
Assert.ok(!namepicker.readOnly, "Name field is writable");
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;
},
dialog => {
let savedItemId = dialog.gEditItemOverlay.itemId;
ok(savedItemId > 0, "Found the itemId");
return PlacesTestUtils.waitForNotification("onItemRemoved",
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
@@ -94,17 +94,17 @@ add_task(async function test_cancel_with
function openDialog() {
tree.controller.doCommand("placesCmd_show:info");
},
async function test(dialogWin) {
let acceptButton = dialogWin.document.documentElement.getButton("accept");
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);
// The dialog is instant apply.
await promiseTitleChangeNotification;
// Ensure that the addition really is finished before we hit cancel.
--- a/browser/components/places/tests/browser/browser_library_batch_delete.js
+++ b/browser/components/places/tests/browser/browser_library_batch_delete.js
@@ -52,17 +52,17 @@ add_task(async function test_create_and_
Assert.equal(unsortedNode.childCount, 2, "Unsorted node has 2 children");
let folderNode = unsortedNode.getChild(0);
Assert.equal(folderNode.title, "deleteme", "Folder found in unsorted bookmarks");
// Check delete command is available.
PO._places.selectNode(folderNode);
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");
await promiseItemRemovedNotification;
Assert.ok(!(await PlacesUtils.bookmarks.fetch({url: testURI})),
"Bookmark has been correctly removed");
--- a/browser/components/places/tests/browser/browser_library_commands.js
+++ b/browser/components/places/tests/browser/browser_library_commands.js
@@ -54,18 +54,18 @@ add_task(async function test_date_contai
ok(PO._places.controller.isCommandEnabled("cmd_copy"),
"Copy command is enabled");
ok(!PO._places.controller.isCommandEnabled("cmd_cut"),
"Cut command is disabled");
ok(PO._places.controller.isCommandEnabled("cmd_delete"),
"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;
// Test live update of "History" query.
is(historyNode.childCount, 0, "History node has no more children");
historyNode.containerOpen = false;
@@ -119,18 +119,18 @@ add_task(async function test_query_on_to
ok(PO._places.controller.isCommandEnabled("cmd_copy"),
"Copy command is enabled");
ok(PO._places.controller.isCommandEnabled("cmd_cut"),
"Cut command is enabled");
ok(PO._places.controller.isCommandEnabled("cmd_delete"),
"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;
is((await PlacesUtils.bookmarks.fetch(query.guid)), null,
"Query node bookmark has been correctly removed");
toolbarNode.containerOpen = false;
--- a/browser/components/places/tests/browser/browser_toolbar_drop_text.js
+++ b/browser/components/places/tests/browser/browser_toolbar_drop_text.js
@@ -30,17 +30,17 @@ add_task(async function test() {
*
* @param aEffect
* The effect to use for the drop operation: move, copy, or link.
* @param aMimeType
* The mime type to use for the drop operation.
*/
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
// to simulate the drag. The actual data for the drop is passed via the
// drag data. Note: The toolbar is used rather than another bookmark node,
// as we need something that is immovable from a places perspective, as this
// forces the move into a copy.
EventUtils.synthesizeDrop(toolbar,
@@ -76,17 +76,17 @@ add_task(async function test() {
"http://www.mozilla.org/091A88BD-5743-4C16-A005-3D2EA3A3B71E"
];
let data;
if (aMimeType == "text/x-moz-url")
data = urls.map(spec => spec + "\n" + spec).join("\n");
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().
EventUtils.synthesizeDrop(toolbar,
placesItems,
[[{type: aMimeType,
data}]],
aEffect, window);
--- a/browser/components/places/tests/browser/head.js
+++ b/browser/components/places/tests/browser/head.js
@@ -155,61 +155,16 @@ function promiseIsURIVisited(aURI) {
PlacesUtils.asyncHistory.isURIVisited(aURI, function(unused, aIsVisited) {
resolve(aIsVisited);
});
});
}
-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
* with hiding or showing the toolbar.
*
* Note that this code assumes that changes to a toolbar's visibility trigger
* a transition on the max-height property of the toolbar element.
* Changes to this styling could cause the returned Promise object to be