dom/tests/mochitest/ajax/jquery/test/unit/ajax.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 module("ajax");
     3 // Safari 3 randomly crashes when running these tests,
     4 // but only in the full suite - you can run just the Ajax
     5 // tests and they'll pass
     6 //if ( !jQuery.browser.safari ) {
     8 if ( !isLocal ) {
    10 test("$.ajax() - success callbacks", function() {
    11 	expect( 8 );
    13 	$.ajaxSetup({ timeout: 0 });
    15 	stop();
    17 	setTimeout(function(){	
    18         $('#foo').ajaxStart(function(){
    19             ok( true, "ajaxStart" );
    20         }).ajaxStop(function(){
    21             ok( true, "ajaxStop" );
    22             start();
    23         }).ajaxSend(function(){
    24             ok( true, "ajaxSend" );
    25         }).ajaxComplete(function(){
    26             ok( true, "ajaxComplete" );
    27         }).ajaxError(function(){
    28             ok( false, "ajaxError" );
    29         }).ajaxSuccess(function(){
    30             ok( true, "ajaxSuccess" );
    31         });
    33         $.ajax({
    34             url: url("data/name.html"),
    35             beforeSend: function(){ ok(true, "beforeSend"); },
    36             success: function(){ ok(true, "success"); },
    37             error: function(){ ok(false, "error"); },
    38             complete: function(){ ok(true, "complete"); }
    39         });
    40     }, 13);
    41 });
    43 /* mozilla: the ajaxSuccess part fails intermittently on MacOSX
    45 test("$.ajax() - error callbacks", function() {
    46     expect( 7 );
    47     stop();
    49     $('#foo').ajaxStart(function(){
    50         ok( true, "ajaxStart" );
    51     }).ajaxStop(function(){
    52         ok( true, "ajaxStop" );
    53         start();
    54     }).ajaxSend(function(){
    55         ok( true, "ajaxSend" );
    56     }).ajaxComplete(function(){
    57         ok( true, "ajaxComplete" );
    58     }).ajaxError(function(){
    59         ok( true, "ajaxError" );
    60     }).ajaxSuccess(function(){
    61         ok( false, "ajaxSuccess" );
    62     })
    63 	;
    65     $.ajaxSetup({ timeout: 500 });
    67     $.ajax({
    68         url: url("data/name.php?wait=5"),
    69         beforeSend: function(){ ok(true, "beforeSend"); },
    70         success: function(){ ok(false, "success"); },
    71         error: function(){ ok(true, "error"); },
    72         complete: function(){ ok(true, "complete"); }
    73     });
    74 });
    76 */
    78 test("$.ajax() - disabled globals", function() {
    79 	expect( 3 );
    80 	stop();
    82 	$('#foo').ajaxStart(function(){
    83 		ok( false, "ajaxStart" );
    84 	}).ajaxStop(function(){
    85 		ok( false, "ajaxStop" );
    86 	}).ajaxSend(function(){
    87 		ok( false, "ajaxSend" );
    88 	}).ajaxComplete(function(){
    89 		ok( false, "ajaxComplete" );
    90 	}).ajaxError(function(){
    91 		ok( false, "ajaxError" );
    92 	}).ajaxSuccess(function(){
    93 		ok( false, "ajaxSuccess" );
    94 	});
    96 	$.ajax({
    97 		global: false,
    98 		url: url("data/name.html"),
    99 		beforeSend: function(){ ok(true, "beforeSend"); },
   100 		success: function(){ ok(true, "success"); },
   101 		error: function(){ ok(false, "error"); },
   102 		complete: function(){
   103 		  ok(true, "complete");
   104 		  setTimeout(function(){ start(); }, 13);
   105         }
   106 	});
   107 });
   109 test("$.ajax - xml: non-namespace elements inside namespaced elements", function() {
   110 	expect(3);
   111 	stop();
   112 	$.ajax({
   113 	  url: url("data/with_fries.xml"),
   114 	  dataType: "xml",
   115 	  success: function(resp) {
   116 	    equals( $("properties", resp).length, 1, 'properties in responseXML' );
   117 	    equals( $("jsconf", resp).length, 1, 'jsconf in responseXML' );
   118 	    equals( $("thing", resp).length, 2, 'things in responseXML' );
   119 	    start();
   120 	  }
   121 	});
   122 });
   124 test("$.ajax - beforeSend", function() {
   125 	expect(1);
   126 	stop();
   128 	var check = false;
   130 	$.ajaxSetup({ timeout: 0 });
   132 	$.ajax({
   133 		url: url("data/name.html"), 
   134 		beforeSend: function(xml) {
   135 			check = true;
   136 		},
   137 		success: function(data) {
   138 			ok( check, "check beforeSend was executed" );
   139 			start();
   140 		}
   141 	});
   142 });
   144 test("$.ajax - beforeSend, cancel request (#2688)", function() {
   145 	expect(2);
   146 	var request = $.ajax({
   147 		url: url("data/name.html"), 
   148 		beforeSend: function() {
   149 			ok( true, "beforeSend got called, canceling" );
   150 			return false;
   151 		},
   152 		success: function() {
   153 			ok( false, "request didn't get canceled" );
   154 		},
   155 		complete: function() {
   156 			ok( false, "request didn't get canceled" );
   157 		},
   158 		error: function() {
   159 			ok( false, "request didn't get canceled" );
   160 		}
   161 	});
   162 	ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
   163 });
   165 var foobar;
   167 test("$.ajax - dataType html", function() {
   168 	expect(5);
   169 	stop();
   171 	foobar = null;
   172 	testFoo = undefined;
   174 	var verifyEvaluation = function() {
   175 	  equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
   176 	  equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
   177 	  start();
   178 	};
   180 	$.ajax({
   181 	  dataType: "html",
   182 	  url: url("data/test.html"),
   183 	  success: function(data) {
   184 	  	$("#ap").html(data);
   185 	    ok( data.match(/^html text/), 'Check content for datatype html' );
   186 	    setTimeout(verifyEvaluation, 600);
   187 	  }
   188 	});
   189 });
   191 test("serialize()", function() {
   192 	expect(6);
   194 	equals( $('#form').serialize(),
   195 		"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
   196 		'Check form serialization as query string');
   198 	equals( $('#form :input').serialize(),
   199 		"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2",
   200 		'Check input serialization as query string');
   202 	equals( $('#testForm').serialize(), 
   203 		'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 
   204 		'Check form serialization as query string');
   206 	equals( $('#testForm :input').serialize(), 
   207 		'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', 
   208 		'Check input serialization as query string');
   210 	equals( $('#form, #testForm').serialize(),
   211 		"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
   212 		'Multiple form serialization as query string');
   214 	equals( $('#form, #testForm :input').serialize(),
   215 		"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
   216 		'Mixed form/input serialization as query string');
   217 });
   219 test("$.param()", function() {
   220 	expect(4);
   221 	var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
   222 	equals( $.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
   224 	params = {someName: [1, 2, 3], regularThing: "blah" };
   225 	equals( $.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
   227 	params = {"foo[]":["baz", 42, "All your base are belong to us"]};
   228 	equals( $.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
   230 	params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
   231 	equals( $.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
   232 });
   234 test("synchronous request", function() {
   235 	expect(1);
   236 	ok( /^{ "data"/.test( $.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" );
   237 });
   239 test("synchronous request with callbacks", function() {
   240 	expect(2);
   241 	var result;
   242 	$.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "success callback executed"); result = data; } });
   243 	ok( /^{ "data"/.test( result ), "check returned text" );
   244 });
   246 test("pass-through request object", function() {
   247 	expect(8);
   248 	stop(true);
   250 	var target = "data/name.html";
   251 	var successCount = 0;
   252 	var errorCount = 0;
   253   var errorEx = "";
   254 	var success = function() {
   255 		successCount++;
   256 	};
   257 	$("#foo").ajaxError(function (e, xml, s, ex) {
   258 		errorCount++;
   259     errorEx += ": " + xml.status;
   260 	});
   261 	$("#foo").one('ajaxStop', function () {
   262 		equals(successCount, 5, "Check all ajax calls successful");
   263 		equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
   264 		$("#foo").unbind('ajaxError');
   265 		start();
   266 	});
   268 	ok( $.get(url(target), success), "get" );
   269 	ok( $.post(url(target), success), "post" );
   270 	ok( $.getScript(url("data/test.js"), success), "script" );
   271 	ok( $.getJSON(url("data/json_obj.js"), success), "json" );
   272 	ok( $.ajax({url: url(target), success: success}), "generic" );
   273 });
   275 /* mozilla: php not currently supported in mochitest (08/08/2008)
   276 test("ajax cache", function () {
   277 	expect(18);
   278 	stop();
   280 	var count = 0;
   282 	$("#firstp").bind("ajaxSuccess", function (e, xml, s) {
   283 		var re = /_=(.*?)(&|$)/g;
   284     var oldOne = null;
   285 		for (var i = 0; i < 6; i++) {
   286       var ret = re.exec(s.url);
   287 			if (!ret) {
   288 				break;
   289 			}
   290       oldOne = ret[1];
   291 		}
   292 		equals(i, 1, "Test to make sure only one 'no-cache' parameter is there");
   293 		ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced");
   294 		if(++count == 6)
   295 			start();
   296 	});
   298 	ok( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" );
   299 	ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" );
   300 	ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" );
   301 	ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" );
   302 	ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" );
   303 	ok( $.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" );
   304 }); 
   305 */
   307 test("global ajaxSettings", function() {
   308 	expect(2);
   310 	var tmp = jQuery.extend({}, jQuery.ajaxSettings);
   311     var orig = { url: "data/with_fries.xml" };
   312 	var t;
   314 	$.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
   316     t = jQuery.extend({}, orig);
   317 	t.data = {};
   318     $.ajax(t);
   319 	ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
   321     t = jQuery.extend({}, orig);
   322 	t.data = { zoo: 'a', ping: 'b' };
   323     $.ajax(t);
   324 	ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" );
   326 	jQuery.ajaxSettings = tmp;
   327 });
   329 test("load(String)", function() {
   330 	expect(1);
   331 	stop(true); // check if load can be called with only url
   332 	$('#first').load("data/name.html", start);
   333 });
   335 test("load('url selector')", function() {
   336 	expect(1);
   337 	stop(true); // check if load can be called with only url
   338 	$('#first').load("data/test3.html div.user", function(){
   339 		equals( $(this).children("div").length, 2, "Verify that specific elements were injected" );
   340 		start();
   341 	});
   342 });
   344 test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() {
   345 	expect(1);
   346 	stop();
   347 	$.ajaxSetup({ dataType: "json" });
   348 	$("#first").ajaxComplete(function (e, xml, s) {
   349 		equals( s.dataType, "html", "Verify the load() dataType was html" );
   350 		$("#first").unbind("ajaxComplete");
   351 		$.ajaxSetup({ dataType: "" });
   352 		start();
   353 	});
   354 	$('#first').load("data/test3.html");
   355 });
   357 test("load(String, Function) - simple: inject text into DOM", function() {
   358 	expect(2);
   359 	stop();
   360 	$('#first').load(url("data/name.html"), function() {
   361 		ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' );
   362 		start();
   363 	});
   364 });
   366 test("load(String, Function) - check scripts", function() {
   367 	expect(7);
   368 	stop();
   369 	window.testFoo = undefined;
   370 	window.foobar = null;
   371 	var verifyEvaluation = function() {
   372 		equals( foobar, "bar", 'Check if script src was evaluated after load' );
   373 		equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
   374 		 start();
   375 	};
   376 	$('#first').load(url('data/test.html'), function() {
   377 		ok( $('#first').html().match(/^html text/), 'Check content after loading html' );
   378 		equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
   379 		equals( testFoo, "foo", 'Check if script was evaluated after load' );
   380 		setTimeout(verifyEvaluation, 600);
   381 	});
   382 });
   384 test("load(String, Function) - check file with only a script tag", function() {
   385 	expect(3);
   386 	stop();
   387 	testFoo = undefined;
   388 	$('#first').load(url('data/test2.html'), function() {
   389 		equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
   390 		equals( testFoo, "foo", 'Check if script was evaluated after load' );
   391 		start();
   392 	});
   393 });
   395 test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
   396 	expect(2);
   397 	stop();
   398 	$.get(url('data/dashboard.xml'), function(xml) {
   399 		var content = [];
   400 		$('tab', xml).each(function() {
   401 			content.push($(this).text());
   402 		});
   403 		equals( content[0], 'blabla', 'Check first tab');
   404 		equals( content[1], 'blublu', 'Check second tab');
   405 		start();
   406 	});
   407 });
   409 test("$.getScript(String, Function) - with callback", function() {
   410 	expect(2);
   411 	stop();
   412 	window.foobar = null;
   413 	$.getScript(url("data/test.js"), function() {
   414 		equals( foobar, "bar", 'Check if script was evaluated' );
   415 		setTimeout(start, 100);
   416 	});
   417 });
   419 test("$.getScript(String, Function) - no callback", function() {
   420 	expect(1);
   421 	stop(true);
   422 	$.getScript(url("data/test.js"), start);
   423 });
   425 /* mozilla: Tests using php scripts not currently supported (06/26/2008)
   427 test("$.ajax() - JSONP, Local", function() {
   428 	expect(7);
   430 	var count = 0;
   431 	function plus(){ if ( ++count == 7 ) start(); }
   433 	stop();
   435 	$.ajax({
   436 		url: "data/jsonp.php",
   437 		dataType: "jsonp",
   438 		success: function(data){
   439 			ok( data.data, "JSON results returned (GET, no callback)" );
   440 			plus();
   441 		},
   442 		error: function(data){
   443 			ok( false, "Ajax error JSON (GET, no callback)" );
   444 			plus();
   445 		}
   446 	});
   448 	$.ajax({
   449 		url: "data/jsonp.php?callback=?",
   450 		dataType: "jsonp",
   451 		success: function(data){
   452 			ok( data.data, "JSON results returned (GET, url callback)" );
   453 			plus();
   454 		},
   455 		error: function(data){
   456 			ok( false, "Ajax error JSON (GET, url callback)" );
   457 			plus();
   458 		}
   459 	});
   461 	$.ajax({
   462 		url: "data/jsonp.php",
   463 		dataType: "jsonp",
   464 		data: "callback=?",
   465 		success: function(data){
   466 			ok( data.data, "JSON results returned (GET, data callback)" );
   467 			plus();
   468 		},
   469 		error: function(data){
   470 			ok( false, "Ajax error JSON (GET, data callback)" );
   471 			plus();
   472 		}
   473 	});
   475 	$.ajax({
   476 		url: "data/jsonp.php",
   477 		dataType: "jsonp",
   478 		jsonp: "callback",
   479 		success: function(data){
   480 			ok( data.data, "JSON results returned (GET, data obj callback)" );
   481 			plus();
   482 		},
   483 		error: function(data){
   484 			ok( false, "Ajax error JSON (GET, data obj callback)" );
   485 			plus();
   486 		}
   487 	});
   489 	$.ajax({
   490 		type: "POST",
   491 		url: "data/jsonp.php",
   492 		dataType: "jsonp",
   493 		success: function(data){
   494 			ok( data.data, "JSON results returned (POST, no callback)" );
   495 			plus();
   496 		},
   497 		error: function(data){
   498 			ok( false, "Ajax error JSON (GET, data obj callback)" );
   499 			plus();
   500 		}
   501 	});
   503 	$.ajax({
   504 		type: "POST",
   505 		url: "data/jsonp.php",
   506 		data: "callback=?",
   507 		dataType: "jsonp",
   508 		success: function(data){
   509 			ok( data.data, "JSON results returned (POST, data callback)" );
   510 			plus();
   511 		},
   512 		error: function(data){
   513 			ok( false, "Ajax error JSON (POST, data callback)" );
   514 			plus();
   515 		}
   516 	});
   518 	$.ajax({
   519 		type: "POST",
   520 		url: "data/jsonp.php",
   521 		jsonp: "callback",
   522 		dataType: "jsonp",
   523 		success: function(data){
   524 			ok( data.data, "JSON results returned (POST, data obj callback)" );
   525 			plus();
   526 		},
   527 		error: function(data){
   528 			ok( false, "Ajax error JSON (POST, data obj callback)" );
   529 			plus();
   530 		}
   531 	});
   532 });
   534 test("$.ajax() - JSONP, Remote", function() {
   535 	expect(4);
   537 	var count = 0;
   538 	function plus(){ if ( ++count == 4 ) start(); }
   540 	var base = window.location.href.replace(/\?.*$/, "");
   542 	stop();
   544 	$.ajax({
   545 		url: base + "data/jsonp.php",
   546 		dataType: "jsonp",
   547 		success: function(data){
   548 			ok( data.data, "JSON results returned (GET, no callback)" );
   549 			plus();
   550 		},
   551 		error: function(data){
   552 			ok( false, "Ajax error JSON (GET, no callback)" );
   553 			plus();
   554 		}
   555 	});
   557 	$.ajax({
   558 		url: base + "data/jsonp.php?callback=?",
   559 		dataType: "jsonp",
   560 		success: function(data){
   561 			ok( data.data, "JSON results returned (GET, url callback)" );
   562 			plus();
   563 		},
   564 		error: function(data){
   565 			ok( false, "Ajax error JSON (GET, url callback)" );
   566 			plus();
   567 		}
   568 	});
   570 	$.ajax({
   571 		url: base + "data/jsonp.php",
   572 		dataType: "jsonp",
   573 		data: "callback=?",
   574 		success: function(data){
   575 			ok( data.data, "JSON results returned (GET, data callback)" );
   576 			plus();
   577 		},
   578 		error: function(data){
   579 			ok( false, "Ajax error JSON (GET, data callback)" );
   580 			plus();
   581 		}
   582 	});
   584 	$.ajax({
   585 		url: base + "data/jsonp.php",
   586 		dataType: "jsonp",
   587 		jsonp: "callback",
   588 		success: function(data){
   589 			ok( data.data, "JSON results returned (GET, data obj callback)" );
   590 			plus();
   591 		},
   592 		error: function(data){
   593 			ok( false, "Ajax error JSON (GET, data obj callback)" );
   594 			plus();
   595 		}
   596 	});
   597 });
   599 test("$.ajax() - script, Remote", function() {
   600 	expect(2);
   602 	var base = window.location.href.replace(/\?.*$/, "");
   604 	stop();
   606 	window.foobar = null;
   607 	$.ajax({
   608 		url: base + "data/test.js",
   609 		dataType: "script",
   610 		success: function(data){
   611 			ok( foobar, "Script results returned (GET, no callback)" );
   612 			start();
   613 		}
   614 	});
   615 });
   617 test("$.ajax() - script, Remote with POST", function() {
   618 	expect(3);
   620 	var base = window.location.href.replace(/\?.*$/, "");
   622 	stop();
   624 	window.foobar = null;
   625 	$.ajax({
   626 		url: base + "data/test.js",
   627 		type: "POST",
   628 		dataType: "script",
   629 		success: function(data, status){
   630 			ok( foobar, "Script results returned (GET, no callback)" );
   631 			equals( status, "success", "Script results returned (GET, no callback)" );
   632 			start();
   633 		}
   634 	});
   635 });
   637 test("$.ajax() - script, Remote with scheme-less URL", function() {
   638 	expect(2);
   640 	var base = window.location.href.replace(/\?.*$/, "");
   641 	base = base.replace(/^.*?\/\//, "//");
   643 	stop();
   645 	window.foobar = null;
   646 	$.ajax({
   647 		url: base + "data/test.js",
   648 		dataType: "script",
   649 		success: function(data){
   650 			ok( foobar, "Script results returned (GET, no callback)" );
   651 			start();
   652 		}
   653 	});
   654 });
   656 test("$.getJSON(String, Hash, Function) - JSON array", function() {
   657 	expect(4);
   658 	stop();
   659 	$.getJSON(url("data/json.php"), {json: "array"}, function(json) {
   660 	  equals( json[0].name, 'John', 'Check JSON: first, name' );
   661 	  equals( json[0].age, 21, 'Check JSON: first, age' );
   662 	  equals( json[1].name, 'Peter', 'Check JSON: second, name' );
   663 	  equals( json[1].age, 25, 'Check JSON: second, age' );
   664 	  start();
   665 	});
   666 });
   668 test("$.getJSON(String, Function) - JSON object", function() {
   669 	expect(2);
   670 	stop();
   671 	$.getJSON(url("data/json.php"), function(json) {
   672 	  equals( json.data.lang, 'en', 'Check JSON: lang' );
   673 	  equals( json.data.length, 25, 'Check JSON: length' );
   674 	  start();
   675 	});
   676 });
   678 test("$.getJSON(String, Function) - JSON object with absolute url to local content", function() {
   679 	expect(2);
   681 	var base = window.location.href.replace(/\?.*$/, "");
   683 	stop();
   684 	$.getJSON(url(base + "data/json.php"), function(json) {
   685 	  equals( json.data.lang, 'en', 'Check JSON: lang' );
   686 	  equals( json.data.length, 25, 'Check JSON: length' );
   687 	  start();
   688 	});
   689 });
   691 test("$.post(String, Hash, Function) - simple with xml", function() {
   692 	expect(4);
   693 	stop();
   694 	$.post(url("data/name.php"), {xml: "5-2"}, function(xml){
   695 	  $('math', xml).each(function() {
   696 		    equals( $('calculation', this).text(), '5-2', 'Check for XML' );
   697 		    equals( $('result', this).text(), '3', 'Check for XML' );
   698 		 });
   699 	});
   701 	$.post(url("data/name.php?xml=5-2"), {}, function(xml){
   702 	  $('math', xml).each(function() {
   703 		    equals( $('calculation', this).text(), '5-2', 'Check for XML' );
   704 		    equals( $('result', this).text(), '3', 'Check for XML' );
   705 		 });
   706 	  start();
   707 	});
   708 });
   710 test("$.ajaxSetup({timeout: Number}) - with global timeout", function() {
   711 	stop();
   713 	var passed = 0;
   715 	$.ajaxSetup({timeout: 1000});
   717 	var pass = function() {
   718 		passed++;
   719 		if ( passed == 2 ) {
   720 			ok( true, 'Check local and global callbacks after timeout' );
   721 	     	$('#main').unbind("ajaxError");
   722 			start();
   723 		}
   724 	};
   726 	var fail = function(a,b,c) {
   727 		ok( false, 'Check for timeout failed ' + a + ' ' + b );
   728 		start();
   729 	};
   731 	$('#main').ajaxError(pass);
   733 	$.ajax({
   734 	  type: "GET",
   735 	  url: url("data/name.php?wait=5"),
   736 	  error: pass,
   737 	  success: fail
   738 	});
   740 	// reset timeout
   741 	$.ajaxSetup({timeout: 0});
   742 });
   744 test("$.ajaxSetup({timeout: Number}) with localtimeout", function() {
   745 	stop();
   746 	$.ajaxSetup({timeout: 50});
   748 	$.ajax({
   749 	  type: "GET",
   750 	  timeout: 5000,
   751 	  url: url("data/name.php?wait=1"),
   752 	  error: function() {
   753 		   ok( false, 'Check for local timeout failed' );
   754 		   start();
   755 	  },
   756 	  success: function() {
   757 	    ok( true, 'Check for local timeout' );
   758 	    start();
   759 	  }
   760 	});
   762 	// reset timeout
   763 	$.ajaxSetup({timeout: 0});
   764 });
   766 test("$.ajax - simple get", function() {
   767 	expect(1);
   768 	stop();
   769 	$.ajax({
   770 	  type: "GET",
   771 	  url: url("data/name.php?name=foo"),
   772 	  success: function(msg){
   773 	    equals( msg, 'bar', 'Check for GET' );
   774 	    start();
   775 	  }
   776 	});
   777 });
   779 test("$.ajax - simple post", function() {
   780 	expect(1);
   781 	stop();
   782 	$.ajax({
   783 	  type: "POST",
   784 	  url: url("data/name.php"),
   785 	  data: "name=peter",
   786 	  success: function(msg){
   787 	    equals( msg, 'pan', 'Check for POST' );
   788 	    start();
   789 	  }
   790 	});
   791 });
   793 test("ajaxSetup()", function() {
   794 	expect(1);
   795 	stop();
   796 	$.ajaxSetup({
   797 		url: url("data/name.php?name=foo"),
   798 		success: function(msg){
   799 	    	equals( msg, 'bar', 'Check for GET' );
   800 			start();
   801 		}
   802 	});
   803 	$.ajax();
   804 });
   806 test("custom timeout does not set error message when timeout occurs, see #970", function() {
   807 	stop();
   808 	$.ajax({
   809 		url: "data/name.php?wait=10",
   810 		timeout: 500,
   811 		error: function(request, status) {
   812 			ok( status != null, "status shouldn't be null in error handler" );
   813 			equals( "timeout", status );
   814 			start();
   815 		}
   816 	});
   817 });
   819 test("data option: evaluate function values (#2806)", function() {
   820 	stop();
   821 	$.ajax({
   822 		url: "data/echoQuery.php",
   823 		data: {
   824 			key: function() {
   825 				return "value";
   826 			}
   827 		},
   828 		success: function(result) {
   829 			equals( result, "key=value" );
   830 			start();
   831 		}
   832 	})
   833 });
   834 */
   835 }
   837 //}

mercurial