| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 """Common utilities used in unit tests, within this directory.""" | 5 """Common utilities used in unit tests, within this directory.""" |
| 6 | 6 |
| 7 import dependency_graph |
| 7 import devtools_monitor | 8 import devtools_monitor |
| 8 import loading_model | 9 import loading_model |
| 9 import loading_trace | 10 import loading_trace |
| 10 import page_track | 11 import page_track |
| 11 import request_track | 12 import request_track |
| 12 import tracing | 13 import tracing |
| 13 import user_satisfied_lens | 14 import user_satisfied_lens |
| 14 | 15 |
| 15 | 16 |
| 16 class FakeRequestTrack(devtools_monitor.Track): | 17 class FakeRequestTrack(devtools_monitor.Track): |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 160 |
| 160 class TestResourceGraph(loading_model.ResourceGraph): | 161 class TestResourceGraph(loading_model.ResourceGraph): |
| 161 """Replace the default request lens in a ResourceGraph with our SimpleLens.""" | 162 """Replace the default request lens in a ResourceGraph with our SimpleLens.""" |
| 162 REQUEST_LENS = SimpleLens | 163 REQUEST_LENS = SimpleLens |
| 163 | 164 |
| 164 @classmethod | 165 @classmethod |
| 165 def FromRequestList(cls, requests, page_events=None, trace_events=None): | 166 def FromRequestList(cls, requests, page_events=None, trace_events=None): |
| 166 return cls(LoadingTraceFromEvents(requests, page_events, trace_events)) | 167 return cls(LoadingTraceFromEvents(requests, page_events, trace_events)) |
| 167 | 168 |
| 168 | 169 |
| 170 class TestDependencyGraph(dependency_graph.RequestDependencyGraph): |
| 171 """A dependency graph created from requests using a simple lens.""" |
| 172 def __init__(self, requests): |
| 173 lens = SimpleLens(LoadingTraceFromEvents(requests)) |
| 174 super(TestDependencyGraph, self).__init__(requests, lens) |
| 175 |
| 176 |
| 169 class MockConnection(object): | 177 class MockConnection(object): |
| 170 """Mock out connection for testing. | 178 """Mock out connection for testing. |
| 171 | 179 |
| 172 Use Expect* for requests expecting a repsonse. SyncRequestNoResponse puts | 180 Use Expect* for requests expecting a repsonse. SyncRequestNoResponse puts |
| 173 requests into no_response_requests_seen. | 181 requests into no_response_requests_seen. |
| 174 | 182 |
| 175 TODO(mattcary): use a standard mock system (the back-ported python3 | 183 TODO(mattcary): use a standard mock system (the back-ported python3 |
| 176 unittest.mock? devil.utils.mock_calls?) | 184 unittest.mock? devil.utils.mock_calls?) |
| 177 | 185 |
| 178 """ | 186 """ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 207 if not self._expected_responses[method]: | 215 if not self._expected_responses[method]: |
| 208 del self._expected_responses[method] | 216 del self._expected_responses[method] |
| 209 self._test_case.assertEqual(expected_params, params) | 217 self._test_case.assertEqual(expected_params, params) |
| 210 return response | 218 return response |
| 211 | 219 |
| 212 | 220 |
| 213 class MockUserSatisfiedLens(user_satisfied_lens._UserSatisfiedLens): | 221 class MockUserSatisfiedLens(user_satisfied_lens._UserSatisfiedLens): |
| 214 def _CalculateTimes(self, _): | 222 def _CalculateTimes(self, _): |
| 215 self._satisfied_msec = float('inf') | 223 self._satisfied_msec = float('inf') |
| 216 self._event_msec = float('inf') | 224 self._event_msec = float('inf') |
| OLD | NEW |