OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import webvr_latency_test | |
6 | |
7 import logging | |
8 import os | |
9 import time | |
10 | |
11 DEFAULT_SCREEN_WIDTH = 720 | |
12 DEFAULT_SCREEN_HEIGHT = 1280 | |
13 | |
14 class AndroidWebVrLatencyTest(webvr_latency_test.WebVrLatencyTest): | |
15 """Android implementation of the WebVR latency test.""" | |
16 def __init__(self, args): | |
17 super(AndroidWebVrLatencyTest, self).__init__(args) | |
18 self.device_name = self._Adb(['shell', 'getprop', | |
19 'ro.product.name']).strip() | |
20 | |
21 def _Setup(self): | |
22 self._Adb(['root']) | |
23 # Install the latest VrCore APK | |
24 self._Adb(['install', '-r', '-d', | |
25 '../../third_party/gvr-android-sdk/test-apks/vr_services' | |
26 '/vr_services_current.apk']) | |
27 self._SaveInstalledVrCoreVersion() | |
28 # TODO(bsheedy): Make APK path configurable so usable with other channels | |
29 self._Adb(['install', '-r', 'apks/ChromePublic.apk']) | |
30 # Force WebVR support, remove open tabs, and don't have first run | |
31 # experience. | |
32 self._SetChromeCommandLineFlags(['--enable-webvr', '--no-restore-state', | |
33 '--disable-fre']) | |
34 # Wake up the device and sleep, otherwise WebGL can crash on startup. | |
35 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_WAKEUP']) | |
36 time.sleep(1) | |
37 # Start Chrome | |
38 # TODO(bsheedy): See about having versioned copies of the flicker app | |
39 # instead of using personal github. | |
40 self._Adb(['shell', 'am', 'start', | |
41 '-a', 'android.intent.action.MAIN', | |
42 '-n', 'org.chromium.chrome/com.google.android.apps.chrome.Main', | |
43 'https://weableandbob.github.io/Motopho/flicker_apps/webvr/webvr- flicker-app-klaus.html?polyfill=0\&canvasClickPresents=1']) | |
Lei Lei
2017/04/17 22:57:13
This line is too long, can you split it into multi
bsheedy
2017/04/18 21:17:25
Done.
| |
44 time.sleep(10) | |
45 # Tap the center of the screen to start presenting. | |
46 (width, height) = self._GetScreenResolution() | |
47 self._Adb(['shell', 'input', 'touchscreen', 'tap', str(width/2), | |
48 str(height/2)]) | |
Lei Lei
2017/04/17 22:57:13
Is there any way to verify if Chrome is in VR mode
bsheedy
2017/04/18 21:17:25
There's no way to query it directly. However, VrCo
Lei Lei
2017/04/20 04:56:20
I am not sure if this will be an issue, but I reme
| |
49 time.sleep(5) | |
50 | |
51 def _Teardown(self): | |
52 # Exit VR and Close Chrome | |
53 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_BACK']) | |
54 self._Adb(['shell', 'am', 'force-stop', 'org.chromium.chrome']) | |
55 # Turn off the screen | |
56 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_POWER']) | |
57 | |
58 def _Adb(self, cmd): | |
59 """Runs the given command via adb. | |
60 | |
61 Returns: | |
62 A string containing the stdout and stderr of the adb command. | |
63 """ | |
64 # TODO(bsheedy): Maybe migrate to use Devil (overkill?) | |
Lei Lei
2017/04/17 22:57:13
I think it is better to migrate to use Devil, so w
bsheedy
2017/04/18 21:17:25
I got it working with Devil, but its dependencies
| |
65 return self._RunCommand([self.args.adb_path] + cmd) | |
66 | |
67 def _SaveInstalledVrCoreVersion(self): | |
68 """Retrieves the VrCore version and saves it for dashboard uploading.""" | |
69 output = self._Adb(['shell', 'dumpsys', 'package', 'com.google.vr.vrcore']) | |
70 version = None | |
71 for line in output.split('\n'): | |
72 if 'versionName' in line: | |
73 version = line.split('=')[1] | |
74 break | |
75 if version: | |
76 logging.info('VrCore version is %s', version) | |
77 else: | |
78 logging.info('VrCore version not retrieved') | |
79 version = '0' | |
80 if not (self.args.output_dir and os.path.isdir(self.args.output_dir)): | |
81 logging.warning('No output directory, not saving VrCore version') | |
82 return | |
83 with file(os.path.join(self.args.output_dir, | |
84 self.args.vrcore_version_file), 'w') as outfile: | |
85 outfile.write(version) | |
86 | |
87 def _SetChromeCommandLineFlags(self, flags): | |
88 """Sets the Chrome command line flags to the given list.""" | |
89 self._Adb(['shell', "echo 'chrome " + ' '.join(flags) + "' > " | |
90 + '/data/local/tmp/chrome-command-line']) | |
91 | |
92 def _GetScreenResolution(self): | |
93 """Retrieves the device's screen resolution, or a default if not found. | |
94 | |
95 Returns: | |
96 A tuple (width, height). | |
97 """ | |
98 output = self._Adb(['shell', 'dumpsys', 'display']) | |
99 width = None | |
100 height = None | |
101 for line in output.split('\n'): | |
102 if 'mDisplayWidth' in line: | |
103 width = int(line.split('=')[1]) | |
104 elif 'mDisplayHeight' in line: | |
105 height = int(line.split('=')[1]) | |
106 if width and height: | |
107 break | |
108 if not width: | |
109 logging.warning('Could not get actual screen width, defaulting to %d', | |
110 DEFAULT_SCREEN_WIDTH) | |
111 width = DEFAULT_SCREEN_WIDTH | |
112 if not height: | |
113 logging.warning('Could not get actual screen height, defaulting to %d', | |
114 DEFAULT_SCREEN_HEIGHT) | |
115 height = DEFAULT_SCREEN_HEIGHT | |
116 return (width, height) | |
OLD | NEW |