browser_ipprotection_panel.js (3816B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const lazy = {}; 8 9 ChromeUtils.defineESModuleGetters(lazy, { 10 IPProtectionWidget: 11 "moz-src:///browser/components/ipprotection/IPProtection.sys.mjs", 12 IPProtectionPanel: 13 "moz-src:///browser/components/ipprotection/IPProtectionPanel.sys.mjs", 14 }); 15 16 /** 17 * Tests that clicking toolbar button opens the panel, 18 * the panel contains a `<ipprotection-content>` element, 19 * and the browser.ipProtection.panelOpenCount pref is set 20 */ 21 add_task(async function click_toolbar_button() { 22 let button = document.getElementById(lazy.IPProtectionWidget.WIDGET_ID); 23 let panelView = PanelMultiView.getViewNode( 24 document, 25 lazy.IPProtectionWidget.PANEL_ID 26 ); 27 28 let panelOpenCount = Services.prefs.getIntPref( 29 "browser.ipProtection.panelOpenCount", 30 0 31 ); 32 33 let panelShownPromise = waitForPanelEvent(document, "popupshown"); 34 // Open the panel 35 button.click(); 36 await panelShownPromise; 37 38 let panelOpenCountAfter = Services.prefs.getIntPref( 39 "browser.ipProtection.panelOpenCount", 40 0 41 ); 42 Assert.equal( 43 panelOpenCountAfter, 44 panelOpenCount + 1, 45 "panelOpenCount should increase by 1 when the panel is opened" 46 ); 47 48 let component = panelView.querySelector( 49 lazy.IPProtectionPanel.CONTENT_TAGNAME 50 ); 51 Assert.ok( 52 BrowserTestUtils.isVisible(component), 53 "ipprotection-content component should be present" 54 ); 55 56 let header = panelView.querySelector( 57 `#${lazy.IPProtectionPanel.HEADER_AREA_ID}` 58 ); 59 Assert.ok( 60 BrowserTestUtils.isVisible(header), 61 "ipprotection-header component should be present" 62 ); 63 64 // Close the panel 65 let panelHiddenPromise = waitForPanelEvent(document, "popuphidden"); 66 EventUtils.synthesizeKey("KEY_Escape"); 67 await panelHiddenPromise; 68 69 Services.prefs.clearUserPref("browser.ipProtection.panelOpenCount"); 70 }); 71 72 /** 73 * Tests that the panel also loads the custom elements in a new window. 74 */ 75 add_task(async function test_panel_in_new_window() { 76 let newWindow = await BrowserTestUtils.openNewBrowserWindow({ 77 url: "about:newtab", 78 }); 79 newWindow.focus(); 80 81 let button = newWindow.document.getElementById( 82 lazy.IPProtectionWidget.WIDGET_ID 83 ); 84 let panelView = PanelMultiView.getViewNode( 85 newWindow.document, 86 lazy.IPProtectionWidget.PANEL_ID 87 ); 88 89 let panelShownPromise = waitForPanelEvent(newWindow.document, "popupshown"); 90 // Open the panel 91 button.click(); 92 await panelShownPromise; 93 94 let component = panelView.querySelector( 95 lazy.IPProtectionPanel.CONTENT_TAGNAME 96 ); 97 Assert.ok( 98 BrowserTestUtils.isVisible(component), 99 "ipprotection-content component should be present" 100 ); 101 102 let header = panelView.querySelector( 103 `#${lazy.IPProtectionPanel.HEADER_AREA_ID}` 104 ); 105 Assert.ok( 106 BrowserTestUtils.isVisible(header), 107 "ipprotection-header component should be present" 108 ); 109 110 await BrowserTestUtils.closeWindow(newWindow); 111 }); 112 113 /** 114 * Tests that sending IPProtection:Close closes the panel. 115 */ 116 add_task(async function test_close_panel() { 117 let button = document.getElementById(lazy.IPProtectionWidget.WIDGET_ID); 118 let panelView = PanelMultiView.getViewNode( 119 document, 120 lazy.IPProtectionWidget.PANEL_ID 121 ); 122 123 let panelShownPromise = waitForPanelEvent(document, "popupshown"); 124 // Open the panel 125 button.click(); 126 await panelShownPromise; 127 128 // Close the panel 129 let panelHiddenPromise = waitForPanelEvent(document, "popuphidden"); 130 131 panelView.dispatchEvent( 132 new CustomEvent("IPProtection:Close", { bubbles: true }) 133 ); 134 135 await panelHiddenPromise; 136 137 Assert.ok(!BrowserTestUtils.isVisible(panelView), "Panel should be closed"); 138 });