1 // Copyright (c) 2011 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.title = 'page cycler'; 6 7 // The __pages is assumed an array which containing the directories for 8 // various pages to exercise. Some page cycler tests don't have this variable. 9 10 var initialPage; 11 var hasVariablePages = (typeof __pages != 'undefined') && 12 (__pages instanceof Array); 13 if (hasVariablePages) 14 initialPage = __pages[0]; 15 16 document.cookie = '__navigated_to_report=0; path=/'; 17 document.cookie = '__pc_done=0; path=/'; 18 if (hasVariablePages) 19 document.cookie = '__pc_pages=' + __pages + '; path=/'; 20 document.cookie = '__pc_timings=; path=/'; 21 22 var options = location.search.substring(1).split('&'); 23 24 function getopt(name) { 25 var r = new RegExp('^' + name + '='); 26 for (var i = 0; i < options.length; ++i) { 27 if (options[i].match(r)) { 28 return options[i].substring(name.length + 1); 29 } 30 } 31 return null; 32 } 33 34 function start() { 35 var iterations = document.getElementById('iterations').value; 36 window.resizeTo(800, 800); 37 var ts = (new Date()).getTime(); 38 var url = ''; 39 if (hasVariablePages) 40 url = initialPage + '/'; 41 url += 'index.html?n=' + iterations + '&i=0&p=0&ts=' + ts + '&td=0'; 42 window.location = url; 43 } 44 45 function render_form() { 46 var form = document.createElement('FORM'); 47 form.onsubmit = function(e) { 48 start(); 49 e.preventDefault(); 50 }; 51 52 var label = document.createTextNode('Iterations: '); 53 form.appendChild(label); 54 55 var input = document.createElement('INPUT'); 56 input.setAttribute('id', 'iterations'); 57 input.setAttribute('type', 'number'); 58 var iterations = getopt('iterations'); 59 input.setAttribute('value', iterations ? iterations : '5'); 60 form.appendChild(input); 61 62 input = document.createElement('INPUT'); 63 input.setAttribute('type', 'submit'); 64 input.setAttribute('value', 'Start'); 65 form.appendChild(input); 66 67 document.body.appendChild(form); 68 } 69 70 render_form(); 71 72 // should we start automatically? 73 if (location.search.match('auto=1')) { 74 start(); 75 } else { 76 if (!window.gc) { 77 document.write('<h3 style=\'color:red\'>WARNING: window.gc is not ' + 78 'defined. Test results may be unreliable! You must ' + 79 'started chrome also with <tt>--js-flags=\"--expose_gc\"' + 80 '</tt> for this test to work manually</h3>'); 81 } 82 } 83