testing/mozbase/mozprofile/tests/test_nonce.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2
michael@0 3 """
michael@0 4 test nonce in prefs delimeters
michael@0 5 see https://bugzilla.mozilla.org/show_bug.cgi?id=722804
michael@0 6 """
michael@0 7
michael@0 8 import os
michael@0 9 import tempfile
michael@0 10 import time
michael@0 11 import unittest
michael@0 12 from mozprofile.prefs import Preferences
michael@0 13 from mozprofile.profile import Profile
michael@0 14
michael@0 15 class PreferencesNonceTest(unittest.TestCase):
michael@0 16
michael@0 17 def test_nonce(self):
michael@0 18
michael@0 19 # make a profile with one preference
michael@0 20 path = tempfile.mktemp()
michael@0 21 profile = Profile(path,
michael@0 22 preferences={'foo': 'bar'},
michael@0 23 restore=False)
michael@0 24 user_js = os.path.join(profile.profile, 'user.js')
michael@0 25 self.assertTrue(os.path.exists(user_js))
michael@0 26
michael@0 27 # ensure the preference is correct
michael@0 28 prefs = Preferences.read_prefs(user_js)
michael@0 29 self.assertEqual(dict(prefs), {'foo': 'bar'})
michael@0 30
michael@0 31 del profile
michael@0 32
michael@0 33 # augment the profile with a second preference
michael@0 34 profile = Profile(path,
michael@0 35 preferences={'fleem': 'baz'},
michael@0 36 restore=True)
michael@0 37 prefs = Preferences.read_prefs(user_js)
michael@0 38 self.assertEqual(dict(prefs), {'foo': 'bar', 'fleem': 'baz'})
michael@0 39
michael@0 40 # cleanup the profile;
michael@0 41 # this should remove the new preferences but not the old
michael@0 42 profile.cleanup()
michael@0 43 prefs = Preferences.read_prefs(user_js)
michael@0 44 self.assertEqual(dict(prefs), {'foo': 'bar'})
michael@0 45
michael@0 46 if __name__ == '__main__':
michael@0 47 unittest.main()

mercurial