diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/mozbase/mozprofile/tests/test_chrome_profile.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mozbase/mozprofile/tests/test_chrome_profile.py')
-rw-r--r-- | testing/mozbase/mozprofile/tests/test_chrome_profile.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/mozbase/mozprofile/tests/test_chrome_profile.py b/testing/mozbase/mozprofile/tests/test_chrome_profile.py new file mode 100644 index 0000000000..27c07686f8 --- /dev/null +++ b/testing/mozbase/mozprofile/tests/test_chrome_profile.py @@ -0,0 +1,72 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. + +import json +import os + +import mozunit +from mozprofile import ChromeProfile + + +def test_chrome_profile_pre_existing(tmpdir): + path = tmpdir.strpath + profile = ChromeProfile(profile=path) + assert not profile.create_new + assert os.path.isdir(profile.profile) + assert profile.profile == path + + +def test_chrome_profile_create_new(): + profile = ChromeProfile() + assert profile.create_new + assert os.path.isdir(profile.profile) + assert profile.profile.endswith("Default") + + +def test_chrome_preferences(tmpdir): + prefs = {"foo": "bar"} + profile = ChromeProfile(preferences=prefs) + prefs_file = os.path.join(profile.profile, "Preferences") + + assert os.path.isfile(prefs_file) + + with open(prefs_file) as fh: + assert json.load(fh) == prefs + + # test with existing prefs + prefs_file = tmpdir.join("Preferences").strpath + with open(prefs_file, "w") as fh: + json.dump({"num": "1"}, fh) + + profile = ChromeProfile(profile=tmpdir.strpath, preferences=prefs) + + def assert_prefs(): + with open(prefs_file) as fh: + data = json.load(fh) + + assert len(data) == 2 + assert data.get("foo") == "bar" + assert data.get("num") == "1" + + assert_prefs() + profile.reset() + assert_prefs() + + +def test_chrome_addons(): + addons = ["foo", "bar"] + profile = ChromeProfile(addons=addons) + + assert isinstance(profile.addons, list) + assert profile.addons == addons + + profile.addons.install("baz") + assert profile.addons == addons + ["baz"] + + profile.reset() + assert profile.addons == addons + + +if __name__ == "__main__": + mozunit.main() |