testing/mozbase/mozprofile/tests/test_nonce.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozprofile/tests/test_nonce.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +"""
     1.7 +test nonce in prefs delimeters
     1.8 +see https://bugzilla.mozilla.org/show_bug.cgi?id=722804
     1.9 +"""
    1.10 +
    1.11 +import os
    1.12 +import tempfile
    1.13 +import time
    1.14 +import unittest
    1.15 +from mozprofile.prefs import Preferences
    1.16 +from mozprofile.profile import Profile
    1.17 +
    1.18 +class PreferencesNonceTest(unittest.TestCase):
    1.19 +
    1.20 +    def test_nonce(self):
    1.21 +
    1.22 +        # make a profile with one preference
    1.23 +        path = tempfile.mktemp()
    1.24 +        profile = Profile(path,
    1.25 +                          preferences={'foo': 'bar'},
    1.26 +                          restore=False)
    1.27 +        user_js = os.path.join(profile.profile, 'user.js')
    1.28 +        self.assertTrue(os.path.exists(user_js))
    1.29 +
    1.30 +        # ensure the preference is correct
    1.31 +        prefs = Preferences.read_prefs(user_js)
    1.32 +        self.assertEqual(dict(prefs), {'foo': 'bar'})
    1.33 +
    1.34 +        del profile
    1.35 +
    1.36 +        # augment the profile with a second preference
    1.37 +        profile = Profile(path,
    1.38 +                          preferences={'fleem': 'baz'},
    1.39 +                          restore=True)
    1.40 +        prefs = Preferences.read_prefs(user_js)
    1.41 +        self.assertEqual(dict(prefs), {'foo': 'bar', 'fleem': 'baz'})
    1.42 +
    1.43 +        # cleanup the profile;
    1.44 +        # this should remove the new preferences but not the old
    1.45 +        profile.cleanup()
    1.46 +        prefs = Preferences.read_prefs(user_js)
    1.47 +        self.assertEqual(dict(prefs), {'foo': 'bar'})
    1.48 +
    1.49 +if __name__ == '__main__':
    1.50 +    unittest.main()

mercurial