OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 document.cookie = "__navigated_to_report=0; path=/"; |
| 6 document.cookie = "__pc_done=0; path=/"; |
| 7 document.cookie = "__pc_timings=; path=/"; |
| 8 |
| 9 function dirname(path) { |
| 10 var match = path.match(/(.*)\//); |
| 11 if (match) { |
| 12 return match[1]; |
| 13 } else { |
| 14 return "."; |
| 15 } |
| 16 } |
| 17 |
| 18 function IsWprRecordMode() { |
| 19 var kStatusUrl = "http://wprwprwpr/web-page-replay-command-status"; |
| 20 var isRecordMode; |
| 21 var xhr = new XMLHttpRequest(); |
| 22 var useAsync = false; |
| 23 xhr.open("GET", kStatusUrl, useAsync); |
| 24 xhr.timeout = 500; |
| 25 xhr.onreadystatechange = function() { |
| 26 if (xhr.readyState == 4 && xhr.status == 200) { |
| 27 var status = JSON.parse(xhr.responseText); |
| 28 isRecordMode = status["is_record_mode"]; |
| 29 console.log("WPR record mode?: " + isRecordMode); |
| 30 } |
| 31 }; |
| 32 try { |
| 33 xhr.send(); |
| 34 } catch(e) { |
| 35 throw "Web Page Replay is not responding. Start WPR to continue." |
| 36 } |
| 37 return isRecordMode; |
| 38 } |
| 39 |
| 40 |
| 41 function TryStart() { |
| 42 console.log("try start"); |
| 43 var status_element = document.getElementById("status"); |
| 44 |
| 45 var config_json; |
| 46 var config; |
| 47 try { |
| 48 config_json = document.getElementById("json").textContent; |
| 49 config = JSON.parse(config_json); |
| 50 } catch(err) { |
| 51 console.log("Bad json data: " + config_json); |
| 52 status_element.textContent = "Exception: " + err + "\njson data: " + |
| 53 config_json; |
| 54 return; |
| 55 } |
| 56 var isRecordMode = false; |
| 57 try { |
| 58 isRecordMode = IsWprRecordMode(); |
| 59 } catch (err) { |
| 60 status_element.textContent = err; |
| 61 setTimeout(TryStart, 5000); |
| 62 return; |
| 63 } |
| 64 |
| 65 if (!config["shouldStart"]) { |
| 66 status_element.textContent = |
| 67 "Press 'Start' to continue (or load this page with 'auto=1')."; |
| 68 return; |
| 69 } |
| 70 |
| 71 try { |
| 72 var reportDir = dirname(dirname(window.location.pathname)) + "/common"; |
| 73 config["reportUrl"] = "file://" + reportDir + "/report.html"; |
| 74 config["isRecordMode"] = isRecordMode; |
| 75 var port = chrome.extension.connect(); |
| 76 port.postMessage({message: "start", benchmark: config}); |
| 77 console.log("sending start message: page count, " + |
| 78 config["pageSets"].length); |
| 79 } catch(err) { |
| 80 console.log("TryStart retrying after exception: " + err); |
| 81 status_element.textContent = "Exception: " + err; |
| 82 setTimeout(TryStart, 1000); |
| 83 return; |
| 84 } |
| 85 status_element.textContent = "STARTING"; |
| 86 } |
| 87 |
| 88 // We wait before starting the test just to let chrome warm up better. |
| 89 setTimeout(TryStart, 250); |
OLD | NEW |