From 0c93c0877c816f3b565eaaab7987e9c131475c1c Mon Sep 17 00:00:00 2001 From: James Graham Date: Thu, 12 Apr 2018 13:48:29 +0100 Subject: [PATCH] Use version-specific prefs files when running Firefox Firefox requires a prefs file to be loaded to ensure that it doesn't make external network connections, and to make sure that other settings are appropriate for testing. Previously we always used the version of the prefs file from master, which is usually fine for nightly builds, but doesn't work with release builds if it happens that a pref changed. This change uses the correct release version of the prefs file for firefox releases and beta versions. It continues to use the master version for any nightly build; this could be fixed in some cases if we are able to access the actual commit hash used to build Firefox, but probably isn't too bad an approximation. The caching algorithm was changed so that release versions of the prefs are cached forever, and the nightly version is updated once per day (although this doesn't quite match the nightly release cadence, it's only going to fail in edge cases where the prefs were changed in the file, but the nightly version was not yet updated, of vice-versa.) --- tools/wpt/browser.py | 66 ++++++++++++++++++++++++++++++++++++++------ tools/wpt/run.py | 3 +- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/tools/wpt/browser.py b/tools/wpt/browser.py index d52feb03576043..0c37e13ab48daf 100644 --- a/tools/wpt/browser.py +++ b/tools/wpt/browser.py @@ -179,22 +179,70 @@ def find_certutil(self): def find_webdriver(self): return find_executable("geckodriver") - def install_prefs(self, dest=None): + def get_version_number(self, binary): + version_re = re.compile("Mozilla Firefox (\d+\.\d+(?:\.\d+)?)(a|b)?") + proc = subprocess.Popen([binary, "--version"], stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + stdout.strip() + m = version_re.match(stdout) + if not m: + return None, "nightly" + version, status = m.groups() + channel = {"a": "nightly", "b": "beta"} + return version, channel.get(status, "stable") + + def get_prefs_url(self, version, channel): + if channel == "stable": + repo = "https://hg.mozilla.org/releases/mozilla-release" + tag = "FIREFOX_%s_RELEASE" % version.replace(".", "_") + else: + repo = "https://hg.mozilla.org/mozilla-central" + if channel == "beta": + tag = "FIREFOX_%s_BETA" % version.split(".", 1)[0] + else: + # Always use tip as the tag for nightly; this isn't quite right + # but to do better we need the actual build revision, which we + # can get if we have an application.ini file + tag = "tip" + + return "%s/raw-file/%s/testing/profiles/prefs_general.js" % (repo, tag) + + def install_prefs(self, binary, dest=None): + version, channel = self.get_version_number(binary) + if dest is None: dest = os.pwd dest = os.path.join(dest, "profiles") if not os.path.exists(dest): os.makedirs(dest) - prefs_path = os.path.join(dest, "prefs_general.js") - - now = datetime.now() - if (not os.path.exists(prefs_path) or - (datetime.fromtimestamp(os.stat(prefs_path).st_mtime) < - now - timedelta(days=2))): - with open(prefs_path, "wb") as f: - resp = get("https://hg.mozilla.org/mozilla-central/raw-file/tip/testing/profiles/prefs_general.js") + prefs_file = os.path.join(dest, "prefs_general.js") + cache_file = os.path.join(dest, + "%s-%s.cache" % (version, channel) + if channel != "nightly" + else "nightly.cache") + + have_cache = False + if os.path.exists(cache_file): + if channel != "nightly": + have_cache = True + else: + now = datetime.now() + have_cache = (datetime.fromtimestamp(os.stat(cache_file).st_mtime) > + now - timedelta(days=1)) + + # If we don't have a recent download, grab the url + if not have_cache: + url = self.get_prefs_url(version, channel) + + with open(cache_file, "wb") as f: + print("Installing test prefs from %s" % url) + resp = get(url) f.write(resp.content) + else: + print("Using cached test prefs from %s" % cache_file) + + shutil.copyfile(cache_file, prefs_file) return dest diff --git a/tools/wpt/run.py b/tools/wpt/run.py index 6b39eb9d4d44fb..5761ab89cc98ca 100644 --- a/tools/wpt/run.py +++ b/tools/wpt/run.py @@ -201,8 +201,7 @@ def setup_kwargs(self, kwargs): kwargs["test_types"].remove("wdspec") if kwargs["prefs_root"] is None: - print("Downloading gecko prefs") - prefs_root = self.browser.install_prefs(self.venv.path) + prefs_root = self.browser.install_prefs(kwargs["binary"], self.venv.path) kwargs["prefs_root"] = prefs_root