Debian Codegraph @

testing/mozbase/mozprofile/tests/test_nonce.py

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