Chromium Code Reviews| Index: tools/chrome_remote_control/chrome_remote_control/inspector_page.py |
| diff --git a/tools/chrome_remote_control/chrome_remote_control/inspector_page.py b/tools/chrome_remote_control/chrome_remote_control/inspector_page.py |
| index 5018cb295e17dda358be2b7706d80af205b4a5ae..f08b19bca6146346ed4551162d268fb88bc5e5fa 100644 |
| --- a/tools/chrome_remote_control/chrome_remote_control/inspector_page.py |
| +++ b/tools/chrome_remote_control/chrome_remote_control/inspector_page.py |
| @@ -13,46 +13,33 @@ class InspectorPage(object): |
| 'Page', |
| self._OnNotification, |
| self._OnClose) |
| - self._pending_navigate_url = None |
| + self._navigation_pending = False |
| def _OnNotification(self, msg): |
| logging.debug('Notification: %s', json.dumps(msg, indent=2)) |
|
nduca
2012/11/07 04:13:49
dont forget a unit test for the new method in this
marja
2012/11/07 10:52:27
Done.
|
| - if msg['method'] == 'Page.frameNavigated' and self._pending_navigate_url: |
| + if msg['method'] == 'Page.frameNavigated' and self._navigation_pending: |
| url = msg['params']['frame']['url'] |
| if not url == 'chrome://newtab/': |
| # Marks the navigation as complete and unblocks the navigate call. |
| - self._pending_navigate_url = None |
| + self._navigation_pending = False |
| def _OnClose(self): |
| pass |
| - def Navigate(self, url, timeout=60): |
| - """Navigates to url""" |
| + def PerformActionAndWaitForNavigate(self, action_function, timeout=60): |
|
nduca
2012/11/07 04:13:49
Love it, but, add some doc strings to this, explai
marja
2012/11/07 10:52:27
Done.
|
| # Turn on notifications. We need them to get the Page.frameNavigated event. |
| request = { |
| - 'method': 'Page.enable' |
| - } |
| + 'method': 'Page.enable' |
| + } |
| res = self._inspector_backend.SyncRequest(request, timeout) |
| assert len(res['result'].keys()) == 0 |
| - # Navigate the page. However, there seems to be a bug in chrome devtools |
| - # protocol where the request id for this event gets held on the browser side |
| - # pretty much indefinitely. |
| - # |
| - # So, instead of waiting for the event to actually complete, wait for the |
| - # Page.frameNavigated event. |
| - request = { |
| - 'method': 'Page.navigate', |
| - 'params': { |
| - 'url': url, |
| - } |
| - } |
| - res = self._inspector_backend.SendAndIgnoreResponse(request) |
| + action_function() |
|
nduca
2012/11/07 04:13:49
if action_function raises an exception, then we're
marja
2012/11/07 10:52:27
Done.
|
| - self._pending_navigate_url = url |
| + self._navigation_pending = True |
| def IsNavigationDone(time_left): |
| self._inspector_backend.DispatchNotifications(time_left) |
| - return self._pending_navigate_url == None |
| + return not self._navigation_pending |
| util.WaitFor(IsNavigationDone, timeout, pass_time_left_to_func=True) |
| @@ -63,3 +50,22 @@ class InspectorPage(object): |
| res = self._inspector_backend.SyncRequest(request, timeout) |
| assert len(res['result'].keys()) == 0 |
| + def Navigate(self, url, timeout=60): |
| + """Navigates to url""" |
| + |
| + def DoNavigate(): |
| + # Navigate the page. However, there seems to be a bug in chrome devtools |
| + # protocol where the request id for this event gets held on the browser |
| + # side pretty much indefinitely. |
| + # |
| + # So, instead of waiting for the event to actually complete, wait for the |
| + # Page.frameNavigated event. |
| + request = { |
| + 'method': 'Page.navigate', |
| + 'params': { |
| + 'url': url, |
| + } |
| + } |
| + self._inspector_backend.SendAndIgnoreResponse(request) |
| + |
| + self.PerformActionAndWaitForNavigate(DoNavigate, timeout) |