Permalink
Browse files

ehanson - merged experimental1 branch into trunk

  • Loading branch information...
1 parent c54b448 commit 16a70b2b2bf96a80adca1d0fa6144dd61e3ba59b ehanson committed May 6, 2008
View
36 app/BaseUiManager.js
@@ -0,0 +1,36 @@
+JsUnit.BaseUiManager = function() {
+}
+
+JsUnit.BaseUiManager.prototype.makeHTMLSafe = function (string) {
+ string = string.replace(/&/g, '&');
+ string = string.replace(/</g, '&lt;');
+ string = string.replace(/>/g, '&gt;');
+ return string;
+}
+
+JsUnit.BaseUiManager.prototype.problemDetailMessageFor = function (excep) {
+ if (excep.isJsUnitFailure) {
+ var result = '';
+ if (excep.comment != null)
+ result += ('"' + excep.comment + '"\n');
+
+ result += excep.jsUnitMessage;
+
+ if (excep.stackTrace)
+ result += '\n\nStack trace follows:\n' + excep.stackTrace;
+ return result;
+ }
+ else {
+ var result = 'Error message is:\n"';
+ result +=
+ (typeof(excep.description) == 'undefined') ?
+ excep :
+ excep.description;
+ result += '"';
+
+ if (typeof(excep.stack) != 'undefined') // Mozilla only
+ result += '\n\nStack trace follows:\n' + excep.stack;
+ return result;
+ }
+}
+
View
288 app/ClassicUiManager.js
@@ -0,0 +1,288 @@
+JsUnit.ClassicUiManager = function(testManager) {
+ this._testManager = testManager;
+}
+
+JsUnit.Util.inherit(JsUnit.BaseUiManager, JsUnit.ClassicUiManager);
+
+JsUnit.ClassicUiManager.prototype.onLoad = function(mainFrame) {
+ var mainData = mainFrame.frames.mainData;
+
+ // form elements on mainData frame
+ this.testFileName = mainData.document.testRunnerForm.testFileName;
+ this.runButton = mainData.document.testRunnerForm.runButton;
+ this.stopButton = mainData.document.testRunnerForm.stopButton;
+ this.traceLevel = mainData.document.testRunnerForm.traceLevel;
+ this.closeTraceWindowOnNewRun = mainData.document.testRunnerForm.closeTraceWindowOnNewRun;
+ this.timeout = mainData.document.testRunnerForm.timeout;
+ this.setUpPageTimeout = mainData.document.testRunnerForm.setUpPageTimeout;
+
+ // image output
+ this.progressBar = mainFrame.frames.mainProgress.document.progress;
+
+ this.problemsListField = mainFrame.frames.mainErrors.document.testRunnerForm.problemsList;
+
+ // 'layer' output frames
+ this.uiFrames = new Object();
+ this.uiFrames.mainStatus = mainFrame.frames.mainStatus;
+
+ var mainCounts = mainFrame.frames.mainCounts;
+
+ this.uiFrames.mainCountsErrors = mainCounts.frames.mainCountsErrors;
+ this.uiFrames.mainCountsFailures = mainCounts.frames.mainCountsFailures;
+ this.uiFrames.mainCountsRuns = mainCounts.frames.mainCountsRuns;
+
+ this._windowForAllProblemMessages = null;
+
+ this._traceWindow = null;
+ this.popupWindowsBlocked = false;
+}
+
+JsUnit.ClassicUiManager.prototype.getUiFrameUrl = function() {
+ return './app/main-frame.html';
+}
+
+JsUnit.ClassicUiManager.prototype.getTestFileName = function() {
+ return this.testFileName.value;
+}
+
+JsUnit.ClassicUiManager.prototype.getTraceLevel = function() {
+ var levelNumber = eval(this.traceLevel.value);
+ return JsUnitTraceLevel.findByLevelNumber(levelNumber);
+}
+
+JsUnit.ClassicUiManager.prototype.starting = function () {
+ this._setRunButtonEnabled(false);
+ this._clearProblemsList();
+
+ this.initializeTracer();
+
+ var traceLevel = this.getTraceLevel();
+ if (traceLevel != JsUnitTraceLevel.NONE) {
+ this.openTracer();
+ }
+}
+
+JsUnit.ClassicUiManager.prototype.finishing = function () {
+ this._setRunButtonEnabled(true);
+
+ this.finalizeTracer();
+}
+
+JsUnit.ClassicUiManager.prototype.submittingResults = function () {
+ this.runButton.disabled = true;
+ this.stopButton.disabled = true;
+}
+
+JsUnit.ClassicUiManager.prototype.initializeTracer = function() {
+ if (this._traceWindow != null && this.closeTraceWindowOnNewRun.checked)
+ this._traceWindow.close();
+ this._traceWindow = null;
+}
+
+JsUnit.ClassicUiManager.prototype.finalizeTracer = function() {
+ if (this._traceWindow != null) {
+ this._traceWindow.document.write('<\/body>\n<\/html>');
+ this._traceWindow.document.close();
+ }
+}
+
+JsUnit.ClassicUiManager.prototype.openTracer = function() {
+ var traceWindow = this._getTraceWindow();
+ if (traceWindow) {
+ traceWindow.focus();
+ }
+ else {
+ this.fatalError('Tracing requires popup windows, and popups are blocked in your browser.\n\nPlease enable popups if you wish to use tracing.');
+ }
+}
+
+JsUnit.ClassicUiManager.prototype._clearProblemsList = function () {
+ var listField = this.problemsListField;
+ var initialLength = listField.options.length;
+
+ for (var i = 0; i < initialLength; i++)
+ listField.remove(0);
+}
+
+JsUnit.ClassicUiManager.prototype._setRunButtonEnabled = function (b) {
+ this.runButton.disabled = !b;
+ this.stopButton.disabled = b;
+}
+
+JsUnit.ClassicUiManager.prototype._setTextOnLayer = function (layerName, str) {
+ try {
+ var content;
+ if (content = this.uiFrames[layerName].document.getElementById('content'))
+ content.innerHTML = str;
+ else
+ throw new Error("No content div found.");
+ }
+ catch (e) {
+ var html = '';
+ html += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
+ html += '<html><head><link rel="stylesheet" type="text/css" href="css/jsUnitStyle.css"><\/head>';
+ html += '<body><div id="content">';
+ html += str;
+ html += '<\/div><\/body>';
+ html += '<\/html>';
+ this.uiFrames[layerName].document.write(html);
+ this.uiFrames[layerName].document.close();
+ }
+}
+
+JsUnit.ClassicUiManager.prototype.setStatus = function (str) {
+ this._setTextOnLayer('mainStatus', '<b>Status:<\/b> ' + str);
+}
+
+JsUnit.ClassicUiManager.prototype._setErrors = function (n) {
+ this._setTextOnLayer('mainCountsErrors', '<b>Errors: <\/b>' + n);
+}
+
+JsUnit.ClassicUiManager.prototype._setFailures = function (n) {
+ this._setTextOnLayer('mainCountsFailures', '<b>Failures:<\/b> ' + n);
+}
+
+JsUnit.ClassicUiManager.prototype._setTotal = function (n) {
+ this._setTextOnLayer('mainCountsRuns', '<b>Runs:<\/b> ' + n);
+}
+
+JsUnit.ClassicUiManager.prototype._setProgressBarImage = function (imgName) {
+ this.progressBar.src = imgName;
+}
+
+JsUnit.ClassicUiManager.prototype._setProgressBarWidth = function (w) {
+ this.progressBar.width = w;
+}
+
+JsUnit.ClassicUiManager.prototype.updateProgressIndicators = function (totalCount, errorCount, failureCount, progressBarProportion) {
+ this._setTotal(totalCount);
+ this._setErrors(errorCount);
+ this._setFailures(failureCount);
+ this._setProgressBarWidth(300 * progressBarProportion);
+
+ if (errorCount > 0 || failureCount > 0)
+ this._setProgressBarImage('../images/red.gif');
+ else
+ this._setProgressBarImage('../images/green.gif');
+}
+
+JsUnit.ClassicUiManager.prototype.testCompleted = function (test) {
+ if (test.status != 'success') {
+ var listField = this.problemsListField;
+ var exceptionText = this.problemDetailMessageFor(test.exception);
+ this._testManager._addOption(listField, exceptionText, test.message);
+ }
+}
+
+JsUnit.ClassicUiManager.prototype.showMessageForSelectedProblemTest = function () {
+ var problemTestIndex = this.problemsListField.selectedIndex;
+ if (problemTestIndex != -1)
+ this.fatalError(this.problemsListField[problemTestIndex].value);
+}
+
+JsUnit.ClassicUiManager.prototype.showMessagesForAllProblemTests = function () {
+ if (this.problemsListField.length == 0)
+ return;
+
+ this._tryToCloseWindow(this._windowForAllProblemMessages);
+
+ var body = '<p>Tests with problems (' + this.problemsListField.length + ' total) - JsUnit<\/p>'
+ + '<p>Running on ' + navigator.userAgent + '</p>';
+
+ for (var i = 0; i < this.problemsListField.length; i++) {
+ body += '<p class="jsUnitDefault">';
+ body += '<b>' + (i + 1) + '. ';
+ body += this.problemsListField[i].text;
+ body += '<\/b><\/p><p><pre>';
+ body += this.makeHTMLSafe(this.problemsListField[i].value);
+ body += '<\/pre><\/p>';
+ }
+
+ this._windowForAllProblemMessages = this._createWindow("Tests with problems", body);
+}
+
+JsUnit.ClassicUiManager.prototype.showLog = function() {
+ this._tryToCloseWindow(this.logWindow);
+
+ var body = "<pre>";
+
+ var log = this._testManager.log;
+ for (var i = 0; i < log.length; i++) {
+ body += log[i];
+ body += "\n";
+ }
+
+ body += "</pre>";
+
+ this.logWindow = this._createWindow("Log", body);
+}
+
+JsUnit.ClassicUiManager.prototype._tryToCloseWindow = function(w) {
+ try {
+ if (w && !w.closed) w.close();
+ } catch(e) {
+ }
+}
+
+JsUnit.ClassicUiManager.prototype._createWindow = function(title, body) {
+ var w = window.open('', '', 'width=600, height=350,status=no,resizable=yes,scrollbars=yes');
+ var resDoc = w.document;
+ resDoc.write('<html><head><link rel="stylesheet" href="../css/jsUnitStyle.css"><title>');
+ resDoc.write(title);
+ resDoc.write(' - JsUnit<\/title><head><body>');
+ resDoc.write(body);
+ resDoc.write('<\/body><\/html>');
+ resDoc.close();
+}
+
+
+JsUnit.ClassicUiManager.prototype.fatalError = function(aMessage) {
+ if (this._testManager._params.shouldSuppressDialogs()) // todo: huh?
+ this.setStatus(aMessage);
+ else
+ alert(aMessage);
+}
+
+JsUnit.ClassicUiManager.prototype.userConfirm = function(aMessage) {
+ if (this._testManager._params.shouldSuppressDialogs()) // todo: huh?
+ return false;
+ else
+ return confirm(aMessage);
+}
+
+JsUnit.ClassicUiManager.prototype.addedTraceData = function(theTest, traceMessage) {
+ if (this.getTraceLevel().matches(traceMessage.traceLevel)) {
+ var traceString = traceMessage.message;
+ if (traceMessage.value)
+ traceString += ': ' + traceMessage.value;
+ var prefix = theTest.testPage.url + ":" + theTest.testName + " - ";
+ this._writeToTraceWindow(prefix, traceString, traceMessage.traceLevel);
+ }
+}
+
+JsUnit.ClassicUiManager.prototype._writeToTraceWindow = function(prefix, traceString, traceLevel) {
+ var htmlToAppend = '<p class="jsUnitDefault">' + prefix + '<font color="' + traceLevel.getColor() + '">' + traceString + '</font><\/p>\n';
+ this._getTraceWindow().document.write(htmlToAppend);
+}
+
+JsUnit.ClassicUiManager.prototype._getTraceWindow = function() {
+ if (this._traceWindow == null && !this._testManager._params.shouldSubmitResults() && !this.popupWindowsBlocked) {
+ this._traceWindow = window.open('', '', 'width=600, height=350,status=no,resizable=yes,scrollbars=yes');
+ if (!this._traceWindow)
+ this.popupWindowsBlocked = true;
+ else {
+ var resDoc = this._traceWindow.document;
+ resDoc.write('<html>\n<head>\n<link rel="stylesheet" href="css/jsUnitStyle.css">\n<title>Tracing - JsUnit<\/title>\n<head>\n<body>');
+ resDoc.write('<h2>Tracing - JsUnit<\/h2>\n');
+ resDoc.write('<p class="jsUnitDefault"><i>(Traces are color coded: ');
+ resDoc.write('<font color="' + JsUnitTraceLevel.WARNING.getColor() + '">Warning</font> - ');
+ resDoc.write('<font color="' + JsUnitTraceLevel.INFO.getColor() + '">Information</font> - ');
+ resDoc.write('<font color="' + JsUnitTraceLevel.DEBUG.getColor() + '">Debug</font>');
+ resDoc.write(')</i></p>');
+ }
+ }
+ return this._traceWindow;
+}
+
+JsUnit.ClassicUiManager.prototype.learnedOfTestPage = function() {
+}
View
281 app/ModernUiManager.js
@@ -0,0 +1,281 @@
+Function.prototype.bind = function() {
+ var __method = this, args = Array.prototype.slice.call(arguments, 1), object = arguments[0];
+ return function() {
+ return __method.apply(object, args.concat(Array.prototype.slice.call(arguments)));
+ }
+}
+
+JsUnit.ModernUiManager = function(testManager) {
+ this._testManager = testManager;
+
+ this._recentlyUpdated = [];
+ this._recentlyUpdatedClearTime = 0;
+}
+
+JsUnit.Util.inherit(JsUnit.BaseUiManager, JsUnit.ModernUiManager);
+
+JsUnit.ModernUiManager.prototype.onLoad = function(uiWindow) {
+ this._uiWindow = uiWindow;
+ this._uiDoc = uiWindow.document;
+
+ this._testFileInput = this._uiDoc.getElementById("testFileInput");
+
+ this._statusTextNode = this._findTextNode("status");
+ this._runCountTextNode = this._findTextNode("runCount");
+ this._errorCountTextNode = this._findTextNode("errorCount");
+ this._failureCountTextNode = this._findTextNode("failureCount");
+ this._elapsedTimeTextNode = this._findTextNode("elapsedTime");
+
+ this._progressBar = this._uiDoc.getElementById("progress");
+
+ // tests info area
+ this._testsInfoDiv = this._uiDoc.getElementById("testsInfo");
+ this._testsInfoCompleteDiv = this._uiDoc.getElementById("testsInfoComplete");
+ this._testsInfoCurrentSuiteDiv = this._uiDoc.getElementById("testsInfoCurrentSuite");
+ this._testsInfoCurrentTestTextNode = this._findTextNode("testsInfoCurrentTest");
+
+ this._testResultTestDiv = this._uiDoc.getElementById("testResultTest");
+ this._testResultDetailsDiv = this._uiDoc.getElementById("testResultDetails");
+
+ this.showPassed(false);
+}
+
+JsUnit.ModernUiManager.prototype.getUiFrameUrl = function() {
+ return './app/modernUi.html';
+}
+
+JsUnit.ModernUiManager.prototype.getTestFileName = function() {
+ return this._testFileInput.value;
+}
+
+JsUnit.ModernUiManager.prototype.getTraceLevel = function() {
+ return JsUnitTraceLevel.NONE;
+}
+
+JsUnit.ModernUiManager.prototype.starting = function () {
+ this._testsInfoCompleteDiv.innerHTML = '';
+}
+
+JsUnit.ModernUiManager.prototype.submittingResults = function () {
+}
+
+JsUnit.ModernUiManager.prototype.showMessageForSelectedProblemTest = function () {
+}
+
+JsUnit.ModernUiManager.prototype.showMessagesForAllProblemTests = function () {
+}
+
+JsUnit.ModernUiManager.prototype.showLog = function() {
+}
+
+JsUnit.ModernUiManager.prototype.fatalError = function(aMessage) {
+ if (this._testManager._params.shouldSuppressDialogs()) // todo: huh?
+ this.setStatus(aMessage);
+ else
+ alert(aMessage);
+}
+
+JsUnit.ModernUiManager.prototype.userConfirm = function(aMessage) {
+ if (this._testManager._params.shouldSuppressDialogs()) // todo: huh?
+ return false;
+ else
+ return confirm(aMessage);
+}
+
+Object.extend = function(obj, extendWith) {
+ for (var name in extendWith) {
+ obj[name] = extendWith[name];
+ }
+}
+
+Object.extend(JsUnit.ModernUiManager.prototype, {
+ _findTextNode: function(id) {
+ var element = this._uiDoc.getElementById(id);
+ if (element.childNodes.length == 1) {
+ return element.childNodes[0];
+ }
+ var node = this._uiDoc.createTextNode("");
+ element.appendChild(node);
+ return node;
+ },
+
+ _setSpanText: function(span, text) {
+ span.innerHTML = text;
+ },
+
+ _setTextNode: function(textNode, text) {
+ textNode.data = text;
+ },
+
+ setStatus: function(str) {
+ this._setTextNode(this._statusTextNode, str);
+ },
+
+ _addRecentlyUpdated: function(element) {
+ var cssClasses = element.getAttribute("class");
+ if (cssClasses.indexOf(" recentlyUpdated") > -1) return;
+
+ element.setAttribute("class", cssClasses + " recentlyUpdated");
+ this._recentlyUpdated.push(element);
+
+ this._testsInfoDiv.scrollTop = element.offsetTop - 30;
+ },
+
+ _clearRecentlyUpdated: function(clearAll) {
+ if (this._recentlyUpdated.length == 0) return;
+
+ var time = new Date().getTime();
+ if (!clearAll && time < this._recentlyUpdatedClearTime + 250) return;
+ this._recentlyUpdatedClearTime = time;
+ var lastToClear = this._recentlyUpdated.length;
+ if (!clearAll) lastToClear--;
+ for (var i = 0; i < lastToClear; i++) {
+ var element = this._recentlyUpdated[i];
+ var cssClasses = element.getAttribute("class").replace(" recentlyUpdated", "");
+ element.setAttribute("class", cssClasses);
+ }
+ },
+
+ finishing: function () {
+ this._clearRecentlyUpdated(true);
+ this._setTextNode(this._testsInfoCurrentTestTextNode, "");
+ },
+
+ _setProgressBarImage: function (imgName) {
+ this._progressBar.src = imgName;
+ },
+
+ _setProgressBarWidth: function (w) {
+ this._progressBar.width = w;
+ },
+
+ updateProgressIndicators: function (totalCount, errorCount, failureCount, progressBarProportion) {
+ this._setTextNode(this._runCountTextNode, totalCount);
+ this._setTextNode(this._errorCountTextNode, errorCount);
+ this._setTextNode(this._failureCountTextNode, failureCount);
+ this._setProgressBarWidth(300 * progressBarProportion);
+
+ if (errorCount > 0 || failureCount > 0)
+ this._setProgressBarImage('../images/red.gif');
+ else
+ this._setProgressBarImage('../images/green.gif');
+
+// this._setTextNode(this._elapsedTimeTextNode, this.elapsedTime());
+ },
+
+ learnedOfTestPage: function(testPage) {
+ testPage.headerElement = this._uiDoc.createElement("li");
+ testPage.headerElement.innerHTML = testPage.url;
+
+ testPage.testListElement = this._uiDoc.createElement("ul");
+
+ this._testsInfoCompleteDiv.appendChild(testPage.headerElement);
+ this._testsInfoCompleteDiv.appendChild(testPage.testListElement);
+
+ this._testPageUpdate(testPage, JsUnit.TestPage.STATUS_CHANGE_EVENT);
+ testPage.listen(this._testPageUpdate.bind(this));
+ },
+
+ _testPageUpdate: function(testPage, event) {
+ if (event == JsUnit.TestPage.READY_EVENT) {
+ for (var i = 0; i < testPage.tests.length; i++) {
+ var theTest = testPage.tests[i];
+ theTest.listen(this.testCompleted.bind(this));
+ this._displayTestResult(theTest);
+ }
+ }
+ testPage.headerElement.setAttribute("class", "testPage " + testPage.getStatus());
+ this._addRecentlyUpdated(testPage.headerElement);
+ },
+
+ testCompleted: function(test) {
+ this._updateTestResultStatus(test);
+ },
+
+
+ _showDetails: function(theTest) {
+ var div = theTest.div;
+ this._testResultTestDiv.innerHTML = theTest.testPage.url + "." + theTest.testName;
+ var text;
+ switch (theTest.status) {
+ case 'success':
+ text = "Test succeeded!";
+ break;
+ case 'failure':
+ case 'error':
+ text = theTest.message + ":\n";
+ text += this.problemDetailMessageFor(theTest.exception);
+ break;
+ default:
+ throw new Error("unknown status '" + theTest.status + "'");
+ }
+
+ var traceMessages = theTest.traceMessages;
+ if (traceMessages.length > 0) {
+ text += "<blockquote>";
+ for (var i = 0; i < traceMessages.length; i++) {
+ text += "<span style=\"color: " + traceMessages[i].traceLevel.getColor() + "\">";
+ text += traceMessages[i].message;
+ text += "</span>\n";
+ }
+ text += "</blockquote>";
+ }
+
+ text = this.makeHTMLSafe(text).split('\n').join("\n<br />\n");
+ text = text.replace(/(Stack trace follows:\n)/, "$1<div class=\"stackTrace\">") + "</div>";
+ this._testResultDetailsDiv.innerHTML = text;
+ },
+
+ _displayTestResult: function(theTest) {
+ var timeTaken = theTest.timeTaken;
+
+ var manager = this;
+ var clicked = function() {
+ manager._showDetails.call(manager, theTest);
+ };
+
+ var div = this._createItem("&nbsp;&nbsp;" + theTest.testName, theTest.status, clicked);
+ theTest.div = div;
+ theTest.testPage.testListElement.appendChild(div);
+ this._updateTestResultStatus(theTest);
+
+ this._testPageUpdate(theTest.testPage);
+ this._clearRecentlyUpdated(false);
+ },
+
+ _updateTestResultStatus: function(theTest) {
+ var element = theTest.div;
+ element.setAttribute("class", "testResult " + theTest.status);
+ this._addRecentlyUpdated(element);
+ },
+
+ _createItem: function(name, status, onClick) {
+ var div = this._uiDoc.createElement("li");
+ if (div.addEventListener) {
+ div.addEventListener("click", onClick, true);
+ } else if (div.attachEvent) {
+ div.attachEvent('on' + "click", onClick);
+ }
+
+// div.addNode(document.createTextNode(theTest.getFunctionName()));
+ div.innerHTML = name;
+ return div;
+ },
+
+ _displayTestException: function(problemValue, problemMessage) {
+ var listField = this.problemsListField;
+ this._addOption(listField, problemValue, problemMessage);
+ },
+
+ addedTraceData: function(theTest, traceMessage) {
+ },
+
+ showPassed: function(shouldShow) {
+ this._testsInfoCompleteDiv.setAttribute("class", shouldShow ? "showPassed" : "hidePassed");
+ },
+
+ _last: null
+
+});
+
+
View
358 app/jsUnitCore.js
@@ -1,18 +1,21 @@
/**
* @fileoverview
- * jsUnitCore.js contains the implementation of the core JsUnit functionality: assertions, JsUnitTestSuites, and JsUnitException.
+ * jsUnitCore.js contains the implementation of the core JsUnit functionality: assertions, JsUnitTestSuites, and JsUnit.Failure.
* An HTML page is considered to be a JsUnit Test Page if it "includes" jsUnitCore.js, i.e. the following line is present:
* <code>
* &lt;script type="text/javascript" src="/path/to/jsUnitCore.js"&gt;&lt;/script&gt;
* </code>
* @author Edward Hieatt, edward@jsunit.net, http://www.jsunit.net
*/
+var JsUnit = {};
+
/**
* The JsUnit version
* @version
*/
-var JSUNIT_VERSION = 2.2;
+JsUnit.VERSION = 2.2;
+var JSUNIT_VERSION = JsUnit.VERSION;
/**
* For convenience, a variable that equals "undefined"
@@ -27,35 +30,35 @@ var isTestPageLoaded = false;
/**
* Predicate used for testing JavaScript == (i.e. equality excluding type)
*/
-var DOUBLE_EQUALITY_PREDICATE = function(var1, var2) {return var1 == var2;};
+JsUnit.DOUBLE_EQUALITY_PREDICATE = function(var1, var2) {return var1 == var2;};
/**
* Predicate used for testing JavaScript === (i.e. equality including type)
*/
-var TRIPLE_EQUALITY_PREDICATE = function(var1, var2) {return var1 === var2;};
+JsUnit.TRIPLE_EQUALITY_PREDICATE = function(var1, var2) {return var1 === var2;};
/**
* Predicate used for testing whether two obects' toStrings are equal
*/
-var TO_STRING_EQUALITY_PREDICATE = function(var1, var2) {return var1.toString() === var2.toString();};
+JsUnit.TO_STRING_EQUALITY_PREDICATE = function(var1, var2) {return var1.toString() === var2.toString();};
/**
* Hash of predicates for testing equality by primitive type
*/
-var PRIMITIVE_EQUALITY_PREDICATES = {
- 'String': DOUBLE_EQUALITY_PREDICATE,
- 'Number': DOUBLE_EQUALITY_PREDICATE,
- 'Boolean': DOUBLE_EQUALITY_PREDICATE,
- 'Date': TRIPLE_EQUALITY_PREDICATE,
- 'RegExp': TO_STRING_EQUALITY_PREDICATE,
- 'Function': TO_STRING_EQUALITY_PREDICATE
+JsUnit.PRIMITIVE_EQUALITY_PREDICATES = {
+ 'String': JsUnit.DOUBLE_EQUALITY_PREDICATE,
+ 'Number': JsUnit.DOUBLE_EQUALITY_PREDICATE,
+ 'Boolean': JsUnit.DOUBLE_EQUALITY_PREDICATE,
+ 'Date': JsUnit.TRIPLE_EQUALITY_PREDICATE,
+ 'RegExp': JsUnit.TO_STRING_EQUALITY_PREDICATE,
+ 'Function': JsUnit.TO_STRING_EQUALITY_PREDICATE
}
/**
* Hack for NS62 bug
* @private
*/
-function _jsUnitFixTop() {
+JsUnit._fixTop = function() {
var tempTop = top;
if (!tempTop) {
tempTop = window;
@@ -73,14 +76,14 @@ function _jsUnitFixTop() {
}
}
-_jsUnitFixTop();
+JsUnit._fixTop();
/**
* @param Any object
* @return String - the type of the given object
* @private
*/
-function _trueTypeOf(something) {
+JsUnit._trueTypeOf = function(something) {
var result = typeof something;
try {
switch (result) {
@@ -133,226 +136,226 @@ function _trueTypeOf(something) {
/**
* @private
*/
-function _displayStringForValue(aVar) {
+JsUnit._displayStringForValue = function(aVar) {
var result = '<' + aVar + '>';
if (!(aVar === null || aVar === JSUNIT_UNDEFINED_VALUE)) {
- result += ' (' + _trueTypeOf(aVar) + ')';
+ result += ' (' + JsUnit._trueTypeOf(aVar) + ')';
}
return result;
}
/**
* @private
*/
-function _argumentsIncludeComments(expectedNumberOfNonCommentArgs, args) {
+JsUnit._argumentsIncludeComments = function(expectedNumberOfNonCommentArgs, args) {
return args.length == expectedNumberOfNonCommentArgs + 1;
}
/**
* @private
*/
-function _commentArg(expectedNumberOfNonCommentArgs, args) {
- if (_argumentsIncludeComments(expectedNumberOfNonCommentArgs, args))
+JsUnit._commentArg = function(expectedNumberOfNonCommentArgs, args) {
+ if (JsUnit._argumentsIncludeComments(expectedNumberOfNonCommentArgs, args))
return args[0];
return null;
}
/**
* @private
*/
-function _nonCommentArg(desiredNonCommentArgIndex, expectedNumberOfNonCommentArgs, args) {
- return _argumentsIncludeComments(expectedNumberOfNonCommentArgs, args) ?
+JsUnit._nonCommentArg = function(desiredNonCommentArgIndex, expectedNumberOfNonCommentArgs, args) {
+ return JsUnit._argumentsIncludeComments(expectedNumberOfNonCommentArgs, args) ?
args[desiredNonCommentArgIndex] :
args[desiredNonCommentArgIndex - 1];
}
/**
* @private
*/
-function _validateArguments(expectedNumberOfNonCommentArgs, args) {
+JsUnit._validateArguments = function(expectedNumberOfNonCommentArgs, args) {
if (!( args.length == expectedNumberOfNonCommentArgs ||
(args.length == expectedNumberOfNonCommentArgs + 1 && (typeof(args[0]) == 'string') || args[0] == null)))
- throw new JsUnitAssertionArgumentError('Incorrect arguments passed to assert function');
+ throw new JsUnit.AssertionArgumentError('Incorrect arguments passed to assert function');
}
/**
* @private
*/
-function _checkEquals(var1, var2) {
+JsUnit._checkEquals = function(var1, var2) {
return var1 === var2;
}
/**
* @private
*/
-function _checkNotUndefined(aVar) {
+JsUnit._checkNotUndefined = function(aVar) {
return aVar !== JSUNIT_UNDEFINED_VALUE;
}
/**
* @private
*/
-function _checkNotNull(aVar) {
+JsUnit._checkNotNull = function(aVar) {
return aVar !== null;
}
/**
* All assertions ultimately go through this method.
* @private
*/
-function _assert(comment, booleanValue, failureMessage) {
+JsUnit._assert = function(comment, booleanValue, failureMessage) {
if (!booleanValue)
- throw new JsUnitFailure(comment, failureMessage);
+ throw new JsUnit.Failure(comment, failureMessage);
}
/**
* Checks that the given boolean value is true.
* @param comment optional, displayed in the case of failure
* @value value that is expected to be true
- * @throws JsUnitFailure if the given value is not true
+ * @throws JsUnit.Failure if the given value is not true
* @throws JsUnitInvalidAssertionArgument if the given value is not a boolean or if an incorrect number of arguments is passed
*/
function assert() {
- _validateArguments(1, arguments);
- var booleanValue = _nonCommentArg(1, 1, arguments);
+ JsUnit._validateArguments(1, arguments);
+ var booleanValue = JsUnit._nonCommentArg(1, 1, arguments);
if (typeof(booleanValue) != 'boolean')
- throw new JsUnitAssertionArgumentError('Bad argument to assert(boolean)');
+ throw new JsUnit.AssertionArgumentError('Bad argument to assert(boolean)');
- _assert(_commentArg(1, arguments), booleanValue === true, 'Call to assert(boolean) with false');
+ JsUnit._assert(JsUnit._commentArg(1, arguments), booleanValue === true, 'Call to assert(boolean) with false');
}
/**
* Synonym for assertTrue
* @see #assert
*/
function assertTrue() {
- _validateArguments(1, arguments);
- assert(_commentArg(1, arguments), _nonCommentArg(1, 1, arguments));
+ JsUnit._validateArguments(1, arguments);
+ assert(JsUnit._commentArg(1, arguments), JsUnit._nonCommentArg(1, 1, arguments));
}
/**
* Checks that a boolean value is false.
* @param comment optional, displayed in the case of failure
* @value value that is expected to be false
- * @throws JsUnitFailure if value is not false
+ * @throws JsUnit.Failure if value is not false
* @throws JsUnitInvalidAssertionArgument if the given value is not a boolean or if an incorrect number of arguments is passed
*/
function assertFalse() {
- _validateArguments(1, arguments);
- var booleanValue = _nonCommentArg(1, 1, arguments);
+ JsUnit._validateArguments(1, arguments);
+ var booleanValue = JsUnit._nonCommentArg(1, 1, arguments);
if (typeof(booleanValue) != 'boolean')
- throw new JsUnitAssertionArgumentError('Bad argument to assertFalse(boolean)');
+ throw new JsUnit.AssertionArgumentError('Bad argument to assertFalse(boolean)');
- _assert(_commentArg(1, arguments), booleanValue === false, 'Call to assertFalse(boolean) with true');
+ JsUnit._assert(JsUnit._commentArg(1, arguments), booleanValue === false, 'Call to assertFalse(boolean) with true');
}
/**
* Checks that two values are equal (using ===)
* @param comment optional, displayed in the case of failure
* @param expected the expected value
* @param actual the actual value
- * @throws JsUnitFailure if the values are not equal
+ * @throws JsUnit.Failure if the values are not equal
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertEquals() {
- _validateArguments(2, arguments);
- var var1 = _nonCommentArg(1, 2, arguments);
- var var2 = _nonCommentArg(2, 2, arguments);
- _assert(_commentArg(2, arguments), _checkEquals(var1, var2), 'Expected ' + _displayStringForValue(var1) + ' but was ' + _displayStringForValue(var2));
+ JsUnit._validateArguments(2, arguments);
+ var var1 = JsUnit._nonCommentArg(1, 2, arguments);
+ var var2 = JsUnit._nonCommentArg(2, 2, arguments);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), JsUnit._checkEquals(var1, var2), 'Expected ' + JsUnit._displayStringForValue(var1) + ' but was ' + JsUnit._displayStringForValue(var2));
}
/**
* Checks that two values are not equal (using !==)
* @param comment optional, displayed in the case of failure
* @param value1 a value
* @param value2 another value
- * @throws JsUnitFailure if the values are equal
+ * @throws JsUnit.Failure if the values are equal
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertNotEquals() {
- _validateArguments(2, arguments);
- var var1 = _nonCommentArg(1, 2, arguments);
- var var2 = _nonCommentArg(2, 2, arguments);
- _assert(_commentArg(2, arguments), var1 !== var2, 'Expected not to be ' + _displayStringForValue(var2));
+ JsUnit._validateArguments(2, arguments);
+ var var1 = JsUnit._nonCommentArg(1, 2, arguments);
+ var var2 = JsUnit._nonCommentArg(2, 2, arguments);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), var1 !== var2, 'Expected not to be ' + JsUnit._displayStringForValue(var2));
}
/**
* Checks that a value is null
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the value is not null
+ * @throws JsUnit.Failure if the value is not null
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertNull() {
- _validateArguments(1, arguments);
- var aVar = _nonCommentArg(1, 1, arguments);
- _assert(_commentArg(1, arguments), aVar === null, 'Expected ' + _displayStringForValue(null) + ' but was ' + _displayStringForValue(aVar));
+ JsUnit._validateArguments(1, arguments);
+ var aVar = JsUnit._nonCommentArg(1, 1, arguments);
+ JsUnit._assert(JsUnit._commentArg(1, arguments), aVar === null, 'Expected ' + JsUnit._displayStringForValue(null) + ' but was ' + JsUnit._displayStringForValue(aVar));
}
/**
* Checks that a value is not null
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the value is null
+ * @throws JsUnit.Failure if the value is null
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertNotNull() {
- _validateArguments(1, arguments);
- var aVar = _nonCommentArg(1, 1, arguments);
- _assert(_commentArg(1, arguments), _checkNotNull(aVar), 'Expected not to be ' + _displayStringForValue(null));
+ JsUnit._validateArguments(1, arguments);
+ var aVar = JsUnit._nonCommentArg(1, 1, arguments);
+ JsUnit._assert(JsUnit._commentArg(1, arguments), JsUnit._checkNotNull(aVar), 'Expected not to be ' + JsUnit._displayStringForValue(null));
}
/**
* Checks that a value is undefined
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the value is not undefined
+ * @throws JsUnit.Failure if the value is not undefined
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertUndefined() {
- _validateArguments(1, arguments);
- var aVar = _nonCommentArg(1, 1, arguments);
- _assert(_commentArg(1, arguments), aVar === JSUNIT_UNDEFINED_VALUE, 'Expected ' + _displayStringForValue(JSUNIT_UNDEFINED_VALUE) + ' but was ' + _displayStringForValue(aVar));
+ JsUnit._validateArguments(1, arguments);
+ var aVar = JsUnit._nonCommentArg(1, 1, arguments);
+ JsUnit._assert(JsUnit._commentArg(1, arguments), aVar === JSUNIT_UNDEFINED_VALUE, 'Expected ' + JsUnit._displayStringForValue(JSUNIT_UNDEFINED_VALUE) + ' but was ' + JsUnit._displayStringForValue(aVar));
}
/**
* Checks that a value is not undefined
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the value is undefined
+ * @throws JsUnit.Failure if the value is undefined
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertNotUndefined() {
- _validateArguments(1, arguments);
- var aVar = _nonCommentArg(1, 1, arguments);
- _assert(_commentArg(1, arguments), _checkNotUndefined(aVar), 'Expected not to be ' + _displayStringForValue(JSUNIT_UNDEFINED_VALUE));
+ JsUnit._validateArguments(1, arguments);
+ var aVar = JsUnit._nonCommentArg(1, 1, arguments);
+ JsUnit._assert(JsUnit._commentArg(1, arguments), JsUnit._checkNotUndefined(aVar), 'Expected not to be ' + JsUnit._displayStringForValue(JSUNIT_UNDEFINED_VALUE));
}
/**
* Checks that a value is NaN (Not a Number)
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the value is a number
+ * @throws JsUnit.Failure if the value is a number
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertNaN() {
- _validateArguments(1, arguments);
- var aVar = _nonCommentArg(1, 1, arguments);
- _assert(_commentArg(1, arguments), isNaN(aVar), 'Expected NaN');
+ JsUnit._validateArguments(1, arguments);
+ var aVar = JsUnit._nonCommentArg(1, 1, arguments);
+ JsUnit._assert(JsUnit._commentArg(1, arguments), isNaN(aVar), 'Expected NaN');
}
/**
* Checks that a value is not NaN (i.e. is a number)
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the value is not a number
+ * @throws JsUnit.Failure if the value is not a number
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertNotNaN() {
- _validateArguments(1, arguments);
- var aVar = _nonCommentArg(1, 1, arguments);
- _assert(_commentArg(1, arguments), !isNaN(aVar), 'Expected not NaN');
+ JsUnit._validateArguments(1, arguments);
+ var aVar = JsUnit._nonCommentArg(1, 1, arguments);
+ JsUnit._assert(JsUnit._commentArg(1, arguments), !isNaN(aVar), 'Expected not NaN');
}
/**
@@ -361,85 +364,85 @@ function assertNotNaN() {
* @param comment optional, displayed in the case of failure
* @param value the expected value
* @param value the actual value
- * @throws JsUnitFailure if the actual value does not equal the expected value
+ * @throws JsUnit.Failure if the actual value does not equal the expected value
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertObjectEquals() {
- _validateArguments(2, arguments);
- var var1 = _nonCommentArg(1, 2, arguments);
- var var2 = _nonCommentArg(2, 2, arguments);
- var failureMessage = _commentArg(2, arguments) ? _commentArg(2, arguments) : '';
+ JsUnit._validateArguments(2, arguments);
+ var var1 = JsUnit._nonCommentArg(1, 2, arguments);
+ var var2 = JsUnit._nonCommentArg(2, 2, arguments);
+ var failureMessage = JsUnit._commentArg(2, arguments) ? JsUnit._commentArg(2, arguments) : '';
if (var1 === var2)
return;
var isEqual = false;
- var typeOfVar1 = _trueTypeOf(var1);
- var typeOfVar2 = _trueTypeOf(var2);
+ var typeOfVar1 = JsUnit._trueTypeOf(var1);
+ var typeOfVar2 = JsUnit._trueTypeOf(var2);
if (typeOfVar1 == typeOfVar2) {
- var primitiveEqualityPredicate = PRIMITIVE_EQUALITY_PREDICATES[typeOfVar1];
+ var primitiveEqualityPredicate = JsUnit.PRIMITIVE_EQUALITY_PREDICATES[typeOfVar1];
if (primitiveEqualityPredicate) {
isEqual = primitiveEqualityPredicate(var1, var2);
} else {
- var expectedKeys = Utilities.getKeys(var1).sort().join(", ");
- var actualKeys = Utilities.getKeys(var2).sort().join(", ");
+ var expectedKeys = JsUnit.Util.getKeys(var1).sort().join(", ");
+ var actualKeys = JsUnit.Util.getKeys(var2).sort().join(", ");
if (expectedKeys != actualKeys) {
- _assert(failureMessage, false, 'Expected keys "' + expectedKeys + '" but found "' + actualKeys + '"');
+ JsUnit._assert(failureMessage, false, 'Expected keys "' + expectedKeys + '" but found "' + actualKeys + '"');
}
for (var i in var1) {
assertObjectEquals(failureMessage + ' found nested ' + typeOfVar1 + '@' + i + '\n', var1[i], var2[i]);
}
isEqual = true;
}
}
- _assert(failureMessage, isEqual, 'Expected ' + _displayStringForValue(var1) + ' but was ' + _displayStringForValue(var2));
+ JsUnit._assert(failureMessage, isEqual, 'Expected ' + JsUnit._displayStringForValue(var1) + ' but was ' + JsUnit._displayStringForValue(var2));
}
/**
* Checks that an array is equal to another by checking that both are arrays and then comparing their elements using assertObjectEquals
* @param comment optional, displayed in the case of failure
* @param value the expected array
* @param value the actual array
- * @throws JsUnitFailure if the actual value does not equal the expected value
+ * @throws JsUnit.Failure if the actual value does not equal the expected value
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertArrayEquals() {
- _validateArguments(2, arguments);
- var array1 = _nonCommentArg(1, 2, arguments);
- var array2 = _nonCommentArg(2, 2, arguments);
- if (_trueTypeOf(array1) != 'Array' || _trueTypeOf(array2) != 'Array') {
- throw new JsUnitAssertionArgumentError('Non-array passed to assertArrayEquals');
+ JsUnit._validateArguments(2, arguments);
+ var array1 = JsUnit._nonCommentArg(1, 2, arguments);
+ var array2 = JsUnit._nonCommentArg(2, 2, arguments);
+ if (JsUnit._trueTypeOf(array1) != 'Array' || JsUnit._trueTypeOf(array2) != 'Array') {
+ throw new JsUnit.AssertionArgumentError('Non-array passed to assertArrayEquals');
}
- assertObjectEquals(_commentArg(2, arguments), _nonCommentArg(1, 2, arguments), _nonCommentArg(2, 2, arguments));
+ assertObjectEquals(JsUnit._commentArg(2, arguments), JsUnit._nonCommentArg(1, 2, arguments), JsUnit._nonCommentArg(2, 2, arguments));
}
/**
* Checks that a value evaluates to true in the sense that value == true
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the actual value does not evaluate to true
+ * @throws JsUnit.Failure if the actual value does not evaluate to true
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertEvaluatesToTrue() {
- _validateArguments(1, arguments);
- var value = _nonCommentArg(1, 1, arguments);
+ JsUnit._validateArguments(1, arguments);
+ var value = JsUnit._nonCommentArg(1, 1, arguments);
if (!value)
- fail(_commentArg(1, arguments));
+ fail(JsUnit._commentArg(1, arguments));
}
/**
* Checks that a value evaluates to false in the sense that value == false
* @param comment optional, displayed in the case of failure
* @param value the value
- * @throws JsUnitFailure if the actual value does not evaluate to true
+ * @throws JsUnit.Failure if the actual value does not evaluate to true
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertEvaluatesToFalse() {
- _validateArguments(1, arguments);
- var value = _nonCommentArg(1, 1, arguments);
+ JsUnit._validateArguments(1, arguments);
+ var value = JsUnit._nonCommentArg(1, 1, arguments);
if (value)
- fail(_commentArg(1, arguments));
+ fail(JsUnit._commentArg(1, arguments));
}
/**
@@ -449,17 +452,17 @@ function assertEvaluatesToFalse() {
* @param comment optional, displayed in the case of failure
* @param value1 the expected HTML string
* @param value2 the actual HTML string
- * @throws JsUnitFailure if the standardized actual value does not equal the standardized expected value
+ * @throws JsUnit.Failure if the standardized actual value does not equal the standardized expected value
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertHTMLEquals() {
- _validateArguments(2, arguments);
- var var1 = _nonCommentArg(1, 2, arguments);
- var var2 = _nonCommentArg(2, 2, arguments);
- var var1Standardized = Utilities.standardizeHTML(var1);
- var var2Standardized = Utilities.standardizeHTML(var2);
+ JsUnit._validateArguments(2, arguments);
+ var var1 = JsUnit._nonCommentArg(1, 2, arguments);
+ var var2 = JsUnit._nonCommentArg(2, 2, arguments);
+ var var1Standardized = JsUnit.Util.standardizeHTML(var1);
+ var var2Standardized = JsUnit.Util.standardizeHTML(var2);
- _assert(_commentArg(2, arguments), var1Standardized === var2Standardized, 'Expected ' + _displayStringForValue(var1Standardized) + ' but was ' + _displayStringForValue(var2Standardized));
+ JsUnit._assert(JsUnit._commentArg(2, arguments), var1Standardized === var2Standardized, 'Expected ' + JsUnit._displayStringForValue(var1Standardized) + ' but was ' + JsUnit._displayStringForValue(var2Standardized));
}
/**
@@ -469,13 +472,13 @@ function assertHTMLEquals() {
* @param comment optional, displayed in the case of failure
* @param value the expected hash
* @param value the actual hash
- * @throws JsUnitFailure if the actual hash does not evaluate to true
+ * @throws JsUnit.Failure if the actual hash does not evaluate to true
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertHashEquals() {
- _validateArguments(2, arguments);
- var var1 = _nonCommentArg(1, 2, arguments);
- var var2 = _nonCommentArg(2, 2, arguments);
+ JsUnit._validateArguments(2, arguments);
+ var var1 = JsUnit._nonCommentArg(1, 2, arguments);
+ var var2 = JsUnit._nonCommentArg(2, 2, arguments);
for (var key in var1) {
assertNotUndefined("Expected hash had key " + key + " that was not found", var2[key]);
assertEquals(
@@ -494,14 +497,14 @@ function assertHashEquals() {
* @param value1 a value
* @param value1 another value
* @param tolerance the tolerance
- * @throws JsUnitFailure if the two values are not within tolerance of each other
+ * @throws JsUnit.Failure if the two values are not within tolerance of each other
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments is passed
*/
function assertRoughlyEquals() {
- _validateArguments(3, arguments);
- var expected = _nonCommentArg(1, 3, arguments);
- var actual = _nonCommentArg(2, 3, arguments);
- var tolerance = _nonCommentArg(3, 3, arguments);
+ JsUnit._validateArguments(3, arguments);
+ var expected = JsUnit._nonCommentArg(1, 3, arguments);
+ var actual = JsUnit._nonCommentArg(2, 3, arguments);
+ var tolerance = JsUnit._nonCommentArg(3, 3, arguments);
assertTrue(
"Expected " + expected + ", but got " + actual + " which was more than " + tolerance + " away",
Math.abs(expected - actual) < tolerance
@@ -513,13 +516,13 @@ function assertRoughlyEquals() {
* @param comment optional, displayed in the case of failure
* @param collection the collection
* @param value the value
- * @throws JsUnitFailure if the collection does not contain the value
+ * @throws JsUnit.Failure if the collection does not contain the value
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments are passed
*/
function assertContains() {
- _validateArguments(2, arguments);
- var value = _nonCommentArg(1, 2, arguments);
- var collection = _nonCommentArg(2, 2, arguments);
+ JsUnit._validateArguments(2, arguments);
+ var value = JsUnit._nonCommentArg(1, 2, arguments);
+ var collection = JsUnit._nonCommentArg(2, 2, arguments);
assertTrue(
"Expected '" + collection + "' to contain '" + value + "'",
collection.indexOf(value) != -1
@@ -531,26 +534,26 @@ function assertContains() {
* @param comment optional, displayed in the case of failure
* @param array1 first array
* @param array2 second array
- * @throws JsUnitFailure if the two arrays contain different contents
+ * @throws JsUnit.Failure if the two arrays contain different contents
* @throws JsUnitInvalidAssertionArgument if an incorrect number of arguments are passed
*/
function assertArrayEqualsIgnoringOrder() {
- _validateArguments(2, arguments);
- var var1 = _nonCommentArg(1, 2, arguments);
- var var2 = _nonCommentArg(2, 2, arguments);
+ JsUnit._validateArguments(2, arguments);
+ var var1 = JsUnit._nonCommentArg(1, 2, arguments);
+ var var2 = JsUnit._nonCommentArg(2, 2, arguments);
- var notEqualsMessage = "Expected arrays " + _displayStringForValue(var1) + " and " + _displayStringForValue(var2) + " to be equal (ignoring order)";
- var notArraysMessage = "Expected arguments " + _displayStringForValue(var1) + " and " + _displayStringForValue(var2) + " to be arrays";
+ var notEqualsMessage = "Expected arrays " + JsUnit._displayStringForValue(var1) + " and " + JsUnit._displayStringForValue(var2) + " to be equal (ignoring order)";
+ var notArraysMessage = "Expected arguments " + JsUnit._displayStringForValue(var1) + " and " + JsUnit._displayStringForValue(var2) + " to be arrays";
- _assert(_commentArg(2, arguments), _checkNotNull(var1), notEqualsMessage);
- _assert(_commentArg(2, arguments), _checkNotNull(var2), notEqualsMessage);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), JsUnit._checkNotNull(var1), notEqualsMessage);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), JsUnit._checkNotNull(var2), notEqualsMessage);
- _assert(_commentArg(2, arguments), _checkNotUndefined(var1.length), notArraysMessage);
- _assert(_commentArg(2, arguments), _checkNotUndefined(var1.join), notArraysMessage);
- _assert(_commentArg(2, arguments), _checkNotUndefined(var2.length), notArraysMessage);
- _assert(_commentArg(2, arguments), _checkNotUndefined(var2.join), notArraysMessage);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), JsUnit._checkNotUndefined(var1.length), notArraysMessage);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), JsUnit._checkNotUndefined(var1.join), notArraysMessage);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), JsUnit._checkNotUndefined(var2.length), notArraysMessage);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), JsUnit._checkNotUndefined(var2.join), notArraysMessage);
- _assert(_commentArg(1, arguments), _checkEquals(var1.length, var2.length), notEqualsMessage);
+ JsUnit._assert(JsUnit._commentArg(1, arguments), JsUnit._checkEquals(var1.length, var2.length), notEqualsMessage);
for (var i = 0; i < var1.length; i++) {
var found = false;
@@ -561,7 +564,7 @@ function assertArrayEqualsIgnoringOrder() {
} catch (ignored) {
}
}
- _assert(_commentArg(2, arguments), found, notEqualsMessage);
+ JsUnit._assert(JsUnit._commentArg(2, arguments), found, notEqualsMessage);
}
}
@@ -570,16 +573,16 @@ function assertArrayEqualsIgnoringOrder() {
* @see #assertArrayEqualsIgnoringOrder
*/
function assertEqualsIgnoringOrder() {
- _validateArguments(2, arguments);
- assertArrayEqualsIgnoringOrder(_commentArg(2, arguments), _nonCommentArg(1, 2, arguments), _nonCommentArg(2, 2, arguments));
+ JsUnit._validateArguments(2, arguments);
+ assertArrayEqualsIgnoringOrder(JsUnit._commentArg(2, arguments), JsUnit._nonCommentArg(1, 2, arguments), JsUnit._nonCommentArg(2, 2, arguments));
}
/**
* Causes a failure
* @param failureMessage the message for the failure
*/
function fail(failureMessage) {
- throw new JsUnitFailure("Call to fail()", failureMessage);
+ throw new JsUnit.Failure("Call to fail()", failureMessage);
}
/**
@@ -592,13 +595,13 @@ function error(errorMessage) {
/**
* @class
- * A JsUnitFailure represents an assertion failure (or a call to fail()) during the execution of a Test Function
+ * A JsUnit.Failure represents an assertion failure (or a call to fail()) during the execution of a Test Function
* @param comment an optional comment about the failure
* @param message the reason for the failure
*/
-function JsUnitFailure(comment, message) {
+JsUnit.Failure = function(comment, message) {
/**
- * Declaration that this is a JsUnitFailure
+ * Declaration that this is a JsUnit.Failure
* @ignore
*/
this.isJsUnitFailure = true;
@@ -613,32 +616,42 @@ function JsUnitFailure(comment, message) {
/**
* The stack trace at the point at which the failure was encountered
*/
- this.stackTrace = Utilities.getStackTrace();
+ this.stackTrace = JsUnit.Util.getStackTrace();
}
/**
+ * @deprecated
+ */
+JsUnitFailure = JsUnit.Failure;
+
+/**
* @class
* A JsUnitError represents an error (an exception or a call to error()) during the execution of a Test Function
* @param description the reason for the failure
*/
-function JsUnitError(description) {
+JsUnit.Error = function(description) {
/**
* The description of the error
*/
this.description = description;
/**
* The stack trace at the point at which the error was encountered
*/
- this.stackTrace = Utilities.getStackTrace();
+ this.stackTrace = JsUnit.Util.getStackTrace();
}
/**
+ * @deprecated
+ */
+JsUnitError = JsUnit.Error;
+
+/**
* @class
* A JsUnitAssertionArgumentError represents an invalid call to an assertion function - either an invalid argument type
* or an incorrect number of arguments
* @param description a description of the argument error
*/
-function JsUnitAssertionArgumentError(description) {
+JsUnit.AssertionArgumentError = function(description) {
/**
* A description of the argument error
*/
@@ -713,8 +726,8 @@ function JsUnitTestSuite() {
* Adds a Test Page to the suite
* @param pageName the path to the Test Page
*/
-JsUnitTestSuite.prototype.addTestPage = function (pageName) {
- this._testPages[this._testPages.length] = pageName;
+JsUnitTestSuite.prototype.addTestPage = function (page) {
+ this._testPages[this._testPages.length] = page;
}
/**
@@ -765,18 +778,14 @@ function setJsUnitTracer(aJsUnitTracer) {
}
function jsUnitGetParm(name) {
- if (typeof(top.jsUnitParmHash[name]) != 'undefined')
- {
- return top.jsUnitParmHash[name];
- }
- return null;
+ return top.params.get(name);
}
-function newOnLoadEvent() {
+JsUnit._newOnLoadEvent = function() {
isTestPageLoaded = true;
}
-function jsUnitSetOnLoad(windowRef, onloadHandler) {
+JsUnit._setOnLoad = function(windowRef, onloadHandler) {
var isKonqueror = navigator.userAgent.indexOf('Konqueror/') != -1;
if (typeof(windowRef.attachEvent) != 'undefined') {
@@ -808,42 +817,41 @@ function jsUnitSetOnLoad(windowRef, onloadHandler) {
* @constructor
* Contains utility functions for the JsUnit framework
*/
-var Utilities = function() {
-}
+JsUnit.Util = {};
/**
* Standardizes an HTML string by temporarily creating a DIV, setting its innerHTML to the string, and the asking for
* the innerHTML back
* @param html
*/
-Utilities.standardizeHTML = function(html) {
+JsUnit.Util.standardizeHTML = function(html) {
var translator = document.createElement("DIV");
translator.innerHTML = html;
- return Utilities.trim(translator.innerHTML);
+ return JsUnit.Util.trim(translator.innerHTML);
}
/**
* Returns whether the given string is blank after being trimmed of whitespace
* @param string
*/
-Utilities.isBlank = function(string) {
- return Utilities.trim(string) == '';
+JsUnit.Util.isBlank = function(string) {
+ return JsUnit.Util.trim(string) == '';
}
/**
* Implemented here because the JavaScript Array.push(anObject) and Array.pop() functions are not available in IE 5.0
* @param anArray the array onto which to push
* @param anObject the object to push onto the array
*/
-Utilities.push = function(anArray, anObject) {
+JsUnit.Util.push = function(anArray, anObject) {
anArray[anArray.length] = anObject;
}
/**
* Implemented here because the JavaScript Array.push(anObject) and Array.pop() functions are not available in IE 5.0
* @param anArray the array from which to pop
*/
-Utilities.pop = function pop(anArray) {
+JsUnit.Util.pop = function pop(anArray) {
if (anArray.length >= 1) {
delete anArray[anArray.length - 1];
anArray.length--;
@@ -854,7 +862,7 @@ Utilities.pop = function pop(anArray) {
* Returns the name of the given function, or 'anonymous' if it has no name
* @param aFunction
*/
-Utilities.getFunctionName = function(aFunction) {
+JsUnit.Util.getFunctionName = function(aFunction) {
var regexpResult = aFunction.toString().match(/function(\s*)(\w*)/);
if (regexpResult && regexpResult.length >= 2 && regexpResult[2]) {
return regexpResult[2];
@@ -865,12 +873,12 @@ Utilities.getFunctionName = function(aFunction) {
/**
* Returns the current stack trace
*/
-Utilities.getStackTrace = function() {
+JsUnit.Util.getStackTrace = function() {
var result = '';
if (typeof(arguments.caller) != 'undefined') { // IE, not ECMA
for (var a = arguments.caller; a != null; a = a.caller) {
- result += '> ' + Utilities.getFunctionName(a.callee) + '\n';
+ result += '> ' + JsUnit.Util.getFunctionName(a.callee) + '\n';
if (a.caller == a) {
result += '*';
break;
@@ -885,7 +893,7 @@ Utilities.getStackTrace = function() {
}
catch(exception)
{
- var stack = Utilities.parseErrorStack(exception);
+ var stack = JsUnit.Util.parseErrorStack(exception);
for (var i = 1; i < stack.length; i++)
{
result += '> ' + stack[i] + '\n';
@@ -900,7 +908,7 @@ Utilities.getStackTrace = function() {
* Returns an array of stack trace elements from the given exception
* @param exception
*/
-Utilities.parseErrorStack = function(exception) {
+JsUnit.Util.parseErrorStack = function(exception) {
var stack = [];
var name;
@@ -932,7 +940,7 @@ Utilities.parseErrorStack = function(exception) {
* Strips whitespace from either end of the given string
* @param string
*/
-Utilities.trim = function(string) {
+JsUnit.Util.trim = function(string) {
if (string == null)
return null;
@@ -952,12 +960,18 @@ Utilities.trim = function(string) {
return string.substring(startingIndex, endingIndex + 1);
}
-Utilities.getKeys = function(obj) {
+JsUnit.Util.getKeys = function(obj) {
var keys = [];
for (var key in obj) {
- Utilities.push(keys, key);
+ JsUnit.Util.push(keys, key);
}
return keys;
}
-jsUnitSetOnLoad(window, newOnLoadEvent);
+JsUnit.Util.inherit = function(superclass, subclass) {
+ var x = function() {};
+ x.prototype = superclass.prototype;
+ subclass.prototype = new x();
+}
+
+JsUnit._setOnLoad(window, JsUnit._newOnLoadEvent);
View
113 app/jsUnitParams.js
@@ -0,0 +1,113 @@
+JsUnit.Params = function(string) {
+ this.hash = new Object();
+
+ if (!string) return;
+
+ var i = string.indexOf('?');
+ if (i != -1) {
+ string = string.substring(i + 1);
+ }
+
+ var parmList = string.split('&');
+ var a;
+ for (j = 0; j < parmList.length; j++) {
+ a = parmList[j].split('=');
+ a[0] = unescape(a[0].toLowerCase());
+ if (a.length > 1) {
+ this.hash[a[0]] = unescape(a[1]);
+ }
+ else {
+ this.hash[a[0]] = true;
+ }
+ }
+}
+
+JsUnit.Params.prototype.get = function(name) {
+ if (typeof(this.hash[name]) != 'undefined') {
+ return this.hash[name];
+ }
+ return null;
+}
+
+JsUnit.Params.prototype.getTestPage = function() {
+ return this.get('testpage');
+}
+
+JsUnit.Params.prototype.shouldKickOffTestsAutomatically = function() {
+ return this.get('autorun') == "true";
+}
+
+JsUnit.Params.prototype.shouldShowTestFrame = function() {
+ return this.get('showtestframe');
+}
+
+JsUnit.Params.prototype.getShowTestFrameHeight = function() {
+ var param = this.get('showtestframe');
+ return param == "true" ? JsUnitTestManager.DEFAULT_TEST_FRAME_HEIGHT : param;
+}
+
+JsUnit.Params.prototype.shouldSuppressDialogs = function() {
+ return this.shouldSubmitResults() || this.get('suppressdialogs');
+}
+
+JsUnit.Params.prototype.getPageLoadTimeout = function() {
+ return this.get('pageloadtimeout') || JsUnitTestManager.TESTPAGE_WAIT_SEC;
+}
+
+JsUnit.Params.prototype.getSetupPageTimeout = function() {
+ return this.get('setuppagetimeout') || JsUnitTestManager.SETUPPAGE_TIMEOUT;
+}
+
+JsUnit.Params.prototype.getResultId = function() {
+ if (this.get('resultid'))
+ return this.get('resultid');
+ return "";
+}
+
+JsUnit.Params.prototype.getBrowserId = function() {
+ if (this.get('browserid'))
+ return this.get('browserid');
+ return "";
+}
+
+JsUnit.Params.prototype.shouldSubmitResults = function() {
+ return this.get('submitresults');
+}
+
+JsUnit.Params.prototype.getSpecifiedResultUrl = function() {
+ return this.get('submitresults');
+}
+
+JsUnit.Params.prototype.wasResultUrlSpecified = function() {
+ return this.shouldSubmitResults() && this.get('submitresults') != 'true';
+}
+
+JsUnit.Params.prototype.constructTestParams = function() {
+ var parms = '';
+
+ for (var p in this.hash) {
+ var value = this.hash[p];
+
+ if (!value ||
+ p == 'testpage' ||
+ p == 'autorun' ||
+ p == 'submitresults' ||
+ p == 'showtestframe' ||
+ p == 'browserid' ||
+ p == 'resultid') {
+ continue;
+ }
+
+ if (parms) {
+ parms += '&';
+ }
+
+ parms += escape(p);
+
+ if (typeof(value) != 'boolean') {
+ parms += '=' + escape(value);
+ }
+ }
+
+ return parms;
+}
View
726 app/jsUnitTestManager.js
@@ -1,45 +1,140 @@
-function JsUnitTestManager() {
- this.log = [];
+JsUnit.TestGroup = function() {
+ this._testPages = [];
+ this._index = 0;
+}
- this._windowForAllProblemMessages = null;
+JsUnit.TestGroup.prototype.addTestPage = function(testPageUrl) {
+ var testPage = new JsUnit.TestPage(testPageUrl);
+ JsUnit.Util.push(this._testPages, testPage);
+ return testPage;
+}
- this.container = top.frames.testContainer;
- this.documentLoader = top.frames.documentLoader;
- this.mainFrame = top.frames.mainFrame;
+JsUnit.TestGroup.prototype.hasMorePages = function() {
+ return this._index < this._testPages.length;
+}
- this.containerController = this.container.frames.testContainerController;
- this.containerTestFrame = this.container.frames.testFrame;
+JsUnit.TestGroup.prototype.nextPage = function() {
+ return this._testPages[this._index++];
+}
- var mainData = this.mainFrame.frames.mainData;
- // form elements on mainData frame
- this.testFileName = mainData.document.testRunnerForm.testFileName;
- this.runButton = mainData.document.testRunnerForm.runButton;
- this.stopButton = mainData.document.testRunnerForm.stopButton;
- this.traceLevel = mainData.document.testRunnerForm.traceLevel;
- this.closeTraceWindowOnNewRun = mainData.document.testRunnerForm.closeTraceWindowOnNewRun;
- this.timeout = mainData.document.testRunnerForm.timeout;
- this.setUpPageTimeout = mainData.document.testRunnerForm.setUpPageTimeout;
+JsUnit.TestPage = function(url) {
+ this.url = url;
+ this.tests = [];
- // image output
- this.progressBar = this.mainFrame.frames.mainProgress.document.progress;
+ this.running = false;
- this.problemsListField = this.mainFrame.frames.mainErrors.document.testRunnerForm.problemsList;
- this.testCaseResultsField = this.mainFrame.frames.mainResults.document.resultsForm.testCaseResults;
- this.resultsTimeField = this.mainFrame.frames.mainResults.document.resultsForm.time;
+ this.successCount = 0;
+ this.errorCount = 0;
+ this.failureCount = 0;
+
+ this._listeners = [];
+}
- // 'layer' output frames
- this.uiFrames = new Object();
- this.uiFrames.mainStatus = this.mainFrame.frames.mainStatus;
+JsUnit.TestPage.STATUS_CHANGE_EVENT = "statusChange";
+JsUnit.TestPage.READY_EVENT = "ready";
- var mainCounts = this.mainFrame.frames.mainCounts;
+JsUnit.TestPage.prototype.addTest = function(testName) {
+ var test = new JsUnit.Test(this, testName);
+ JsUnit.Util.push(this.tests, test);
+ return test;
+}
+
+JsUnit.TestPage.prototype.listen = function(callback) {
+ JsUnit.Util.push(this._listeners, callback);
+}
+
+JsUnit.TestPage.prototype.notify = function(event) {
+ for (var i = 0; i < this._listeners.length; i++) {
+ this._listeners[i].call(null, this, event);
+ }
+}
+
+JsUnit.TestPage.prototype.getStatus = function(testName) {
+ if (this.tests.length == 0) return 'noTestsYet';
+ if (this.running) return 'running';
+
+ if (this.errorCount > 0) return 'error';
+ if (this.failureCount > 0) return 'failure';
+ if (this.successCount > 0) return 'success';
+ return 'ready';
+}
+
+JsUnit.Test = function(testPage, testName) {
+ this.testPage = testPage;
+ this.testName = testName;
+ this.traceMessages = [];
+ this.status = 'ready';
+
+ this._listeners = [];
+}
+
+JsUnit.Test.prototype.addTraceMessage = function(traceMessage) {
+ this.traceMessages.push(traceMessage);
+}
+
+JsUnit.Test.prototype.listen = function(callback) {
+ JsUnit.Util.push(this._listeners, callback);
+}
+
+JsUnit.Test.prototype.notify = function(event) {
+ for (var i = 0; i < this._listeners.length; i++) {
+ this._listeners[i].call(null, this, event);
+ }
+}
+
+
+JsUnit.TraceMessage = function(message, value, traceLevel) {
+ this.message = message;
+ this.value = value;
+ this.traceLevel = traceLevel;
+}
+
+function JsUnitTestManager(params) {
+ this._params = params || new JsUnit.Params();
+
+ this.log = [];
- this.uiFrames.mainCountsErrors = mainCounts.frames.mainCountsErrors;
- this.uiFrames.mainCountsFailures = mainCounts.frames.mainCountsFailures;
- this.uiFrames.mainCountsRuns = mainCounts.frames.mainCountsRuns;
this._baseURL = "";
this.setup();
+
+ if (this._params.get("ui") == "modern") {
+ this._uiManager = new JsUnit.ModernUiManager(this);
+ } else {
+ this._uiManager = new JsUnit.ClassicUiManager(this);
+ }
+}
+
+JsUnitTestManager.prototype.getUiManager = function() {
+ return this._uiManager;
+}
+
+JsUnitTestManager.prototype.getUiFrameUrl = function() {
+ return this._uiManager.getUiFrameUrl();
+}
+
+// call after all frames have loaded
+JsUnitTestManager.prototype.onLoad = function() {
+ var topLevelFrames = top.frames;
+
+ this.container = topLevelFrames.testContainer;
+ this.documentLoader = topLevelFrames.documentLoader;
+
+ this.containerController = this.container.frames.testContainerController;
+ this.testFrame = this.container.frames.testFrame;
+
+ this._uiManager.onLoad(topLevelFrames.mainFrame);
+
+ this.resultsFrame = topLevelFrames.mainResults;
+ this.resultsForm = this.resultsFrame.document.resultsForm;
+ this.testCaseResultsField = this.resultsFrame.document.resultsForm.testCaseResults;
+ this.resultsTimeField = this.resultsFrame.document.resultsForm.time;
+
+ var testRunnerFrameset = document.getElementById('testRunnerFrameset');
+ if (this._params.shouldShowTestFrame() && testRunnerFrameset) {
+ testRunnerFrameset.rows = '*,0,0,' + this._params.getShowTestFrameHeight();
+ }
}
// seconds to wait for each test page to load
@@ -56,63 +151,117 @@ JsUnitTestManager.SETUPPAGE_INTERVAL = 100;
JsUnitTestManager.RESTORED_HTML_DIV_ID = "jsUnitRestoredHTML";
+JsUnitTestManager.DEFAULT_TEST_FRAME_HEIGHT = 250;
+
+
JsUnitTestManager.prototype.setup = function () {
this.totalCount = 0;
this.errorCount = 0;
this.failureCount = 0;
- this._suiteStack = Array();
+ this._testGroupStack = Array();
+
+ var initialSuite = new JsUnitTestSuite();
+ this.addTestSuite(initialSuite);
+}
+
+JsUnitTestManager.prototype.getTracer = function () {
+ return top.tracer;
+}
+
+JsUnitTestManager.prototype.maybeRun = function () {
+ if (this._params.shouldKickOffTestsAutomatically()) {
+ this.kickOffTests();
+ }
+}
+
+JsUnitTestManager.prototype.addTestSuite = function(testSuite) {
+ var testGroup = new JsUnit.TestGroup();
- var initialSuite = new top.jsUnitTestSuite();
- Utilities.push(this._suiteStack, initialSuite);
+ while (testSuite.hasMorePages()) {
+ var testPage = testGroup.addTestPage(testSuite.nextPage());
+ this.notifyUiOfTestPage(testPage);
+ }
+
+ JsUnit.Util.push(this._testGroupStack, testGroup);
+}
+
+JsUnitTestManager.prototype.kickOffTests = function() {
+ if (JsUnit.Util.isBlank(this.getTestFileName())) {
+ this.fatalError('No Test Page specified.');
+ return;
+ }
+
+ this.setup();
+
+ this._currentTestGroup().addTestPage(this.resolveUserEnteredTestFileName());
+
+ this.start();
}
JsUnitTestManager.prototype.start = function () {
- this._baseURL = this.resolveUserEnteredTestFileName();
- var firstQuery = this._baseURL.indexOf("?");
+ var url = this.resolveUserEnteredTestFileName();
+ this._baseURL = this._determineBaseUrl(url);
+
+ this._timeRunStarted = new Date();
+ this.initialize();
+ setTimeout('top.testManager._nextPage();', JsUnitTestManager.TIMEOUT_LENGTH);
+}
+
+JsUnitTestManager.prototype._determineBaseUrl = function (url) {
+ var firstQuery = url.indexOf("?");
if (firstQuery >= 0) {
- this._baseURL = this._baseURL.substring(0, firstQuery);
+ url = url.substring(0, firstQuery);
}
- var lastSlash = this._baseURL.lastIndexOf("/");
- var lastRevSlash = this._baseURL.lastIndexOf("\\");
+ var lastSlash = url.lastIndexOf("/");
+ var lastRevSlash = url.lastIndexOf("\\");
if (lastRevSlash > lastSlash) {
lastSlash = lastRevSlash;
}
if (lastSlash > 0) {
- this._baseURL = this._baseURL.substring(0, lastSlash + 1);
+ url = url.substring(0, lastSlash + 1);
}
-
- this._timeRunStarted = new Date();
- this.initialize();
- setTimeout('top.testManager._nextPage();', JsUnitTestManager.TIMEOUT_LENGTH);
+ return url;
}
JsUnitTestManager.prototype.getBaseURL = function () {
return this._baseURL;
}
-JsUnitTestManager.prototype.doneLoadingPage = function (pageName) {
- this._testFileName = pageName;
+JsUnitTestManager.prototype.notifyUiOfTestPage = function(testPage) {
+ if (testPage.alreadyNotifiedUi) return;
+
+ this._uiManager.learnedOfTestPage(testPage);
+ testPage.alreadyNotifiedUi = true;
+}
+
+JsUnitTestManager.prototype.doneLoadingPage = function(testPage) {
+ this.notifyUiOfTestPage(testPage);
+ this._currentTestPage = testPage;
if (this.isTestPageSuite())
this._handleNewSuite();
else
{
this._testIndex = 0;
- this._testsInPage = this.getTestFunctionNames();
- this._numberOfTestsInPage = this._testsInPage.length;
+ var testNames = this.getTestFunctionNames();
+ for (var i = 0; i < testNames.length; i++) {
+ testPage.addTest(testNames[i]);
+ }
+ testPage.notify(JsUnit.TestPage.READY_EVENT);
+ this._numberOfTestsInPage = testNames.length;
this._runTest();
}
}
JsUnitTestManager.prototype._handleNewSuite = function () {
- var allegedSuite = this.containerTestFrame.suite();
+ var allegedSuite = this.testFrame.suite();
if (allegedSuite.isJsUnitTestSuite) {
var newSuite = this._cloneTestSuite(allegedSuite);
if (newSuite.containsTestPages())
- Utilities.push(this._suiteStack, newSuite);
+ this.addTestSuite(newSuite);
this._nextPage();
}
else {
- this.fatalError('Invalid test suite in file ' + this._testFileName);
+ this.fatalError('Invalid test suite in file ' + this._currentTestPage.url);
this.abort();
}
}
@@ -127,41 +276,46 @@ JsUnitTestManager.prototype._cloneTestSuite = function(suite) {
}
JsUnitTestManager.prototype._runTest = function () {
- if (this._testIndex + 1 > this._numberOfTestsInPage)
- {
+ if (this._testIndex + 1 > this._numberOfTestsInPage) {
// execute tearDownPage *synchronously*
// (unlike setUpPage which is asynchronous)
- if (typeof this.containerTestFrame.tearDownPage == 'function') {
- this.containerTestFrame.tearDownPage();
+ if (typeof this.testFrame.tearDownPage == 'function') {
+ this.testFrame.tearDownPage();
}
+ this._currentTestPage.running = false;
+ this._currentTestPage.notify(JsUnit.TestPage.STATUS_CHANGE_EVENT);
+
this._nextPage();
return;
}
if (this._testIndex == 0) {
+ this._currentTestPage.running = true;
+ this._currentTestPage.notify(JsUnit.TestPage.STATUS_CHANGE_EVENT);
+
this.storeRestoredHTML();
- if (typeof(this.containerTestFrame.setUpPage) == 'function') {
+ if (typeof(this.testFrame.setUpPage) == 'function') {
// first test for this page and a setUpPage is defined
- if (typeof(this.containerTestFrame.setUpPageStatus) == 'undefined') {
+ if (typeof(this.testFrame.setUpPageStatus) == 'undefined') {
// setUpPage() not called yet, so call it
- this.containerTestFrame.setUpPageStatus = false;
- this.containerTestFrame.startTime = new Date();
- this.containerTestFrame.setUpPage();
+ this.testFrame.setUpPageStatus = false;
+ this.testFrame.startTime = new Date();
+ this.testFrame.setUpPage();
// try test again later
setTimeout('top.testManager._runTest()', JsUnitTestManager.SETUPPAGE_INTERVAL);
return;
}
- if (this.containerTestFrame.setUpPageStatus != 'complete') {
- top.status = 'setUpPage not completed... ' + this.containerTestFrame.setUpPageStatus + ' ' + (new Date());
- if ((new Date() - this.containerTestFrame.startTime) / 1000 > this.getsetUpPageTimeout()) {
+ if (this.testFrame.setUpPageStatus != 'complete') {
+ this.setWindowStatus('setUpPage not completed... ' + this.testFrame.setUpPageStatus + ' ' + (new Date()));
+ if ((new Date() - this.testFrame.startTime) / 1000 > this.getsetUpPageTimeout()) {
this.fatalError('setUpPage timed out without completing.');
if (!this.userConfirm('Retry Test Run?')) {
this.abort();
return;
}
- this.containerTestFrame.startTime = (new Date());
+ this.testFrame.startTime = (new Date());
}
// try test again later
setTimeout('top.testManager._runTest()', JsUnitTestManager.SETUPPAGE_INTERVAL);
@@ -170,15 +324,50 @@ JsUnitTestManager.prototype._runTest = function () {
}
}
- top.status = '';
+ this.setWindowStatus('');
// either not first test, or no setUpPage defined, or setUpPage completed
- this.executeTestFunction(this._testsInPage[this._testIndex]);
+
+ var theTest = this._currentTestPage.tests[this._testIndex];
+ theTest.status = 'running';
+ theTest.notify('statusChange');
+ // todo: need to yield back so display will update here...
+
+ this.executeTestFunction(theTest);
this.totalCount++;
this.updateProgressIndicators();
this._testIndex++;
setTimeout('if (top.testManager) top.testManager._runTest()', JsUnitTestManager.TIMEOUT_LENGTH);
}
+JsUnitTestManager.prototype.setWindowStatus = function(string) {
+ top.status = string;
+}
+
+JsUnitTestManager.prototype._populateHeaderFields = function(id, browserId, userAgent, jsUnitVersion, baseURL) {
+ this.resultsForm.id.value = id;
+ this.resultsForm.browserId.value = browserId;
+ this.resultsForm.userAgent.value = userAgent;
+ this.resultsForm.jsUnitVersion.value = jsUnitVersion;
+ this.resultsForm.url.value = baseURL;
+ this.resultsForm.cacheBuster.value = new Date().getTime();
+}
+
+JsUnitTestManager.prototype._submitResultsForm = function() {
+ var testCasesField = this.testCaseResultsField;
+ for (var i = 0; i < testCasesField.length; i++) {
+ testCasesField[i].selected = true;
+ }
+
+ this.resultsForm.action = this.getSubmitUrl();
+ this.resultsForm.submit();
+}
+
+JsUnitTestManager.prototype.submitResults = function() {
+ this._uiManager.submittingResults();
+ this._populateHeaderFields(this._params.getResultId(), this._params.getBrowserId(), navigator.userAgent, JSUNIT_VERSION, this.resolveUserEnteredTestFileName());
+ this._submitResultsForm();
+}
+
JsUnitTestManager.prototype._done = function () {
var secondsSinceRunBegan = (new Date() - this._timeRunStarted) / 1000;
this.setStatus('Done (' + secondsSinceRunBegan + ' seconds)');
@@ -189,31 +378,32 @@ JsUnitTestManager.prototype._done = function () {
}