tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_taskbartab_sessionstate.py (2878B)


      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 # add this directory to the path
     10 sys.path.append(os.path.dirname(__file__))
     11 from session_store_test_case import SessionStoreTestCase
     12 
     13 
     14 def inline(title):
     15    return f"data:text/html;charset=utf-8,<html><head><title>{title}</title></head><body></body></html>"
     16 
     17 
     18 class TestTaskbarTabSessionState(SessionStoreTestCase):
     19    def setUp(self):
     20        super().setUp(
     21            startup_page=1,
     22            include_private=False,
     23            restore_on_demand=False,
     24            taskbartabs_enable=True,
     25            test_windows=set([
     26                # Window 1
     27                (
     28                    inline("lorem ipsom"),
     29                    inline("dolor"),
     30                ),
     31            ]),
     32        )
     33 
     34    """
     35    Close all Firefox windows with the web app being closed last,
     36    the session store state should include the last regular window
     37    that's closed, but not the web app
     38    """
     39 
     40    def test_taskbartab_session_state(self):
     41        self.wait_for_windows(
     42            self.all_windows, "Not all requested windows have been opened"
     43        )
     44 
     45        self.marionette.enforce_gecko_prefs({"browser.taskbarTabs.enabled": True})
     46 
     47        self.open_taskbartab_window()
     48 
     49        # Close the original regular Firefox window
     50        taskbar_tab_window_handle = self.marionette.close_chrome_window()[0]
     51        self.marionette.switch_to_window(taskbar_tab_window_handle)
     52 
     53        self.marionette.set_context("content")
     54        dummy_html = self.marionette.absolute_url("empty.html")
     55        self.marionette.navigate(dummy_html)
     56        self.marionette.set_context("chrome")
     57 
     58        self.marionette.quit()
     59        self.marionette.start_session()
     60        self.marionette.set_context("chrome")
     61 
     62        # check for the session store state, it should have only two tabs and one window
     63        self.assertEqual(
     64            self.marionette.execute_script(
     65                """
     66                const { _LastSession } = ChromeUtils.importESModule(
     67                    "resource:///modules/sessionstore/SessionStore.sys.mjs"
     68                    );
     69                return _LastSession.getState().windows.length
     70            """
     71            ),
     72            1,
     73            "One window should be in the session state",
     74        )
     75 
     76        self.assertEqual(
     77            self.marionette.execute_script(
     78                """
     79                const { _LastSession } = ChromeUtils.importESModule(
     80                    "resource:///modules/sessionstore/SessionStore.sys.mjs"
     81                    );
     82                return _LastSession.getState().windows[0].tabs.length
     83            """
     84            ),
     85            2,
     86            "Two tabs should be in the session state",
     87        )