Commit 3f632e1b authored by hjd's avatar hjd Committed by Commit bot

Fix WebviewBackendSettings use of adb

adb was moved to being owned by AndroidBrowserBackend in
crrev.com/522553002/.

Review URL: https://codereview.chromium.org/609903002

Cr-Commit-Position: refs/heads/master@{#297000}
parent d9983ebf
...@@ -37,7 +37,7 @@ class AndroidBrowserBackendSettings(object): ...@@ -37,7 +37,7 @@ class AndroidBrowserBackendSettings(object):
def GetCommandLineFile(self, is_user_debug_build): # pylint: disable=W0613 def GetCommandLineFile(self, is_user_debug_build): # pylint: disable=W0613
return self._cmdline_file return self._cmdline_file
def GetDevtoolsRemotePort(self): def GetDevtoolsRemotePort(self, adb):
raise NotImplementedError() raise NotImplementedError()
def RemoveProfile(self, adb): def RemoveProfile(self, adb):
...@@ -47,7 +47,7 @@ class AndroidBrowserBackendSettings(object): ...@@ -47,7 +47,7 @@ class AndroidBrowserBackendSettings(object):
paths = ['"%s/%s"' % (self.profile_dir, f) for f in files if f != 'lib'] paths = ['"%s/%s"' % (self.profile_dir, f) for f in files if f != 'lib']
adb.device().RunShellCommand('rm -r %s' % ' '.join(paths), as_root=True) adb.device().RunShellCommand('rm -r %s' % ' '.join(paths), as_root=True)
def PushProfile(self, _): def PushProfile(self, _new_profile_dir, _adb):
logging.critical('Profiles cannot be overriden with current configuration') logging.critical('Profiles cannot be overriden with current configuration')
sys.exit(1) sys.exit(1)
...@@ -74,10 +74,10 @@ class ChromeBackendSettings(AndroidBrowserBackendSettings): ...@@ -74,10 +74,10 @@ class ChromeBackendSettings(AndroidBrowserBackendSettings):
pseudo_exec_name='chrome', pseudo_exec_name='chrome',
supports_tab_control=True) supports_tab_control=True)
def GetDevtoolsRemotePort(self): def GetDevtoolsRemotePort(self, adb):
return 'localabstract:chrome_devtools_remote' return 'localabstract:chrome_devtools_remote'
def PushProfile(self, new_profile_dir): def PushProfile(self, new_profile_dir, adb):
# Pushing the profile is slow, so we don't want to do it every time. # Pushing the profile is slow, so we don't want to do it every time.
# Avoid this by pushing to a safe location using PushChangedFiles, and # Avoid this by pushing to a safe location using PushChangedFiles, and
# then copying into the correct location on each test run. # then copying into the correct location on each test run.
...@@ -89,21 +89,21 @@ class ChromeBackendSettings(AndroidBrowserBackendSettings): ...@@ -89,21 +89,21 @@ class ChromeBackendSettings(AndroidBrowserBackendSettings):
profile_base = os.path.basename(profile_parent) profile_base = os.path.basename(profile_parent)
saved_profile_location = '/sdcard/profile/%s' % profile_base saved_profile_location = '/sdcard/profile/%s' % profile_base
self.adb.device().PushChangedFiles(new_profile_dir, saved_profile_location) adb.device().PushChangedFiles(new_profile_dir, saved_profile_location)
self.adb.device().old_interface.EfficientDeviceDirectoryCopy( adb.device().old_interface.EfficientDeviceDirectoryCopy(
saved_profile_location, self.profile_dir) saved_profile_location, self.profile_dir)
dumpsys = self.adb.device().RunShellCommand( dumpsys = adb.device().RunShellCommand(
'dumpsys package %s' % self.package) 'dumpsys package %s' % self.package)
id_line = next(line for line in dumpsys if 'userId=' in line) id_line = next(line for line in dumpsys if 'userId=' in line)
uid = re.search('\d+', id_line).group() uid = re.search('\d+', id_line).group()
files = self.adb.device().RunShellCommand( files = adb.device().RunShellCommand(
'ls "%s"' % self.profile_dir, as_root=True) 'ls "%s"' % self.profile_dir, as_root=True)
files.remove('lib') files.remove('lib')
paths = ['%s/%s' % (self.profile_dir, f) for f in files] paths = ['%s/%s' % (self.profile_dir, f) for f in files]
for path in paths: for path in paths:
extended_path = '%s %s/* %s/*/* %s/*/*/*' % (path, path, path, path) extended_path = '%s %s/* %s/*/* %s/*/*/*' % (path, path, path, path)
self.adb.device().RunShellCommand( adb.device().RunShellCommand(
'chown %s.%s %s' % (uid, uid, extended_path)) 'chown %s.%s %s' % (uid, uid, extended_path))
class ContentShellBackendSettings(AndroidBrowserBackendSettings): class ContentShellBackendSettings(AndroidBrowserBackendSettings):
...@@ -115,7 +115,7 @@ class ContentShellBackendSettings(AndroidBrowserBackendSettings): ...@@ -115,7 +115,7 @@ class ContentShellBackendSettings(AndroidBrowserBackendSettings):
pseudo_exec_name='content_shell', pseudo_exec_name='content_shell',
supports_tab_control=False) supports_tab_control=False)
def GetDevtoolsRemotePort(self): def GetDevtoolsRemotePort(self, adb):
return 'localabstract:content_shell_devtools_remote' return 'localabstract:content_shell_devtools_remote'
...@@ -128,7 +128,7 @@ class ChromeShellBackendSettings(AndroidBrowserBackendSettings): ...@@ -128,7 +128,7 @@ class ChromeShellBackendSettings(AndroidBrowserBackendSettings):
pseudo_exec_name='chrome_shell', pseudo_exec_name='chrome_shell',
supports_tab_control=False) supports_tab_control=False)
def GetDevtoolsRemotePort(self): def GetDevtoolsRemotePort(self, adb):
return 'localabstract:chrome_shell_devtools_remote' return 'localabstract:chrome_shell_devtools_remote'
class WebviewBackendSettings(AndroidBrowserBackendSettings): class WebviewBackendSettings(AndroidBrowserBackendSettings):
...@@ -141,13 +141,13 @@ class WebviewBackendSettings(AndroidBrowserBackendSettings): ...@@ -141,13 +141,13 @@ class WebviewBackendSettings(AndroidBrowserBackendSettings):
pseudo_exec_name='webview', pseudo_exec_name='webview',
supports_tab_control=False) supports_tab_control=False)
def GetDevtoolsRemotePort(self): def GetDevtoolsRemotePort(self, adb):
# The DevTools socket name for WebView depends on the activity PID's. # The DevTools socket name for WebView depends on the activity PID's.
retries = 0 retries = 0
timeout = 1 timeout = 1
pid = None pid = None
while True: while True:
pids = self.adb.ExtractPid(self.package) pids = adb.ExtractPid(self.package)
if (len(pids) > 0): if (len(pids) > 0):
pid = pids[-1] pid = pids[-1]
break break
...@@ -206,7 +206,8 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): ...@@ -206,7 +206,8 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend):
if self._adb.device().old_interface.CanAccessProtectedFileContents(): if self._adb.device().old_interface.CanAccessProtectedFileContents():
if self.browser_options.profile_dir: if self.browser_options.profile_dir:
self._backend_settings.PushProfile(self.browser_options.profile_dir) self._backend_settings.PushProfile(self.browser_options.profile_dir,
self._adb)
elif not self.browser_options.dont_override_profile: elif not self.browser_options.dont_override_profile:
self._backend_settings.RemoveProfile(self._adb) self._backend_settings.RemoveProfile(self._adb)
...@@ -304,7 +305,7 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): ...@@ -304,7 +305,7 @@ class AndroidBrowserBackend(chrome_browser_backend.ChromeBrowserBackend):
blocking=True) blocking=True)
self._adb.Forward('tcp:%d' % self._port, self._adb.Forward('tcp:%d' % self._port,
self._backend_settings.GetDevtoolsRemotePort()) self._backend_settings.GetDevtoolsRemotePort(self._adb))
try: try:
self._WaitForBrowserToComeUp() self._WaitForBrowserToComeUp()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment