OLD | NEW |
1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import re | 5 import re |
6 import time | 6 import time |
7 | 7 |
8 from telemetry.core import android_process | 8 from telemetry.core import android_process |
9 from telemetry.core import util | 9 from telemetry.core import util |
10 from telemetry.core import web_contents | 10 from telemetry.core import web_contents |
11 from telemetry.core.backends import adb_commands | 11 from telemetry.core.backends import adb_commands |
12 from telemetry.core.backends import app_backend | 12 from telemetry.core.backends import app_backend |
| 13 from telemetry.core.backends import android_browser_backend_settings |
| 14 from telemetry.core.backends import android_command_line_backend |
13 | 15 |
14 | 16 |
15 class AndroidAppBackend(app_backend.AppBackend): | 17 class AndroidAppBackend(app_backend.AppBackend): |
| 18 |
16 def __init__(self, android_platform_backend, start_intent, | 19 def __init__(self, android_platform_backend, start_intent, |
17 is_app_ready_predicate=None): | 20 is_app_ready_predicate=None): |
18 super(AndroidAppBackend, self).__init__( | 21 super(AndroidAppBackend, self).__init__( |
19 start_intent.package, android_platform_backend) | 22 start_intent.package, android_platform_backend) |
20 self._default_process_name = start_intent.package | 23 self._default_process_name = start_intent.package |
21 self._start_intent = start_intent | 24 self._start_intent = start_intent |
22 self._is_app_ready_predicate = is_app_ready_predicate | 25 self._is_app_ready_predicate = is_app_ready_predicate |
23 self._is_running = False | 26 self._is_running = False |
24 self._existing_processes_by_pid = {} | 27 self._existing_processes_by_pid = {} |
25 | 28 |
26 @property | 29 @property |
27 def _adb(self): | 30 def _adb(self): |
28 return self.platform_backend.adb | 31 return self.platform_backend.adb |
29 | 32 |
30 def _IsAppReady(self): | 33 def _IsAppReady(self): |
31 return self._is_app_ready_predicate(self.app) | 34 return self._is_app_ready_predicate(self.app) |
32 | 35 |
33 def Start(self): | 36 def Start(self): |
34 """Start an Android app and wait for it to finish launching. | 37 """Start an Android app and wait for it to finish launching. |
35 | 38 |
36 AppStory derivations can customize the wait-for-ready-state to wait | 39 AppStory derivations can customize the wait-for-ready-state to wait |
37 for a more specific event if needed. | 40 for a more specific event if needed. |
38 """ | 41 """ |
39 # TODO(slamm): check if can use "blocking=True" instead of needing to sleep. | 42 webview_startup_args = self.GetWebviewStartupArgs() |
40 # If "blocking=True" does not work, switch sleep to "ps" check. | 43 backend_settings = android_browser_backend_settings.WebviewBackendSettings( |
41 self._adb.device().StartActivity(self._start_intent, blocking=False) | 44 'android-webview') |
42 util.WaitFor(self._IsAppReady, timeout=60) | 45 with android_command_line_backend.SetUpCommandLineFlags( |
| 46 self._adb, backend_settings, webview_startup_args): |
| 47 # TODO(slamm): check if can use "blocking=True" instead of needing to |
| 48 # sleep. If "blocking=True" does not work, switch sleep to "ps" check. |
| 49 self._adb.device().StartActivity(self._start_intent, blocking=False) |
| 50 util.WaitFor(self._IsAppReady, timeout=60) |
43 self._is_running = True | 51 self._is_running = True |
44 | 52 |
45 def Close(self): | 53 def Close(self): |
46 self._is_running = False | 54 self._is_running = False |
47 self.platform_backend.KillApplication(self._start_intent.package) | 55 self.platform_backend.KillApplication(self._start_intent.package) |
48 | 56 |
49 def IsAppRunning(self): | 57 def IsAppRunning(self): |
50 return self._is_running | 58 return self._is_running |
51 | 59 |
52 def GetStandardOutput(self): | 60 def GetStandardOutput(self): |
(...skipping 21 matching lines...) Expand all Loading... |
74 def GetProcess(self, subprocess_name): | 82 def GetProcess(self, subprocess_name): |
75 assert subprocess_name.startswith(':') | 83 assert subprocess_name.startswith(':') |
76 process_name = self._default_process_name + subprocess_name | 84 process_name = self._default_process_name + subprocess_name |
77 return self.GetProcesses(lambda n: n == process_name).pop() | 85 return self.GetProcesses(lambda n: n == process_name).pop() |
78 | 86 |
79 def GetWebViews(self): | 87 def GetWebViews(self): |
80 webviews = set() | 88 webviews = set() |
81 for process in self.GetProcesses(): | 89 for process in self.GetProcesses(): |
82 webviews.update(process.GetWebViews()) | 90 webviews.update(process.GetWebViews()) |
83 return webviews | 91 return webviews |
| 92 |
| 93 def GetWebviewStartupArgs(self): |
| 94 args = [] |
| 95 |
| 96 # Turn on GPU benchmarking extension for all runs. The only side effect of |
| 97 # the extension being on is that render stats are tracked. This is believed |
| 98 # to be effectively free. And, by doing so here, it avoids us having to |
| 99 # programmatically inspect a pageset's actions in order to determine if it |
| 100 # might eventually scroll. |
| 101 args.append('--enable-gpu-benchmarking') |
| 102 |
| 103 return args |
OLD | NEW |