Bug 1255985 - Switch from using BrowserTestUtils.openNewForegroundTab to .withNewTab to make sure that we yield until the tab is fully closed. r=Paolo, a=test-only
authorJared Wein <jwein@mozilla.com>
Thu, 26 Jan 2017 16:56:50 -0500
changeset 375705 d79fad3792f12458dcba6f3f3516ecbdd184b887
parent 375704 d5487c1011247bd8a6279a18bffb276a426ae494
child 375706 5cac4397780c0a46bc3862b042b0cb3d8783ccf3
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersPaolo, test-only
bugs1255985
milestone53.0a2
Bug 1255985 - Switch from using BrowserTestUtils.openNewForegroundTab to .withNewTab to make sure that we yield until the tab is fully closed. r=Paolo, a=test-only 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,