PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 102 lines | 87 code | 15 blank | 0 comment | 16 complexity | cd02a42fc0ac84eafd02c95b22321ee5 MD5 | raw file
  1var TRACE_LEVEL_NONE = new JsUnitTraceLevel(0, null);
  2var TRACE_LEVEL_WARNING = new JsUnitTraceLevel(1, "#FF0000");
  3var TRACE_LEVEL_INFO = new JsUnitTraceLevel(2, "#009966");
  4var TRACE_LEVEL_DEBUG = new JsUnitTraceLevel(3, "#0000FF");
  5
  6function JsUnitTracer(testManager) {
  7    this._testManager = testManager;
  8    this._traceWindow = null;
  9    this.popupWindowsBlocked = false;
 10}
 11
 12JsUnitTracer.prototype.initialize = function() {
 13    if (this._traceWindow != null && top.testManager.closeTraceWindowOnNewRun.checked)
 14        this._traceWindow.close();
 15    this._traceWindow = null;
 16}
 17
 18JsUnitTracer.prototype.finalize = function() {
 19    if (this._traceWindow != null) {
 20        this._traceWindow.document.write('<\/body>\n<\/html>');
 21        this._traceWindow.document.close();
 22    }
 23}
 24
 25JsUnitTracer.prototype.warn = function() {
 26    this._trace(arguments[0], arguments[1], TRACE_LEVEL_WARNING);
 27}
 28
 29JsUnitTracer.prototype.inform = function() {
 30    this._trace(arguments[0], arguments[1], TRACE_LEVEL_INFO);
 31}
 32
 33JsUnitTracer.prototype.debug = function() {
 34    this._trace(arguments[0], arguments[1], TRACE_LEVEL_DEBUG);
 35}
 36
 37JsUnitTracer.prototype._trace = function(message, value, traceLevel) {
 38    if (!top.shouldSubmitResults() && this._getChosenTraceLevel().matches(traceLevel)) {
 39        var traceString = message;
 40        if (value)
 41            traceString += ': ' + value;
 42        var prefix = this._testManager.getTestFileName() + ":" +
 43                     this._testManager.getTestFunctionName() + " - ";
 44        this._writeToTraceWindow(prefix, traceString, traceLevel);
 45    }
 46}
 47
 48JsUnitTracer.prototype._getChosenTraceLevel = function() {
 49    var levelNumber = eval(top.testManager.traceLevel.value);
 50    return traceLevelByLevelNumber(levelNumber);
 51}
 52
 53JsUnitTracer.prototype._writeToTraceWindow = function(prefix, traceString, traceLevel) {
 54    var htmlToAppend = '<p class="jsUnitDefault">' + prefix + '<font color="' + traceLevel.getColor() + '">' + traceString + '</font><\/p>\n';
 55    this._getTraceWindow().document.write(htmlToAppend);
 56}
 57
 58JsUnitTracer.prototype._getTraceWindow = function() {
 59    if (this._traceWindow == null && !top.shouldSubmitResults() && !this.popupWindowsBlocked) {
 60        this._traceWindow = window.open('', '', 'width=600, height=350,status=no,resizable=yes,scrollbars=yes');
 61        if (!this._traceWindow)
 62            this.popupWindowsBlocked = true;
 63        else {
 64            var resDoc = this._traceWindow.document;
 65            resDoc.write('<html>\n<head>\n<link rel="stylesheet" href="css/jsUnitStyle.css">\n<title>Tracing - JsUnit<\/title>\n<head>\n<body>');
 66            resDoc.write('<h2>Tracing - JsUnit<\/h2>\n');
 67            resDoc.write('<p class="jsUnitDefault"><i>(Traces are color coded: ');
 68            resDoc.write('<font color="' + TRACE_LEVEL_WARNING.getColor() + '">Warning</font> - ');
 69            resDoc.write('<font color="' + TRACE_LEVEL_INFO.getColor() + '">Information</font> - ');
 70            resDoc.write('<font color="' + TRACE_LEVEL_DEBUG.getColor() + '">Debug</font>');
 71            resDoc.write(')</i></p>');
 72        }
 73    }
 74    return this._traceWindow;
 75}
 76
 77if (xbDEBUG.on) {
 78    xbDebugTraceObject('window', 'JsUnitTracer');
 79}
 80
 81function JsUnitTraceLevel(levelNumber, color) {
 82    this._levelNumber = levelNumber;
 83    this._color = color;
 84}
 85
 86JsUnitTraceLevel.prototype.matches = function(anotherTraceLevel) {
 87    return this._levelNumber >= anotherTraceLevel._levelNumber;
 88}
 89
 90JsUnitTraceLevel.prototype.getColor = function() {
 91    return this._color;
 92}
 93
 94function traceLevelByLevelNumber(levelNumber) {
 95    switch (levelNumber) {
 96        case 0: return TRACE_LEVEL_NONE;
 97        case 1: return TRACE_LEVEL_WARNING;
 98        case 2: return TRACE_LEVEL_INFO;
 99        case 3: return TRACE_LEVEL_DEBUG;
100    }
101    return null;
102}