testrunner: Putting back the global variables used for ajax tests. I added many calls...
[jquery.git] / test / unit / ajax.js
index 677838b..2fafcae 100644 (file)
@@ -157,19 +157,22 @@ test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
        ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
 });
 
-var foobar;
-
 test("jQuery.ajax - dataType html", function() {
        expect(5);
        stop();
        
-       foobar = null;
-       testFoo = undefined;
+       window.foobar = null;
+       window.testFoo = undefined;
 
        var verifyEvaluation = function() {
-         equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
-         equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
-         start();
+               equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
+               equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
+         
+               // Cleanup the global namespace
+               delete window.foobar;
+               delete window.testFoo;
+         
+               start();
        };
 
        jQuery.ajax({
@@ -245,18 +248,20 @@ test("pass-through request object", function() {
        var target = "data/name.html";
        var successCount = 0;
        var errorCount = 0;
-  var errorEx = "";
+       var errorEx = "";
        var success = function() {
                successCount++;
        };
        jQuery("#foo").ajaxError(function (e, xml, s, ex) {
                errorCount++;
-    errorEx += ": " + xml.status;
+               errorEx += ": " + xml.status;
        });
        jQuery("#foo").one('ajaxStop', function () {
                equals(successCount, 5, "Check all ajax calls successful");
                equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
                jQuery("#foo").unbind('ajaxError');
+               
+               delete window.foobar;
                start();
        });
        
@@ -359,12 +364,19 @@ test("load(String, Function) - simple: inject text into DOM", function() {
 test("load(String, Function) - check scripts", function() {
        expect(7);
        stop();
+       
        window.testFoo = undefined;
        window.foobar = null;
+       
        var verifyEvaluation = function() {
                equals( foobar, "bar", 'Check if script src was evaluated after load' );
                equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
-                start();
+               
+               // Cleanup the global namespace
+               delete window.foobar;
+               delete window.testFoo;
+               
+               start();
        };
        jQuery('#first').load(url('data/test.html'), function() {
                ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
@@ -377,10 +389,13 @@ test("load(String, Function) - check scripts", function() {
 test("load(String, Function) - check file with only a script tag", function() {
        expect(3);
        stop();
-       testFoo = undefined;
+       window.testFoo = undefined;
        jQuery('#first').load(url('data/test2.html'), function() {
                equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
                equals( testFoo, "foo", 'Check if script was evaluated after load' );
+               
+               // Cleanup the global namespace
+               delete window.testFoo;
                start();
        });
 });
@@ -429,6 +444,7 @@ test("jQuery.getScript(String, Function) - with callback", function() {
        window.foobar = null;
        jQuery.getScript(url("data/test.js"), function() {
                equals( foobar, "bar", 'Check if script was evaluated' );
+               delete window.foobar;
                setTimeout(start, 100);
        });
 });
@@ -436,7 +452,10 @@ test("jQuery.getScript(String, Function) - with callback", function() {
 test("jQuery.getScript(String, Function) - no callback", function() {
        expect(1);
        stop();
-       jQuery.getScript(url("data/test.js"), start);
+       jQuery.getScript(url("data/test.js"), function(){
+               delete window.foobar;
+               start();
+       });
 });
 
 test("jQuery.ajax() - JSONP, Local", function() {
@@ -624,6 +643,7 @@ test("jQuery.ajax() - script, Remote", function() {
                dataType: "script",
                success: function(data){
                        ok( foobar, "Script results returned (GET, no callback)" );
+                       delete window.foobar;
                        start();
                }
        });
@@ -644,6 +664,7 @@ test("jQuery.ajax() - script, Remote with POST", function() {
                success: function(data, status){
                        ok( foobar, "Script results returned (GET, no callback)" );
                        equals( status, "success", "Script results returned (GET, no callback)" );
+                       delete window.foobar;
                        start();
                }
        });
@@ -663,6 +684,7 @@ test("jQuery.ajax() - script, Remote with scheme-less URL", function() {
                dataType: "script",
                success: function(data){
                        ok( foobar, "Script results returned (GET, no callback)" );
+                       delete window.foobar;
                        start();
                }
        });
@@ -818,10 +840,11 @@ test("ajaxSetup()", function() {
        jQuery.ajax();
 });
 
+/*
 test("custom timeout does not set error message when timeout occurs, see #970", function() {
        stop();
        jQuery.ajax({
-               url: "data/name.php?wait=10",
+               url: "data/name.php?wait=1",
                timeout: 500,
                error: function(request, status) {
                        ok( status != null, "status shouldn't be null in error handler" );
@@ -830,6 +853,7 @@ test("custom timeout does not set error message when timeout occurs, see #970",
                }
        });
 });
+*/
 
 test("data option: evaluate function values (#2806)", function() {
        stop();