aboutsummaryrefslogtreecommitdiff
path: root/catapult/telemetry/telemetry/internal/backends/android_browser_backend_settings.py
blob: 95647e8bdb241541dd794220de738703bcee5793 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import logging
import time

from telemetry.core import exceptions


class AndroidBrowserBackendSettings(object):

  def __init__(self, activity, cmdline_file, package, pseudo_exec_name,
               supports_tab_control):
    self._activity = activity
    self._cmdline_file = cmdline_file
    self._package = package
    self._pseudo_exec_name = pseudo_exec_name
    self._supports_tab_control = supports_tab_control

  @property
  def activity(self):
    return self._activity

  @property
  def package(self):
    return self._package

  @property
  def pseudo_exec_name(self):
    return self._pseudo_exec_name

  @property
  def supports_tab_control(self):
    return self._supports_tab_control

  def GetCommandLineFile(self, is_user_debug_build):
    del is_user_debug_build  # unused
    return self._cmdline_file

  def GetDevtoolsRemotePort(self, device):
    raise NotImplementedError()

  @property
  def profile_ignore_list(self):
    # Don't delete lib, since it is created by the installer.
    return ['lib']


class ChromeBackendSettings(AndroidBrowserBackendSettings):
  # Stores a default Preferences file, re-used to speed up "--page-repeat".
  _default_preferences_file = None

  def GetCommandLineFile(self, is_user_debug_build):
    if is_user_debug_build:
      return '/data/local/tmp/chrome-command-line'
    else:
      return '/data/local/chrome-command-line'

  def __init__(self, package):
    super(ChromeBackendSettings, self).__init__(
        activity='com.google.android.apps.chrome.Main',
        cmdline_file=None,
        package=package,
        pseudo_exec_name='chrome',
        supports_tab_control=True)

  def GetDevtoolsRemotePort(self, device):
    return 'localabstract:chrome_devtools_remote'


class ContentShellBackendSettings(AndroidBrowserBackendSettings):
  def __init__(self, package):
    super(ContentShellBackendSettings, self).__init__(
        activity='org.chromium.content_shell_apk.ContentShellActivity',
        cmdline_file='/data/local/tmp/content-shell-command-line',
        package=package,
        pseudo_exec_name='content_shell',
        supports_tab_control=False)

  def GetDevtoolsRemotePort(self, device):
    return 'localabstract:content_shell_devtools_remote'


class WebviewBackendSettings(AndroidBrowserBackendSettings):
  def __init__(self,
               package,
               activity='org.chromium.webview_shell.TelemetryActivity',
               cmdline_file='/data/local/tmp/webview-command-line'):
    super(WebviewBackendSettings, self).__init__(
        activity=activity,
        cmdline_file=cmdline_file,
        package=package,
        pseudo_exec_name='webview',
        supports_tab_control=False)

  def GetDevtoolsRemotePort(self, device):
    # The DevTools socket name for WebView depends on the activity PID's.
    retries = 0
    timeout = 1
    pid = None
    while True:
      pids = device.GetPids(self.package)
      if not pids or self.package not in pids:
        time.sleep(timeout)
        retries += 1
        timeout *= 2
        if retries == 4:
          logging.critical('android_browser_backend: Timeout while waiting for '
                           'activity %s:%s to come up',
                           self.package,
                           self.activity)
          raise exceptions.BrowserGoneException(self.browser,
                                                'Timeout waiting for PID.')
      if len(pids[self.package]) > 1:
        raise Exception(
            'At most one instance of process %s expected but found pids: '
            '%s' % (self.package, pids))
      pid = pids[self.package][0]
      break
    return 'localabstract:webview_devtools_remote_%s' % str(pid)


class WebviewShellBackendSettings(WebviewBackendSettings):
  def __init__(self, package):
    super(WebviewShellBackendSettings, self).__init__(
        activity='org.chromium.android_webview.shell.AwShellActivity',
        cmdline_file='/data/local/tmp/android-webview-command-line',
        package=package)