test_taskbartab_restore.py (4086B)
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 import os 7 import sys 8 9 from marionette_driver import Wait 10 11 # add this directory to the path 12 sys.path.append(os.path.dirname(__file__)) 13 from session_store_test_case import SessionStoreTestCase 14 15 16 def inline(title): 17 return f"data:text/html;charset=utf-8,<html><head><title>{title}</title></head><body></body></html>" 18 19 20 class TestManualRestoreWithTaskbarTabs(SessionStoreTestCase): 21 def setUp(self): 22 super().setUp( 23 startup_page=1, 24 include_private=False, 25 restore_on_demand=False, 26 taskbartabs_enable=True, 27 test_windows=set([ 28 # Window 1 29 ( 30 inline("lorem ipsom"), 31 inline("dolor"), 32 ), 33 ]), 34 ) 35 36 """ 37 Close all regular windows except for a taskbar tab window. The 38 session should be over at this point. Opening another regular Firefox 39 window will open "restore previous session" in the hamburger menu. 40 And clicking it will restore the correct session. 41 """ 42 43 def test_restore_without_closing_taskbartab(self): 44 self.wait_for_windows( 45 self.all_windows, "Not all requested windows have been opened" 46 ) 47 48 # See session_store_test_case.py 49 self.setup_taskbartab_restore_scenario() 50 51 # Verify that "restore previous session" button 52 # is visible in the hamburger menu 53 self.assertEqual( 54 self.marionette.execute_script( 55 """ 56 let newWindow = BrowserWindowTracker.getTopWindow({ allowTaskbarTabs: false }); 57 return PanelMultiView.getViewNode( 58 newWindow.document, 59 "appMenu-restoreSession" 60 ).hasAttribute("disabled"); 61 """ 62 ), 63 False, 64 "The restore last session button should be visible", 65 ) 66 67 # Simulate clicking "restore previous session" 68 self.marionette.execute_script( 69 """ 70 SessionStore.restoreLastSession(); 71 """ 72 ) 73 74 # Wait for the restore to be completed, 75 # meaning the window we opened should have 76 # two tabs again. 77 Wait(self.marionette).until( 78 lambda mn: mn.execute_script( 79 """ 80 let newWindow = BrowserWindowTracker.getTopWindow({ allowTaskbarTabs: false }); 81 return newWindow.gBrowser.tabs.length; 82 """ 83 ) 84 == 2 85 ) 86 87 88 class TestAutoRestoreWithTaskbarTabs(SessionStoreTestCase): 89 def setUp(self): 90 super().setUp( 91 startup_page=3, 92 include_private=False, 93 restore_on_demand=False, 94 taskbartabs_enable=True, 95 test_windows=set([ 96 # Window 1 97 ( 98 inline("lorem ipsom"), 99 inline("dolor"), 100 ), 101 ]), 102 ) 103 104 """ 105 Close all regular windows except for a taskbar tab window. The 106 session should be over at this point. Opening another regular Firefox 107 window will open automatically restore the correct session 108 """ 109 110 def test_restore_without_closing_taskbartab(self): 111 self.wait_for_windows( 112 self.all_windows, "Not all requested windows have been opened" 113 ) 114 115 self.setup_taskbartab_restore_scenario() 116 117 # Wait for the auto restore to be completed, 118 # meaning the window we opened should have 119 # the original two tabs plus the home page tab. 120 Wait(self.marionette).until( 121 lambda mn: mn.execute_script( 122 """ 123 let newWindow = BrowserWindowTracker.getTopWindow({ allowTaskbarTabs: false }); 124 return newWindow.gBrowser.tabs.length; 125 """ 126 ) 127 == 3 128 )