From fcf89c67213597fcd4c772fd7db73098d101f7cc Mon Sep 17 00:00:00 2001 From: Michael Kaply Date: Tue, 12 Nov 2019 18:18:49 +0000 Subject: [PATCH] Bug 1594584 - Marionette test for autoconfig. r=whimboo,kmag Differential Revision: https://phabricator.services.mozilla.com/D52106 --HG-- extra : moz-landing-system : lando --- extensions/pref/autoconfig/moz.build | 2 + .../autoconfig/test/marionette/autoconfig.cfg | 18 +++++ .../autoconfig/test/marionette/autoconfig.js | 5 ++ .../autoconfig/test/marionette/manifest.ini | 1 + .../test/marionette/test_autoconfig.py | 76 +++++++++++++++++++ .../marionette_harness/tests/unit-tests.ini | 3 + 6 files changed, 105 insertions(+) create mode 100644 extensions/pref/autoconfig/test/marionette/autoconfig.cfg create mode 100644 extensions/pref/autoconfig/test/marionette/autoconfig.js create mode 100644 extensions/pref/autoconfig/test/marionette/manifest.ini create mode 100644 extensions/pref/autoconfig/test/marionette/test_autoconfig.py diff --git a/extensions/pref/autoconfig/moz.build b/extensions/pref/autoconfig/moz.build index 9eff0b90b2bd..4027ba61b07a 100644 --- a/extensions/pref/autoconfig/moz.build +++ b/extensions/pref/autoconfig/moz.build @@ -7,3 +7,5 @@ DIRS += ['src'] XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini'] + +MARIONETTE_UNIT_MANIFESTS += ['test/marionette/manifest.ini'] diff --git a/extensions/pref/autoconfig/test/marionette/autoconfig.cfg b/extensions/pref/autoconfig/test/marionette/autoconfig.cfg new file mode 100644 index 000000000000..1e6fde18bf8d --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/autoconfig.cfg @@ -0,0 +1,18 @@ +// # don't remove this comment! (the first line is ignored by Mozilla) + +// Verify this one has a user value +pref("_autoconfig_.test.userpref", "userpref"); + +// Verify this one has a default pref +defaultPref("_autoconfig_.test.defaultpref", "defaultpref"); + +// Verify this one is locked +lockPref("_autoconfig_.test.lockpref", "lockpref"); + +lockPref("_autoconfig_.test.unlockpref", "unlockpref"); +// Verify this one is unlocked +unlockPref("_autoconfig_.test.unlockpref"); + +pref("_autoconfig_.test.clearpref", "clearpref"); +// Verify this one has no value +clearPref("_autoconfig_.test.clearpref"); diff --git a/extensions/pref/autoconfig/test/marionette/autoconfig.js b/extensions/pref/autoconfig/test/marionette/autoconfig.js new file mode 100644 index 000000000000..c891c5d1088c --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/autoconfig.js @@ -0,0 +1,5 @@ +/* global pref */ +pref("general.config.sandbox_enabled", true); +pref("general.config.filename", "autoconfig.cfg"); +pref("general.config.vendor", "autoconfig"); +pref("general.config.obscure_value", 0); diff --git a/extensions/pref/autoconfig/test/marionette/manifest.ini b/extensions/pref/autoconfig/test/marionette/manifest.ini new file mode 100644 index 000000000000..c10c20c2aee4 --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/manifest.ini @@ -0,0 +1 @@ +[test_autoconfig.py] diff --git a/extensions/pref/autoconfig/test/marionette/test_autoconfig.py b/extensions/pref/autoconfig/test/marionette/test_autoconfig.py new file mode 100644 index 000000000000..98bee6eec61f --- /dev/null +++ b/extensions/pref/autoconfig/test/marionette/test_autoconfig.py @@ -0,0 +1,76 @@ +# 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/. + +from __future__ import absolute_import + +import os +import shutil + +from marionette_harness import MarionetteTestCase + + +class TestAutoConfig(MarionetteTestCase): + + def tearDown(self): + self.marionette.quit(clean=True) + + if hasattr(self, 'pref_file'): + os.remove(self.pref_file) + if hasattr(self, 'autoconfig_file'): + os.remove(self.autoconfig_file) + + super(TestAutoConfig, self).tearDown() + + def pref_has_user_value(self, pref): + with self.marionette.using_context("chrome"): + return self.marionette.execute_script(""" + return Services.prefs.prefHasUserValue(arguments[0]); + """, script_args=(pref,)) + + def pref_is_locked(self, pref): + with self.marionette.using_context("chrome"): + return self.marionette.execute_script(""" + return Services.prefs.prefIsLocked(arguments[0]); + """, script_args=(pref,)) + + def test_autoconfig(self): + with self.marionette.using_context("chrome"): + self.exe_dir = self.marionette.execute_script(""" + return Services.dirsvc.get("GreD", Ci.nsIFile).path; + """) + + self.marionette.quit() + + test_dir = os.path.dirname(__file__) + self.pref_file = os.path.join(self.exe_dir, "defaults", "pref", "autoconfig.js") + shutil.copyfile(os.path.join(test_dir, "autoconfig.js"), self.pref_file) + self.autoconfig_file = os.path.join(self.exe_dir, "autoconfig.cfg") + shutil.copyfile(os.path.join(test_dir, "autoconfig.cfg"), self.autoconfig_file) + + self.marionette.start_session() + + with self.marionette.using_context("chrome"): + self.assertTrue(self.pref_has_user_value("_autoconfig_.test.userpref"), + "Pref should have user value") + + self.assertEqual(self.marionette.get_pref("_autoconfig_.test.userpref"), + "userpref", "User pref should be set") + + self.assertEqual(self.marionette.get_pref("_autoconfig_.test.defaultpref", True), + "defaultpref", "Default pref should be set") + + self.assertTrue(self.pref_is_locked("_autoconfig_.test.lockpref"), + "Pref should be locked") + + self.assertEqual(self.marionette.get_pref("_autoconfig_.test.lockpref"), + "lockpref", "Locked pref should be set") + + self.assertFalse(self.pref_is_locked("_autoconfig_.test.unlockpref"), + "Pref should be unlocked") + + self.assertEqual(self.marionette.get_pref("_autoconfig_.test.unlockpref"), + "unlockpref", "Unlocked pref should be set") + + self.assertFalse(self.pref_has_user_value("_autoconfig_.test.clearpref"), + "Pref should be cleared") diff --git a/testing/marionette/harness/marionette_harness/tests/unit-tests.ini b/testing/marionette/harness/marionette_harness/tests/unit-tests.ini index dabff7beade1..5088906e6038 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit-tests.ini +++ b/testing/marionette/harness/marionette_harness/tests/unit-tests.ini @@ -12,3 +12,6 @@ # searchservice tests [include:../../../../../browser/components/search/test/marionette/manifest.ini] + +# autoconfig tests +[include:../../../../../extensions/pref/autoconfig/test/marionette/manifest.ini]