Bug 1466929 - Fix intermittent issues in browser_bookmarkProperties_remember_folders.js. r=mak
authorMark Banner <standard8@mozilla.com>
Thu, 07 Jun 2018 11:42:11 +0000
changeset 421795 4d7a1f17b57308bea883eeda84d2346c46627968
parent 421794 2ad747fb382a7ee26512d4d6f9f365f5933a8913
child 421796 4f885a43b217705eb052a618117c53e9f183c5ba
push id104125
push useraciure@mozilla.com
push dateThu, 07 Jun 2018 21:57:03 +0000
treeherdermozilla-inbound@38c222c1bf73 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1466929
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466929 - Fix intermittent issues in browser_bookmarkProperties_remember_folders.js. r=mak Ensure we wait for the onItemMoved notification before proceeding, to avoid async issues. Also improve the wait for checks to provide better debug. Differential Revision: https://phabricator.services.mozilla.com/D1579
browser/components/places/tests/browser/browser_bookmarkProperties_remember_folders.js
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_remember_folders.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_remember_folders.js
@@ -19,50 +19,71 @@ async function clickBookmarkStar() {
 
 async function hideBookmarksPanel() {
   let hiddenPromise = promisePopupHidden(bookmarkPanel);
   // Confirm and close the dialog.
   document.getElementById("editBookmarkPanelDoneButton").click();
   await hiddenPromise;
 }
 
-async function openPopupAndSelectFolder(guid) {
+async function openPopupAndSelectFolder(guid, newBookmark = false) {
   await clickBookmarkStar();
 
+  let notificationPromise;
+  if (!newBookmark) {
+    notificationPromise = PlacesTestUtils.waitForNotification("onItemMoved",
+      (id, oldParentId, oldIndex, newParentId, newIndex, type,
+       itemGuid, oldParentGuid, newParentGuid) => guid == newParentGuid);
+  }
+
   // Expand the folder tree.
   document.getElementById("editBMPanel_foldersExpander").click();
   document.getElementById("editBMPanel_folderTree").selectItems([guid]);
 
   await hideBookmarksPanel();
-  // Ensure the meta data has had chance to be written to disk.
-  await PlacesTestUtils.promiseAsyncUpdates();
+  if (!newBookmark) {
+    await notificationPromise;
+  }
 }
 
 async function assertRecentFolders(expectedGuids, msg) {
+  // Give the metadata chance to be written to the database before we attempt
+  // to open the dialog again.
+  let diskGuids = [];
+  await TestUtils.waitForCondition(async () => {
+    diskGuids = await PlacesUtils.metadata.get(PlacesUIUtils.LAST_USED_FOLDERS_META_KEY, []);
+    return diskGuids.length == expectedGuids.length;
+  }, `Should have written data to disk for: ${msg}`);
+
+  Assert.deepEqual(diskGuids, expectedGuids, `Should match the disk GUIDS for ${msg}`);
+
   await clickBookmarkStar();
 
   let actualGuids = [];
   function getGuids() {
+    actualGuids = [];
     const folderMenuPopup = document.getElementById("editBMPanel_folderMenuList").children[0];
 
     let separatorFound = false;
     // The list of folders goes from editBMPanel_foldersSeparator to the end.
     for (let child of folderMenuPopup.children) {
       if (separatorFound) {
         actualGuids.push(child.folderGuid);
       } else if (child.id == "editBMPanel_foldersSeparator") {
         separatorFound = true;
       }
     }
   }
 
+  // The dialog fills in the folder list asnychronously, so we might need to wait
+  // for that to complete.
   await TestUtils.waitForCondition(() => {
     getGuids();
     return actualGuids.length == expectedGuids.length;
-  }, msg);
+  }, `Should have opened dialog with expected recent folders for: ${msg}`);
 
   Assert.deepEqual(actualGuids, expectedGuids, msg);
 
   await hideBookmarksPanel();
 }
 
 add_task(async function setup() {
   await PlacesUtils.bookmarks.eraseEverything();
@@ -110,17 +131,17 @@ add_task(async function setup() {
     await PlacesUtils.bookmarks.eraseEverything();
     await PlacesUtils.metadata.delete(PlacesUIUtils.LAST_USED_FOLDERS_META_KEY);
   });
 });
 
 add_task(async function test_remember_last_folder() {
   await assertRecentFolders([], "Should have no recent folders to start with.");
 
-  await openPopupAndSelectFolder(folders[0].guid);
+  await openPopupAndSelectFolder(folders[0].guid, true);
 
   await assertRecentFolders([folders[0].guid], "Should have one folder in the list.");
 });
 
 add_task(async function test_forget_oldest_folder() {
   // Add some more folders.
   let expectedFolders = [folders[0].guid];
   for (let i = 1; i < folders.length; i++) {