Bug 1437476 - Add a test for checking that a bookmark can be loaded inside the Bookmarks sidebar. r=Standard8 draft
authorPaul Silaghi <psilaghi@mozilla.com>
Wed, 28 Feb 2018 15:59:57 +0000
changeset 761045 52f981f535a8
parent 761044 91371355dddc
push id100832
push userbmo:standard8@mozilla.com
push dateWed, 28 Feb 2018 16:01:28 +0000
reviewersStandard8
bugs1437476
milestone60.0a1
Bug 1437476 - Add a test for checking that a bookmark can be loaded inside the Bookmarks sidebar. r=Standard8 MozReview-Commit-ID: 2UfcC1tF6Eh
browser/components/places/tests/browser/browser.ini
browser/components/places/tests/browser/browser_bookmark_load_in_sidebar.js
--- a/browser/components/places/tests/browser/browser.ini
+++ b/browser/components/places/tests/browser/browser.ini
@@ -14,16 +14,18 @@ support-files =
 [browser_0_library_left_pane_migration.js]
 [browser_addBookmarkForFrame.js]
 [browser_bookmark_add_tags.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmark_change_location.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmark_folder_moveability.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
+[browser_bookmark_load_in_sidebar.js]
+skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmark_private_window.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmark_remove_tags.js]
 skip-if = (os == 'win' && ccov) # Bug 1423667
 [browser_bookmarklet_windowOpen.js]
 support-files =
   bookmarklet_windowOpen_dummy.html
 [browser_bookmarks_change_title.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/places/tests/browser/browser_bookmark_load_in_sidebar.js
@@ -0,0 +1,72 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * Test that a bookmark can be loaded inside the Bookmarks sidebar.
+ */
+"use strict";
+
+const TEST_URL = "about:buildconfig";
+
+// Cleanup.
+registerCleanupFunction(async () => {
+  await PlacesUtils.bookmarks.eraseEverything();
+});
+
+add_task(async function test_load_in_sidebar() {
+  let bm = await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+    url: TEST_URL,
+    title: TEST_URL,
+  });
+
+  await withSidebarTree("bookmarks", async function(tree) {
+    tree.selectItems([bm.guid]);
+    await withBookmarksDialog(
+      false,
+      function openPropertiesDialog() {
+        tree.controller.doCommand("placesCmd_show:info");
+      },
+
+      // Check the "Load this bookmark in the sidebar" option.
+      async function test(dialogWin) {
+        let loadInSidebar = dialogWin.document.getElementById("editBMPanel_loadInSidebarCheckbox");
+        let promiseCheckboxChanged = PlacesTestUtils.waitForNotification(
+          "onItemChanged",
+          (id, parentId, checked) => checked === true
+        );
+
+        loadInSidebar.click();
+
+        EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
+        await promiseCheckboxChanged;
+      }
+    );
+
+    let sidebar = document.getElementById("sidebar");
+
+    let sidebarLoadedPromise = new Promise(resolve => {
+      sidebar.addEventListener("load", function() {
+        executeSoon(resolve);
+      }, {capture: true, once: true});
+    });
+
+    // Select and open the bookmark in the sidebar.
+    tree.selectItems([bm.guid]);
+    tree.controller.doCommand("placesCmd_open");
+
+    await sidebarLoadedPromise;
+
+    let sidebarTitle = document.getElementById("sidebar-title");
+    let sidebarBrowser = sidebar.contentDocument.getElementById("web-panels-browser");
+
+    await BrowserTestUtils.browserLoaded(sidebarBrowser, false, TEST_URL);
+
+    let h1Elem = sidebarBrowser.contentDocument.getElementsByTagName("h1")[0];
+
+    // Check that the title and the content of the page are loaded successfully.
+    Assert.equal(sidebarTitle.value, TEST_URL, "The sidebar title is successfully loaded.");
+    Assert.equal(h1Elem.textContent, TEST_URL, "The sidebar content is successfully loaded.");
+  });
+});