+ Empty local files will issue errors, it's a known limitation.
+
+
+
+ Results
+
+
+
+ Success:
+
+
+
+
+ Error:
+
+
+
+
+
+ Logs:
+
+
+
+
+
\ No newline at end of file
diff --git a/test/networkerror.html b/test/networkerror.html
new file mode 100644
index 00000000..b06a6ba4
--- /dev/null
+++ b/test/networkerror.html
@@ -0,0 +1,101 @@
+
+
+
+
+
+ jQuery Network Error Test for Firefox
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ jQuery Network Error Test for Firefox
+
+
+ This is a test page for
+
+ #8135
+
+ which was reported in Firefox when accessing properties
+ of an XMLHttpRequest object after a network error occured.
+
+
Take the following steps:
+
+
+ make sure you accessed this page through a web server,
+
+
+ stop the web server,
+
+
+ open the console,
+
+
+ click this
+
+ ,
+
+
+ wait for both requests to fail.
+
+
+
+ Test passes if you get two log lines:
+
+
+ the first starting with "abort",
+
+
+ the second starting with "complete",
+
+
+
+
+ Test fails if the browser notifies an exception.
+
+ Test for jQuery.readyWait, which can be used
+ by plugins and other scripts to indicate something
+ important to the page is still loading and needs
+ to block the DOM ready callbacks that are registered
+ with jQuery.
+
+
+ Script loaders are the most likely kind of script
+ to use jQuery.readyWait, but it could be used by
+ other things like a script that loads a CSS file
+ and wants to pause the DOM ready callbacks.
+
+
+ Expected Result: The text
+ It Worked!
+ appears below after about 2 seconds.
+
+
+ If there is an error in the console,
+ or the text does not show up, then the test failed.
+
+
+
+
diff --git a/test/test.js b/test/test.js
deleted file mode 100644
index e76b795a..00000000
--- a/test/test.js
+++ /dev/null
@@ -1,41 +0,0 @@
-load( "build/js/writeFile.js", "build/js/parse.js" );
-
-function addParams(name, params) {
- if(params.length > 0) {
- name += "(";
- for ( var i = 0; i < params.length; i++) {
- name += params[i].type + ", ";
- }
- return name.substring(0, name.length - 2) + ")";
- } else {
- return name + "()";
- }
-}
-function addTestWrapper(name, test) {
- return 'test("' + name + '", function() {\n' + test + '\n});';
-}
-
-var dir = arguments[1];
-var jq = parse( read(arguments[0]) );
-
-var testFile = [];
-
-String.prototype.decode = function() {
- return this.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
-};
-
-for ( var i = 0; i < jq.length; i++ ) {
- if ( jq[i].tests.length > 0 ) {
- var method = jq[i];
- var name = addParams(method.name, method.params);
- for(var j = 0; j < method.tests.length; j++) {
- if(j > 0) {
- name += "x";
- }
- testFile[testFile.length] = addTestWrapper(name, method.tests[j].decode()) + "\n";
- }
- }
-}
-
-var indexFile = readFile( "build/test/index.html" );
-writeFile( dir + "/index.html", indexFile.replace( /{TESTS}/g, testFile.join("\n") ) );
diff --git a/test/unit/ajax.js b/test/unit/ajax.js
index b44f0773..2a2ac46a 100644
--- a/test/unit/ajax.js
+++ b/test/unit/ajax.js
@@ -240,6 +240,68 @@ test("jQuery.ajax() - error callbacks", function() {
});
});
+test( "jQuery.ajax - multiple method signatures introduced in 1.5 ( #8107)", function() {
+
+ expect( 4 );
+
+ stop();
+
+ jQuery.when(
+ jQuery.ajax().success(function() { ok( true, 'With no arguments' ); }),
+ jQuery.ajax('data/name.html').success(function() { ok( true, 'With only string URL argument' ); }),
+ jQuery.ajax('data/name.html', {} ).success(function() { ok( true, 'With string URL param and map' ); }),
+ jQuery.ajax({ url: 'data/name.html'} ).success(function() { ok( true, 'With only map' ); })
+ ).then( start, start );
+
+});
+
+test("jQuery.ajax() - textStatus and errorThrown values", function() {
+
+ var nb = 2;
+
+ expect( 2 * nb );
+ stop();
+
+ function startN() {
+ if ( !( --nb ) ) {
+ start();
+ }
+ }
+
+ /*
+ Safari 3.x returns "OK" instead of "Not Found"
+ Safari 4.x doesn't have this issue so the test should be re-instated once
+ we drop support for 3.x
+
+ jQuery.ajax({
+ url: url("data/nonExistingURL"),
+ error: function( _ , textStatus , errorThrown ){
+ strictEqual( textStatus, "error", "textStatus is 'error' for 404" );
+ strictEqual( errorThrown, "Not Found", "errorThrown is 'Not Found' for 404");
+ startN();
+ }
+ });
+ */
+
+ jQuery.ajax({
+ url: url("data/name.php?wait=5"),
+ error: function( _ , textStatus , errorThrown ){
+ strictEqual( textStatus, "abort", "textStatus is 'abort' for abort" );
+ strictEqual( errorThrown, "abort", "errorThrown is 'abort' for abort");
+ startN();
+ }
+ }).abort();
+
+ jQuery.ajax({
+ url: url("data/name.php?wait=5"),
+ error: function( _ , textStatus , errorThrown ){
+ strictEqual( textStatus, "mystatus", "textStatus is 'mystatus' for abort('mystatus')" );
+ strictEqual( errorThrown, "mystatus", "errorThrown is 'mystatus' for abort('mystatus')");
+ startN();
+ }
+ }).abort( "mystatus" );
+});
+
test("jQuery.ajax() - responseText on error", function() {
expect( 1 );
@@ -249,7 +311,7 @@ test("jQuery.ajax() - responseText on error", function() {
jQuery.ajax({
url: url("data/errorWithText.php"),
error: function(xhr) {
- strictEqual( xhr.responseText , "plain text message" , "Test jXHR.responseText is filled for HTTP errors" );
+ strictEqual( xhr.responseText , "plain text message" , "Test jqXHR.responseText is filled for HTTP errors" );
},
complete: function() {
start();
@@ -282,14 +344,18 @@ test(".ajax() - retry with jQuery.ajax( this )", function() {
test(".ajax() - headers" , function() {
- expect( 2 );
+ expect( 4 );
stop();
+ jQuery('#foo').ajaxSend(function( evt, xhr ) {
+ xhr.setRequestHeader( "ajax-send", "test" );
+ });
+
var requestHeaders = {
- siMPle: "value",
- "SometHing-elsE": "other value",
- OthEr: "something else"
+ siMPle: "value",
+ "SometHing-elsE": "other value",
+ OthEr: "something else"
},
list = [],
i;
@@ -297,22 +363,31 @@ test(".ajax() - headers" , function() {
for( i in requestHeaders ) {
list.push( i );
}
+ list.push( "ajax-send" );
jQuery.ajax(url("data/headers.php?keys="+list.join( "_" ) ), {
+
headers: requestHeaders,
success: function( data , _ , xhr ) {
var tmp = [];
for ( i in requestHeaders ) {
tmp.push( i , ": " , requestHeaders[ i ] , "\n" );
}
+ tmp.push( "ajax-send: test\n" );
tmp = tmp.join( "" );
- equals( data , tmp , "Headers were sent" );
- equals( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
- start();
+ strictEqual( data , tmp , "Headers were sent" );
+ strictEqual( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" );
+ if ( jQuery.browser.mozilla ) {
+ ok( true, "Firefox doesn't support empty headers" );
+ } else {
+ strictEqual( xhr.getResponseHeader( "Empty-Header" ) , "" , "Empty header received" );
+ }
+ strictEqual( xhr.getResponseHeader( "Sample-Header2" ) , "Hello World 2" , "Second sample header received" );
},
error: function(){ ok(false, "error"); }
- });
+
+ }).then( start, start );
});
@@ -374,6 +449,18 @@ test(".ajax() - contentType" , function() {
});
+test(".ajax() - protocol-less urls", function() {
+ expect(1);
+
+ jQuery.ajax({
+ url: "//somedomain.com",
+ beforeSend: function( xhr, settings ) {
+ equals(settings.url, location.protocol + "//somedomain.com", "Make sure that the protocol is added.");
+ return false;
+ }
+ });
+});
+
test(".ajax() - hash", function() {
expect(3);
@@ -405,7 +492,7 @@ test(".ajax() - hash", function() {
test("jQuery ajax - cross-domain detection", function() {
- expect( 4 );
+ expect( 5 );
var loc = document.location,
otherPort = loc.port === 666 ? 667 : 666,
@@ -420,6 +507,14 @@ test("jQuery ajax - cross-domain detection", function() {
}
});
+ jQuery.ajax({
+ url: 'app:/path',
+ beforeSend: function( _ , s ) {
+ ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
+ return false;
+ }
+ });
+
jQuery.ajax({
dataType: "jsonp",
url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
@@ -450,22 +545,7 @@ test("jQuery ajax - cross-domain detection", function() {
});
-test(".ajax() - 304", function() {
- expect( 1 );
- stop();
-
- jQuery.ajax({
- url: url("data/notmodified.php"),
- success: function(){ ok(true, "304 ok"); },
- // Do this because opera simply refuses to implement 304 handling :(
- // A feature-driven way of detecting this would be appreciated
- // See: http://gist.github.com/599419
- error: function(){ ok(jQuery.browser.opera, "304 not ok "); },
- complete: function(xhr){ start(); }
- });
-});
-
-test(".load()) - 404 error callbacks", function() {
+test(".load() - 404 error callbacks", function() {
expect( 6 );
stop();
@@ -856,7 +936,7 @@ test("serialize()", function() {
});
test("jQuery.param()", function() {
- expect(22);
+ expect(24);
equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
@@ -891,6 +971,9 @@ test("jQuery.param()", function() {
equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
+ // #7945
+ equals( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
+
jQuery.ajaxSetup({ traditional: true });
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
@@ -919,6 +1002,9 @@ test("jQuery.param()", function() {
params = { param1: null };
equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
+
+ params = {'test': {'length': 3, 'foo': 'bar'} };
+ equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
});
test("synchronous request", function() {
@@ -1124,6 +1210,21 @@ test("load(String, String, Function)", function() {
});
});
+test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() {
+ expect(1);
+ stop();
+ jQuery.ajaxSetup({
+ data: "helloworld"
+ });
+ jQuery.get(url('data/echoQuery.php'), function(data) {
+ ok( /helloworld$/.test( data ), 'Data from ajaxSettings was used');
+ jQuery.ajaxSetup({
+ data: null
+ });
+ start();
+ });
+});
+
test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
expect(2);
stop();
@@ -1139,10 +1240,11 @@ test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", f
});
test("jQuery.getScript(String, Function) - with callback", function() {
- expect(2);
+ expect(3);
stop();
- jQuery.getScript(url("data/test.js"), function() {
+ jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) {
equals( foobar, "bar", 'Check if script was evaluated' );
+ strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
setTimeout(start, 100);
});
});
@@ -1158,10 +1260,10 @@ test("jQuery.getScript(String, Function) - no callback", function() {
jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label ) {
test("jQuery.ajax() - JSONP, " + label, function() {
- expect(17);
+ expect(20);
var count = 0;
- function plus(){ if ( ++count == 17 ) start(); }
+ function plus(){ if ( ++count == 18 ) start(); }
stop();
@@ -1265,23 +1367,6 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
}
});
- jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- data: {
- callback: "?"
- },
- success: function(data){
- ok( data.data, "JSON results returned (GET, processed data callback)" );
- plus();
- },
- error: function(data){
- ok( false, "Ajax error JSON (GET, processed data callback)" );
- plus();
- }
- });
-
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
@@ -1318,6 +1403,38 @@ jQuery.each( [ "Same Domain", "Cross Domain" ] , function( crossDomain , label )
}
});
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ jsonpCallback: "functionToCleanUp",
+ success: function(data){
+ ok( data.data, "JSON results returned (GET, custom callback name to be cleaned up)" );
+ strictEqual( window.functionToCleanUp, undefined, "Callback was removed (GET, custom callback name to be cleaned up)" );
+ plus();
+ var xhr;
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ jsonpCallback: "functionToCleanUp",
+ beforeSend: function( jqXHR ) {
+ xhr = jqXHR;
+ return false;
+ }
+ });
+ xhr.error(function() {
+ ok( true, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
+ strictEqual( window.functionToCleanUp, undefined, "Callback was removed after early abort (GET, custom callback name to be cleaned up)" );
+ plus();
+ });
+ },
+ error: function(data){
+ ok( false, "Ajax error JSON (GET, custom callback name to be cleaned up)" );
+ plus();
+ }
+ });
+
jQuery.ajax({
type: "POST",
url: "data/jsonp.php",
@@ -1480,17 +1597,23 @@ test("jQuery.ajax() - malformed JSON", function() {
});
test("jQuery.ajax() - script by content-type", function() {
- expect(1);
+ expect(2);
stop();
- jQuery.ajax({
- url: "data/script.php",
- data: { header: "script" },
- success: function() {
- start();
- }
- });
+ jQuery.when(
+
+ jQuery.ajax({
+ url: "data/script.php",
+ data: { header: "script" }
+ }),
+
+ jQuery.ajax({
+ url: "data/script.php",
+ data: { header: "ecma" }
+ })
+
+ ).then( start, start );
});
test("jQuery.ajax() - json by content-type", function() {
@@ -1593,17 +1716,32 @@ test("jQuery.getJSON(String, Function) - JSON object with absolute url to local
});
});
-test("jQuery.post - data", function() {
- expect(2);
+test("jQuery.post - data", 3, function() {
stop();
- jQuery.post(url("data/name.php"), {xml: "5-2", length: 3}, function(xml){
- jQuery('math', xml).each(function() {
- equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
- equals( jQuery('result', this).text(), '3', 'Check for XML' );
- });
- start();
- });
+ jQuery.when(
+ jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) {
+ jQuery( 'math', xml ).each( function() {
+ equals( jQuery( 'calculation', this ).text(), '5-2', 'Check for XML' );
+ equals( jQuery( 'result', this ).text(), '3', 'Check for XML' );
+ });
+ }),
+
+ jQuery.ajax({
+ url: url('data/echoData.php'),
+ type: "POST",
+ data: {
+ 'test': {
+ 'length': 7,
+ 'foo': 'bar'
+ }
+ },
+ success: function( data ) {
+ strictEqual( data, 'test%5Blength%5D=7&test%5Bfoo%5D=bar', 'Check if a sub-object with a length param is serialized correctly');
+ }
+ })
+ ).then( start, start );
+
});
test("jQuery.post(String, Hash, Function) - simple with xml", function() {
@@ -1768,96 +1906,105 @@ test("data option: empty bodies for non-GET requests", function() {
});
});
-test("jQuery.ajax - If-Modified-Since support", function() {
- expect( 3 );
+var ifModifiedNow = new Date();
- stop();
+jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache ) {
- var url = "data/if_modified_since.php?ts=" + new Date();
+ test("jQuery.ajax - If-Modified-Since support" + label, function() {
+ expect( 3 );
- jQuery.ajax({
- url: url,
- ifModified: true,
- success: function(data, status) {
- equals(status, "success");
+ stop();
- jQuery.ajax({
- url: url,
- ifModified: true,
- success: function(data, status) {
- if ( data === "FAIL" ) {
- ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
- ok(true, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
- } else {
- equals(status, "notmodified");
- ok(data == null, "response body should be empty");
+ var url = "data/if_modified_since.php?ts=" + ifModifiedNow++;
+
+ jQuery.ajax({
+ url: url,
+ ifModified: true,
+ cache: cache,
+ success: function(data, status) {
+ equals(status, "success" );
+
+ jQuery.ajax({
+ url: url,
+ ifModified: true,
+ cache: cache,
+ success: function(data, status) {
+ if ( data === "FAIL" ) {
+ ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
+ ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since').");
+ } else {
+ equals(status, "notmodified");
+ ok(data == null, "response body should be empty");
+ }
+ start();
+ },
+ error: function() {
+ // Do this because opera simply refuses to implement 304 handling :(
+ // A feature-driven way of detecting this would be appreciated
+ // See: http://gist.github.com/599419
+ ok(jQuery.browser.opera, "error");
+ ok(jQuery.browser.opera, "error");
+ start();
}
- start();
- },
- error: function() {
- // Do this because opera simply refuses to implement 304 handling :(
- // A feature-driven way of detecting this would be appreciated
- // See: http://gist.github.com/599419
- ok(jQuery.browser.opera, "error");
- ok(jQuery.browser.opera, "error");
- start();
- }
- });
- },
- error: function() {
- equals(false, "error");
- // Do this because opera simply refuses to implement 304 handling :(
- // A feature-driven way of detecting this would be appreciated
- // See: http://gist.github.com/599419
- ok(jQuery.browser.opera, "error");
- start();
- }
+ });
+ },
+ error: function() {
+ equals(false, "error");
+ // Do this because opera simply refuses to implement 304 handling :(
+ // A feature-driven way of detecting this would be appreciated
+ // See: http://gist.github.com/599419
+ ok(jQuery.browser.opera, "error");
+ start();
+ }
+ });
});
-});
-test("jQuery.ajax - Etag support", function() {
- expect( 3 );
+ test("jQuery.ajax - Etag support" + label, function() {
+ expect( 3 );
- stop();
+ stop();
- var url = "data/etag.php?ts=" + new Date();
+ var url = "data/etag.php?ts=" + ifModifiedNow++;
- jQuery.ajax({
- url: url,
- ifModified: true,
- success: function(data, status) {
- equals(status, "success");
+ jQuery.ajax({
+ url: url,
+ ifModified: true,
+ cache: cache,
+ success: function(data, status) {
+ equals(status, "success" );
- jQuery.ajax({
- url: url,
- ifModified: true,
- success: function(data, status) {
- if ( data === "FAIL" ) {
- ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
- ok(true, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
- } else {
- equals(status, "notmodified");
- ok(data == null, "response body should be empty");
+ jQuery.ajax({
+ url: url,
+ ifModified: true,
+ cache: cache,
+ success: function(data, status) {
+ if ( data === "FAIL" ) {
+ ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
+ ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match').");
+ } else {
+ equals(status, "notmodified");
+ ok(data == null, "response body should be empty");
+ }
+ start();
+ },
+ error: function() {
+ // Do this because opera simply refuses to implement 304 handling :(
+ // A feature-driven way of detecting this would be appreciated
+ // See: http://gist.github.com/599419
+ ok(jQuery.browser.opera, "error");
+ ok(jQuery.browser.opera, "error");
+ start();
}
- start();
- },
- error: function() {
- // Do this because opera simply refuses to implement 304 handling :(
- // A feature-driven way of detecting this would be appreciated
- // See: http://gist.github.com/599419
- ok(jQuery.browser.opera, "error");
- ok(jQuery.browser.opera, "error");
- start();
- }
- });
- },
- error: function() {
- // Do this because opera simply refuses to implement 304 handling :(
- // A feature-driven way of detecting this would be appreciated
- // See: http://gist.github.com/599419
- ok(jQuery.browser.opera, "error");
- start();
- }
+ });
+ },
+ error: function() {
+ // Do this because opera simply refuses to implement 304 handling :(
+ // A feature-driven way of detecting this would be appreciated
+ // See: http://gist.github.com/599419
+ ok(jQuery.browser.opera, "error");
+ start();
+ }
+ });
});
});
@@ -1949,16 +2096,16 @@ test( "jQuery.ajax - statusCode" , function() {
}).statusCode( createStatusCodes( "immediately with method" , isSuccess ) );
jQuery.ajax( url( uri ) , {
- complete: function(jXHR) {
- jXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
+ complete: function(jqXHR) {
+ jqXHR.statusCode( createStatusCodes( "on complete" , isSuccess ) );
countComplete();
}
});
jQuery.ajax( url( uri ) , {
- complete: function(jXHR) {
+ complete: function(jqXHR) {
setTimeout( function() {
- jXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
+ jqXHR.statusCode( createStatusCodes( "very late binding" , isSuccess ) );
countComplete();
} , 100 );
}
@@ -1966,10 +2113,10 @@ test( "jQuery.ajax - statusCode" , function() {
jQuery.ajax( url( uri ) , {
statusCode: createStatusCodes( "all (options)" , isSuccess ),
- complete: function(jXHR) {
- jXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
+ complete: function(jqXHR) {
+ jqXHR.statusCode( createStatusCodes( "all (on complete)" , isSuccess ) );
setTimeout( function() {
- jXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
+ jqXHR.statusCode( createStatusCodes( "all (very late binding)" , isSuccess ) );
countComplete();
} , 100 );
}
@@ -1978,22 +2125,22 @@ test( "jQuery.ajax - statusCode" , function() {
var testString = "";
jQuery.ajax( url( uri ), {
- success: function( a , b , jXHR ) {
+ success: function( a , b , jqXHR ) {
ok( isSuccess , "success" );
var statusCode = {};
- statusCode[ jXHR.status ] = function() {
+ statusCode[ jqXHR.status ] = function() {
testString += "B";
};
- jXHR.statusCode( statusCode );
+ jqXHR.statusCode( statusCode );
testString += "A";
},
- error: function( jXHR ) {
+ error: function( jqXHR ) {
ok( ! isSuccess , "error" );
var statusCode = {};
- statusCode[ jXHR.status ] = function() {
+ statusCode[ jqXHR.status ] = function() {
testString += "B";
};
- jXHR.statusCode( statusCode );
+ jqXHR.statusCode( statusCode );
testString += "A";
},
complete: function() {
@@ -2016,12 +2163,12 @@ test("jQuery.ajax - transitive conversions", function() {
jQuery.ajax( url("data/json.php") , {
converters: {
- "json myjson": function( data ) {
+ "json myJson": function( data ) {
ok( true , "converter called" );
return data;
}
},
- dataType: "myjson",
+ dataType: "myJson",
success: function() {
ok( true , "Transitive conversion worked" );
strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" );
@@ -2031,13 +2178,13 @@ test("jQuery.ajax - transitive conversions", function() {
jQuery.ajax( url("data/json.php") , {
converters: {
- "json myjson": function( data ) {
+ "json myJson": function( data ) {
ok( true , "converter called (*)" );
return data;
}
},
contents: false, /* headers are wrong so we ignore them */
- dataType: "* myjson",
+ dataType: "* myJson",
success: function() {
ok( true , "Transitive conversion worked (*)" );
strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" );
@@ -2049,6 +2196,53 @@ test("jQuery.ajax - transitive conversions", function() {
});
+test("jQuery.ajax - overrideMimeType", function() {
+
+ expect( 2 );
+
+ stop();
+
+ jQuery.when(
+
+ jQuery.ajax( url("data/json.php") , {
+ beforeSend: function( xhr ) {
+ xhr.overrideMimeType( "application/json" );
+ },
+ success: function( json ) {
+ ok( json.data , "Mimetype overriden using beforeSend" );
+ }
+ }),
+
+ jQuery.ajax( url("data/json.php") , {
+ mimeType: "application/json",
+ success: function( json ) {
+ ok( json.data , "Mimetype overriden using mimeType option" );
+ }
+ })
+
+ ).then( start , start );
+
+});
+
+test("jQuery.ajax - abort in prefilter", function() {
+
+ expect( 1 );
+
+ jQuery.ajaxPrefilter(function( options, _, jqXHR ) {
+ if ( options.abortInPrefilter ) {
+ jqXHR.abort();
+ }
+ });
+
+ strictEqual( jQuery.ajax({
+ abortInPrefilter: true,
+ error: function() {
+ ok( false, "error callback called" );
+ }
+ }), false, "Request was properly aborted early by the prefilter" );
+
+});
+
test("jQuery.ajax - active counter", function() {
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
});
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index c58111de..8cf47bed 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -546,6 +546,25 @@ test("val(Function) with incoming value", function() {
equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
});
+// testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only)
+test("val(select) after form.reset() (Bug #2551)", function() {
+ expect(3);
+
+ jQuery('').appendTo("#main");
+
+ jQuery("#kkk").val( "gf" );
+
+ document.kk.reset();
+
+ equal( jQuery("#kkk")[0].value, "cf", "Check value of select after form reset." );
+ equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );
+
+ // re-verify the multi-select is not broken (after form.reset) by our fix for single-select
+ same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
+
+ jQuery("#kk").remove();
+});
+
var testAddClass = function(valueObj) {
expect(5);
var div = jQuery("div");
diff --git a/test/unit/core.js b/test/unit/core.js
index 30039bf9..bce0de0f 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -537,29 +537,29 @@ test("end()", function() {
test("length", function() {
expect(1);
- equals( jQuery("p").length, 6, "Get Number of Elements Found" );
+ equals( jQuery("#main p").length, 6, "Get Number of Elements Found" );
});
test("size()", function() {
expect(1);
- equals( jQuery("p").size(), 6, "Get Number of Elements Found" );
+ equals( jQuery("#main p").size(), 6, "Get Number of Elements Found" );
});
test("get()", function() {
expect(1);
- same( jQuery("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
+ same( jQuery("#main p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
});
test("toArray()", function() {
expect(1);
- same( jQuery("p").toArray(),
+ same( jQuery("#main p").toArray(),
q("firstp","ap","sndp","en","sap","first"),
"Convert jQuery object to an Array" )
})
test("get(Number)", function() {
expect(2);
- equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" );
+ equals( jQuery("#main p").get(0), document.getElementById("firstp"), "Get A Single Element" );
strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
});
@@ -1129,11 +1129,60 @@ test("jQuery.when() - joined", function() {
});
});
-test("jQuery.subclass", function(){
+test("jQuery.sub() - Static Methods", function(){
+ expect(18);
+ var Subclass = jQuery.sub();
+ Subclass.extend({
+ topLevelMethod: function() {return this.debug;},
+ debug: false,
+ config: {
+ locale: 'en_US'
+ },
+ setup: function(config) {
+ this.extend(true, this.config, config);
+ }
+ });
+ Subclass.fn.extend({subClassMethod: function() { return this;}});
+
+ //Test Simple Subclass
+ ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
+ ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
+ same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
+ equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
+
+ //Create a SubSubclass
+ var SubSubclass = Subclass.sub();
+
+ //Make Sure the SubSubclass inherited properly
+ ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true');
+ ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!');
+ same(SubSubclass.config.test, undefined, 'SubSubclass.config.test is set incorrectly');
+ equal(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
+
+ //Modify The Subclass and test the Modifications
+ SubSubclass.fn.extend({subSubClassMethod: function() { return this;}});
+ SubSubclass.setup({locale: 'es_MX', test: 'worked'});
+ SubSubclass.debug = true;
+ SubSubclass.ajax = function() {return false;};
+ ok(SubSubclass.topLevelMethod(), 'SubSubclass.topLevelMethod thought debug was false');
+ same(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, 'Methods Differ!');
+ ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!');
+ ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly');
+ notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
+
+ //This shows that the modifications to the SubSubClass did not bubble back up to it's superclass
+ ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
+ ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
+ same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
+ same(Subclass(document).subSubClassMethod, undefined, 'subSubClassMethod set incorrectly');
+ equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
+});
+
+test("jQuery.sub() - .fn Methods", function(){
expect(378);
- var Subclass = jQuery.subclass(),
- SubclassSubclass = Subclass.subclass(),
+ var Subclass = jQuery.sub(),
+ SubclassSubclass = Subclass.sub(),
jQueryDocument = jQuery(document),
selectors, contexts, methods, method, arg, description;
diff --git a/test/unit/data.js b/test/unit/data.js
index 889fc2da..8fb7f35a 100644
--- a/test/unit/data.js
+++ b/test/unit/data.js
@@ -180,15 +180,28 @@ test(".data()", function() {
var div = jQuery("#foo");
strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" );
div.data("test", "success");
- same( div.data(), {test: "success"}, "data() get the entire data object" );
+
+ var dataObj = div.data();
+
+ // TODO: Remove this hack which was introduced in 1.5.1
+ delete dataObj.toJSON;
+
+ same( dataObj, {test: "success"}, "data() get the entire data object" );
strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
var nodiv = jQuery("#unfound");
equals( nodiv.data(), null, "data() on empty set returns null" );
var obj = { foo: "bar" };
- deepEqual( jQuery(obj).data(), {}, "Retrieve data object from a wrapped JS object (#7524)" );
-})
+ jQuery(obj).data("foo", "baz");
+
+ dataObj = jQuery.extend(true, {}, jQuery(obj).data());
+
+ // TODO: Remove this hack which was introduced for 1.5.1
+ delete dataObj.toJSON;
+
+ deepEqual( dataObj, { foo: "baz" }, "Retrieve data object from a wrapped JS object (#7524)" );
+});
test(".data(String) and .data(String, Object)", function() {
expect(29);
@@ -461,4 +474,15 @@ test(".removeData()", function() {
div.removeData("test.foo");
equals( div.data("test.foo"), undefined, "Make sure data is intact" );
-});
\ No newline at end of file
+});
+
+if (window.JSON && window.JSON.stringify) {
+ test("JSON serialization (#8108)", function () {
+ expect(1);
+
+ var obj = { foo: "bar" };
+ jQuery.data(obj, "hidden", true);
+
+ equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" );
+ });
+}
\ No newline at end of file
diff --git a/test/unit/effects.js b/test/unit/effects.js
index b1dd2884..c0a812f4 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -39,24 +39,23 @@ test("show()", function() {
ok( pass, "Show" );
var speeds = {
- "null speed": null,
- "undefined speed": undefined,
- "empty string speed": "",
- "false speed": false
+ "null speed": null,
+ "undefined speed": undefined,
+ "empty string speed": "",
+ "false speed": false
};
jQuery.each(speeds, function(name, speed) {
- pass = true;
- div.hide().show(speed).each(function() {
- if ( this.style.display == "none" ) pass = false;
- });
- ok( pass, "Show with " + name);
- });
-
+ pass = true;
+ div.hide().show(speed).each(function() {
+ if ( this.style.display == "none" ) pass = false;
+ });
+ ok( pass, "Show with " + name);
+ });
jQuery.each(speeds, function(name, speed) {
- pass = true;
- div.hide().show(speed, function() {
+ pass = true;
+ div.hide().show(speed, function() {
pass = false;
});
ok( pass, "Show with " + name + " does not call animate callback" );
@@ -132,9 +131,9 @@ test("show(Number) - other displays", function() {
-// Supports #7397
+// Supports #7397
test("Persist correct display value", function() {
- expect(3);
+ expect(3);
QUnit.reset();
stop();
@@ -142,31 +141,25 @@ test("Persist correct display value", function() {
jQuery("#main").append('
foo
');
var $span = jQuery("#show-tests span"),
- displayNone = $span.css("display"),
- display = '', num = 0;
+ displayNone = $span.css("display"),
+ display = '', num = 0;
- $span.show();
+ $span.show();
- display = $span.css("display");
+ display = $span.css("display");
- $span.hide();
+ $span.hide();
- $span.fadeIn(100, function() {
-
- equals($span.css("display"), display, "Expecting display: " + display);
-
- $span.fadeOut(100, function () {
-
- equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
-
- $span.fadeIn(100, function() {
-
- equals($span.css("display"), display, "Expecting display: " + display);
-
- start();
- });
- });
- });
+ $span.fadeIn(100, function() {
+ equals($span.css("display"), display, "Expecting display: " + display);
+ $span.fadeOut(100, function () {
+ equals($span.css("display"), displayNone, "Expecting display: " + displayNone);
+ $span.fadeIn(100, function() {
+ equals($span.css("display"), display, "Expecting display: " + display);
+ start();
+ });
+ });
+ });
});
test("animate(Hash, Object, Function)", function() {
@@ -565,21 +558,54 @@ jQuery.checkOverflowDisplay = function(){
start();
}
-test("support negative values < -10000 (bug #7193)", function () {
- expect(1);
- stop();
+test( "jQuery.fx.prototype.cur()", 6, function() {
+ var div = jQuery( "" ).appendTo( "#main" ).css({
+ color: "#ABC",
+ border: "5px solid black",
+ left: "auto",
+ marginBottom: "-11000px"
+ })[0];
- jQuery.extend(jQuery.fx.step, {
- "marginBottom": function(fx) {
- equals( fx.cur(), -11000, "Element has margin-bottom of -11000" );
- delete jQuery.fx.step.marginBottom;
+ equals(
+ ( new jQuery.fx( div, {}, "color" ) ).cur(),
+ jQuery.css( div, "color" ),
+ "Return the same value as jQuery.css for complex properties (bug #7912)"
+ );
+
+ strictEqual(
+ ( new jQuery.fx( div, {}, "borderLeftWidth" ) ).cur(),
+ 5,
+ "Return simple values parsed as Float"
+ );
+
+ // backgroundPosition actually returns 0% 0% in most browser
+ // this fakes a "" return
+ jQuery.cssHooks.backgroundPosition = {
+ get: function() {
+ ok( true, "hook used" );
+ return "";
}
- });
+ };
- jQuery("#main").css("marginBottom", "-11000px").animate({ marginBottom: "-11001px" }, {
- duration: 1,
- complete: start
- });
+ strictEqual(
+ ( new jQuery.fx( div, {}, "backgroundPosition" ) ).cur(),
+ 0,
+ "Return 0 when jQuery.css returns an empty string"
+ );
+
+ delete jQuery.cssHooks.backgroundPosition;
+
+ strictEqual(
+ ( new jQuery.fx( div, {}, "left" ) ).cur(),
+ 0,
+ "Return 0 when jQuery.css returns 'auto'"
+ );
+
+ equals(
+ ( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
+ -11000,
+ "support negative values < -10000 (bug #7193)"
+ );
});
test("JS Overflow and Display", function() {
@@ -803,7 +829,7 @@ test("Chain toggle out", function() {
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
});
test("Chain toggle out with easing and callback", function() {
- jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
+ jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
});
test("Chain slideDown slideUp", function() {
jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
@@ -850,16 +876,16 @@ jQuery.makeTest.id = 1;
test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function () {
expect(4);
- stop();
+ stop();
var $checkedtest = jQuery("#checkedtest");
// IE6 was clearing "checked" in jQuery(elem).show("fast");
$checkedtest.hide().show("fast", function() {
- ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
- ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
- ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
- ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
- start();
+ ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
+ ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
+ ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
+ ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
+ start();
});
});
@@ -926,3 +952,13 @@ test("hide hidden elements, with animation (bug #7141)", function() {
});
});
});
+
+test("animate unit-less properties (#4966)", 2, function() {
+ stop();
+ var div = jQuery( "" ).appendTo( "#main" );
+ equal( div.css( "z-index" ), "0", "z-index is 0" );
+ div.animate({ zIndex: 2 }, function() {
+ equal( div.css( "z-index" ), "2", "z-index is 2" );
+ start();
+ });
+});
diff --git a/test/unit/event.js b/test/unit/event.js
index e4caee82..b7b26046 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -2,22 +2,16 @@ module("event", { teardown: moduleTeardown });
test("null or undefined handler", function() {
expect(2);
- // Supports Fixes bug #7229
- try {
+ // Supports Fixes bug #7229
+ try {
+ jQuery("#firstp").click(null);
+ ok(true, "Passing a null handler will not throw an exception");
+ } catch (e) {}
- jQuery("#firstp").click(null);
-
- ok(true, "Passing a null handler will not throw an exception");
-
- } catch (e) {}
-
- try {
-
- jQuery("#firstp").click(undefined);
-
- ok(true, "Passing an undefined handler will not throw an exception");
-
- } catch (e) {}
+ try {
+ jQuery("#firstp").click(undefined);
+ ok(true, "Passing an undefined handler will not throw an exception");
+ } catch (e) {}
});
test("bind(), with data", function() {
@@ -312,7 +306,7 @@ test("bind/delegate bubbling, isDefaultPrevented", function() {
// Use a native click so we don't get jQuery simulated bubbling
if ( document.createEvent ) {
var e = document.createEvent( 'MouseEvents' );
- e.initEvent( "click", true, true );
+ e.initEvent( "click", true, true );
$jq[0].dispatchEvent(e);
}
else if ( $jq[0].click ) {
@@ -367,38 +361,47 @@ test("bind(), trigger change on select", function() {
}).trigger('change');
});
-test("bind(), namespaced events, cloned events", function() {
- expect(6);
+test("bind(), namespaced events, cloned events", 18, function() {
+ var firstp = jQuery( "#firstp" );
- jQuery("#firstp").bind("custom.test",function(e){
- ok(true, "Custom event triggered");
+ firstp.bind("custom.test",function(e){
+ ok(false, "Custom event triggered");
});
- jQuery("#firstp").bind("click",function(e){
+ firstp.bind("click",function(e){
ok(true, "Normal click triggered");
+ equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
});
- jQuery("#firstp").bind("click.test",function(e){
- ok(true, "Namespaced click triggered");
+ firstp.bind("click.test",function(e){
+ var check = "click";
+ ok( true, "Namespaced click triggered" );
+ if ( e.namespace ) {
+ check += "test";
+ }
+ equal( e.type + e.namespace, check, "Check that only click/click.test events trigger this fn" );
});
- // Trigger both bound fn (2)
- jQuery("#firstp").trigger("click");
+ //clone(true) element to verify events are cloned correctly
+ firstp = firstp.add( firstp.clone( true ).attr( "id", "firstp2" ).insertBefore( firstp ) );
- // Trigger one bound fn (1)
- jQuery("#firstp").trigger("click.test");
+ // Trigger both bound fn (8)
+ firstp.trigger("click");
+
+ // Trigger one bound fn (4)
+ firstp.trigger("click.test");
// Remove only the one fn
- jQuery("#firstp").unbind("click.test");
+ firstp.unbind("click.test");
- // Trigger the remaining fn (1)
- jQuery("#firstp").trigger("click");
+ // Trigger the remaining fn (4)
+ firstp.trigger("click");
- // Remove the remaining fn
- jQuery("#firstp").unbind(".test");
+ // Remove the remaining namespaced fn
+ firstp.unbind(".test");
- // Trigger the remaining fn (0)
- jQuery("#firstp").trigger("custom");
+ // Try triggering the custom event (0)
+ firstp.trigger("custom");
// using contents will get comments regular, text, and comment nodes
jQuery("#nonnodes").contents().bind("tester", function () {
@@ -406,7 +409,7 @@ test("bind(), namespaced events, cloned events", function() {
}).trigger("tester");
// Make sure events stick with appendTo'd elements (which are cloned) #2027
- jQuery("test").click(function(){ return false; }).appendTo("p");
+ jQuery("test").click(function(){ return false; }).appendTo("#main");
ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
});
@@ -471,7 +474,7 @@ test("bind(), multi-namespaced events", function() {
test("bind(), with same function", function() {
expect(2)
- var count = 0 , func = function(){
+ var count = 0, func = function(){
count++;
};
@@ -548,7 +551,7 @@ test("bind(name, false), unbind(name, false)", function() {
});
test("bind()/trigger()/unbind() on plain object", function() {
- expect( 8 );
+ expect( 7 );
var obj = {};
@@ -570,7 +573,6 @@ test("bind()/trigger()/unbind() on plain object", function() {
var events = jQuery._data(obj, "events");
ok( events, "Object has events bound." );
equals( obj.events, undefined, "Events object on plain objects is not events" );
- equals( typeof events, "function", "'events' expando is a function on plain objects." );
equals( obj.test, undefined, "Make sure that test event is not on the plain object." );
equals( obj.handle, undefined, "Make sure that the event handler is not on the plain object." );
@@ -588,7 +590,7 @@ test("bind()/trigger()/unbind() on plain object", function() {
jQuery(obj).unbind("test");
equals( obj && obj[ jQuery.expando ] &&
- obj[ jQuery.expando ][ jQuery.expando ] &&
+ obj[ jQuery.expando ][ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ].events, undefined, "Make sure events object is removed" );
});
@@ -613,18 +615,18 @@ test("unbind(type)", function() {
message = "unbind many with function";
$elem.bind('error1 error2',error)
- .unbind('error1 error2', error )
- .trigger('error1').triggerHandler('error2');
+ .unbind('error1 error2', error )
+ .trigger('error1').triggerHandler('error2');
message = "unbind many"; // #3538
$elem.bind('error1 error2',error)
- .unbind('error1 error2')
- .trigger('error1').triggerHandler('error2');
+ .unbind('error1 error2')
+ .trigger('error1').triggerHandler('error2');
message = "unbind without a type or handler";
$elem.bind("error1 error2.test",error)
- .unbind()
- .trigger("error1").triggerHandler("error2");
+ .unbind()
+ .trigger("error1").triggerHandler("error2");
});
test("unbind(eventObject)", function() {
@@ -1453,6 +1455,8 @@ test("live with change", function(){
});
test("live with submit", function() {
+ expect(5);
+
var count1 = 0, count2 = 0;
jQuery("#testForm").live("submit", function(ev) {
@@ -1469,7 +1473,16 @@ test("live with submit", function() {
equals( count1, 1, "Verify form submit." );
equals( count2, 1, "Verify body submit." );
+ jQuery("#testForm input[name=sub1]").live("click", function(ev) {
+ ok( true, "cancelling submit still calls click handler" );
+ });
+
+ jQuery("#testForm input[name=sub1]")[0].click();
+ equals( count1, 2, "Verify form submit." );
+ equals( count2, 2, "Verify body submit." );
+
jQuery("#testForm").die("submit");
+ jQuery("#testForm input[name=sub1]").die("click");
jQuery("body").die("submit");
});
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 739868bd..34425ed3 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -402,7 +402,8 @@ test("append(Function) with incoming value", function() {
});
test("append the same fragment with events (Bug #6997, 5566)", function () {
- expect(2 + (document.fireEvent ? 1 : 0));
+ var doExtra = !jQuery.support.noCloneEvent && document.fireEvent;
+ expect(2 + (doExtra ? 1 : 0));
stop(1000);
var element;
@@ -410,7 +411,7 @@ test("append the same fragment with events (Bug #6997, 5566)", function () {
// This patch modified the way that cloning occurs in IE; we need to make sure that
// native event handlers on the original object don't get disturbed when they are
// modified on the clone
- if (!jQuery.support.noCloneEvent && document.fireEvent) {
+ if ( doExtra ) {
element = jQuery("div:first").click(function () {
ok(true, "Event exists on original after being unbound on clone");
jQuery(this).unbind('click');
@@ -883,6 +884,19 @@ test("jQuery.clone() (#8017)", function() {
equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
});
+test("clone() (#8070)", function () {
+ expect(2);
+
+ jQuery('').appendTo('#main');
+ var selects = jQuery('.test8070');
+ selects.append('');
+
+ equals( selects[0].childNodes.length, 2, "First select got two nodes" );
+ equals( selects[1].childNodes.length, 2, "Second select got two nodes" );
+
+ selects.remove();
+});
+
test("clone()", function() {
expect(37);
equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
@@ -940,6 +954,17 @@ test("clone()", function() {
div.remove();
clone.remove();
+ var divEvt = jQuery("
test
").click(function(){
+ ok( false, "Bound event still exists after .clone()." );
+ }),
+ cloneEvt = divEvt.clone();
+
+ // Make sure that doing .clone() doesn't clone events
+ cloneEvt.trigger("click");
+
+ cloneEvt.remove();
+ divEvt.remove();
+
// this is technically an invalid object, but because of the special
// classid instantiation it is the only kind that IE has trouble with,
// so let's test with it too.
@@ -982,7 +1007,7 @@ test("clone()", function() {
test("clone(form element) (Bug #3879, #6655)", function() {
expect(6);
- element = jQuery("");
+ var element = jQuery("");
equals( element.clone().find("option:selected").val(), element.find("option:selected").val(), "Selected option cloned correctly" );
@@ -991,7 +1016,7 @@ test("clone(form element) (Bug #3879, #6655)", function() {
equals( clone.is(":checked"), element.is(":checked"), "Checked input cloned correctly" );
equals( clone[0].defaultValue, "foo", "Checked input defaultValue cloned correctly" );
- equals( clone[0].defaultChecked, !jQuery.support.noCloneEvent, "Checked input defaultChecked cloned correctly" );
+ equals( clone[0].defaultChecked, !jQuery.support.noCloneChecked, "Checked input defaultChecked cloned correctly" );
element = jQuery("");
clone = element.clone();
@@ -1002,6 +1027,14 @@ test("clone(form element) (Bug #3879, #6655)", function() {
equals( clone[0].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
});
+test("clone(multiple selected options) (Bug #8129)", function() {
+ expect(1);
+ var element = jQuery("");
+
+ equals( element.clone().find("option:selected").length, element.find("option:selected").length, "Multiple selected options cloned correctly" );
+
+});
+
if (!isLocal) {
test("clone() on XML nodes", function() {
expect(2);
diff --git a/test/unit/selector.js b/test/unit/selector.js
deleted file mode 100644
index d23b4e43..00000000
--- a/test/unit/selector.js
+++ /dev/null
@@ -1,510 +0,0 @@
-module("selector", { teardown: moduleTeardown });
-
-test("element", function() {
- expect(21);
- QUnit.reset();
-
- ok( jQuery("*").size() >= 30, "Select all" );
- var all = jQuery("*"), good = true;
- for ( var i = 0; i < all.length; i++ )
- if ( all[i].nodeType == 8 )
- good = false;
- ok( good, "Select all elements, no comment nodes" );
- t( "Element Selector", "p", ["firstp","ap","sndp","en","sap","first"] );
- t( "Element Selector", "body", ["body"] );
- t( "Element Selector", "html", ["html"] );
- t( "Parent Element", "div p", ["firstp","ap","sndp","en","sap","first"] );
- equals( jQuery("param", "#object1").length, 2, "Object/param as context" );
-
- same( jQuery("p", document.getElementsByTagName("div")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
- same( jQuery("p", "div").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
- same( jQuery("p", jQuery("div")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
- same( jQuery("div").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context." );
-
- same( jQuery("#form").find("select").get(), q("select1","select2","select3","select4","select5"), "Finding selects with a context." );
-
- ok( jQuery("#length").length, '<input name="length"> cannot be found under IE, see #945' );
- ok( jQuery("#lengthtest input").length, '<input name="length"> cannot be found under IE, see #945' );
-
- // Check for unique-ness and sort order
- same( jQuery("p, div p").get(), jQuery("p").get(), "Check for duplicates: p, div p" );
-
- t( "Checking sort order", "h2, h1", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
- t( "Checking sort order", "h2:first, h1:first", ["qunit-header", "qunit-banner"] );
- t( "Checking sort order", "p, p a", ["firstp", "simon1", "ap", "google", "groups", "anchor1", "mark", "sndp", "en", "yahoo", "sap", "anchor2", "simon", "first"] );
-
- // Test Conflict ID
- same( jQuery("#lengthtest").find("#idTest").get(), q("idTest"), "Finding element with id of ID." );
- same( jQuery("#lengthtest").find("[name='id']").get(), q("idTest"), "Finding element with id of ID." );
- same( jQuery("#lengthtest").find("input[id='idTest']").get(), q("idTest"), "Finding elements with a context." );
-});
-
-if ( location.protocol != "file:" ) {
- test("XML Document Selectors", function() {
- expect(8);
- stop();
- jQuery.get("data/with_fries.xml", function(xml) {
- equals( jQuery("foo_bar", xml).length, 1, "Element Selector with underscore" );
- equals( jQuery(".component", xml).length, 1, "Class selector" );
- equals( jQuery("[class*=component]", xml).length, 1, "Attribute selector for class" );
- equals( jQuery("property[name=prop2]", xml).length, 1, "Attribute selector with name" );
- equals( jQuery("[name=prop2]", xml).length, 1, "Attribute selector with name" );
- equals( jQuery("#seite1", xml).length, 1, "Attribute selector with ID" );
- equals( jQuery("component#seite1", xml).length, 1, "Attribute selector with ID" );
- equals( jQuery("component", xml).filter("#seite1").length, 1, "Attribute selector filter with ID" );
- start();
- });
- });
-}
-
-test("broken", function() {
- expect(19);
-
- function broken(name, selector) {
- try {
- jQuery(selector);
- ok( false, name + ": " + selector );
- } catch(e){
- ok( typeof e === "string" && e.indexOf("Syntax error") >= 0,
- name + ": " + selector );
- }
- }
-
- broken( "Broken Selector", "[", [] );
- broken( "Broken Selector", "(", [] );
- broken( "Broken Selector", "{", [] );
- broken( "Broken Selector", "<", [] );
- broken( "Broken Selector", "()", [] );
- broken( "Broken Selector", "<>", [] );
- broken( "Broken Selector", "{}", [] );
- broken( "Doesn't exist", ":visble", [] );
- broken( "Nth-child", ":nth-child", [] );
- broken( "Nth-child", ":nth-child(-)", [] );
- // Sigh. WebKit thinks this is a real selector in qSA
- // They've already fixed this and it'll be coming into
- // current browsers soon.
- //broken( "Nth-child", ":nth-child(asdf)", [] );
- broken( "Nth-child", ":nth-child(2n+-0)", [] );
- broken( "Nth-child", ":nth-child(2+0)", [] );
- broken( "Nth-child", ":nth-child(- 1n)", [] );
- broken( "Nth-child", ":nth-child(-1 n)", [] );
- broken( "First-child", ":first-child(n)", [] );
- broken( "Last-child", ":last-child(n)", [] );
- broken( "Only-child", ":only-child(n)", [] );
-
- // Make sure attribute value quoting works correctly. See: #6093
- var attrbad = jQuery('').appendTo("body");
-
- broken( "Attribute not escaped", "input[name=foo.baz]", [] );
- broken( "Attribute not escaped", "input[name=foo[baz]]", [] );
-
- attrbad.remove();
-});
-
-test("id", function() {
- expect(29);
- t( "ID Selector", "#body", ["body"] );
- t( "ID Selector w/ Element", "body#body", ["body"] );
- t( "ID Selector w/ Element", "ul#first", [] );
- t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] );
- t( "ID selector with non-existant descendant", "#firstp #foobar", [] );
- t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] );
- t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] );
- t( "Descendant ID selector using UTF8", "div #台北", ["台北"] );
- t( "Child ID selector using UTF8", "form > #台北", ["台北"] );
-
- t( "Escaped ID", "#foo\\:bar", ["foo:bar"] );
- t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
- t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] );
- t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
- t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] );
- t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
-
- t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
- t( "ID Selector, not an ancestor ID", "#form #first", [] );
- t( "ID Selector, not a child ID", "#form > #option1a", [] );
-
- t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] );
- t( "All Children of ID with no children", "#firstUL > *", [] );
-
- var a = jQuery('
').appendTo('#main');
- equals( jQuery("#tName1")[0].id, 'tName1', "ID selector with same value for a name attribute" );
- equals( jQuery("#tName2").length, 0, "ID selector non-existing but name attribute on an A tag" );
- a.remove();
-
- t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] );
-
- t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986
-
- same( jQuery("body").find("div#form").get(), [], "ID selector within the context of another element" );
-
- //#7533
- equal( jQuery("
foo
").find("p").length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" );
-
- t( "Underscore ID", "#types_all", ["types_all"] );
- t( "Dash ID", "#fx-queue", ["fx-queue"] );
-
- t( "ID with weird characters in it", "#name\\+value", ["name+value"] );
-});
-
-test("class", function() {
- expect(22);
- t( "Class Selector", ".blog", ["mark","simon"] );
- t( "Class Selector", ".GROUPS", ["groups"] );
- t( "Class Selector", ".blog.link", ["simon"] );
- t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
- t( "Parent Class Selector", "p .blog", ["mark","simon"] );
-
- same( jQuery(".blog", document.getElementsByTagName("p")).get(), q("mark", "simon"), "Finding elements with a context." );
- same( jQuery(".blog", "p").get(), q("mark", "simon"), "Finding elements with a context." );
- same( jQuery(".blog", jQuery("p")).get(), q("mark", "simon"), "Finding elements with a context." );
- same( jQuery("p").find(".blog").get(), q("mark", "simon"), "Finding elements with a context." );
-
- t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] );
- //t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
- t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] );
- t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
- t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
- t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] );
-
- t( "Escaped Class", ".foo\\:bar", ["foo:bar"] );
- t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
- t( "Descendant scaped Class", "div .foo\\:bar", ["foo:bar"] );
- t( "Descendant scaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
- t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
- t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
-
- var div = document.createElement("div");
- div.innerHTML = "";
- same( jQuery(".e", div).get(), [ div.firstChild ], "Finding a second class." );
-
- div.lastChild.className = "e";
-
- same( jQuery(".e", div).get(), [ div.firstChild, div.lastChild ], "Finding a modified class." );
-});
-
-test("name", function() {
- expect(15);
-
- t( "Name selector", "input[name=action]", ["text1"] );
- t( "Name selector with single quotes", "input[name='action']", ["text1"] );
- t( "Name selector with double quotes", 'input[name="action"]', ["text1"] );
-
- t( "Name selector non-input", "[name=test]", ["length", "fx-queue"] );
- t( "Name selector non-input", "[name=div]", ["fadein"] );
- t( "Name selector non-input", "*[name=iframe]", ["iframe"] );
-
- t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] )
-
- same( jQuery("#form").find("input[name=action]").get(), q("text1"), "Name selector within the context of another element" );
- same( jQuery("#form").find("input[name='foo[bar]']").get(), q("hidden2"), "Name selector for grouped form element within the context of another element" );
-
- var form = jQuery("").appendTo("body");
-
- equals( form.find("input").length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
-
- form.remove();
-
- var a = jQuery('