From e4d4a7a870172e737eace6c81accffb326430260 Mon Sep 17 00:00:00 2001 From: David Fugate <dfugate@microsoft.com> Date: Thu, 3 Feb 2011 16:28:52 -0800 Subject: [PATCH] test\harness\helper.js: extended the 'finished' method to accept as input the total elapsed execution time of the tests. Emit this to the activity bar test\harness\sta.js: too many years of Python had me thinking JavaScript arrays have an append method:) Fixed. Also, added a pickled representation of all test helper functions found in this file test\harness\sth.js: detached most test helper functions from the iframe's document object (as globals) and inject these into the actual test cases. It's a bit slower and not as elegant, but it is cleaner from an ES5 purist perspective. Still need to move Sputnik helper functions into sta.js Extended Controller such that it now measures overall test execution time. Such a change is very useful for measuring performance-impact changes such as the aforementioned improvement --- test/harness/helper.js | 4 ++-- test/harness/sta.js | 22 ++++++++++--------- test/harness/sth.js | 25 +++++++++++++--------- website/resources/scripts/global/helper.js | 4 ++-- website/resources/scripts/global/sta.js | 22 ++++++++++--------- website/resources/scripts/global/sth.js | 25 +++++++++++++--------- 6 files changed, 58 insertions(+), 44 deletions(-) diff --git a/test/harness/helper.js b/test/harness/helper.js index 28d3405016..fb3d044283 100644 --- a/test/harness/helper.js +++ b/test/harness/helper.js @@ -289,9 +289,9 @@ function Presenter() { renderCurrentSection(); } - this.finished = function() { + this.finished = function(elapsed) { $('.button-start').attr('src', 'resources/images/start.png'); - activityBar.text(''); + activityBar.text('Overall Execution Time: ' + elapsed + ' minutes'); } /* Refresh display of the report */ diff --git a/test/harness/sta.js b/test/harness/sta.js index 90a8c6e0c1..fd3873438a 100644 --- a/test/harness/sta.js +++ b/test/harness/sta.js @@ -38,7 +38,7 @@ function compareArray(aExpected, aActual) { } return true; } -SimpleTestAPIs.append(compareArray); +SimpleTestAPIs.push(compareArray); //----------------------------------------------------------------------------- function arrayContains(arr, expected) { @@ -57,7 +57,7 @@ function arrayContains(arr, expected) { } return true; } -SimpleTestAPIs.append(arrayContains); +SimpleTestAPIs.push(arrayContains); //----------------------------------------------------------------------------- var supportsArrayIndexGettersOnArrays = undefined; @@ -81,7 +81,7 @@ function fnSupportsArrayIndexGettersOnArrays() { return supportsArrayIndexGettersOnArrays; } -SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnArrays); +SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnArrays); //----------------------------------------------------------------------------- var supportsArrayIndexGettersOnObjects = undefined; @@ -104,13 +104,13 @@ function fnSupportsArrayIndexGettersOnObjects() { return supportsArrayIndexGettersOnObjects; } -SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnObjects); +SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnObjects); //----------------------------------------------------------------------------- function ConvertToFileUrl(pathStr) { return "file:" + pathStr.replace(/\\/g, "/"); } -SimpleTestAPIs.append(ConvertToFileUrl); +SimpleTestAPIs.push(ConvertToFileUrl); //----------------------------------------------------------------------------- function fnExists(/*arguments*/) { @@ -119,7 +119,7 @@ function fnExists(/*arguments*/) { } return true; } -SimpleTestAPIs.append(fnExists); +SimpleTestAPIs.push(fnExists); //----------------------------------------------------------------------------- var supportsStrict = undefined; @@ -137,13 +137,13 @@ function fnSupportsStrict() { } return supportsStrict; } -SimpleTestAPIs.append(fnSupportsStrict); +SimpleTestAPIs.push(fnSupportsStrict); //----------------------------------------------------------------------------- function fnGlobalObject() { return (function() { return this }).call(null); } -SimpleTestAPIs.append(fnGlobalObject); +SimpleTestAPIs.push(fnGlobalObject); //----------------------------------------------------------------------------- //Verify all attributes specified data property of given object: value, writable, enumerable, configurable @@ -207,7 +207,7 @@ function dataPropertyAttributesAreCorrect(obj, name, value, writable, enumerable return attributesCorrect; } -SimpleTestAPIs.append(dataPropertyAttributesAreCorrect); +SimpleTestAPIs.push(dataPropertyAttributesAreCorrect); //----------------------------------------------------------------------------- //Verify all attributes specified accessor property of given object: get, set, enumerable, configurable @@ -273,4 +273,6 @@ function accessorPropertyAttributesAreCorrect(obj, name, get, set, setVerifyHelp return attributesCorrect; } -SimpleTestAPIs.append(accessorPropertyAttributesAreCorrect); \ No newline at end of file +SimpleTestAPIs.push(accessorPropertyAttributesAreCorrect); +//----------------------------------------------------------------------------- +var PickledSimpleTestAPIs = SimpleTestAPIs.join(" "); \ No newline at end of file diff --git a/test/harness/sth.js b/test/harness/sth.js index 35729e70a5..40bd303bdc 100644 --- a/test/harness/sth.js +++ b/test/harness/sth.js @@ -91,20 +91,12 @@ function BrowserRunner() { // Set up some globals. win.testRun = testRun; win.testFinished = testFinished; - win.fnSupportsStrict = fnSupportsStrict; - win.fnExists = fnExists; - win.ConvertToFileUrl = ConvertToFileUrl; - win.fnSupportsArrayIndexGettersOnObjects = fnSupportsArrayIndexGettersOnObjects; - win.fnSupportsArrayIndexGettersOnArrays = fnSupportsArrayIndexGettersOnArrays; - win.arrayContains = arrayContains; - win.compareArray = compareArray; + //TODO: these should be moved to sta.js win.SputnikError = SputnikError; win.$ERROR = $ERROR; win.$FAIL = $FAIL; win.$PRINT = function () {}; win.$INCLUDE = function() {}; - win.dataPropertyAttributesAreCorrect = dataPropertyAttributesAreCorrect; - win.accessorPropertyAttributesAreCorrect = accessorPropertyAttributesAreCorrect; if(includes !== null) { // We have some includes, so loop through each include and pull in the dependencies. @@ -125,6 +117,10 @@ function BrowserRunner() { } } + //Write out all of our helper functions + doc.writeln("<script type='text/javascript'>" + PickledSimpleTestAPIs + "</script>"); + + // Write ES5Harness.registerTest and fnGlobalObject, which returns the global object, and the testFinished call. doc.writeln("<script type='text/javascript'>ES5Harness = {};" + "function fnGlobalObject() { return window; }" + @@ -243,6 +239,8 @@ function Controller() { var runner = new BrowserRunner(); var loader = new TestLoader(); var controller = this; + var startTime; + var elapsed = 0; runner.onComplete = function(test) { presenter.addTestResult(test); @@ -268,21 +266,28 @@ function Controller() { loader.onTestsExhausted = function() { state = 'stopped'; - presenter.finished(); + elapsed += new Date() - startTime; + elapsed = elapsed/(1000*60); //minutes + elapsed = elapsed.toFixed(1); + presenter.finished(elapsed); } this.start = function() { state = 'running'; + startTime = new Date(); loader.getNextTest(); presenter.started(); } this.pause = function() { + elapsed += new Date() - startTime; state = 'paused'; presenter.paused(); } this.reset = function() { + startTime = new Date(); + elapsed = 0; loader.reset(); presenter.reset(); } diff --git a/website/resources/scripts/global/helper.js b/website/resources/scripts/global/helper.js index 28d3405016..fb3d044283 100644 --- a/website/resources/scripts/global/helper.js +++ b/website/resources/scripts/global/helper.js @@ -289,9 +289,9 @@ function Presenter() { renderCurrentSection(); } - this.finished = function() { + this.finished = function(elapsed) { $('.button-start').attr('src', 'resources/images/start.png'); - activityBar.text(''); + activityBar.text('Overall Execution Time: ' + elapsed + ' minutes'); } /* Refresh display of the report */ diff --git a/website/resources/scripts/global/sta.js b/website/resources/scripts/global/sta.js index 90a8c6e0c1..fd3873438a 100644 --- a/website/resources/scripts/global/sta.js +++ b/website/resources/scripts/global/sta.js @@ -38,7 +38,7 @@ function compareArray(aExpected, aActual) { } return true; } -SimpleTestAPIs.append(compareArray); +SimpleTestAPIs.push(compareArray); //----------------------------------------------------------------------------- function arrayContains(arr, expected) { @@ -57,7 +57,7 @@ function arrayContains(arr, expected) { } return true; } -SimpleTestAPIs.append(arrayContains); +SimpleTestAPIs.push(arrayContains); //----------------------------------------------------------------------------- var supportsArrayIndexGettersOnArrays = undefined; @@ -81,7 +81,7 @@ function fnSupportsArrayIndexGettersOnArrays() { return supportsArrayIndexGettersOnArrays; } -SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnArrays); +SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnArrays); //----------------------------------------------------------------------------- var supportsArrayIndexGettersOnObjects = undefined; @@ -104,13 +104,13 @@ function fnSupportsArrayIndexGettersOnObjects() { return supportsArrayIndexGettersOnObjects; } -SimpleTestAPIs.append(fnSupportsArrayIndexGettersOnObjects); +SimpleTestAPIs.push(fnSupportsArrayIndexGettersOnObjects); //----------------------------------------------------------------------------- function ConvertToFileUrl(pathStr) { return "file:" + pathStr.replace(/\\/g, "/"); } -SimpleTestAPIs.append(ConvertToFileUrl); +SimpleTestAPIs.push(ConvertToFileUrl); //----------------------------------------------------------------------------- function fnExists(/*arguments*/) { @@ -119,7 +119,7 @@ function fnExists(/*arguments*/) { } return true; } -SimpleTestAPIs.append(fnExists); +SimpleTestAPIs.push(fnExists); //----------------------------------------------------------------------------- var supportsStrict = undefined; @@ -137,13 +137,13 @@ function fnSupportsStrict() { } return supportsStrict; } -SimpleTestAPIs.append(fnSupportsStrict); +SimpleTestAPIs.push(fnSupportsStrict); //----------------------------------------------------------------------------- function fnGlobalObject() { return (function() { return this }).call(null); } -SimpleTestAPIs.append(fnGlobalObject); +SimpleTestAPIs.push(fnGlobalObject); //----------------------------------------------------------------------------- //Verify all attributes specified data property of given object: value, writable, enumerable, configurable @@ -207,7 +207,7 @@ function dataPropertyAttributesAreCorrect(obj, name, value, writable, enumerable return attributesCorrect; } -SimpleTestAPIs.append(dataPropertyAttributesAreCorrect); +SimpleTestAPIs.push(dataPropertyAttributesAreCorrect); //----------------------------------------------------------------------------- //Verify all attributes specified accessor property of given object: get, set, enumerable, configurable @@ -273,4 +273,6 @@ function accessorPropertyAttributesAreCorrect(obj, name, get, set, setVerifyHelp return attributesCorrect; } -SimpleTestAPIs.append(accessorPropertyAttributesAreCorrect); \ No newline at end of file +SimpleTestAPIs.push(accessorPropertyAttributesAreCorrect); +//----------------------------------------------------------------------------- +var PickledSimpleTestAPIs = SimpleTestAPIs.join(" "); \ No newline at end of file diff --git a/website/resources/scripts/global/sth.js b/website/resources/scripts/global/sth.js index 35729e70a5..40bd303bdc 100644 --- a/website/resources/scripts/global/sth.js +++ b/website/resources/scripts/global/sth.js @@ -91,20 +91,12 @@ function BrowserRunner() { // Set up some globals. win.testRun = testRun; win.testFinished = testFinished; - win.fnSupportsStrict = fnSupportsStrict; - win.fnExists = fnExists; - win.ConvertToFileUrl = ConvertToFileUrl; - win.fnSupportsArrayIndexGettersOnObjects = fnSupportsArrayIndexGettersOnObjects; - win.fnSupportsArrayIndexGettersOnArrays = fnSupportsArrayIndexGettersOnArrays; - win.arrayContains = arrayContains; - win.compareArray = compareArray; + //TODO: these should be moved to sta.js win.SputnikError = SputnikError; win.$ERROR = $ERROR; win.$FAIL = $FAIL; win.$PRINT = function () {}; win.$INCLUDE = function() {}; - win.dataPropertyAttributesAreCorrect = dataPropertyAttributesAreCorrect; - win.accessorPropertyAttributesAreCorrect = accessorPropertyAttributesAreCorrect; if(includes !== null) { // We have some includes, so loop through each include and pull in the dependencies. @@ -125,6 +117,10 @@ function BrowserRunner() { } } + //Write out all of our helper functions + doc.writeln("<script type='text/javascript'>" + PickledSimpleTestAPIs + "</script>"); + + // Write ES5Harness.registerTest and fnGlobalObject, which returns the global object, and the testFinished call. doc.writeln("<script type='text/javascript'>ES5Harness = {};" + "function fnGlobalObject() { return window; }" + @@ -243,6 +239,8 @@ function Controller() { var runner = new BrowserRunner(); var loader = new TestLoader(); var controller = this; + var startTime; + var elapsed = 0; runner.onComplete = function(test) { presenter.addTestResult(test); @@ -268,21 +266,28 @@ function Controller() { loader.onTestsExhausted = function() { state = 'stopped'; - presenter.finished(); + elapsed += new Date() - startTime; + elapsed = elapsed/(1000*60); //minutes + elapsed = elapsed.toFixed(1); + presenter.finished(elapsed); } this.start = function() { state = 'running'; + startTime = new Date(); loader.getNextTest(); presenter.started(); } this.pause = function() { + elapsed += new Date() - startTime; state = 'paused'; presenter.paused(); } this.reset = function() { + startTime = new Date(); + elapsed = 0; loader.reset(); presenter.reset(); } -- GitLab