browser_setting_pane_sub_pane.js (3473B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 describe("setting-pane", () => { 7 let doc, win, testSubPaneButton; 8 9 beforeEach(async function setup() { 10 await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true }); 11 doc = gBrowser.selectedBrowser.contentDocument; 12 win = doc.ownerGlobal; 13 testSubPaneButton = doc.createElement("moz-button"); 14 testSubPaneButton.hidden = true; 15 testSubPaneButton.setAttribute("data-category", "panePrivacy"); 16 testSubPaneButton.textContent = "Go to test pane"; 17 testSubPaneButton.addEventListener("click", () => 18 win.gotoPref("paneTestSubPane") 19 ); 20 let privacyHeading = doc.getElementById("browserPrivacyCategory"); 21 privacyHeading.insertAdjacentElement("afterend", testSubPaneButton); 22 win.Preferences.addSetting({ 23 id: "testSetting", 24 get: () => true, 25 }); 26 win.SettingGroupManager.registerGroup("testGroup", { 27 l10nId: "downloads-header-2", 28 headingLevel: 2, 29 items: [ 30 { 31 id: "testSetting", 32 controlAttrs: { 33 label: "Test setting", 34 }, 35 }, 36 ], 37 }); 38 win.SettingPaneManager.registerPane("testSubPane", { 39 parent: "privacy", 40 l10nId: "containers-section-header", 41 groupIds: ["testGroup"], 42 }); 43 }); 44 45 afterEach(() => BrowserTestUtils.removeTab(gBrowser.selectedTab)); 46 47 it("can load/go back sub-pane", async () => { 48 let pane = doc.querySelector( 49 'setting-pane[data-category="paneTestSubPane"]' 50 ); 51 is_element_hidden(pane, "Sub pane is initially hidden"); 52 53 // Load the privacy pane 54 let paneLoaded = waitForPaneChange("privacy"); 55 EventUtils.synthesizeMouseAtCenter( 56 doc.getElementById("category-privacy"), 57 {}, 58 win 59 ); 60 await paneLoaded; 61 62 // Load the sub pane 63 paneLoaded = waitForPaneChange("testSubPane"); 64 EventUtils.synthesizeMouseAtCenter(testSubPaneButton, {}, win); 65 await paneLoaded; 66 67 is_element_visible(pane, "Page header is visible"); 68 ok(pane, "There is a setting pane"); 69 await pane.updateComplete; 70 let pageHeader = pane.pageHeaderEl; 71 ok(pageHeader, "There is a page header"); 72 is( 73 pageHeader.dataset.l10nId, 74 "containers-section-header", 75 "Page header has its l10nId" 76 ); 77 let heading = pageHeader.headingEl; 78 ok(heading, "There is a heading in the header"); 79 ok(heading.innerText, "The heading has text"); 80 is(heading.innerText, pageHeader.heading, "The text is localized"); 81 let backButton = pageHeader.backButtonEl; 82 ok(backButton, "There is a back button"); 83 84 /** 85 * Must dispatch paneshown event manually to have 86 * focus fire after contents on the page have loaded 87 * to replicate what happens in non-test environment. 88 */ 89 doc.dispatchEvent( 90 new CustomEvent("paneshown", { 91 bubbles: true, 92 cancelable: true, 93 detail: { 94 category: "paneTestSubPane", 95 }, 96 }) 97 ); 98 const checkbox = pane.querySelector("moz-checkbox"); 99 is( 100 doc.activeElement, 101 checkbox, 102 "First element on the page (moz-checkbox) should be focused after pane is shown" 103 ); 104 105 // Go back 106 paneLoaded = waitForPaneChange("privacy"); 107 EventUtils.synthesizeMouseAtCenter(backButton, {}, win); 108 await paneLoaded; 109 is_element_hidden(pane, "Sub pane is hidden again"); 110 }); 111 });