Exemplo n.º 1
0
    def test_nonce(self):

        # make a profile with one preference
        path = tempfile.mktemp()
        self.addCleanup(mozfile.remove, path)
        profile = Profile(path, preferences={'foo': 'bar'}, restore=False)
        user_js = os.path.join(profile.profile, 'user.js')
        self.assertTrue(os.path.exists(user_js))

        # ensure the preference is correct
        prefs = Preferences.read_prefs(user_js)
        self.assertEqual(dict(prefs), {'foo': 'bar'})

        del profile

        # augment the profile with a second preference
        profile = Profile(path, preferences={'fleem': 'baz'}, restore=True)
        prefs = Preferences.read_prefs(user_js)
        self.assertEqual(dict(prefs), {'foo': 'bar', 'fleem': 'baz'})

        # cleanup the profile;
        # this should remove the new preferences but not the old
        profile.cleanup()
        prefs = Preferences.read_prefs(user_js)
        self.assertEqual(dict(prefs), {'foo': 'bar'})
Exemplo n.º 2
0
 def setUp(self):
     # make a profile with one preference
     path = tempfile.mktemp()
     self.addCleanup(mozfile.remove, path)
     self.profile = Profile(path, preferences={'foo': 'bar'}, restore=False)
     user_js = os.path.join(self.profile.profile, 'user.js')
     self.assertTrue(os.path.exists(user_js))
Exemplo n.º 3
0
    def test_reset_should_remove_added_prefs(self):
        """Check that when we call reset the items we expect are updated"""

        profile = Profile()
        prefs_file = os.path.join(profile.profile, 'user.js')

        # we shouldn't have any initial preferences
        initial_prefs = Preferences.read_prefs(prefs_file)
        self.assertFalse(initial_prefs)
        initial_prefs = file(prefs_file).read().strip()
        self.assertFalse(initial_prefs)

        # add some preferences
        prefs1 = [("mr.t.quotes", "i aint getting on no plane!")]
        profile.set_preferences(prefs1)
        self.assertEqual(prefs1, Preferences.read_prefs(prefs_file))
        lines = file(prefs_file).read().strip().splitlines()
        self.assertTrue(
            bool([
                line for line in lines
                if line.startswith('#MozRunner Prefs Start')
            ]))
        self.assertTrue(
            bool([
                line for line in lines
                if line.startswith('#MozRunner Prefs End')
            ]))

        profile.reset()
        self.assertNotEqual(
            prefs1,
            Preferences.read_prefs(os.path.join(profile.profile, 'user.js')),
            "I pity the fool who left my pref")
Exemplo n.º 4
0
def profile(tmpdir):
    # make a profile with one preference
    path = tmpdir.mkdtemp().strpath
    profile = Profile(path, preferences={"foo": "bar"}, restore=False)
    user_js = os.path.join(profile.profile, "user.js")
    assert os.path.exists(user_js)
    return profile
Exemplo n.º 5
0
    def test_magic_markers(self):
        """ensure our magic markers are working"""

        profile = Profile()
        prefs_file = os.path.join(profile.profile, 'user.js')

        # we shouldn't have any initial preferences
        initial_prefs = Preferences.read_prefs(prefs_file)
        self.assertFalse(initial_prefs)
        initial_prefs = file(prefs_file).read().strip()
        self.assertFalse(initial_prefs)

        # add some preferences
        prefs1 = [("browser.startup.homepage", "http://planet.mozilla.org/"),
                  ("zoom.minPercent", 30)]
        profile.set_preferences(prefs1)
        self.assertEqual(prefs1, Preferences.read_prefs(prefs_file))
        lines = file(prefs_file).read().strip().splitlines()
        self.assertTrue(
            bool([
                line for line in lines
                if line.startswith('#MozRunner Prefs Start')
            ]))
        self.assertTrue(
            bool([
                line for line in lines
                if line.startswith('#MozRunner Prefs End')
            ]))

        # add some more preferences
        prefs2 = [("zoom.maxPercent", 300), ("webgl.verbose", 'false')]
        profile.set_preferences(prefs2)
        self.assertEqual(prefs1 + prefs2, Preferences.read_prefs(prefs_file))
        lines = file(prefs_file).read().strip().splitlines()
        self.assertTrue(
            len([
                line for line in lines
                if line.startswith('#MozRunner Prefs Start')
            ]) == 2)
        self.assertTrue(
            len([
                line for line in lines
                if line.startswith('#MozRunner Prefs End')
            ]) == 2)

        # now clean it up
        profile.clean_preferences()
        final_prefs = Preferences.read_prefs(prefs_file)
        self.assertFalse(final_prefs)
        lines = file(prefs_file).read().strip().splitlines()
        self.assertTrue('#MozRunner Prefs Start' not in lines)
        self.assertTrue('#MozRunner Prefs End' not in lines)
Exemplo n.º 6
0
def test_nonce(tmpdir):
    # make a profile with one preference
    path = tmpdir.strpath
    profile = Profile(path, preferences={"foo": "bar"}, restore=False)
    user_js = os.path.join(profile.profile, "user.js")
    assert os.path.exists(user_js)

    # ensure the preference is correct
    prefs = Preferences.read_prefs(user_js)
    assert dict(prefs) == {"foo": "bar"}

    del profile

    # augment the profile with a second preference
    profile = Profile(path, preferences={"fleem": "baz"}, restore=True)
    prefs = Preferences.read_prefs(user_js)
    assert dict(prefs) == {"foo": "bar", "fleem": "baz"}

    # cleanup the profile;
    # this should remove the new preferences but not the old
    profile.cleanup()
    prefs = Preferences.read_prefs(user_js)
    assert dict(prefs) == {"foo": "bar"}
