PageRenderTime 40ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/doc/example-jsunit/jsunit/app/jsUnitTestManager.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 705 lines | 633 code | 62 blank | 10 comment | 34 complexity | 0b1f4050c676851484bdc6577489896c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. function jsUnitTestManager() {
  2. this._windowForAllProblemMessages = null;
  3. this.container = top.frames.testContainer
  4. this.documentLoader = top.frames.documentLoader;
  5. this.mainFrame = top.frames.mainFrame;
  6. this.containerController = this.container.frames.testContainerController;
  7. this.containerTestFrame = this.container.frames.testFrame;
  8. var mainData = this.mainFrame.frames.mainData;
  9. // form elements on mainData frame
  10. this.testFileName = mainData.document.testRunnerForm.testFileName;
  11. this.runButton = mainData.document.testRunnerForm.runButton;
  12. this.traceLevel = mainData.document.testRunnerForm.traceLevel;
  13. this.closeTraceWindowOnNewRun = mainData.document.testRunnerForm.closeTraceWindowOnNewRun;
  14. this.timeout = mainData.document.testRunnerForm.timeout;
  15. this.setUpPageTimeout = mainData.document.testRunnerForm.setUpPageTimeout;
  16. // image output
  17. this.progressBar = this.mainFrame.frames.mainProgress.document.progress;
  18. this.problemsListField = this.mainFrame.frames.mainErrors.document.testRunnerForm.problemsList;
  19. this.testCaseResultsField = this.mainFrame.frames.mainResults.document.resultsForm.testCases;
  20. this.resultsTimeField = this.mainFrame.frames.mainResults.document.resultsForm.time;
  21. // 'layer' output frames
  22. this.uiFrames = new Object();
  23. this.uiFrames.mainStatus = this.mainFrame.frames.mainStatus;
  24. var mainCounts = this.mainFrame.frames.mainCounts;
  25. this.uiFrames.mainCountsErrors = mainCounts.frames.mainCountsErrors;
  26. this.uiFrames.mainCountsFailures = mainCounts.frames.mainCountsFailures;
  27. this.uiFrames.mainCountsRuns = mainCounts.frames.mainCountsRuns;
  28. this._baseURL = "";
  29. this.setup();
  30. }
  31. // seconds to wait for each test page to load
  32. jsUnitTestManager.TESTPAGE_WAIT_SEC = 120;
  33. jsUnitTestManager.TIMEOUT_LENGTH = 20;
  34. // seconds to wait for setUpPage to complete
  35. jsUnitTestManager.SETUPPAGE_TIMEOUT = 120;
  36. // milliseconds to wait between polls on setUpPages
  37. jsUnitTestManager.SETUPPAGE_INTERVAL = 100;
  38. jsUnitTestManager.RESTORED_HTML_DIV_ID = "jsUnitRestoredHTML";
  39. jsUnitTestManager.prototype.setup = function () {
  40. this.totalCount = 0;
  41. this.errorCount = 0;
  42. this.failureCount = 0;
  43. this._suiteStack = Array();
  44. var initialSuite = new top.jsUnitTestSuite();
  45. push(this._suiteStack, initialSuite);
  46. }
  47. jsUnitTestManager.prototype.start = function () {
  48. this._baseURL = this.resolveUserEnteredTestFileName();
  49. var firstQuery = this._baseURL.indexOf("?");
  50. if (firstQuery >= 0) {
  51. this._baseURL = this._baseURL.substring(0, firstQuery);
  52. }
  53. var lastSlash = this._baseURL.lastIndexOf("/");
  54. var lastRevSlash = this._baseURL.lastIndexOf("\\");
  55. if (lastRevSlash > lastSlash) {
  56. lastSlash = lastRevSlash;
  57. }
  58. if (lastSlash > 0) {
  59. this._baseURL = this._baseURL.substring(0, lastSlash + 1);
  60. }
  61. this._timeRunStarted = new Date();
  62. this.initialize();
  63. setTimeout('top.testManager._nextPage();', jsUnitTestManager.TIMEOUT_LENGTH);
  64. }
  65. jsUnitTestManager.prototype.getBaseURL = function () {
  66. return this._baseURL;
  67. }
  68. jsUnitTestManager.prototype.doneLoadingPage = function (pageName) {
  69. //this.containerTestFrame.setTracer(top.tracer);
  70. this._testFileName = pageName;
  71. if (this.isTestPageSuite())
  72. this._handleNewSuite();
  73. else
  74. {
  75. this._testIndex = 0;
  76. this._testsInPage = this.getTestFunctionNames();
  77. this._numberOfTestsInPage = this._testsInPage.length;
  78. this._runTest();
  79. }
  80. }
  81. jsUnitTestManager.prototype._handleNewSuite = function () {
  82. var allegedSuite = this.containerTestFrame.suite();
  83. if (allegedSuite.isjsUnitTestSuite) {
  84. var newSuite = allegedSuite.clone();
  85. if (newSuite.containsTestPages())
  86. push(this._suiteStack, newSuite);
  87. this._nextPage();
  88. }
  89. else {
  90. this.fatalError('Invalid test suite in file ' + this._testFileName);
  91. this.abort();
  92. }
  93. }
  94. jsUnitTestManager.prototype._runTest = function () {
  95. if (this._testIndex + 1 > this._numberOfTestsInPage)
  96. {
  97. // execute tearDownPage *synchronously*
  98. // (unlike setUpPage which is asynchronous)
  99. if (typeof this.containerTestFrame.tearDownPage == 'function') {
  100. this.containerTestFrame.tearDownPage();
  101. }
  102. this._nextPage();
  103. return;
  104. }
  105. if (this._testIndex == 0) {
  106. this.storeRestoredHTML();
  107. if (typeof(this.containerTestFrame.setUpPage) == 'function') {
  108. // first test for this page and a setUpPage is defined
  109. if (typeof(this.containerTestFrame.setUpPageStatus) == 'undefined') {
  110. // setUpPage() not called yet, so call it
  111. this.containerTestFrame.setUpPageStatus = false;
  112. this.containerTestFrame.startTime = new Date();
  113. this.containerTestFrame.setUpPage();
  114. // try test again later
  115. setTimeout('top.testManager._runTest()', jsUnitTestManager.SETUPPAGE_INTERVAL);
  116. return;
  117. }
  118. if (this.containerTestFrame.setUpPageStatus != 'complete') {
  119. top.status = 'setUpPage not completed... ' + this.containerTestFrame.setUpPageStatus + ' ' + (new Date());
  120. if ((new Date() - this.containerTestFrame.startTime) / 1000 > this.getsetUpPageTimeout()) {
  121. this.fatalError('setUpPage timed out without completing.');
  122. if (!this.userConfirm('Retry Test Run?')) {
  123. this.abort();
  124. return;
  125. }
  126. this.containerTestFrame.startTime = (new Date());
  127. }
  128. // try test again later
  129. setTimeout('top.testManager._runTest()', jsUnitTestManager.SETUPPAGE_INTERVAL);
  130. return;
  131. }
  132. }
  133. }
  134. top.status = '';
  135. // either not first test, or no setUpPage defined, or setUpPage completed
  136. this.executeTestFunction(this._testsInPage[this._testIndex]);
  137. this.totalCount++;
  138. this.updateProgressIndicators();
  139. this._testIndex++;
  140. setTimeout('top.testManager._runTest()', jsUnitTestManager.TIMEOUT_LENGTH);
  141. }
  142. jsUnitTestManager.prototype._done = function () {
  143. var secondsSinceRunBegan = (new Date() - this._timeRunStarted) / 1000;
  144. this.setStatus('Done (' + secondsSinceRunBegan + ' seconds)');
  145. this._cleanUp();
  146. if (top.shouldSubmitResults()) {
  147. this.resultsTimeField.value = secondsSinceRunBegan;
  148. top.submitResults();
  149. }
  150. }
  151. jsUnitTestManager.prototype._nextPage = function () {
  152. this._restoredHTML = null;
  153. if (this._currentSuite().hasMorePages()) {
  154. this.loadPage(this._currentSuite().nextPage());
  155. }
  156. else {
  157. pop(this._suiteStack);
  158. if (this._currentSuite() == null)
  159. this._done();
  160. else
  161. this._nextPage();
  162. }
  163. }
  164. jsUnitTestManager.prototype._currentSuite = function () {
  165. var suite = null;
  166. if (this._suiteStack && this._suiteStack.length > 0)
  167. suite = this._suiteStack[this._suiteStack.length - 1];
  168. return suite;
  169. }
  170. jsUnitTestManager.prototype.calculateProgressBarProportion = function () {
  171. if (this.totalCount == 0)
  172. return 0;
  173. var currentDivisor = 1;
  174. var result = 0;
  175. for (var i = 0; i < this._suiteStack.length; i++) {
  176. var aSuite = this._suiteStack[i];
  177. currentDivisor *= aSuite.testPages.length;
  178. result += (aSuite.pageIndex - 1) / currentDivisor;
  179. }
  180. result += (this._testIndex + 1) / (this._numberOfTestsInPage * currentDivisor);
  181. return result;
  182. }
  183. jsUnitTestManager.prototype._cleanUp = function () {
  184. this.containerController.setTestPage('./app/emptyPage.html');
  185. this.finalize();
  186. top.tracer.finalize();
  187. }
  188. jsUnitTestManager.prototype.abort = function () {
  189. this.setStatus('Aborted');
  190. this._cleanUp();
  191. }
  192. jsUnitTestManager.prototype.getTimeout = function () {
  193. var result = jsUnitTestManager.TESTPAGE_WAIT_SEC;
  194. try {
  195. result = eval(this.timeout.value);
  196. }
  197. catch (e) {
  198. }
  199. return result;
  200. }
  201. jsUnitTestManager.prototype.getsetUpPageTimeout = function () {
  202. var result = jsUnitTestManager.SETUPPAGE_TIMEOUT;
  203. try {
  204. result = eval(this.setUpPageTimeout.value);
  205. }
  206. catch (e) {
  207. }
  208. return result;
  209. }
  210. jsUnitTestManager.prototype.isTestPageSuite = function () {
  211. var result = false;
  212. if (typeof(this.containerTestFrame.suite) == 'function')
  213. {
  214. result = true;
  215. }
  216. return result;
  217. }
  218. jsUnitTestManager.prototype.getTestFunctionNames = function () {
  219. var testFrame = this.containerTestFrame;
  220. var testFunctionNames = new Array();
  221. var i;
  222. if (testFrame && typeof(testFrame.exposeTestFunctionNames) == 'function')
  223. return testFrame.exposeTestFunctionNames();
  224. if (testFrame &&
  225. testFrame.document &&
  226. typeof(testFrame.document.scripts) != 'undefined' &&
  227. testFrame.document.scripts.length > 0) { // IE5 and up
  228. var scriptsInTestFrame = testFrame.document.scripts;
  229. for (i = 0; i < scriptsInTestFrame.length; i++) {
  230. var someNames = this._extractTestFunctionNamesFromScript(scriptsInTestFrame[i]);
  231. if (someNames)
  232. testFunctionNames = testFunctionNames.concat(someNames);
  233. }
  234. }
  235. else {
  236. for (i in testFrame) {
  237. if (i.substring(0, 4) == 'test' && typeof(testFrame[i]) == 'function')
  238. push(testFunctionNames, i);
  239. }
  240. }
  241. return testFunctionNames;
  242. }
  243. jsUnitTestManager.prototype._extractTestFunctionNamesFromScript = function (aScript) {
  244. var result;
  245. var remainingScriptToInspect = aScript.text;
  246. var currentIndex = this._indexOfTestFunctionIn(remainingScriptToInspect);
  247. while (currentIndex != -1) {
  248. if (!result)
  249. result = new Array();
  250. var fragment = remainingScriptToInspect.substring(currentIndex, remainingScriptToInspect.length);
  251. result = result.concat(fragment.substring('function '.length, fragment.indexOf('(')));
  252. remainingScriptToInspect = remainingScriptToInspect.substring(currentIndex + 12, remainingScriptToInspect.length);
  253. currentIndex = this._indexOfTestFunctionIn(remainingScriptToInspect);
  254. }
  255. return result;
  256. }
  257. jsUnitTestManager.prototype._indexOfTestFunctionIn = function (string) {
  258. return string.indexOf('function test');
  259. }
  260. jsUnitTestManager.prototype.loadPage = function (testFileName) {
  261. this._testFileName = testFileName;
  262. this._loadAttemptStartTime = new Date();
  263. this.setStatus('Opening Test Page "' + this._testFileName + '"');
  264. this.containerController.setTestPage(this._testFileName);
  265. this._callBackWhenPageIsLoaded();
  266. }
  267. jsUnitTestManager.prototype._callBackWhenPageIsLoaded = function () {
  268. if ((new Date() - this._loadAttemptStartTime) / 1000 > this.getTimeout()) {
  269. this.fatalError('Reading Test Page ' + this._testFileName + ' timed out.\nMake sure that the file exists and is a Test Page.');
  270. if (this.userConfirm('Retry Test Run?')) {
  271. this.loadPage(this._testFileName);
  272. return;
  273. } else {
  274. this.abort();
  275. return;
  276. }
  277. }
  278. if (!this._isTestFrameLoaded()) {
  279. setTimeout('top.testManager._callBackWhenPageIsLoaded();', jsUnitTestManager.TIMEOUT_LENGTH);
  280. return;
  281. }
  282. this.doneLoadingPage(this._testFileName);
  283. }
  284. jsUnitTestManager.prototype._isTestFrameLoaded = function () {
  285. try {
  286. return this.containerController.isPageLoaded();
  287. }
  288. catch (e) {
  289. }
  290. return false;
  291. }
  292. jsUnitTestManager.prototype.executeTestFunction = function (functionName) {
  293. this._testFunctionName = functionName;
  294. this.setStatus('Running test "' + this._testFunctionName + '"');
  295. var excep = null;
  296. var timeBefore = new Date();
  297. try {
  298. if (this._restoredHTML)
  299. top.testContainer.testFrame.document.getElementById(jsUnitTestManager.RESTORED_HTML_DIV_ID).innerHTML = this._restoredHTML;
  300. if (this.containerTestFrame.setUp !== JSUNIT_UNDEFINED_VALUE)
  301. this.containerTestFrame.setUp();
  302. this.containerTestFrame[this._testFunctionName]();
  303. }
  304. catch (e1) {
  305. excep = e1;
  306. }
  307. finally {
  308. try {
  309. if (this.containerTestFrame.tearDown !== JSUNIT_UNDEFINED_VALUE)
  310. this.containerTestFrame.tearDown();
  311. }
  312. catch (e2) {
  313. //Unlike JUnit, only assign a tearDown exception to excep if there is not already an exception from the test body
  314. if (excep == null)
  315. excep = e2;
  316. }
  317. }
  318. var timeTaken = (new Date() - timeBefore) / 1000;
  319. if (excep != null)
  320. this._handleTestException(excep);
  321. var serializedTestCaseString = this._currentTestFunctionNameWithTestPageName(true) + "|" + timeTaken + "|";
  322. if (excep == null)
  323. serializedTestCaseString += "S||";
  324. else {
  325. if (typeof(excep.isJsUnitException) != 'undefined' && excep.isJsUnitException)
  326. serializedTestCaseString += "F|";
  327. else {
  328. serializedTestCaseString += "E|";
  329. }
  330. serializedTestCaseString += this._problemDetailMessageFor(excep);
  331. }
  332. this._addOption(this.testCaseResultsField,
  333. serializedTestCaseString,
  334. serializedTestCaseString);
  335. }
  336. jsUnitTestManager.prototype._currentTestFunctionNameWithTestPageName = function(useFullyQualifiedTestPageName) {
  337. var testURL = this.containerTestFrame.location.href;
  338. var testQuery = testURL.indexOf("?");
  339. if (testQuery >= 0) {
  340. testURL = testURL.substring(0, testQuery);
  341. }
  342. if (!useFullyQualifiedTestPageName) {
  343. if (testURL.substring(0, this._baseURL.length) == this._baseURL)
  344. testURL = testURL.substring(this._baseURL.length);
  345. }
  346. return testURL + ':' + this._testFunctionName;
  347. }
  348. jsUnitTestManager.prototype._addOption = function(listField, problemValue, problemMessage) {
  349. if (typeof(listField.ownerDocument) != 'undefined'
  350. && typeof(listField.ownerDocument.createElement) != 'undefined') {
  351. // DOM Level 2 HTML method.
  352. // this is required for Opera 7 since appending to the end of the
  353. // options array does not work, and adding an Option created by new Option()
  354. // and appended by listField.options.add() fails due to WRONG_DOCUMENT_ERR
  355. var problemDocument = listField.ownerDocument;
  356. var errOption = problemDocument.createElement('option');
  357. errOption.setAttribute('value', problemValue);
  358. errOption.appendChild(problemDocument.createTextNode(problemMessage));
  359. listField.appendChild(errOption);
  360. }
  361. else {
  362. // new Option() is DOM 0
  363. errOption = new Option(problemMessage, problemValue);
  364. if (typeof(listField.add) != 'undefined') {
  365. // DOM 2 HTML
  366. listField.add(errOption, null);
  367. }
  368. else if (typeof(listField.options.add) != 'undefined') {
  369. // DOM 0
  370. listField.options.add(errOption, null);
  371. }
  372. else {
  373. // DOM 0
  374. listField.options[listField.length] = errOption;
  375. }
  376. }
  377. }
  378. jsUnitTestManager.prototype._handleTestException = function (excep) {
  379. var problemMessage = this._currentTestFunctionNameWithTestPageName(false) + ' ';
  380. var errOption;
  381. if (typeof(excep.isJsUnitException) == 'undefined' || !excep.isJsUnitException) {
  382. problemMessage += 'had an error';
  383. this.errorCount++;
  384. }
  385. else {
  386. problemMessage += 'failed';
  387. this.failureCount++;
  388. }
  389. var listField = this.problemsListField;
  390. this._addOption(listField,
  391. this._problemDetailMessageFor(excep),
  392. problemMessage);
  393. }
  394. jsUnitTestManager.prototype._problemDetailMessageFor = function (excep) {
  395. var result = null;
  396. if (typeof(excep.isJsUnitException) != 'undefined' && excep.isJsUnitException) {
  397. result = '';
  398. if (excep.comment != null)
  399. result += ('"' + excep.comment + '"\n');
  400. result += excep.jsUnitMessage;
  401. if (excep.stackTrace)
  402. result += '\n\nStack trace follows:\n' + excep.stackTrace;
  403. }
  404. else {
  405. result = 'Error message is:\n"';
  406. result +=
  407. (typeof(excep.description) == 'undefined') ?
  408. excep :
  409. excep.description;
  410. result += '"';
  411. if (typeof(excep.stack) != 'undefined') // Mozilla only
  412. result += '\n\nStack trace follows:\n' + excep.stack;
  413. }
  414. return result;
  415. }
  416. jsUnitTestManager.prototype._setTextOnLayer = function (layerName, str) {
  417. try {
  418. var content;
  419. if (content = this.uiFrames[layerName].document.getElementById('content'))
  420. content.innerHTML = str;
  421. else
  422. throw 'No content div found.';
  423. }
  424. catch (e) {
  425. var html = '';
  426. html += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
  427. html += '<html><head><link rel="stylesheet" type="text/css" href="css/jsUnitStyle.css"><\/head>';
  428. html += '<body><div id="content">';
  429. html += str;
  430. html += '<\/div><\/body>';
  431. html += '<\/html>';
  432. this.uiFrames[layerName].document.write(html);
  433. this.uiFrames[layerName].document.close();
  434. }
  435. }
  436. jsUnitTestManager.prototype.setStatus = function (str) {
  437. this._setTextOnLayer('mainStatus', '<b>Status:<\/b> ' + str);
  438. }
  439. jsUnitTestManager.prototype._setErrors = function (n) {
  440. this._setTextOnLayer('mainCountsErrors', '<b>Errors: <\/b>' + n);
  441. }
  442. jsUnitTestManager.prototype._setFailures = function (n) {
  443. this._setTextOnLayer('mainCountsFailures', '<b>Failures:<\/b> ' + n);
  444. }
  445. jsUnitTestManager.prototype._setTotal = function (n) {
  446. this._setTextOnLayer('mainCountsRuns', '<b>Runs:<\/b> ' + n);
  447. }
  448. jsUnitTestManager.prototype._setProgressBarImage = function (imgName) {
  449. this.progressBar.src = imgName;
  450. }
  451. jsUnitTestManager.prototype._setProgressBarWidth = function (w) {
  452. this.progressBar.width = w;
  453. }
  454. jsUnitTestManager.prototype.updateProgressIndicators = function () {
  455. this._setTotal(this.totalCount);
  456. this._setErrors(this.errorCount);
  457. this._setFailures(this.failureCount);
  458. this._setProgressBarWidth(300 * this.calculateProgressBarProportion());
  459. if (this.errorCount > 0 || this.failureCount > 0)
  460. this._setProgressBarImage('../images/red.gif');
  461. else
  462. this._setProgressBarImage('../images/green.gif');
  463. }
  464. jsUnitTestManager.prototype.showMessageForSelectedProblemTest = function () {
  465. var problemTestIndex = this.problemsListField.selectedIndex;
  466. if (problemTestIndex != -1)
  467. this.fatalError(this.problemsListField[problemTestIndex].value);
  468. }
  469. jsUnitTestManager.prototype.showMessagesForAllProblemTests = function () {
  470. if (this.problemsListField.length == 0)
  471. return;
  472. try {
  473. if (this._windowForAllProblemMessages && !this._windowForAllProblemMessages.closed)
  474. this._windowForAllProblemMessages.close();
  475. }
  476. catch(e) {
  477. }
  478. this._windowForAllProblemMessages = window.open('', '', 'width=600, height=350,status=no,resizable=yes,scrollbars=yes');
  479. var resDoc = this._windowForAllProblemMessages.document;
  480. resDoc.write('<html><head><link rel="stylesheet" href="../css/jsUnitStyle.css"><title>Tests with problems - JsUnit<\/title><head><body>');
  481. resDoc.write('<p class="jsUnitSubHeading">Tests with problems (' + this.problemsListField.length + ' total) - JsUnit<\/p>');
  482. resDoc.write('<p class="jsUnitSubSubHeading"><i>Running on ' + navigator.userAgent + '</i></p>');
  483. for (var i = 0; i < this.problemsListField.length; i++)
  484. {
  485. resDoc.write('<p class="jsUnitDefault">');
  486. resDoc.write('<b>' + (i + 1) + '. ');
  487. resDoc.write(this.problemsListField[i].text);
  488. resDoc.write('<\/b><\/p><p><pre>');
  489. resDoc.write(this._makeHTMLSafe(this.problemsListField[i].value));
  490. resDoc.write('<\/pre><\/p>');
  491. }
  492. resDoc.write('<\/body><\/html>');
  493. resDoc.close();
  494. }
  495. jsUnitTestManager.prototype._makeHTMLSafe = function (string) {
  496. string = string.replace(/&/g, '&amp;');
  497. string = string.replace(/</g, '&lt;');
  498. string = string.replace(/>/g, '&gt;');
  499. return string;
  500. }
  501. jsUnitTestManager.prototype._clearProblemsList = function () {
  502. var listField = this.problemsListField;
  503. var initialLength = listField.options.length;
  504. for (var i = 0; i < initialLength; i++)
  505. listField.remove(0);
  506. }
  507. jsUnitTestManager.prototype.initialize = function () {
  508. this.setStatus('Initializing...');
  509. this._setRunButtonEnabled(false);
  510. this._clearProblemsList();
  511. this.updateProgressIndicators();
  512. this.setStatus('Done initializing');
  513. }
  514. jsUnitTestManager.prototype.finalize = function () {
  515. this._setRunButtonEnabled(true);
  516. }
  517. jsUnitTestManager.prototype._setRunButtonEnabled = function (b) {
  518. this.runButton.disabled = !b;
  519. }
  520. jsUnitTestManager.prototype.getTestFileName = function () {
  521. var rawEnteredFileName = this.testFileName.value;
  522. var result = rawEnteredFileName;
  523. while (result.indexOf('\\') != -1)
  524. result = result.replace('\\', '/');
  525. return result;
  526. }
  527. jsUnitTestManager.prototype.getTestFunctionName = function () {
  528. return this._testFunctionName;
  529. }
  530. jsUnitTestManager.prototype.resolveUserEnteredTestFileName = function (rawText) {
  531. var userEnteredTestFileName = top.testManager.getTestFileName();
  532. // only test for file:// since Opera uses a different format
  533. if (userEnteredTestFileName.indexOf('http://') == 0 || userEnteredTestFileName.indexOf('https://') == 0 || userEnteredTestFileName.indexOf('file://') == 0)
  534. return userEnteredTestFileName;
  535. return getTestFileProtocol() + this.getTestFileName();
  536. }
  537. jsUnitTestManager.prototype.storeRestoredHTML = function () {
  538. if (document.getElementById && top.testContainer.testFrame.document.getElementById(jsUnitTestManager.RESTORED_HTML_DIV_ID))
  539. this._restoredHTML = top.testContainer.testFrame.document.getElementById(jsUnitTestManager.RESTORED_HTML_DIV_ID).innerHTML;
  540. }
  541. jsUnitTestManager.prototype.fatalError = function(aMessage) {
  542. if (top.shouldSubmitResults())
  543. this.setStatus(aMessage);
  544. else
  545. alert(aMessage);
  546. }
  547. jsUnitTestManager.prototype.userConfirm = function(aMessage) {
  548. if (top.shouldSubmitResults())
  549. return false;
  550. else
  551. return confirm(aMessage);
  552. }
  553. function getTestFileProtocol() {
  554. return getDocumentProtocol();
  555. }
  556. function getDocumentProtocol() {
  557. var protocol = top.document.location.protocol;
  558. if (protocol == "file:")
  559. return "file:///";
  560. if (protocol == "http:")
  561. return "http://";
  562. if (protocol == 'https:')
  563. return 'https://';
  564. if (protocol == "chrome:")
  565. return "chrome://";
  566. return null;
  567. }
  568. function browserSupportsReadingFullPathFromFileField() {
  569. return !isOpera() && !isIE7();
  570. }
  571. function isOpera() {
  572. return navigator.userAgent.toLowerCase().indexOf("opera") != -1;
  573. }
  574. function isIE7() {
  575. return navigator.userAgent.toLowerCase().indexOf("msie 7") != -1;
  576. }
  577. function isBeingRunOverHTTP() {
  578. return getDocumentProtocol() == "http://";
  579. }
  580. function getWebserver() {
  581. if (isBeingRunOverHTTP()) {
  582. var myUrl = location.href;
  583. var myUrlWithProtocolStripped = myUrl.substring(myUrl.indexOf("/") + 2);
  584. return myUrlWithProtocolStripped.substring(0, myUrlWithProtocolStripped.indexOf("/"));
  585. }
  586. return null;
  587. }
  588. // the functions push(anArray, anObject) and pop(anArray)
  589. // exist because the JavaScript Array.push(anObject) and Array.pop()
  590. // functions are not available in IE 5.0
  591. function push(anArray, anObject) {
  592. anArray[anArray.length] = anObject;
  593. }
  594. function pop(anArray) {
  595. if (anArray.length >= 1) {
  596. delete anArray[anArray.length - 1];
  597. anArray.length--;
  598. }
  599. }
  600. if (xbDEBUG.on) {
  601. xbDebugTraceObject('window', 'jsUnitTestManager');
  602. xbDebugTraceFunction('window', 'getTestFileProtocol');
  603. xbDebugTraceFunction('window', 'getDocumentProtocol');
  604. }