Bug 1453641 [wpt PR 10443] - Use version-specific prefs files when running Firefox, a=testonly
authorjgraham <james@hoppipolla.co.uk>
Sun, 22 Apr 2018 14:51:21 +0000
changeset 468861 f8aebe28f718953583c54d81ff15f7600f17f9b8
parent 468860 697915768dc79b473127124d83746d370bc2cf1e
child 468862 35a8769bac5b0ca27802dc264da9696f1fb28f7a
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1453641, 10443
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1453641 [wpt PR 10443] - Use version-specific prefs files when running Firefox, a=testonly Automatic update from web-platform-testsUse version-specific prefs files when running Firefox (#10443) 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.) -- wpt-commits: cf2ef62f1c470b47a03275c795c6dedd69eace88 wpt-pr: 10443
testing/web-platform/tests/tools/wpt/browser.py
testing/web-platform/tests/tools/wpt/run.py
--- a/testing/web-platform/tests/tools/wpt/browser.py
+++ b/testing/web-platform/tests/tools/wpt/browser.py
@@ -174,32 +174,80 @@ class Firefox(Browser):
             return None
         if os.path.splitdrive(path)[1].split(os.path.sep) == ["", "Windows", "system32", "certutil.exe"]:
             return None
         return path
 
     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")
+        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")
 
-        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")
+        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
 
     def _latest_geckodriver_version(self):
         """Get and return latest version number for geckodriver."""
         # This is used rather than an API call to avoid rate limits
         tags = call("git", "ls-remote", "--tags", "--refs",
                     "https://github.com/mozilla/geckodriver.git")
--- a/testing/web-platform/tests/tools/wpt/run.py
+++ b/testing/web-platform/tests/tools/wpt/run.py
@@ -196,18 +196,17 @@ Consider installing certutil via your OS
 
             if webdriver_binary:
                 kwargs["webdriver_binary"] = webdriver_binary
             else:
                 print("Unable to find or install geckodriver, skipping wdspec tests")
                 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
 
 
 class Chrome(BrowserSetup):
     name = "chrome"
     browser_cls = browser.Chrome
 
     def setup_kwargs(self, kwargs):