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

Unified Diff: tools/page_cycler/webpagereplay/extension/start.js

Issue 9956045: Add Web Page Replay test to page cycler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows compile error. Created 8 years, 8 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/page_cycler/webpagereplay/extension/start.js
diff --git a/tools/page_cycler/webpagereplay/extension/start.js b/tools/page_cycler/webpagereplay/extension/start.js
new file mode 100644
index 0000000000000000000000000000000000000000..3250edbb90d5326573928413d1357dbcea47c94c
--- /dev/null
+++ b/tools/page_cycler/webpagereplay/extension/start.js
@@ -0,0 +1,89 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+document.cookie = "__navigated_to_report=0; path=/";
+document.cookie = "__pc_done=0; path=/";
+document.cookie = "__pc_timings=; path=/";
+
+function dirname(path) {
+ var match = path.match(/(.*)\//);
+ if (match) {
+ return match[1];
+ } else {
+ return ".";
+ }
+}
+
+function IsWprRecordMode() {
+ var kStatusUrl = "http://wprwprwpr/web-page-replay-command-status";
+ var isRecordMode;
+ var xhr = new XMLHttpRequest();
+ var useAsync = false;
+ xhr.open("GET", kStatusUrl, useAsync);
+ xhr.timeout = 500;
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4 && xhr.status == 200) {
+ var status = JSON.parse(xhr.responseText);
+ isRecordMode = status["is_record_mode"];
+ console.log("WPR record mode?: " + isRecordMode);
+ }
+ };
+ try {
+ xhr.send();
+ } catch(e) {
+ throw "Web Page Replay is not responding. Start WPR to continue."
+ }
+ return isRecordMode;
+}
+
+
+function TryStart() {
+ console.log("try start");
+ var status_element = document.getElementById("status");
+
+ var config_json;
+ var config;
+ try {
+ config_json = document.getElementById("json").textContent;
+ config = JSON.parse(config_json);
+ } catch(err) {
+ console.log("Bad json data: " + config_json);
+ status_element.textContent = "Exception: " + err + "\njson data: " +
+ config_json;
+ return;
+ }
+ var isRecordMode = false;
+ try {
+ isRecordMode = IsWprRecordMode();
+ } catch (err) {
+ status_element.textContent = err;
+ setTimeout(TryStart, 5000);
+ return;
+ }
+
+ if (!config["shouldStart"]) {
+ status_element.textContent =
+ "Press 'Start' to continue (or load this page with 'auto=1').";
+ return;
+ }
+
+ try {
+ var reportDir = dirname(dirname(window.location.pathname)) + "/common";
+ config["reportUrl"] = "file://" + reportDir + "/report.html";
+ config["isRecordMode"] = isRecordMode;
+ var port = chrome.extension.connect();
+ port.postMessage({message: "start", benchmark: config});
+ console.log("sending start message: page count, " +
+ config["pageSets"].length);
+ } catch(err) {
+ console.log("TryStart retrying after exception: " + err);
+ status_element.textContent = "Exception: " + err;
+ setTimeout(TryStart, 1000);
+ return;
+ }
+ status_element.textContent = "STARTING";
+}
+
+// We wait before starting the test just to let chrome warm up better.
+setTimeout(TryStart, 250);
« no previous file with comments | « tools/page_cycler/webpagereplay/extension/page_cycler.js ('k') | tools/page_cycler/webpagereplay/start.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698