Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Provides fakes for several of Telemetry's internal objects. | 5 """Provides fakes for several of Telemetry's internal objects. |
| 6 | 6 |
| 7 These allow code like story_runner and Benchmark to be run and tested | 7 These allow code like story_runner and Benchmark to be run and tested |
| 8 without compiling or starting a browser. Class names prepended with an | 8 without compiling or starting a browser. Class names prepended with an |
| 9 underscore are intended to be implementation details, and should not | 9 underscore are intended to be implementation details, and should not |
| 10 be subclassed; however, some, like _FakeBrowser, have public APIs that | 10 be subclassed; however, some, like _FakeBrowser, have public APIs that |
| 11 may need to be called in tests. | 11 may need to be called in tests. |
| 12 """ | 12 """ |
| 13 import tempfile | |
| 14 | |
| 13 from telemetry.internal.backends.chrome_inspector import websocket | 15 from telemetry.internal.backends.chrome_inspector import websocket |
| 14 from telemetry.internal.browser import browser_options | 16 from telemetry.internal.browser import browser_options |
| 17 from telemetry.internal.image_processing import video | |
| 15 from telemetry.internal.platform import system_info | 18 from telemetry.internal.platform import system_info |
| 16 from telemetry.page import shared_page_state | 19 from telemetry.page import shared_page_state |
| 17 from telemetry.util import image_util | 20 from telemetry.util import image_util |
| 18 from telemetry.testing.internal import fake_gpu_info | 21 from telemetry.testing.internal import fake_gpu_info |
| 19 from types import ModuleType | 22 from types import ModuleType |
| 20 | 23 |
| 21 | 24 |
| 22 # Classes and functions which are intended to be part of the public | 25 # Classes and functions which are intended to be part of the public |
| 23 # fakes API. | 26 # fakes API. |
| 24 | 27 |
| 28 class FakePlatformBackend(object): | |
| 29 def __init__(self): | |
| 30 self.platform = FakePlatform() | |
| 31 | |
| 32 def DidStartBrowser(self, _, _2): | |
|
nednguyen
2017/05/16 17:39:25
nits: our style is keep the parameter the same & u
rnephew (Reviews Here)
2017/05/16 17:56:28
Done.
| |
| 33 pass | |
| 34 | |
| 35 def WillCloseBrowser(self, _, _2): | |
| 36 pass | |
| 37 | |
| 38 | |
| 25 class FakePlatform(object): | 39 class FakePlatform(object): |
| 26 def __init__(self): | 40 def __init__(self): |
| 27 self._network_controller = None | 41 self._network_controller = None |
| 28 self._tracing_controller = None | 42 self._tracing_controller = None |
| 29 self._has_battor = False | 43 self._has_battor = False |
| 30 self._os_name = 'FakeOS' | 44 self._os_name = 'FakeOS' |
| 45 self.device = 'fake_device' | |
| 46 self._is_video_capture_running = False | |
| 47 | |
| 48 def StartVideoCapture(self, _): | |
| 49 self._is_video_capture_running = True | |
| 50 | |
| 51 def StopVideoCapture(self): | |
| 52 self._is_video_capture_running = False | |
| 53 return video.Video(tempfile.NamedTemporaryFile()) | |
| 54 | |
| 55 @property | |
| 56 def is_video_capture_running(self): | |
| 57 return self._is_video_capture_running | |
| 31 | 58 |
| 32 @property | 59 @property |
| 33 def is_host_platform(self): | 60 def is_host_platform(self): |
| 34 raise NotImplementedError | 61 raise NotImplementedError |
| 35 | 62 |
| 36 @property | 63 @property |
| 37 def network_controller(self): | 64 def network_controller(self): |
| 38 if self._network_controller is None: | 65 if self._network_controller is None: |
| 39 self._network_controller = _FakeNetworkController() | 66 self._network_controller = _FakeNetworkController() |
| 40 return self._network_controller | 67 return self._network_controller |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 self._elapsed_time = time | 574 self._elapsed_time = time |
| 548 | 575 |
| 549 def __del__(self): | 576 def __del__(self): |
| 550 self.Restore() | 577 self.Restore() |
| 551 | 578 |
| 552 def Restore(self): | 579 def Restore(self): |
| 553 if self._module: | 580 if self._module: |
| 554 self._module.time = self._actual_time | 581 self._module.time = self._actual_time |
| 555 self._module = None | 582 self._module = None |
| 556 self._actual_time = None | 583 self._actual_time = None |
| 557 | |
| OLD | NEW |