Complete overhaul of the Ajax test suite, it's now passing in all browsers. In order...
[jquery.git] / build / test / data / testrunner.js
index 337c0dd..25ffb3f 100644 (file)
@@ -13,12 +13,11 @@ var _config = {
        asyncTimeout: 2 // seconds for async timeout
 };
 
+var isLocal = !!(window.location.protocol == 'file:');
+
 $(function() {
        $('#userAgent').html(navigator.userAgent);
-       if($.browser.safari)
-               $("h1").append(" - Disabled for Safari");
-       else
-               runTest();      
+       runTest();      
 });
 
 function synchronize(callback) {
@@ -42,13 +41,17 @@ function stop(allowFailure) {
                ok( false, "Test timed out" );
                start();
        };
-       _config.timeout = setTimeout(handler, _config.asyncTimeout * 1000);
+       // Disabled, caused too many random errors
+       //_config.timeout = setTimeout(handler, _config.asyncTimeout * 1000);
 }
 function start() {
-       if(_config.timeout)
-               clearTimeout(_config.timeout);
-       _config.blocking = false;
-       process();
+       // A slight delay, to avoid any current callbacks
+       setTimeout(function(){
+               if(_config.timeout)
+                       clearTimeout(_config.timeout);
+               _config.blocking = false;
+               process();
+       }, 13);
 }
 
 function runTest() {
@@ -67,17 +70,13 @@ function runTest() {
 }
 
 function test(name, callback, nowait) {
-       // safari seems to have some memory problems, so we need to slow it down
-       if($.browser.safari && !nowait) {
-               test("", function() {
-                       stop();
-                       setTimeout(start, 250);
-               }, true);
-       }
-
        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 {
@@ -123,7 +122,7 @@ function test(name, callback, nowait) {
                var li = document.createElement("li");
                li.className = state;
        
-               var b = document.createElement("b");
+               var b = 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 n = this.nextSibling;
@@ -132,6 +131,13 @@ function test(name, callback, nowait) {
                        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( b );
                li.appendChild( ol );
        
@@ -171,7 +177,7 @@ function ok(a, msg) {
  */
 function isSet(a, b, msg) {
        var ret = true;
-       if ( a && b && a.length == b.length ) {
+       if ( a && b && a.length != undefined && a.length == b.length ) {
                for ( var i = 0; i < a.length; i++ )
                        if ( a[i] != b[i] )
                                ret = false;
@@ -183,18 +189,40 @@ function isSet(a, b, msg) {
                _config.Test.push( [ ret, msg ] );
 }
 
+/**
+ * Asserts that two objects are equivalent
+ */
+function isObj(a, b, msg) {
+       var ret = true;
+       
+       if ( a && b ) {
+               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( [ ret, msg ] );
+}
+
 function serialArray( a ) {
        var r = [];
-       for ( var i = 0; i < a.length; i++ ) {
-               var str = a[i].nodeName;
-               if ( str ) {
-                       str = str.toLowerCase();
-                       if ( a[i].id )
-                               str += "#" + a[i].id;
-               } else
-                       str = a[i];
-               r.push( str );
-       }
+       
+       if ( a && a.length )
+        for ( var i = 0; i < a.length; i++ ) {
+            var str = a[i].nodeName;
+            if ( str ) {
+                str = str.toLowerCase();
+                if ( a[i].id )
+                    str += "#" + a[i].id;
+            } else
+                str = a[i];
+            r.push( str );
+        }
 
        return "[ " + r.join(", ") + " ]"
 }
@@ -249,7 +277,7 @@ function url(value) {
  * @param Object actual
  * @param String message (optional)
  */
-function equals(expected, actual, message) {
+function equals(actual, expected, message) {
        var result = expected == actual;
        message = message || (result ? "okay" : "failed");
        _config.Test.push( [ result, result ? message + ": " + expected : message + " expected: " + expected + " actual: " + actual ] );