Bug 1255985 - Switch from using BrowserTestUtils.openNewForegroundTab to .withNewTab to make sure that we yield until the tab is fully closed. r?paolo draft
authorJared Wein <jwein@mozilla.com>
Thu, 26 Jan 2017 16:56:50 -0500
changeset 467316 5e031aa2830ef5e8575df1a64c9648141d6e0f8a
parent 466816 d92fd6b6d6bfc5b566222ae2957e55772d60151a
child 543662 1683811bd19472c02eccabd354c2ae0f21bae475
push id43149
push userbmo:jaws@mozilla.com
push dateFri, 27 Jan 2017 18:09:43 +0000
reviewerspaolo
bugs1255985
milestone54.0a1
Bug 1255985 - Switch from using BrowserTestUtils.openNewForegroundTab to .withNewTab to make sure that we yield until the tab is fully closed. r?paolo MozReview-Commit-ID: 8PGmikTeiJ6
browser/base/content/test/general/browser_bookmark_popup.js
--- a/browser/base/content/test/general/browser_bookmark_popup.js
+++ b/browser/base/content/test/general/browser_bookmark_popup.js
@@ -11,82 +11,82 @@
 let bookmarkPanel = document.getElementById("editBookmarkPanel");
 let bookmarkStar = document.getElementById("bookmarks-menu-button");
 let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
 
 StarUI._closePanelQuickForTesting = true;
 
 function* test_bookmarks_popup({isNewBookmark, popupShowFn, popupEditFn,
                                 shouldAutoClose, popupHideFn, isBookmarkRemoved}) {
-  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:home");
-  try {
-    if (!isNewBookmark) {
-      yield PlacesUtils.bookmarks.insert({
-        parentGuid: PlacesUtils.bookmarks.unfiledGuid,
-        url: "about:home",
-        title: "Home Page"
-      });
-    }
+  yield BrowserTestUtils.withNewTab({gBrowser, url: "about:home"}, function*(browser) {
+    try {
+      if (!isNewBookmark) {
+        yield PlacesUtils.bookmarks.insert({
+          parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+          url: "about:home",
+          title: "Home Page"
+        });
+      }
+
+      is(bookmarkStar.hasAttribute("starred"), !isNewBookmark,
+         "Page should only be starred prior to popupshown if editing bookmark");
+      is(bookmarkPanel.state, "closed", "Panel should be 'closed' to start test");
+      let shownPromise = promisePopupShown(bookmarkPanel);
+      yield popupShowFn(browser);
+      yield shownPromise;
+      is(bookmarkPanel.state, "open", "Panel should be 'open' after shownPromise is resolved");
 
-    is(bookmarkStar.hasAttribute("starred"), !isNewBookmark,
-       "Page should only be starred prior to popupshown if editing bookmark");
-    is(bookmarkPanel.state, "closed", "Panel should be 'closed' to start test");
-    let shownPromise = promisePopupShown(bookmarkPanel);
-    yield popupShowFn(tab.linkedBrowser);
-    yield shownPromise;
-    is(bookmarkPanel.state, "open", "Panel should be 'open' after shownPromise is resolved");
+      if (popupEditFn) {
+        yield popupEditFn();
+      }
+      let bookmarks = [];
+      yield PlacesUtils.bookmarks.fetch({url: "about:home"}, bm => bookmarks.push(bm));
+      is(bookmarks.length, 1, "Only one bookmark should exist");
+      is(bookmarkStar.getAttribute("starred"), "true", "Page is starred");
+      is(bookmarkPanelTitle.value,
+        isNewBookmark ?
+          gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
+          gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle"),
+        "title should match isEditingBookmark state");
 
-    if (popupEditFn) {
-      yield popupEditFn();
+      if (!shouldAutoClose) {
+        yield new Promise(resolve => setTimeout(resolve, 400));
+        is(bookmarkPanel.state, "open", "Panel should still be 'open' for non-autoclose");
+      }
+
+      let hiddenPromise = promisePopupHidden(bookmarkPanel);
+      if (popupHideFn) {
+        yield popupHideFn();
+      }
+      yield hiddenPromise;
+      is(bookmarkStar.hasAttribute("starred"), !isBookmarkRemoved,
+         "Page is starred after closing");
+    } finally {
+      let bookmark = yield PlacesUtils.bookmarks.fetch({url: "about:home"});
+      is(!!bookmark, !isBookmarkRemoved,
+         "bookmark should not be present if a panel action should've removed it");
+      if (bookmark) {
+        yield PlacesUtils.bookmarks.remove(bookmark);
+      }
     }
-    let bookmarks = [];
-    yield PlacesUtils.bookmarks.fetch({url: "about:home"}, bm => bookmarks.push(bm));
-    is(bookmarks.length, 1, "Only one bookmark should exist");
-    is(bookmarkStar.getAttribute("starred"), "true", "Page is starred");
-    is(bookmarkPanelTitle.value,
-      isNewBookmark ?
-        gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
-        gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle"),
-      "title should match isEditingBookmark state");
-
-    if (!shouldAutoClose) {
-      yield new Promise(resolve => setTimeout(resolve, 400));
-      is(bookmarkPanel.state, "open", "Panel should still be 'open' for non-autoclose");
-    }
-
-    let hiddenPromise = promisePopupHidden(bookmarkPanel);
-    if (popupHideFn) {
-      yield popupHideFn();
-    }
-    yield hiddenPromise;
-    is(bookmarkStar.hasAttribute("starred"), !isBookmarkRemoved,
-       "Page is starred after closing");
-  } finally {
-    let bookmark = yield PlacesUtils.bookmarks.fetch({url: "about:home"});
-    is(!!bookmark, !isBookmarkRemoved,
-       "bookmark should not be present if a panel action should've removed it");
-    if (bookmark) {
-      yield PlacesUtils.bookmarks.remove(bookmark);
-    }
-    gBrowser.removeTab(tab);
-  }
+  });
 }
 
 add_task(function* panel_shown_for_new_bookmarks_and_autocloses() {
   yield test_bookmarks_popup({
     isNewBookmark: true,
     popupShowFn() {
       bookmarkStar.click();
     },
     shouldAutoClose: true,
     isBookmarkRemoved: false,
   });
 });
 
-add_task(function* panel_shown_for_once_for_doubleclick_on_new_bookmark_star_and_autocloses() {
+add_task(function* panel_shown_once_for_doubleclick_on_new_bookmark_star_and_autocloses() {
   yield test_bookmarks_popup({
     isNewBookmark: true,
     popupShowFn() {
       EventUtils.synthesizeMouse(bookmarkStar, 10, 10, { clickCount: 2 },
                                  window);
     },
     shouldAutoClose: true,
     isBookmarkRemoved: false,