Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 import os as real_os | |
| 5 import unittest | 4 import unittest |
| 6 | 5 |
| 7 from chrome_remote_control import browser_options | 6 from chrome_remote_control import browser_options |
| 8 from chrome_remote_control import desktop_browser_finder | 7 from chrome_remote_control import desktop_browser_finder |
| 9 from chrome_remote_control.system_stub import * | 8 from chrome_remote_control.system_stub import * |
| 10 | 9 |
| 11 # This file verifies the logic for finding a browser instance on all platforms | 10 # This file verifies the logic for finding a browser instance on all platforms |
| 12 # at once. It does so by providing stubs for the OS/sys/subprocess primitives | 11 # at once. It does so by providing stubs for the OS/sys/subprocess primitives |
| 13 # that the underlying finding logic usually uses to locate a suitable browser. | 12 # that the underlying finding logic usually uses to locate a suitable browser. |
| 14 # We prefer this approach to having to run the same test on every platform on | 13 # We prefer this approach to having to run the same test on every platform on |
| 15 # which we want this code to work. | 14 # which we want this code to work. |
| 16 | 15 |
| 17 class StubSubprocess(object): | |
| 18 def __init__(self): | |
| 19 self.call_hook = None | |
| 20 | |
| 21 def call(self, *args, **kwargs): | |
| 22 assert self.call_hook | |
| 23 return self.call_hook(*args, **kwargs) | |
| 24 | |
| 25 class FindTestBase(unittest.TestCase): | 16 class FindTestBase(unittest.TestCase): |
| 26 def setUp(self): | 17 def setUp(self): |
| 27 self._options = browser_options.BrowserOptions() | 18 self._options = browser_options.BrowserOptions() |
| 28 self._options.chrome_root = '../../../' | 19 self._options.chrome_root = '../../../' |
| 29 self._sys_stub = SysModuleStub() | 20 self._sys_stub = SysModuleStub() |
| 30 self._os_stub = OSModuleStub(self._sys_stub) | 21 self._os_stub = OSModuleStub(self._sys_stub) |
| 31 self._subprocess_stub = StubSubprocess() | 22 self._subprocess_stub = SubprocessModuleStub() |
|
nduca
2012/09/20 04:18:30
Where do you tear down?
dtu
2012/09/25 02:01:50
Done.
| |
| 32 | 23 |
| 33 @property | 24 @property |
| 34 def _files(self): | 25 def _files(self): |
| 35 return self._os_stub.files | 26 return self._os_stub.files |
| 36 | 27 |
| 37 def DoFindAll(self): | 28 def DoFindAll(self): |
| 38 return desktop_browser_finder.FindAllAvailableBrowsers(self._options, | 29 with Override(desktop_browser_finder, |
| 39 self._os_stub, self._sys_stub, self._subprocess_stub) | 30 os=self._os_stub, |
|
nduca
2012/09/20 04:18:30
how about making override just create all the righ
dtu
2012/09/25 02:01:50
Done. Override is from system_stub.
| |
| 31 subprocess=self._subprocess_stub, | |
| 32 sys=self._sys_stub): | |
| 33 return desktop_browser_finder.FindAllAvailableBrowsers(self._options) | |
| 40 | 34 |
| 41 def DoFindAllTypes(self): | 35 def DoFindAllTypes(self): |
| 42 browsers = self.DoFindAll() | 36 browsers = self.DoFindAll() |
| 43 return [b.browser_type for b in browsers] | 37 return [b.browser_type for b in browsers] |
| 44 | 38 |
| 45 def has_type(array, browser_type): | 39 def has_type(array, browser_type): |
| 46 return len([x for x in array if x.browser_type == browser_type]) != 0 | 40 return len([x for x in array if x.browser_type == browser_type]) != 0 |
| 47 | 41 |
| 48 class OSXFindTest(FindTestBase): | 42 class OSXFindTest(FindTestBase): |
| 49 def setUp(self): | 43 def setUp(self): |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 137 |
| 144 def testFindAllWithExact(self): | 138 def testFindAllWithExact(self): |
| 145 self._options.browser_executable = 'c:\\tmp\\chrome.exe' | 139 self._options.browser_executable = 'c:\\tmp\\chrome.exe' |
| 146 types = self.DoFindAllTypes() | 140 types = self.DoFindAllTypes() |
| 147 self.assertEquals( | 141 self.assertEquals( |
| 148 set(types), | 142 set(types), |
| 149 set(['exact', | 143 set(['exact', |
| 150 'debug', 'release', | 144 'debug', 'release', |
| 151 'content-shell-debug', 'content-shell-release', | 145 'content-shell-debug', 'content-shell-release', |
| 152 'system', 'canary'])) | 146 'system', 'canary'])) |
| OLD | NEW |