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
) {
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.', '');
49 console
.log(shortName
+ ": " + results
.objectCount
);
51 console
.log(shortName
+ ": 0");
53 return testDone(err
, name
, results
);
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) {
71 xhr
.open('POST', 'results', true);
72 xhr
.send(JSON
.stringify({
73 agentMetadata
: fullReport
.getAgentMetadata(),
81 runPerformanceTestsButton
.addEventListener('click', function () {
82 if (performanceTestsRunning
) {
83 throw new Error('Tests already running');
88 runPerformanceTests(function (err
, results
) {
93 uploadPerformanceTestsButton
.addEventListener('click', function () {
94 if (performanceTestsRunning
) {
95 throw new Error('Tests already running');
100 runAndUploadPerformanceTests(function (err
, results
) {
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);
113 getVars
[part
] = true;
118 if ('auto' in getVars
) {
119 runPerformanceTests();