tor-browser

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

test_prefs_enforce.py (2019B)


      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 from marionette_harness import MarionetteTestCase
      6 
      7 
      8 class TestEnforcePreferences(MarionetteTestCase):
      9    def setUp(self):
     10        super(TestEnforcePreferences, self).setUp()
     11        self.marionette.set_context("chrome")
     12 
     13    def tearDown(self):
     14        self.marionette.restart(in_app=False, clean=True)
     15 
     16        super(TestEnforcePreferences, self).tearDown()
     17 
     18    def enforce_prefs(self, prefs=None):
     19        test_prefs = {
     20            "marionette.test.bool": True,
     21            "marionette.test.int": 3,
     22            "marionette.test.string": "testing",
     23        }
     24 
     25        self.marionette.enforce_gecko_prefs(prefs or test_prefs)
     26 
     27    def test_preferences_are_set(self):
     28        self.enforce_prefs()
     29        self.assertTrue(self.marionette.get_pref("marionette.test.bool"))
     30        self.assertEqual(self.marionette.get_pref("marionette.test.string"), "testing")
     31        self.assertEqual(self.marionette.get_pref("marionette.test.int"), 3)
     32 
     33    def test_change_enforced_preference(self):
     34        self.enforce_prefs()
     35        self.assertTrue(self.marionette.get_pref("marionette.test.bool"))
     36 
     37        self.enforce_prefs({"marionette.test.bool": False})
     38        self.assertFalse(self.marionette.get_pref("marionette.test.bool"))
     39 
     40    def test_restart_with_clean_profile_after_enforce_prefs(self):
     41        self.enforce_prefs()
     42        self.assertTrue(self.marionette.get_pref("marionette.test.bool"))
     43 
     44        self.marionette.restart(in_app=False, clean=True)
     45        self.assertEqual(self.marionette.get_pref("marionette.test.bool"), None)
     46 
     47    def test_restart_preserves_requested_capabilities(self):
     48        self.marionette.delete_session()
     49        self.marionette.start_session(capabilities={"test:fooBar": True})
     50 
     51        self.enforce_prefs()
     52        self.assertEqual(self.marionette.session.get("test:fooBar"), True)