| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 webvr_latency_test | 5 import webvr_latency_test |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import time | 9 import time |
| 10 | 10 |
| 11 | 11 |
| 12 DEFAULT_SCREEN_WIDTH = 720 | 12 DEFAULT_SCREEN_WIDTH = 720 |
| 13 DEFAULT_SCREEN_HEIGHT = 1280 | 13 DEFAULT_SCREEN_HEIGHT = 1280 |
| 14 NUM_VR_ENTRY_ATTEMPTS = 5 | 14 NUM_VR_ENTRY_ATTEMPTS = 5 |
| 15 | 15 |
| 16 | 16 |
| 17 class AndroidWebVrLatencyTest(webvr_latency_test.WebVrLatencyTest): | 17 class AndroidWebVrLatencyTest(webvr_latency_test.WebVrLatencyTest): |
| 18 """Android implementation of the WebVR latency test.""" | 18 """Android implementation of the WebVR latency test.""" |
| 19 def __init__(self, args): | 19 def __init__(self, args): |
| 20 super(AndroidWebVrLatencyTest, self).__init__(args) | 20 super(AndroidWebVrLatencyTest, self).__init__(args) |
| 21 self._device_name = self._Adb(['shell', 'getprop', | 21 self._device_name = self._Adb(['shell', 'getprop', |
| 22 'ro.product.name']).strip() | 22 'ro.product.name']).strip() |
| 23 | 23 |
| 24 def _Setup(self): | 24 def _OneTimeSetup(self): |
| 25 self._Adb(['root']) | 25 self._Adb(['root']) |
| 26 | 26 |
| 27 # Install the latest VrCore and Chrome APKs | 27 # Install the latest VrCore and Chrome APKs |
| 28 self._Adb(['install', '-r', '-d', | 28 self._Adb(['install', '-r', '-d', |
| 29 '../../third_party/gvr-android-sdk/test-apks/vr_services' | 29 '../../third_party/gvr-android-sdk/test-apks/vr_services' |
| 30 '/vr_services_current.apk']) | 30 '/vr_services_current.apk']) |
| 31 self._SaveInstalledVrCoreVersion() | 31 self._SaveInstalledVrCoreVersion() |
| 32 # TODO(bsheedy): Make APK path configurable so usable with other channels | 32 # TODO(bsheedy): Make APK path configurable so usable with other channels |
| 33 self._Adb(['install', '-r', 'apks/ChromePublic.apk']) | 33 self._Adb(['install', '-r', 'apks/ChromePublic.apk']) |
| 34 | 34 |
| 35 # Force WebVR support, remove open tabs, and don't have first run | 35 # Force WebVR support, remove open tabs, and don't have first run |
| 36 # experience. | 36 # experience. |
| 37 self._SetChromeCommandLineFlags(['--enable-webvr', '--no-restore-state', | 37 self._SetChromeCommandLineFlags(['--enable-webvr', '--no-restore-state', |
| 38 '--disable-fre']) | 38 '--disable-fre']) |
| 39 # Wake up the device and sleep, otherwise WebGL can crash on startup. | 39 # Wake up the device and sleep, otherwise WebGL can crash on startup. |
| 40 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_WAKEUP']) | 40 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_WAKEUP']) |
| 41 time.sleep(1) | 41 time.sleep(1) |
| 42 | 42 |
| 43 |
| 44 def _Setup(self, url): |
| 43 # Start Chrome | 45 # Start Chrome |
| 44 self._Adb(['shell', 'am', 'start', | 46 self._Adb(['shell', 'am', 'start', |
| 45 '-a', 'android.intent.action.MAIN', | 47 '-a', 'android.intent.action.MAIN', |
| 46 '-n', 'org.chromium.chrome/com.google.android.apps.chrome.Main', | 48 '-n', 'org.chromium.chrome/com.google.android.apps.chrome.Main', |
| 47 self._flicker_app_url]) | 49 url]) |
| 48 time.sleep(10) | 50 time.sleep(10) |
| 49 | 51 |
| 50 # Tap the center of the screen to start presenting. | 52 # Tap the center of the screen to start presenting. |
| 51 # It's technically possible that the screen tap won't enter VR on the first | 53 # It's technically possible that the screen tap won't enter VR on the first |
| 52 # time, so try several times by checking for the logcat output from | 54 # time, so try several times by checking for the logcat output from |
| 53 # entering VR | 55 # entering VR |
| 54 (width, height) = self._GetScreenResolution() | 56 (width, height) = self._GetScreenResolution() |
| 55 entered_vr = False | 57 entered_vr = False |
| 56 for _ in xrange(NUM_VR_ENTRY_ATTEMPTS): | 58 for _ in xrange(NUM_VR_ENTRY_ATTEMPTS): |
| 57 self._Adb(['logcat', '-c']) | 59 self._Adb(['logcat', '-c']) |
| 58 self._Adb(['shell', 'input', 'touchscreen', 'tap', str(width/2), | 60 self._Adb(['shell', 'input', 'touchscreen', 'tap', str(width/2), |
| 59 str(height/2)]) | 61 str(height/2)]) |
| 60 time.sleep(5) | 62 time.sleep(5) |
| 61 output = self._Adb(['logcat', '-d']) | 63 output = self._Adb(['logcat', '-d']) |
| 62 if 'Initialized GVR version' in output: | 64 if 'Initialized GVR version' in output: |
| 63 entered_vr = True | 65 entered_vr = True |
| 64 break | 66 break |
| 65 logging.warning('Failed to enter VR, retrying') | 67 logging.warning('Failed to enter VR, retrying') |
| 66 if not entered_vr: | 68 if not entered_vr: |
| 67 raise RuntimeError('Failed to enter VR after %d attempts' | 69 raise RuntimeError('Failed to enter VR after %d attempts' |
| 68 % NUM_VR_ENTRY_ATTEMPTS) | 70 % NUM_VR_ENTRY_ATTEMPTS) |
| 69 | 71 |
| 70 def _Teardown(self): | 72 def _Teardown(self): |
| 71 # Exit VR and close Chrome | 73 # Exit VR and close Chrome |
| 72 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_BACK']) | 74 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_BACK']) |
| 73 self._Adb(['shell', 'am', 'force-stop', 'org.chromium.chrome']) | 75 self._Adb(['shell', 'am', 'force-stop', 'org.chromium.chrome']) |
| 76 |
| 77 def _OneTimeTeardown(self): |
| 78 # Perform teardown again in case an exception was thrown |
| 79 self._Teardown() |
| 74 # Turn off the screen | 80 # Turn off the screen |
| 75 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_POWER']) | 81 self._Adb(['shell', 'input', 'keyevent', 'KEYCODE_POWER']) |
| 76 | 82 |
| 77 def _Adb(self, cmd): | 83 def _Adb(self, cmd): |
| 78 """Runs the given command via adb. | 84 """Runs the given command via adb. |
| 79 | 85 |
| 80 Returns: | 86 Returns: |
| 81 A string containing the stdout and stderr of the adb command. | 87 A string containing the stdout and stderr of the adb command. |
| 82 """ | 88 """ |
| 83 # TODO(bsheedy): Maybe migrate to use Devil (overkill?) | 89 # TODO(bsheedy): Maybe migrate to use Devil (overkill?) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 break | 132 break |
| 127 if not width: | 133 if not width: |
| 128 logging.warning('Could not get actual screen width, defaulting to %d', | 134 logging.warning('Could not get actual screen width, defaulting to %d', |
| 129 DEFAULT_SCREEN_WIDTH) | 135 DEFAULT_SCREEN_WIDTH) |
| 130 width = DEFAULT_SCREEN_WIDTH | 136 width = DEFAULT_SCREEN_WIDTH |
| 131 if not height: | 137 if not height: |
| 132 logging.warning('Could not get actual screen height, defaulting to %d', | 138 logging.warning('Could not get actual screen height, defaulting to %d', |
| 133 DEFAULT_SCREEN_HEIGHT) | 139 DEFAULT_SCREEN_HEIGHT) |
| 134 height = DEFAULT_SCREEN_HEIGHT | 140 height = DEFAULT_SCREEN_HEIGHT |
| 135 return (width, height) | 141 return (width, height) |
| OLD | NEW |