Commit dd8f21b8 authored by dtu@chromium.org's avatar dtu@chromium.org

[telemetry] Update examples so they work.

Change Browser so that entering a with block calls Start(). This better matches the already existing behavior where exiting a with block calls Close().


BUG=None.
TEST=tools/telemetry/examples/list_available_browsers; tools/telemetry/examples/telemetry_perf_test.py --browser=system; tools/perf/run_benchmark tab_switching.top_10; tools/perf/run_tests; tools/telemetry/run_tests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243874 0039d316-1c4b-4281-b951-d872f2087c98
parent e1a72965
......@@ -81,7 +81,7 @@ def _SyncFilesToCloud(input_api, output_api):
try:
bucket_input = raw_input('Uploading to Cloud Storage: %s\n'
'Is this file [p]ublic or Google-[i]nternal?'
'Is this file [P]ublic or Google-[i]nternal?'
% file_path).lower()
if 'public'.startswith(bucket_input):
bucket = cloud_storage.PUBLIC_BUCKET
......
......@@ -59,7 +59,8 @@ class PresubmitTest(unittest.TestCase):
success_file_hash = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
self._stubs = system_stub.Override(
PRESUBMIT, ['cloud_storage', 'open', 'os'])
PRESUBMIT, ['cloud_storage', 'open', 'os', 'raw_input'])
self._stubs.raw_input.input = 'public'
# Files in Cloud Storage.
self._stubs.cloud_storage.remote_paths = [
'skip'.zfill(40),
......@@ -122,8 +123,7 @@ class PresubmitTest(unittest.TestCase):
def testSkip(self):
results = self._CheckUpload(['/path/to/skip.wpr.sha1'])
self.assertResultCount(results, 0, 1)
self.assertTrue('skipping' in str(results[0]), msg=results[0])
self.assertResultCount(results, 0, 0)
def testSuccess(self):
results = self._CheckUpload(['/path/to/success.wpr.sha1'])
......
......@@ -2,20 +2,22 @@
# Copyright (c) 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.
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
from telemetry.core import browser_options
def Main(args):
options = browser_options.BrowserOptions()
options.browser_type = 'list';
options = browser_options.BrowserFinderOptions()
options.browser_type = 'list'
parser = options.CreateParser('list_available_browsers')
parser.parse_args()
return 0
if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))
......@@ -2,15 +2,17 @@
# Copyright (c) 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.
import os
import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir))
from telemetry.core import browser_finder
from telemetry.core import browser_options
def Main(args):
options = browser_options.BrowserFinderOptions()
parser = options.CreateParser('telemetry_perf_test.py')
......@@ -40,5 +42,6 @@ def Main(args):
return 0
if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))
......@@ -36,7 +36,6 @@ class FormBasedCredentialsBackendUnitTestBase(unittest.TestCase):
options = options_for_unittests.GetCopy()
with browser_finder.FindBrowser(options).Create() as b:
b.Start()
b.credentials.credentials_path = credentials_path
if not b.credentials.CanLogin(self._credentials_type):
return
......@@ -54,7 +53,6 @@ class FormBasedCredentialsBackendUnitTestBase(unittest.TestCase):
# Login once to make sure our default profile is logged in.
with browser_finder.FindBrowser(options).Create() as b:
b.Start()
b.credentials.credentials_path = credentials_path
if not b.credentials.CanLogin(self._credentials_type):
......
......@@ -44,6 +44,7 @@ class Browser(object):
self._profilers_states = {}
def __enter__(self):
self.Start()
return self
def __exit__(self, *args):
......
......@@ -77,7 +77,6 @@ class NonExistentExtensionTest(unittest.TestCase):
extension_path, options.browser_type)
browser_to_create = browser_finder.FindBrowser(options)
with browser_to_create.Create() as b:
b.Start()
if b.supports_extensions:
self.assertRaises(extension_dict_backend.ExtensionNotFoundException,
lambda: b.extensions[load_extension])
......@@ -149,7 +148,6 @@ class ComponentExtensionTest(unittest.TestCase):
return
with browser_to_create.Create() as b:
b.Start()
extension = b.extensions[load_extension]
self.assertTrue(
extension.EvaluateJavaScript('chrome.runtime != null'))
......
......@@ -21,7 +21,6 @@ class TemporaryHTTPServerTest(unittest.TestCase):
options = options_for_unittests.GetCopy()
browser_to_create = browser_finder.FindBrowser(options)
with browser_to_create.Create() as b:
b.Start()
b.SetHTTPServerDirectories(util.GetUnittestDataDir())
t = b.tabs[0]
t.Navigate(b.http_server.UrlOf('/blank.html'))
......
......@@ -20,6 +20,7 @@ class Override(object):
'open': OpenFunctionStub,
'os': OsModuleStub,
'perf_control': PerfControlModuleStub,
'raw_input': RawInputFunctionStub,
'subprocess': SubprocessModuleStub,
'sys': SysModuleStub,
'thermal_throttle': ThermalThrottleModuleStub,
......@@ -219,6 +220,14 @@ class PerfControlModuleStub(object):
self.PerfControl = PerfControlModuleStub.PerfControlStub
class RawInputFunctionStub(object):
def __init__(self):
self.input = ''
def __call__(self, name, *args, **kwargs):
return self.input
class SubprocessModuleStub(object):
class PopenStub(object):
def __init__(self):
......
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