Commit 94a58f5d authored by slamm's avatar slamm Committed by Commit bot

Do not save finder options in PossibleApp/PossibleBrowser.

Without this, the browser may get created with old finder_options because FindBrowser has a caching decorator.

This should fix flakiness of telemetry/page/page_runner_unittest/PageRunnerTests/testUserAgent.

http://build.chromium.org/f/chromium/flakiness/
[test type: telemetry_unittests]

BUG=428967

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

Cr-Commit-Position: refs/heads/master@{#302504}
parent 66f514ae
......@@ -47,7 +47,7 @@ class CrOSAutoTest(unittest.TestCase):
self.assertTrue(browser_to_create)
options.browser_options.create_browser_with_oobe = True
options.browser_options.auto_login = auto_login
b = browser_to_create.Create()
b = browser_to_create.Create(options)
b.Start()
return b
......
......@@ -20,7 +20,7 @@ def Main(args):
browser_to_create = browser_finder.FindBrowser(options)
assert browser_to_create
with browser_to_create.Create() as b:
with browser_to_create.Create(options) as b:
tab = b.tabs[0]
# Measure round-trip-time for evaluate
......
......@@ -10,7 +10,7 @@ class AndroidApp(app.App):
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:
with possible_android_app.Create(options) as android_app:
... do all your operations on android_app here
"""
def __init__(self, backend, platform_backend):
......
......@@ -7,7 +7,7 @@ class App(object):
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:
with possible_app.Create(options) as app:
... do all your operations on app here
"""
def __init__(self, app_backend, platform_backend):
......
......@@ -70,15 +70,14 @@ class PossibleAndroidBrowser(possible_browser.PossibleBrowser):
"""A launchable android browser instance."""
def __init__(self, browser_type, finder_options, android_platform,
backend_settings, apk_name):
super(PossibleAndroidBrowser, self).__init__(browser_type, 'android',
finder_options, backend_settings.supports_tab_control)
assert browser_type in FindAllBrowserTypes(finder_options), \
('Please add %s to android_browser_finder.FindAllBrowserTypes' %
super(PossibleAndroidBrowser, self).__init__(
browser_type, 'android', backend_settings.supports_tab_control)
assert browser_type in FindAllBrowserTypes(finder_options), (
'Please add %s to android_browser_finder.FindAllBrowserTypes' %
browser_type)
self._platform = android_platform
self._platform_backend = (
android_platform._platform_backend # pylint: disable=W0212
)
android_platform._platform_backend) # pylint: disable=W0212
self._backend_settings = backend_settings
self._local_apk = None
......@@ -103,21 +102,21 @@ class PossibleAndroidBrowser(possible_browser.PossibleBrowser):
def _InitPlatformIfNeeded(self):
pass
def Create(self):
def Create(self, finder_options):
self._InitPlatformIfNeeded()
use_rndis_forwarder = (self.finder_options.android_rndis or
self.finder_options.browser_options.netsim or
use_rndis_forwarder = (finder_options.android_rndis or
finder_options.browser_options.netsim or
platform.GetHostPlatform().GetOSName() != 'linux')
backend = android_browser_backend.AndroidBrowserBackend(
self.finder_options.browser_options, self._backend_settings,
browser_backend = android_browser_backend.AndroidBrowserBackend(
finder_options.browser_options, self._backend_settings,
use_rndis_forwarder,
output_profile_path=self.finder_options.output_profile_path,
extensions_to_load=self.finder_options.extensions_to_load,
target_arch=self.finder_options.target_arch,
output_profile_path=finder_options.output_profile_path,
extensions_to_load=finder_options.extensions_to_load,
target_arch=finder_options.target_arch,
android_platform_backend=self._platform_backend)
return browser.Browser(
backend, self._platform_backend, self._credentials_path)
browser_backend, self._platform_backend, self._credentials_path)
def SupportsOptions(self, finder_options):
......
......@@ -22,10 +22,9 @@ def _IsRunningOnCrOS():
class PossibleCrOSBrowser(possible_browser.PossibleBrowser):
"""A launchable CrOS browser instance."""
def __init__(self, browser_type, finder_options, cros_platform, is_guest):
super(PossibleCrOSBrowser, self).__init__(browser_type, 'cros',
finder_options, True)
assert browser_type in FindAllBrowserTypes(finder_options), \
('Please add %s to cros_browser_finder.FindAllBrowserTypes()' %
super(PossibleCrOSBrowser, self).__init__(browser_type, 'cros', True)
assert browser_type in FindAllBrowserTypes(finder_options), (
'Please add %s to cros_browser_finder.FindAllBrowserTypes()' %
browser_type)
self._platform = cros_platform
self._platform_backend = (
......@@ -38,22 +37,22 @@ class PossibleCrOSBrowser(possible_browser.PossibleBrowser):
def _InitPlatformIfNeeded(self):
pass
def Create(self):
if self.finder_options.output_profile_path:
def Create(self, finder_options):
if finder_options.output_profile_path:
raise NotImplementedError(
'Profile generation is not yet supported on CrOS.')
browser_options = self.finder_options.browser_options
backend = cros_browser_backend.CrOSBrowserBackend(
browser_options = finder_options.browser_options
browser_backend = cros_browser_backend.CrOSBrowserBackend(
browser_options, self._platform_backend.cri, self._is_guest,
extensions_to_load=self.finder_options.extensions_to_load)
extensions_to_load=finder_options.extensions_to_load)
if browser_options.create_browser_with_oobe:
return cros_browser_with_oobe.CrOSBrowserWithOOBE(
backend,
browser_backend,
self._platform_backend,
self._credentials_path)
return browser.Browser(
backend, self._platform_backend, self._credentials_path)
browser_backend, self._platform_backend, self._credentials_path)
def SupportsOptions(self, finder_options):
if (len(finder_options.extensions_to_load) != 0) and self._is_guest:
......
......@@ -48,7 +48,7 @@ class CrOSTestCase(unittest.TestCase):
if password is not None:
browser_options.password = password
return browser_to_create.Create()
return browser_to_create.Create(options)
def _GetAutotestExtension(self, browser):
"""Returns the autotest extension instance"""
......
......@@ -21,10 +21,10 @@ class PossibleDesktopBrowser(possible_browser.PossibleBrowser):
def __init__(self, browser_type, finder_options, executable, flash_path,
is_content_shell, browser_directory, is_local_build=False):
target_os = sys.platform.lower()
super(PossibleDesktopBrowser, self).__init__(browser_type, target_os,
finder_options, not is_content_shell)
assert browser_type in FindAllBrowserTypes(finder_options), \
('Please add %s to desktop_browser_finder.FindAllBrowserTypes' %
super(PossibleDesktopBrowser, self).__init__(
browser_type, target_os, not is_content_shell)
assert browser_type in FindAllBrowserTypes(finder_options), (
'Please add %s to desktop_browser_finder.FindAllBrowserTypes' %
browser_type)
self._local_executable = executable
self._flash_path = flash_path
......@@ -45,7 +45,7 @@ class PossibleDesktopBrowser(possible_browser.PossibleBrowser):
# pylint: disable=W0212
self._platform_backend = self._platform._platform_backend
def Create(self):
def Create(self, finder_options):
if self._flash_path and not os.path.exists(self._flash_path):
logging.warning(
'Could not find Flash at %s. Continuing without Flash.\n'
......@@ -55,13 +55,13 @@ class PossibleDesktopBrowser(possible_browser.PossibleBrowser):
self._InitPlatformIfNeeded()
backend = desktop_browser_backend.DesktopBrowserBackend(
self.finder_options.browser_options, self._local_executable,
browser_backend = desktop_browser_backend.DesktopBrowserBackend(
finder_options.browser_options, self._local_executable,
self._flash_path, self._is_content_shell, self._browser_directory,
output_profile_path=self.finder_options.output_profile_path,
extensions_to_load=self.finder_options.extensions_to_load)
output_profile_path=finder_options.output_profile_path,
extensions_to_load=finder_options.extensions_to_load)
return browser.Browser(
backend, self._platform_backend, self._credentials_path)
browser_backend, self._platform_backend, self._credentials_path)
def SupportsOptions(self, finder_options):
if (len(finder_options.extensions_to_load) != 0) and self._is_content_shell:
......
......@@ -27,16 +27,15 @@ IOS_WEBKIT_DEBUG_PROXY = 'ios_webkit_debug_proxy'
class PossibleIOSBrowser(possible_browser.PossibleBrowser):
"""A running iOS browser instance."""
def __init__(self, browser_type, finder_options):
super(PossibleIOSBrowser, self).__init__(browser_type, 'ios',
finder_options, True)
def __init__(self, browser_type, _):
super(PossibleIOSBrowser, self).__init__(browser_type, 'ios', True)
# TODO(baxley): Implement the following methods for iOS.
def Create(self):
backend = ios_browser_backend.IosBrowserBackend(
self.finder_options.browser_options)
def Create(self, finder_options):
browser_backend = ios_browser_backend.IosBrowserBackend(
finder_options.browser_options)
return browser.Browser(
backend, self._platform_backend, self._credentials_path)
browser_backend, self._platform_backend, self._credentials_path)
def SupportsOptions(self, finder_options):
#TODO(baxley): Implement me.
......
......@@ -36,7 +36,7 @@ class FormBasedCredentialsBackendUnitTestBase(unittest.TestCase):
return
options = options_for_unittests.GetCopy()
with browser_finder.FindBrowser(options).Create() as b:
with browser_finder.FindBrowser(options).Create(options) as b:
b.credentials.credentials_path = credentials_path
if not b.credentials.CanLogin(self._credentials_type):
return
......
......@@ -24,14 +24,13 @@ SUCCESS, NO_CHANGES, ERROR = range(3)
class PossibleTrybotBrowser(possible_browser.PossibleBrowser):
"""A script that sends a job to a trybot."""
def __init__(self, browser_type, finder_options):
def __init__(self, browser_type, _):
target_os = browser_type.split('-')[1]
self._buildername = '%s_perf_bisect' % browser_type.replace(
'trybot-', '').replace('-', '_')
super(PossibleTrybotBrowser, self).__init__(browser_type, target_os,
finder_options, True)
super(PossibleTrybotBrowser, self).__init__(browser_type, target_os, True)
def Create(self):
def Create(self, finder_options):
raise NotImplementedError()
def SupportsOptions(self, finder_options):
......
......@@ -46,7 +46,7 @@ class PossibleWebDriverBrowser(possible_browser.PossibleBrowser):
# pylint: disable=W0212
self._platform_backend = self._platform._platform_backend
def Create(self):
def Create(self, finder_options):
self._InitPlatformIfNeeded()
backend = self.CreateWebDriverBackend(self._platform_backend)
return browser.Browser(backend,
......
......@@ -23,7 +23,7 @@ class Browser(app.App):
Be sure to clean up after yourself by calling Close() when you are done with
the browser. Or better yet:
browser_to_create = FindBrowser(options)
with browser_to_create.Create() as browser:
with browser_to_create.Create(options) as browser:
... do all your operations on browser here
"""
def __init__(self, backend, platform_backend, credentials_path):
......
......@@ -161,7 +161,7 @@ def _GenerateBrowserProfile(number_of_tabs):
options = options_for_unittests.GetCopy()
options.output_profile_path = profile_dir
browser_to_create = browser_finder.FindBrowser(options)
with browser_to_create.Create() as browser:
with browser_to_create.Create(options) as browser:
browser.SetHTTPServerDirectories(path.GetUnittestDataDir())
blank_file_path = os.path.join(path.GetUnittestDataDir(), 'blank.html')
blank_url = browser.http_server.UrlOf(blank_file_path)
......@@ -180,16 +180,17 @@ class BrowserRestoreSessionTest(unittest.TestCase):
def setUpClass(cls):
cls._number_of_tabs = 4
cls._profile_dir = _GenerateBrowserProfile(cls._number_of_tabs)
options = options_for_unittests.GetCopy()
options.browser_options.AppendExtraBrowserArgs(['--restore-last-session'])
options.browser_options.profile_dir = cls._profile_dir
cls._browser_to_create = browser_finder.FindBrowser(options)
cls._options = options_for_unittests.GetCopy()
cls._options.browser_options.AppendExtraBrowserArgs(
['--restore-last-session'])
cls._options.browser_options.profile_dir = cls._profile_dir
cls._browser_to_create = browser_finder.FindBrowser(cls._options)
@benchmark.Enabled('has tabs')
@benchmark.Disabled('chromeos', 'win')
# TODO(nednguyen): Enable this test on windowsn platform
def testRestoreBrowserWithMultipleTabs(self):
with self._browser_to_create.Create() as browser:
with self._browser_to_create.Create(self._options) as browser:
# The number of tabs will be self._number_of_tabs + 1 as it includes the
# old tabs and a new blank tab.
expected_number_of_tabs = self._number_of_tabs + 1
......
......@@ -31,7 +31,7 @@ class ExtensionTest(unittest.TestCase):
if not browser_to_create:
# May not find a browser that supports extensions.
return False
self._browser = browser_to_create.Create()
self._browser = browser_to_create.Create(options)
self._extension = self._browser.extensions[load_extension]
self._extension_id = load_extension.extension_id
self.assertTrue(self._extension)
......@@ -96,7 +96,7 @@ class NonExistentExtensionTest(unittest.TestCase):
load_extension = extension_to_load.ExtensionToLoad(
extension_path, options.browser_type)
browser_to_create = browser_finder.FindBrowser(options)
with browser_to_create.Create() as b:
with browser_to_create.Create(options) as b:
if b.supports_extensions:
self.assertRaises(KeyError, lambda: b.extensions[load_extension])
......@@ -122,7 +122,7 @@ class MultipleExtensionTest(unittest.TestCase):
self._browser = None
# May not find a browser that supports extensions.
if browser_to_create:
self._browser = browser_to_create.Create()
self._browser = browser_to_create.Create(options)
def tearDown(self):
if self._browser:
......@@ -165,7 +165,7 @@ class ComponentExtensionTest(unittest.TestCase):
'skipping test.')
return
with browser_to_create.Create() as b:
with browser_to_create.Create(options) as b:
extension = b.extensions[load_extension]
self.assertTrue(
extension.EvaluateJavaScript('chrome.runtime != null'))
......
......@@ -9,10 +9,9 @@ class PossibleApp(object):
Call Create() to launch the app and begin manipulating it.
"""
def __init__(self, app_type, target_os, finder_options):
def __init__(self, app_type, target_os):
self._app_type = app_type
self._target_os = target_os
self._finder_options = finder_options
self._platform = None
self._platform_backend = None
......@@ -28,10 +27,6 @@ class PossibleApp(object):
"""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()
......@@ -40,7 +35,7 @@ class PossibleApp(object):
def _InitPlatformIfNeeded(self):
raise NotImplementedError()
def Create(self):
def Create(self, finder_options):
raise NotImplementedError()
def SupportsOptions(self, finder_options):
......
......@@ -11,11 +11,9 @@ class PossibleBrowser(possible_app.PossibleApp):
Call Create() to launch the browser and begin manipulating it..
"""
def __init__(self, browser_type, target_os, finder_options,
supports_tab_control):
def __init__(self, browser_type, target_os, supports_tab_control):
super(PossibleBrowser, self).__init__(app_type=browser_type,
target_os=target_os,
finder_options=finder_options)
target_os=target_os)
self._supports_tab_control = supports_tab_control
self._credentials_path = None
......@@ -33,7 +31,7 @@ class PossibleBrowser(possible_app.PossibleApp):
def _InitPlatformIfNeeded(self):
raise NotImplementedError()
def Create(self):
def Create(self, finder_options):
raise NotImplementedError()
def SupportsOptions(self, finder_options):
......
......@@ -75,7 +75,7 @@ class _RunState(object):
possible_browser.SetCredentialsPath(page.credentials_path)
test.WillStartBrowser(possible_browser.platform)
self.browser = possible_browser.Create()
self.browser = possible_browser.Create(finder_options)
test.DidStartBrowser(self.browser)
if self._first_browser:
......
......@@ -21,7 +21,7 @@ class BrowserTestCase(unittest.TestCase):
cls._browser = None
try:
cls._browser = browser_to_create.Create()
cls._browser = browser_to_create.Create(options)
except:
cls.tearDownClass()
raise
......
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