Skip to content

Commit

Permalink
Simplified headers tests: removed multiline headers (support is far t…
Browse files Browse the repository at this point in the history
…oo servers & browsers dependant) and made all the tests in a single request.
  • Loading branch information
jaubourg committed Dec 11, 2010
1 parent 0b0889c commit 974637d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 46 deletions.
21 changes: 18 additions & 3 deletions test/data/headers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

header( "Multiple-Line: Hello\n World" );
header( "Multiple-Multiple-Line: Hello\n Beautiful\n\t World" );
header( "Single-Line: Hello World" );
header( "Sample-Header: Hello World" );

$headers = array();

foreach( $_SERVER as $key => $value ) {

if ( substr( $key , 0 , 5 ) == "HTTP_" ) {

$key = str_replace( "_" , "-" , substr( $key , 5) );
$headers[ $key ] = $value;

}

}

foreach( explode( "_" , $_GET[ "keys" ] ) as $key ) {
echo "$key: " . $headers[ strtoupper( $key ) ] . "\n";
}
18 changes: 0 additions & 18 deletions test/data/headers.request.php

This file was deleted.

31 changes: 6 additions & 25 deletions test/unit/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ test("jQuery.ajax() - error callbacks", function() {

test(".ajax() - headers" , function() {

// No multiple line headers in IE
expect( jQuery.browser.msie ? 3 : 5 );
expect( 2 );

stop();

Expand All @@ -291,42 +290,24 @@ test(".ajax() - headers" , function() {
OthEr: "something else"
},
list = [],
i,
sync = 2;
i;

for( i in requestHeaders ) {
list.push( i );
}

list = list.join( "_" );

jQuery.ajax(url("data/headers.request.php?keys="+list), {
jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
headers: requestHeaders,
success: function( data ) {
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" );
if ( ! --sync ) start();
}
});

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" );
}
if ( ! --sync ) start();
equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
start();
},
error: function(){ ok(false, "error"); }
});
Expand Down

0 comments on commit 974637d

Please sign in to comment.