Bug 1899500 - Implement explicit resource management in Baseline compiler. r=arai
[gecko.git] / browser / components / preferences / tests / browser_homepages_use_bookmark.js
blob572783481da56d22d03c83efc6a1a27959e1f1c1
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 const TEST_URL1 = "http://example.com/1";
7 const TEST_URL2 = "http://example.com/2";
9 add_setup(async function () {
10   let oldHomepagePref = Services.prefs.getCharPref("browser.startup.homepage");
12   await openPreferencesViaOpenPreferencesAPI("paneHome", { leaveOpen: true });
14   Assert.equal(
15     gBrowser.currentURI.spec,
16     "about:preferences#home",
17     "#home should be in the URI for about:preferences"
18   );
20   registerCleanupFunction(async () => {
21     Services.prefs.setCharPref("browser.startup.homepage", oldHomepagePref);
22     BrowserTestUtils.removeTab(gBrowser.selectedTab);
23     await PlacesUtils.bookmarks.eraseEverything();
24   });
25 });
27 add_task(async function testSetHomepageFromBookmark() {
28   let bm = await PlacesUtils.bookmarks.insert({
29     parentGuid: PlacesUtils.bookmarks.menuGuid,
30     title: "TestHomepage",
31     url: TEST_URL1,
32   });
34   let doc = gBrowser.contentDocument;
35   // Select the custom URLs option.
36   doc.getElementById("homeMode").value = 2;
38   let promiseSubDialogLoaded = promiseLoadSubDialog(
39     "chrome://browser/content/preferences/dialogs/selectBookmark.xhtml"
40   );
41   doc.getElementById("useBookmarkBtn").click();
43   let dialog = await promiseSubDialogLoaded;
44   dialog.document.getElementById("bookmarks").selectItems([bm.guid]);
45   dialog.document
46     .getElementById("selectBookmarkDialog")
47     .getButton("accept")
48     .click();
50   await TestUtils.waitForCondition(() => HomePage.get() == TEST_URL1);
52   Assert.equal(
53     HomePage.get(),
54     TEST_URL1,
55     "Should have set the homepage to the same as the bookmark."
56   );
57 });
59 add_task(async function testSetHomepageFromTopLevelFolder() {
60   // Insert a second item into the menu folder
61   await PlacesUtils.bookmarks.insert({
62     parentGuid: PlacesUtils.bookmarks.menuGuid,
63     title: "TestHomepage",
64     url: TEST_URL2,
65   });
67   let doc = gBrowser.contentDocument;
68   // Select the custom URLs option.
69   doc.getElementById("homeMode").value = 2;
71   let promiseSubDialogLoaded = promiseLoadSubDialog(
72     "chrome://browser/content/preferences/dialogs/selectBookmark.xhtml"
73   );
74   doc.getElementById("useBookmarkBtn").click();
76   let dialog = await promiseSubDialogLoaded;
77   dialog.document
78     .getElementById("bookmarks")
79     .selectItems([PlacesUtils.bookmarks.menuGuid]);
80   dialog.document
81     .getElementById("selectBookmarkDialog")
82     .getButton("accept")
83     .click();
85   await TestUtils.waitForCondition(
86     () => HomePage.get() == `${TEST_URL1}|${TEST_URL2}`
87   );
89   Assert.equal(
90     HomePage.get(),
91     `${TEST_URL1}|${TEST_URL2}`,
92     "Should have set the homepage to the same as the bookmark."
93   );
94 });