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

Unified Diff: tools/telemetry/telemetry/core/web_contents.py

Issue 185413005: [Telemetry] Move page quiescence test to WebContents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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/telemetry/telemetry/core/network_quiescence.js ('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/web_contents.py
diff --git a/tools/telemetry/telemetry/core/web_contents.py b/tools/telemetry/telemetry/core/web_contents.py
index 4e29c7d5a7f7fc1164c00705555279b75f65eac4..1837a301ca728e74ca6f8e4d79be33d48c53d4e2 100644
--- a/tools/telemetry/telemetry/core/web_contents.py
+++ b/tools/telemetry/telemetry/core/web_contents.py
@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import os
+
from telemetry.core import util
DEFAULT_WEB_CONTENTS_TIMEOUT = 90
@@ -13,6 +15,10 @@ class WebContents(object):
def __init__(self, inspector_backend):
self._inspector_backend = inspector_backend
+ with open(os.path.join(os.path.dirname(__file__),
+ 'network_quiescence.js')) as f:
+ self._quiescence_js = f.read()
+
def Close(self):
"""Closes this page.
@@ -46,6 +52,22 @@ class WebContents(object):
return False
util.WaitFor(IsTrue, timeout)
+ def HasReachedQuiescence(self):
+ """Determine whether the page has reached quiescence after loading.
+
+ Returns:
+ True if 2 seconds have passed since last resource received, false
+ otherwise."""
+
+ # Inclusion of the script that provides
+ # window.__telemetry_testHasReachedNetworkQuiescence()
+ # is idempotent, it's run on every call because WebContents doesn't track
+ # page loads and we need to execute anew for every newly loaded page.
+ has_reached_quiescence = (
+ self.EvaluateJavaScript(self._quiescence_js +
+ "window.__telemetry_testHasReachedNetworkQuiescence()"))
+ return has_reached_quiescence
+
def ExecuteJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
"""Executes expr in JavaScript. Does not return the result.
« no previous file with comments | « tools/telemetry/telemetry/core/network_quiescence.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698