Commit 675a377e authored by wuhu's avatar wuhu Committed by Commit bot

Adding App, AndroidApp, AppBackend, AndroidAppBackend, PossibleApp.

Renaming variable name (browser_backend, browser) and function names
(under platform) where applicable.

BUG=

Review URL: https://codereview.chromium.org/647193002

Cr-Commit-Position: refs/heads/master@{#299357}
parent 9954e0bd
# Copyright 2012 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.
from telemetry.core import app
class AndroidApp(app.App):
"""A running android app instance that can be controlled in a limited way.
Be sure to clean up after yourself by calling Close() when you are done with
the app. Or better yet:
with possible_android_app.Create() as android_app:
... do all your operations on android_app here
"""
def __init__(self, backend, platform_backend):
super(AndroidApp, self).__init__(app_backend=backend,
platform_backend=platform_backend)
def Close(self):
raise NotImplementedError()
# Copyright 2012 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.
class App(object):
""" A running application instance that can be controlled in a limited way.
Be sure to clean up after yourself by calling Close() when you are done with
the app. Or better yet:
with possible_app.Create() as app:
... do all your operations on app here
"""
def __init__(self, app_backend, platform_backend):
assert platform_backend.platform != None
self._app_backend = app_backend
self._platform_backend = platform_backend
@property
def platform(self):
return self._platform_backend.platform
def Close(self):
raise NotImplementedError()
# Copyright 2012 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.
from telemetry.core.backends import app_backend
class AndroidAppBackend(app_backend.AppBackend):
def __init__(self):
super(AndroidAppBackend, self).__init__()
# Copyright 2012 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.
class AppBackend(object):
def __init__(self):
super(AppBackend, self).__init__()
self._app = None
def SetApp(self, app):
self._app = app
@property
def app(self):
return self._app
...@@ -7,6 +7,7 @@ import os ...@@ -7,6 +7,7 @@ import os
from telemetry import decorators from telemetry import decorators
from telemetry.core import platform from telemetry.core import platform
from telemetry.core import web_contents from telemetry.core import web_contents
from telemetry.core.backends import app_backend
from telemetry.core.forwarders import do_nothing_forwarder from telemetry.core.forwarders import do_nothing_forwarder
...@@ -14,11 +15,12 @@ class ExtensionsNotSupportedException(Exception): ...@@ -14,11 +15,12 @@ class ExtensionsNotSupportedException(Exception):
pass pass
class BrowserBackend(object): class BrowserBackend(app_backend.AppBackend):
"""A base class for browser backends.""" """A base class for browser backends."""
def __init__(self, supports_extensions, browser_options, tab_list_backend): def __init__(self, supports_extensions, browser_options, tab_list_backend):
assert browser_options.browser_type assert browser_options.browser_type
super(BrowserBackend, self).__init__()
self.browser_type = browser_options.browser_type self.browser_type = browser_options.browser_type
self._supports_extensions = supports_extensions self._supports_extensions = supports_extensions
self.browser_options = browser_options self.browser_options = browser_options
......
...@@ -206,7 +206,7 @@ class PossibleTrybotBrowser(possible_browser.PossibleBrowser): ...@@ -206,7 +206,7 @@ class PossibleTrybotBrowser(possible_browser.PossibleBrowser):
else: else:
logging.error('No local changes found in chromium or blink trees. ' logging.error('No local changes found in chromium or blink trees. '
'browser=%s argument sends local changes to the %s ' 'browser=%s argument sends local changes to the %s '
'perf trybot.', self._browser_type, self._buildername) 'perf trybot.', self.browser_type, self._buildername)
return return
def _InitPlatformIfNeeded(self): def _InitPlatformIfNeeded(self):
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import os import os
from telemetry import decorators from telemetry import decorators
from telemetry.core import app
from telemetry.core import browser_credentials from telemetry.core import browser_credentials
from telemetry.core import exceptions from telemetry.core import exceptions
from telemetry.core import extension_dict from telemetry.core import extension_dict
...@@ -16,7 +17,7 @@ from telemetry.core import wpr_server ...@@ -16,7 +17,7 @@ from telemetry.core import wpr_server
from telemetry.core.backends import browser_backend from telemetry.core.backends import browser_backend
class Browser(object): class Browser(app.App):
"""A running browser instance that can be controlled in a limited way. """A running browser instance that can be controlled in a limited way.
To create a browser instance, use browser_finder.FindBrowser. To create a browser instance, use browser_finder.FindBrowser.
...@@ -30,8 +31,8 @@ class Browser(object): ...@@ -30,8 +31,8 @@ class Browser(object):
def __init__(self, backend, platform_backend, archive_path, def __init__(self, backend, platform_backend, archive_path,
append_to_existing_wpr, make_javascript_deterministic, append_to_existing_wpr, make_javascript_deterministic,
credentials_path): credentials_path):
assert platform_backend.platform != None super(Browser, self).__init__(app_backend=backend,
platform_backend=platform_backend)
self._browser_backend = backend self._browser_backend = backend
self._platform_backend = platform_backend self._platform_backend = platform_backend
self._wpr_server = None self._wpr_server = None
...@@ -66,10 +67,6 @@ class Browser(object): ...@@ -66,10 +67,6 @@ class Browser(object):
def __exit__(self, *args): def __exit__(self, *args):
self.Close() self.Close()
@property
def platform(self):
return self._platform_backend.platform
@property @property
def browser_type(self): def browser_type(self):
return self._browser_backend.browser_type return self._browser_backend.browser_type
......
# Copyright 2012 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.
class PossibleApp(object):
"""A factory class that can be used to create a running instance of app.
Call Create() to launch the app and begin manipulating it.
"""
def __init__(self, app_type, target_os, finder_options):
self._app_type = app_type
self._target_os = target_os
self._finder_options = finder_options
self._platform = None
self._platform_backend = None
def __repr__(self):
return 'PossibleApp(app_type=%s)' % self.app_type
@property
def app_type(self):
return self._app_type
@property
def target_os(self):
"""Target OS, the app will run on."""
return self._target_os
@property
def finder_options(self):
return self._finder_options
@property
def platform(self):
self._InitPlatformIfNeeded()
return self._platform
def _InitPlatformIfNeeded(self):
raise NotImplementedError()
def Create(self):
raise NotImplementedError()
def SupportsOptions(self, finder_options):
"""Tests for extension support."""
raise NotImplementedError()
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
from telemetry.core import possible_app
class PossibleBrowser(object): class PossibleBrowser(possible_app.PossibleApp):
"""A browser that can be controlled. """A browser that can be controlled.
Call Create() to launch the browser and begin manipulating it.. Call Create() to launch the browser and begin manipulating it..
...@@ -12,42 +13,26 @@ class PossibleBrowser(object): ...@@ -12,42 +13,26 @@ class PossibleBrowser(object):
def __init__(self, browser_type, target_os, finder_options, def __init__(self, browser_type, target_os, finder_options,
supports_tab_control): supports_tab_control):
self._browser_type = browser_type super(PossibleBrowser, self).__init__(app_type=browser_type,
self._target_os = target_os target_os=target_os,
self._finder_options = finder_options finder_options=finder_options)
self._supports_tab_control = supports_tab_control self._supports_tab_control = supports_tab_control
self._platform = None
self._platform_backend = None
self._archive_path = None self._archive_path = None
self._append_to_existing_wpr = False self._append_to_existing_wpr = False
self._make_javascript_deterministic = True self._make_javascript_deterministic = True
self._credentials_path = None self._credentials_path = None
def __repr__(self): def __repr__(self):
return 'PossibleBrowser(browser_type=%s)' % self.browser_type return 'PossibleBrowser(app_type=%s)' % self.app_type
@property @property
def browser_type(self): def browser_type(self):
return self._browser_type return self.app_type
@property
def target_os(self):
"""Target OS, the browser will run on."""
return self._target_os
@property
def finder_options(self):
return self._finder_options
@property @property
def supports_tab_control(self): def supports_tab_control(self):
return self._supports_tab_control return self._supports_tab_control
@property
def platform(self):
self._InitPlatformIfNeeded()
return self._platform
def _InitPlatformIfNeeded(self): def _InitPlatformIfNeeded(self):
raise NotImplementedError() raise NotImplementedError()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment