Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit cc864ad

Browse files
committed
[wpt] Support detecting Chrome for Android version
Consequently, we can now install the correct ChromeDriver version. * The change also includes some drive-by whitespace fixes in the file.
1 parent 2882eb7 commit cc864ad

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

docs/running-tests/chrome_android.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ connect to the device. Run `adb devices` to verify.
77

88
Currently, Android support is a prototype with some known issues:
99

10-
* We install ChromeDriver corresponding to the Chrome version on your *host*,
11-
so you will need a special flag to bypass ChromeDriver's version check if the
12-
test device runs a different version of Chrome from your host.
10+
* If you have previously run `./wpt run` against Chrome, you might need to
11+
remove `_venv/bin/chromedriver` so that we can install the correct
12+
ChromeDriver corresponding to your Chrome for Android version.
1313
* The package name is hard coded. If you are testing a custom build, you will
1414
need to search and replace `com.android.chrome` in `tools/`.
1515
* We do not support reftests at the moment.
@@ -19,5 +19,5 @@ Note: rooting the device or installing a root CA is no longer required.
1919
Example:
2020

2121
```bash
22-
./wpt run --webdriver-arg=--disable-build-check --test-type=testharness chrome_android TESTS
22+
./wpt run --test-type=testharness chrome_android TESTS
2323
```

tools/wpt/browser.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def handle_remove_readonly(func, path, exc):
3636
else:
3737
raise
3838

39+
3940
class Browser(object):
4041
__metaclass__ = ABCMeta
4142

@@ -534,28 +535,32 @@ def _chromium_chromedriver_url(self, chrome_version):
534535
self.chromium_platform_string(), revision, self.platform_string())
535536
return url
536537

537-
def _latest_chromedriver_url(self, browser_binary=None):
538-
chrome_version = self.version(browser_binary)
539-
assert chrome_version, "Cannot detect the version of Chrome"
538+
def _latest_chromedriver_url(self, chrome_version):
540539
# Remove channel suffixes (e.g. " dev").
541540
chrome_version = chrome_version.split(' ')[0]
542541
return (self._official_chromedriver_url(chrome_version) or
543542
self._chromium_chromedriver_url(chrome_version))
544543

545-
def install_webdriver(self, dest=None, channel=None, browser_binary=None):
544+
def install_webdriver_by_version(self, version, dest=None):
545+
assert version, "Cannot install ChromeDriver without Chrome version"
546546
if dest is None:
547547
dest = os.pwd
548-
if browser_binary is None:
549-
browser_binary = self.find_binary(channel)
550-
url = self._latest_chromedriver_url(browser_binary)
548+
url = self._latest_chromedriver_url(version)
551549
self.logger.info("Downloading ChromeDriver from %s" % url)
552550
unzip(get(url).raw, dest)
553-
chromedriver_dir = os.path.join(dest, 'chromedriver_%s' % self.platform_string())
551+
chromedriver_dir = os.path.join(
552+
dest, 'chromedriver_%s' % self.platform_string())
554553
if os.path.isfile(os.path.join(chromedriver_dir, "chromedriver")):
555554
shutil.move(os.path.join(chromedriver_dir, "chromedriver"), dest)
556555
shutil.rmtree(chromedriver_dir)
557556
return find_executable("chromedriver", dest)
558557

558+
def install_webdriver(self, dest=None, channel=None, browser_binary=None):
559+
if browser_binary is None:
560+
browser_binary = self.find_binary(channel)
561+
return self.install_webdriver_by_version(
562+
self.version(browser_binary), dest)
563+
559564
def version(self, binary=None, webdriver_binary=None):
560565
if not binary:
561566
self.logger.warning("No browser binary provided.")
@@ -585,6 +590,9 @@ class ChromeAndroid(Browser):
585590
product = "chrome_android"
586591
requirements = "requirements_chrome_android.txt"
587592

593+
def __init__(self, logger):
594+
super(ChromeAndroid, self).__init__(logger)
595+
588596
def install(self, dest=None, channel=None):
589597
raise NotImplementedError
590598

@@ -596,10 +604,20 @@ def find_webdriver(self, channel=None):
596604

597605
def install_webdriver(self, dest=None, channel=None, browser_binary=None):
598606
chrome = Chrome(self.logger)
599-
return chrome.install_webdriver(dest, channel)
607+
return chrome.install_webdriver_by_version(self.version(), dest)
600608

601609
def version(self, binary=None, webdriver_binary=None):
602-
return None
610+
command = ['adb', 'shell', 'dumpsys', 'package', 'com.android.chrome']
611+
try:
612+
output = call(*command)
613+
except (subprocess.CalledProcessError, OSError):
614+
self.logger.warning("Failed to call %s" % " ".join(command))
615+
return None
616+
match = re.search(r'versionName=(.*)', output)
617+
if not match:
618+
self.logger.warning("Failed to find versionName")
619+
return None
620+
return match.group(1)
603621

604622

605623
class ChromeiOS(Browser):
@@ -699,6 +717,7 @@ def version(self, binary=None, webdriver_binary=None):
699717
if m:
700718
return m.group(0)
701719

720+
702721
class EdgeChromium(Browser):
703722
"""MicrosoftEdge-specific interface."""
704723
platform = {
@@ -725,16 +744,16 @@ def find_binary(self, venv_path=None, channel=None):
725744
os.path.expandvars("$SYSTEMDRIVE\\Program Files\\Microsoft\\Edge Dev\\Application"),
726745
os.path.expandvars("$SYSTEMDRIVE\\Program Files (x86)\\Microsoft\\Edge Beta\\Application"),
727746
os.path.expandvars("$SYSTEMDRIVE\\Program Files (x86)\\Microsoft\\Edge Dev\\Application"),
728-
os.path.expanduser("~\\AppData\Local\\Microsoft\\Edge SxS\\Application"),]
747+
os.path.expanduser("~\\AppData\Local\\Microsoft\\Edge SxS\\Application")]
729748
return find_executable(binaryname, os.pathsep.join(winpaths))
730749
if self.platform == "macos":
731750
binaryname = "Microsoft Edge Canary"
732751
binary = find_executable(binaryname)
733752
if not binary:
734753
macpaths = ["/Applications/Microsoft Edge.app/Contents/MacOS",
735-
os.path.expanduser("~/Applications/Microsoft Edge.app/Contents/MacOS"),
736-
"/Applications/Microsoft Edge Canary.app/Contents/MacOS",
737-
os.path.expanduser("~/Applications/Microsoft Edge Canary.app/Contents/MacOS")]
754+
os.path.expanduser("~/Applications/Microsoft Edge.app/Contents/MacOS"),
755+
"/Applications/Microsoft Edge Canary.app/Contents/MacOS",
756+
os.path.expanduser("~/Applications/Microsoft Edge Canary.app/Contents/MacOS")]
738757
return find_executable("Microsoft Edge Canary", os.pathsep.join(macpaths))
739758
return binary
740759

@@ -797,6 +816,7 @@ def version(self, binary=None, webdriver_binary=None):
797816
self.logger.warning("Failed to find Edge binary.")
798817
return None
799818

819+
800820
class Edge(Browser):
801821
"""Edge-specific interface."""
802822

tools/wpt/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
latest_channels = {
77
'firefox': 'nightly',
88
'chrome': 'dev',
9+
'chrome_android': 'dev',
910
'edgechromium': 'dev',
1011
'safari': 'preview',
1112
'servo': 'nightly'

0 commit comments

Comments
 (0)