⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsunittestmanager.js

📁 一个用javascript开发的可以拖拽表单的例子,很精典.
💻 JS
📖 第 1 页 / 共 2 页
字号:
jsUnitTestManager.prototype._isTestFrameLoaded = function () {  try {    return this.containerController.isPageLoaded();  }   catch (e) {  }  return false;}jsUnitTestManager.prototype.executeTestFunction = function (functionName) {  this._testFunctionName=functionName;  this.setStatus('Running test "' + this._testFunctionName + '"');  var excep=null;  var timeBefore = new Date();    try {    this.containerTestFrame.setUp();    eval('this.containerTestFrame.' + this._testFunctionName + '();');  }   catch (e1) {    excep = e1;  }  finally {    try {      this.containerTestFrame.tearDown();    }     catch (e2) {      excep = e2;    }  }  var timeTaken = (new Date() - timeBefore) / 1000;  if (excep != null)    this._handleTestException(excep);  var serializedTestCaseString = this._fullyQualifiedCurrentTestFunctionName()+"|"+timeTaken+"|";  if (excep==null)  	serializedTestCaseString+="S||";  else {  	if (typeof(excep.isJsUnitException) != 'undefined' && excep.isJsUnitException)  		serializedTestCaseString+="F|";  	else {  		serializedTestCaseString+="E|";  	}  	serializedTestCaseString+=this._problemDetailMessageFor(excep);  }  	  var newOption = new Option(serializedTestCaseString);  this.testCaseResultsField[this.testCaseResultsField.length]=newOption;  }jsUnitTestManager.prototype._fullyQualifiedCurrentTestFunctionName = function() {    var testURL = this.containerTestFrame.location.href;    var testQuery = testURL.indexOf("?");    if (testQuery >= 0) {        testURL = testURL.substring(0, testQuery);    }    if (testURL.substring(0, this._baseURL.length) == this._baseURL) {          testURL = testURL.substring(this._baseURL.length);    }    return testURL + ':' + this._testFunctionName;}jsUnitTestManager.prototype._handleTestException = function (excep) {  var problemMessage = this._fullyQualifiedCurrentTestFunctionName() + ' ';  var errOption;  if (typeof(excep.isJsUnitException) == 'undefined' || !excep.isJsUnitException) {    problemMessage += 'had an error';    this.errorCount++;  }   else {    problemMessage += 'failed';    this.failureCount++;  }  var listField = this.problemsListField;  var problemDocument = this.mainFrame.frames.mainErrors.document;  if (typeof(problemDocument.createElement) != 'undefined') {    // DOM Level 2 HTML method.    // this is required for Opera 7 since appending to the end of the     // options array does not work, and adding an Option created by new Option()    // and appended by listField.options.add() fails due to WRONG_DOCUMENT_ERR    errOption = problemDocument.createElement('option');    errOption.setAttribute('value', this._problemDetailMessageFor(excep));    errOption.appendChild(problemDocument.createTextNode(problemMessage));    listField.appendChild(errOption);  }  else {    // new Option() is DOM 0    errOption = new Option(problemMessage, this._problemDetailMessageFor(excep));    if (typeof(listField.add) != 'undefined') {      // DOM 2 HTML       listField.add( errOption , null);    }    else if (typeof(listField.options.add) != 'undefined') {      // DOM 0      listField.options.add( errOption, null);    }    else {      // DOM 0      listField.options[listField.length]= errOption;    }  }}jsUnitTestManager.prototype._problemDetailMessageFor = function (excep) {  var result=null;  if (typeof(excep.isJsUnitException) != 'undefined' && excep.isJsUnitException) {    result = '';    if (excep.comment != null)      result+=('"'+excep.comment+'"\n');        result += excep.jsUnitMessage;        if (excep.stackTrace)      result+='\n\nStack trace follows:\n'+excep.stackTrace;  }  else {    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;}jsUnitTestManager.prototype._setTextOnLayer = function (layerName, str){  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>';  html += str;  html += '<\/div><\/body>';  html += '<\/html>';  this.uiFrames[layerName].document.write(html);  this.uiFrames[layerName].document.close();}jsUnitTestManager.prototype.setStatus = function (str){  this._setTextOnLayer('mainStatus', '<b>Status:<\/b> '+str);}jsUnitTestManager.prototype._setErrors = function (n){  this._setTextOnLayer('mainCountsErrors', '<b>Errors: <\/b>' + n);}jsUnitTestManager.prototype._setFailures = function (n){  this._setTextOnLayer('mainCountsFailures', '<b>Failures:<\/b> ' + n);}jsUnitTestManager.prototype._setTotal = function (n){  this._setTextOnLayer('mainCountsRuns', '<b>Runs:<\/b> ' + n);}jsUnitTestManager.prototype._setProgressBarImage = function (imgName){  this.progressBar.src=imgName;}jsUnitTestManager.prototype._setProgressBarWidth = function (w){  this.progressBar.width=w;}jsUnitTestManager.prototype.updateProgressIndicators = function (){  this._setTotal(this.totalCount);  this._setErrors(this.errorCount);  this._setFailures(this.failureCount);  this._setProgressBarWidth(300 * this.calculateProgressBarProportion());  if (this.errorCount > 0 || this.failureCount > 0)    this._setProgressBarImage('../images/red.gif');  else    this._setProgressBarImage('../images/green.gif');}jsUnitTestManager.prototype.showMessageForSelectedProblemTest = function (){  var problemTestIndex = this.problemsListField.selectedIndex;  if (problemTestIndex != -1)    alert(this.problemsListField[problemTestIndex].value);}jsUnitTestManager.prototype.showMessagesForAllProblemTests = function (){   if (this.problemsListField.length == 0)      return;   try   {     if (this._windowForAllProblemMessages && !this._windowForAllProblemMessages.closed)       this._windowForAllProblemMessages.close();   }   catch(e)   {   }   this._windowForAllProblemMessages = window.open('','','width=600, height=350,status=no,resizable=yes,scrollbars=yes');   var resDoc = this._windowForAllProblemMessages.document;   resDoc.write('<html><head><link rel="stylesheet" href="../css/jsUnitStyle.css"><title>Tests with problems - JsUnit<\/title><head><body>');   resDoc.write('<p class="jsUnitSubHeading">Tests with problems (' + this.problemsListField.length + ' total) - JsUnit<\/p>');   resDoc.write('<p class="jsUnitSubSubHeading"><i>Running on '+navigator.userAgent+'</i></p>');   for (var i = 0; i < this.problemsListField.length; i++)   {     resDoc.write('<p class="jsUnitDefault">');     resDoc.write('<b>' + (i + 1) + '. ');     resDoc.write(this.problemsListField[i].text);     resDoc.write('<\/b><\/p><p><pre>');     resDoc.write(this.problemsListField[i].value);     resDoc.write('<\/pre><\/p>');   }   resDoc.write('<\/body><\/html>');   resDoc.close();}jsUnitTestManager.prototype._clearProblemsList = function (){  var listField = this.problemsListField;  var initialLength=listField.options.length;  for (var i = 0; i < initialLength; i++)    listField.remove(0);}jsUnitTestManager.prototype.initialize = function (){  this.setStatus('Initializing...');  this._setRunButtonEnabled(false);  this._clearProblemsList();  this.updateProgressIndicators();  this.setStatus('Done initializing');}jsUnitTestManager.prototype.finalize = function (){  this._setRunButtonEnabled(true);}jsUnitTestManager.prototype._setRunButtonEnabled = function (b){  this.runButton.disabled = !b;}jsUnitTestManager.prototype.getTestFileName = function () {  var rawEnteredFileName = this.testFileName.value;  var result             = rawEnteredFileName;  while (result.indexOf('\\') != -1)    result = result.replace('\\', '/');  return result;}jsUnitTestManager.prototype.resolveUserEnteredTestFileName = function (rawText) {  var userEnteredTestFileName = top.testManager.getTestFileName();    // only test for file:// since Opera uses a different format  if (userEnteredTestFileName.indexOf('http://') == 0 || userEnteredTestFileName.indexOf('https://') == 0 || userEnteredTestFileName.indexOf('file://') == 0)    return userEnteredTestFileName;      return getTestFileProtocol() + this.getTestFileName();}function getTestFileProtocol(){  return getDocumentProtocol();}function getDocumentProtocol() {  var protocol = top.document.location.protocol;      if (protocol == "file:")     return "file:///";  if (protocol == "http:")     return "http://";      if (protocol == 'https:')     return 'https://';          if (protocol == "chrome:")     return "chrome://";  return null;}function isBeingRunOverHTTP() {	return getDocumentProtocol()=="http://";}   function getWebserver() {	if (isBeingRunOverHTTP()) {		var myUrl = location.href;		var myUrlWithProtocolStripped = myUrl.substring(myUrl.indexOf("/") + 2);		return myUrlWithProtocolStripped.substring(0, myUrlWithProtocolStripped.indexOf("/"));	}	return null;}// the functions push(anArray, anObject) and pop(anArray) // exist because the JavaScript Array.push(anObject) and Array.pop() // functions are not available in IE 5.0function push(anArray, anObject) {  anArray[anArray.length]=anObject;}function pop(anArray) {  if (anArray.length>=1) {    delete anArray[anArray.length - 1];    anArray.length--;  }}if (xbDEBUG.on){  xbDebugTraceObject('window', 'jsUnitTestManager');  xbDebugTraceFunction('window', 'getTestFileProtocol');  xbDebugTraceFunction('window', 'getDocumentProtocol');}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -