Bug 1427701 - Add a test for checking that tags can be added to bookmarks using the star-shaped button. r=Standard8
authorIoana Crisan <icrisan@mozilla.com>
Wed, 10 Jan 2018 12:56:08 +0200
changeset 452927 b69e9e95470a48e8d8ba0235c79e62b55454647f
parent 452885 b62099b50fc7c8a625092a23be6d532fa45ce6a6
child 452928 077e64a34f6b99495167267619e53e60c403e4b1
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1427701
milestone59.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 1427701 - Add a test for checking that tags can be added to bookmarks using the star-shaped button. r=Standard8
browser/components/places/tests/browser/browser.ini
browser/components/places/tests/browser/browser_bookmarkProperties_addTags.js
browser/components/places/tests/browser/head.js
--- a/browser/components/places/tests/browser/browser.ini
+++ b/browser/components/places/tests/browser/browser.ini
@@ -21,16 +21,17 @@ skip-if = (os == 'win' && ccov) # Bug 14
 support-files =
   pageopeningwindow.html
 [browser_bookmarkProperties_addFolderDefaultButton.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmarkProperties_addKeywordForThisSearch.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmarkProperties_addLivemark.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
+[browser_bookmarkProperties_addTags.js]
 [browser_bookmarkProperties_bookmarkAllTabs.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmarkProperties_cancel.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmarkProperties_editTagContainer.js]
 [browser_bookmarkProperties_readOnlyRoot.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmarksProperties.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_addTags.js
@@ -0,0 +1,74 @@
+/**
+ *  Test that tags can be added to bookmarks using the star-shaped button.
+ */
+"use strict";
+
+let bookmarkPanel = document.getElementById("editBookmarkPanel");
+let doneButton = document.getElementById("editBookmarkPanelDoneButton");
+let bookmarkStar = BookmarkingUI.star;
+let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
+let TEST_URL = "about:buildconfig";
+
+async function clickBookmarkStar() {
+  let shownPromise = promisePopupShown(bookmarkPanel);
+  bookmarkStar.click();
+  await shownPromise;
+}
+
+async function hideBookmarksPanel(callback) {
+  let hiddenPromise = promisePopupHidden(bookmarkPanel);
+  callback();
+  await hiddenPromise;
+}
+
+add_task(async function test_add_tags() {
+  let tab = await BrowserTestUtils.openNewForegroundTab({
+    gBrowser,
+    opening: TEST_URL,
+    waitForStateStop: true
+  });
+
+  // The bookmarks panel is expected to auto-close after this step.
+  await hideBookmarksPanel(async () => {
+    // Click the bookmark star to bookmark the page.
+    await clickBookmarkStar();
+    Assert.equal(bookmarkPanelTitle.value, gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle"), "Bookmark title is correct");
+    Assert.equal(bookmarkStar.getAttribute("starred"), "true", "Page is starred");
+  });
+
+  // Click the bookmark star again to add tags.
+  await clickBookmarkStar();
+  Assert.equal(bookmarkPanelTitle.value, gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle"), "Bookmark title is correct");
+  let promiseNotification = PlacesTestUtils.waitForNotification("onItemAdded", (id, parentId, index, type, itemUrl) => {
+    if (itemUrl !== null) {
+      return itemUrl.equals(Services.io.newURI(TEST_URL));
+    }
+    return true;
+  });
+  await fillBookmarkTextField("editBMPanel_tagsField", "tag1", window);
+  await promiseNotification;
+  let bookmarks = [];
+  await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm => bookmarks.push(bm));
+  Assert.equal(PlacesUtils.tagging.getTagsForURI(Services.io.newURI(TEST_URL)).length, 1, "Found the right number of tags");
+  Assert.deepEqual(PlacesUtils.tagging.getTagsForURI(Services.io.newURI(TEST_URL)), ["tag1"]);
+  await hideBookmarksPanel(() => doneButton.click());
+
+  // Click the bookmark star again, add more tags.
+  await clickBookmarkStar();
+  promiseNotification = PlacesTestUtils.waitForNotification("onItemChanged", (id, property) => property == "tags");
+  await fillBookmarkTextField("editBMPanel_tagsField", "tag1, tag2, tag3", window);
+  await promiseNotification;
+  await hideBookmarksPanel(() => doneButton.click());
+
+  bookmarks = [];
+  await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm => bookmarks.push(bm));
+  Assert.equal(bookmarks.length, 1, "Only one bookmark should exist");
+  Assert.equal(PlacesUtils.tagging.getTagsForURI(Services.io.newURI(TEST_URL)).length, 3, "Found the right number of tags");
+  Assert.deepEqual(PlacesUtils.tagging.getTagsForURI(Services.io.newURI(TEST_URL)), ["tag1", "tag2", "tag3"]);
+
+  // Cleanup.
+  registerCleanupFunction(async function() {
+    await PlacesUtils.bookmarks.eraseEverything();
+    await BrowserTestUtils.removeTab(tab);
+  });
+});
--- a/browser/components/places/tests/browser/head.js
+++ b/browser/components/places/tests/browser/head.js
@@ -440,8 +440,34 @@ function promisePlacesInitComplete() {
 
   let placesInitCompleteObserved = TestUtils.topicObserved("places-browser-init-complete");
 
   gBrowserGlue.observe(null, "browser-glue-test",
     "places-browser-init-complete");
 
   return placesInitCompleteObserved;
 }
+
+// Function copied from browser/base/content/test/general/head.js.
+function promisePopupShown(popup) {
+  return new Promise(resolve => {
+    if (popup.state == "open") {
+      resolve();
+    } else {
+      let onPopupShown = event => {
+        popup.removeEventListener("popupshown", onPopupShown);
+        resolve();
+      };
+      popup.addEventListener("popupshown", onPopupShown);
+    }
+  });
+}
+
+// Function copied from browser/base/content/test/general/head.js.
+function promisePopupHidden(popup) {
+  return new Promise(resolve => {
+    let onPopupHidden = event => {
+      popup.removeEventListener("popuphidden", onPopupHidden);
+      resolve();
+    };
+    popup.addEventListener("popuphidden", onPopupHidden);
+  });
+}