Ejemplo 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'})
Ejemplo n.º 2
0
    def test_nonce(self):

        # make a profile with one preference
        path = tempfile.mktemp()
        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'})
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_preexisting_preferences(self):
        """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 = file(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)]
            self.assertTrue(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)
            self.assertTrue(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)
            self.assertTrue(prefs == original_prefs)
        except:
            shutil.rmtree(tempdir)
            raise
Ejemplo n.º 5
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"}