Elim cr-checkbox
[chromium-blink-merge.git] / chrome / test / data / third_party / spaceport / js / index.js
blobb9d6123682a84981923a495558769f223d889b81
1 define([ 'tests/performance', 'testDom', 'testRunner', 'tables', 'util/report', 'util/ensureCallback', 'fullReport' ], function (performance, testDom, testRunner, tables, report, ensureCallback, fullReport) {
2 function testDone(err, name, results) {
3 var domId = name.replace(/[^a-z0-9]/gi, '-');
4 testDom.endTest(domId, err, results);
7 function allTestsDone(err, results) {
8 if (err) {
9 console.error(err);
10 return;
13 var allTestResultsEl = document.getElementById('all-test-results');
14 allTestResultsEl.textContent = fullReport.csvReport(results);
17 registerOnLoad(function () {
18 var table = report.tableTemplate('performance-sprites', report.makeTableLayout(tables.performance.sprites));
19 var tablePlaceholder = document.getElementById('performance-sprites-placeholder');
20 tablePlaceholder.parentNode.replaceChild(table, tablePlaceholder);
22 table = report.tableTemplate('performance-text', report.makeTableLayout(tables.performance.text));
23 tablePlaceholder = document.getElementById('performance-text-placeholder');
24 tablePlaceholder.parentNode.replaceChild(table, tablePlaceholder);
26 var performanceTestsRunning = false;
27 var runPerformanceTestsButton = document.getElementById('start-performance-tests');
28 var uploadPerformanceTestsButton = document.getElementById('upload-performance-tests');
30 function setRunning(isRunning) {
31 performanceTestsRunning = isRunning;
32 runPerformanceTestsButton.disabled = isRunning;
33 uploadPerformanceTestsButton.disabled = isRunning;
36 function runPerformanceTests(callback) {
37 callback = ensureCallback(callback);
39 window.scrollTo(0, 0);
41 testRunner.run('performance', performance, {
42 done: function (err, results) {
43 allTestsDone(err, results);
44 callback(err, results);
46 step: function (err, name, results) {
47 shortName = name.replace('performance.sprites.image.', '');
48 if (results) {
49 console.log(shortName + ": " + results.objectCount);
50 } else {
51 console.log(shortName + ": 0");
53 return testDone(err, name, results);
55 });
58 function runAndUploadPerformanceTests(callback) {
59 callback = ensureCallback(callback);
61 runPerformanceTests(function (err, results) {
62 if (err) return callback(err);
64 var xhr = new XMLHttpRequest();
65 xhr.onreadystatechange = function () {
66 if (xhr.readyState === 4) {
67 // Complete
68 callback(null);
71 xhr.open('POST', 'results', true);
72 xhr.send(JSON.stringify({
73 agentMetadata: fullReport.getAgentMetadata(),
74 results: results
75 }));
76 });
79 setRunning(false);
81 runPerformanceTestsButton.addEventListener('click', function () {
82 if (performanceTestsRunning) {
83 throw new Error('Tests already running');
86 setRunning(true);
88 runPerformanceTests(function (err, results) {
89 setRunning(false);
90 });
91 }, false);
93 uploadPerformanceTestsButton.addEventListener('click', function () {
94 if (performanceTestsRunning) {
95 throw new Error('Tests already running');
98 setRunning(true);
100 runAndUploadPerformanceTests(function (err, results) {
101 setRunning(false);
103 }, false);
105 var getVars = { };
106 if (/^\?/.test(location.search)) {
107 location.search.substr(1).split(/&/g).forEach(function (part) {
108 var equalsIndex = part.indexOf('=');
110 if (equalsIndex >= 0) {
111 getVars[part.substr(0, equalsIndex)] = part.substr(equalsIndex + 1);
112 } else {
113 getVars[part] = true;
118 if ('auto' in getVars) {
119 runPerformanceTests();