tor-browser

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

test_assert_no_toolbar_changes.py (3562B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 0.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/0.0/.
      4 
      5 from marionette_harness import MarionetteTestCase
      6 
      7 
      8 class TestNoToolbarChanges(MarionetteTestCase):
      9    """
     10    Test that toolbar widgets remain in the same order over several restarts of the browser
     11    """
     12 
     13    have_seen_import_button = False
     14 
     15    def setUp(self):
     16        super().setUp()
     17        self.marionette.set_context("chrome")
     18 
     19    def get_area_widgets(self, area):
     20        return self.marionette.execute_script(
     21            f"return CustomizableUI.getWidgetIdsInArea(CustomizableUI.{area}).map(id => id.includes('spring') ? 'spring' : id)"
     22        )
     23 
     24    def get_area_default_placements(self, area):
     25        return self.marionette.execute_script(
     26            f"return CustomizableUI.getDefaultPlacementsForArea(CustomizableUI.{area})"
     27        )
     28 
     29    def check_toolbar_placements(self):
     30        self.assertEqual(
     31            self.get_area_widgets("AREA_TABSTRIP"),
     32            self.get_area_default_placements("AREA_TABSTRIP"),
     33            msg="AREA_TABSTRIP placements are as expected",
     34        )
     35        navbarPlacements = self.get_area_default_placements("AREA_NAVBAR")
     36        navbarPlacements.append("unified-extensions-button")
     37        self.assertEqual(
     38            self.get_area_widgets("AREA_NAVBAR"),
     39            navbarPlacements,
     40            msg="AREA_NAVBAR placements are as expected",
     41        )
     42        actualBookmarkPlacements = self.get_area_widgets("AREA_BOOKMARKS")
     43        bookmarkPlacements = self.get_area_default_placements("AREA_BOOKMARKS")
     44        # The import button is added lazily on startup, so we can't predict
     45        # whether it'll be here. Turning it off via prefs=[] annotations on the
     46        # test also doesn't work
     47        # (https://bugzilla.mozilla.org/show_bug.cgi?id=1959688).
     48        # So we simply accept placements either with or without the button - but
     49        # if we ever see the button we should keep seeing it.
     50        self.have_seen_import_button = (
     51            self.have_seen_import_button or "import-button" in actualBookmarkPlacements
     52        )
     53        if self.have_seen_import_button:
     54            self.assertEqual(
     55                actualBookmarkPlacements,
     56                ["import-button"] + bookmarkPlacements,
     57                msg="AREA_BOOKMARKS placements are as expected",
     58            )
     59        else:
     60            self.assertEqual(
     61                actualBookmarkPlacements,
     62                bookmarkPlacements,
     63                msg="AREA_BOOKMARKS placements are as expected",
     64            )
     65 
     66        self.assertEqual(
     67            self.get_area_widgets("AREA_ADDONS"),
     68            self.get_area_default_placements("AREA_ADDONS"),
     69            msg="AREA_ADDONS placements are as expected",
     70        )
     71        self.assertEqual(
     72            self.get_area_widgets("AREA_FIXED_OVERFLOW_PANEL"),
     73            self.get_area_default_placements("AREA_FIXED_OVERFLOW_PANEL"),
     74            msg="AREA_FIXED_OVERFLOW_PANEL placements are as expected",
     75        )
     76 
     77    def test_no_toolbar_changes(self):
     78        self.check_toolbar_placements()
     79        self.marionette.restart()
     80        self.check_toolbar_placements()
     81        self.marionette.restart()
     82        self.check_toolbar_placements()
     83        self.marionette.restart()
     84        self.check_toolbar_placements()
     85        self.marionette.restart()
     86        self.check_toolbar_placements()
     87        self.marionette.restart()
     88        self.check_toolbar_placements()