test_last_used_sidebar_panel.py (3129B)
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 6 from marionette_driver import Wait 7 from marionette_harness import MarionetteTestCase 8 9 10 class TestLastUsedSidebarPanel(MarionetteTestCase): 11 def setUp(self): 12 super().setUp() 13 self.marionette.set_context("chrome") 14 # Add the sidebar button widget at the start of the horizontal tabstrip 15 self.marionette.execute_script( 16 "CustomizableUI.addWidgetToArea('sidebar-button', CustomizableUI.AREA_NAVBAR, 0)" 17 ) 18 19 def tearDown(self): 20 try: 21 # Make sure subsequent tests get a clean profile 22 self.marionette.restart(in_app=False, clean=True) 23 finally: 24 super().tearDown() 25 26 def click_toolbar_button(self): 27 # Click the button to show the launcher 28 self.marionette.execute_script( 29 """ 30 const window = BrowserWindowTracker.getTopWindow(); 31 return window.document.getElementById("sidebar-button").click() 32 """ 33 ) 34 35 def is_sidebar_panel_visible(self): 36 hidden = self.marionette.execute_script( 37 """ 38 const window = BrowserWindowTracker.getTopWindow(); 39 return window.document.getElementById("sidebar-box").hidden; 40 """ 41 ) 42 return not hidden 43 44 def get_current_sidebar_id(self): 45 return self.marionette.execute_script( 46 """ 47 const window = BrowserWindowTracker.getTopWindow(); 48 return window.document.getElementById("sidebar-box").getAttribute("sidebarcommand"); 49 """ 50 ) 51 52 def test_panel_reopened_legacy(self): 53 self.assertFalse( 54 self.is_sidebar_panel_visible(), "The sidebar panel is not initially shown" 55 ) 56 self.assertEqual( 57 self.get_current_sidebar_id(), None, "The sidebar panel has no current ID" 58 ) 59 60 # Open the history sidebar 61 self.marionette.execute_script( 62 """ 63 const window = BrowserWindowTracker.getTopWindow(); 64 return window.SidebarController.toggle("viewHistorySidebar"); 65 """ 66 ) 67 68 Wait(self.marionette).until( 69 lambda _: self.get_current_sidebar_id() == "viewHistorySidebar", 70 message="The history sidebar is visible", 71 ) 72 73 # Click the toolbar button to close the panel 74 self.click_toolbar_button() 75 76 self.assertFalse( 77 self.is_sidebar_panel_visible(), "The sidebar panel is now closed" 78 ) 79 80 self.marionette.restart(clean=False, in_app=True) 81 self.marionette.set_context("chrome") 82 83 self.assertFalse( 84 self.is_sidebar_panel_visible(), "The sidebar panel is initially closed" 85 ) 86 self.click_toolbar_button() 87 88 Wait(self.marionette).until( 89 lambda _: self.get_current_sidebar_id() == "viewHistorySidebar", 90 message="The history sidebar is visible", 91 )