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