1 BenchmarkRunnerState = Utilities.createClass(
10 currentSuite: function()
12 return this._suites[this._suiteIndex];
15 currentTest: function()
17 var suite = this.currentSuite();
18 return suite ? suite.tests[this._testIndex] : null;
21 isFirstTest: function()
23 return !this._testIndex;
30 var suite = this._suites[this._suiteIndex];
31 if (suite && this._testIndex < suite.tests.length)
37 } while (this._suiteIndex < this._suites.length && this._suites[this._suiteIndex].disabled);
40 prepareCurrentTest: function(runner, frame)
42 var test = this.currentTest();
43 var promise = new SimplePromise;
45 frame.onload = function() {
49 frame.src = "tests/" + test.url;
54 BenchmarkRunner = Utilities.createClass(
55 function(suites, frameContainer, client)
57 this._suites = suites;
58 this._client = client;
59 this._frameContainer = frameContainer;
62 _appendFrame: function()
64 var frame = document.createElement("iframe");
65 frame.setAttribute("scrolling", "no");
67 this._frameContainer.insertBefore(frame, this._frameContainer.firstChild);
72 _removeFrame: function()
75 this._frame.parentNode.removeChild(this._frame);
80 _runBenchmarkAndRecordResults: function(state)
82 var promise = new SimplePromise;
83 var suite = state.currentSuite();
84 var test = state.currentTest();
86 if (this._client && this._client.willRunTest)
87 this._client.willRunTest(suite, test);
89 var contentWindow = this._frame.contentWindow;
92 var options = { complexity: test.complexity };
93 Utilities.extendObject(options, this._client.options);
94 Utilities.extendObject(options, contentWindow.Utilities.parseParameters());
96 var benchmark = new contentWindow.benchmarkClass(options);
97 document.body.style.backgroundColor = benchmark.backgroundColor();
98 benchmark.run().then(function(results) {
99 var suiteResults = self._suitesResults[suite.name] || {};
100 suiteResults[test.name] = results;
101 self._suitesResults[suite.name] = suiteResults;
103 if (self._client && self._client.didRunTest)
104 self._client.didRunTest(suite, test);
107 if (state.currentSuite() != suite)
109 promise.resolve(state);
115 step: function(state)
118 state = new BenchmarkRunnerState(this._suites);
119 this._suitesResults = {};
122 var suite = state.currentSuite();
125 var promise = new SimplePromise;
130 if (state.isFirstTest()) {
134 return state.prepareCurrentTest(this, this._frame).then(function(prepareReturnValue) {
135 return this._runBenchmarkAndRecordResults(state);
139 runAllSteps: function(startingState)
141 var nextCallee = this.runAllSteps.bind(this);
142 this.step(startingState).then(function(nextState) {
144 nextCallee(nextState);
148 runMultipleIterations: function()
151 var currentIteration = 0;
153 this._runNextIteration = function() {
155 if (currentIteration < self._client.iterationCount)
157 else if (this._client && this._client.didFinishLastIteration) {
158 document.body.style.backgroundColor = "";
159 self._client.didFinishLastIteration();
163 if (this._client && this._client.willStartFirstIteration)
164 this._client.willStartFirstIteration();
169 _finalize: function()
173 if (this._client && this._client.didRunSuites)
174 this._client.didRunSuites(this._suitesResults);
176 if (this._runNextIteration)
177 this._runNextIteration();