Closes #741: Remove $("body") case in favor of $(document.body).

This commit is contained in:
Dave Methvin
2012-04-18 12:47:20 -04:00
committed by Rick Waldron waldron.rick@gmail.com
parent 376e0d9fa8
commit 532ba250a9
30 changed files with 757 additions and 627 deletions

View File

@@ -1,3 +1,5 @@
/*jshint multistr:true*/
var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
$ = this.$ || "$",
originaljQuery = jQuery,
@@ -45,6 +47,53 @@ function t(a,b,c) {
deepEqual(f, q.apply(q,c), a + " (" + b + ")");
}
var createDashboardXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<dashboard> \
<locations class="foo"> \
<location for="bar" checked="different"> \
<infowindowtab> \
<tab title="Location"><![CDATA[blabla]]></tab> \
<tab title="Users"><![CDATA[blublu]]></tab> \
</infowindowtab> \
</location> \
</locations> \
</dashboard>';
return jQuery.parseXML(string);
};
var createWithFriesXML = function() {
var string = '<?xml version="1.0" encoding="UTF-8"?> \
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> \
<soap:Body> \
<jsconf xmlns="http://www.example.com/ns1"> \
<response xmlns:ab="http://www.example.com/ns2"> \
<meta> \
<component id="seite1" class="component"> \
<properties xmlns:cd="http://www.example.com/ns3"> \
<property name="prop1"> \
<thing /> \
<value>1</value> \
</property> \
<property name="prop2"> \
<thing att="something" /> \
</property> \
<foo_bar>foo</foo_bar> \
</properties> \
</component> \
</meta> \
</response> \
</jsconf> \
</soap:Body> \
</soap:Envelope>';
return jQuery.parseXML(string);
};
var fireNative;
if ( document.createEvent ) {
fireNative = function( node, type ) {
@@ -159,4 +208,4 @@ function url(value) {
window.start = function() {
oldStart();
};
})();
})();

View File

