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

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

Issue 112413006: [Telemetry] Fix page_cycler for pages with client side redirects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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
« no previous file with comments | « tools/perf/benchmarks/page_cycler.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
diff --git a/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py b/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
index 8c4c6fe899bde6d376c99eab406b652c35a1de4f..dc3bf4cfa5ee48ab0edd08acdc7c32da276bf6b9 100644
--- a/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
+++ b/tools/telemetry/telemetry/core/backends/chrome/inspector_page.py
@@ -15,8 +15,12 @@ class InspectorPage(object):
'Page',
self._OnNotification,
self._OnClose)
+
self._navigation_pending = False
self._navigation_url = ""
+ self._script_to_evaluate_on_commit = None
+ # Turn on notifications. We need them to get the Page.frameNavigated event.
+ self._EnablePageNotifications()
qsr 2014/01/07 16:22:15 Enabling notification only after setting up the va
def _OnNotification(self, msg):
logging.debug('Notification: %s', json.dumps(msg, indent=2))
@@ -32,16 +36,36 @@ class InspectorPage(object):
def _OnClose(self):
pass
- def _EnablePageNotifications(self, timeout):
- request = {
- 'method': 'Page.enable'
- }
- res = self._inspector_backend.SyncRequest(request, timeout)
- assert len(res['result'].keys()) == 0
+ def _SetScriptToEvaluateOnCommit(self, source):
+ existing_source = (self._script_to_evaluate_on_commit and
+ self._script_to_evaluate_on_commit['source'])
+ if source == existing_source:
+ return
+ if existing_source:
+ request = {
+ 'method': 'Page.removeScriptToEvaluateOnLoad',
+ 'params': {
+ 'identifier': self._script_to_evaluate_on_commit['id'],
+ }
+ }
+ self._inspector_backend.SyncRequest(request)
+ self._script_to_evaluate_on_commit = None
+ if source:
+ request = {
+ 'method': 'Page.addScriptToEvaluateOnLoad',
+ 'params': {
+ 'scriptSource': source,
+ }
+ }
+ res = self._inspector_backend.SyncRequest(request)
+ self._script_to_evaluate_on_commit = {
+ 'id': res['result']['identifier'],
+ 'source': source
+ }
- def _DisablePageNotifications(self, timeout):
+ def _EnablePageNotifications(self, timeout=60):
request = {
- 'method': 'Page.disable'
+ 'method': 'Page.enable'
}
res = self._inspector_backend.SyncRequest(request, timeout)
assert len(res['result'].keys()) == 0
@@ -55,19 +79,15 @@ class InspectorPage(object):
start_time = time.time()
remaining_time = timeout
+ action_function()
+ self._navigation_pending = True
try:
- self._EnablePageNotifications(remaining_time)
- try:
- action_function()
- 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(remaining_time)
+ while self._navigation_pending and remaining_time > 0:
+ remaining_time = max(timeout - (time.time() - start_time), 0.0)
+ self._inspector_backend.DispatchNotifications(remaining_time)
except util.TimeoutException:
- # Since we pass remaining_time as timeout to all of the calls in this,
- # method, we need to list the full timeout time in this message.
+ # Since we pass remaining_time to DispatchNotifications, we need to
+ # list the full timeout time in this message.
raise util.TimeoutException('Timed out while waiting %ds for navigation. '
'Error=%s' % (timeout, sys.exc_info()[1]))
@@ -80,14 +100,7 @@ class InspectorPage(object):
"""
def DoNavigate():
- if script_to_evaluate_on_commit:
- request = {
- 'method': 'Page.addScriptToEvaluateOnLoad',
- 'params': {
- 'scriptSource': script_to_evaluate_on_commit,
- }
- }
- self._inspector_backend.SyncRequest(request)
+ self._SetScriptToEvaluateOnCommit(script_to_evaluate_on_commit)
# 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.
« no previous file with comments | « tools/perf/benchmarks/page_cycler.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698