Bug 1439832 - Add a test for checking that bookmarks can be opened from Bookmarks Menu - Recently Added Bookmarks section. r=standard8
☠☠ backed out by be56777fb305 ☠ ☠
authorGeorge Echim <gechim@mozilla.com>
Tue, 06 Mar 2018 17:03:50 +0200
changeset 417725 6bc652b4e61a3abf09dc2a150236e8eaaf8ec0c4
parent 417724 f0ea53cd87260f0e929ed0f8401a76b9a757b265
child 417726 4092dcafedd0ab03224d824617b5439f67559241
push id33978
push userdluca@mozilla.com
push dateThu, 10 May 2018 21:54:47 +0000
treeherdermozilla-central@d302824da0ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs1439832
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 1439832 - Add a test for checking that bookmarks can be opened from Bookmarks Menu - Recently Added Bookmarks section. r=standard8 MozReview-Commit-ID: 69rAIfo2w06
browser/components/places/tests/browser/browser.ini
browser/components/places/tests/browser/browser_toolbar_library_open_recent.js
--- a/browser/components/places/tests/browser/browser.ini
+++ b/browser/components/places/tests/browser/browser.ini
@@ -73,16 +73,17 @@ subsuite = clipboard
 subsuite = clipboard
 [browser_sidebar_open_bookmarks.js]
 [browser_sidebarpanels_click.js]
 skip-if = (os == "mac" && debug) # Bug 1423667
 [browser_sort_in_library.js]
 [browser_stayopenmenu.js]
 skip-if = os == "mac" && debug # bug 1400323
 [browser_toolbar_drop_text.js]
+[browser_toolbar_library_open_recent.js]
 [browser_toolbar_overflow.js]
 [browser_toolbarbutton_menu_context.js]
 [browser_views_iconsupdate.js]
 [browser_bug485100-change-case-loses-tag.js]
 [browser_editBookmark_tags_liveUpdate.js]
 [browser_bug427633_no_newfolder_if_noip.js]
 [browser_editBookmark_keywords.js]
 [browser_bug631374_tags_selector_scroll.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/places/tests/browser/browser_toolbar_library_open_recent.js
@@ -0,0 +1,113 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests that recently added bookmarks can be opened.
+ */
+
+const BASE_URL = "http://example.org/browser/browser/components/places/tests/browser/";
+const bookmarkItems = [{
+  url: `${BASE_URL}bookmark_dummy_1.html`,
+  title: "Custom Title 1"
+}, {
+  url: `${BASE_URL}bookmark_dummy_2.html`,
+  title: "Custom Title 2",
+}];
+let openedTabs = [];
+
+async function openBookmarksPanelInLibraryToolbarButton() {
+  let libraryBtn = document.getElementById("library-button");
+  let libView = document.getElementById("appMenu-libraryView");
+  let viewShownPromise = BrowserTestUtils.waitForEvent(libView, "ViewShown");
+  libraryBtn.click();
+  await viewShownPromise;
+
+  let bookmarksButton;
+  await BrowserTestUtils.waitForCondition(() => {
+    bookmarksButton = document.getElementById("appMenu-library-bookmarks-button");
+    return bookmarksButton;
+  }, "Should have the library bookmarks button");
+
+  let BookmarksView = document.getElementById("PanelUI-bookmarks");
+  let viewRecentPromise = BrowserTestUtils.waitForEvent(BookmarksView, "ViewShown");
+  bookmarksButton.click();
+  await viewRecentPromise;
+}
+
+async function openBookmarkedItemInNewTab(itemFromMenu) {
+  let placesContext = document.getElementById("placesContext");
+  let openContextMenuPromise = BrowserTestUtils.waitForEvent(placesContext, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(itemFromMenu, {
+    button: 2,
+    type: "contextmenu"
+  });
+  await openContextMenuPromise;
+  info("Opened context menu");
+
+  let tabCreatedPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
+
+  let openInNewTabOption = document.getElementById("placesContext_open:newtab");
+  EventUtils.synthesizeMouseAtCenter(openInNewTabOption, {
+    button: 0
+  });
+  info("Click open in new tab");
+
+  let lastOpenedTab = await tabCreatedPromise;
+  Assert.equal(lastOpenedTab.linkedBrowser.currentURI.spec, itemFromMenu._placesNode.uri, "Should have opened the correct URI");
+  openedTabs.push(lastOpenedTab);
+}
+
+async function closeTabs() {
+  for (var i = 0; i < openedTabs.length; i++) {
+    await gBrowser.removeTab(openedTabs[i]);
+  }
+  Assert.equal(gBrowser.tabs.length, 1, "Should close all opened tabs");
+}
+
+async function getRecentlyBookmarkedItems() {
+  let historyMenu = document.getElementById("panelMenu_bookmarksMenu");
+  let items = historyMenu.querySelectorAll("toolbarbutton");
+  Assert.ok(items, "Recently bookmarked items should exists");
+
+  await BrowserTestUtils.waitForCondition(() => items[0].attributes !== "undefined", "Custom bookmark exists");
+
+  if (items) {
+    Assert.equal(items[0]._placesNode.uri, bookmarkItems[1].url, "Should match the expected url");
+    Assert.equal(items[0].getAttribute("label"), bookmarkItems[1].title, "Should be the expected title");
+    Assert.equal(items[1]._placesNode.uri, bookmarkItems[0].url, "Should match the expected url");
+    Assert.equal(items[1].getAttribute("label"), bookmarkItems[0].title, "Should be the expected title");
+  }
+  return Array.from(items).slice(0, 2);
+}
+
+add_task(async function setup() {
+  let libraryButton = CustomizableUI.getPlacementOfWidget("library-button");
+  if (!libraryButton) {
+    CustomizableUI.addWidgetToArea("library-button", CustomizableUI.AREA_NAVBAR);
+  }
+  await PlacesUtils.bookmarks.insertTree({
+    guid: PlacesUtils.bookmarks.menuGuid,
+    children: bookmarkItems,
+  });
+
+  registerCleanupFunction(async () => {
+    await PlacesUtils.bookmarks.eraseEverything();
+    CustomizableUI.reset();
+  });
+});
+
+add_task(async function test_recently_added() {
+  await openBookmarksPanelInLibraryToolbarButton();
+
+  let historyItems = await getRecentlyBookmarkedItems();
+
+  for (let item of historyItems) {
+    await openBookmarkedItemInNewTab(item);
+  }
+
+  registerCleanupFunction(async () => {
+    await closeTabs();
+  });
+});