aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/ajax.js
blob: 23fb0b47359856b7d4b439be461384a326e2e215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
cgit v1.2.3 (git 2.39.1) at 2025-08-13 16:24:21 +0000
 


d='n1592' href='#n1592'>1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
QUnit.module( "ajax", {
	afterEach: function() {
		jQuery( document ).off( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess" );
		moduleTeardown.apply( this, arguments );
	}
} );

( function() {
	QUnit.test( "Unit Testing Environment", function( assert ) {
		assert.expect( 2 );

		assert.ok( hasPHP, "Running in an environment with PHP support. The AJAX tests only run if the environment supports PHP!" );
		assert.ok( !isLocal, "Unit tests are not ran from file:// (especially in Chrome. If you must test from file:// with Chrome, run it with the --allow-file-access-from-files flag!)" );
	} );

	if ( !jQuery.ajax || ( isLocal && !hasPHP ) ) {
		return;
	}

	function addGlobalEvents( expected, assert ) {
		return function() {
			expected = expected || "";
			jQuery( document ).on( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError ajaxSuccess", function( e ) {
				assert.ok( expected.indexOf( e.type ) !== -1, e.type );
			} );
		};
	}

//----------- jQuery.ajax()

	testIframe(
		"XMLHttpRequest - Attempt to block tests because of dangling XHR requests (IE)",
		"ajax/unreleasedXHR.html",
		function( assert ) {
			assert.expect( 1 );
			assert.ok( true, "done" );
		}
	);

	ajaxTest( "jQuery.ajax() - success callbacks", 8, function( assert ) {
		return {
			setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
			url: url( "name.html" ),
			beforeSend: function() {
				assert.ok( true, "beforeSend" );
			},
			success: function() {
				assert.ok( true, "success" );
			},
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - success callbacks - (url, options) syntax", 8, function( assert ) {
		return {
			setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
			create: function( options ) {
				return jQuery.ajax( url( "name.html" ), options );
			},
			beforeSend: function() {
				assert.ok( true, "beforeSend" );
			},
			success: function() {
				assert.ok( true, "success" );
			},
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - execute js for crossOrigin when dataType option is provided", 3,
		function( assert ) {
			return {
				create: function( options ) {
					options.crossDomain = true;
					options.dataType = "script";
					return jQuery.ajax( url( "mock.php?action=script&header=ecma" ), options );
				},
				success: function() {
					assert.ok( true, "success" );
				},
				complete: function() {
					assert.ok( true, "complete" );
				}
			};
		}
	);

	ajaxTest( "jQuery.ajax() - custom attributes for script tag", 4,
		function( assert ) {
			return {
				create: function( options ) {
					var xhr;
					options.dataType = "script";
					options.scriptAttrs = { id: "jquery-ajax-test", async: "async" };
					xhr = jQuery.ajax( url( "mock.php?action=script" ), options );
					assert.equal( jQuery( "#jquery-ajax-test" ).attr( "async" ), "async", "attr value" );
					return xhr;
				},
				success: function() {
					assert.ok( true, "success" );
				},
				complete: function() {
					assert.ok( true, "complete" );
				}
			};
		}
	);

	ajaxTest( "jQuery.ajax() - do not execute js (crossOrigin)", 2, function( assert ) {
		return {
			create: function( options ) {
				options.crossDomain = true;
				return jQuery.ajax( url( "mock.php?action=script" ), options );
			},
			success: function() {
				assert.ok( true, "success" );
			},
			fail: function() {
				assert.ok( false, "fail" );
			},
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - success callbacks (late binding)", 8, function( assert ) {
		return {
			setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
			url: url( "name.html" ),
			beforeSend: function() {
				assert.ok( true, "beforeSend" );
			},
			success: true,
			afterSend: function( request ) {
				request.always( function() {
					assert.ok( true, "complete" );
				} ).done( function() {
					assert.ok( true, "success" );
				} ).fail( function() {
					assert.ok( false, "error" );
				} );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - success callbacks (oncomplete binding)", 8, function( assert ) {
		return {
			setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccess", assert ),
			url: url( "name.html" ),
			beforeSend: function() {
				assert.ok( true, "beforeSend" );
			},
			success: true,
			complete: function( xhr ) {
				xhr.always( function() {
					assert.ok( true, "complete" );
				} ).done( function() {
					assert.ok( true, "success" );
				} ).fail( function() {
					assert.ok( false, "error" );
				} );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - error callbacks", 8, function( assert ) {
		return {
			setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert ),
			url: url( "mock.php?action=wait&wait=5" ),
			beforeSend: function() {
				assert.ok( true, "beforeSend" );
			},
			afterSend: function( request ) {
				request.abort();
			},
			error: function() {
				assert.ok( true, "error" );
			},
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - textStatus and errorThrown values", 4, function( assert ) {
		return [ {
			url: url( "mock.php?action=wait&wait=5" ),
			error: function( _, textStatus, errorThrown ) {
				assert.strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
				assert.strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort" );
			},
			afterSend: function( request ) {
				request.abort();
			}
		},
		{
			url: url( "mock.php?action=wait&wait=5" ),
			error: function( _, textStatus, errorThrown ) {
				assert.strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
				assert.strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')" );
			},
			afterSend: function( request ) {
				request.abort( "mystatus" );
			}
		} ];
	} );

	ajaxTest( "jQuery.ajax() - responseText on error", 1, function( assert ) {
		return {
			url: url( "mock.php?action=error" ),
			error: function( xhr ) {
				assert.strictEqual( xhr.responseText, "plain text message", "Test jqXHR.responseText is filled for HTTP errors" );
			}
		};
	} );

	QUnit.test( "jQuery.ajax() - retry with jQuery.ajax( this )", function( assert ) {
		assert.expect( 2 );
		var previousUrl,
			firstTime = true,
			done = assert.async();
		jQuery.ajax( {
			url: url( "mock.php?action=error" ),
			error: function() {
				if ( firstTime ) {
					firstTime = false;
					jQuery.ajax( this );
				} else {
					assert.ok( true, "Test retrying with jQuery.ajax(this) works" );
					jQuery.ajax( {
						url: url( "mock.php?action=error&x=2" ),
						beforeSend: function() {
							if ( !previousUrl ) {
								previousUrl = this.url;
							} else {
								assert.strictEqual( this.url, previousUrl, "url parameters are not re-appended" );
								done();
								return false;
							}
						},
						error: function() {
							jQuery.ajax( this );
						}
					} );
				}
			}
		} );
	} );

	ajaxTest( "jQuery.ajax() - headers", 8, function( assert ) {
		return {
			setup: function() {
				jQuery( document ).ajaxSend( function( evt, xhr ) {
					xhr.setRequestHeader( "ajax-send", "test" );
				} );
			},
			url: url( "mock.php?action=headers&keys=siMPle|SometHing-elsE|OthEr|Nullable|undefined|Empty|ajax-send" ),
			headers: supportjQuery.extend( {
				"siMPle": "value",
				"SometHing-elsE": "other value",
				"OthEr": "something else",
				"Nullable": null,
				"undefined": undefined

				// Support: IE 9 - 11+, Edge 12 - 14 only
				// IE can receive empty headers but not send them.
			}, QUnit.isIE ? {} : {
				"Empty": ""
			} ),
			success: function( data, _, xhr ) {
				var i,
					requestHeaders = jQuery.extend( this.headers, {
						"ajax-send": "test"
					} ),
					tmp = [];
				for ( i in requestHeaders ) {
					tmp.push( i, ": ", requestHeaders[ i ] + "", "\n" );
				}
				tmp = tmp.join( "" );

				assert.strictEqual( data, tmp, "Headers were sent" );
				assert.strictEqual( xhr.getResponseHeader( "Sample-Header" ), "Hello World", "Sample header received" );
				assert.ok( data.indexOf( "undefined" ) < 0, "Undefined header value was not sent" );
				assert.strictEqual( xhr.getResponseHeader( "Empty-Header" ), "", "Empty header received" );
				assert.strictEqual( xhr.getResponseHeader( "Sample-Header2" ), "Hello World 2", "Second sample header received" );
				assert.strictEqual( xhr.getResponseHeader( "List-Header" ), "Item 1, Item 2", "List header received" );
				assert.strictEqual( xhr.getResponseHeader( "constructor" ), "prototype collision (constructor)", "constructor header received" );
				assert.strictEqual( xhr.getResponseHeader( "__proto__" ), null, "Undefined __proto__ header not received" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - Accept header", 1, function( assert ) {
		return {
			url: url( "mock.php?action=headers&keys=accept" ),
			headers: {
				Accept: "very wrong accept value"
			},
			beforeSend: function( xhr ) {
				xhr.setRequestHeader( "Accept", "*/*" );
			},
			success: function( data ) {
				assert.strictEqual( data, "accept: */*\n", "Test Accept header is set to last value provided" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - contentType", 2, function( assert ) {
		return [
			{
				url: url( "mock.php?action=headers&keys=content-type" ),
				contentType: "test",
				success: function( data ) {
					assert.strictEqual( data, "content-type: test\n", "Test content-type is sent when options.contentType is set" );
				}
			},
			{
				url: url( "mock.php?action=headers&keys=content-type" ),
				contentType: false,
				success: function( data ) {

					// Some server/interpreter combinations always supply a Content-Type to scripts
					data = data || "content-type: \n";
					assert.strictEqual( data, "content-type: \n", "Test content-type is not set when options.contentType===false" );
				}
			}
		];
	} );

	ajaxTest( "jQuery.ajax() - protocol-less urls", 1, function( assert ) {
		return {
			url: "//somedomain.com",
			beforeSend: function( xhr, settings ) {
				assert.equal( settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added." );
				return false;
			},
			error: true
		};
	} );

	ajaxTest( "jQuery.ajax() - URL fragment component preservation", 4, function( assert ) {
		return [
			{
				url: baseURL + "name.html#foo",
				beforeSend: function( xhr, settings ) {
					assert.equal( settings.url, baseURL + "name.html#foo",
						"hash preserved for request with no query component." );
					return false;
				},
				error: true
			},
			{
				url: baseURL + "name.html?abc#foo",
				beforeSend: function( xhr, settings ) {
					assert.equal( settings.url, baseURL + "name.html?abc#foo",
						"hash preserved for request with query component." );
					return false;
				},
				error: true
			},
			{
				url: baseURL + "name.html?abc#foo",
				data: {
					"test": 123
				},
				beforeSend: function( xhr, settings ) {
					assert.equal( settings.url, baseURL + "name.html?abc&test=123#foo",
						"hash preserved for request with query component and data." );
					return false;
				},
				error: true
			},
			{
				url: baseURL + "name.html?abc#brownies",
				data: {
					"devo": "hat"
				},
				cache: false,
				beforeSend: function( xhr, settings ) {
					// Clear the cache-buster param value
					var url = settings.url.replace( /_=[^&#]+/, "_=" );
					assert.equal( url, baseURL + "name.html?abc&devo=hat&_=#brownies",
						"hash preserved for cache-busting request with query component and data." );
					return false;
				},
				error: true
			}
		];
	} );

	ajaxTest( "jQuery.ajax() - traditional param encoding", 4, function( assert ) {
		return [
			{
				url: "/",
				traditional: true,
				data: {
					"devo": "hat",
					"answer": 42,
					"quux": "a space"
				},
				beforeSend: function( xhr, settings ) {
					assert.equal( settings.url, "/?devo=hat&answer=42&quux=a%20space", "Simple case" );
					return false;
				},
				error: true
			},
			{
				url: "/",
				traditional: true,
				data: {
					"a": [ 1, 2, 3 ],
					"b[]": [ "b1", "b2" ]
				},
				beforeSend: function( xhr, settings ) {
					assert.equal( settings.url, "/?a=1&a=2&a=3&b%5B%5D=b1&b%5B%5D=b2", "Arrays" );
					return false;
				},
				error: true
			},
			{
				url: "/",
				traditional: true,
				data: {
					"a": [ [ 1, 2 ], [ 3, 4 ], 5 ]
				},
				beforeSend: function( xhr, settings ) {
					assert.equal( settings.url, "/?a=1%2C2&a=3%2C4&a=5", "Nested arrays" );
					return false;
				},
				error: true
			},
			{
				url: "/",
				traditional: true,
				data: {
					"a": [ "w", [ [ "x", "y" ], "z" ] ]
				},
				cache: false,
				beforeSend: function( xhr, settings ) {
					var url = settings.url.replace( /\d{3,}/, "" );
					assert.equal( url, "/?a=w&a=x%2Cy%2Cz&_=", "Cache-buster" );
					return false;
				},
				error: true
			}
		];
	} );

	ajaxTest( "jQuery.ajax() - cross-domain detection", 8, function( assert ) {
		function request( url, title, crossDomainOrOptions ) {
			return jQuery.extend( {
				dataType: "jsonp",
				url: url,
				beforeSend: function( _, s ) {
					assert.ok( crossDomainOrOptions === false ? !s.crossDomain : s.crossDomain, title );
					return false;
				},
				error: true
			}, crossDomainOrOptions );
		}

		var loc = document.location,
			samePort = loc.port || ( loc.protocol === "http:" ? 80 : 443 ),
			otherPort = loc.port === 666 ? 667 : 666,
			otherProtocol = loc.protocol === "http:" ? "https:" : "http:";

		return [
			request(
				loc.protocol + "//" + loc.hostname + ":" + samePort,
				"Test matching ports are not detected as cross-domain",
				false
			),
			request(
				otherProtocol + "//" + loc.host,
				"Test different protocols are detected as cross-domain"
			),
			request(
				"app:/path",
				"Adobe AIR app:/ URL detected as cross-domain"
			),
			request(
				loc.protocol + "//example.invalid:" + ( loc.port || 80 ),
				"Test different hostnames are detected as cross-domain"
			),
			request(
				loc.protocol + "//" + loc.hostname + ":" + otherPort,
				"Test different ports are detected as cross-domain"
			),
			request(
				"about:blank",
				"Test about:blank is detected as cross-domain"
			),
			request(
				loc.protocol + "//" + loc.host,
				"Test forced crossDomain is detected as cross-domain",
				{
					crossDomain: true
				}
			),
			request(
				" https://otherdomain.com",
				"Cross-domain url with leading space is detected as cross-domain"
			)
		];
	} );

	ajaxTest( "jQuery.ajax() - abort", 9, function( assert ) {
		return {
			setup: addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxError ajaxComplete", assert ),
			url: url( "mock.php?action=wait&wait=5" ),
			beforeSend: function() {
				assert.ok( true, "beforeSend" );
			},
			afterSend: function( xhr ) {
				assert.strictEqual( xhr.readyState, 1, "XHR readyState indicates successful dispatch" );
				xhr.abort();
				assert.strictEqual( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
			},
			error: true,
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - native abort", 2, function( assert ) {
		return {
			url: url( "mock.php?action=wait&wait=1" ),
			xhr: function() {
				var xhr = new window.XMLHttpRequest();
				setTimeout( function() {
					xhr.abort();
				}, 100 );
				return xhr;
			},
			error: function( xhr, msg ) {
				assert.strictEqual( msg, "error", "Native abort triggers error callback" );
			},
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - native timeout", 2, function( assert ) {
		return {
			url: url( "mock.php?action=wait&wait=1" ),
			xhr: function() {
				var xhr = new window.XMLHttpRequest();
				xhr.timeout = 1;
				return xhr;
			},
			error: function( xhr, msg ) {
				assert.strictEqual( msg, "error", "Native timeout triggers error callback" );
			},
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) {
		var context = document.createElement( "div" );

		function event( e ) {
			assert.equal( this, context, e.type );
		}

		function callback( msg ) {
			return function() {
				assert.equal( this, context, "context is preserved on callback " + msg );
			};
		}

		return {
			setup: function() {
				jQuery( context ).appendTo( "#foo" )
					.ajaxSend( event )
					.ajaxComplete( event )
					.ajaxError( event )
					.ajaxSuccess( event );
			},
			requests: [ {
				url: url( "name.html" ),
				context: context,
				beforeSend: callback( "beforeSend" ),
				success: callback( "success" ),
				complete: callback( "complete" )
			}, {
				url: url( "404.txt" ),
				context: context,
				beforeSend: callback( "beforeSend" ),
				error: callback( "error" ),
				complete: callback( "complete" )
			} ]
		};
	} );

	ajaxTest( "jQuery.ajax() - events without context", 3, function( assert ) {
		function nocallback( msg ) {
			return function() {
				assert.equal( typeof this.url, "string", "context is settings on callback " + msg );
			};
		}
		return {
			url: url( "404.txt" ),
			beforeSend: nocallback( "beforeSend" ),
			error: nocallback( "error" ),
			complete:  nocallback( "complete" )
		};
	} );

	ajaxTest( "#15118 - jQuery.ajax() - function without jQuery.event", 1, function( assert ) {
		var holder;
		return {
			url: url( "mock.php?action=json" ),
			setup: function() {
				holder = jQuery.event;
				delete jQuery.event;
			},
			complete: function() {
				assert.ok( true, "Call can be made without jQuery.event" );
				jQuery.event = holder;
			},
			success: true
		};
	} );

	ajaxTest( "#15160 - jQuery.ajax() - request manually aborted in ajaxSend", 3, function( assert ) {
		return {
			setup: function() {
				jQuery( document ).on( "ajaxSend", function( e, jqXHR ) {
					jqXHR.abort();
				} );

				jQuery( document ).on( "ajaxError ajaxComplete", function( e, jqXHR ) {
					assert.equal( jqXHR.statusText, "abort", "jqXHR.statusText equals abort on global ajaxComplete and ajaxError events" );
				} );
			},
			url: url( "name.html" ),
			error: true,
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - context modification", 1, function( assert ) {
		return {
			url: url( "name.html" ),
			context: {},
			beforeSend: function() {
				this.test = "foo";
			},
			afterSend: function() {
				assert.strictEqual( this.context.test, "foo", "Make sure the original object is maintained." );
			},
			success: true
		};
	} );

	ajaxTest( "jQuery.ajax() - context modification through ajaxSetup", 3, function( assert ) {
		var obj = {};
		return {
			setup: function() {
				jQuery.ajaxSetup( {
					context: obj
				} );
				assert.strictEqual( jQuery.ajaxSettings.context, obj, "Make sure the context is properly set in ajaxSettings." );
			},
			requests: [ {
				url: url( "name.html" ),
				success: function() {
					assert.strictEqual( this, obj, "Make sure the original object is maintained." );
				}
			}, {
				url: url( "name.html" ),
				context: {},
				success: function() {
					assert.ok( this !== obj, "Make sure overriding context is possible." );
				}
			} ]
		};
	} );

	ajaxTest( "jQuery.ajax() - disabled globals", 3, function( assert ) {
		return {
			setup: addGlobalEvents( "", assert ),
			global: false,
			url: url( "name.html" ),
			beforeSend: function() {
				assert.ok( true, "beforeSend" );
			},
			success: function() {
				assert.ok( true, "success" );
			},
			complete: function() {
				assert.ok( true, "complete" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements", 3, function( assert ) {
		return {
			url: url( "with_fries.xml" ),
			dataType: "xml",
			success: function( resp ) {
				assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
				assert.equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
				assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - xml: non-namespace elements inside namespaced elements (over JSONP)", 3, function( assert ) {
		return {
			url: url( "mock.php?action=xmlOverJsonp" ),
			dataType: "jsonp xml",
			success: function( resp ) {
				assert.equal( jQuery( "properties", resp ).length, 1, "properties in responseXML" );
				assert.equal( jQuery( "jsconf", resp ).length, 1, "jsconf in responseXML" );
				assert.equal( jQuery( "thing", resp ).length, 2, "things in responseXML" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - HEAD requests", 2, function( assert ) {
		return [
			{
				url: url( "name.html" ),
				type: "HEAD",
				success: function( data, status, xhr ) {
					assert.ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response" );
				}
			},
			{
				url: url( "name.html" ),
				data: {
					"whip_it": "good"
				},
				type: "HEAD",
				success: function( data, status, xhr ) {
					assert.ok( /Date/i.test( xhr.getAllResponseHeaders() ), "No Date in HEAD response with data" );
				}
			}
		];
	} );

	ajaxTest( "jQuery.ajax() - beforeSend", 1, function( assert ) {
		return {
			url: url( "name.html" ),
			beforeSend: function() {
				this.check = true;
			},
			success: function() {
				assert.ok( this.check, "check beforeSend was executed" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - beforeSend, cancel request manually", 2, function( assert ) {
		return {
			create: function() {
				return jQuery.ajax( {
					url: url( "name.html" ),
					beforeSend: function( xhr ) {
						assert.ok( true, "beforeSend got called, canceling" );
						xhr.abort();
					},
					success: function() {
						assert.ok( false, "request didn't get canceled" );
					},
					complete: function() {
						assert.ok( false, "request didn't get canceled" );
					},
					error: function() {
						assert.ok( false, "request didn't get canceled" );
					}
				} );
			},
			fail: function( _, reason ) {
				assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - dataType html", 5, function( assert ) {
		return {
			setup: function() {
				Globals.register( "testFoo" );
				Globals.register( "testBar" );
			},
			dataType: "html",
			url: url( "mock.php?action=testHTML&baseURL=" + baseURL ),
			success: function( data ) {
				assert.ok( data.match( /^html text/ ), "Check content for datatype html" );
				jQuery( "#ap" ).html( data );
				assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated for datatype html" );
				assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated for datatype html" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - do not execute scripts from unsuccessful responses (gh-4250)", 11, function( assert ) {
		var globalEval = jQuery.globalEval;

		var failConverters = {
			"text script": function() {
				assert.ok( false, "No converter for unsuccessful response" );
			}
		};

		function request( title, options ) {
			var testMsg = title + ": expected file missing status";
			return jQuery.extend( {
				beforeSend: function() {
					jQuery.globalEval = function() {
						assert.ok( false, "Should not eval" );
					};
				},
				complete: function() {
					jQuery.globalEval = globalEval;
				},
				// error is the significant assertion
				error: function( xhr ) {
					assert.strictEqual( xhr.status, 404, testMsg );
				},
				success: function() {
					assert.ok( false, "Unanticipated success" );
				}
			}, options );
		}

		return [
			request(
				"HTML reply",
				{
					url: url( "404.txt" )
				}
			),
			request(
				"HTML reply with dataType",
				{
					dataType: "script",
					url: url( "404.txt" )
				}
			),
			request(
				"script reply",
				{
					url: url( "mock.php?action=errorWithScript&withScriptContentType" )
				}
			),
			request(
				"non-script reply",
				{
					url: url( "mock.php?action=errorWithScript" )
				}
			),
			request(
				"script reply with dataType",
				{
					dataType: "script",
					url: url( "mock.php?action=errorWithScript&withScriptContentType" )
				}
			),
			request(
				"non-script reply with dataType",
				{
					dataType: "script",
					url: url( "mock.php?action=errorWithScript" )
				}
			),
			request(
				"script reply with converter",
				{
					converters: failConverters,
					url: url( "mock.php?action=errorWithScript&withScriptContentType" )
				}
			),
			request(
				"non-script reply with converter",
				{
					converters: failConverters,
					url: url( "mock.php?action=errorWithScript" )
				}
			),
			request(
				"script reply with converter and dataType",
				{
					converters: failConverters,
					dataType: "script",
					url: url( "mock.php?action=errorWithScript&withScriptContentType" )
				}
			),
			request(
				"non-script reply with converter and dataType",
				{
					converters: failConverters,
					dataType: "script",
					url: url( "mock.php?action=errorWithScript" )
				}
			),
			request(
				"JSONP reply with dataType",
				{
					dataType: "jsonp",
					url: url( "mock.php?action=errorWithScript" ),
					beforeSend: function() {
						jQuery.globalEval = function( response ) {
							assert.ok( /"status": 404, "msg": "Not Found"/.test( response ), "Error object returned" );
						};
					}
				}
			)
		];
	} );

	ajaxTest( "jQuery.ajax() - synchronous request", 1, function( assert ) {
		return {
			url: url( "json_obj.js" ),
			dataType: "text",
			async: false,
			success: true,
			afterSend: function( xhr ) {
				assert.ok( /^\{ "data"/.test( xhr.responseText ), "check returned text" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - synchronous request with callbacks", 2, function( assert ) {
		return {
			url: url( "json_obj.js" ),
			async: false,
			dataType: "text",
			success: true,
			afterSend: function( xhr ) {
				var result;
				xhr.done( function( data ) {
					assert.ok( true, "success callback executed" );
					result = data;
				} );
				assert.ok( /^\{ "data"/.test( result ), "check returned text" );
			}
		};
	} );

	QUnit.test( "jQuery.ajax(), jQuery.get[Script|JSON](), jQuery.post(), pass-through request object", function( assert ) {
		assert.expect( 8 );
		var done = assert.async();
		var target = "name.html",
			successCount = 0,
			errorCount = 0,
			errorEx = "",
			success = function() {
				successCount++;
			};
		jQuery( document ).on( "ajaxError.passthru", function( e, xml ) {
			errorCount++;
			errorEx += ": " + xml.status;
		} );
		jQuery( document ).one( "ajaxStop", function() {
			assert.equal( successCount, 5, "Check all ajax calls successful" );
			assert.equal( errorCount, 0, "Check no ajax errors (status" + errorEx + ")" );
			jQuery( document ).off( "ajaxError.passthru" );
			done();
		} );
		Globals.register( "testBar" );

		assert.ok( jQuery.get( url( target ), success ), "get" );
		assert.ok( jQuery.post( url( target ), success ), "post" );
		assert.ok( jQuery.getScript( url( "mock.php?action=testbar" ), success ), "script" );
		assert.ok( jQuery.getJSON( url( "json_obj.js" ), success ), "json" );
		assert.ok( jQuery.ajax( {
			url: url( target ),
			success: success
		} ), "generic" );
	} );

	ajaxTest( "jQuery.ajax() - cache", 28, function( assert ) {
		var re = /_=(.*?)(&|$)/g,
			rootUrl = baseURL + "text.txt";

		function request( url, title ) {
			return {
				url: url,
				cache: false,
				beforeSend: function() {
					var parameter, tmp;

					// URL sanity check
					assert.equal( this.url.indexOf( rootUrl ), 0, "root url not mangled: " + this.url );
					assert.equal( /\&.*\?/.test( this.url ), false, "parameter delimiters in order" );

					while ( ( tmp = re.exec( this.url ) ) ) {
						assert.strictEqual( parameter, undefined, title + ": only one 'no-cache' parameter" );
						parameter = tmp[ 1 ];
						assert.notStrictEqual( parameter, "tobereplaced555", title + ": parameter (if it was there) was replaced" );
					}
					return false;
				},
				error: true
			};
		}

		return [
			request(
				rootUrl,
				"no query"
			),
			request(
				rootUrl + "?",
				"empty query"
			),
			request(
				rootUrl + "?pizza=true",
				"1 parameter"
			),
			request(
				rootUrl + "?_=tobereplaced555",
				"_= parameter"
			),
			request(
				rootUrl + "?pizza=true&_=tobereplaced555",
				"1 parameter and _="
			),
			request(
				rootUrl + "?_=tobereplaced555&tv=false",
				"_= and 1 parameter"
			),
			request(
				rootUrl + "?name=David&_=tobereplaced555&washere=true",
				"2 parameters surrounding _="
			)
		];
	} );

	jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {

		ajaxTest( "jQuery.ajax() - JSONP - Query String (?n)" + label, 4, function( assert ) {
			return [
				{
					url: baseURL + "mock.php?action=jsonp&callback=?",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( data.data, "JSON results returned (GET, url callback)" );
					}
				},
				{
					url: baseURL + "mock.php?action=jsonp&callback=??",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( data.data, "JSON results returned (GET, url context-free callback)" );
					}
				},
				{
					url: baseURL + "mock.php/???action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( data.data, "JSON results returned (GET, REST-like)" );
					}
				},
				{
					url: baseURL + "mock.php/???action=jsonp&array=1",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( Array.isArray( data ), "JSON results returned (GET, REST-like with param)" );
					}
				}
			];
		} );

		ajaxTest( "jQuery.ajax() - JSONP - Explicit callback param" + label, 10, function( assert ) {
			return {
				setup: function() {
					Globals.register( "functionToCleanUp" );
					Globals.register( "XXX" );
					Globals.register( "jsonpResults" );
					window[ "jsonpResults" ] = function( data ) {
						assert.ok( data[ "data" ], "JSON results returned (GET, custom callback function)" );
					};
				},
				requests: [ {
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					jsonp: "callback",
					success: function( data ) {
						assert.ok( data[ "data" ], "JSON results returned (GET, data obj callback)" );
					}
				}, {
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					jsonpCallback: "jsonpResults",
					success: function( data ) {
						assert.strictEqual(
							typeof window[ "jsonpResults" ],
							"function",
							"should not rewrite original function"
						);
						assert.ok( data.data, "JSON results returned (GET, custom callback name)" );
					}
				}, {
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					jsonpCallback: "functionToCleanUp",
					success: function( data ) {
						assert.ok( data[ "data" ], "JSON results returned (GET, custom callback name to be cleaned up)" );
						assert.strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed (GET, custom callback name to be cleaned up)" );
						var xhr;
						jQuery.ajax( {
							url: baseURL + "mock.php?action=jsonp",
							dataType: "jsonp",
							crossDomain: crossDomain,
							jsonpCallback: "functionToCleanUp",
							beforeSend: function( jqXHR ) {
								xhr = jqXHR;
								return false;
							}
						} );
						xhr.fail( function() {
							assert.ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
							assert.strictEqual( window[ "functionToCleanUp" ], true, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
						} );
					}
				}, {
					url: baseURL + "mock.php?action=jsonp&callback=XXX",
					dataType: "jsonp",
					jsonp: false,
					jsonpCallback: "XXX",
					crossDomain: crossDomain,
					beforeSend: function() {
						assert.ok( /action=jsonp&callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
					},
					success: function( data ) {
						assert.ok( data[ "data" ], "JSON results returned (GET, custom callback name with no url manipulation)" );
					}
				} ]
			};
		} );

		ajaxTest( "jQuery.ajax() - JSONP - Callback in data" + label, 2, function( assert ) {
			return [
				{
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					data: "callback=?",
					success: function( data ) {
						assert.ok( data.data, "JSON results returned (GET, data callback)" );
					}
				},
				{
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					data: "callback=??",
					success: function( data ) {
						assert.ok( data.data, "JSON results returned (GET, data context-free callback)" );
					}
				}
			];
		} );

		ajaxTest( "jQuery.ajax() - JSONP - POST" + label, 3, function( assert ) {
			return [
				{
					type: "POST",
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( data[ "data" ], "JSON results returned (POST, no callback)" );
					}
				},
				{
					type: "POST",
					url: baseURL + "mock.php?action=jsonp",
					data: "callback=?",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( data[ "data" ], "JSON results returned (POST, data callback)" );
					}
				},
				{
					type: "POST",
					url: baseURL + "mock.php?action=jsonp",
					jsonp: "callback",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( data[ "data" ], "JSON results returned (POST, data obj callback)" );
					}
				}
			];
		} );

		ajaxTest( "jQuery.ajax() - JSONP" + label, 3, function( assert ) {
			return [
				{
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: function( data ) {
						assert.ok( data.data, "JSON results returned (GET, no callback)" );
					}
				},
				{
					create: function( options ) {
						var request = jQuery.ajax( options ),
							promise = request.then( function( data ) {
								assert.ok( data.data, "first request: JSON results returned (GET, no callback)" );
								request = jQuery.ajax( this ).done( function( data ) {
									assert.ok( data.data, "this re-used: JSON results returned (GET, no callback)" );
								} );
								promise.abort = request.abort;
								return request;
							} );
						promise.abort = request.abort;
						return promise;
					},
					url: baseURL + "mock.php?action=jsonp",
					dataType: "jsonp",
					crossDomain: crossDomain,
					success: true
				}
			];
		} );

	} );

	ajaxTest( "jQuery.ajax() - script, Remote", 2, function( assert ) {
		return {
			setup: function() {
				Globals.register( "testBar" );
			},
			url: url( "mock.php?action=testbar" ),
			dataType: "script",
			success: function() {
				assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - script, Remote with POST", 3, function( assert ) {
		return {
			setup: function() {
				Globals.register( "testBar" );
			},
			url: url( "mock.php?action=testbar" ),
			type: "POST",
			dataType: "script",
			success: function( data, status ) {
				assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (POST, no callback)" );
				assert.strictEqual( status, "success", "Script results returned (POST, no callback)" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - script, Remote with scheme-less URL", 2, function( assert ) {
		return {
			setup: function() {
				Globals.register( "testBar" );
			},
			url: url( "mock.php?action=testbar" ),
			dataType: "script",
			success: function() {
				assert.strictEqual( window[ "testBar" ], "bar", "Script results returned (GET, no callback)" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - malformed JSON", 2, function( assert ) {
		return {
			url: baseURL + "badjson.js",
			dataType: "json",
			error: function( xhr, msg, detailedMsg ) {
				assert.strictEqual( msg, "parsererror", "A parse error occurred." );
				assert.ok( /(invalid|error|exception)/i.test( detailedMsg ), "Detailed parsererror message provided" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - script by content-type", 2, function() {
		return [
			{
				url: baseURL + "mock.php?action=script",
				data: {
					"header": "script"
				},
				success: true
			},
			{
				url: baseURL + "mock.php?action=script",
				data: {
					"header": "ecma"
				},
				success: true
			}
		];
	} );

	ajaxTest( "jQuery.ajax() - JSON by content-type", 5, function( assert ) {
		return {
			url: baseURL + "mock.php?action=json",
			data: {
				"header": "json",
				"array": "1"
			},
			success: function( json ) {
				assert.ok( json.length >= 2, "Check length" );
				assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" );
				assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
				assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
				assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - JSON by content-type disabled with options", 6, function( assert ) {
		return {
			url: url( "mock.php?action=json" ),
			data: {
				"header": "json",
				"array": "1"
			},
			contents: {
				"json": false
			},
			success: function( text ) {
				assert.strictEqual( typeof text, "string", "json wasn't auto-determined" );
				var json = JSON.parse( text );
				assert.ok( json.length >= 2, "Check length" );
				assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" );
				assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
				assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
				assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - simple get", 1, function( assert ) {
		return {
			type: "GET",
			url: url( "mock.php?action=name&name=foo" ),
			success: function( msg ) {
				assert.strictEqual( msg, "bar", "Check for GET" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - simple post", 1, function( assert ) {
		return {
			type: "POST",
			url: url( "mock.php?action=name" ),
			data: "name=peter",
			success: function( msg ) {
				assert.strictEqual( msg, "pan", "Check for POST" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - data option - empty bodies for non-GET requests", 1, function( assert ) {
		return {
			url: baseURL + "mock.php?action=echoData",
			data: undefined,
			type: "post",
			success: function( result ) {
				assert.strictEqual( result, "" );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - data - x-www-form-urlencoded (gh-2658)", 1, function( assert ) {
		return {
			url: "bogus.html",
			data: { devo: "A Beautiful World" },
			type: "post",
			beforeSend: function( _, s ) {
				assert.strictEqual( s.data, "devo=A+Beautiful+World", "data is '+'-encoded" );
				return false;
			},
			error: true
		};
	} );

	ajaxTest( "jQuery.ajax() - data - text/plain (gh-2658)", 1, function( assert ) {
		return {
			url: "bogus.html",
			data: { devo: "A Beautiful World" },
			type: "post",
			contentType: "text/plain",
			beforeSend: function( _, s ) {
				assert.strictEqual( s.data, "devo=A%20Beautiful%20World", "data is %20-encoded" );
				return false;
			},
			error: true
		};
	} );

	ajaxTest( "jQuery.ajax() - data - no processing POST", 1, function( assert ) {
		return {
			url: "bogus.html",
			data: { devo: "A Beautiful World" },
			type: "post",
			contentType: "x-special-sauce",
			processData: false,
			beforeSend: function( _, s ) {
				assert.deepEqual( s.data, { devo: "A Beautiful World" }, "data is not processed" );
				return false;
			},
			error: true
		};
	} );

	ajaxTest( "jQuery.ajax() - data - no processing GET", 1, function( assert ) {
		return {
			url: "bogus.html",
			data: { devo: "A Beautiful World" },
			type: "get",
			contentType: "x-something-else",
			processData: false,
			beforeSend: function( _, s ) {
				assert.deepEqual( s.data, { devo: "A Beautiful World" }, "data is not processed" );
				return false;
			},
			error: true
		};
	} );

		ajaxTest( "jQuery.ajax() - data - process string with GET", 2, function( assert ) {
		return {
			url: "bogus.html",
			data: "a=1&b=2",
			type: "get",
			contentType: "x-something-else",
			processData: false,
			beforeSend: function( _, s ) {
				assert.equal( s.url, "bogus.html?a=1&b=2", "added data to url" );
				assert.equal( s.data, undefined, "removed data from settings" );
				return false;
			},
			error: true
		};
	} );

	var ifModifiedNow = new Date();

	jQuery.each(
		/* jQuery.each arguments start */
		{
			" (cache)": true,
			" (no cache)": false
		},
		function( label, cache ) {
			jQuery.each(
				{
					"If-Modified-Since": "mock.php?action=ims",
					"Etag": "mock.php?action=etag"
				},
				function( type, url ) {
					url = baseURL + url + "&ts=" + ifModifiedNow++;
					QUnit.test( "jQuery.ajax() - " + type + " support" + label, function( assert ) {
						assert.expect( 4 );
						var done = assert.async();
						jQuery.ajax( {
							url: url,
							ifModified: true,
							cache: cache,
							success: function( _, status ) {
								assert.strictEqual( status, "success", "Initial status is 'success'" );
								jQuery.ajax( {
									url: url,
									ifModified: true,
									cache: cache,
									success: function( data, status, jqXHR ) {
										assert.strictEqual( status, "notmodified", "Following status is 'notmodified'" );
										assert.strictEqual( jqXHR.status, 304, "XHR status is 304" );
										assert.equal( data, null, "no response body is given" );
									},
									complete: function() {
										done();
									}
								} );
							}
						} );
					} );
				}
			);
		}
		/* jQuery.each arguments end */
	);

	ajaxTest( "jQuery.ajax() - failing cross-domain (non-existing)", 1, function( assert ) {
		return {

			// see RFC 2606
			url: "https://example.invalid",
			error: function( xhr, _, e ) {
				assert.ok( true, "file not found: " + xhr.status + " => " + e );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - failing cross-domain", 1, function( assert ) {
		return {
			url: "https://" + externalHost,
			error: function( xhr, _, e ) {
				assert.ok( true, "access denied: " + xhr.status + " => " + e );
			}
		};
	} );

	ajaxTest( "jQuery.ajax() - atom+xml", 1, function( assert ) {
		return {
			url: url( "mock.php?action=atom" ),
			success: function() {
				assert.ok( true, "success" );
			}
		};
	} );

	QUnit.test( "jQuery.ajax() - statusText", function( assert ) {
		assert.expect( 3 );
		var done = assert.async();
		jQuery.ajax( url( "mock.php?action=status&code=200&text=Hello" ) ).done( function( _, statusText, jqXHR ) {
			assert.strictEqual( statusText, "success", "callback status text ok for success" );
			assert.ok( jqXHR.statusText === "Hello" || jqXHR.statusText === "OK", "jqXHR status text ok for success (" + jqXHR.statusText + ")" );
			jQuery.ajax( url( "mock.php?action=status&code=404&text=World" ) ).fail( function( jqXHR, statusText ) {
				assert.strictEqual( statusText, "error", "callback status text ok for error" );
				done();
			} );
		} );
	} );

	QUnit.test( "jQuery.ajax() - statusCode", function( assert ) {
		assert.expect( 20 );
		var done = assert.async(),
			count = 12;

		function countComplete() {
			if ( !--count ) {
				done();
			}
		}

		function createStatusCodes( name, isSuccess ) {
			name = "Test " + name + " " + ( isSuccess ? "success" : "error" );
			return {
				200: function() {
					assert.ok( isSuccess, name );
				},
				404: function() {
					assert.ok( !isSuccess, name );
				}
			};
		}

		jQuery.each(
			/* jQuery.each arguments start */
			{
				"name.html": true,
				"404.txt": false
			},
			function( uri, isSuccess ) {
				jQuery.ajax( url( uri ), {
					statusCode: createStatusCodes( "in options", isSuccess ),
					complete: countComplete
				} );

				jQuery.ajax( url( uri ), {
					complete: countComplete
				} ).statusCode( createStatusCodes( "immediately with method", isSuccess ) );

				jQuery.ajax( url( uri ), {
					complete: function( jqXHR ) {
						jqXHR.statusCode( createStatusCodes( "on complete", isSuccess ) );
						countComplete();
					}
				} );

				jQuery.ajax( url( uri ), {
					complete: function( jqXHR ) {
						setTimeout( function() {
							jqXHR.statusCode( createStatusCodes( "very late binding", isSuccess ) );
							countComplete();
						}, 100 );
					}
				} );

				jQuery.ajax( url( uri ), {
					statusCode: createStatusCodes( "all (options)", isSuccess ),
					complete: function( jqXHR ) {
						jqXHR.statusCode( createStatusCodes( "all (on complete)", isSuccess ) );
						setTimeout( function() {
							jqXHR.statusCode( createStatusCodes( "all (very late binding)", isSuccess ) );
							countComplete();
						}, 100 );
					}
				} ).statusCode( createStatusCodes( "all (immediately with method)", isSuccess ) );

				var testString = "";

				jQuery.ajax( url( uri ), {
					success: function( a, b, jqXHR ) {
						assert.ok( isSuccess, "success" );
						var statusCode = {};
						statusCode[ jqXHR.status ] = function() {
							testString += "B";
						};
						jqXHR.statusCode( statusCode );
						testString += "A";
					},
					error: function( jqXHR ) {
						assert.ok( !isSuccess, "error" );
						var statusCode = {};
						statusCode[ jqXHR.status ] = function() {
							testString += "B";
						};
						jqXHR.statusCode( statusCode );
						testString += "A";
					},
					complete: function() {
						assert.strictEqual(
							testString,
							"AB",
							"Test statusCode callbacks are ordered like " + ( isSuccess ? "success" :  "error" ) + " callbacks"
						);
						countComplete();
					}
				} );

			}
			/* jQuery.each arguments end*/
		);
	} );

	ajaxTest( "jQuery.ajax() - transitive conversions", 8, function( assert ) {
		return [
			{
				url: url( "mock.php?action=json" ),
				converters: {
					"json myJson": function( data ) {
						assert.ok( true, "converter called" );
						return data;
					}
				},
				dataType: "myJson",
				success: function() {
					assert.ok( true, "Transitive conversion worked" );
					assert.strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text" );
					assert.strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType" );
				}
			},
			{
				url: url( "mock.php?action=json" ),
				converters: {
					"json myJson": function( data ) {
						assert.ok( true, "converter called (*)" );
						return data;
					}
				},
				contents: false, /* headers are wrong so we ignore them */
				dataType: "* myJson",
				success: function() {
					assert.ok( true, "Transitive conversion worked (*)" );
					assert.strictEqual( this.dataTypes[ 0 ], "text", "response was retrieved as text (*)" );
					assert.strictEqual( this.dataTypes[ 1 ], "myjson", "request expected myjson dataType (*)" );
				}
			}
		];
	} );

	ajaxTest( "jQuery.ajax() - overrideMimeType", 2, function( assert ) {
		return [
			{
				url: url( "mock.php?action=json" ),
				beforeSend: function( xhr ) {
					xhr.overrideMimeType( "application/json" );
				},
				success: function( json ) {
					assert.ok( json.data, "Mimetype overridden using beforeSend" );
				}
			},
			{
				url: url( "mock.php?action=json" ),
				mimeType: "application/json",
				success: function( json ) {
					assert.ok( json.data, "Mimetype overridden using mimeType option" );
				}
			}
		];
	} );

	ajaxTest( "jQuery.ajax() - empty json gets to error callback instead of success callback.", 1, function( assert ) {
		return {
			url: url( "mock.php?action=echoData" ),
			error: function( _, __, error ) {
				assert.equal( typeof error === "object", true,  "Didn't get back error object for empty json response" );
			},
			dataType: "json"
		};
	} );

	ajaxTest( "#2688 - jQuery.ajax() - beforeSend, cancel request", 2, function( assert ) {
		return {
			create: function() {
				return jQuery.ajax( {
					url: url( "name.html" ),
					beforeSend: function() {
						assert.ok( true, "beforeSend got called, canceling" );
						return false;
					},
					success: function() {
						assert.ok( false, "request didn't get canceled" );
					},
					complete: function() {
						assert.ok( false, "request didn't get canceled" );
					},
					error: function() {
						assert.ok( false, "request didn't get canceled" );
					}
				} );
			},
			fail: function( _, reason ) {
				assert.strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
			}
		};
	} );

	ajaxTest( "#2806 - jQuery.ajax() - data option - evaluate function values", 1, function( assert ) {
		return {
			url: baseURL + "mock.php?action=echoQuery",
			data: {
				key: function() {
					return "value";
				}
			},
			success: function( result ) {
				assert.strictEqual( result, "action=echoQuery&key=value" );
			}
		};
	} );

	QUnit.test( "#7531 - jQuery.ajax() - Location object as url", function( assert ) {
		assert.expect( 1 );

		var xhr,
			success = false;
		try {
			xhr = jQuery.ajax( {
				url: window.location
			} );
			success = true;
			xhr.abort();
		} catch ( e ) {

		}
		assert.ok( success, "document.location did not generate exception" );
	} );

	jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
		ajaxTest( "#7578 - jQuery.ajax() - JSONP - default for cache option" + label, 1, function( assert ) {
			return {
				url: baseURL + "mock.php?action=jsonp",
				dataType: "jsonp",
				crossDomain: crossDomain,
				beforeSend: function() {
					assert.strictEqual( this.cache, false, "cache must be false on JSON request" );
					return false;
				},
				error: true
			};
		} );
	} );

	ajaxTest( "#8107 - jQuery.ajax() - multiple method signatures introduced in 1.5", 4, function( assert ) {
		return [
			{
				create: function() {
					return jQuery.ajax();
				},
				done: function() {
					assert.ok( true, "With no arguments" );
				}
			},
			{
				create: function() {
					return jQuery.ajax( baseURL + "name.html" );
				},
				done: function() {
					assert.ok( true, "With only string URL argument" );
				}
			},
			{
				create: function() {
					return jQuery.ajax( baseURL + "name.html", {} );
				},
				done: function() {
					assert.ok( true, "With string URL param and map" );
				}
			},
			{
				create: function( options ) {
					return jQuery.ajax( options );
				},
				url: baseURL + "name.html",
				success: function() {
					assert.ok( true, "With only map" );
				}
			}
		];
	} );

	jQuery.each( [ " - Same Domain", " - Cross Domain" ], function( crossDomain, label ) {
		ajaxTest( "#8205 - jQuery.ajax() - JSONP - re-use callbacks name" + label, 4, function( assert ) {
			return {
				url: baseURL + "mock.php?action=jsonp",
				dataType: "jsonp",
				crossDomain: crossDomain,
				beforeSend: function( jqXHR, s ) {
					s.callback = s.jsonpCallback;

					assert.ok( this.callback in window, "JSONP callback name is in the window" );
				},
				success: function() {
					var previous = this;

					assert.strictEqual(
						previous.jsonpCallback,
						undefined,
						"jsonpCallback option is set back to default in callbacks"
					);

					assert.ok(
						!( this.callback in window ),
						"JSONP callback name was removed from the window"
					);

					jQuery.ajax( {
						url: baseURL + "mock.php?action=jsonp",
						dataType: "jsonp",
						crossDomain: crossDomain,
						beforeSend: function() {
							assert.strictEqual( this.jsonpCallback, previous.callback, "JSONP callback name is re-used" );
							return false;
						}
					} );
				}
			};
		} );
	} );

	QUnit.test( "#9887 - jQuery.ajax() - Context with circular references (#9887)", function( assert ) {
		assert.expect( 2 );

		var success = false,
			context = {};
		context.field = context;
		try {
			jQuery.ajax( "non-existing", {
				context: context,
				beforeSend: function() {
					assert.ok( this === context, "context was not deep extended" );
					return false;
				}
			} );
			success = true;
		} catch ( e ) {
			console.log( e );
		}
		assert.ok( success, "context with circular reference did not generate an exception" );
	} );

	jQuery.each( [ "as argument", "in settings object" ], function( inSetting, title ) {

		function request( assert, url, test ) {
			return {
				create: function() {
					return jQuery.ajax( inSetting ? { url: url } : url );
				},
				done: function() {
					assert.ok( true, ( test || url ) + " " + title );
				}
			};
		}

		ajaxTest( "#10093 - jQuery.ajax() - falsy url " + title, 4, function( assert ) {
			return [
				request( assert, "", "empty string" ),
				request( assert, false ),
				request( assert, null ),
				request( assert, undefined )
			];
		} );
	} );

	ajaxTest( "#11151 - jQuery.ajax() - parse error body", 2, function( assert ) {
		return {
			url: url( "mock.php?action=error&json=1" ),
			dataFilter: function( string ) {
				assert.ok( false, "dataFilter called" );
				return string;
			},
			error: function( jqXHR ) {
				assert.strictEqual( jqXHR.responseText, "{ \"code\": 40, \"message\": \"Bad Request\" }", "Error body properly set" );
				assert.deepEqual( jqXHR.responseJSON, { code: 40, message: "Bad Request" }, "Error body properly parsed" );
			}
		};
	} );

	ajaxTest( "#11426 - jQuery.ajax() - loading binary data shouldn't throw an exception in IE", 1, function( assert ) {
		return {
			url: url( "1x1.jpg" ),
			success: function( data ) {
				assert.ok( data === undefined || /JFIF/.test( data ), "success callback reached" );
			}
		};
	} );

if ( typeof window.ArrayBuffer === "undefined" || typeof new XMLHttpRequest().responseType !== "string" ) {

	QUnit.skip( "No ArrayBuffer support in XHR", jQuery.noop );
} else {

	// No built-in support for binary data, but it's easy to add via a prefilter
	jQuery.ajaxPrefilter( "arraybuffer", function( s ) {
		s.xhrFields = { responseType: "arraybuffer" };
		s.responseFields.arraybuffer = "response";
		s.converters[ "binary arraybuffer" ] = true;
	} );

	ajaxTest( "gh-2498 - jQuery.ajax() - binary data shouldn't throw an exception", 2, function( assert ) {
		return {
			url: url( "1x1.jpg" ),
			dataType: "arraybuffer",
			success: function( data, s, jqxhr ) {
				assert.ok( data instanceof window.ArrayBuffer, "correct data type" );
				assert.ok( jqxhr.response instanceof window.ArrayBuffer, "data in jQXHR" );
			}
		};
	} );
}

	QUnit.test( "#11743 - jQuery.ajax() - script, throws exception", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();
		var onerror = window.onerror;
		window.onerror = function() {
			assert.ok( true, "Exception thrown" );
			window.onerror = onerror;
			done();
		};
		jQuery.ajax( {
			url: baseURL + "badjson.js",
			dataType: "script",
			throws: true
		} );
	} );

	jQuery.each( [ "method", "type" ], function( _, globalOption ) {
		function request( assert, option ) {
			var options = {
					url: url( "mock.php?action=echoData" ),
					data: "hello",
					success: function( msg ) {
						assert.strictEqual( msg, "hello", "Check for POST (no override)" );
					}
				};
			if ( option ) {
				options[ option ] = "GET";
				options.success = function( msg ) {
					assert.strictEqual( msg, "", "Check for no POST (overriding with " + option + ")" );
				};
			}
			return options;
		}

		ajaxTest(
			"#12004 - jQuery.ajax() - method is an alias of type - " +
			globalOption + " set globally", 3,
			function( assert ) {
				return {
					setup: function() {
						var options = {};
						options[ globalOption ] = "POST";
						jQuery.ajaxSetup( options );
					},
					requests: [
						request( assert, "type" ),
						request( assert, "method" ),
						request( assert )
					]
				};
			}
		);
	} );

	ajaxTest( "#13276 - jQuery.ajax() - compatibility between XML documents from ajax requests and parsed string", 1, function( assert ) {
		return {
			url: baseURL + "dashboard.xml",
			dataType: "xml",
			success: function( ajaxXML ) {
				var parsedXML = jQuery( jQuery.parseXML( "<tab title=\"Added\">blibli</tab>" ) ).find( "tab" );
				ajaxXML = jQuery( ajaxXML );
				try {
					ajaxXML.find( "infowindowtab" ).append( parsedXML );
				} catch ( e ) {
					assert.strictEqual( e, undefined, "error" );
					return;
				}
				assert.strictEqual( ajaxXML.find( "tab" ).length, 3, "Parsed node was added properly" );
			}
		};
	} );

	ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, function( assert ) {
		return {
			url: baseURL + "mock.php?action=status&code=204&text=No+Content",
			dataType: "testing",
			converters: {
				"* testing": function() {
					throw "converter was called";
				}
			},
			success: function( data, status, jqXHR ) {
				assert.strictEqual( jqXHR.status, 204, "status code is 204" );
				assert.strictEqual( status, "nocontent", "status text is 'nocontent'" );
				assert.strictEqual( data, undefined, "data is undefined" );
			},
			error: function( _, status, error ) {
				assert.ok( false, "error" );
				assert.strictEqual( status, "parsererror", "Parser Error" );
				assert.strictEqual( error, "converter was called", "Converter was called" );
			}
		};
	} );

	ajaxTest( "#13388 - jQuery.ajax() - responseXML", 3, function( assert ) {
		return {
			url: url( "with_fries.xml" ),
			dataType: "xml",
			success: function( resp, _, jqXHR ) {
				assert.notStrictEqual( resp, undefined, "XML document exists" );
				assert.ok( "responseXML" in jqXHR, "jqXHR.responseXML exists" );
				assert.strictEqual( resp, jqXHR.responseXML, "jqXHR.responseXML is set correctly" );
			}
		};
	} );

	ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, function( assert ) {
		return {
			url: baseURL + "mock.php?action=json",
			method: "HEAD",
			data: {
				header: "yes"
			},
			converters: {
				"text json": function() {
					throw "converter was called";
				}
			},
			success: function( data, status ) {
				assert.ok( true, "success" );
				assert.strictEqual( status, "nocontent", "data is undefined" );
				assert.strictEqual( data, undefined, "data is undefined" );
			},
			error: function( _, status, error ) {
				assert.ok( false, "error" );
				assert.strictEqual( status, "parsererror", "Parser Error" );
				assert.strictEqual( error, "converter was called", "Converter was called" );
			}
		};
	} );

	testIframe(
		"#14379 - jQuery.ajax() on unload",
		"ajax/onunload.html",
		function( assert, jQuery, window, document, status ) {
			assert.expect( 1 );
			assert.strictEqual( status, "success", "Request completed" );
		}
	);

	ajaxTest( "#14683 - jQuery.ajax() - Exceptions thrown synchronously by xhr.send should be caught", 4, function( assert ) {
		return [ {
			url: baseURL + "mock.php?action=echoData",
			method: "POST",
			data: {
				toString: function() {
					throw "Can't parse";
				}
			},
			processData: false,
			done: function( data ) {
				assert.ok( false, "done: " + data );
			},
			fail: function( jqXHR, status, error ) {
				assert.ok( true, "exception caught: " + error );
				assert.strictEqual( jqXHR.status, 0, "proper status code" );
				assert.strictEqual( status, "error", "proper status" );
			}
		}, {
			url: "https://" + externalHost + ":80q",
			done: function( data ) {
				assert.ok( false, "done: " + data );
			},
			fail: function( _, status, error ) {
				assert.ok( true, "fail: " + status + " - " + error );
			}
		} ];
	} );

	ajaxTest( "gh-2587 - when content-type not xml, but looks like one", 1, function( assert ) {
		return {
			url: url( "mock.php?action=contentType" ),
			data: {
				contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
				"response": "<test/>"
			},
			success: function( result ) {
				assert.strictEqual(
					typeof result,
					"string",
					"Should handle it as a string, not xml"
				);
			}
		};
	} );

	ajaxTest( "gh-2587 - when content-type not xml, but looks like one", 1, function( assert ) {
		return {
			url: url( "mock.php?action=contentType" ),
			data: {
				contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
				"response": "<test/>"
			},
			success: function( result ) {
				assert.strictEqual(
					typeof result,
					"string",
					"Should handle it as a string, not xml"
				);
			}
		};
	} );

	ajaxTest( "gh-2587 - when content-type not json, but looks like one", 1, function( assert ) {
		return {
			url: url( "mock.php?action=contentType" ),
			data: {
				contentType: "test/jsontest",
				"response": JSON.stringify( { test: "test" } )
			},
			success: function( result ) {
				assert.strictEqual(
					typeof result,
					"string",
					"Should handle it as a string, not json"
				);
			}
		};
	} );

	ajaxTest( "gh-2587 - when content-type not html, but looks like one", 1, function( assert ) {
		return {
			url: url( "mock.php?action=contentType" ),
			data: {
				contentType: "test/htmltest",
				"response": "<p>test</p>"
			},
			success: function( result ) {
				assert.strictEqual(
					typeof result,
					"string",
					"Should handle it as a string, not html"
				);
			}
		};
	} );

	ajaxTest( "gh-2587 - when content-type not javascript, but looks like one", 1, function( assert ) {
		return {
			url: url( "mock.php?action=contentType" ),
			data: {
				contentType: "test/testjavascript",
				"response": "alert(1)"
			},
			success: function( result ) {
				assert.strictEqual(
					typeof result,
					"string",
					"Should handle it as a string, not javascript"
				);
			}
		};
	} );

	ajaxTest( "gh-2587 - when content-type not ecmascript, but looks like one", 1, function( assert ) {
		return {
			url: url( "mock.php?action=contentType" ),
			data: {
				contentType: "test/testjavascript",
				"response": "alert(1)"
			},
			success: function( result ) {
				assert.strictEqual(
					typeof result,
					"string",
					"Should handle it as a string, not ecmascript"
				);
			}
		};
	} );

//----------- jQuery.ajaxPrefilter()

	ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, function( assert ) {
		return {
			dataType: "prefix",
			setup: function() {

				// Ensure prefix does not throw an error
				jQuery.ajaxPrefilter( "+prefix", function( options, _, jqXHR ) {
					if ( options.abortInPrefilter ) {
						jqXHR.abort();
					}
				} );
			},
			abortInPrefilter: true,
			error: function() {
				assert.ok( false, "error callback called" );
			},
			fail: function( _, reason ) {
				assert.strictEqual( reason, "canceled", "Request aborted by the prefilter must fail with 'canceled' status text" );
			}
		};
	} );

//----------- jQuery.ajaxSetup()

	QUnit.test( "jQuery.ajaxSetup()", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();
		jQuery.ajaxSetup( {
			url: url( "mock.php?action=name&name=foo" ),
			success: function( msg ) {
				assert.strictEqual( msg, "bar", "Check for GET" );
				done();
			}
		} );
		jQuery.ajax();
	} );

	QUnit.test( "jQuery.ajaxSetup({ timeout: Number }) - with global timeout", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		var passed = 0,
			pass = function() {
				assert.ok( passed++ < 2, "Error callback executed" );
				if ( passed === 2 ) {
					jQuery( document ).off( "ajaxError.setupTest" );
					done();
				}
			},
			fail = function( a, b ) {
				assert.ok( false, "Check for timeout failed " + a + " " + b );
				done();
			};

		jQuery( document ).on( "ajaxError.setupTest", pass );

		jQuery.ajaxSetup( {
			timeout: 1000
		} );

		jQuery.ajax( {
			type: "GET",
			url: url( "mock.php?action=wait&wait=5" ),
			error: pass,
			success: fail
		} );
	} );

	QUnit.test( "jQuery.ajaxSetup({ timeout: Number }) with localtimeout", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();
		jQuery.ajaxSetup( {
			timeout: 50
		} );
		jQuery.ajax( {
			type: "GET",
			timeout: 15000,
			url: url( "mock.php?action=wait&wait=1" ),
			error: function() {
				assert.ok( false, "Check for local timeout failed" );
				done();
			},
			success: function() {
				assert.ok( true, "Check for local timeout" );
				done();
			}
		} );
	} );

//----------- jQuery.domManip()

	QUnit.test( "#11264 - jQuery.domManip() - no side effect because of ajaxSetup or global events", function( assert ) {
		assert.expect( 1 );

		jQuery.ajaxSetup( {
			type: "POST"
		} );

		jQuery( document ).on( "ajaxStart ajaxStop", function() {
			assert.ok( false, "Global event triggered" );
		} );

		jQuery( "#qunit-fixture" ).append( "<script src='" + baseURL + "mock.php?action=script'></script>" );

		jQuery( document ).off( "ajaxStart ajaxStop" );
	} );

	QUnit.test(
		"jQuery#load() - always use GET method even if it overrided through ajaxSetup (#11264)",
		function( assert ) {
			assert.expect( 1 );
			var done = assert.async();

			jQuery.ajaxSetup( {
				type: "POST"
			} );

			jQuery( "#qunit-fixture" ).load( baseURL + "mock.php?action=echoMethod", function( method ) {
				assert.equal( method, "GET" );
				done();
			} );
		}
	);

	QUnit.test(
		"jQuery#load() - should resolve with correct context",
		function( assert ) {
			assert.expect( 2 );
			var done = assert.async();
			var ps = jQuery( "<p></p><p></p>" );
			var i = 0;

			ps.appendTo( "#qunit-fixture" );

			ps.load( baseURL + "mock.php?action=echoMethod", function() {
				assert.strictEqual( this, ps[ i++ ] );

				if ( i === 2 ) {
					done();
				}
			} );
		}
	);

	QUnit.test(
		"#11402 - jQuery.domManip() - script in comments are properly evaluated",
		function( assert ) {
			assert.expect( 2 );
			jQuery( "#qunit-fixture" ).load( baseURL + "cleanScript.html", assert.async() );
		}
	);

//----------- jQuery.get()

	QUnit.test( "jQuery.get( String, Hash, Function ) - parse xml and use text() on nodes", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		jQuery.get( url( "dashboard.xml" ), function( xml ) {
			var content = [];
			jQuery( "tab", xml ).each( function() {
				content.push( jQuery( this ).text() );
			} );
			assert.strictEqual( content[ 0 ], "blabla", "Check first tab" );
			assert.strictEqual( content[ 1 ], "blublu", "Check second tab" );
			done();
		} );
	} );

	QUnit.test( "#8277 - jQuery.get( String, Function ) - data in ajaxSettings", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();
		jQuery.ajaxSetup( {
			data: "helloworld"
		} );
		jQuery.get( url( "mock.php?action=echoQuery" ), function( data ) {
			assert.ok( /helloworld$/.test( data ), "Data from ajaxSettings was used" );
			done();
		} );
	} );

//----------- jQuery.getJSON()

	QUnit.test( "jQuery.getJSON( String, Hash, Function ) - JSON array", function( assert ) {
		assert.expect( 5 );
		var done = assert.async();
		jQuery.getJSON(
			url( "mock.php?action=json" ),
			{
				"array": "1"
			},
			function( json ) {
				assert.ok( json.length >= 2, "Check length" );
				assert.strictEqual( json[ 0 ][ "name" ], "John", "Check JSON: first, name" );
				assert.strictEqual( json[ 0 ][ "age" ], 21, "Check JSON: first, age" );
				assert.strictEqual( json[ 1 ][ "name" ], "Peter", "Check JSON: second, name" );
				assert.strictEqual( json[ 1 ][ "age" ], 25, "Check JSON: second, age" );
				done();
			}
		);
	} );

	QUnit.test( "jQuery.getJSON( String, Function ) - JSON object", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		jQuery.getJSON( url( "mock.php?action=json" ), function( json ) {
			if ( json && json[ "data" ] ) {
				assert.strictEqual( json[ "data" ][ "lang" ], "en", "Check JSON: lang" );
				assert.strictEqual( json[ "data" ].length, 25, "Check JSON: length" );
				done();
			}
		} );
	} );

	QUnit.test( "jQuery.getJSON( String, Function ) - JSON object with absolute url to local content", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		var absoluteUrl = url( "mock.php?action=json" );

		// Make a relative URL absolute relative to the document location
		if ( !/^[a-z][a-z0-9+.-]*:/i.test( absoluteUrl ) ) {

			// An absolute path replaces everything after the host
			if ( absoluteUrl.charAt( 0 ) === "/" ) {
				absoluteUrl = window.location.href.replace( /(:\/*[^/]*).*$/, "$1" ) + absoluteUrl;

			// A relative path replaces the last slash-separated path segment
			} else {
				absoluteUrl = window.location.href.replace( /[^/]*$/, "" ) + absoluteUrl;
			}
		}

		jQuery.getJSON( absoluteUrl, function( json ) {
			assert.strictEqual( json.data.lang, "en", "Check JSON: lang" );
			assert.strictEqual( json.data.length, 25, "Check JSON: length" );
			done();
		} );
	} );

//----------- jQuery.getScript()

	QUnit.test( "jQuery.getScript( String, Function ) - with callback",
		function( assert ) {
			assert.expect( 2 );
			var done = assert.async();

			Globals.register( "testBar" );
			jQuery.getScript( url( "mock.php?action=testbar" ), function() {
				assert.strictEqual( window[ "testBar" ], "bar", "Check if script was evaluated" );
				done();
			} );
		}
	);

	QUnit.test( "jQuery.getScript( String, Function ) - no callback", function( assert ) {
		assert.expect( 1 );
		Globals.register( "testBar" );
		jQuery.getScript( url( "mock.php?action=testbar" ) ).done( assert.async() );
	} );

	QUnit.test( "#8082 - jQuery.getScript( String, Function ) - source as responseText", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();

		Globals.register( "testBar" );
		jQuery.getScript( url( "mock.php?action=testbar" ), function( data, _, jqXHR ) {
			assert.strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script" );
			done();
		} );
	} );

	QUnit.test( "jQuery.getScript( Object ) - with callback", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();

		Globals.register( "testBar" );
		jQuery.getScript( {
			url: url( "mock.php?action=testbar" ),
			success: function() {
				assert.strictEqual( window[ "testBar" ], "bar", "Check if script was evaluated" );
				done();
			}
		} );
	} );

	QUnit.test( "jQuery.getScript( Object ) - no callback", function( assert ) {
		assert.expect( 1 );
		Globals.register( "testBar" );
		jQuery.getScript( { url: url( "mock.php?action=testbar" ) } ).done( assert.async() );
	} );

// //----------- jQuery.fn.load()

	// check if load can be called with only url
	QUnit.test( "jQuery.fn.load( String )", function( assert ) {
		assert.expect( 2 );
		jQuery.ajaxSetup( {
			beforeSend: function() {
				assert.strictEqual( this.type, "GET", "no data means GET request" );
			}
		} );
		jQuery( "#first" ).load( baseURL + "name.html", assert.async() );
	} );

	QUnit.test( "jQuery.fn.load() - 404 error callbacks", function( assert ) {
		assert.expect( 6 );
		var done = assert.async();

		addGlobalEvents( "ajaxStart ajaxStop ajaxSend ajaxComplete ajaxError", assert )();
		jQuery( document ).ajaxStop( done );
		jQuery( "<div/>" ).load( baseURL + "404.txt", function() {
			assert.ok( true, "complete" );
		} );
	} );

	// check if load can be called with url and null data
	QUnit.test( "jQuery.fn.load( String, null )", function( assert ) {
		assert.expect( 2 );
		jQuery.ajaxSetup( {
			beforeSend: function() {
				assert.strictEqual( this.type, "GET", "no data means GET request" );
			}
		} );
		jQuery( "#first" ).load( baseURL + "name.html", null, assert.async() );
	} );

	// check if load can be called with url and undefined data
	QUnit.test( "jQuery.fn.load( String, undefined )", function( assert ) {
		assert.expect( 2 );
		jQuery.ajaxSetup( {
			beforeSend: function() {
				assert.strictEqual( this.type, "GET", "no data means GET request" );
			}
		} );
		jQuery( "#first" ).load( baseURL + "name.html", undefined, assert.async() );
	} );

	// check if load can be called with only url
	QUnit.test( "jQuery.fn.load( URL_SELECTOR )", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();
		jQuery( "#first" ).load( baseURL + "test3.html div.user", function() {
			assert.strictEqual( jQuery( this ).children( "div" ).length, 2, "Verify that specific elements were injected" );
			done();
		} );
	} );

	// Selector should be trimmed to avoid leading spaces (#14773)
	QUnit.test( "jQuery.fn.load( URL_SELECTOR with spaces )", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();
		jQuery( "#first" ).load( baseURL + "test3.html   #superuser ", function() {
			assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" );
			done();
		} );
	} );

	// Selector should be trimmed to avoid leading spaces (#14773)
	// Selector should include any valid non-HTML whitespace (#3003)
	QUnit.test( "jQuery.fn.load( URL_SELECTOR with non-HTML whitespace(#3003) )", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();
		jQuery( "#first" ).load( baseURL + "test3.html   #whitespace\\\\xA0 ", function() {
			assert.strictEqual( jQuery( this ).children( "div" ).length, 1, "Verify that specific elements were injected" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, Function ) - simple: inject text into DOM", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		jQuery( "#first" ).load( url( "name.html" ), function() {
			assert.ok( /^ERROR/.test( jQuery( "#first" ).text() ), "Check if content was injected into the DOM" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, Function ) - check scripts", function( assert ) {
		assert.expect( 7 );
		var done = assert.async();
		var verifyEvaluation = function() {
			assert.strictEqual( window[ "testBar" ], "bar", "Check if script src was evaluated after load" );
			assert.strictEqual( jQuery( "#ap" ).html(), "bar", "Check if script evaluation has modified DOM" );
			done();
		};

		Globals.register( "testFoo" );
		Globals.register( "testBar" );

		jQuery( "#first" ).load( url( "mock.php?action=testHTML&baseURL=" + baseURL ), function() {
			assert.ok( jQuery( "#first" ).html().match( /^html text/ ), "Check content after loading html" );
			assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
			assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" );
			setTimeout( verifyEvaluation, 600 );
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, Function ) - check file with only a script tag", function( assert ) {
		assert.expect( 3 );
		var done = assert.async();
		Globals.register( "testFoo" );

		jQuery( "#first" ).load( url( "test2.html" ), function() {
			assert.strictEqual( jQuery( "#foo" ).html(), "foo", "Check if script evaluation has modified DOM" );
			assert.strictEqual( window[ "testFoo" ], "foo", "Check if script was evaluated after load" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, Function ) - dataFilter in ajaxSettings", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		jQuery.ajaxSetup( {
			dataFilter: function() {
				return "Hello World";
			}
		} );
		jQuery( "<div/>" ).load( url( "name.html" ), function( responseText ) {
			assert.strictEqual( jQuery( this ).html(), "Hello World", "Test div was filled with filtered data" );
			assert.strictEqual( responseText, "Hello World", "Test callback receives filtered data" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, Object, Function )", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();
		jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), {
			"bar": "ok"
		}, function() {
			var $node = jQuery( this );
			assert.strictEqual( $node.find( "#method" ).text(), "POST", "Check method" );
			assert.strictEqual( $node.find( "#data" ).text(), "bar=ok", "Check if data is passed correctly" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load( String, String, Function )", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();

		jQuery( "<div />" ).load( url( "mock.php?action=echoHtml" ), "foo=3&bar=ok", function() {
			var $node = jQuery( this );
			assert.strictEqual( $node.find( "#method" ).text(), "GET", "Check method" );
			assert.ok( $node.find( "#query" ).text().match( /foo=3&bar=ok/ ), "Check if a string of data is passed correctly" );
			done();
		} );
	} );

	QUnit.test( "jQuery.fn.load() - callbacks get the correct parameters", function( assert ) {
		assert.expect( 8 );
		var completeArgs = {},
			done = assert.async();

		jQuery.ajaxSetup( {
			success: function( _, status, jqXHR ) {
				completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
			},
			error: function( jqXHR, status ) {
				completeArgs[ this.url ] = [ jqXHR.responseText, status, jqXHR ];
			}
		} );

		jQuery.when.apply(
			jQuery,
			jQuery.map( [
				{
					type: "success",
					url: baseURL + "mock.php?action=echoQuery&arg=pop"
				},
				{
					type: "error",
					url: baseURL + "404.txt"
				}
			],
			function( options ) {
				return jQuery.Deferred( function( defer ) {
					jQuery( "#foo" ).load( options.url, function() {
						var args = arguments;
						assert.strictEqual( completeArgs[ options.url ].length, args.length, "same number of arguments (" + options.type + ")" );
						jQuery.each( completeArgs[ options.url ], function( i, value ) {
							assert.strictEqual( args[ i ], value, "argument #" + i + " is the same (" + options.type + ")" );
						} );
						defer.resolve();
					} );
				} );
			} )
		).always( done );
	} );

	QUnit.test( "#2046 - jQuery.fn.load( String, Function ) with ajaxSetup on dataType json", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();

		jQuery.ajaxSetup( {
			dataType: "json"
		} );
		jQuery( document ).ajaxComplete( function( e, xml, s ) {
			assert.strictEqual( s.dataType, "html", "Verify the load() dataType was html" );
			jQuery( document ).off( "ajaxComplete" );
			done();
		} );
		jQuery( "#first" ).load( baseURL + "test3.html" );
	} );

	QUnit.test( "#10524 - jQuery.fn.load() - data specified in ajaxSettings is merged in", function( assert ) {
		assert.expect( 1 );
		var done = assert.async();

		var data = {
			"baz": 1
		};
		jQuery.ajaxSetup( {
			data: {
				"foo": "bar"
			}
		} );
		jQuery( "#foo" ).load( baseURL + "mock.php?action=echoQuery", data );
		jQuery( document ).ajaxComplete( function( event, jqXHR, options ) {
			assert.ok( ~options.data.indexOf( "foo=bar" ), "Data from ajaxSettings was used" );
			done();
		} );
	} );

// //----------- jQuery.post()

	QUnit.test( "jQuery.post() - data", function( assert ) {
		assert.expect( 3 );
		var done = assert.async();

		jQuery.when(
			jQuery.post(
				url( "mock.php?action=xml" ),
				{
					cal: "5-2"
				},
				function( xml ) {
					jQuery( "math", xml ).each( function() {
						assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
						assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
					} );
				}
			),
			jQuery.ajax( {
				url: url( "mock.php?action=echoData" ),
				type: "POST",
				data: {
					"test": {
						"length": 7,
						"foo": "bar"
					}
				},
				success: function( data ) {
					assert.strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly" );
				}
			} )
		).always( done );
	} );

	QUnit.test( "jQuery.post( String, Hash, Function ) - simple with xml", function( assert ) {
		assert.expect( 4 );
		var done = assert.async();

		jQuery.when(
			jQuery.post(
				url( "mock.php?action=xml" ),
				{
					cal: "5-2"
				},
				function( xml ) {
					jQuery( "math", xml ).each( function() {
						assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
						assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
					} );
				}
			),
			jQuery.post( url( "mock.php?action=xml&cal=5-2" ), {}, function( xml ) {
				jQuery( "math", xml ).each( function() {
					assert.strictEqual( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
					assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
				} );
			} )
		).always( function() {
			done();
		} );
	} );

	QUnit.test( "jQuery[get|post]( options ) - simple with xml", function( assert ) {
		assert.expect( 2 );
		var done = assert.async();

		jQuery.when.apply( jQuery,
			jQuery.map( [ "get", "post" ], function( method ) {
				return jQuery[ method ]( {
					url: url( "mock.php?action=xml" ),
					data: {
						cal: "5-2"
					},
					success: function( xml ) {
						jQuery( "math", xml ).each( function() {
							assert.strictEqual( jQuery( "result", this ).text(), "3", "Check for XML" );
						} );
					}
				} );
			} )
		).always( function() {
			done();
		} );
	} );

//----------- jQuery.active

	QUnit.test( "jQuery.active", function( assert ) {
		assert.expect( 1 );
		assert.ok( jQuery.active === 0, "ajax active counter should be zero: " + jQuery.active );
	} );

} )();