browser_homepages_use_bookmark.js (2726B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_URL1 = "http://example.com/1"; 7 const TEST_URL2 = "http://example.com/2"; 8 9 add_setup(async function () { 10 let oldHomepagePref = Services.prefs.getCharPref("browser.startup.homepage"); 11 12 await openPreferencesViaOpenPreferencesAPI("paneHome", { leaveOpen: true }); 13 14 Assert.equal( 15 gBrowser.currentURI.spec, 16 "about:preferences#home", 17 "#home should be in the URI for about:preferences" 18 ); 19 20 registerCleanupFunction(async () => { 21 Services.prefs.setCharPref("browser.startup.homepage", oldHomepagePref); 22 BrowserTestUtils.removeTab(gBrowser.selectedTab); 23 await PlacesUtils.bookmarks.eraseEverything(); 24 }); 25 }); 26 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 }); 33 34 let doc = gBrowser.contentDocument; 35 // Select the custom URLs option. 36 doc.getElementById("homeMode").value = 2; 37 38 let promiseSubDialogLoaded = promiseLoadSubDialog( 39 "chrome://browser/content/preferences/dialogs/selectBookmark.xhtml" 40 ); 41 doc.getElementById("useBookmarkBtn").click(); 42 43 let dialog = await promiseSubDialogLoaded; 44 dialog.document.getElementById("bookmarks").selectItems([bm.guid]); 45 dialog.document 46 .getElementById("selectBookmarkDialog") 47 .getButton("accept") 48 .click(); 49 50 await TestUtils.waitForCondition(() => HomePage.get() == TEST_URL1); 51 52 Assert.equal( 53 HomePage.get(), 54 TEST_URL1, 55 "Should have set the homepage to the same as the bookmark." 56 ); 57 }); 58 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 }); 66 67 let doc = gBrowser.contentDocument; 68 // Select the custom URLs option. 69 doc.getElementById("homeMode").value = 2; 70 71 let promiseSubDialogLoaded = promiseLoadSubDialog( 72 "chrome://browser/content/preferences/dialogs/selectBookmark.xhtml" 73 ); 74 doc.getElementById("useBookmarkBtn").click(); 75 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(); 84 85 await TestUtils.waitForCondition( 86 () => HomePage.get() == `${TEST_URL1}|${TEST_URL2}` 87 ); 88 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 });