Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: tools/telemetry/telemetry/inspector_page.py

Issue 11369075: Chrome remote control multipage tests: Add interactions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: code review (nduca) Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/inspector_page.py
diff --git a/tools/telemetry/telemetry/inspector_page.py b/tools/telemetry/telemetry/inspector_page.py
index a879dcffd435e06974dc557ec8b1676a2a75b929..b37d33049e1a876e0834201b8260df3c1cbaa2be 100644
--- a/tools/telemetry/telemetry/inspector_page.py
+++ b/tools/telemetry/telemetry/inspector_page.py
@@ -13,53 +13,71 @@ 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))
- 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
+ # Marks the navigation as complete and unblocks the
+ # PerformActionAndWaitForNavigate call.
+ self._navigation_pending = False
def _OnClose(self):
pass
- def Navigate(self, url, timeout=60):
- """Navigates to url"""
+ def PerformActionAndWaitForNavigate(self, action_function, timeout=60):
+ """Executes action_function, and waits for the navigation to complete.
+
+ action_function is expect to result in a navigation. This function returns
+ when the navigation is complete or when the timeout has been exceeded.
+ """
+
# 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)
+ def DisablePageNotifications():
+ request = {
+ 'method': 'Page.disable'
+ }
+ res = self._inspector_backend.SyncRequest(request, timeout)
+ assert len(res['result'].keys()) == 0
+
+ self._navigation_pending = True
+ try:
+ action_function()
+ except:
+ DisablePageNotifications()
+ raise
- self._pending_navigate_url = url
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)
- # Turn off notifications.
- request = {
- 'method': 'Page.disable'
- }
- res = self._inspector_backend.SyncRequest(request, timeout)
- assert len(res['result'].keys()) == 0
+ DisablePageNotifications()
+
+ 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)
« no previous file with comments | « tools/telemetry/telemetry/compound_interaction_unittest.py ('k') | tools/telemetry/telemetry/inspector_page_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698