| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 unittest | 5 import unittest |
| 6 import mock | 6 import mock |
| 7 | 7 |
| 8 from telemetry.internal import forwarders | 8 from telemetry.internal import forwarders |
| 9 from telemetry.internal.backends.chrome import chrome_browser_backend | 9 from telemetry.internal.backends.chrome import chrome_browser_backend |
| 10 from telemetry.internal.browser import browser_options as browser_options_module |
| 10 from telemetry.util import wpr_modes | 11 from telemetry.util import wpr_modes |
| 11 | 12 |
| 12 | 13 |
| 13 class FakePlatformBackend(object): | 14 class FakePlatformBackend(object): |
| 14 def __init__(self, is_replay_active, wpr_http_device_port, | 15 def __init__(self, is_replay_active, wpr_http_device_port, |
| 15 wpr_https_device_port, is_host_platform): | 16 wpr_https_device_port, is_host_platform): |
| 16 self.is_host_platform = is_host_platform | 17 self.is_host_platform = is_host_platform |
| 17 | 18 |
| 18 self.forwarder_factory = mock.Mock() | 19 self.forwarder_factory = mock.Mock() |
| 19 | 20 |
| 20 self.network_controller_backend = mock.Mock() | 21 self.network_controller_backend = mock.Mock() |
| 21 self.network_controller_backend.is_replay_active = is_replay_active | 22 self.network_controller_backend.is_replay_active = is_replay_active |
| 22 self.network_controller_backend.wpr_device_ports = forwarders.PortSet( | 23 self.network_controller_backend.wpr_device_ports = forwarders.PortSet( |
| 23 http=wpr_http_device_port, https=wpr_https_device_port, dns=None) | 24 http=wpr_http_device_port, https=wpr_https_device_port, dns=None) |
| 24 self.network_controller_backend.host_ip = '127.0.0.1' | 25 self.network_controller_backend.host_ip = '127.0.0.1' |
| 25 self.network_controller_backend.is_test_ca_installed = False | 26 self.network_controller_backend.is_test_ca_installed = False |
| 26 | 27 |
| 27 | 28 |
| 28 class FakeBrowserOptions(object): | 29 class FakeBrowserOptions(browser_options_module.BrowserOptions): |
| 29 def __init__(self, wpr_mode=wpr_modes.WPR_OFF): | 30 def __init__(self, wpr_mode=wpr_modes.WPR_OFF): |
| 31 super(FakeBrowserOptions, self).__init__() |
| 30 self.wpr_mode = wpr_mode | 32 self.wpr_mode = wpr_mode |
| 31 self.browser_type = 'chrome' | 33 self.browser_type = 'chrome' |
| 32 self.dont_override_profile = False | |
| 33 self.browser_user_agent_type = 'desktop' | 34 self.browser_user_agent_type = 'desktop' |
| 34 self.disable_background_networking = False | 35 self.disable_background_networking = False |
| 35 self.disable_component_extensions_with_background_pages = False | 36 self.disable_component_extensions_with_background_pages = False |
| 36 self.disable_default_apps = False | 37 self.disable_default_apps = False |
| 37 self.extra_browser_args = [] | |
| 38 self.no_proxy_server = False | |
| 39 self.enable_logging = False | |
| 40 | 38 |
| 41 | 39 |
| 42 class TestChromeBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): | 40 class TestChromeBrowserBackend(chrome_browser_backend.ChromeBrowserBackend): |
| 43 # The test does not need to define the abstract methods. | 41 # The test does not need to define the abstract methods. |
| 44 # pylint: disable=abstract-method | 42 # pylint: disable=abstract-method |
| 45 | 43 |
| 46 def __init__(self, browser_options, | 44 def __init__(self, browser_options, |
| 47 wpr_http_device_port=None, wpr_https_device_port=None, | 45 wpr_http_device_port=None, wpr_https_device_port=None, |
| 48 is_running_locally=False): | 46 is_running_locally=False): |
| 49 browser_options.extensions_to_load = [] | 47 browser_options.extensions_to_load = [] |
| 50 browser_options.output_profile_path = None | 48 browser_options.output_profile_path = None |
| 51 super(TestChromeBrowserBackend, self).__init__( | 49 super(TestChromeBrowserBackend, self).__init__( |
| 52 platform_backend=FakePlatformBackend( | 50 platform_backend=FakePlatformBackend( |
| 53 browser_options.wpr_mode != wpr_modes.WPR_OFF, | 51 browser_options.wpr_mode != wpr_modes.WPR_OFF, |
| 54 wpr_http_device_port, wpr_https_device_port, is_running_locally), | 52 wpr_http_device_port, wpr_https_device_port, is_running_locally), |
| 55 supports_tab_control=False, | 53 supports_tab_control=False, |
| 56 supports_extensions=False, | 54 supports_extensions=False, |
| 57 browser_options=browser_options) | 55 browser_options=browser_options) |
| 58 | 56 |
| 59 | 57 |
| 60 class StartupArgsTest(unittest.TestCase): | 58 class StartupArgsTest(unittest.TestCase): |
| 61 """Test expected inputs for GetBrowserStartupArgs.""" | 59 """Test expected inputs for GetBrowserStartupArgs.""" |
| 62 | 60 |
| 63 def testNoProxyServer(self): | 61 def testNoProxyServer(self): |
| 64 browser_options = FakeBrowserOptions() | 62 browser_options = FakeBrowserOptions() |
| 65 browser_options.no_proxy_server = False | 63 browser_options.no_proxy_server = False |
| 66 browser_options.extra_browser_args = ['--proxy-server=http=inter.net'] | 64 browser_options.AppendExtraBrowserArgs('--proxy-server=http=inter.net') |
| 67 browser_backend = TestChromeBrowserBackend(browser_options) | 65 browser_backend = TestChromeBrowserBackend(browser_options) |
| 68 self.assertNotIn('--no-proxy-server', | 66 self.assertNotIn('--no-proxy-server', |
| 69 browser_backend.GetBrowserStartupArgs()) | 67 browser_backend.GetBrowserStartupArgs()) |
| 70 | 68 |
| 71 browser_options.no_proxy_server = True | 69 browser_options.no_proxy_server = True |
| 72 self.assertIn('--no-proxy-server', browser_backend.GetBrowserStartupArgs()) | 70 self.assertIn('--no-proxy-server', browser_backend.GetBrowserStartupArgs()) |
| 73 | 71 |
| 74 class ReplayStartupArgsTest(unittest.TestCase): | 72 class ReplayStartupArgsTest(unittest.TestCase): |
| 75 """Test expected inputs for GetReplayBrowserStartupArgs.""" | 73 """Test expected inputs for GetReplayBrowserStartupArgs.""" |
| 76 | 74 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 93 '--testing-fixed-https-port=567' | 91 '--testing-fixed-https-port=567' |
| 94 ] | 92 ] |
| 95 self.assertEqual( | 93 self.assertEqual( |
| 96 expected_args, | 94 expected_args, |
| 97 sorted(browser_backend.GetReplayBrowserStartupArgs())) | 95 sorted(browser_backend.GetReplayBrowserStartupArgs())) |
| 98 | 96 |
| 99 def testBasicArgs(self): | 97 def testBasicArgs(self): |
| 100 # The result is the same regardless of whether running locally. | 98 # The result is the same regardless of whether running locally. |
| 101 self.BasicArgsHelper(is_running_locally=True) | 99 self.BasicArgsHelper(is_running_locally=True) |
| 102 self.BasicArgsHelper(is_running_locally=False) | 100 self.BasicArgsHelper(is_running_locally=False) |
| OLD | NEW |