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

Unified Diff: trunk/src/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py

Issue 60233004: Revert 232959 "[Telemetry] Fix image_decoding_measurement timeout." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 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: trunk/src/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
===================================================================
--- trunk/src/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py (revision 233019)
+++ trunk/src/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py (working copy)
@@ -3,8 +3,9 @@
# found in the LICENSE file.
import json
import logging
-import time
+from telemetry.core import util
+
class InspectorPage(object):
def __init__(self, inspector_backend):
self._inspector_backend = inspector_backend
@@ -29,38 +30,41 @@
def _OnClose(self):
pass
- def _EnablePageNotifications(self):
+ 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'
}
- res = self._inspector_backend.SyncRequest(request)
+ res = self._inspector_backend.SyncRequest(request, timeout)
assert len(res['result'].keys()) == 0
- def _DisablePageNotifications(self):
- request = {
- 'method': 'Page.disable'
- }
- res = self._inspector_backend.SyncRequest(request)
- assert len(res['result'].keys()) == 0
+ def DisablePageNotifications():
+ request = {
+ 'method': 'Page.disable'
+ }
+ res = self._inspector_backend.SyncRequest(request, timeout)
+ assert len(res['result'].keys()) == 0
- 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.
- """
- self._EnablePageNotifications()
+ self._navigation_pending = True
try:
action_function()
- start_time = time.time()
- remaining_time = timeout
- self._navigation_pending = True
- while self._navigation_pending and remaining_time > 0:
- remaining_time = max(timeout - (time.time() - start_time), 0.0)
- self._inspector_backend.DispatchNotifications(remaining_time)
- finally:
- self._DisablePageNotifications()
+ except:
+ DisablePageNotifications()
+ raise
+ def IsNavigationDone(time_left):
+ self._inspector_backend.DispatchNotifications(time_left)
+ return not self._navigation_pending
+ util.WaitFor(IsNavigationDone, timeout, pass_time_left_to_func=True)
+
+ DisablePageNotifications()
+
def Navigate(self, url, script_to_evaluate_on_commit=None, timeout=60):
"""Navigates to |url|.

Powered by Google App Engine
This is Rietveld 408576698