Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3410)

Unified Diff: build/android/pylib/device/remote_device_environment.py

Issue 745793002: Add AMP support to test runner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get rid of old/done TODOs Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/device/remote_device_environment.py
diff --git a/build/android/pylib/device/remote_device_environment.py b/build/android/pylib/device/remote_device_environment.py
new file mode 100644
index 0000000000000000000000000000000000000000..e9118ce6ad702adfd96e98ba2d05241ab710abee
--- /dev/null
+++ b/build/android/pylib/device/remote_device_environment.py
@@ -0,0 +1,119 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
jbudorick 2014/11/30 22:57:02 These need to be in build/android/pylib/remote/dev
rnephew (Reviews Here) 2014/12/02 19:47:48 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Environment setup and teardown for remote devices."""
+
+import os
+import sys
+
+from pylib import constants
+from pylib.base import environment
+from pylib.device import remote_device_utils
+
+sys.path.append(os.path.join(
+ constants.DIR_SOURCE_ROOT, 'third_party', 'appurify-python', 'src'))
+import appurify.api
+
+
+class RemoteDeviceEnvironment(environment.Environment):
+ """An environment for running on remote devices."""
+
+ def __init__(self, options, error_func):
+ """Constructor.
+
+ Args:
+ options: Command line options.
+ error_func: error to show when using bad command line options.
+ """
+ super(RemoteDeviceEnvironment, self).__init__()
+ #TODO(rnephew): store only needed options
+ # list of files checked for this: self
+ if not options.api_key:
+ error_func('Must set api key')
+ if not options.api_secret:
+ error_func('Must set api secret')
+ self._api_key = options.api_key
+ self._api_secret = options.api_secret
+ self._api_protocol = options.api_protocol
+ self._api_address = options.api_address
+ self._device_list = ''
+ self._access_token = ''
+ self._results_path = options.results_path
+ self._remote_device = options.remote_device
+ self._remote_device_os = options.remote_device_os
+ self._runner_package = options.runner_package
+ self._runner_type = options.runner_type
+ self._device = ''
+
+ def SetUp(self):
+ """Set up the test environment."""
+ os.environ['APPURIFY_API_PROTO'] = self._api_protocol
+ os.environ['APPURIFY_API_HOST'] = self._api_address
+ os.environ['APPURIFY_API_PORT'] = '80'
+ self.GetAccessToken()
+ self.GetDeviceList()
+ self._device = self.SelectDevice()
+
+ def TearDown(self):
+ """Teardown the test environment."""
+ self.RevokeAccessToken()
+
+ def __enter__(self):
+ """Runs when entering with with keyword."""
+ self.SetUp()
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Runs when exiting with with keyword."""
+ self.TearDown()
+
+ def GetAccessToken(self):
+ """Generates access token for remote device service."""
+ access_token_results = appurify.api.access_token_generate(
+ self._api_key, self._api_secret)
+ remote_device_utils.TestHttpResponse(access_token_results,
+ 'Unable to generate access token.')
+ self._access_token = access_token_results.json()['response']['access_token']
+
+ def RevokeAccessToken(self):
+ """Destroys access token for remote device service."""
+ revoke_token_results = appurify.api.access_token_revoke(self._access_token)
+ remote_device_utils.TestHttpResponse(revoke_token_results,
+ 'Unable to revoke access token.')
+
+ def GetDeviceList(self):
jbudorick 2014/11/30 22:57:02 Why are GetDeviceList and SelectDevice separate? D
rnephew (Reviews Here) 2014/12/02 19:47:48 Done.
+ """Get list devices available on remote device service."""
+ dev_list_res = appurify.api.devices_list(self._access_token)
+ remote_device_utils.TestHttpResponse(dev_list_res,
+ 'Unable to generate access token.')
+ self._device_list = dev_list_res.json()['response']
+
+ def SelectDevice(self):
+ """Select which device to use."""
+ for device in self._device_list:
+ if (device['name'] == self._remote_device and
+ device['os_version'] == self._remote_device_os):
+ return device['device_type_id']
+ raise remote_device_utils.RemoteDeviceError('No device found: %s %s' %(
+ self._remote_device, self._remote_device_os))
+
+ @property
+ def device(self):
+ return self._device
+
+ @property
+ def token(self):
+ return self._access_token
+
+ @property
+ def results_path(self):
+ return self._results_path
+
+ @property
+ def runner_type(self):
+ return self._runner_type
+
+ @property
+ def runner_package(self):
+ return self._runner_package

Powered by Google App Engine
This is Rietveld 408576698