Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / tools / page_cycler / webpagereplay / start.js
blob6ff5e6dc9c6c216feb23968d1cc72e1fccc649df
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.
5 // webpagereplay/start.js - Start Web Page Replay (WPR) test.
6 //
7 // This script is included by webpagereplay/start.html.
8 // The query parameter "test=TEST_NAME" is required to load the
9 // test configuration from webpagereplay/tests/TEST_NAME.js
10 // That JavaScript file defines a global, "pageSets", as a list of lists:
11 // [ [url_1, url_2], [url_3], ...],
12 // - Before each sublist:
13 // Run chrome.browingData.remove and close the connections.
14 // - Before each url in a sublist:
15 // Close the connections.
17 // These WPR tests use a Chrome extension to load the test URLs.
18 // The extension loads the test configuration via a DOM elemment
19 // (id=json). This script sets the content of that DOM element.
21 // The test runs immediately after being loaded.
25 var options = location.search.substring(1).split('&');
26 function getopt(name) {
27 var r = new RegExp('^' + name + '=');
28 for (i = 0; i < options.length; ++i) {
29 if (options[i].match(r)) {
30 return options[i].substring(name.length + 1);
33 return null;
36 function LoadTestConfigurationScript(testUrl, callback) {
37 var testjs = document.createElement('script');
38 testjs.type = 'text/javascript';
39 testjs.async = true;
40 testjs.src = testUrl
41 var s = document.getElementsByTagName('script')[0];
42 testjs.addEventListener('load', callback, false);
43 s.parentNode.insertBefore(testjs, s);
46 function ReloadIfStuck() {
47 setTimeout(function() {
48 var status = document.getElementById('status');
49 // The status text is set to 'STARTING' by the extension.
50 if (status.textContent != 'STARTING') {
51 console.log('Benchmark stuck? Reloading.');
52 window.location.reload(true);
54 }, 30000);
57 function RenderForm() {
58 var form = document.createElement('FORM');
59 form.setAttribute('action', 'start.html');
61 var label = document.createTextNode('Iterations: ');
62 form.appendChild(label);
64 var input = document.createElement('INPUT');
65 var iterations = getopt('iterations');
66 input.setAttribute('name', 'iterations');
67 input.setAttribute('value', iterations ? iterations : '5');
68 form.appendChild(input);
70 form.appendChild(document.createElement('P'));
72 var label = document.createTextNode('Test: ');
73 form.appendChild(label);
75 var input = document.createElement('INPUT');
76 input.setAttribute('name', 'test');
77 var test = getopt('test');
78 input.setAttribute('value', test ? test : '');
79 form.appendChild(input);
81 var input = document.createElement('INPUT');
82 input.setAttribute('name', 'auto');
83 var auto = getopt('auto');
84 input.setAttribute('value', 1);
85 input.setAttribute('type', 'hidden');
86 form.appendChild(input);
88 form.appendChild(document.createElement('P'));
90 input = document.createElement('INPUT');
91 input.setAttribute('type', 'submit');
92 input.setAttribute('value', 'Start');
93 form.appendChild(input);
95 document.getElementById('startform').appendChild(form);
99 var iterations = getopt('iterations');
100 var test_name = getopt('test');
101 var is_auto_start = getopt('auto');
103 RenderForm();
104 if (test_name) {
105 var testUrl = 'tests/' + test_name + '.js';
106 LoadTestConfigurationScript(testUrl, function() {
107 var testConfig = {};
108 if (iterations) {
109 testConfig['iterations'] = iterations;
111 // The pageSets global is set by test configuration script.
112 testConfig['pageSets'] = pageSets;
114 if (is_auto_start) {
115 testConfig['shouldStart'] = 1;
116 ReloadIfStuck();
118 // Write testConfig to "json" DOM element for the Chrome extension.
119 document.getElementById('json').textContent = JSON.stringify(testConfig);
121 } else {
122 console.log('Need "test=TEST_NAME" query parameter.');