Exemplo n.º 7
0
def create_profile(addons, pref_categories, profile=None):
    from mozprofile.prefs import Preferences
    from mozprofile.profile import Profile
    from subprocess import check_output

    prefs = Preferences()
    for category in pref_categories:
        prefs.add_file("{}:{}".format(C.MOZRUNNER_PREFS_INI, category))

    return Profile(
        addons=addons,
        preferences=prefs(),
        restore=False,
    )
Exemplo n.º 8
0
def test_preexisting_preferences():
    """ensure you don't clobber preexisting preferences"""

    # make a pretend profile
    tempdir = tempfile.mkdtemp()

    try:
        # make a user.js
        contents = """
user_pref("webgl.enabled_for_all_sites", true);
user_pref("webgl.force-enabled", true);
"""
        user_js = os.path.join(tempdir, "user.js")
        f = open(user_js, "w")
        f.write(contents)
        f.close()

        # make sure you can read it
        prefs = Preferences.read_prefs(user_js)
        original_prefs = [
            ("webgl.enabled_for_all_sites", True),
            ("webgl.force-enabled", True),
        ]
        assert prefs == original_prefs

        # now read this as a profile
        profile = Profile(
            tempdir, preferences={"browser.download.dir": "/home/jhammel"})

        # make sure the new pref is now there
        new_prefs = original_prefs[:] + [
            ("browser.download.dir", "/home/jhammel")
        ]
        prefs = Preferences.read_prefs(user_js)
        assert prefs == new_prefs

        # clean up the added preferences
        profile.cleanup()
        del profile

        # make sure you have the original preferences
        prefs = Preferences.read_prefs(user_js)
        assert prefs == original_prefs
    finally:
        shutil.rmtree(tempdir)
Exemplo n.º 9
0
def test_magic_markers():
    """ensure our magic markers are working"""

    profile = Profile()
    prefs_file = os.path.join(profile.profile, "user.js")

    # we shouldn't have any initial preferences
    initial_prefs = Preferences.read_prefs(prefs_file)
    assert not initial_prefs
    initial_prefs = open(prefs_file).read().strip()
    assert not initial_prefs

    # add some preferences
    prefs1 = [
        ("browser.startup.homepage", "http://planet.mozilla.org/"),
        ("zoom.minPercent", 30),
    ]
    profile.set_preferences(prefs1)
    assert prefs1 == Preferences.read_prefs(prefs_file)
    lines = open(prefs_file).read().strip().splitlines()
    assert bool(
        [line for line in lines if line.startswith("#MozRunner Prefs Start")])
    assert bool(
        [line for line in lines if line.startswith("#MozRunner Prefs End")])

    # add some more preferences
    prefs2 = [("zoom.maxPercent", 300), ("webgl.verbose", "false")]
    profile.set_preferences(prefs2)
    assert prefs1 + prefs2 == Preferences.read_prefs(prefs_file)
    lines = open(prefs_file).read().strip().splitlines()
    assert (len([
        line for line in lines if line.startswith("#MozRunner Prefs Start")
    ]) == 2)
    assert len([
        line for line in lines if line.startswith("#MozRunner Prefs End")
    ]) == 2

    # now clean it up
    profile.clean_preferences()
    final_prefs = Preferences.read_prefs(prefs_file)
    assert not final_prefs
    lines = open(prefs_file).read().strip().splitlines()
    assert "#MozRunner Prefs Start" not in lines
    assert "#MozRunner Prefs End" not in lines
Exemplo n.º 10
0
    def start_firefox(self):
        env = os.environ.copy()
        env['MOZ_CRASHREPORTER_NO_REPORT'] = '1'

        profile = Profile()
        profile.set_preferences({"marionette.defaultPrefs.enabled": True,
                                 "marionette.defaultPrefs.port": self.marionette_port,
                                 "dom.disable_open_during_load": False,
                                 "dom.max_script_run_time": 0})

        self.firefox_runner = FirefoxRunner(profile,
                                            self.firefox_binary,
                                            cmdargs=["--marionette"],
                                            env=env,
                                            kp_kwargs = {"processOutputLine":[self.on_output]},
                                            process_class=self.process_cls)
        self.logger.debug("Starting Firefox")
        self.firefox_runner.start()
        self.logger.debug("Firefox Started")
Exemplo n.º 11
0
def test_reset_should_keep_user_added_prefs():
    """Check that when we call reset the items we expect are updated"""
    profile = Profile()
    prefs_file = os.path.join(profile.profile, 'user.js')

    # we shouldn't have any initial preferences
    initial_prefs = Preferences.read_prefs(prefs_file)
    assert not initial_prefs
    initial_prefs = open(prefs_file).read().strip()
    assert not initial_prefs

    # add some preferences
    prefs1 = [("mr.t.quotes", "i aint getting on no plane!")]
    profile.set_persistent_preferences(prefs1)
    assert prefs1 == Preferences.read_prefs(prefs_file)
    lines = open(prefs_file).read().strip().splitlines()
    assert any(line.startswith('#MozRunner Prefs Start') for line in lines)
    assert any(line.startswith('#MozRunner Prefs End') for line in lines)

    profile.reset()
    assert prefs1 == Preferences.read_prefs(os.path.join(profile.profile, 'user.js'))