Вход Регистрация
Файл: framework/thirdparty/jquery-metadata/test/testrunner.js
Строк: 317
<?php
var _config = {
    
fixturenull,
    
Test: [],
    
stats: {
        
all0,
        
bad0
    
},
    
queue: [],
    
blockingtrue,
    
timeoutnull,
    
expectednull,
    
currentModulenull,
    
asyncTimeout// seconds for async timeout
};

$(function() {
    $(
'#userAgent').html(navigator.userAgent);
    
runTest();    
});

function 
synchronize(callback) {
    
_config.queue[_config.queue.length] = callback;
    if(!
_config.blocking) {
        
process();
    }
}

function 
process() {
    while(
_config.queue.length && !_config.blocking) {
        var 
call _config.queue[0];
        
_config.queue _config.queue.slice(1);
        
call();
    }
}

function 
stop(allowFailure) {
    
_config.blocking true;
    var 
handler allowFailure start : function() {
        
okfalse"Test timed out" );
        
start();
    };
    
_config.timeout setTimeout(handler_config.asyncTimeout 1000);
}
function 
start() {
    if(
_config.timeout)
        
clearTimeout(_config.timeout);
    
_config.blocking false;
    
process();
}

function 
runTest() {
    
_config.blocking false;
    var 
time = new Date();
    
_config.fixture document.getElementById('main').innerHTML;
    
reset();
    
synchronize(function() {
        
time = new Date() - time;
        $(
"<div>").html(['<p class="result">Tests completed in ',
            
time' milliseconds.<br/>',
            
_config.stats.bad' tests of '_config.stats.all' failed.</p>']
            .
join(''))
            .
appendTo("body");
        $(
"#banner").addClass(_config.stats.bad "fail" "pass");
    });
}

function 
test(namecallbacknowait) {
    if(
_config.currentModule)
        
name _config.currentModule " module: " name;
        
    var 
filter location.search.slice(1);
    if ( 
filter && encodeURIComponent(name) != filter )
        return;
        
    
synchronize(function() {
        
_config.Test = [];
        try {
            
callback();
        } catch(
e) {
            if( 
typeof console != "undefined" && console.error && console.warn ) {
                
console.error("Test " name " died, exception and test follows");
                
console.error(e);
                
console.warn(callback.toString());
            }
            
_config.Test.push( [ false"Died on test #" + (_config.Test.length+1) + ": " ] );
            
//throw e;
        
}
    });
    
synchronize(function() {
        
reset();
        
        
// don't output pause tests
        
if(nowait) return;
        
        if(
_config.expected && _config.expected != _config.Test.length) {
            
_config.Test.push( [ false"Expected " _config.expected " assertions, but " _config.Test.length " were run" ] );
        }
        
_config.expected null;
        
        var 
good 0bad 0;
        var 
ol document.createElement("ol");
        
ol.style.display "none";
        var 
li ""state "pass";
        for ( var 
0_config.Test.lengthi++ ) {
            var 
li document.createElement("li");
            
li.className _config.Test[i][0] ? "pass" "fail";
            
li.innerHTML _config.Test[i][1];
            
ol.appendChildli );
            
            
_config.stats.all++;
            if ( !
_config.Test[i][0] ) {
                
state "fail";
                
bad++;
                
_config.stats.bad++;
            } else 
good++;
        }
    
        var 
li document.createElement("li");
        
li.className state;
    
        var 
document.createElement("strong");
        
b.innerHTML name " <b style='color:black;'>(<b class='fail'>" bad "</b>, <b class='pass'>" good "</b>, " _config.Test.length ")</b>";
        
b.onclick = function(){
            var 
this.nextSibling;
            if ( 
jQuery.cssn"display" ) == "none" )
                
n.style.display "block";
            else
                
n.style.display "none";
        };
        $(
b).dblclick(function(event) {
            var 
target jQuery(event.target).filter("strong").clone();
            if ( 
target.length ) {
                
target.children().remove();
                
location.href location.href.match(/^(.+?)(?.*)?$/)[1] + "?" encodeURIComponent($.trim(target.text()));
            }
        });
        
li.appendChild);
        
li.appendChildol );
    
        
document.getElementById("tests").appendChildli );        
    });
}

