Bug 1534218 - Fix setting the home page based on top-level folders. r=mak
authorMark Banner <standard8@mozilla.com>
Tue, 12 Mar 2019 08:50:01 +0000
changeset 521507 e651386473ed
parent 521506 5dcadd523711
child 521508 caa78f1b6498
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1534218
milestone67.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 1534218 - Fix setting the home page based on top-level folders. r=mak Differential Revision: https://phabricator.services.mozilla.com/D23005
browser/components/preferences/in-content/tests/browser_homepages_use_bookmark.js
browser/components/preferences/selectBookmark.js
--- a/browser/components/preferences/in-content/tests/browser_homepages_use_bookmark.js
+++ b/browser/components/preferences/in-content/tests/browser_homepages_use_bookmark.js
@@ -1,14 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-const TEST_URL = "http://example.com/";
+const TEST_URL1 = "http://example.com/1";
+const TEST_URL2 = "http://example.com/2";
 
 add_task(async function setup() {
   let oldHomepagePref = Services.prefs.getCharPref("browser.startup.homepage");
 
   await openPreferencesViaOpenPreferencesAPI("paneHome", {leaveOpen: true});
 
   Assert.equal(gBrowser.currentURI.spec, "about:preferences#home",
                "#home should be in the URI for about:preferences");
@@ -19,29 +20,50 @@ add_task(async function setup() {
     await PlacesUtils.bookmarks.eraseEverything();
   });
 });
 
 add_task(async function testSetHomepageFromBookmark() {
   let bm = await PlacesUtils.bookmarks.insert({
     parentGuid: PlacesUtils.bookmarks.menuGuid,
     title: "TestHomepage",
-    url: TEST_URL,
+    url: TEST_URL1,
   });
 
   let doc = gBrowser.contentDocument;
-
   // Select the custom URLs option.
   doc.getElementById("homeMode").value = 2;
 
   let promiseSubDialogLoaded = promiseLoadSubDialog("chrome://browser/content/preferences/selectBookmark.xul");
-
   doc.getElementById("useBookmarkBtn").click();
 
   let dialog = await promiseSubDialogLoaded;
-
   dialog.document.getElementById("bookmarks").selectItems([bm.guid]);
-
   dialog.document.documentElement.getButton("accept").click();
 
-  Assert.equal(Services.prefs.getCharPref("browser.startup.homepage"), TEST_URL,
+  Assert.equal(Services.prefs.getCharPref("browser.startup.homepage"), TEST_URL1,
                "Should have set the homepage to the same as the bookmark.");
 });
+
+add_task(async function testSetHomepageFromTopLevelFolder() {
+  // Insert a second item into the menu folder
+  await PlacesUtils.bookmarks.insert({
+    parentGuid: PlacesUtils.bookmarks.menuGuid,
+    title: "TestHomepage",
+    url: TEST_URL2,
+  });
+
+  let doc = gBrowser.contentDocument;
+  // Select the custom URLs option.
+  doc.getElementById("homeMode").value = 2;
+
+  let promiseSubDialogLoaded = promiseLoadSubDialog("chrome://browser/content/preferences/selectBookmark.xul");
+  doc.getElementById("useBookmarkBtn").click();
+
+  let dialog = await promiseSubDialogLoaded;
+  dialog.document.getElementById("bookmarks")
+        .selectItems([PlacesUtils.bookmarks.menuGuid]);
+  dialog.document.documentElement.getButton("accept").click();
+
+  Assert.equal(Services.prefs.getCharPref("browser.startup.homepage"),
+               `${TEST_URL1}|${TEST_URL2}`,
+               "Should have set the homepage to the same as the bookmark.");
+});
--- a/browser/components/preferences/selectBookmark.js
+++ b/browser/components/preferences/selectBookmark.js
@@ -73,17 +73,18 @@ var SelectBookmarkDialog = {
   accept: function SBD_accept() {
     var bookmarks = document.getElementById("bookmarks");
     if (!bookmarks.hasSelection)
       throw new Error("Should not be able to accept dialog if there is no selected URL!");
     var urls = [];
     var names = [];
     var selectedNode = bookmarks.selectedNode;
     if (PlacesUtils.nodeIsFolder(selectedNode)) {
-      var contents = PlacesUtils.getFolderContents(selectedNode.bookmarkGuid).root;
+      let concreteGuid = PlacesUtils.getConcreteItemGuid(selectedNode);
+      var contents = PlacesUtils.getFolderContents(concreteGuid).root;
       var cc = contents.childCount;
       for (var i = 0; i < cc; ++i) {
         var node = contents.getChild(i);
         if (PlacesUtils.nodeIsURI(node)) {
           urls.push(node.uri);
           names.push(node.title);
         }
       }