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

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: Ready for review. Created 8 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
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..05b8ed60024d9d35dddd4db088d124cc29d586ba
--- /dev/null
+++ b/tools/page_cycler/webpagereplay/extension/start.js
@@ -0,0 +1,86 @@
+// 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;
+ }
+
+ try {
+ var testDir = dirname(window.location.pathname);
+ var reportUrl = "file://" + dirname(dirname(testDir)) +
+ "/common/report.html";
+ config["testDir"] = testDir;
+ config["reportUrl"] = reportUrl;
+ 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);

Powered by Google App Engine
This is Rietveld 408576698