// call on start of module test to prepend name to all tests
function module(moduleName) {
    
_config.currentModule moduleName;
}

/**
 * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through.
 */
function expect(asserts) {
    
_config.expected asserts;
}

/**
 * Resets the test setup. Useful for tests that modify the DOM.
 */
function reset() {
    
document.getElementById('main').innerHTML _config.fixture;
}

/**
 * Asserts true.
 * @example ok( $("a").size() > 5, "There must be at least 5 anchors" );
 */
function ok(amsg) {
    
_config.Test.push( [ !!amsg ] );
}

/**
 * Asserts that two arrays are the same
 */
function isSet(abmsg) {
    var 
ret true;
    if ( 
&& && a.length != undefined && a.length == b.length ) {
        for ( var 
0a.lengthi++ )
            if ( 
a[i] != b[i] )
                
ret false;
    } else
        
ret false;
    if ( !
ret )
        
_config.Test.push( [ retmsg " expected: " serialArray(b) + " result: " serialArray(a) ] );
    else 
        
_config.Test.push( [ retmsg ] );
}

/**
 * Asserts that two objects are equivalent
 */
function isObj(abmsg) {
    var 
ret true;
    
    if ( 
&& ) {
        for ( var 
i in a )
            if ( 
a[i] != b[i] )
                
ret false;

        for ( 
i in b )
            if ( 
a[i] != b[i] )
                
ret false;
    } else
        
ret false;

    
_config.Test.push( [ retmsg ] );
}

function 
serialArray) {
    var 
= [];
    
    if ( 
&& a.length )
        for ( var 
0a.lengthi++ ) {
            var 
str a[i].nodeName;
            if ( 
str ) {
                
str str.toLowerCase();
                if ( 
a[i].id )
                    
str += "#" a[i].id;
            } else
                
str a[i];
            
r.pushstr );
        }

    return 
"[ " r.join(", ") + " ]"
}

/**
 * Returns an array of elements with the given IDs, eg.
 * @example q("main", "foo", "bar")
 * @result [<div id="main">, <span id="foo">, <input id="bar">]
 */
function q() {
    var 
= [];
    for ( var 
0arguments.lengthi++ )
        
r.pushdocument.getElementByIdarguments[i] ) );
    return 
r;
}

/**
 * Asserts that a select matches the given IDs
 * @example t("Check for something", "//[a]", ["foo", "baar"]);
 * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
 */
function t(a,b,c) {
    var 
jQuery(b);
    var 
"";
    for ( var 
0f.lengthi++ )
        
+= (&& ",") + '"' f[i].id '"';
    isSet(
fq.apply(q,c), " (" ")");
}

/**
 * Add random number to url to stop IE from caching
 *
 * @example url("data/test.html")
 * @result "data/test.html?10538358428943"
 *
 * @example url("data/test.php?foo=bar")
 * @result "data/test.php?foo=bar&10538358345554"
 */
function url(value) {
    return 
value + (/?/.test(value) ? "&" "?") + new Date().getTime() + "" parseInt(Math.random()*100000);
}

/**
 * Checks that the first two arguments are equal, with an optional message.
 * Prints out both expected and actual values on failure.
 *
 * Prefered to ok( expected == actual, message )
 *
 * @example equals( "Expected 2 characters.", v.formatMessage("Expected {0} characters.", 2) );
 *
 * @param Object expected
 * @param Object actual
 * @param String message (optional)
 */
function equals(expectedactualmessage) {
    var 
result expected == actual;
    
message message || (result "okay" "failed");
    
_config.Test.push( [ resultresult message ": " expected message " expected: " expected " actual: " actual ] );
}

/**
 * Trigger an event on an element.
 *
 * @example triggerEvent( document.body, "click" );
 *
 * @param DOMElement elem
 * @param String type
 */
function triggerEventelemtypeevent ) {
    if ( 
jQuery.browser.mozilla || jQuery.browser.opera ) {
        
event document.createEvent("MouseEvents");
        
event.initMouseEvent(typetruetrueelem.ownerDocument.defaultView,
            
00000falsefalsefalsefalse0null);
        
elem.dispatchEventevent );
    } else if ( 
jQuery.browser.msie ) {
        
elem.fireEvent("on"+type);
    }
}
?>
Онлайн: 0
Реклама