Skip to content

Commit

Permalink
Use version-specific prefs files when running Firefox
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
jgraham committed Apr 12, 2018
1 parent e504871 commit 0c93c08
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
66 changes: 57 additions & 9 deletions tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions tools/wpt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 0c93c08

Please sign in to comment.