michael@0: #!/usr/bin/env python michael@0: michael@0: """ michael@0: test nonce in prefs delimeters michael@0: see https://bugzilla.mozilla.org/show_bug.cgi?id=722804 michael@0: """ michael@0: michael@0: import os michael@0: import tempfile michael@0: import time michael@0: import unittest michael@0: from mozprofile.prefs import Preferences michael@0: from mozprofile.profile import Profile michael@0: michael@0: class PreferencesNonceTest(unittest.TestCase): michael@0: michael@0: def test_nonce(self): michael@0: michael@0: # make a profile with one preference michael@0: path = tempfile.mktemp() michael@0: profile = Profile(path, michael@0: preferences={'foo': 'bar'}, michael@0: restore=False) michael@0: user_js = os.path.join(profile.profile, 'user.js') michael@0: self.assertTrue(os.path.exists(user_js)) michael@0: michael@0: # ensure the preference is correct michael@0: prefs = Preferences.read_prefs(user_js) michael@0: self.assertEqual(dict(prefs), {'foo': 'bar'}) michael@0: michael@0: del profile michael@0: michael@0: # augment the profile with a second preference michael@0: profile = Profile(path, michael@0: preferences={'fleem': 'baz'}, michael@0: restore=True) michael@0: prefs = Preferences.read_prefs(user_js) michael@0: self.assertEqual(dict(prefs), {'foo': 'bar', 'fleem': 'baz'}) michael@0: michael@0: # cleanup the profile; michael@0: # this should remove the new preferences but not the old michael@0: profile.cleanup() michael@0: prefs = Preferences.read_prefs(user_js) michael@0: self.assertEqual(dict(prefs), {'foo': 'bar'}) michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()