@@ -857,7 +857,7 @@ test("jQuery.ajax - beforeSend", function() {
test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
expect(2);
var request = jQuery.ajax({
jQuery.ajax({
url: url("data/name.html"),
beforeSend: function() {
ok( true, "beforeSend got called, canceling" );
@@ -872,13 +872,14 @@ test("jQuery.ajax - beforeSend, cancel request (#2688)", function() {
error: function() {
ok( false, "request didn't get canceled" );
}
}).fail(function( _, reason ) {
strictEqual( reason, "canceled", "canceled request must fail with 'canceled' status text" );
});
ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
});
test("jQuery.ajax - beforeSend, cancel request manually", function() {
expect(2);
var request = jQuery.ajax({
jQuery.ajax({
url: url("data/name.html"),
beforeSend: function(xhr) {
ok( true, "beforeSend got called, canceling" );
@@ -893,8 +894,9 @@ test("jQuery.ajax - beforeSend, cancel request manually", function() {
error: function() {
ok( false, "request didn't get canceled" );
}
}).fail(function( _, reason ) {
strictEqual( reason, "canceled", "manually canceled request must fail with 'canceled' status text" );
});
ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" );
});
window.foobar = null;
@@ -960,13 +962,16 @@ test("serialize()", function() {
});
test("jQuery.param()", function() {
expect(21);
expect(22);
equal( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"string":"foo","null":null,"undefined":undefined};
equal( jQuery.param(params), "string=foo&null=&undefined=", "handle nulls and undefineds properly" );
params = {someName: [1, 2, 3], regularThing: "blah" };
equal( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
@@ -980,13 +985,13 @@ test("jQuery.param()", function() {
equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure" );
equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" );
params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equal( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
equal( decodeURIComponent( jQuery.param({ a: [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
@@ -1011,16 +1016,16 @@ test("jQuery.param()", function() {
equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure" );
equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" );
params = { a: [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { b: [ 7, [ 8, 9 ], [ { c: 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { e: { f: { g: [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equal( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=undefined&i[]=10&i[]=11&j=true&k=false&l[]=undefined&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
params = { param1: null };
equal( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
equal( jQuery.param(params,false), "param1=", "Make sure that null params aren't traversed." );
params = {"test": {"length": 3, "foo": "bar"} };
equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
@@ -2109,13 +2114,14 @@ test( "jQuery.ajax - Context with circular references (#9887)", 2, function () {
context = {};
context.field = context;
try {
success = !jQuery.ajax( "non-existing", {
jQuery.ajax( "non-existing", {
context: context,
beforeSend: function() {
ok( this === context, "context was not deep extended" );
return false;
}
});
success = true;
} catch (e) { console.log( e ); }
ok( success, "context with circular reference did not generate an exception" );
});
@@ -2315,12 +2321,14 @@ test("jQuery.ajax - abort in prefilter", function() {
}
});
strictEqual( jQuery.ajax({
jQuery.ajax({
abortInPrefilter: true,
error: function() {
ok( false, "error callback called" );
}
}), false, "Request was properly aborted early by the prefilter" );
}).fail(function( _, reason ) {
strictEqual( reason, 'canceled', "Request aborted by the prefilter must fail with 'canceled' status text" );
});
});

View File

@@ -127,18 +127,13 @@ test("attr(String)", function() {
equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
});
if ( !isLocal ) {
test("attr(String) in XML Files", function() {
expect(3);
stop();
jQuery.get("data/dashboard.xml", function( xml ) {
equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" );
start();
});
});
}
test("attr(String) in XML Files", function() {
expect(3);
var xml = createDashboardXML();
equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" );
});
test("attr(String, Function)", function() {
expect(2);
@@ -392,21 +387,16 @@ test("attr(jquery_method)", function(){
equal( elem.style.paddingRight, "1px", "attr({...})");
});
if ( !isLocal ) {
test("attr(String, Object) - Loaded via XML document", function() {
expect(2);
stop();
jQuery.get("data/dashboard.xml", function( xml ) {
var titles = [];
jQuery( "tab", xml ).each(function() {
titles.push( jQuery(this).attr("title") );
});
equal( titles[0], "Location", "attr() in XML context: Check first title" );
equal( titles[1], "Users", "attr() in XML context: Check second title" );
start();
});
test("attr(String, Object) - Loaded via XML document", function() {
expect(2);
var xml = createDashboardXML();
var titles = [];
jQuery( "tab", xml ).each(function() {
titles.push( jQuery(this).attr("title") );
});
}
equal( titles[0], "Location", "attr() in XML context: Check first title" );
equal( titles[1], "Users", "attr() in XML context: Check second title" );
});
test("attr('tabindex')", function() {
expect(8);
@@ -1192,3 +1182,16 @@ test("coords returns correct values in IE6/IE7, see #10828", function() {
area = map.html("<area shape='rect' href='#' alt='a' /></map>").find("area");
equal( area.attr("coords"), undefined, "did not retrieve coords correctly");
});
test("Handle cased attributes on XML DOM correctly in removeAttr()", function() {
expect(1);
var xmlStr = "<root><item fooBar='123' /></root>",
$xmlDoc = jQuery( jQuery.parseXML( xmlStr ) ),
$item = $xmlDoc.find( "item" ),
el = $item[0];
$item.removeAttr( "fooBar" );
equal( el.attributes.length, 0, "attribute with upper case did not get removed" );
});

View File

@@ -33,149 +33,171 @@ var output,
}
};
jQuery.each( tests, function( flags, resultString ) {
function showFlags( flags ) {
if ( typeof flags === "string" ) {
return '"' + flags + '"';
}
var output = [], key;
for ( key in flags ) {
output.push( '"' + key + '": ' + flags[ key ] );
}
return "{ " + output.join( ", " ) + " }";
}
jQuery.each( tests, function( strFlags, resultString ) {
var objectFlags = {};
jQuery.each( strFlags.split( " " ), function() {
if ( this.length ) {
objectFlags[ this ] = true;
}
});
jQuery.each( filters, function( filterLabel, filter ) {
test( "jQuery.Callbacks( \"" + flags + "\" ) - " + filterLabel, function() {
jQuery.each( { "string": strFlags, "object": objectFlags }, function( flagsTypes, flags ) {
expect( 20 );
test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() {
// Give qunit a little breathing room
stop();
setTimeout( start, 0 );
expect( 20 );
var cblist;
results = resultString.split( /\s+/ );
// Give qunit a little breathing room
stop();
setTimeout( start, 0 );
// Basic binding and firing
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function( str ) {
output += str;
});
cblist.fire( "A" );
strictEqual( output, "XA", "Basic binding and firing" );
strictEqual( cblist.fired(), true, ".fired() detects firing" );
output = "X";
cblist.disable();
cblist.add(function( str ) {
output += str;
});
strictEqual( output, "X", "Adding a callback after disabling" );
cblist.fire( "A" );
strictEqual( output, "X", "Firing after disabling" );
var cblist;
results = resultString.split( /\s+/ );
// Basic binding and firing (context, arguments)
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function() {
equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" );
});
cblist.fireWith( window, [ "A", "B" ] );
strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
// Basic binding and firing
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function( str ) {
output += str;
});
cblist.fire( "A" );
strictEqual( output, "XA", "Basic binding and firing" );
strictEqual( cblist.fired(), true, ".fired() detects firing" );
output = "X";
cblist.disable();
cblist.add(function( str ) {
output += str;
});
strictEqual( output, "X", "Adding a callback after disabling" );
cblist.fire( "A" );
strictEqual( output, "X", "Firing after disabling" );
// fireWith with no arguments
output = "";
cblist = jQuery.Callbacks( flags );
cblist.add(function() {
equal( this, window, "fireWith with no arguments (context is window)" );
strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
});
cblist.fireWith();
// Basic binding and firing (context, arguments)
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add(function() {
equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" );
});
cblist.fireWith( window, [ "A", "B" ] );
strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
// Basic binding, removing and firing
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA, outputB, outputC );
cblist.remove( outputB, outputC );
cblist.fire();
strictEqual( output, "XA", "Basic binding, removing and firing" );
// fireWith with no arguments
output = "";
cblist = jQuery.Callbacks( flags );
cblist.add(function() {
equal( this, window, "fireWith with no arguments (context is window)" );
strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
});
cblist.fireWith();
// Empty
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA );
cblist.add( outputB );
cblist.add( outputC );
cblist.empty();
cblist.fire();
strictEqual( output, "X", "Empty" );
// Basic binding, removing and firing
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA, outputB, outputC );
cblist.remove( outputB, outputC );
cblist.fire();
strictEqual( output, "XA", "Basic binding, removing and firing" );
// Locking
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( function( str ) {
output += str;
});
cblist.lock();
cblist.add( function( str ) {
output += str;
});
cblist.fire( "A" );
cblist.add( function( str ) {
output += str;
});
strictEqual( output, "X", "Lock early" );
// Ordering
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( function() {
// Empty
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA );
cblist.add( outputB );
cblist.add( outputC );
outputA();
}, outputB );
cblist.fire();
strictEqual( output, results.shift(), "Proper ordering" );
cblist.empty();
cblist.fire();
strictEqual( output, "X", "Empty" );
// Add and fire again
output = "X";
cblist.add( function() {
// Locking
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( function( str ) {
output += str;
});
cblist.lock();
cblist.add( function( str ) {
output += str;
});
cblist.fire( "A" );
cblist.add( function( str ) {
output += str;
});
strictEqual( output, "X", "Lock early" );
// Ordering
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( function() {
cblist.add( outputC );
outputA();
}, outputB );
cblist.fire();
strictEqual( output, results.shift(), "Proper ordering" );
// Add and fire again
output = "X";
cblist.add( function() {
cblist.add( outputC );
outputA();
}, outputB );
strictEqual( output, results.shift(), "Add after fire" );
output = "X";
cblist.fire();
strictEqual( output, results.shift(), "Fire again" );
// Multiple fire
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( function( str ) {
output += str;
} );
cblist.fire( "A" );
strictEqual( output, "XA", "Multiple fire (first fire)" );
output = "X";
cblist.add( function( str ) {
output += str;
} );
strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
output = "X";
cblist.fire( "B" );
strictEqual( output, results.shift(), "Multiple fire (second fire)" );
output = "X";
cblist.add( function( str ) {
output += str;
} );
strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
// Return false
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA, function() { return false; }, outputB );
cblist.add( outputA );
cblist.fire();
strictEqual( output, results.shift(), "Callback returning false" );
// Add another callback (to control lists with memory do not fire anymore)
output = "X";
cblist.add( outputC );
outputA();
}, outputB );
strictEqual( output, results.shift(), "Add after fire" );
output = "X";
cblist.fire();
strictEqual( output, results.shift(), "Fire again" );
// Multiple fire
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( function( str ) {
output += str;
} );
cblist.fire( "A" );
strictEqual( output, "XA", "Multiple fire (first fire)" );
output = "X";
cblist.add( function( str ) {
output += str;
} );
strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
output = "X";
cblist.fire( "B" );
strictEqual( output, results.shift(), "Multiple fire (second fire)" );
output = "X";
cblist.add( function( str ) {
output += str;
} );
strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
// Return false
output = "X";
cblist = jQuery.Callbacks( flags );
cblist.add( outputA, function() { return false; }, outputB );
cblist.add( outputA );
cblist.fire();
strictEqual( output, results.shift(), "Callback returning false" );
// Add another callback (to control lists with memory do not fire anymore)
output = "X";
cblist.add( outputC );
strictEqual( output, results.shift(), "Adding a callback after one returned false" );
strictEqual( output, results.shift(), "Adding a callback after one returned false" );
});
});
});
});

View File

@@ -547,21 +547,16 @@ test("XSS via location.hash", function() {
jQuery( '#<img id="check9521" src="no-such-.gif" onerror="jQuery._check9521(false)">' ).appendTo("#qunit-fixture");
} catch (err) {
jQuery._check9521(true);
};
}
});
if ( !isLocal ) {
test("isXMLDoc - XML", function() {
expect(3);
stop();
jQuery.get("data/dashboard.xml", function(xml) {
ok( jQuery.isXMLDoc( xml ), "XML document" );
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
start();
});
var xml = createDashboardXML();
ok( jQuery.isXMLDoc( xml ), "XML document" );
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
});
}
test("isWindow", function() {
expect( 14 );
@@ -638,20 +633,16 @@ test("jQuery('html', context)", function() {
equal($span.length, 1, "Verify a span created with a div context works, #1763");
});
if ( !isLocal ) {
test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
expect(2);
stop();
jQuery.get("data/dashboard.xml", function(xml) {
// tests for #1419 where IE was a problem
var tab = jQuery("tab", xml).eq(0);
equal( tab.text(), "blabla", "Verify initial text correct" );
tab.text("newtext");
equal( tab.text(), "newtext", "Verify new text correct" );
start();
});
var xml = createDashboardXML();
// tests for #1419 where IE was a problem
var tab = jQuery("tab", xml).eq(0);
equal( tab.text(), "blabla", "Verify initial text correct" );
tab.text("newtext");
equal( tab.text(), "newtext", "Verify new text correct" );
});
}
test("end()", function() {
expect(3);

View File

@@ -555,6 +555,18 @@ test("outerWidth(true) and css('margin') returning % instead of px in Webkit, se
equal( el.outerWidth(true), 400, "outerWidth(true) and css('margin') returning % instead of px in Webkit, see #10639" );
});
test("css('width') should respect box-sizing, see #11004", function() {
var el_disconnected = jQuery("<div style='width:300px;margin:2px;padding:2px;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>"),
el = el_disconnected.clone().appendTo("#qunit-fixture"),
width_initial = el.css("width"),
width_roundtrip = el.css("width", el.css("width")).css("width"),
width_initial_disconnected = el_disconnected.css("width"),
width_roundtrip_disconnected = el_disconnected.css("width", el_disconnected.css("width")).css("width");
equal( width_roundtrip, width_initial, "css('width') is not respecting box-sizing, see #11004");
equal( width_roundtrip_disconnected, width_initial_disconnected, "css('width') is not respecting box-sizing for disconnected element, see #11004");
});
test( "cssHooks - expand", function() {
expect( 15 );
var result,

View File

@@ -184,9 +184,6 @@ test(".data()", function() {
var dataObj = div.data();
// TODO: Remove this hack which was introduced in 1.5.1
delete dataObj.toJSON;
deepEqual( dataObj, {test: "success"}, "data() get the entire data object" );
strictEqual( div.data("foo"), undefined, "Make sure that missing result is still undefined" );
@@ -198,9 +195,6 @@ test(".data()", function() {
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)" );
});

View File

@@ -8,32 +8,36 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
test("jQuery.Deferred" + withNew, function() {
expect( 22 );
expect( 23 );
createDeferred().resolve().then( function() {
var defer = createDeferred();
strictEqual( defer.pipe, defer.then, "pipe is an alias of then" );
createDeferred().resolve().done(function() {
ok( true , "Success on resolve" );
ok( this.isResolved(), "Deferred is resolved" );
strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
}, function() {
}).fail(function() {
ok( false , "Error on resolve" );
}).always( function() {
}).always(function() {
ok( true , "Always callback on resolve" );
});
createDeferred().reject().then( function() {
createDeferred().reject().done(function() {
ok( false , "Success on reject" );
}, function() {
}).fail(function() {
ok( true , "Error on reject" );
ok( this.isRejected(), "Deferred is rejected" );
strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
}).always( function() {
}).always(function() {
ok( true , "Always callback on reject" );
});
createDeferred( function( defer ) {
createDeferred(function( defer ) {
ok( this === defer , "Defer passed as this & first argument" );
this.resolve( "done" );
}).then( function( value ) {
}).done( function( value ) {
strictEqual( value , "done" , "Passed function executed" );
});
@@ -58,7 +62,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
test( "jQuery.Deferred - chainability", function() {
var methods = "resolve reject notify resolveWith rejectWith notifyWith done fail progress then always".split( " " ),
var methods = "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split( " " ),
defer = jQuery.Deferred();
expect( methods.length );
@@ -69,12 +73,12 @@ test( "jQuery.Deferred - chainability", function() {
});
});
test( "jQuery.Deferred.pipe - filtering (done)", function() {
test( "jQuery.Deferred.then - filtering (done)", function() {
expect(4);
var defer = jQuery.Deferred(),
piped = defer.pipe(function( a, b ) {
piped = defer.then(function( a, b ) {
return a * b;
}),
value1,
@@ -96,21 +100,21 @@ test( "jQuery.Deferred.pipe - filtering (done)", function() {
strictEqual( value2, 3, "second resolve value ok" );
strictEqual( value3, 6, "result of filter ok" );
jQuery.Deferred().reject().pipe(function() {
ok( false, "pipe should not be called on reject" );
jQuery.Deferred().reject().then(function() {
ok( false, "then should not be called on reject" );
});
jQuery.Deferred().resolve().pipe( jQuery.noop ).done(function( value ) {
strictEqual( value, undefined, "pipe done callback can return undefined/null" );
jQuery.Deferred().resolve().then( jQuery.noop ).done(function( value ) {
strictEqual( value, undefined, "then done callback can return undefined/null" );
});
});
test( "jQuery.Deferred.pipe - filtering (fail)", function() {
test( "jQuery.Deferred.then - filtering (fail)", function() {
expect(4);
var defer = jQuery.Deferred(),
piped = defer.pipe( null, function( a, b ) {
piped = defer.then( null, function( a, b ) {
return a * b;
} ),
value1,
@@ -132,21 +136,21 @@ test( "jQuery.Deferred.pipe - filtering (fail)", function() {
strictEqual( value2, 3, "second reject value ok" );
strictEqual( value3, 6, "result of filter ok" );
jQuery.Deferred().resolve().pipe( null, function() {
ok( false, "pipe should not be called on resolve" );
jQuery.Deferred().resolve().then( null, function() {
ok( false, "then should not be called on resolve" );
} );
jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) {
strictEqual( value, undefined, "pipe fail callback can return undefined/null" );
jQuery.Deferred().reject().then( null, jQuery.noop ).fail(function( value ) {
strictEqual( value, undefined, "then fail callback can return undefined/null" );
});
});
test( "jQuery.Deferred.pipe - filtering (progress)", function() {
test( "jQuery.Deferred.then - filtering (progress)", function() {
expect(3);
var defer = jQuery.Deferred(),
piped = defer.pipe( null, null, function( a, b ) {
piped = defer.then( null, null, function( a, b ) {
return a * b;
} ),
value1,
@@ -169,12 +173,12 @@ test( "jQuery.Deferred.pipe - filtering (progress)", function() {
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.pipe - deferred (done)", function() {
test( "jQuery.Deferred.then - deferred (done)", function() {
expect(3);
var defer = jQuery.Deferred(),
piped = defer.pipe(function( a, b ) {
piped = defer.then(function( a, b ) {
return jQuery.Deferred(function( defer ) {
defer.reject( a * b );
});
@@ -199,12 +203,12 @@ test( "jQuery.Deferred.pipe - deferred (done)", function() {
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.pipe - deferred (fail)", function() {
test( "jQuery.Deferred.then - deferred (fail)", function() {
expect(3);
var defer = jQuery.Deferred(),
piped = defer.pipe( null, function( a, b ) {
piped = defer.then( null, function( a, b ) {
return jQuery.Deferred(function( defer ) {
defer.resolve( a * b );
});
@@ -229,12 +233,12 @@ test( "jQuery.Deferred.pipe - deferred (fail)", function() {
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.pipe - deferred (progress)", function() {
test( "jQuery.Deferred.then - deferred (progress)", function() {
expect(3);
var defer = jQuery.Deferred(),
piped = defer.pipe( null, null, function( a, b ) {
piped = defer.then( null, null, function( a, b ) {
return jQuery.Deferred(function( defer ) {
defer.resolve( a * b );
});
@@ -259,13 +263,13 @@ test( "jQuery.Deferred.pipe - deferred (progress)", function() {
strictEqual( value3, 6, "result of filter ok" );
});
test( "jQuery.Deferred.pipe - context", function() {
test( "jQuery.Deferred.then - context", function() {
expect(4);
var context = {};
jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) {
jQuery.Deferred().resolveWith( context, [ 2 ] ).then(function( value ) {
return value * 3;
}).done(function( value ) {
strictEqual( this, context, "custom context correctly propagated" );
@@ -273,7 +277,7 @@ test( "jQuery.Deferred.pipe - context", function() {
});
var defer = jQuery.Deferred(),
piped = defer.pipe(function( value ) {
piped = defer.then(function( value ) {
return value * 3;
});

View File

@@ -230,12 +230,13 @@ test("outerWidth()", function() {
jQuery.removeData($div[0], "olddisplay", true);
});
test("child of a hidden elem has accurate inner/outer/Width()/Height() see #9441 #9300", function() {
expect(8);
test("child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function() {
expect(16);
// setup html
var $divNormal = jQuery("<div>").css({ width: "100px", height: "100px", border: "10px solid white", padding: "2px", margin: "3px" }),
$divChild = $divNormal.clone(),
var $divNormal = jQuery("<div>").css({ width: "100px", height: "100px", border: "10px solid white", padding: "2px", margin: "3px" }),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
$divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body");
$divNormal.appendTo("body");
@@ -250,6 +251,17 @@ test("child of a hidden elem has accurate inner/outer/Width()/Height() see #944
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
// tests that child div of an unconnected div works the same as a normal div
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #9441" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" );
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #9441" );
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #9441" );
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #9441" );
equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
@@ -278,6 +290,43 @@ test("getting dimensions shouldnt modify runtimeStyle see #9233", function() {
$div.remove();
});
test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function() {
expect(16);
// setup html
var $divNormal = jQuery("<div>").css({ boxSizing: "border-box", width: "100px", height: "100px", border: "10px solid white", padding: "2px", margin: "3px" }),
$divChild = $divNormal.clone(),
$divUnconnected = $divNormal.clone(),
$divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body");
$divNormal.appendTo("body");
// tests that child div of a hidden div works the same as a normal div
equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" );
equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" );
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #10413" );
equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #10413" );
equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #10413" );
equal( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
// tests that child div of an unconnected div works the same as a normal div
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #10413" );
equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #10413" );
equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #10413" );
equal( $divUnconnected.outerHeight(true), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
});
test("outerHeight()", function() {
expect(11);

View File

@@ -263,6 +263,15 @@ test("animate negative height", function() {
});
});
test("animate negative margin", function() {
expect(1);
stop();
jQuery("#foo").animate({ marginTop: -100 }, 100, function() {
equal( jQuery(this).css("marginTop"), "-100px", "Verify margin." );
start();
});
});
test("animate negative padding", function() {
expect(1);
stop();

View File

@@ -2867,4 +2867,15 @@ test("fixHooks extensions", function() {
})();
asyncTest("trigger click on checkbox, fires change event", function() {
expect(1);
var check = jQuery("#check2");
check.on( "change", function() {
// get it?
check.off("change");
ok( true, "Change event fired as a result of triggered click" );
start();
}).trigger("click");
});

View File

@@ -555,6 +555,28 @@ test("html(String) with HTML5 (Bug #6485)", function() {
equal( jQuery("#qunit-fixture").children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." );
});
test("IE8 serialization bug", function () {
expect(2);
var wrapper = jQuery("<div></div>");
wrapper.html("<div></div><article></article>");
equal( wrapper.children("article").length, 1, "HTML5 elements are insertable with .html()");
wrapper.html("<div></div><link></link>");
equal( wrapper.children("link").length, 1, "Link elements are insertable with .html()");
});
test("html() object element #10324", function() {
expect( 1 );
var object = jQuery("<object id='object2'><param name='object2test' value='test'></param></object>?").appendTo("#qunit-fixture"),
clone = object.clone();
equal( clone.html(), object.html(), "html() returns correct innerhtml of cloned object elements" );
});
test("append(xml)", function() {
expect( 1 );
@@ -902,7 +924,7 @@ test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
});
var testReplaceWith = function(val) {
expect(21);
expect(22);
jQuery("#yahoo").replaceWith(val( "<b id='replace'>buga</b>" ));
ok( jQuery("#replace")[0], "Replace element with string" );
ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after string" );
@@ -963,6 +985,9 @@ var testReplaceWith = function(val) {
equal( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." );
equal( set.length, 1, "Replace the disconnected node." );
// #11338
ok( jQuery("<div>1</div>").replaceWith( val("<span/>") ).is("span"), "#11338, Make sure disconnected node with content is replaced");
var non_existant = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") );
equal( non_existant.length, 0, "Length of non existant element." );
@@ -993,7 +1018,7 @@ test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
test("replaceWith(Function)", function() {
testReplaceWith(functionReturningObj);
expect(22);
expect(23);
var y = jQuery("#yahoo")[0];
@@ -1220,22 +1245,17 @@ test("clone(multiple selected options) (Bug #8129)", function() {
});
if (!isLocal) {
test("clone() on XML nodes", function() {
expect(2);
stop();
jQuery.get("data/dashboard.xml", function (xml) {
var root = jQuery(xml.documentElement).clone();
var origTab = jQuery("tab", xml).eq(0);
var cloneTab = jQuery("tab", root).eq(0);
origTab.text("origval");
cloneTab.text("cloneval");
equal(origTab.text(), "origval", "Check original XML node was correctly set");
equal(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
start();
});
var xml = createDashboardXML();
var root = jQuery(xml.documentElement).clone();
var origTab = jQuery("tab", xml).eq(0);
var cloneTab = jQuery("tab", root).eq(0);
origTab.text("origval");
cloneTab.text("cloneval");
equal(origTab.text(), "origval", "Check original XML node was correctly set");
equal(cloneTab.text(), "cloneval", "Check cloned XML node was correctly set");
});
}
test("clone() on local XML nodes with html5 nodename", function() {
expect(2);
@@ -1755,4 +1775,12 @@ test("Guard against exceptions when clearing safeChildNodes", function() {
} catch(e) {}
ok( div && div.jquery, "Created nodes safely, guarded against exceptions on safeChildNodes[ -1 ]" );
});
});
test("Ensure oldIE creates a new set on appendTo (#8894)", function() {
strictEqual( jQuery("<div/>").clone().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.clone" );
strictEqual( jQuery("<div/>").find("p").end().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.find" );
strictEqual( jQuery("<div/>").text("test").addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after jQuery.fn.text" );
strictEqual( jQuery("<bdi/>").clone().addClass("test").appendTo("<div/>").end().hasClass("test"), false, "Check jQuery.fn.appendTo after clone html5 element" );
strictEqual( jQuery("<p/>").appendTo("<div/>").end().length, jQuery("<p>test</p>").appendTo("<div/>").end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" );
});

View File

@@ -98,10 +98,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotAddBorder":true,
"doesAddBorderForTableAndCells":false,
"fixedPosition":true,
"subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -141,10 +137,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
"doesNotAddBorder":false,
"doesAddBorderForTableAndCells":true,
"fixedPosition":true,
"subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -164,11 +156,8 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"cors": false,
"cssFloat": false,
"deleteExpando": false,
"doesAddBorderForTableAndCells": true,
"doesNotAddBorder": true,
"doesNotIncludeMarginInBodyOffset": true,
"enctype": true,
"fixedPosition": true,
"focusinBubbles": true,
"getSetAttribute": false,
"hrefNormalized": false,
@@ -186,7 +175,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableMarginRight": true,
"shrinkWrapBlocks": false,
"submitBubbles": false,
"subtractsBorderForOverflowNotVisible": false,
"tbody": false,
"style": false
};
@@ -227,10 +215,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
"doesNotAddBorder":true,
"doesAddBorderForTableAndCells":true,
"fixedPosition":false,
"subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -270,10 +254,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotAddBorder":true,
"doesAddBorderForTableAndCells":false,
"fixedPosition":true,
"subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {
@@ -313,10 +293,6 @@ if ( /chrome\/16\.0/i.test(userAgent) ) {
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
"doesNotAddBorder":true,
"doesAddBorderForTableAndCells":true,
"fixedPosition":true,
"subtractsBorderForOverflowNotVisible":false,
"doesNotIncludeMarginInBodyOffset":true
};
for ( i in expected ) {

View File

@@ -370,21 +370,27 @@ test("not(jQuery)", function() {
});
test("has(Element)", function() {
expect(2);
expect(3);
var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
var detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
});
test("has(Selector)", function() {
expect(3);
expect(4);
var obj = jQuery("#qunit-fixture").has("#sndp");
deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
var detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
@@ -393,11 +399,14 @@ test("has(Selector)", function() {
});
test("has(Arrayish)", function() {
expect(3);
expect(4);
var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
var detached = jQuery("<a><b><i/></b></a>");
deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );