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

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

Issue 178363005: [Telemetry] Measure power in tab_switching measurement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extreneous change Created 6 years, 10 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
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 dd04e3ce0a9fee4c3be53b8b9fbbe959915238fc..e619ae3222638a27c3494d4d00b735920a5bc2a2 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,12 @@ class WebContents(object):
def __init__(self, inspector_backend):
self._inspector_backend = inspector_backend
+ self._has_reached_quiescence = False
+ self._quiescence_js_loaded = False
+ with open(os.path.join(os.path.dirname(__file__),
+ 'time_since_last_response.js')) as f:
+ self._quiescence_js = f.read()
+
def Close(self):
"""Closes this page.
@@ -46,6 +54,28 @@ 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."""
+ # The script that provides the function window.timeSinceLastResponseMs()
+ # needs to be loaded for this function, but it must be loaded AFTER
+ # PageMeasurement's WillNavigateToPage function is called, otherwise it will
+ # not be available here. The script should only be re-loaded once per page
+ # so that variables in the script get reset only for a new page.
+ if not self._quiescence_js_loaded:
+ self.ExecuteJavaScript(self._quiescence_js)
+ self._quiescence_js_loaded = True
+
+ if (self._has_reached_quiescence):
+ return True
+ time_since_last_response_ms = (
+ self.EvaluateJavaScript("window.timeSinceLastResponseAfterLoadMs()"))
+ self._has_reached_quiescence = time_since_last_response_ms > 2000
+ return self._has_reached_quiescence
+
def ExecuteJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
"""Executes expr in JavaScript. Does not return the result.

Powered by Google App Engine
This is Rietveld 408576698