@@ -10,7 +10,7 @@ QUnit.test( "jQuery.ajax() deprecations on jqXHR", function( assert ) {
1010
1111 expectWarning ( assert , ".success(), .error(), .compete() calls" , 3 , function ( ) {
1212
13- jQuery . ajax ( "/ not-found.404" )
13+ return jQuery . ajax ( url ( " not-found.404" ) )
1414 . success ( jQuery . noop )
1515 . error ( function ( jQXHR ) {
1616
@@ -19,12 +19,104 @@ QUnit.test( "jQuery.ajax() deprecations on jqXHR", function( assert ) {
1919 } )
2020 . complete ( function ( ) {
2121 assert . ok ( true , "ajax complete" ) ;
22+ } )
23+ . catch ( jQuery . noop ) ;
24+ } ) . then ( function ( ) {
25+ done ( ) ;
26+ } ) ;
27+
28+ } ) ;
29+
30+ [ " - Same Domain" , " - Cross Domain" ] . forEach ( function ( label , crossDomain ) {
31+
32+ // The JSON-to-JSONP auto-promotion behavior is gone in jQuery 4.0 and as
33+ // it has security implications, we don't want to restore the legacy behavior.
34+ QUnit [ jQueryVersionSince ( "4.0.0" ) ? "skip" : "test" ] (
35+ "jQuery.ajax() JSON-to-JSONP auto-promotion" + label , function ( assert ) {
36+
37+ assert . expect ( 5 ) ;
38+
39+ var done = assert . async ( ) ,
40+ tests = [
41+ function ( ) {
42+ return expectNoWarning ( assert , "dataType: \"json\"" ,
43+ function ( ) {
44+ return jQuery . ajax ( {
45+ url : url ( "data/null.json" ) ,
46+ crossDomain : crossDomain ,
47+ dataType : "json"
48+ } ) . catch ( jQuery . noop ) ;
49+ }
50+ ) ;
51+ } ,
2252
23- // Wait for expectWarning to complete
24- setTimeout ( done , 1 ) ;
53+ function ( ) {
54+ return expectWarning ( assert , "dataType: \"json\", URL callback" , 1 ,
55+ function ( ) {
56+ return jQuery . ajax ( {
57+ url : url ( "data/null.json?callback=?" ) ,
58+ crossDomain : crossDomain ,
59+ dataType : "json"
60+ } ) . catch ( jQuery . noop ) ;
61+ }
62+ ) ;
63+ } ,
64+
65+ function ( ) {
66+ return expectWarning ( assert , "dataType: \"json\", data callback" , 1 ,
67+ function ( ) {
68+ return jQuery . ajax ( {
69+ url : url ( "data/null.json" ) ,
70+ crossDomain : crossDomain ,
71+ data : "callback=?" ,
72+ dataType : "json"
73+ } ) . catch ( jQuery . noop ) ;
74+ }
75+ ) ;
76+ } ,
77+
78+ function ( ) {
79+ return expectNoWarning ( assert , "dataType: \"jsonp\", URL callback" ,
80+ function ( ) {
81+ return jQuery . ajax ( {
82+ url : url ( "data/null.json?callback=?" ) ,
83+ crossDomain : crossDomain ,
84+ dataType : "jsonp"
85+ } ) . catch ( jQuery . noop ) ;
86+ }
87+ ) ;
88+ } ,
89+
90+ function ( ) {
91+ return expectNoWarning ( assert , "dataType: \"jsonp\", data callback" ,
92+ function ( ) {
93+ return jQuery . ajax ( {
94+ url : url ( "data/null.json" ) ,
95+ crossDomain : crossDomain ,
96+ data : "callback=?" ,
97+ dataType : "jsonp"
98+ } ) . catch ( jQuery . noop ) ;
99+ }
100+ ) ;
101+ }
102+ ] ;
103+
104+ // Invoke tests sequentially as they're async and early tests could get warnings
105+ // from later ones.
106+ function run ( tests ) {
107+ var test = tests [ 0 ] ;
108+ return test ( ) . then ( function ( ) {
109+ if ( tests . length > 1 ) {
110+ return run ( tests . slice ( 1 ) ) ;
111+ }
25112 } ) ;
26- } ) ;
113+ }
27114
115+ run ( tests )
116+ . then ( function ( ) {
117+ done ( ) ;
118+ } ) ;
119+ } ) ;
28120} ) ;
29121
30122}
0 commit comments