X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fajax.js;h=222dd9a38a2f06cd5abee653c1c03efb4f76a83e;hb=d303687815581987f75f2e40e833022fc25c8741;hp=87430c93a28cede36a018269531875d5bac5a927;hpb=ab3ba4a81252c4357a7aab5f24d765d41d47986e;p=jquery.git diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 87430c9..222dd9a 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -280,28 +280,38 @@ test("jQuery.ajax() - error callbacks", function() { test(".ajax() - headers" , function() { - // No multiple line headers in IE - expect( jQuery.browser.msie ? 2 : 4 ); + expect( 2 ); stop(); - jQuery.ajax({ - url: url("data/headers.php"), - success: function( _1 , _2 , xhr ){ - ok(true, "success"); - equals( xhr.getResponseHeader( "Single-Line" ) , "Hello World" , "Single line header" ); - // No multiple line headers in IE - if ( ! jQuery.browser.msie ) { - // Each browser has its own unique way to deal with spaces after line breaks - // in multiple line headers, so we use regular expressions - ok( /^Hello\s+World$/.test( xhr.getResponseHeader( "Multiple-Line" ) ) , "Multiple line" ); - ok( /^Hello\s+Beautiful\s+World$/.test( xhr.getResponseHeader( "Multiple-Multiple-Line" ) ) , "Multiple multiple line" ); + var requestHeaders = { + siMPle: "value", + "SometHing-elsE": "other value", + OthEr: "something else" + }, + list = [], + i; + + for( i in requestHeaders ) { + list.push( i ); + } + + jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), { + headers: requestHeaders, + success: function( data , _ , xhr ) { + var tmp = []; + for ( i in requestHeaders ) { + tmp.push( i , ": " , requestHeaders[ i ] , "\n" ); } + tmp = tmp.join( "" ); + + equals( data , tmp , "Headers were sent" ); + equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" ); start(); }, error: function(){ ok(false, "error"); } }); - + }); test(".ajax() - hash", function() { @@ -697,6 +707,10 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' ); equals( jQuery("thing", resp).length, 2, 'things in responseXML' ); start(); + }, + error: function(_1,_2,error) { + ok( false, error ); + start(); } }); }); @@ -1477,7 +1491,7 @@ test("jQuery.ajax() - json by content-type disabled with options", function() { }, success: function( text ) { equals( typeof text , "string" , "json wasn't auto-determined" ); - var json = this.dataConverters["text => json"]( text ); + var json = this.dataConverters["text json"]( text ); ok( json.length >= 2, "Check length"); equals( json[0].name, 'John', 'Check JSON: first, name' ); equals( json[0].age, 21, 'Check JSON: first, age' ); @@ -1813,23 +1827,6 @@ test("jQuery.ajax - Etag support", function() { }); }); -test("jQuery ajax - headers", function() { - - stop(); - - jQuery.ajax(url("data/css.php?wait=1&id=headers"), { - headers: { - testKey: "testValue" - }, - beforeSend: function( xhr ) { - equals( xhr.getRequestHeader("testKey") , "testValue" , "Headers properly set" ); - setTimeout( start , 13 ); - return false; - } - }); - -}); - test("jQuery ajax - failing cross-domain", function() { expect( 2 ); @@ -1874,7 +1871,7 @@ test("jQuery.ajax - active counter", function() { test( "jQuery.ajax - Location object as url (#7531)", 1, function () { var success = false; try { - var xhr = jQuery.ajax({ url: document.location }); + var xhr = jQuery.ajax({ url: window.location }); success = true; xhr.abort(); } catch (e) {}