" ).appendTo( "#qunit-fixture" ),
@@ -331,9 +360,9 @@ QUnit.test( "getting dimensions shouldn't modify runtimeStyle see #9233", functi
$div.outerWidth( true );
if ( runtimeStyle ) {
- assert.equal( div.runtimeStyle.left, "11em", "getting dimensions modifies runtimeStyle, see #9233" );
+ assert.equal( div.runtimeStyle.left, "11em", "getting dimensions modifies runtimeStyle, see trac-9233" );
} else {
- assert.ok( true, "this browser doesn't support runtimeStyle, see #9233" );
+ assert.ok( true, "this browser doesn't support runtimeStyle, see trac-9233" );
}
$div.remove();
@@ -342,14 +371,14 @@ QUnit.test( "getting dimensions shouldn't modify runtimeStyle see #9233", functi
QUnit.test( "table dimensions", function( assert ) {
assert.expect( 2 );
- var table = jQuery( "
" ).appendTo( "#qunit-fixture" ),
tdElem = table.find( "td" ).first(),
colElem = table.find( "col" ).first().width( 300 );
table.find( "td" ).css( { "margin": 0, "padding": 0 } );
- assert.equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see #11293" );
- assert.equal( colElem.width(), 300, "col elements have width(), see #12243" );
+ assert.equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see trac-11293" );
+ assert.equal( colElem.width(), 300, "col elements have width(), see trac-12243" );
} );
QUnit.test( "SVG dimensions (basic content-box)", function( assert ) {
@@ -412,7 +441,7 @@ QUnit.test( "SVG dimensions (border-box)", function( assert ) {
svg.remove();
} );
-QUnit.test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) {
+QUnit.test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see trac-10413", function( assert ) {
assert.expect( 16 );
// setup html
@@ -423,38 +452,38 @@ QUnit.test( "box-sizing:border-box child of a hidden elem (or unconnected node)
$divNormal.appendTo( "body" );
// tests that child div of a hidden div works the same as a normal div
- assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" );
- assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" );
- assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
- assert.equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
+ assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see trac-10413" );
+ assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see trac-10413" );
+ assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see trac-10413" );
+ assert.equal( $divChild.outerWidth( true ), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see trac-10413" );
- assert.equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #10413" );
- assert.equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #10413" );
- assert.equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #10413" );
- assert.equal( $divChild.outerHeight( true ), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
+ assert.equal( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see trac-10413" );
+ assert.equal( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see trac-10413" );
+ assert.equal( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see trac-10413" );
+ assert.equal( $divChild.outerHeight( true ), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see trac-10413" );
// tests that child div of an unconnected div works the same as a normal div
- assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
- assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" );
- assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
- assert.equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
+ assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see trac-10413" );
+ assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see trac-10413" );
+ assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see trac-10413" );
+ assert.equal( $divUnconnected.outerWidth( true ), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see trac-10413" );
- assert.equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see #10413" );
- assert.equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see #10413" );
- assert.equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see #10413" );
- assert.equal( $divUnconnected.outerHeight( true ), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
+ assert.equal( $divUnconnected.height(), $divNormal.height(), "unconnected element height() is wrong see trac-10413" );
+ assert.equal( $divUnconnected.innerHeight(), $divNormal.innerHeight(), "unconnected element innerHeight() is wrong see trac-10413" );
+ assert.equal( $divUnconnected.outerHeight(), $divNormal.outerHeight(), "unconnected element outerHeight() is wrong see trac-10413" );
+ assert.equal( $divUnconnected.outerHeight( true ), $divNormal.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see trac-10413" );
// teardown html
$divHiddenParent.remove();
$divNormal.remove();
} );
-QUnit.test( "passing undefined is a setter #5571", function( assert ) {
+QUnit.test( "passing undefined is a setter trac-5571", function( assert ) {
assert.expect( 4 );
- assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).height( undefined ).height(), 30, ".height(undefined) is chainable (#5571)" );
- assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).innerHeight( undefined ).height(), 30, ".innerHeight(undefined) is chainable (#5571)" );
- assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).outerHeight( undefined ).height(), 30, ".outerHeight(undefined) is chainable (#5571)" );
- assert.equal( jQuery( "#nothiddendiv" ).width( 30 ).width( undefined ).width(), 30, ".width(undefined) is chainable (#5571)" );
+ assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).height( undefined ).height(), 30, ".height(undefined) is chainable (trac-5571)" );
+ assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).innerHeight( undefined ).height(), 30, ".innerHeight(undefined) is chainable (trac-5571)" );
+ assert.equal( jQuery( "#nothiddendiv" ).height( 30 ).outerHeight( undefined ).height(), 30, ".outerHeight(undefined) is chainable (trac-5571)" );
+ assert.equal( jQuery( "#nothiddendiv" ).width( 30 ).width( undefined ).width(), 30, ".width(undefined) is chainable (trac-5571)" );
} );
QUnit.test( "setters with and without box-sizing:border-box", function( assert ) {
@@ -536,7 +565,7 @@ QUnit.test( "allow modification of coordinates argument (gh-1848)", function( as
assert.expect( 1 );
var offsetTop,
- element = jQuery( "
" ).appendTo( "#qunit-fixture" );
element.offset( function( index, coords ) {
coords.top = 100;
@@ -583,7 +612,7 @@ QUnit.test( "width/height on element with transform (gh-3193)", function( assert
assert.expect( 2 );
- var $elem = jQuery( "
" )
.appendTo( "#qunit-fixture" );
assert.equal( $elem.width(), 200, "Width ignores transforms" );
@@ -627,7 +656,8 @@ QUnit.test( "width/height on an inline element with percentage dimensions (gh-36
}
);
-QUnit.test( "width/height on a table row with phantom borders (gh-3698)", function( assert ) {
+QUnit.test(
+ "width/height on a table row with phantom borders (gh-3698)", function( assert ) {
assert.expect( 4 );
jQuery( "
" +
@@ -656,16 +686,16 @@ QUnit.test( "interaction with scrollbars (gh-3589)", function( assert ) {
return old + adjustment;
};
},
- parent = jQuery( "
" )
+ parent = jQuery( "
" )
.css( { position: "absolute", width: "1000px", height: "1000px" } )
.appendTo( "#qunit-fixture" ),
- fraction = jQuery.support.boxSizingReliable() ?
- jQuery( "
" ).appendTo( parent ).width() % 1 :
- 0,
+
+ // Workarounds for IE kill fractional output here.
+ fraction = document.documentMode ? 0 : 0.5,
borderWidth = 1,
padding = 2,
size = 100 + fraction,
- plainBox = jQuery( "
" )
+ plainBox = jQuery( "
" )
.css( {
"box-sizing": "content-box",
position: "absolute",
@@ -687,19 +717,7 @@ QUnit.test( "interaction with scrollbars (gh-3589)", function( assert ) {
.css( { position: "relative" } ),
$boxes = jQuery(
[ plainBox[ 0 ], contentBox[ 0 ], borderBox[ 0 ], relativeBorderBox[ 0 ] ]
- ).appendTo( parent ),
-
- // Support: IE 9 only
- // Computed width seems to report content width even with "box-sizing: border-box", and
- // "overflow: scroll" actually _shrinks_ the element (gh-3699).
- borderBoxLoss =
- borderBox.clone().css( { overflow: "auto" } ).appendTo( parent )[ 0 ].offsetWidth -
- borderBox[ 0 ].offsetWidth;
-
- if ( borderBoxLoss > 0 ) {
- borderBox[ 0 ].style.width = ( size + borderBoxLoss ) + "px";
- borderBox[ 0 ].style.height = ( size + borderBoxLoss ) + "px";
- }
+ ).appendTo( parent );
for ( i = 0; i < 3; i++ ) {
if ( i === 1 ) {
@@ -752,41 +770,29 @@ QUnit.test( "interaction with scrollbars (gh-3589)", function( assert ) {
QUnit.test( "outerWidth/Height for table cells and textarea with border-box in IE 11 (gh-4102)", function( assert ) {
assert.expect( 5 );
- var $table = jQuery( "" ).appendTo( "#qunit-fixture" ),
- $thead = jQuery( " " ).appendTo( $table ),
- $firstTh = jQuery( " " ),
- $secondTh = jQuery( " " ),
- $thirdTh = jQuery( " " ),
-
- // Support: Firefox 63, Edge 16-17, Android 8, iOS 7-11
- // These browsers completely ignore the border-box and height settings
- // The computed height is instead just line-height + border
- // Either way, what we're doing in css.js is correct
+ var $table = jQuery( "" ).appendTo( "#qunit-fixture" ),
+ $thead = jQuery( " " ).appendTo( $table ),
+ $firstTh = jQuery( " " ),
+ $secondTh = jQuery( " " ),
+ $thirdTh = jQuery( " " ),
+
+ // Most browsers completely ignore the border-box and height settings.
+ // The computed height is instead just line-height + border.
+ // Either way, what we're doing in css.js is correct.
$td = jQuery( "text " ),
- $tbody = jQuery( " " ).appendTo( $table ),
- $textarea = jQuery( "" ).appendTo( "#qunit-fixture" );
+ $tbody = jQuery( " " ).appendTo( $table ),
+ $textarea = jQuery( "" ).appendTo( "#qunit-fixture" );
- jQuery( " " ).appendTo( $thead ).append( $firstTh );
- jQuery( " " ).appendTo( $thead ).append( $secondTh );
- jQuery( " " ).appendTo( $thead ).append( $thirdTh );
+ jQuery( " " ).appendTo( $thead ).append( $firstTh );
+ jQuery( " " ).appendTo( $thead ).append( $secondTh );
+ jQuery( " " ).appendTo( $thead ).append( $thirdTh );
jQuery( " " ).appendTo( $tbody ).append( $td );
assert.strictEqual( $firstTh.outerWidth(), 200, "First th has outerWidth 200." );
assert.strictEqual( $secondTh.outerWidth(), 200, "Second th has outerWidth 200." );
assert.strictEqual( $thirdTh.outerWidth(), 200, "Third th has outerWidth 200." );
-
- // Support: Android 4.0-4.3 only
- // Android Browser disregards td's box-sizing, treating it like it was content-box.
- // Unlike in IE, offsetHeight shares the same issue so there's no easy way to workaround
- // the issue without incurring high size penalty. Let's at least check we get the size
- // as the browser sees it.
- if ( /android 4\.[0-3]/i.test( navigator.userAgent ) ) {
- assert.ok( [ 30, 32 ].indexOf( $td.outerHeight() ) > -1,
- "outerHeight of td with border-box should include padding." );
- } else {
- assert.strictEqual( $td.outerHeight(), 30, "outerHeight of td with border-box should include padding." );
- }
+ assert.strictEqual( $td.outerHeight(), 30, "outerHeight of td with border-box should include padding." );
assert.strictEqual( $textarea.outerHeight(), 6, "outerHeight of textarea with border-box should include padding and border." );
} );
diff --git a/test/unit/effects.js b/test/unit/effects.js
index f71eafb62c..8f6492124e 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -1,35 +1,37 @@
( function() {
// Can't test what ain't there
-if ( !jQuery.fx ) {
+if ( !includesModule( "effects" ) ) {
return;
}
-var oldRaf = window.requestAnimationFrame,
+var fxInterval = 13,
+ oldRaf = window.requestAnimationFrame,
hideOptions = {
- inline: function() { jQuery.style( this, "display", "none" ); },
- cascade: function() { this.className = "hidden"; }
+ inline: function() {
+ jQuery.style( this, "display", "none" );
+ },
+ cascade: function() {
+ this.className = "hidden";
+ }
};
QUnit.module( "effects", {
beforeEach: function() {
- window.requestAnimationFrame = null;
- this.sandbox = sinon.sandbox.create();
+ this.sandbox = sinon.createSandbox();
this.clock = this.sandbox.useFakeTimers( 505877050 );
- this._oldInterval = jQuery.fx.interval;
+ window.requestAnimationFrame = null;
jQuery.fx.step = {};
- jQuery.fx.interval = 10;
},
afterEach: function() {
this.sandbox.restore();
jQuery.fx.stop();
- jQuery.fx.interval = this._oldInterval;
window.requestAnimationFrame = oldRaf;
return moduleTeardown.apply( this, arguments );
}
} );
-QUnit[ jQuery.find.compile ? "test" : "skip" ]( "sanity check", function( assert ) {
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "sanity check", function( assert ) {
assert.expect( 1 );
assert.equal( jQuery( "#qunit-fixture:visible, #foo:visible" ).length, 2, "QUnit state is correct for testing effects" );
} );
@@ -90,9 +92,6 @@ QUnit.test( "show()", function( assert ) {
assert.ok( pass, "Show with " + name + " does not call animate callback" );
} );
- // Tolerate data from show()/hide()
- assert.expectJqData( this, div, "olddisplay" );
-
jQuery(
"" +
"
" +
@@ -144,7 +143,7 @@ supportjQuery.each( hideOptions, function( type, setup ) {
// Note: inline elements are expected to be inline-block
// because we're showing width/height
// Can't animate width/height inline
- // See #14344
+ // See trac-14344
var test = {
"div": "block",
"p": "block",
@@ -163,9 +162,9 @@ supportjQuery.each( hideOptions, function( type, setup ) {
};
jQuery.each( test, function( selector ) {
- jQuery( selector, "#show-tests" ).show( 100 );
+ jQuery( selector, "#show-tests" ).show( fxInterval * 10 );
} );
- this.clock.tick( 50 );
+ this.clock.tick( fxInterval * 5 );
jQuery.each( test, function( selector, expected ) {
jQuery( selector, "#show-tests" ).each( function() {
assert.equal(
@@ -175,7 +174,7 @@ supportjQuery.each( hideOptions, function( type, setup ) {
);
} );
} );
- this.clock.tick( 50 );
+ this.clock.tick( fxInterval * 5 );
jQuery.each( test, function( selector, expected ) {
jQuery( selector, "#show-tests" ).each( function() {
assert.equal( jQuery( this ).css( "display" ), expected,
@@ -187,7 +186,7 @@ supportjQuery.each( hideOptions, function( type, setup ) {
} );
} );
-// Supports #7397
+// Supports trac-7397
supportjQuery.each( hideOptions, function( type, setup ) {
QUnit.test( "Persist correct display value - " + type + " hidden", function( assert ) {
assert.expect( 3 );
@@ -206,22 +205,22 @@ supportjQuery.each( hideOptions, function( type, setup ) {
$span.hide();
- $span.fadeIn( 100, function() {
+ $span.fadeIn( fxInterval * 10, function() {
assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
- $span.fadeOut( 100, function() {
+ $span.fadeOut( fxInterval * 10, function() {
assert.equal( $span.css( "display" ), displayNone, "Expecting display: " + displayNone );
- $span.fadeIn( 100, function() {
+ $span.fadeIn( fxInterval * 10, function() {
assert.equal( $span.css( "display" ), display, "Expecting display: " + display );
} );
} );
} );
- clock.tick( 300 );
-
- assert.expectJqData( this, $span, "olddisplay" );
+ clock.tick( fxInterval * 30 );
} );
- QUnit[ document.body.attachShadow ? "test" : "skip" ](
+ // Support: IE 11+
+ // IE doesn't support Shadow DOM.
+ QUnit.testUnlessIE(
"Persist correct display value - " + type + " hidden, shadow child", function( assert ) {
assert.expect( 3 );
@@ -238,19 +237,17 @@ supportjQuery.each( hideOptions, function( type, setup ) {
var display = "inline";
var clock = this.clock;
- $shadowChild.fadeIn( 100, function() {
+ $shadowChild.fadeIn( fxInterval * 10, function() {
assert.equal( $shadowChild.css( "display" ), display, "Expecting shadow display: " + display );
- $shadowChild.fadeOut( 100, function() {
+ $shadowChild.fadeOut( fxInterval * 10, function() {
assert.equal( $shadowChild.css( "display" ), displayNone, "Expecting shadow display: " + displayNone );
- $shadowChild.fadeIn( 100, function() {
+ $shadowChild.fadeIn( fxInterval * 10, function() {
assert.equal( $shadowChild.css( "display" ), display, "Expecting shadow display: " + display );
} );
} );
} );
- clock.tick( 300 );
-
- assert.expectJqData( this, $shadowChild, "olddisplay" );
+ clock.tick( fxInterval * 30 );
} );
} );
@@ -289,7 +286,7 @@ QUnit.test( "animate relative values", function( assert ) {
baseScale = elem[ 0 ].offsetHeight / value,
adjustScale = elem[ 0 ].offsetWidth / value;
- elem.css( "width", base ).animate( adjust, 100, function() {
+ elem.css( "width", base ).animate( adjust, fxInterval * 10, function() {
assert.equal( this.offsetHeight, value * baseScale + 2 * adjustScale,
baseUnit + "+=" + adjustUnit );
assert.equal( this.offsetWidth, value * baseScale - 2 * adjustScale,
@@ -297,52 +294,52 @@ QUnit.test( "animate relative values", function( assert ) {
} );
- clock.tick( 100 );
+ clock.tick( fxInterval * 10 );
} );
} );
} );
QUnit.test( "animate negative height", function( assert ) {
assert.expect( 1 );
- jQuery( "#foo" ).animate( { height: -100 }, 100, function() {
+ jQuery( "#foo" ).animate( { height: -100 }, fxInterval * 10, function() {
assert.equal( this.offsetHeight, 0, "Verify height." );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate negative margin", function( assert ) {
assert.expect( 1 );
- jQuery( "#foo" ).animate( { "marginTop": -100 }, 100, function() {
+ jQuery( "#foo" ).animate( { "marginTop": -100 }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate negative margin with px", function( assert ) {
assert.expect( 1 );
- jQuery( "#foo" ).animate( { marginTop: "-100px" }, 100, function() {
+ jQuery( "#foo" ).animate( { marginTop: "-100px" }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "marginTop" ), "-100px", "Verify margin." );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate negative padding", function( assert ) {
assert.expect( 1 );
- jQuery( "#foo" ).animate( { "paddingBottom": -100 }, 100, function() {
+ jQuery( "#foo" ).animate( { "paddingBottom": -100 }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "paddingBottom" ), "0px", "Verify paddingBottom." );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate block as inline width/height", function( assert ) {
assert.expect( 3 );
- jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, 100, function() {
+ jQuery( "#foo" ).css( { display: "inline", width: "", height: "" } ).animate( { width: 42, height: 42 }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
assert.equal( this.offsetWidth, 42, "width was animated" );
assert.equal( this.offsetHeight, 42, "height was animated" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate native inline width/height", function( assert ) {
@@ -351,12 +348,12 @@ QUnit.test( "animate native inline width/height", function( assert ) {
jQuery( "#foo" ).css( { display: "", width: "", height: "" } )
.append( "
text " )
.children( "span" )
- .animate( { width: 42, height: 42 }, 100, function() {
+ .animate( { width: 42, height: 42 }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "display" ), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
assert.equal( this.offsetWidth, 42, "width was animated" );
assert.equal( this.offsetHeight, 42, "height was animated" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate block width/height", function( assert ) {
@@ -371,7 +368,7 @@ QUnit.test( "animate block width/height", function( assert ) {
width: 42,
height: 42
}, {
- duration: 100,
+ duration: fxInterval * 10,
step: function() {
if ( jQuery( this ).width() > 42 ) {
assert.ok( false, "width was incorrectly augmented during animation" );
@@ -383,16 +380,16 @@ QUnit.test( "animate block width/height", function( assert ) {
assert.equal( jQuery( this ).height(), 42, "height was animated" );
}
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate table width/height", function( assert ) {
assert.expect( 1 );
- jQuery( "#table" ).animate( { width: 42, height: 42 }, 100, function() {
+ jQuery( "#table" ).animate( { width: 42, height: 42 }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "display" ), "table", "display mode is correct" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate table-row width/height", function( assert ) {
@@ -402,12 +399,12 @@ QUnit.test( "animate table-row width/height", function( assert ) {
.html( "
" )
.find( "tr" );
- tr.animate( { width: 10, height: 10 }, 100, function() {
+ tr.animate( { width: 10, height: 10 }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "display" ), "table-row", "display mode is correct" );
assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate table-cell width/height", function( assert ) {
@@ -418,12 +415,12 @@ QUnit.test( "animate table-cell width/height", function( assert ) {
.html( "
" )
.find( "td" );
- td.animate( { width: 10, height: 10 }, 100, function() {
+ td.animate( { width: 10, height: 10 }, fxInterval * 10, function() {
assert.equal( jQuery( this ).css( "display" ), "table-cell", "display mode is correct" );
assert.equal( this.offsetWidth, 20, "width animated to shrink wrap point" );
assert.equal( this.offsetHeight, 20, "height animated to shrink wrap point" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate percentage(%) on width/height", function( assert ) {
@@ -432,46 +429,25 @@ QUnit.test( "animate percentage(%) on width/height", function( assert ) {
var $div = jQuery( "
" )
.appendTo( "#qunit-fixture" ).children( "div" );
- $div.animate( { width: "25%", height: "25%" }, 13, function() {
+ $div.animate( { width: "25%", height: "25%" }, fxInterval, function() {
var $this = jQuery( this );
assert.equal( $this.css( "width" ), "15px", "Width was animated to 15px rather than 25px" );
assert.equal( $this.css( "height" ), "15px", "Height was animated to 15px rather than 25px" );
} );
- this.clock.tick( 20 );
+ this.clock.tick( fxInterval * 1.5 );
} );
QUnit.test( "animate resets overflow-x and overflow-y when finished", function( assert ) {
assert.expect( 2 );
jQuery( "#foo" )
.css( { display: "block", width: 20, height: 20, overflowX: "visible", overflowY: "auto" } )
- .animate( { width: 42, height: 42 }, 100, function() {
+ .animate( { width: 42, height: 42 }, fxInterval * 10, function() {
assert.equal( this.style.overflowX, "visible", "overflow-x is visible" );
assert.equal( this.style.overflowY, "auto", "overflow-y is auto" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
-/* // This test ends up being flaky depending upon the CPU load
-QUnit.test("animate option (queue === false)", function( assert ) {
- var done = assert.async();
- assert.expect(1);
-
- var order = [];
-
- var $foo = jQuery("#foo");
- $foo.animate({width:"100px"}, 3000, function () {
- // should finish after unqueued animation so second
- order.push(2);
- assert.deepEqual( order, [ 1, 2 ], "Animations finished in the correct order" );
- done();
- });
- $foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
- // short duration and out of queue so should finish first
- order.push(1);
- }});
-});
-*/
-
QUnit.test( "animate option { queue: false }", function( assert ) {
assert.expect( 2 );
var foo = jQuery( "#foo" );
@@ -480,12 +456,12 @@ QUnit.test( "animate option { queue: false }", function( assert ) {
fontSize: "2em"
}, {
queue: false,
- duration: 10,
+ duration: fxInterval,
complete: function() {
assert.ok( true, "Animation Completed" );
}
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
assert.equal( foo.queue().length, 0, "Queue is empty" );
} );
@@ -498,7 +474,7 @@ QUnit.test( "animate option { queue: true }", function( assert ) {
fontSize: "2em"
}, {
queue: true,
- duration: 10,
+ duration: fxInterval,
complete: function() {
assert.ok( true, "Animation Completed" );
}
@@ -507,7 +483,7 @@ QUnit.test( "animate option { queue: true }", function( assert ) {
assert.notEqual( foo.queue().length, 0, "Default queue is not empty" );
//clear out existing timers before next test
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
QUnit.test( "animate option { queue: 'name' }", function( assert ) {
@@ -538,7 +514,7 @@ QUnit.test( "animate option { queue: 'name' }", function( assert ) {
assert.equal( foo.queue( "name" ).length, 2, "Queue length of 'name' queue" );
foo.dequeue( "name" );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
@@ -558,22 +534,22 @@ QUnit.test( "animate with no properties", function( assert ) {
foo = jQuery( "#foo" );
foo.animate( {} );
- foo.animate( { top: 10 }, 100, function() {
+ foo.animate( { top: 10 }, fxInterval * 10, function() {
assert.ok( true, "Animation was properly dequeued." );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
QUnit.test( "animate duration 0", function( assert ) {
assert.expect( 11 );
var $elem,
- $elems = jQuery( [ { a:0 }, { a:0 } ] ),
+ $elems = jQuery( [ { a: 0 }, { a: 0 } ] ),
counter = 0;
assert.equal( jQuery.timers.length, 0, "Make sure no animation was running from another test" );
- $elems.eq( 0 ).animate( { a:1 }, 0, function() {
+ $elems.eq( 0 ).animate( { a: 1 }, 0, function() {
assert.ok( true, "Animate a simple property." );
counter++;
} );
@@ -583,26 +559,26 @@ QUnit.test( "animate duration 0", function( assert ) {
assert.equal( counter, 1, "One synchronic animations" );
- $elems.animate( { a:2 }, 0, function() {
+ $elems.animate( { a: 2 }, 0, function() {
assert.ok( true, "Animate a second simple property." );
counter++;
} );
assert.equal( counter, 3, "Multiple synchronic animations" );
- $elems.eq( 0 ).animate( { a:3 }, 0, function() {
+ $elems.eq( 0 ).animate( { a: 3 }, 0, function() {
assert.ok( true, "Animate a third simple property." );
counter++;
} );
- $elems.eq( 1 ).animate( { a:3 }, 200, function() {
+ $elems.eq( 1 ).animate( { a: 3 }, fxInterval * 20, function() {
counter++;
// Failed until [6115]
assert.equal( counter, 5, "One synchronic and one asynchronic" );
} );
- this.clock.tick( 200 );
+ this.clock.tick( fxInterval * 20 );
- $elem = jQuery( "
" );
+ $elem = jQuery( "
" );
$elem.show( 0, function() {
assert.ok( true, "Show callback with no duration" );
} );
@@ -619,12 +595,12 @@ QUnit.test( "animate hyphenated properties", function( assert ) {
jQuery( "#foo" )
.css( "font-size", 10 )
- .animate( { "font-size": 20 }, 200, function() {
+ .animate( { "font-size": 20 }, fxInterval * 20, function() {
assert.equal( this.style.fontSize, "20px", "The font-size property was animated." );
} );
// FIXME why is this double only when run with other tests
- this.clock.tick( 400 );
+ this.clock.tick( fxInterval * 40 );
} );
@@ -633,10 +609,10 @@ QUnit.test( "animate non-element", function( assert ) {
var obj = { test: 0 };
- jQuery( obj ).animate( { test: 200 }, 200, function() {
+ jQuery( obj ).animate( { test: 200 }, fxInterval * 20, function() {
assert.equal( obj.test, 200, "The custom property should be modified." );
} );
- this.clock.tick( 200 );
+ this.clock.tick( fxInterval * 20 );
} );
QUnit.test( "animate non-element's zIndex without appending \"px\"", function( assert ) {
@@ -644,10 +620,10 @@ QUnit.test( "animate non-element's zIndex without appending \"px\"", function( a
var obj = { zIndex: 0 };
- jQuery( obj ).animate( { zIndex: 200 }, 200, function() {
+ jQuery( obj ).animate( { zIndex: 200 }, fxInterval * 20, function() {
assert.equal( obj.zIndex, 200, "The custom property should be modified without appending \"px\"." );
} );
- this.clock.tick( 200 );
+ this.clock.tick( fxInterval * 20 );
} );
QUnit.test( "stop()", function( assert ) {
@@ -659,9 +635,9 @@ QUnit.test( "stop()", function( assert ) {
nw;
$foo.hide().css( "width", 200 )
- .animate( { "width": "show" }, 1500 );
+ .animate( { "width": "show" }, fxInterval * 150 );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
nw = $foo.css( "width" );
assert.notEqual( parseFloat( nw ), w, "An animation occurred " + nw + " " + w + "px" );
$foo.stop();
@@ -669,7 +645,7 @@ QUnit.test( "stop()", function( assert ) {
nw = $foo.css( "width" );
assert.notEqual( parseFloat( nw ), w, "Stop didn't reset the animation " + nw + " " + w + "px" );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
$foo.removeData();
$foo.removeData( undefined, true );
@@ -677,57 +653,48 @@ QUnit.test( "stop()", function( assert ) {
$one = jQuery( "#fadein" );
$two = jQuery( "#show" );
- $one.fadeTo( 100, 0, function() {
+ $one.fadeTo( fxInterval * 10, 0, function() {
$one.stop();
} );
- this.clock.tick( 100 );
- $two.fadeTo( 100, 0, function() {
- assert.equal( $two.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (#6641)" );
+ this.clock.tick( fxInterval * 10 );
+ $two.fadeTo( fxInterval * 10, 0, function() {
+ assert.equal( $two.css( "opacity" ), "0", "Stop does not interfere with animations on other elements (trac-6641)" );
// Reset styles
$one.add( $two ).css( "opacity", "" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
-// In IE9 inside testswarm this test doesn't work properly
-( function() {
- var type = "test";
-
- if ( QUnit.isSwarm && /msie 9\.0/i.test( window.navigator.userAgent ) ) {
- type = "skip";
- }
-
- QUnit[ type ]( "stop() - several in queue", function( assert ) {
- assert.expect( 5 );
+QUnit.test( "stop() - several in queue", function( assert ) {
+ assert.expect( 5 );
- var nw, $foo = jQuery( "#foo" );
+ var nw, $foo = jQuery( "#foo" );
- // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
- $foo.hide().css( "width", 800 );
+ // default duration is 400ms, so 800px ensures we aren't 0 or 1 after 1ms
+ $foo.hide().css( "width", 800 );
- $foo.animate( { "width": "show" }, 400, "linear" );
- $foo.animate( { "width": "hide" } );
- $foo.animate( { "width": "show" } );
+ $foo.animate( { "width": "show" }, 400, "linear" );
+ $foo.animate( { "width": "hide" } );
+ $foo.animate( { "width": "show" } );
- this.clock.tick( 1 );
+ this.clock.tick( 1 );
- jQuery.fx.tick();
- assert.equal( $foo.queue().length, 3, "3 in the queue" );
+ jQuery.fx.tick();
+ assert.equal( $foo.queue().length, 3, "3 in the queue" );
- nw = $foo.css( "width" );
- assert.notEqual( parseFloat( nw ), 1, "An animation occurred " + nw );
- $foo.stop();
+ nw = $foo.css( "width" );
+ assert.notEqual( parseFloat( nw ), 1, "An animation occurred " + nw );
+ $foo.stop();
- assert.equal( $foo.queue().length, 2, "2 in the queue" );
- nw = $foo.css( "width" );
- assert.notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw );
+ assert.equal( $foo.queue().length, 2, "2 in the queue" );
+ nw = $foo.css( "width" );
+ assert.notEqual( parseFloat( nw ), 1, "Stop didn't reset the animation " + nw );
- $foo.stop( true );
+ $foo.stop( true );
- assert.equal( $foo.queue().length, 0, "0 in the queue" );
- } );
-} )();
+ assert.equal( $foo.queue().length, 0, "0 in the queue" );
+} );
QUnit.test( "stop(clearQueue)", function( assert ) {
assert.expect( 4 );
@@ -735,12 +702,12 @@ QUnit.test( "stop(clearQueue)", function( assert ) {
var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css( "width" );
+ $foo.hide().css( "width", fxInterval * 20 ).css( "width" );
- $foo.animate( { "width": "show" }, 1000 );
- $foo.animate( { "width": "hide" }, 1000 );
- $foo.animate( { "width": "show" }, 1000 );
- this.clock.tick( 100 );
+ $foo.animate( { "width": "show" }, fxInterval * 100 );
+ $foo.animate( { "width": "hide" }, fxInterval * 100 );
+ $foo.animate( { "width": "show" }, fxInterval * 100 );
+ this.clock.tick( fxInterval * 10 );
nw = $foo.css( "width" );
assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
$foo.stop( true );
@@ -749,7 +716,7 @@ QUnit.test( "stop(clearQueue)", function( assert ) {
assert.ok( parseFloat( nw ) !== w, "Stop didn't reset the animation " + nw + " " + w + "px" );
assert.equal( $foo.queue().length, 0, "The animation queue was cleared" );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
assert.equal( nw, $foo.css( "width" ), "The animation didn't continue" );
} );
@@ -759,13 +726,13 @@ QUnit.test( "stop(clearQueue, gotoEnd)", function( assert ) {
var $foo = jQuery( "#foo" ),
w = 0,
nw;
- $foo.hide().css( "width", 200 ).css( "width" );
+ $foo.hide().css( "width", fxInterval * 20 ).css( "width" );
- $foo.animate( { width: "show" }, 1000 );
- $foo.animate( { width: "hide" }, 1000 );
- $foo.animate( { width: "show" }, 1000 );
- $foo.animate( { width: "hide" }, 1000 );
- this.clock.tick( 100 );
+ $foo.animate( { width: "show" }, fxInterval * 100 );
+ $foo.animate( { width: "hide" }, fxInterval * 100 );
+ $foo.animate( { width: "show" }, fxInterval * 100 );
+ $foo.animate( { width: "hide" }, fxInterval * 100 );
+ this.clock.tick( fxInterval * 10 );
nw = $foo.css( "width" );
assert.ok( parseFloat( nw ) !== w, "An animation occurred " + nw + " " + w + "px" );
$foo.stop( false, true );
@@ -775,7 +742,7 @@ QUnit.test( "stop(clearQueue, gotoEnd)", function( assert ) {
// Disabled, being flaky
//equal( nw, 1, "Stop() reset the animation" );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
// Disabled, being flaky
//equal( $foo.queue().length, 2, "The next animation continued" );
@@ -790,7 +757,7 @@ QUnit.test( "stop( queue, ..., ... ) - Stop single queues", function( assert ) {
foo.animate( {
width: 400
}, {
- duration: 500,
+ duration: fxInterval * 50,
complete: function() {
assert.equal( parseFloat( foo.css( "width" ) ), 400, "Animation completed for standard queue" );
assert.equal( parseFloat( foo.css( "height" ) ), saved, "Height was not changed after the second stop" );
@@ -800,7 +767,7 @@ QUnit.test( "stop( queue, ..., ... ) - Stop single queues", function( assert ) {
foo.animate( {
height: 400
}, {
- duration: 1000,
+ duration: fxInterval * 100,
queue: "height"
} ).dequeue( "height" ).stop( "height", false, true );
@@ -809,14 +776,14 @@ QUnit.test( "stop( queue, ..., ... ) - Stop single queues", function( assert ) {
foo.animate( {
height: 200
}, {
- duration: 1000,
+ duration: fxInterval * 100,
queue: "height"
} ).dequeue( "height" ).stop( "height", false, false );
saved = parseFloat( foo.css( "height" ) );
- this.clock.tick( 500 );
+ this.clock.tick( fxInterval * 50 );
} );
-QUnit[ jQuery.find.compile ? "test" : "skip" ]( "toggle()", function( assert ) {
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "toggle()", function( assert ) {
assert.expect( 6 );
var x = jQuery( "#foo" );
assert.ok( x.is( ":visible" ), "is visible" );
@@ -846,7 +813,7 @@ QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert ) {
assert.equal(
( new jQuery.fx( div, {}, "color" ) ).cur(),
jQuery.css( div, "color" ),
- "Return the same value as jQuery.css for complex properties (bug #7912)"
+ "Return the same value as jQuery.css for complex properties (bug trac-7912)"
);
assert.strictEqual(
@@ -883,7 +850,7 @@ QUnit.test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", function( assert ) {
assert.equal(
( new jQuery.fx( div, {}, "marginBottom" ) ).cur(),
-11000,
- "support negative values < -10000 (bug #7193)"
+ "support negative values < -10000 (bug trac-7193)"
);
jQuery( div ).remove();
@@ -908,7 +875,7 @@ QUnit.test( "Overflow and Display", function( assert ) {
.before( "text before" )
.after( "text after" )
.animate( { opacity: 0.5 }, "slow", done );
- this.clock.tick( 600 );
+ this.clock.tick( 600 + fxInterval );
} );
jQuery.each( {
@@ -985,21 +952,39 @@ jQuery.each( {
num = 0;
// TODO: uncrowd this
- if ( t_h === "show" ) { num++; }
- if ( t_w === "show" ) { num++; }
- if ( t_w === "hide" || t_w === "show" ) { num++; }
- if ( t_h === "hide" || t_h === "show" ) { num++; }
- if ( t_o === "hide" || t_o === "show" ) { num++; }
- if ( t_w === "hide" ) { num++; }
- if ( t_o.constructor === Number ) { num += 2; }
- if ( t_w.constructor === Number ) { num += 2; }
- if ( t_h.constructor === Number ) { num += 2; }
+ if ( t_h === "show" ) {
+ num++;
+ }
+ if ( t_w === "show" ) {
+ num++;
+ }
+ if ( t_w === "hide" || t_w === "show" ) {
+ num++;
+ }
+ if ( t_h === "hide" || t_h === "show" ) {
+ num++;
+ }
+ if ( t_o === "hide" || t_o === "show" ) {
+ num++;
+ }
+ if ( t_w === "hide" ) {
+ num++;
+ }
+ if ( t_o.constructor === Number ) {
+ num += 2;
+ }
+ if ( t_w.constructor === Number ) {
+ num += 2;
+ }
+ if ( t_h.constructor === Number ) {
+ num += 2;
+ }
assert.expect( num );
anim = { width: t_w, height: t_h, opacity: t_o };
- elem.animate( anim, 50 );
+ elem.animate( anim, fxInterval * 5 );
jQuery.when( elem ).done( function( $elem ) {
var cur_o, cur_w, cur_h, old_h,
@@ -1069,7 +1054,7 @@ jQuery.each( {
jQuery( elem ).remove();
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
} );
} );
@@ -1117,7 +1102,7 @@ QUnit.test( "Effects chaining", function( assert ) {
setup( ".fadeToggle().fadeToggle() - out", "#fadetoggleout div" ).fadeToggle( "fast" ).fadeToggle( "fast", check );
setup( ".fadeTo(0.5).fadeTo(1.0, easing)", "#fadeto div" ).fadeTo( "fast", 0.5 ).fadeTo( "fast", 1.0, "linear", check );
- this.clock.tick( 400 );
+ this.clock.tick( 400 + fxInterval * 2 );
} );
jQuery.makeTest = function( text ) {
@@ -1135,7 +1120,7 @@ jQuery.makeTest = function( text ) {
jQuery.makeTest.id = 1;
-QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function( assert ) {
+QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug trac-1095)", function( assert ) {
assert.expect( 4 );
var $checkedtest = jQuery( "#checkedtest" );
@@ -1145,15 +1130,14 @@ QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug #1095)", funct
assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
} );
- this.clock.tick( 200 );
+ this.clock.tick( 200 + fxInterval );
} );
QUnit.test( "interrupt toggle", function( assert ) {
assert.expect( 24 );
- var env = this,
- longDuration = 2000,
- shortDuration = 500,
+ var longDuration = fxInterval * 200,
+ shortDuration = fxInterval * 50,
remaining = 0,
$elems = jQuery( ".chain-test" ),
clock = this.clock,
@@ -1168,9 +1152,6 @@ QUnit.test( "interrupt toggle", function( assert ) {
// Save original property value for comparison
jQuery.data( this, "startVal", jQuery( this ).css( prop ) );
-
- // Expect olddisplay data from our .hide() call below
- assert.expectJqData( env, this, "olddisplay" );
} );
// Interrupt a hiding toggle
@@ -1239,7 +1220,7 @@ QUnit.test( "animate with per-property easing", function( assert ) {
return p;
};
- jQuery( data ).animate( props, 400, "_defaultTest", function() {
+ jQuery( data ).animate( props, fxInterval * 40, "_defaultTest", function() {
assert.ok( test1Called, "Easing function (_test1) called" );
assert.ok( test2Called, "Easing function (_test2) called" );
assert.ok( defaultTestCalled, "Easing function (_default) called" );
@@ -1247,7 +1228,7 @@ QUnit.test( "animate with per-property easing", function( assert ) {
assert.equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)" );
} );
- this.clock.tick( 400 );
+ this.clock.tick( fxInterval * 40 );
} );
QUnit.test( "animate with CSS shorthand properties", function( assert ) {
@@ -1273,7 +1254,8 @@ QUnit.test( "animate with CSS shorthand properties", function( assert ) {
};
jQuery( "#foo" )
- .animate( propsBasic, 200, "animationScope", function() {
+ .animate( propsBasic, fxInterval * 20,
+ "animationScope", function() {
assert.equal( this.style.paddingTop, "10px", "padding-top was animated" );
assert.equal( this.style.paddingLeft, "20px", "padding-left was animated" );
assert.equal( this.style.paddingRight, "20px", "padding-right was animated" );
@@ -1281,7 +1263,8 @@ QUnit.test( "animate with CSS shorthand properties", function( assert ) {
assert.equal( easeAnimation_count, 4, "per-animation default easing called for each property" );
easeAnimation_count = 0;
} )
- .animate( propsSpecial, 200, "animationScope", function() {
+ .animate( propsSpecial, fxInterval * 20,
+ "animationScope", function() {
assert.equal( this.style.paddingTop, "1px", "padding-top was animated again" );
assert.equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
assert.equal( this.style.paddingRight, "2px", "padding-right was animated again" );
@@ -1293,13 +1276,13 @@ QUnit.test( "animate with CSS shorthand properties", function( assert ) {
delete jQuery.easing.animationScope;
delete jQuery.easing.propertyScope;
} );
- this.clock.tick( 400 );
+ this.clock.tick( fxInterval * 40 );
} );
-QUnit.test( "hide hidden elements, with animation (bug #7141)", function( assert ) {
+QUnit.test( "hide hidden elements, with animation (bug trac-7141)", function( assert ) {
assert.expect( 4 );
- var div = jQuery( "
" ).appendTo( "#qunit-fixture" );
+ var div = jQuery( "
" ).appendTo( "#qunit-fixture" );
assert.equal( div.css( "display" ), "none", "Element is initially hidden" );
div.hide( 10, function() {
assert.equal( div.css( "display" ), "none", "Element is hidden in .hide() callback" );
@@ -1311,7 +1294,7 @@ QUnit.test( "hide hidden elements, with animation (bug #7141)", function( assert
assert.equal( div.css( "display" ), "block", "Element is visible after animations" );
} );
-QUnit.test( "animate unit-less properties (#4966)", function( assert ) {
+QUnit.test( "animate unit-less properties (trac-4966)", function( assert ) {
assert.expect( 2 );
var div = jQuery( "
" ).appendTo( "#qunit-fixture" );
@@ -1319,10 +1302,10 @@ QUnit.test( "animate unit-less properties (#4966)", function( assert ) {
div.animate( { zIndex: 2 }, function() {
assert.equal( div.css( "z-index" ), "2", "z-index is 2" );
} );
- this.clock.tick( 400 );
+ this.clock.tick( 400 + fxInterval );
} );
-QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function( assert ) {
+QUnit.test( "animate properties missing px w/ opacity as last (trac-9074)", function( assert ) {
assert.expect( 6 );
var ml, l,
@@ -1337,9 +1320,9 @@ QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function
left: 200,
marginLeft: 200,
opacity: 0
- }, 2000 );
+ }, fxInterval * 200 );
- this.clock.tick( 500 );
+ this.clock.tick( fxInterval * 50 );
ml = cssInt( "marginLeft" );
l = cssInt( "left" );
@@ -1350,7 +1333,7 @@ QUnit.test( "animate properties missing px w/ opacity as last (#9074)", function
div.stop().remove();
} );
-QUnit.test( "callbacks should fire in correct order (#9100)", function( assert ) {
+QUnit.test( "callbacks should fire in correct order (trac-9100)", function( assert ) {
assert.expect( 1 );
var a = 1,
@@ -1359,17 +1342,17 @@ QUnit.test( "callbacks should fire in correct order (#9100)", function( assert )
jQuery( "
" ).appendTo( "#qunit-fixture" )
// The test will always pass if no properties are animated or if the duration is 0
- .animate( { fontSize: 12 }, 13, function() {
+ .animate( { fontSize: 12 }, fxInterval, function() {
a *= jQuery( this ).data( "operation" ) === "*2" ? 2 : a;
cb++;
if ( cb === 2 ) {
assert.equal( a, 4, "test value has been *2 and _then_ ^2" );
}
} );
- this.clock.tick( 20 );
+ this.clock.tick( fxInterval * 1.5 );
} );
-QUnit.test( "callbacks that throw exceptions will be removed (#5684)", function( assert ) {
+QUnit.test( "callbacks that throw exceptions will be removed (trac-5684)", function( assert ) {
assert.expect( 2 );
var foo = jQuery( "#foo" );
@@ -1422,7 +1405,7 @@ QUnit.test( "animate will scale margin properties individually", function( asser
} );
} );
-QUnit.test( "Do not append px to 'fill-opacity' #9548", function( assert ) {
+QUnit.test( "Do not append px to 'fill-opacity' trac-9548", function( assert ) {
assert.expect( 1 );
var $div = jQuery( "
" ).appendTo( "#qunit-fixture" );
@@ -1433,13 +1416,13 @@ QUnit.test( "Do not append px to 'fill-opacity' #9548", function( assert ) {
} );
} );
-QUnit.test( "line-height animates correctly (#13855)", function( assert ) {
+QUnit.test( "line-height animates correctly (trac-13855)", function( assert ) {
assert.expect( 12 );
var t0,
clock = this.clock,
- longDuration = 2000,
- shortDuration = 500,
+ longDuration = fxInterval * 200,
+ shortDuration = fxInterval * 50,
animated = jQuery(
"
unitless
" +
"
px
" +
@@ -1489,11 +1472,11 @@ QUnit.test( "line-height animates correctly (#13855)", function( assert ) {
animated.stop( true, true );
}, shortDuration );
-clock.tick( shortDuration );
+ clock.tick( shortDuration );
}, shortDuration );
-clock.tick( shortDuration );
- }, 50 );
-clock.tick( 50 );
+ clock.tick( shortDuration );
+ }, fxInterval * 5 );
+ clock.tick( fxInterval * 5 );
} );
// Start 1.8 Animation tests
@@ -1521,7 +1504,7 @@ QUnit.test( "jQuery.Animation( object, props, opts )", function( assert ) {
assert.deepEqual( testObject, testDest, "No unexpected properties" );
} );
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
QUnit.test( "Animate Option: step: function( percent, tween )", function( assert ) {
@@ -1549,7 +1532,7 @@ QUnit.test( "Animate Option: step: function( percent, tween )", function( assert
}, "Step function was called once at 0% and once at 100% for each property" );
next();
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
QUnit.test( "Animate callbacks have correct context", function( assert ) {
@@ -1558,18 +1541,18 @@ QUnit.test( "Animate callbacks have correct context", function( assert ) {
var foo = jQuery( "#foo" );
foo.animate( {
height: 10
- }, 10, function() {
+ }, fxInterval, function() {
assert.equal( foo[ 0 ], this, "Complete callback after stop(true) `this` is element" );
} ).stop( true, true );
foo.animate( {
height: 100
- }, 10, function() {
+ }, fxInterval, function() {
assert.equal( foo[ 0 ], this, "Complete callback `this` is element" );
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
-QUnit.test( "User supplied callback called after show when fx off (#8892)", function( assert ) {
+QUnit.test( "User supplied callback called after show when fx off (trac-8892)", function( assert ) {
assert.expect( 2 );
var foo = jQuery( "#foo" );
@@ -1588,8 +1571,7 @@ QUnit.test( "User supplied callback called after show when fx off (#8892)", func
QUnit.test( "animate should set display for disconnected nodes", function( assert ) {
assert.expect( 20 );
- var env = this,
- showMethods = {
+ var showMethods = {
fadeIn: [],
fadeTo: [ "fast", 0.5 ],
slideDown: [ "fast" ],
@@ -1600,10 +1582,10 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser
toggle: [ 1 ],
slideToggle: []
},
- $divEmpty = jQuery( "
" ),
+ $divEmpty = jQuery( "
" ),
$divTest = jQuery( "
test
" ),
- $divNone = jQuery( "
" ),
- $divInline = jQuery( "
" ),
+ $divNone = jQuery( "
" ),
+ $divInline = jQuery( "
" ),
nullParentDisplay = $divEmpty.css( "display" ),
underFragmentDisplay = $divTest.css( "display" ),
clock = this.clock;
@@ -1620,10 +1602,8 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser
assert.strictEqual( $divInline.show()[ 0 ].style.display, "inline",
"show() should not change display if it already set" );
- assert.expectJqData( env, $divNone[ 0 ], "olddisplay" );
-
jQuery.each( showMethods, function( name, opt ) {
- jQuery.fn[ name ].apply( jQuery( "
" ), opt.concat( [ function() {
+ jQuery.fn[ name ].apply( jQuery( "
" ), opt.concat( [ function() {
assert.strictEqual( jQuery( this ).css( "display" ), nullParentDisplay,
"." + name + " block with null parentNode" );
} ] ) );
@@ -1634,7 +1614,7 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser
} ] ) );
} );
jQuery.each( toggleMethods, function( name, opt ) {
- jQuery.fn[ name ].apply( jQuery( "
" ), opt.concat( [ function() {
+ jQuery.fn[ name ].apply( jQuery( "
" ), opt.concat( [ function() {
assert.strictEqual( jQuery( this ).css( "display" ), "none",
"." + name + " block with null parentNode" );
} ] ) );
@@ -1644,23 +1624,23 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser
"." + name + " block under fragment" );
} ] ) );
} );
- clock.tick( 400 );
+ clock.tick( 400 + fxInterval );
} );
-QUnit[ jQuery.find.compile ? "test" : "skip" ]( "Animation callback should not show animated element as :animated (#7157)", function( assert ) {
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "Animation callback should not show animated element as :animated (trac-7157)", function( assert ) {
assert.expect( 1 );
var foo = jQuery( "#foo" );
foo.animate( {
opacity: 0
- }, 100, function() {
+ }, fxInterval * 10, function() {
assert.ok( !foo.is( ":animated" ), "The element is not animated" );
} );
- this.clock.tick( 100 );
+ this.clock.tick( fxInterval * 10 );
} );
-QUnit[ jQuery.find.compile ? "test" : "skip" ]( "Initial step callback should show element as :animated (#14623)", function( assert ) {
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "Initial step callback should show element as :animated (trac-14623)", function( assert ) {
assert.expect( 1 );
var foo = jQuery( "#foo" );
@@ -1677,7 +1657,7 @@ QUnit[ jQuery.find.compile ? "test" : "skip" ]( "Initial step callback should sh
foo.stop();
} );
-QUnit.test( "hide called on element within hidden parent should set display to none (#10045)", function( assert ) {
+QUnit.test( "hide called on element within hidden parent should set display to none (trac-10045)", function( assert ) {
assert.expect( 3 );
var hidden = jQuery( ".hidden" ),
@@ -1696,7 +1676,7 @@ QUnit.test( "hide called on element within hidden parent should set display to n
elems.remove();
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
QUnit.test( "hide, fadeOut and slideUp called on element width height and width = 0 should set display to none", function( assert ) {
@@ -1727,10 +1707,10 @@ QUnit.test( "hide, fadeOut and slideUp called on element width height and width
assert.strictEqual( elems.get( 4 ).style.display, "none", "slideUp() called on element width height and width = 0 should set display to none" );
} );
- this.clock.tick( 400 );
+ this.clock.tick( 400 + fxInterval );
} );
-QUnit.test( "hide should not leave hidden inline elements visible (#14848)", function( assert ) {
+QUnit.test( "hide should not leave hidden inline elements visible (trac-14848)", function( assert ) {
assert.expect( 2 );
var el = jQuery( "#simon1" );
@@ -1754,7 +1734,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
foo.animate( {
top: 1
}, {
- duration: 10,
+ duration: fxInterval,
queue: false,
complete: function() {
assert.ok( step++ <= 2, "Step one or two" );
@@ -1762,21 +1742,21 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
} ).animate( {
bottom: 1
}, {
- duration: 10,
+ duration: fxInterval,
complete: function() {
assert.ok( step > 2 && step < 5, "Step three or four" );
step++;
}
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
foo.promise().done( function() {
assert.equal( step++, 5, "steps 1-5: queue:false then queue:fx done" );
foo.animate( {
top: 10
}, {
- duration: 10,
+ duration: fxInterval,
complete: function() {
assert.ok( step > 5 && step < 8, "Step six or seven" );
step++;
@@ -1784,7 +1764,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
} ).animate( {
bottom: 10
}, {
- duration: 10,
+ duration: fxInterval,
queue: false,
complete: function() {
assert.ok( step > 7 && step < 10, "Step eight or nine" );
@@ -1795,7 +1775,7 @@ QUnit.test( "Handle queue:false promises", function( assert ) {
} );
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
QUnit.test( "multiple unqueued and promise", function( assert ) {
@@ -1830,10 +1810,10 @@ QUnit.test( "multiple unqueued and promise", function( assert ) {
} ).promise().done( function() {
assert.strictEqual( step++, 4, "Step 4" );
} );
- this.clock.tick( 1000 );
+ this.clock.tick( 1000 + fxInterval );
} );
-QUnit.test( "animate does not change start value for non-px animation (#7109)", function( assert ) {
+QUnit.test( "animate does not change start value for non-px animation (trac-7109)", function( assert ) {
assert.expect( 1 );
var parent = jQuery( "
" ).css( { width: 284, height: 1 } ).appendTo( "#qunit-fixture" ),
@@ -1853,10 +1833,10 @@ QUnit.test( "animate does not change start value for non-px animation (#7109)",
next();
parent.remove();
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
-QUnit.test( "non-px animation handles non-numeric start (#11971)", function( assert ) {
+QUnit.test( "non-px animation handles non-numeric start (trac-11971)", function( assert ) {
assert.expect( 2 );
var foo = jQuery( "#foo" ),
@@ -1885,10 +1865,10 @@ QUnit.test( "non-px animation handles non-numeric start (#11971)", function( ass
assert.equal( jQuery.style( this, "backgroundPositionX" ), "42%", "End reached" );
}
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
-QUnit.test( "Animation callbacks (#11797)", function( assert ) {
+QUnit.test( "Animation callbacks (trac-11797)", function( assert ) {
assert.expect( 15 );
var prog = 0,
@@ -1965,10 +1945,10 @@ QUnit.test( "Animation callbacks (#11797)", function( assert ) {
assert.ok( true, "async: always" );
}
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
-QUnit.test( "Animation callbacks in order (#2292)", function( assert ) {
+QUnit.test( "Animation callbacks in order (gh-2283)", function( assert ) {
assert.expect( 9 );
var done = assert.async(),
@@ -2005,10 +1985,10 @@ QUnit.test( "Animation callbacks in order (#2292)", function( assert ) {
}
} ).finish();
- this.clock.tick( dur + 10 );
+ this.clock.tick( dur + fxInterval );
} );
-QUnit.test( "Animate properly sets overflow hidden when animating width/height (#12117)", function( assert ) {
+QUnit.test( "Animate properly sets overflow hidden when animating width/height (trac-12117)", function( assert ) {
assert.expect( 8 );
jQuery.each( [ "height", "width" ], function( _, prop ) {
@@ -2026,7 +2006,7 @@ QUnit.test( "Animate properly sets overflow hidden when animating width/height (
} );
} );
-QUnit.test( "Each tick of the timer loop uses a fresh time (#12837)", function( assert ) {
+QUnit.test( "Each tick of the timer loop uses a fresh time (trac-12837)", function( assert ) {
var lastVal,
tmp = jQuery( {
test: 0
@@ -2051,7 +2031,7 @@ QUnit.test( "Each tick of the timer loop uses a fresh time (#12837)", function(
tmp.stop();
} );
-QUnit.test( "Animations with 0 duration don't ease (#12273)", function( assert ) {
+QUnit.test( "Animations with 0 duration don't ease (trac-12273)", function( assert ) {
assert.expect( 1 );
jQuery.easing.test = function() {
@@ -2076,7 +2056,7 @@ jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) {
// this test would look a lot better if we were using something to override
// the default timers
var duration = 1500;
- QUnit.test( "toggle state tests: " + method + " (#8685)", function( assert ) {
+ QUnit.test( "toggle state tests: " + method + " (trac-8685)", function( assert ) {
function secondToggle() {
var stopped = parseFloat( element.css( check ) );
tested = false;
@@ -2115,8 +2095,8 @@ jQuery.map( [ "toggle", "slideToggle", "fadeToggle" ], function( method ) {
always: secondToggle
} );
- //FIXME figure out why 470
- this.clock.tick( 470 );
+ // FIXME figure out why 470
+ this.clock.tick( 470 + fxInterval * 2 );
} );
} );
@@ -2176,7 +2156,7 @@ QUnit.test( ".finish() completes all queued animations", function( assert ) {
} );
assert.equal( div.queue().length, 0, "empty queue when done" );
- if ( jQuery.find.compile ) {
+ if ( QUnit.jQuerySelectors ) {
assert.equal( div.is( ":animated" ), false, ":animated doesn't match" );
} else {
assert.ok( "skip", ":animated selector not supported with selector-native" );
@@ -2216,7 +2196,7 @@ QUnit.test( ".finish( false ) - unqueued animations", function( assert ) {
assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
} );
- if ( jQuery.find.compile ) {
+ if ( QUnit.jQuerySelectors ) {
assert.equal( div.is( ":animated" ), false, ":animated doesn't match" );
} else {
assert.ok( "skip", ":animated selector not supported with selector-native" );
@@ -2255,7 +2235,7 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert
// start the first animation
div.dequeue( "custom" );
- if ( jQuery.find.compile ) {
+ if ( QUnit.jQuerySelectors ) {
assert.equal( div.is( ":animated" ), true, ":animated matches" );
} else {
assert.ok( "skip", ":animated selector not supported with selector-native" );
@@ -2266,7 +2246,7 @@ QUnit.test( ".finish( \"custom\" ) - custom queue animations", function( assert
assert.equal( parseFloat( div.css( prop ) ), value, prop + " finished at correct value" );
} );
- if ( jQuery.find.compile ) {
+ if ( QUnit.jQuerySelectors ) {
assert.equal( div.is( ":animated" ), false, ":animated doesn't match" );
} else {
assert.ok( "skip", ":animated selector not supported with selector-native" );
@@ -2305,12 +2285,15 @@ QUnit.test( ".finish() calls finish of custom queue functions", function( assert
div.remove();
} );
-QUnit.test( ".finish() is applied correctly when multiple elements were animated (#13937)", function( assert ) {
+QUnit.test( ".finish() is applied correctly when multiple elements were animated (trac-13937)", function( assert ) {
assert.expect( 3 );
var elems = jQuery( "
0 1 2 " );
- elems.animate( { opacity: 0 }, 1500 ).animate( { opacity: 1 }, 1500 );
+ elems
+ .animate( { opacity: 0 }, fxInterval * 150 )
+ .animate( { opacity: 1 }, fxInterval * 150 );
+
setTimeout( function() {
elems.eq( 1 ).finish();
assert.ok( !elems.eq( 1 ).queue().length, "empty queue for .finish()ed element" );
@@ -2319,10 +2302,10 @@ QUnit.test( ".finish() is applied correctly when multiple elements were animated
elems.stop( true );
}, 100 );
- this.clock.tick( 1500 );
+ this.clock.tick( fxInterval * 150 );
} );
-QUnit.test( "slideDown() after stop() (#13483)", function( assert ) {
+QUnit.test( "slideDown() after stop() (trac-13483)", function( assert ) {
assert.expect( 2 );
var ul = jQuery( "
" )
@@ -2331,36 +2314,36 @@ QUnit.test( "slideDown() after stop() (#13483)", function( assert ) {
clock = this.clock;
// First test. slideUp() -> stop() in the middle -> slideDown() until the end
- ul.slideUp( 1000 );
- clock.tick( 500 );
+ ul.slideUp( fxInterval * 100 );
+ clock.tick( fxInterval * 50 );
ul.stop( true );
ul.slideDown( 1, function() {
assert.equal( ul.height(), origHeight, "slideDown() after interrupting slideUp() with stop(). Height must be in original value" );
// Second test. slideDown() -> stop() in the middle -> slideDown() until the end
ul.slideUp( 1 );
- clock.tick( 10 );
- ul.slideDown( 1000 );
- clock.tick( 500 );
+ clock.tick( fxInterval );
+ ul.slideDown( fxInterval * 100 );
+ clock.tick( fxInterval * 50 );
ul.stop( true );
ul.slideDown( 1 );
assert.equal( ul.height(), origHeight, "slideDown() after interrupting slideDown() with stop(). Height must be in original value" );
// Cleanup
ul.remove();
- clock.tick( 10 );
+ clock.tick( fxInterval );
} );
- clock.tick( 10 );
+ clock.tick( fxInterval );
} );
-QUnit.test( "Respect display value on inline elements (#14824)", function( assert ) {
+QUnit.test( "Respect display value on inline elements (trac-14824)", function( assert ) {
assert.expect( 2 );
var clock = this.clock,
- fromStyleSheet = jQuery( "
" ),
- fromStyleAttr = jQuery( "
" );
+ fromStyleSheet = jQuery( "
" ),
+ fromStyleAttr = jQuery( "
" );
jQuery( "#qunit-fixture" ).append( fromStyleSheet, fromStyleAttr );
@@ -2378,7 +2361,7 @@ QUnit.test( "Respect display value on inline elements (#14824)", function( asser
} );
} );
- clock.tick( 800 );
+ clock.tick( 800 + fxInterval * 2 );
} );
QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) {
@@ -2402,7 +2385,7 @@ QUnit.test( "jQuery.easing._default (gh-2218)", function( assert ) {
} )
.stop();
- this.clock.tick( 25 );
+ this.clock.tick( 10 + fxInterval );
} );
QUnit.test( "jQuery.easing._default in Animation (gh-2218", function( assert ) {
@@ -2430,7 +2413,7 @@ QUnit.test( "jQuery.easing._default in Animation (gh-2218", function( assert ) {
delete jQuery.easing.custom;
} );
- this.clock.tick( 10 );
+ this.clock.tick( fxInterval );
} );
QUnit.test( "jQuery.easing._default in Tween (gh-2218)", function( assert ) {
@@ -2460,7 +2443,7 @@ QUnit.test( "jQuery.easing._default in Tween (gh-2218)", function( assert ) {
QUnit.test( "Display value is correct for disconnected nodes (trac-13310)", function( assert ) {
assert.expect( 3 );
- var div = jQuery( "
" );
+ var div = jQuery( "
" );
assert.equal( div.css( "display", "inline" ).hide().show().appendTo( "body" ).css( "display" ), "inline", "Initialized display value has returned" );
div.remove();
@@ -2481,9 +2464,9 @@ QUnit.test( "Show/hide/toggle and display: inline", function( assert ) {
var clock = this.clock;
- jQuery( "
" ).each( function() {
+ jQuery( "
" ).each( function() {
var completed, interrupted,
- N = 100,
+ N = fxInterval * 10,
fixture = jQuery( "#qunit-fixture" ),
$el = jQuery( this ),
kind = this.title || this.nodeName.toLowerCase();
@@ -2496,7 +2479,9 @@ QUnit.test( "Show/hide/toggle and display: inline", function( assert ) {
.hide().show( N ),
$el.clone().data( { call: "hide+toggle", done: "inline" } ).appendTo( fixture )
.hide().toggle( N )
- ], function( $clone ) { return $clone[ 0 ]; } );
+ ], function( $clone ) {
+ return $clone[ 0 ];
+ } );
// Animations not allowed to complete
interrupted = jQuery.map( [
@@ -2504,7 +2489,9 @@ QUnit.test( "Show/hide/toggle and display: inline", function( assert ) {
$el.clone().data( { call: "toggle+stop" } ).appendTo( fixture ).toggle( N ),
$el.clone().data( { call: "hide+show+stop" } ).appendTo( fixture ).hide().show( N ),
$el.clone().data( { call: "hide+toggle+stop" } ).appendTo( fixture ).hide().toggle( N )
- ], function( $clone ) { return $clone[ 0 ]; } );
+ ], function( $clone ) {
+ return $clone[ 0 ];
+ } );
// All elements should be inline-block during the animation
clock.tick( N / 2 );
@@ -2549,7 +2536,7 @@ function testEasing( assert, speed, easing, complete ) {
assert.expect( 4 );
var options = jQuery.speed( speed, easing, complete );
- assert.equal( options.duration, 10, "Duration set properly" );
+ assert.equal( options.duration, fxInterval, "Duration set properly" );
assert.equal(
typeof options.easing === "function" ? options.easing() : options.easing,
"linear",
@@ -2560,7 +2547,7 @@ function testEasing( assert, speed, easing, complete ) {
}
QUnit.test( "jQuery.speed( speed, easing, complete )", function( assert ) {
- testEasing( assert, 10, "linear", function() {
+ testEasing( assert, fxInterval, "linear", function() {
assert.ok( true, "Complete called" );
} );
} );
@@ -2568,7 +2555,7 @@ QUnit.test( "jQuery.speed( speed, easing, complete )", function( assert ) {
QUnit.test( "jQuery.speed( speed, easing, complete ) - with easing function", function( assert ) {
testEasing(
assert,
- 10,
+ fxInterval,
function() {
return "linear";
},
@@ -2580,7 +2567,7 @@ QUnit.test( "jQuery.speed( speed, easing, complete ) - with easing function", fu
QUnit.test( "jQuery.speed( options )", function( assert ) {
testEasing( assert, {
- duration: 10,
+ duration: fxInterval,
easing: "linear",
complete: function() {
assert.ok( true, "Complete called" );
@@ -2590,7 +2577,7 @@ QUnit.test( "jQuery.speed( options )", function( assert ) {
QUnit.test( "jQuery.speed( options ) - with easing function", function( assert ) {
testEasing( assert, {
- duration: 10,
+ duration: fxInterval,
easing: function() {
return "linear";
},
diff --git a/test/unit/event.js b/test/unit/event.js
index c7497b9b0f..2d49aa10c1 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -8,7 +8,7 @@ QUnit.module( "event", {
QUnit.test( "null or undefined handler", function( assert ) {
assert.expect( 4 );
- // Supports Fixes bug #7229
+ // Supports Fixes bug trac-7229
try {
jQuery( "#firstp" ).on( "click", null );
assert.ok( true, "Passing a null handler will not throw an exception" );
@@ -153,7 +153,7 @@ QUnit.test( "on(), multiple events at once and namespaces", function( assert ) {
var cur, div,
obj = {};
- div = jQuery( "
" ).on( "focusin.a", function( e ) {
+ div = jQuery( "
" ).on( "focusin.a", function( e ) {
assert.equal( e.type, cur, "Verify right single event was fired." );
} );
@@ -163,7 +163,7 @@ QUnit.test( "on(), multiple events at once and namespaces", function( assert ) {
// manually clean up detached elements
div.remove();
- div = jQuery( "
" ).on( "click mouseover", obj, function( e ) {
+ div = jQuery( "
" ).on( "click mouseover", obj, function( e ) {
assert.equal( e.type, cur, "Verify right multi event was fired." );
assert.equal( e.data, obj, "Make sure the data came in correctly." );
} );
@@ -177,7 +177,7 @@ QUnit.test( "on(), multiple events at once and namespaces", function( assert ) {
// manually clean up detached elements
div.remove();
- div = jQuery( "
" ).on( "focusin.a focusout.b", function( e ) {
+ div = jQuery( "
" ).on( "focusin.a focusout.b", function( e ) {
assert.equal( e.type, cur, "Verify right multi event was fired." );
} );
@@ -195,7 +195,7 @@ QUnit.test( "on(), namespace with special add", function( assert ) {
assert.expect( 27 );
var i = 0,
- div = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "test", function() {
+ div = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "test", function() {
assert.ok( true, "Test event fired." );
} );
@@ -224,12 +224,12 @@ QUnit.test( "on(), namespace with special add", function( assert ) {
div.on( "test.a", { x: 1 }, function( e ) {
assert.ok( !!e.xyz, "Make sure that the data is getting passed through." );
- assert.equal( e.data[ "x" ], 1, "Make sure data is attached properly." );
+ assert.equal( e.data.x, 1, "Make sure data is attached properly." );
} );
div.on( "test.b", { x: 2 }, function( e ) {
assert.ok( !!e.xyz, "Make sure that the data is getting passed through." );
- assert.equal( e.data[ "x" ], 2, "Make sure data is attached properly." );
+ assert.equal( e.data.x, 2, "Make sure data is attached properly." );
} );
// Should trigger 5
@@ -244,7 +244,7 @@ QUnit.test( "on(), namespace with special add", function( assert ) {
// Should trigger 4
div.off( "test" );
- div = jQuery( "
" ).on( "test", function() {
+ div = jQuery( "
" ).on( "test", function() {
assert.ok( true, "Test event fired." );
} );
@@ -293,14 +293,14 @@ QUnit.test( "on/one/off(Object)", function( assert ) {
// Regular bind
.on( {
- "click":handler,
- "mouseover":handler
+ "click": handler,
+ "mouseover": handler
} )
// Bind with data
.one( {
- "click":handlerWithData,
- "mouseover":handlerWithData
+ "click": handlerWithData,
+ "mouseover": handlerWithData
}, 2 );
trigger();
@@ -313,8 +313,8 @@ QUnit.test( "on/one/off(Object)", function( assert ) {
assert.equal( mouseoverCounter, 4, "on(Object)" );
jQuery( "#firstp" ).off( {
- "click":handler,
- "mouseover":handler
+ "click": handler,
+ "mouseover": handler
} );
trigger();
@@ -484,7 +484,7 @@ QUnit.test( "trigger() works with events that were previously stopped", function
QUnit.test( "on(), iframes", function( assert ) {
assert.expect( 1 );
- // events don't work with iframes, see #939 - this test fails in IE because of contentDocument
+ // events don't work with iframes, see trac-939 - this test fails in IE because of contentDocument
var doc = jQuery( "#loadediframe" ).contents();
jQuery( "div", doc ).on( "click", function() {
@@ -552,8 +552,10 @@ QUnit.test( "on(), namespaced events, cloned events", function( assert ) {
assert.equal( this.nodeType, 1, "Check node,textnode,comment on just does real nodes" );
} ).trigger( "tester" );
- // Make sure events stick with appendTo'd elements (which are cloned) #2027
- jQuery( "
test " ).on( "click", function() { return false; } ).appendTo( "#qunit-fixture" );
+ // Make sure events stick with appendTo'd elements (which are cloned) trac-2027
+ jQuery( "
test " ).on( "click", function() {
+ return false;
+ } ).appendTo( "#qunit-fixture" );
assert.ok( jQuery( "a.test" ).eq( 0 ).triggerHandler( "click" ) === false, "Handler is bound to appendTo'd elements" );
} );
@@ -589,7 +591,7 @@ QUnit.test( "on(), multi-namespaced events", function( assert ) {
check( "click.test.abc", "Namespaced click triggered" );
} );
- // Those would not trigger/off (#5303)
+ // Those would not trigger/off (trac-5303)
jQuery( "#firstp" ).trigger( "click.a.test" );
jQuery( "#firstp" ).off( "click.a.test" );
@@ -704,7 +706,9 @@ QUnit.test( "on(name, false), off(name, false)", function( assert ) {
assert.expect( 3 );
var main = 0;
- jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
+ jQuery( "#qunit-fixture" ).on( "click", function() {
+ main++;
+ } );
jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
@@ -727,7 +731,9 @@ QUnit.test( "on(name, selector, false), off(name, selector, false)", function( a
var main = 0;
- jQuery( "#qunit-fixture" ).on( "click", "#ap", function() { main++; } );
+ jQuery( "#qunit-fixture" ).on( "click", "#ap", function() {
+ main++;
+ } );
jQuery( "#ap" ).trigger( "click" );
assert.equal( main, 1, "Verify that the trigger happened correctly." );
@@ -766,7 +772,7 @@ QUnit.test( "on()/trigger()/off() on plain object", function( assert ) {
events = jQuery._data( obj, "events" );
assert.ok( events, "Object has events bound." );
- assert.equal( obj[ "events" ], undefined, "Events object on plain objects is not events" );
+ assert.equal( obj.events, undefined, "Events object on plain objects is not events" );
assert.equal( obj.test, undefined, "Make sure that test event is not on the plain object." );
assert.equal( obj.handle, undefined, "Make sure that the event handler is not on the plain object." );
@@ -785,7 +791,7 @@ QUnit.test( "on()/trigger()/off() on plain object", function( assert ) {
assert.equal( obj && obj[ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] &&
- obj[ jQuery.expando ][ jQuery.expando ][ "events" ], undefined, "Make sure events object is removed" );
+ obj[ jQuery.expando ][ jQuery.expando ].events, undefined, "Make sure events object is removed" );
} );
QUnit.test( "off(type)", function( assert ) {
@@ -812,7 +818,7 @@ QUnit.test( "off(type)", function( assert ) {
.off( "error1 error2", error )
.trigger( "error1" ).triggerHandler( "error2" );
- message = "unbind many"; // #3538
+ message = "unbind many"; // trac-3538
$elem.on( "error1 error2", error )
.off( "error1 error2" )
.trigger( "error1" ).triggerHandler( "error2" );
@@ -876,7 +882,7 @@ QUnit.test( "mouseover triggers mouseenter", function( assert ) {
assert.expect( 1 );
var count = 0,
- elem = jQuery( "
" );
+ elem = jQuery( "
" );
elem.on( "mouseenter", function() {
count++;
} );
@@ -890,7 +896,7 @@ QUnit.test( "pointerover triggers pointerenter", function( assert ) {
assert.expect( 1 );
var count = 0,
- elem = jQuery( "
" );
+ elem = jQuery( "
" );
elem.on( "pointerenter", function() {
count++;
} );
@@ -938,12 +944,26 @@ QUnit.test( "trigger() bubbling", function( assert ) {
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
- jQuery( window ).on( "click", function() { win++; } );
- jQuery( document ).on( "click", function( e ) { if ( e.target !== document ) { doc++; } } );
- jQuery( "html" ).on( "click", function() { html++; } );
- jQuery( "body" ).on( "click", function() { body++; } );
- jQuery( "#qunit-fixture" ).on( "click", function() { main++; } );
- jQuery( "#ap" ).on( "click", function() { ap++; return false; } );
+ jQuery( window ).on( "click", function() {
+ win++;
+ } );
+ jQuery( document ).on( "click", function( e ) {
+ if ( e.target !== document ) {
+ doc++;
+ }
+ } );
+ jQuery( "html" ).on( "click", function() {
+ html++;
+ } );
+ jQuery( "body" ).on( "click", function() {
+ body++;
+ } );
+ jQuery( "#qunit-fixture" ).on( "click", function() {
+ main++;
+ } );
+ jQuery( "#ap" ).on( "click", function() {
+ ap++; return false;
+ } );
jQuery( "html" ).trigger( "click" );
assert.equal( win, 1, "HTML bubble" );
@@ -1041,7 +1061,7 @@ QUnit.test( "trigger(type, [data], [fn])", function( assert ) {
} catch ( e ) {
pass = false;
}
- assert.ok( pass, "Trigger on a table with a colon in the even type, see #3533" );
+ assert.ok( pass, "Trigger on a table with a colon in the even type, see trac-3533" );
form = jQuery( "
" ).appendTo( "body" );
@@ -1069,13 +1089,13 @@ QUnit.test( "trigger(type, [data], [fn])", function( assert ) {
form.remove();
} );
-QUnit.test( "submit event bubbles on copied forms (#11649)", function( assert ) {
+QUnit.test( "submit event bubbles on copied forms (trac-11649)", function( assert ) {
assert.expect( 3 );
var $formByClone, $formByHTML,
$testForm = jQuery( "#testForm" ),
$fixture = jQuery( "#qunit-fixture" ),
- $wrapperDiv = jQuery( "
" ).appendTo( $fixture );
+ $wrapperDiv = jQuery( "
" ).appendTo( $fixture );
function noSubmit( e ) {
e.preventDefault();
@@ -1105,13 +1125,13 @@ QUnit.test( "submit event bubbles on copied forms (#11649)", function( assert )
$testForm.off( "submit", noSubmit );
} );
-QUnit.test( "change event bubbles on copied forms (#11796)", function( assert ) {
+QUnit.test( "change event bubbles on copied forms (trac-11796)", function( assert ) {
assert.expect( 3 );
var $formByClone, $formByHTML,
$form = jQuery( "#form" ),
$fixture = jQuery( "#qunit-fixture" ),
- $wrapperDiv = jQuery( "
" ).appendTo( $fixture );
+ $wrapperDiv = jQuery( "
" ).appendTo( $fixture );
function delegatedChange() {
assert.ok( true, "Make sure change event bubbles up." );
@@ -1141,7 +1161,7 @@ QUnit.test( "trigger(eventObject, [data], [fn])", function( assert ) {
assert.expect( 28 );
var event,
- $parent = jQuery( "
" ).appendTo( "body" ),
+ $parent = jQuery( "
" ).appendTo( "body" ),
$child = jQuery( "
foo
" ).appendTo( $parent );
$parent.get( 0 ).style.display = "none";
@@ -1159,7 +1179,9 @@ QUnit.test( "trigger(eventObject, [data], [fn])", function( assert ) {
event.stopPropagation();
assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
- event.isPropagationStopped = function() { return false; };
+ event.isPropagationStopped = function() {
+ return false;
+ };
event.stopImmediatePropagation();
assert.equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
assert.equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
@@ -1227,7 +1249,7 @@ QUnit.test( "trigger(eventObject, [data], [fn])", function( assert ) {
assert.equal( event.isDefaultPrevented(), false, "default not prevented" );
} );
-QUnit.test( ".trigger() bubbling on disconnected elements (#10489)", function( assert ) {
+QUnit.test( ".trigger() bubbling on disconnected elements (trac-10489)", function( assert ) {
assert.expect( 2 );
jQuery( window ).on( "click", function() {
@@ -1251,7 +1273,7 @@ QUnit.test( ".trigger() bubbling on disconnected elements (#10489)", function( a
jQuery( window ).off( "click" );
} );
-QUnit.test( ".trigger() doesn't bubble load event (#10717)", function( assert ) {
+QUnit.test( ".trigger() doesn't bubble load event (trac-10717)", function( assert ) {
assert.expect( 1 );
jQuery( window ).on( "load", function() {
@@ -1269,7 +1291,7 @@ QUnit.test( ".trigger() doesn't bubble load event (#10717)", function( assert )
jQuery( window ).off( "load" );
} );
-QUnit.test( "Delegated events in SVG (#10791; #13180)", function( assert ) {
+QUnit.test( "Delegated events in SVG (trac-10791; trac-13180)", function( assert ) {
assert.expect( 2 );
var useElem, e,
@@ -1295,7 +1317,7 @@ QUnit.test( "Delegated events in SVG (#10791; #13180)", function( assert ) {
.end();
// Fire a native click on an SVGElementInstance (the instance tree of an SVG
)
- // to confirm that it doesn't break our event delegation handling (#13180)
+ // to confirm that it doesn't break our event delegation handling (trac-13180)
useElem = svg.find( "#use" )[ 0 ];
if ( document.createEvent && useElem && useElem.instanceRoot ) {
e = document.createEvent( "MouseEvents" );
@@ -1317,11 +1339,11 @@ QUnit.test( "Delegated events with malformed selectors (gh-3071)", function( ass
jQuery( "#foo" ).on( "click", "nonexistent:not", function() {} );
}, "short-circuitable malformed selector throws on attach" );
- jQuery( "#foo > :first-child" ).click();
+ jQuery( "#foo > :first-child" ).trigger( "click" );
assert.ok( true, "malformed selector does not throw on event" );
} );
-QUnit.test( "Delegated events in forms (#10844; #11145; #8165; #11382, #11764)", function( assert ) {
+QUnit.test( "Delegated events in forms (trac-10844; trac-11145; trac-8165; trac-11382, trac-11764)", function( assert ) {
assert.expect( 5 );
// Alias names like "id" cause havoc
@@ -1376,7 +1398,7 @@ QUnit.test( "Delegated events in forms (#10844; #11145; #8165; #11382, #11764)",
form.remove();
} );
-QUnit.test( "Submit event can be stopped (#11049)", function( assert ) {
+QUnit.test( "Submit event can be stopped (trac-11049)", function( assert ) {
assert.expect( 1 );
// Since we manually bubble in IE, make sure inner handlers get a chance to cancel
@@ -1394,7 +1416,9 @@ QUnit.test( "Submit event can be stopped (#11049)", function( assert ) {
return false;
} )
.find( "#myform input[type=submit]" )
- .each( function() { this.click(); } )
+ .each( function() {
+ this.click();
+ } )
.end()
.on( "submit", function() {
assert.ok( false, "submit bubbled on second handler" );
@@ -1414,7 +1438,7 @@ QUnit.test( "Submit event can be stopped (#11049)", function( assert ) {
form.remove();
} );
-// Support: iOS 7 - 9
+// Support: iOS <=7 - 12+
// iOS has the window.onbeforeunload field but doesn't support the beforeunload
// handler making it impossible to feature-detect the support.
QUnit[ /(ipad|iphone|ipod)/i.test( navigator.userAgent ) ? "skip" : "test" ](
@@ -1450,7 +1474,7 @@ QUnit.test( "jQuery.Event( type, props )", function( assert ) {
assert.equal( event.type, "keydown", "Verify type" );
// ensure "type" in props won't clobber the one set by constructor
- assert.equal( jQuery.inArray( "type", jQuery.event.props ), -1, "'type' property not in props (#10375)" );
+ assert.equal( jQuery.inArray( "type", jQuery.event.props ), -1, "'type' property not in props (trac-10375)" );
assert.ok( "keyCode" in event, "Special 'keyCode' property exists" );
@@ -1506,10 +1530,18 @@ QUnit.test( ".on()/.off()", function( assert ) {
var event, clicked, hash, called, livec, lived, livee,
submit = 0, div = 0, livea = 0, liveb = 0;
- jQuery( "#body" ).on( "submit", "#qunit-fixture div", function() { submit++; return false; } );
- jQuery( "#body" ).on( "click", "#qunit-fixture div", function() { div++; } );
- jQuery( "#body" ).on( "click", "div#nothiddendiv", function() { livea++; } );
- jQuery( "#body" ).on( "click", "div#nothiddendivchild", function() { liveb++; } );
+ jQuery( "#body" ).on( "submit", "#qunit-fixture div", function() {
+ submit++; return false;
+ } );
+ jQuery( "#body" ).on( "click", "#qunit-fixture div", function() {
+ div++;
+ } );
+ jQuery( "#body" ).on( "click", "div#nothiddendiv", function() {
+ livea++;
+} );
+ jQuery( "#body" ).on( "click", "div#nothiddendivchild", function() {
+ liveb++;
+ } );
// Nothing should trigger on the body
jQuery( "body" ).trigger( "click" );
@@ -1569,7 +1601,9 @@ QUnit.test( ".on()/.off()", function( assert ) {
// Make sure that stopPropagation doesn't stop live events
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery( "#body" ).on( "click", "div#nothiddendivchild", function( e ) { liveb++; e.stopPropagation(); } );
+ jQuery( "#body" ).on( "click", "div#nothiddendivchild", function( e ) {
+ liveb++; e.stopPropagation();
+ } );
jQuery( "div#nothiddendivchild" ).trigger( "click" );
assert.equal( submit, 0, "stopPropagation Click on inner div" );
assert.equal( div, 1, "stopPropagation Click on inner div" );
@@ -1591,7 +1625,9 @@ QUnit.test( ".on()/.off()", function( assert ) {
// Test binding with a different context
clicked = 0;
- jQuery( "#qunit-fixture" ).on( "click", "#foo", function() { clicked++; } );
+ jQuery( "#qunit-fixture" ).on( "click", "#foo", function() {
+ clicked++;
+ } );
jQuery( "#qunit-fixture div" ).trigger( "click" );
jQuery( "#foo" ).trigger( "click" );
jQuery( "#qunit-fixture" ).trigger( "click" );
@@ -1635,14 +1671,18 @@ QUnit.test( ".on()/.off()", function( assert ) {
jQuery( "#body" ).off( "click", "#foo" );
// Verify that return false prevents default action
- jQuery( "#body" ).on( "click", "#anchor2", function() { return false; } );
+ jQuery( "#body" ).on( "click", "#anchor2", function() {
+ return false;
+ } );
hash = window.location.hash;
jQuery( "#anchor2" ).trigger( "click" );
assert.equal( window.location.hash, hash, "return false worked" );
jQuery( "#body" ).off( "click", "#anchor2" );
// Verify that .preventDefault() prevents default action
- jQuery( "#body" ).on( "click", "#anchor2", function( e ) { e.preventDefault(); } );
+ jQuery( "#body" ).on( "click", "#anchor2", function( e ) {
+ e.preventDefault();
+ } );
hash = window.location.hash;
jQuery( "#anchor2" ).trigger( "click" );
assert.equal( window.location.hash, hash, "e.preventDefault() worked" );
@@ -1650,7 +1690,9 @@ QUnit.test( ".on()/.off()", function( assert ) {
// Test binding the same handler to multiple points
called = 0;
- function callback() { called++; return false; }
+ function callback() {
+ called++; return false;
+ }
jQuery( "#body" ).on( "click", "#nothiddendiv", callback );
jQuery( "#body" ).on( "click", "#anchor2", callback );
@@ -1696,8 +1738,14 @@ QUnit.test( ".on()/.off()", function( assert ) {
livec = 0;
jQuery( "#nothiddendivchild" ).html( " " );
- jQuery( "#body" ).on( "click", "#nothiddendivchild", function() { jQuery( "#nothiddendivchild" ).html( "" ); } );
- jQuery( "#body" ).on( "click", "#nothiddendivchild", function( e ) { if ( e.target ) {livec++;} } );
+ jQuery( "#body" ).on( "click", "#nothiddendivchild", function() {
+ jQuery( "#nothiddendivchild" ).html( "" );
+ } );
+ jQuery( "#body" ).on( "click", "#nothiddendivchild", function( e ) {
+ if ( e.target ) {
+ livec++;
+ }
+ } );
jQuery( "#nothiddendiv span" ).trigger( "click" );
assert.equal( jQuery( "#nothiddendiv span" ).length, 0, "Verify that first handler occurred and modified the DOM." );
@@ -1712,16 +1760,26 @@ QUnit.test( ".on()/.off()", function( assert ) {
livee = 0;
// bind one pair in one order
- jQuery( "#body" ).on( "click", "span#liveSpan1 a", function() { lived++; return false; } );
- jQuery( "#body" ).on( "click", "span#liveSpan1", function() { livee++; } );
+ jQuery( "#body" ).on( "click", "span#liveSpan1 a", function() {
+ lived++;
+ return false;
+ } );
+ jQuery( "#body" ).on( "click", "span#liveSpan1", function() {
+ livee++;
+ } );
jQuery( "span#liveSpan1 a" ).trigger( "click" );
assert.equal( lived, 1, "Verify that only one first handler occurred." );
assert.equal( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse
- jQuery( "#body" ).on( "click", "span#liveSpan2", function() { livee++; } );
- jQuery( "#body" ).on( "click", "span#liveSpan2 a", function() { lived++; return false; } );
+ jQuery( "#body" ).on( "click", "span#liveSpan2", function() {
+ livee++;
+ } );
+ jQuery( "#body" ).on( "click", "span#liveSpan2 a", function() {
+ lived++;
+ return false;
+ } );
lived = 0;
livee = 0;
@@ -1747,11 +1805,17 @@ QUnit.test( ".on()/.off()", function( assert ) {
// Work with deep selectors
livee = 0;
- function clickB() { livee++; }
+ function clickB() {
+ livee++;
+ }
- jQuery( "#body" ).on( "click", "#nothiddendiv div", function() { livee++; } );
+ jQuery( "#body" ).on( "click", "#nothiddendiv div", function() {
+ livee++;
+ } );
jQuery( "#body" ).on( "click", "#nothiddendiv div", clickB );
- jQuery( "#body" ).on( "mouseover", "#nothiddendiv div", function() { livee++; } );
+ jQuery( "#body" ).on( "mouseover", "#nothiddendiv div", function() {
+ livee++;
+ } );
assert.equal( livee, 0, "No clicks, deep selector." );
@@ -1796,12 +1860,56 @@ QUnit.test( "jQuery.off using dispatched jQuery.Event", function( assert ) {
.remove();
} );
+QUnit.test( "events with type matching an Object.prototype property (gh-3256)", function( assert ) {
+ assert.expect( 1 );
+
+ var elem = jQuery( "
" ),
+ eventFired = false;
+
+ elem.appendTo( "#qunit-fixture" );
+
+ try {
+ elem
+ .one( "hasOwnProperty", function() {
+ eventFired = true;
+ } )
+ .trigger( "hasOwnProperty" );
+ } finally {
+ assert.strictEqual( eventFired, true, "trigger fired without crashing" );
+ }
+} );
+
+QUnit.test( "events with type matching an Object.prototype property, cloned element (gh-3256)",
+ function( assert ) {
+ assert.expect( 1 );
+
+ var elem = jQuery( "
" ),
+ eventFired = false;
+
+ elem.appendTo( "#qunit-fixture" );
+
+ try {
+
+ // Make sure the original element has some event data.
+ elem.on( "click", function() {} );
+
+ elem
+ .clone( true )
+ .one( "hasOwnProperty", function() {
+ eventFired = true;
+ } )
+ .trigger( "hasOwnProperty" );
+ } finally {
+ assert.strictEqual( eventFired, true, "trigger fired without crashing" );
+ }
+} );
+
// selector-native does not support scope-fixing in delegation
-QUnit[ jQuery.find.compile ? "test" : "skip" ]( "delegated event with delegateTarget-relative selector", function( assert ) {
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "delegated event with delegateTarget-relative selector", function( assert ) {
assert.expect( 3 );
var markup = jQuery( "" ).appendTo( "#qunit-fixture" );
- // Non-positional selector (#12383)
+ // Non-positional selector (trac-12383)
markup.find( "#ul0" )
.on( "click", "div li a", function() {
assert.ok( false, "div is ABOVE the delegation point!" );
@@ -1815,23 +1923,29 @@ QUnit[ jQuery.find.compile ? "test" : "skip" ]( "delegated event with delegateTa
.find( "#a0_0" ).trigger( "click" ).end()
.off( "click" );
- // Positional selector (#11315)
- markup.find( "ul" ).eq( 0 )
- .on( "click", ">li>a", function() {
- assert.ok( this.id === "a0", "child li was clicked" );
- } )
- .find( "#ul0" )
- .on( "click", "li:first>a", function() {
- assert.ok( this.id === "a0_0", "first li under #u10 was clicked" );
+ if ( QUnit.jQuerySelectorsPos ) {
+
+ // Positional selector (trac-11315)
+ markup.find( "ul" ).eq( 0 )
+ .on( "click", ">li>a", function() {
+ assert.ok( this.id === "a0", "child li was clicked" );
} )
- .end()
- .find( "a" ).trigger( "click" ).end()
- .find( "#ul0" ).off();
+ .find( "#ul0" )
+ .on( "click", "li:first>a", function() {
+ assert.ok( this.id === "a0_0", "first li under #u10 was clicked" );
+ } )
+ .end()
+ .find( "a" ).trigger( "click" ).end()
+ .find( "#ul0" ).off();
+ } else {
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ }
markup.remove();
} );
-QUnit.test( "delegated event with selector matching Object.prototype property (#13203)", function( assert ) {
+QUnit.test( "delegated event with selector matching Object.prototype property (trac-13203)", function( assert ) {
assert.expect( 1 );
var matched = 0;
@@ -1845,7 +1959,7 @@ QUnit.test( "delegated event with selector matching Object.prototype property (#
assert.equal( matched, 0, "Nothing matched 'toString'" );
} );
-QUnit.test( "delegated event with intermediate DOM manipulation (#13208)", function( assert ) {
+QUnit.test( "delegated event with intermediate DOM manipulation (trac-13208)", function( assert ) {
assert.expect( 1 );
jQuery( "#foo" ).on( "click", "[id=sap]", function() {} );
@@ -1906,8 +2020,12 @@ QUnit.test( "off all bound delegated events", function( assert ) {
clicks = 0,
div = jQuery( "#body" );
- div.on( "click submit", "div#nothiddendivchild", function() { count++; } );
- div.on( "click", function() { clicks++; } );
+ div.on( "click submit", "div#nothiddendivchild", function() {
+ count++;
+ } );
+ div.on( "click", function() {
+ clicks++;
+ } );
div.off( undefined, "**" );
jQuery( "div#nothiddendivchild" ).trigger( "click" );
@@ -1926,7 +2044,9 @@ QUnit.test( "on with multiple delegated events", function( assert ) {
var count = 0,
div = jQuery( "#body" );
- div.on( "click submit", "div#nothiddendivchild", function() { count++; } );
+ div.on( "click submit", "div#nothiddendivchild", function() {
+ count++;
+ } );
jQuery( "div#nothiddendivchild" ).trigger( "click" );
jQuery( "div#nothiddendivchild" ).trigger( "submit" );
@@ -2124,12 +2244,12 @@ QUnit.test( "focusin bubbles", function( assert ) {
// Removed since DOM focus is unreliable on test swarm
// DOM focus method
-// input[0].focus();
+// input[ 0 ].focus();
// To make the next focus test work, we need to take focus off the input.
// This will fire another focusin event, so set order to reflect that.
// order = 1;
-// jQuery("#text1")[0].focus();
+// jQuery( "#text1" )[ 0 ].focus();
// jQuery trigger, which calls DOM focus
order = 0;
@@ -2139,7 +2259,43 @@ QUnit.test( "focusin bubbles", function( assert ) {
jQuery( "body" ).off( "focusin.focusinBubblesTest" );
} );
-QUnit.test( "custom events with colons (#3533, #8272)", function( assert ) {
+QUnit.test( "focus does not bubble", function( assert ) {
+ assert.expect( 1 );
+
+ var done = assert.async(),
+ input = jQuery( " " ).prependTo( "body" );
+
+ // focus the element so DOM focus won't fire
+ input[ 0 ].focus();
+
+ jQuery( "body" ).on( "focus.focusDoesNotBubbleTest", function() {
+ assert.ok( false, "focus doesn't fire on body" );
+ } );
+
+ input.on( "focus.focusDoesNotBubbleTest", function() {
+ assert.ok( true, "focus on the element" );
+ } );
+
+// Removed since DOM focus is unreliable on test swarm
+ // DOM focus method
+// input[ 0 ].focus();
+
+ // To make the next focus test work, we need to take focus off the input.
+ // This will fire another focusin event, so set order to reflect that.
+// jQuery( "#text1" )[ 0 ].focus();
+
+ // jQuery trigger, which calls DOM focus
+ input.trigger( "focus" );
+
+ input.remove();
+ jQuery( "body" ).off( "focus.focusDoesNotBubbleTest" );
+
+ setTimeout( function() {
+ done();
+ }, 50 );
+} );
+
+QUnit.test( "custom events with colons (trac-3533, trac-8272)", function( assert ) {
assert.expect( 1 );
var tab = jQuery( "" ).appendTo( "body" );
@@ -2245,7 +2401,7 @@ QUnit.test( ".on and .off", function( assert ) {
// We should have removed all the event handlers ... kinda hacky way to check this
data = jQuery.data[ jQuery( "#onandoff" )[ 0 ].expando ] || {};
- assert.equal( data[ "events" ], undefined, "no events left" );
+ assert.equal( data.events, undefined, "no events left" );
$onandoff.remove();
} );
@@ -2319,10 +2475,10 @@ QUnit.test( "special on name mapping", function( assert ) {
.trigger( "gutfeeling" ) // This one should not
.remove();
- delete jQuery.event.special[ "gutfeeling" ];
+ delete jQuery.event.special.gutfeeling;
} );
-QUnit.test( ".on and .off, selective mixed removal (#10705)", function( assert ) {
+QUnit.test( ".on and .off, selective mixed removal (trac-10705)", function( assert ) {
assert.expect( 7 );
var timingx = function( e ) {
@@ -2344,7 +2500,27 @@ QUnit.test( ".on and .off, selective mixed removal (#10705)", function( assert )
.trigger( "click" ); // 0
} );
-QUnit.test( ".on( event-map, null-selector, data ) #11130", function( assert ) {
+QUnit.test( "special interference with Object.prototype", function( assert ) {
+ assert.expect( 1 );
+
+ var triggered = false;
+
+ Object.prototype.jqfake = {
+ trigger: function() {
+ triggered = true;
+ }
+ };
+
+ jQuery( "
" )
+ .appendTo( "#qunit-fixture" )
+ .trigger( "jqfake" );
+
+ delete Object.prototype.jqfake;
+
+ assert.ok( !triggered, "Object.prototype.jqfake.trigger not called" );
+} );
+
+QUnit.test( ".on( event-map, null-selector, data ) trac-11130", function( assert ) {
assert.expect( 1 );
@@ -2360,7 +2536,7 @@ QUnit.test( ".on( event-map, null-selector, data ) #11130", function( assert ) {
$p.on( map, null, data ).trigger( "foo" );
} );
-QUnit.test( "clone() delegated events (#11076)", function( assert ) {
+QUnit.test( "clone() delegated events (trac-11076)", function( assert ) {
assert.expect( 3 );
var counter = { "center": 0, "fold": 0, "centerfold": 0 },
@@ -2434,7 +2610,7 @@ QUnit.test( "event object properties on natively-triggered event", function( ass
$link = jQuery( link ),
evt = document.createEvent( "MouseEvents" );
- // Support: IE <=9 - 11 only
+ // Support: IE <=9 - 11+
// IE requires element to be in the body before it will dispatch
$link.appendTo( "body" ).on( "click", function( e ) {
@@ -2460,7 +2636,9 @@ QUnit.test( "addProp extensions", function( assert ) {
fireNative( $fixture[ 0 ], "click" );
$fixture.off( "click" );
- jQuery.event.addProp( "testProperty", function() { return 42; } );
+ jQuery.event.addProp( "testProperty", function() {
+ return 42;
+ } );
// Trigger a native click and ensure the property is set
$fixture.on( "click", function( event ) {
@@ -2490,7 +2668,7 @@ QUnit.test( "drag/drop events copy mouse-related event properties (gh-1925, gh-2
fireNative( $fixture[ 0 ], "drop" );
- $fixture.unbind( "dragmove drop" ).remove();
+ $fixture.off( "dragmove drop" ).remove();
} );
QUnit.test( "focusin using non-element targets", function( assert ) {
@@ -2512,38 +2690,115 @@ testIframe(
function( assert, framejQuery, frameWin, frameDoc ) {
assert.expect( 1 );
- var input = jQuery( frameDoc ).find( "#frame-input" );
+ var done = assert.async(),
+ focus = false,
+ input = jQuery( frameDoc ).find( "#frame-input" );
// Create a focusin handler on the parent; shouldn't affect the iframe's fate
jQuery( "body" ).on( "focusin.iframeTest", function() {
- assert.ok( false, "fired a focusin event in the parent document" );
+
+ // Support: IE 9 - 11+
+ // IE does propagate the event to the parent document. In this test
+ // we mainly care about the inner element so we'll just skip this one
+ // assertion in IE.
+ if ( !document.documentMode ) {
+ assert.ok( false, "fired a focusin event in the parent document" );
+ }
} );
input.on( "focusin", function() {
+ focus = true;
assert.ok( true, "fired a focusin event in the iframe" );
} );
// Avoid a native event; Chrome can't force focus to another frame
- input.trigger( "focusin" );
-
- // Must manually remove handler to avoid leaks in our data store
- input.remove();
-
- // Be sure it was removed; nothing should happen
- input.trigger( "focusin" );
+ input[ 0 ].focus();
// Remove body handler manually since it's outside the fixture
jQuery( "body" ).off( "focusin.iframeTest" );
+
+ setTimeout( function() {
+
+ // DOM focus is unreliable in TestSwarm
+ if ( QUnit.isSwarm && !focus ) {
+ assert.ok( true, "GAP: Could not observe focus change" );
+ }
+
+ done();
+ }, 50 );
}
);
+QUnit.test( "focusin on document & window", function( assert ) {
+ assert.expect( 1 );
+
+ var counter = 0,
+ input = jQuery( " " );
+
+ function increment() {
+ counter++;
+ }
+
+ input.appendTo( "#qunit-fixture" );
+
+ input[ 0 ].focus();
+
+ jQuery( window ).on( "focusout", increment );
+ jQuery( document ).on( "focusout", increment );
+
+ input[ 0 ].blur();
+
+ // DOM focus is unreliable in TestSwarm
+ if ( QUnit.isSwarm && counter === 0 ) {
+ assert.ok( true, "GAP: Could not observe focus change" );
+ }
+
+ assert.strictEqual( counter, 2,
+ "focusout handlers on document/window fired once only" );
+
+ jQuery( window ).off( "focusout", increment );
+ jQuery( document ).off( "focusout", increment );
+} );
+
+QUnit.test( "element removed during focusout (gh-4417)", function( assert ) {
+ assert.expect( 1 );
+
+ var button = jQuery( "Click me " );
+
+ button.appendTo( "#qunit-fixture" );
+
+ button.on( "click", function() {
+ button.trigger( "blur" );
+ assert.ok( true, "Removing the element didn't crash" );
+ } );
+
+ // Support: Chrome 86+
+ // In Chrome, if an element having a focusout handler is blurred by
+ // clicking outside of it, it invokes the handler synchronously. However,
+ // if the click happens programmatically, the invocation is asynchronous.
+ // As we have no way to simulate real user input in unit tests, simulate
+ // this behavior by calling `jQuery.cleanData` & removing the element using
+ // native APIs.
+ button[ 0 ].blur = function() {
+ jQuery.cleanData( [ this ] );
+ this.parentNode.removeChild( this );
+
+ // Redefine `blur` to avoid a hard crash in Karma tests that stop
+ // the test runner in case this test fails.
+ this.blur = jQuery.noop;
+ };
+
+ button[ 0 ].click();
+} );
+
testIframe(
"jQuery.ready promise",
"event/promiseReady.html",
function( assert, jQuery, window, document, isOk ) {
assert.expect( 1 );
assert.ok( isOk, "$.when( $.ready ) works" );
- }
+ },
+ jQuery.when ? QUnit.test : QUnit.skip
);
// need PHP here to make the incepted IFRAME hang
@@ -2624,7 +2879,7 @@ QUnit.test( "trigger click on checkbox, fires change event", function( assert )
} ).trigger( "click" );
} );
-QUnit.test( "Namespace preserved when passed an Event (#12739)", function( assert ) {
+QUnit.test( "Namespace preserved when passed an Event (trac-12739)", function( assert ) {
assert.expect( 4 );
var markup = jQuery(
@@ -2712,7 +2967,7 @@ QUnit.test( "make sure events cloned correctly", function( assert ) {
clone.find( "#check1" ).trigger( "change" ); // 0 events should fire
} );
-QUnit.test( "String.prototype.namespace does not cause trigger() to throw (#13360)", function( assert ) {
+QUnit.test( "String.prototype.namespace does not cause trigger() to throw (trac-13360)", function( assert ) {
assert.expect( 1 );
var errored = false;
@@ -2727,7 +2982,7 @@ QUnit.test( "String.prototype.namespace does not cause trigger() to throw (#1336
delete String.prototype.namespace;
} );
-QUnit.test( "Inline event result is returned (#13993)", function( assert ) {
+QUnit.test( "Inline event result is returned (trac-13993)", function( assert ) {
assert.expect( 1 );
var result = jQuery( "hello
" ).triggerHandler( "click" );
@@ -2739,7 +2994,7 @@ QUnit.test( ".off() removes the expando when there's no more data", function( as
assert.expect( 2 );
var key,
- div = jQuery( "
" ).appendTo( "#qunit-fixture" );
+ div = jQuery( "
" ).appendTo( "#qunit-fixture" );
div.on( "click", false );
div.on( "custom", function() {
@@ -2806,6 +3061,15 @@ QUnit.test( "preventDefault() on focusin does not throw exception", function( as
}, QUnit.config.testTimeout / 4 || 1000 );
} );
+QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) {
+ assert.expect( 1 );
+
+ jQuery( document.createTextNode( "text" ) )
+ .on( "focus", function() {} );
+
+ assert.ok( true, "No crash" );
+} );
+
QUnit.test( "Donor event interference", function( assert ) {
assert.expect( 8 );
@@ -2931,114 +3195,203 @@ QUnit.test( "trigger('click') on radio passes extra params", function( assert )
$radio.trigger( "click", [ true ] );
} );
-// Support: IE <=9 only
-// https://msdn.microsoft.com/en-us/library/hh801223(v=vs.85).aspx
-QUnit.test( "VML with special event handlers (trac-7071)", function( assert ) {
- assert.expect( 1 );
+QUnit.test( "focusout/focusin support", function( assert ) {
+ assert.expect( 6 );
- var ns = jQuery( " " ).appendTo( "head" );
+ var focus,
+ parent = jQuery( "" ),
+ input = jQuery( "
" ),
+ inputExternal = jQuery( "
" );
- jQuery( "
" ).appendTo( "#form" );
- jQuery( "#form" ).on( "keydown", function() {
- assert.ok( true, "no error was thrown" );
- } );
- jQuery( "#oval" ).trigger( "click" ).trigger( "keydown" );
- ns.remove();
-} );
+ parent.append( input );
+ jQuery( "#qunit-fixture" ).append( parent ).append( inputExternal );
-QUnit.test( "Check order of focusin/focusout events", function( assert ) {
- assert.expect( 2 );
+ // initially, lose focus
+ inputExternal[ 0 ].focus();
- var focus, blur,
- input = jQuery( "#name" );
+ parent
+ .on( "focus", function() {
+ assert.ok( false, "parent: focus not fired" );
+ } )
+ .on( "focusin", function() {
+ assert.ok( true, "parent: focusin fired" );
+ } )
+ .on( "blur", function() {
+ assert.ok( false, "parent: blur not fired" );
+ } )
+ .on( "focusout", function() {
+ assert.ok( true, "parent: focusout fired" );
+ } );
input
.on( "focus", function() {
- focus = true;
+ assert.ok( true, "element: focus fired" );
} )
.on( "focusin", function() {
- assert.ok( !focus, "Focusin event should fire before focus does" );
+ assert.ok( true, "element: focusin fired" );
focus = true;
} )
.on( "blur", function() {
- blur = true;
+ assert.ok( true, "parent: blur fired" );
} )
.on( "focusout", function() {
- assert.ok( !blur, "Focusout event should fire before blur does" );
- blur = true;
+ assert.ok( true, "element: focusout fired" );
} );
// gain focus
- input.trigger( "focus" );
+ input[ 0 ].focus();
// then lose it
- jQuery( "#search" ).trigger( "focus" );
-
- // cleanup
- input.off();
+ inputExternal[ 0 ].focus();
// DOM focus is unreliable in TestSwarm
- if ( !focus ) {
+ if ( QUnit.isSwarm && !focus ) {
+ assert.ok( true, "GAP: Could not observe focus change" );
+ assert.ok( true, "GAP: Could not observe focus change" );
+ assert.ok( true, "GAP: Could not observe focus change" );
+ assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
assert.ok( true, "GAP: Could not observe focus change" );
}
+
+ // cleanup
+ parent.off();
+ input.off();
} );
-QUnit.test( "focus-blur order (#12868)", function( assert ) {
+QUnit.test( "focus-blur order (trac-12868)", function( assert ) {
assert.expect( 5 );
var order,
$text = jQuery( "#text1" ),
- $radio = jQuery( "#radio1" ),
-
- // Support: IE <=9 - 11+
- // focus and blur events are asynchronous; this is the resulting mess.
- // The browser window must be topmost for this to work properly!!
- done = assert.async();
+ $radio = jQuery( "#radio1" );
$radio[ 0 ].focus();
- setTimeout( function() {
+ $text
+ .on( "focus", function() {
+ assert.equal( order++, 1, "text focus" );
+ } )
+ .on( "blur", function() {
+ assert.equal( order++, 0, "text blur" );
+ } );
+ $radio
+ .on( "focus", function() {
+ assert.equal( order++, 1, "radio focus" );
+ } )
+ .on( "blur", function() {
+ assert.equal( order++, 0, "radio blur" );
+ } );
- $text
- .on( "focus", function() {
- assert.equal( order++, 1, "text focus" );
- } )
- .on( "blur", function() {
- assert.equal( order++, 0, "text blur" );
+ // Enabled input getting focus
+ order = 0;
+ assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" );
+ $text.trigger( "focus" );
+
+ // DOM focus is unreliable in TestSwarm
+ if ( QUnit.isSwarm && order === 0 ) {
+ assert.ok( true, "GAP: Could not observe focus change" );
+ assert.ok( true, "GAP: Could not observe focus change" );
+ }
+
+ assert.equal( document.activeElement, $text[ 0 ], "text has focus" );
+
+ // Run handlers without native method on an input
+ order = 1;
+ $radio.triggerHandler( "focus" );
+
+ // Clean up
+ $text.off();
+ $radio.off();
+} );
+
+QUnit.test( "Event handling works with multiple async focus events (gh-4350)", function( assert ) {
+ assert.expect( 3 );
+
+ var remaining = 3,
+ input = jQuery( "#name" ),
+ done = assert.async();
+
+ input
+ .on( "focus", function() {
+ remaining--;
+ assert.ok( true, "received focus event, expecting " + remaining + " more" );
+ if ( remaining > 0 ) {
+ input.trigger( "blur" );
+ } else {
+
+ if ( QUnit.isIE ) {
+
+ // Support: <=IE 11+
+ // In IE, one of the blurs sometimes triggers a focus on body
+ // which in turn restores focus to the input, leading to 4 assertions
+ // firing instead of three. This only happens if other tests are
+ // running on the same test page. Avoid this issue in tests by removing
+ // the handler early.
+ input.off( "focus" );
+ }
+ done();
+ }
+ } )
+ .on( "blur", function() {
+ setTimeout( function() {
+ input.trigger( "focus" );
} );
- $radio
- .on( "focus", function() {
- assert.equal( order++, 1, "radio focus" );
- } )
- .on( "blur", function() {
- assert.equal( order++, 0, "radio blur" );
+ } );
+
+ // gain focus
+ input.trigger( "focus" );
+
+ // DOM focus is unreliable in TestSwarm
+ setTimeout( function() {
+ if ( QUnit.isSwarm && remaining === 3 ) {
+ assert.ok( true, "GAP: Could not observe focus change" );
+ assert.ok( true, "GAP: Could not observe focus change" );
+ assert.ok( true, "GAP: Could not observe focus change" );
+ setTimeout( function() {
+ done();
} );
+ }
+ } );
+} );
- // Enabled input getting focus
- order = 0;
- assert.equal( document.activeElement, $radio[ 0 ], "radio has focus" );
- $text.trigger( "focus" );
- setTimeout( function() {
+// Support: IE <=9 - 11+
+// focus and blur events are asynchronous.
+// The browser window must be topmost for this to work properly!!
+QUnit.test( "async focus queues properly (gh-4859)", function( assert ) {
+ assert.expect( 1 );
- // DOM focus is unreliable in TestSwarm
- if ( order === 0 ) {
- assert.ok( true, "GAP: Could not observe focus change" );
- assert.ok( true, "GAP: Could not observe focus change" );
- }
+ var $text = jQuery( "#text1" ),
+ $radio = jQuery( "#radio1" ),
+ done = assert.async();
+
+ $text.trigger( "focus" );
+ $radio.trigger( "focus" );
+ $text.trigger( "focus" );
- assert.equal( document.activeElement, $text[ 0 ], "text has focus" );
+ setTimeout( function() {
+ assert.equal( document.activeElement, $text[ 0 ], "focus follows the last trigger" );
+ done();
+ }, 500 );
+} );
- // Run handlers without native method on an input
- order = 1;
- $radio.triggerHandler( "focus" );
+// Support: IE <=9 - 11+
+// focus and blur events are asynchronous.
+// The browser window must be topmost for this to work properly!!
+QUnit.test( "async focus queues properly with blur (gh-4856)", function( assert ) {
+ assert.expect( 1 );
- // Clean up
- $text.off();
- $radio.off();
- done();
- }, 50 );
- }, 50 );
+ var $text = jQuery( "#text1" ),
+ done = assert.async();
+
+ $text.trigger( "focus" );
+ $text.trigger( "blur" );
+ $text.trigger( "focus" );
+
+ setTimeout( function() {
+ assert.equal( document.activeElement, $text[ 0 ], "focus-after-blur is respected" );
+ done();
+ }, 500 );
} );
QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", function( assert ) {
@@ -3050,12 +3403,7 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
targets = jQuery( parent[ 0 ].childNodes ),
checkbox = jQuery( targets[ 0 ] ),
data = [ "arg1", "arg2" ],
- slice = data.slice,
-
- // Support: IE <=9 - 11+
- // focus and blur events are asynchronous; this is the resulting mess.
- // The browser window must be topmost for this to work properly!!
- done = assert.async();
+ slice = data.slice;
// click (gh-4139)
assert.strictEqual( targets[ 0 ].checked, false, "checkbox unchecked before click" );
@@ -3081,18 +3429,123 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
var type = event.type;
assert.deepEqual( slice.call( arguments, 1 ), data,
type + " handler received correct data" );
+
+ if ( QUnit.isIE && type === "focus" ) {
+
+ // Support: <=IE 11+
+ // In IE, one of the blurs sometimes triggers a focus on body
+ // which in turn restores focus to the input, leading to 4 assertions
+ // firing instead of three. This only happens if other tests are
+ // running on the same test page. Avoid this issue in tests by removing
+ // the handler early.
+ checkbox.off( "focus" );
+ }
} );
checkbox.trigger( "focus", data );
+
+ assert.strictEqual( document.activeElement, checkbox[ 0 ],
+ "element focused after focus event (default action)" );
+ checkbox.trigger( "blur", data );
+
+ assert.notEqual( document.activeElement, checkbox[ 0 ],
+ "element not focused after blur event (default action)" );
+} );
+
+QUnit.test( "focus change during a focus handler (gh-4382)", function( assert ) {
+ assert.expect( 2 );
+
+ var done = assert.async(),
+ select = jQuery( "
A " ),
+ button = jQuery( "
Focus target " );
+
+ jQuery( "#qunit-fixture" )
+ .append( select )
+ .append( button );
+
+ select.on( "focus", function() {
+ button.trigger( "focus" );
+ } );
+
+ jQuery( document ).on( "focusin.focusTests", function( ev ) {
+
+ // Support: IE 11+
+ // In IE focus is async so focusin on document is fired multiple times,
+ // for each of the elements. In other browsers it's fired just once, for
+ // the last one.
+ if ( ev.target === button[ 0 ] ) {
+ assert.ok( true, "focusin propagated to document from the button" );
+ }
+ } );
+
+ select.trigger( "focus" );
+
setTimeout( function() {
- assert.strictEqual( document.activeElement, checkbox[ 0 ],
- "element focused after focus event (default action)" );
- checkbox.trigger( "blur", data );
- setTimeout( function() {
- assert.notEqual( document.activeElement, checkbox[ 0 ],
- "element not focused after blur event (default action)" );
- done();
- }, 50 );
- }, 50 );
+ assert.strictEqual( document.activeElement, button[ 0 ], "Focus redirect worked" );
+ jQuery( document ).off( ".focusTests" );
+ done();
+ } );
+} );
+
+QUnit.test( "trigger(focus) works after .on(focus).off(focus) (gh-4867)", function( assert ) {
+ assert.expect( 1 );
+
+ var input = jQuery( "
" );
+
+ input.appendTo( "#qunit-fixture" );
+
+ input
+ .on( "focus", function() {} )
+ .off( "focus" );
+
+ input.trigger( "focus" );
+
+ assert.equal( document.activeElement, input[ 0 ], "input has focus" );
+} );
+
+QUnit.test( "trigger(focus) works after focusing when hidden (gh-4950)", function( assert ) {
+ assert.expect( 1 );
+
+ var input = jQuery( "
" );
+
+ input.appendTo( "#qunit-fixture" );
+
+ input
+ .css( "display", "none" )
+ .trigger( "focus" )
+ .css( "display", "" )
+ .trigger( "focus" );
+
+ assert.equal( document.activeElement, input[ 0 ], "input has focus" );
+} );
+
+QUnit.test( "trigger(focus) fires native & jQuery handlers (gh-5015)", function( assert ) {
+ assert.expect( 3 );
+
+ var input = jQuery( "
" ),
+
+ // Support: IE 9 - 11+
+ // focus is async in IE; we now emulate it via sync focusin in jQuery
+ // but this test also attaches native handlers.
+ done = assert.async( 3 );
+
+ input.appendTo( "#qunit-fixture" );
+
+ input[ 0 ].addEventListener( "focus", function() {
+ assert.ok( true, "1st native handler fired" );
+ done();
+ } );
+
+ input.on( "focus", function() {
+ assert.ok( true, "jQuery handler fired" );
+ done();
+ } );
+
+ input[ 0 ].addEventListener( "focus", function() {
+ assert.ok( true, "2nd native handler fired" );
+ done();
+ } );
+
+ input.trigger( "focus" );
} );
// TODO replace with an adaptation of
@@ -3103,10 +3556,13 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
checkbox: "
",
radio: "
"
},
- makeTestFor3751
+ function( type, html ) {
+ makeTestForGh3751( type, html );
+ makeTestForGh5015( type, html );
+ }
);
- function makeTestFor3751( type, html ) {
+ function makeTestForGh3751( type, html ) {
var testName = "native-backed namespaced clicks are handled correctly (gh-3751) - " + type;
QUnit.test( testName, function( assert ) {
assert.expect( 2 );
@@ -3133,4 +3589,30 @@ QUnit.test( "native-backed events preserve trigger data (gh-1741, gh-4139)", fun
target.trigger( "click.fired" );
} );
}
+
+ function makeTestForGh5015( type, html ) {
+ var testName = "trigger(click) fires native & jQuery handlers (gh-5015) - " + type;
+ QUnit.test( testName, function( assert ) {
+ assert.expect( 3 );
+
+ var parent = supportjQuery( "
" + html + "
" ),
+ input = jQuery( parent[ 0 ].firstChild );
+
+ parent.appendTo( "#qunit-fixture" );
+
+ input[ 0 ].addEventListener( "click", function() {
+ assert.ok( true, "1st native handler fired" );
+ } );
+
+ input.on( "click", function() {
+ assert.ok( true, "jQuery handler fired" );
+ } );
+
+ input[ 0 ].addEventListener( "click", function() {
+ assert.ok( true, "2nd native handler fired" );
+ } );
+
+ input.trigger( "click" );
+ } );
+ }
} )();
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index b0d3e3a884..8be07c1df0 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -30,18 +30,18 @@ function manipulationFunctionReturningObj( value ) {
QUnit.test( "text()", function( assert ) {
- assert.expect( 5 );
+ assert.expect( 6 );
- var expected, frag, $newLineTest;
+ var expected, frag, $newLineTest, doc;
expected = "This link has class=\"blog\": Simon Willison's Weblog";
assert.equal( jQuery( "#sap" ).text(), expected, "Check for merged text of more then one element." );
// Check serialization of text values
assert.equal( jQuery( document.createTextNode( "foo" ) ).text(), "foo", "Text node was retrieved from .text()." );
- assert.notEqual( jQuery( document ).text(), "", "Retrieving text for the document retrieves all text (#10724)." );
+ assert.notEqual( jQuery( document ).text(), "", "Retrieving text for the document retrieves all text (trac-10724)." );
- // Retrieve from document fragments #10864
+ // Retrieve from document fragments trac-10864
frag = document.createDocumentFragment();
frag.appendChild( document.createTextNode( "foo" ) );
@@ -49,16 +49,19 @@ QUnit.test( "text()", function( assert ) {
$newLineTest = jQuery( "
test testy
" ).appendTo( "#moretests" );
$newLineTest.find( "br" ).replaceWith( "\n" );
- assert.equal( $newLineTest.text(), "test\ntesty", "text() does not remove new lines (#11153)" );
+ assert.equal( $newLineTest.text(), "test\ntesty", "text() does not remove new lines (trac-11153)" );
$newLineTest.remove();
+
+ doc = new DOMParser().parseFromString( "
example ", "text/html" );
+ assert.equal( jQuery( doc ).text(), "example", "text() on HTMLDocument (gh-5264)" );
} );
QUnit.test( "text(undefined)", function( assert ) {
assert.expect( 1 );
- assert.equal( jQuery( "#foo" ).text( "
Hello
" ).add( "
World
" );
$multipleElements.text( expected );
- assert.equal( $multipleElements.eq( 0 ).text(), expected, "text() updates multiple elements (#11809)" );
- assert.equal( $multipleElements.eq( 1 ).text(), expected, "text() updates multiple elements (#11809)" );
+ assert.equal( $multipleElements.eq( 0 ).text(), expected, "text() updates multiple elements (trac-11809)" );
+ assert.equal( $multipleElements.eq( 1 ).text(), expected, "text() updates multiple elements (trac-11809)" );
- // Prevent memory leaks #11809
- $childDiv = jQuery( "
" );
+ // Prevent memory leaks trac-11809
+ $childDiv = jQuery( "
" );
$childDiv.data( "leak", true );
- $parentDiv = jQuery( "
" );
+ $parentDiv = jQuery( "
" );
$parentDiv.append( $childDiv );
$parentDiv.text( "Dry off" );
}
@@ -187,13 +190,13 @@ function testAppendForObject( valueObj, isFragment, assert ) {
assert.equal( $base.clone().append( valueObj( document.getElementById( "form" ).cloneNode( true ) ) ).children( "form" ).length,
1,
- "Check for appending a form (#910)" + type
+ "Check for appending a form (trac-910)" + type
);
}
function testAppend( valueObj, assert ) {
- assert.expect( 78 );
+ assert.expect( 82 );
testAppendForObject( valueObj, false, assert );
testAppendForObject( valueObj, true, assert );
@@ -214,12 +217,12 @@ function testAppend( valueObj, assert ) {
jQuery( "#qunit-fixture form" ).append( valueObj( "
" ) );
jQuery( "#qunit-fixture form input[name=radiotest2]" ).each( function() {
- assert.ok( jQuery( this ).is( ":checked" ), "Append alternately formated checked radio" );
+ assert.ok( jQuery( this ).is( ":checked" ), "Append alternately formatted checked radio" );
} ).remove();
jQuery( "#qunit-fixture form" ).append( valueObj( "
" ) );
jQuery( "#qunit-fixture form input[name=radiotest3]" ).each( function() {
- assert.ok( jQuery( this ).is( ":checked" ), "Append HTML5-formated checked radio" );
+ assert.ok( jQuery( this ).is( ":checked" ), "Append HTML5-formatted checked radio" );
} ).remove();
jQuery( "#qunit-fixture form" ).append( valueObj( "
" ) );
@@ -241,10 +244,10 @@ function testAppend( valueObj, assert ) {
assert.strictEqual( e.message || e, undefined, message );
}
- jQuery( "
" ).appendTo( "#form" ).append( valueObj( "
test " ) );
+ jQuery( "
" ).appendTo( "#form" ).append( valueObj( "
test " ) );
assert.t( "Append legend", "#legend", [ "legend" ] );
- $map = jQuery( "
" ).append( valueObj( "
" ) );
+ $map = jQuery( "
" ).append( valueObj( "
" ) );
assert.equal( $map[ 0 ].childNodes.length, 1, "The area was inserted." );
assert.equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
@@ -264,7 +267,7 @@ function testAppend( valueObj, assert ) {
assert.ok( jQuery.parseHTML( "<" + name + "/>" ).length, name + " wrapped correctly" );
} );
- jQuery( "#table colgroup" ).append( valueObj( "
" ) );
+ jQuery( "#table colgroup" ).append( valueObj( "
" ) );
assert.equal( jQuery( "#table colgroup col" ).length, 1, "Append col" );
jQuery( "#form" )
@@ -272,12 +275,12 @@ function testAppend( valueObj, assert ) {
.append( valueObj( "
Test " ) );
assert.t( "Append Select", "#appendSelect1, #appendSelect2", [ "appendSelect1", "appendSelect2" ] );
- assert.equal( "Two nodes", jQuery( "
" ).append( "Two", " nodes" ).text(), "Appending two text nodes (#4011)" );
- assert.equal( jQuery( "
" ).append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" );
+ assert.equal( "Two nodes", jQuery( "
" ).append( "Two", " nodes" ).text(), "Appending two text nodes (trac-4011)" );
+ assert.equal( jQuery( "
" ).append( "1", "", 3 ).text(), "13", "If median is false-like value, subsequent arguments should not be ignored" );
// using contents will get comments regular, text, and comment nodes
j = jQuery( "#nonnodes" ).contents();
- d = jQuery( "
" ).appendTo( "#nonnodes" ).append( j );
+ d = jQuery( "
" ).appendTo( "#nonnodes" ).append( j );
assert.equal( jQuery( "#nonnodes" ).length, 1, "Check node,textnode,comment append moved leaving just the div" );
assert.equal( d.contents().length, 3, "Check node,textnode,comment append works" );
@@ -294,12 +297,12 @@ function testAppend( valueObj, assert ) {
$radioChecked.trigger( "click" );
$radioUnchecked[ 0 ].checked = false;
- jQuery( "
" ).insertBefore( $radioParent ).append( $radioParent );
+ jQuery( "
" ).insertBefore( $radioParent ).append( $radioParent );
assert.equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" );
assert.equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" );
- assert.equal( jQuery( "
" ).append( valueObj( "option
" ) )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
+ assert.equal( jQuery( "
" ).append( valueObj( "option
" ) )[ 0 ].childNodes.length, 2, "HTML-string with leading text should be processed correctly" );
}
QUnit.test( "append(String|Element|Array
|jQuery)", function( assert ) {
@@ -310,7 +313,7 @@ QUnit.test( "append(Function)", function( assert ) {
testAppend( manipulationFunctionReturningObj, assert );
} );
-QUnit.test( "append(param) to object, see #11280", function( assert ) {
+QUnit.test( "append(param) to object, see trac-11280", function( assert ) {
assert.expect( 5 );
@@ -402,7 +405,7 @@ QUnit.test( "append(Function) returns Number", function( assert ) {
assert.ok( jQuery( "#sap" )[ 0 ].innerHTML.match( /5$/ ), "Check for appending a number" );
} );
-QUnit.test( "XML DOM manipulation (#9960)", function( assert ) {
+QUnit.test( "XML DOM manipulation (trac-9960)", function( assert ) {
assert.expect( 5 );
@@ -430,7 +433,7 @@ QUnit.test( "XML DOM manipulation (#9960)", function( assert ) {
assert.deepEqual( jQuery( "state", xml2 ).get(), scxml1.find( "state" ).get(), "replaceWith" );
} );
-QUnit.test( "append HTML5 sectioning elements (Bug #6485)", function( assert ) {
+QUnit.test( "append HTML5 sectioning elements (Bug trac-6485)", function( assert ) {
assert.expect( 2 );
@@ -445,20 +448,18 @@ QUnit.test( "append HTML5 sectioning elements (Bug #6485)", function( assert ) {
assert.equal( aside.length, 1, "HTML5 elements do not collapse their children" );
} );
-if ( jQuery.css ) {
- QUnit.test( "HTML5 Elements inherit styles from style rules (Bug #10501)", function( assert ) {
+QUnit[ includesModule( "css" ) ? "test" : "skip" ]( "HTML5 Elements inherit styles from style rules (Bug trac-10501)", function( assert ) {
- assert.expect( 1 );
+ assert.expect( 1 );
- jQuery( "#qunit-fixture" ).append( " " );
- jQuery( "#article" ).append( "This section should have a pink background. " );
+ jQuery( "#qunit-fixture" ).append( " " );
+ jQuery( "#article" ).append( "This section should have a pink background. " );
- // In IE, the missing background color will claim its value is "transparent"
- assert.notEqual( jQuery( "section" ).css( "background-color" ), "transparent", "HTML5 elements inherit styles" );
- } );
-}
+ // In IE, the missing background color will claim its value is "transparent"
+ assert.notEqual( jQuery( "section" ).css( "background-color" ), "transparent", "HTML5 elements inherit styles" );
+} );
-QUnit.test( "html(String) with HTML5 (Bug #6485)", function( assert ) {
+QUnit.test( "html(String) with HTML5 (Bug trac-6485)", function( assert ) {
assert.expect( 2 );
@@ -467,7 +468,7 @@ QUnit.test( "html(String) with HTML5 (Bug #6485)", function( assert ) {
assert.equal( jQuery( "#qunit-fixture" ).children().children().children().length, 1, "Make sure nested HTML5 elements can hold children." );
} );
-QUnit.test( "html(String) tag-hyphenated elements (Bug #1987)", function( assert ) {
+QUnit.test( "html(String) tag-hyphenated elements (Bug gh-1987)", function( assert ) {
assert.expect( 27 );
@@ -511,18 +512,6 @@ QUnit.test( "Tag name processing respects the HTML Standard (gh-2005)", function
}
function assertSpecialCharsSupport( method, characters ) {
- // Support: Android 4.4 only
- // Chromium < 35 incorrectly upper-cases µ; Android 4.4 uses such a version by default
- // (and its WebView, being un-updatable, will use it for eternity) so we need to blacklist
- // that one for the tests to pass.
- if ( characters === "µ" && /chrome/i.test( navigator.userAgent ) &&
- navigator.userAgent.match( /chrome\/(\d+)/i )[ 1 ] < 35 ) {
- assert.ok( true, "This Chromium version upper-cases µ incorrectly; skip test" );
- assert.ok( true, "This Chromium version upper-cases µ incorrectly; skip test" );
- assert.ok( true, "This Chromium version upper-cases µ incorrectly; skip test" );
- return;
- }
-
var child,
codepoint = characters.charCodeAt( 0 ).toString( 16 ).toUpperCase(),
description = characters.length === 1 ?
@@ -575,7 +564,7 @@ QUnit.test( "IE8 serialization bug", function( assert ) {
assert.equal( wrapper.children( "link" ).length, 1, "Link elements are insertable with .html()" );
} );
-QUnit.test( "html() object element #10324", function( assert ) {
+QUnit.test( "html() object element trac-10324", function( assert ) {
assert.expect( 1 );
@@ -592,28 +581,7 @@ QUnit.test( "append(xml)", function( assert ) {
var xmlDoc, xml1, xml2;
function createXMLDoc() {
-
- // Initialize DOM based upon latest installed MSXML or Netscape
- var elem, n, len,
- aActiveX =
- [ "MSXML6.DomDocument",
- "MSXML3.DomDocument",
- "MSXML2.DomDocument",
- "MSXML.DomDocument",
- "Microsoft.XmlDom" ];
-
- if ( document.implementation && "createDocument" in document.implementation ) {
- return document.implementation.createDocument( "", "", null );
- } else {
-
- // IE
- for ( n = 0, len = aActiveX.length; n < len; n++ ) {
- try {
- elem = new window.ActiveXObject( aActiveX[ n ] );
- return elem;
- } catch ( _ ) {}
- }
- }
+ return document.implementation.createDocument( "", "", null );
}
xmlDoc = createXMLDoc();
@@ -672,7 +640,7 @@ QUnit.test( "appendTo(jQuery)", function( assert ) {
jQuery( "#select1" ).appendTo( "#foo" );
assert.t( "Append select", "#foo select", [ "select1" ] );
- div = jQuery( "
" ).on( "click", function() {
+ div = jQuery( "
" ).on( "click", function() {
assert.ok( true, "Running a cloned click." );
} );
div.appendTo( "#qunit-fixture, #moretests" );
@@ -680,7 +648,7 @@ QUnit.test( "appendTo(jQuery)", function( assert ) {
jQuery( "#qunit-fixture div" ).last().trigger( "click" );
jQuery( "#moretests div" ).last().trigger( "click" );
- div = jQuery( "
" ).appendTo( "#qunit-fixture, #moretests" );
+ div = jQuery( "
" ).appendTo( "#qunit-fixture, #moretests" );
assert.equal( div.length, 2, "appendTo returns the inserted elements" );
@@ -689,7 +657,7 @@ QUnit.test( "appendTo(jQuery)", function( assert ) {
assert.ok( jQuery( "#qunit-fixture div" ).last().hasClass( "test" ), "appendTo element was modified after the insertion" );
assert.ok( jQuery( "#moretests div" ).last().hasClass( "test" ), "appendTo element was modified after the insertion" );
- div = jQuery( "
" );
+ div = jQuery( "
" );
jQuery( "a b " ).filter( "span" ).appendTo( div );
assert.equal( div.children().length, 1, "Make sure the right number of children were inserted." );
@@ -989,12 +957,12 @@ QUnit.test( "before(no-op)", function( assert ) {
assert.expect( 2 );
var set;
- set = jQuery( "
" ).before( "test " );
+ set = jQuery( "
" ).before( "test " );
assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert before a disconnected node should be a no-op" );
assert.equal( set.length, 1, "Insert the element before the disconnected node. should be a no-op" );
} );
-QUnit.test( "before and after w/ empty object (#10812)", function( assert ) {
+QUnit.test( "before and after w/ empty object (trac-10812)", function( assert ) {
assert.expect( 1 );
@@ -1008,8 +976,8 @@ QUnit.test( ".before() and .after() disconnected node", function( assert ) {
assert.expect( 2 );
- assert.equal( jQuery( " " ).before( "
" ).length, 1, "before() on disconnected node is no-op" );
- assert.equal( jQuery( " " ).after( "
" ).length, 1, "after() on disconnected node is no-op" );
+ assert.equal( jQuery( " " ).before( "
" ).length, 1, "before() on disconnected node is no-op" );
+ assert.equal( jQuery( " " ).after( "
" ).length, 1, "after() on disconnected node is no-op" );
} );
QUnit.test( "insert with .before() on disconnected node last", function( assert ) {
@@ -1018,7 +986,7 @@ QUnit.test( "insert with .before() on disconnected node last", function( assert
var expectedBefore = "This is a normal link: bugaYahoo";
- jQuery( "#yahoo" ).add( " " ).before( "buga " );
+ jQuery( "#yahoo" ).add( " " ).before( "buga " );
assert.equal( jQuery( "#en" ).text(), expectedBefore, "Insert String before with disconnected node last" );
} );
@@ -1028,7 +996,7 @@ QUnit.test( "insert with .before() on disconnected node first", function( assert
var expectedBefore = "This is a normal link: bugaYahoo";
- jQuery( " " ).add( "#yahoo" ).before( "buga " );
+ jQuery( " " ).add( "#yahoo" ).before( "buga " );
assert.equal( jQuery( "#en" ).text(), expectedBefore, "Insert String before with disconnected node first" );
} );
@@ -1038,7 +1006,7 @@ QUnit.test( "insert with .before() on disconnected node last", function( assert
var expectedAfter = "This is a normal link: Yahoobuga";
- jQuery( "#yahoo" ).add( " " ).after( "buga " );
+ jQuery( "#yahoo" ).add( " " ).after( "buga " );
assert.equal( jQuery( "#en" ).text(), expectedAfter, "Insert String after with disconnected node last" );
} );
@@ -1048,7 +1016,7 @@ QUnit.test( "insert with .before() on disconnected node last", function( assert
var expectedAfter = "This is a normal link: Yahoobuga";
- jQuery( " " ).add( "#yahoo" ).after( "buga " );
+ jQuery( " " ).add( "#yahoo" ).after( "buga " );
assert.equal( jQuery( "#en" ).text(), expectedAfter, "Insert String after with disconnected node first" );
} );
@@ -1168,7 +1136,7 @@ QUnit.test( ".after(disconnected node)", function( assert ) {
assert.expect( 2 );
- var set = jQuery( "
" ).before( "test " );
+ var set = jQuery( "
" ).before( "test " );
assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "Insert after a disconnected node should be a no-op" );
assert.equal( set.length, 1, "Insert the element after the disconnected node should be a no-op" );
} );
@@ -1230,7 +1198,7 @@ function testReplaceWith( val, assert ) {
assert.ok( !jQuery( "#baz" )[ 0 ], "Verify that original element is gone, after element" );
jQuery( "#bar" ).replaceWith( "
", "...", "
" );
- assert.deepEqual( jQuery( "#yahoo, #baz" ).get(), q( "yahoo", "baz" ), "Replace element with multiple arguments (#13722)" );
+ assert.deepEqual( jQuery( "#yahoo, #baz" ).get(), q( "yahoo", "baz" ), "Replace element with multiple arguments (trac-13722)" );
assert.strictEqual( jQuery( "#yahoo" )[ 0 ].nextSibling, jQuery( "#baz" )[ 0 ].previousSibling, "Argument order preserved" );
assert.deepEqual( jQuery( "#bar" ).get(), [], "Verify that original element is gone, after multiple arguments" );
@@ -1243,17 +1211,17 @@ function testReplaceWith( val, assert ) {
assert.ok( !jQuery( "#groups" )[ 0 ], "Verify that original element is gone, after jQuery collection" );
jQuery( "#mark, #first" ).replaceWith( val( " " ) );
- assert.equal( jQuery( "#qunit-fixture .replacement" ).length, 4, "Replace multiple elements (#12449)" );
+ assert.equal( jQuery( "#qunit-fixture .replacement" ).length, 4, "Replace multiple elements (trac-12449)" );
assert.deepEqual( jQuery( "#mark, #first" ).get(), [], "Verify that original elements are gone, after replace multiple" );
tmp = jQuery( "content " )[ 0 ];
jQuery( "#anchor1" ).contents().replaceWith( val( tmp ) );
assert.deepEqual( jQuery( "#anchor1" ).contents().get(), [ tmp ], "Replace text node with element" );
- tmp = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "click", function() {
+ tmp = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( true, "Newly bound click run." );
} );
- y = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "click", function() {
+ y = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( false, "Previously bound click run." );
} );
child = y.append( "test " ).find( "b" ).on( "click", function() {
@@ -1267,7 +1235,7 @@ function testReplaceWith( val, assert ) {
y.trigger( "click" ); // Shouldn't be run
child.trigger( "click" ); // Shouldn't be run
- y = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "click", function() {
+ y = jQuery( "
" ).appendTo( "#qunit-fixture" ).on( "click", function() {
assert.ok( false, "Previously bound click run." );
} );
child2 = y.append( "test " ).find( "u" ).on( "click", function() {
@@ -1279,19 +1247,19 @@ function testReplaceWith( val, assert ) {
child2.trigger( "click" );
- set = jQuery( "
" ).replaceWith( val( "test " ) );
+ set = jQuery( "
" ).replaceWith( val( "test " ) );
assert.equal( set[ 0 ].nodeName.toLowerCase(), "div", "No effect on a disconnected node." );
assert.equal( set.length, 1, "No effect on a disconnected node." );
assert.equal( set[ 0 ].childNodes.length, 0, "No effect on a disconnected node." );
child = jQuery( "#qunit-fixture" ).children().first();
- $div = jQuery( "
" ).insertBefore( child );
+ $div = jQuery( "
" ).insertBefore( child );
$div.replaceWith( $div );
assert.deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), $div.get(),
"Self-replacement" );
$div.replaceWith( child );
assert.deepEqual( jQuery( "#qunit-fixture" ).children().first().get(), child.get(),
- "Replacement with following sibling (#13810)" );
+ "Replacement with following sibling (trac-13810)" );
assert.deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), [],
"Replacement with following sibling (context removed)" );
@@ -1342,7 +1310,7 @@ QUnit.test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function( ass
assert.expect( 25 );
- var $el = jQuery( "
" ).html( "0
" ),
+ var $el = jQuery( "
" ).html( "0
" ),
expectedHTML = $el.html(),
tests = {
"empty string": "",
@@ -1355,13 +1323,17 @@ QUnit.test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function( ass
};
jQuery.each( tests, function( label, input ) {
- $el.html( " " ).children().replaceWith( input );
+ $el.html( " " ).children().replaceWith( input );
assert.strictEqual( $el.html(), "", "replaceWith(" + label + ")" );
- $el.html( " " ).children().replaceWith( function() { return input; } );
+ $el.html( " " ).children().replaceWith( function() {
+ return input;
+ } );
assert.strictEqual( $el.html(), "", "replaceWith(function returning " + label + ")" );
- $el.html( " " ).children().replaceWith( function( i ) { return input; } );
+ $el.html( " " ).children().replaceWith( function( i ) {
+ return input;
+ } );
assert.strictEqual( $el.html(), "", "replaceWith(other function returning " + label + ")" );
- $el.html( "
" ).children().replaceWith( function( i ) {
+ $el.html( "
" ).children().replaceWith( function( i ) {
return i ?
input :
jQuery( this ).html( i + "" );
@@ -1411,7 +1383,7 @@ QUnit.test( "replaceAll(jQuery)", function( assert ) {
assert.ok( !jQuery( "#yahoo" )[ 0 ], "Verify that original element is gone, after set of elements" );
} );
-QUnit.test( "jQuery.clone() (#8017)", function( assert ) {
+QUnit.test( "jQuery.clone() (trac-8017)", function( assert ) {
assert.expect( 2 );
@@ -1423,7 +1395,7 @@ QUnit.test( "jQuery.clone() (#8017)", function( assert ) {
assert.equal( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" );
} );
-QUnit.test( "append to multiple elements (#8070)", function( assert ) {
+QUnit.test( "append to multiple elements (trac-8070)", function( assert ) {
assert.expect( 2 );
@@ -1482,7 +1454,7 @@ QUnit.test( "clone()", function( assert ) {
div.remove();
// Verify that cloned children can keep event listeners
- div = jQuery( "
" ).append( [ document.createElement( "table" ), document.createElement( "table" ) ] );
+ div = jQuery( "
" ).append( [ document.createElement( "table" ), document.createElement( "table" ) ] );
div.find( "table" ).on( "click", function() {
assert.ok( true, "Bound event still exists." );
} );
@@ -1509,7 +1481,7 @@ QUnit.test( "clone()", function( assert ) {
div.remove();
// Test both html() and clone() for and types
- div = jQuery( "
" ).html( " " );
+ div = jQuery( "
" ).html( " " );
clone = div.clone( true );
assert.equal( clone.length, 1, "One element cloned" );
@@ -1519,7 +1491,7 @@ QUnit.test( "clone()", function( assert ) {
// 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.
- div = jQuery( "
" ).html( " " );
+ div = jQuery( "
" ).html( " " );
clone = div.clone( true );
assert.equal( clone.length, 1, "One element cloned" );
@@ -1546,14 +1518,14 @@ QUnit.test( "clone()", function( assert ) {
} )();
// and here's a valid one.
- div = jQuery( "
" ).html( " " );
+ div = jQuery( "
" ).html( " " );
clone = div.clone( true );
assert.equal( clone.length, 1, "One element cloned" );
assert.equal( clone.html(), div.html(), "Element contents cloned" );
assert.equal( clone[ 0 ].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
- div = jQuery( "
" ).data( { "a": true } );
+ div = jQuery( "
" ).data( { "a": true } );
clone = div.clone( true );
assert.equal( clone.data( "a" ), true, "Data cloned." );
clone.data( "a", false );
@@ -1578,7 +1550,7 @@ QUnit.test( "clone()", function( assert ) {
body.remove();
} );
-QUnit.test( "clone(script type=non-javascript) (#11359)", function( assert ) {
+QUnit.test( "clone(script type=non-javascript) (trac-11359)", function( assert ) {
assert.expect( 3 );
@@ -1591,7 +1563,7 @@ QUnit.test( "clone(script type=non-javascript) (#11359)", function( assert ) {
dest.remove();
} );
-QUnit.test( "clone(form element) (Bug #3879, #6655)", function( assert ) {
+QUnit.test( "clone(form element) (Bug trac-3879, trac-6655)", function( assert ) {
assert.expect( 5 );
@@ -1599,7 +1571,9 @@ QUnit.test( "clone(form element) (Bug #3879, #6655)", function( assert ) {
element = jQuery( "Foo Bar " );
- assert.equal( element.clone().find( "option" ).filter( function() { return this.selected; } ).val(), "selected", "Selected option cloned correctly" );
+ assert.equal( element.clone().find( "option" ).filter( function() {
+ return this.selected;
+ } ).val(), "selected", "Selected option cloned correctly" );
element = jQuery( " " ).attr( "checked", "checked" );
clone = element.clone();
@@ -1616,7 +1590,7 @@ QUnit.test( "clone(form element) (Bug #3879, #6655)", function( assert ) {
assert.equal( clone[ 0 ].defaultValue, "foo", "Textarea defaultValue cloned correctly" );
} );
-QUnit.test( "clone(multiple selected options) (Bug #8129)", function( assert ) {
+QUnit.test( "clone(multiple selected options) (Bug trac-8129)", function( assert ) {
assert.expect( 1 );
@@ -1665,14 +1639,14 @@ QUnit.test( "html(undefined)", function( assert ) {
assert.expect( 1 );
- assert.equal( jQuery( "#foo" ).html( "test " ).html( undefined ).html().toLowerCase(), "test ", ".html(undefined) is chainable (#5571)" );
+ assert.equal( jQuery( "#foo" ).html( "test " ).html( undefined ).html().toLowerCase(), "test ", ".html(undefined) is chainable (trac-5571)" );
} );
QUnit.test( "html() on empty set", function( assert ) {
assert.expect( 1 );
- assert.strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (#11962)" );
+ assert.strictEqual( jQuery().html(), undefined, ".html() returns undefined for empty sets (trac-11962)" );
} );
function childNodeNames( node ) {
@@ -1688,12 +1662,12 @@ function testHtml( valueObj, assert ) {
div = jQuery( "
" ),
fixture = jQuery( "#qunit-fixture" );
- div.html( valueObj( "
" ) );
+ div.html( valueObj( "
" ) );
assert.equal( div.children().length, 2, "Found children" );
assert.equal( div.children().children().length, 1, "Found grandchild" );
actual = []; expected = [];
- tmp = jQuery( " " ).html( valueObj( " " ) ).each( function() {
+ tmp = jQuery( " " ).html( valueObj( " " ) ).each( function() {
expected.push( "AREA" );
actual.push( childNodeNames( this ) );
} );
@@ -1748,7 +1722,7 @@ function testHtml( valueObj, assert ) {
assert.equal( expected.length, 1, "Expecting one parent" );
assert.deepEqual( actual, expected, "Found the inserted style element" );
- fixture.html( valueObj( " " ) );
+ fixture.html( valueObj( " " ) );
jQuery( "#qunit-fixture select" ).html( valueObj( "O1 O2 O3 " ) );
assert.equal( jQuery( "#qunit-fixture select" ).val(), "O2", "Selected option correct" );
@@ -1773,7 +1747,7 @@ function testHtml( valueObj, assert ) {
fixture.html( valueObj( "" ) );
fixture.html( valueObj( "" ) );
fixture.html( valueObj( "" ) );
- fixture.html( valueObj( "foo " ) );
+ fixture.html( valueObj( "foo " ) );
jQuery.scriptorder = 0;
fixture.html( valueObj( [
@@ -1797,13 +1771,9 @@ QUnit.test( "html(Function)", function( assert ) {
testHtml( manipulationFunctionReturningObj, assert );
} );
-QUnit[
- // Support: Edge 16-18+
- // Edge sometimes doesn't execute module scripts so skip the test there.
- ( QUnit.moduleTypeSupported && !/edge\//i.test( navigator.userAgent ) ) ?
- "test" :
- "skip"
-]( "html(script type module)", function( assert ) {
+// Support: IE 9 - 11+
+// IE doesn't support modules.
+QUnit.testUnlessIE( "html(script type module)", function( assert ) {
assert.expect( 4 );
var done = assert.async(),
$fixture = jQuery( "#qunit-fixture" );
@@ -1825,25 +1795,19 @@ QUnit[
}, 1000 );
} );
-QUnit[
- // Support: IE 9-11 only, Android 4.0-4.4 only, iOS 7-10 only
+QUnit.test( "html(script nomodule)", function( assert ) {
+
// `nomodule` scripts should be executed by legacy browsers only.
- // iOS 10 supports `",
+ "",
"",
"",
- "",
+ "",
"",
"
"
].join( "" )
@@ -1855,6 +1819,35 @@ QUnit[
}, 1000 );
} );
+QUnit.test( "html(self-removing script) (gh-5377)", function( assert ) {
+ assert.expect( 2 );
+
+ var $fixture = jQuery( "#qunit-fixture" );
+
+ $fixture.html(
+ [
+ "",
+ "",
+ "",
+ "
"
+ ].join( "\n" )
+ );
+} );
+
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {
assert.expect( 4 );
@@ -1903,7 +1896,7 @@ QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function(
assert.equal( j.html().replace( / xmlns="[^"]+"/g, "" ).toLowerCase(), "bold ", "Check node,textnode,comment with html()" );
- $div = jQuery( "
" );
+ $div = jQuery( "
" );
assert.equal( $div.html( function( i, val ) {
assert.equal( val, "", "Make sure the incoming value is correct." );
@@ -1915,7 +1908,7 @@ QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function(
return 0;
} ).html(), "0", "Setting a zero as html" );
- $div2 = jQuery( "
" );
+ $div2 = jQuery( "
" );
insert = "<div>hello1</div>";
assert.equal( $div2.html( function( i, val ) {
assert.equal( val, "", "Make sure the incoming value is correct." );
@@ -1933,7 +1926,7 @@ QUnit.test( "html(Function) with incoming value -- jQuery.contents()", function(
} ).html().replace( />/g, ">" ), " " + insert, "Verify escaped insertion." );
} );
-QUnit.test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function( assert ) {
+QUnit.test( "clone()/html() don't expose jQuery/Sizzle expandos (trac-12858)", function( assert ) {
assert.expect( 2 );
@@ -1984,7 +1977,7 @@ QUnit.test( "remove() with filters", function( assert ) {
div.children().remove( "span:nth-child(2n)" );
assert.equal( div.text(), "13", "relative selector in remove" );
- if ( jQuery.find.compile ) {
+ if ( QUnit.jQuerySelectorsPos ) {
div = jQuery( markup );
div.children().remove( "span:first" );
assert.equal( div.text(), "234", "positional selector in remove" );
@@ -1992,8 +1985,8 @@ QUnit.test( "remove() with filters", function( assert ) {
div.children().remove( "span:last" );
assert.equal( div.text(), "123", "positional selector in remove" );
} else {
- assert.ok( "skip", "Positional selectors not supported in selector-native" );
- assert.ok( "skip", "Positional selectors not supported in selector-native" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
}
// using contents will get comments regular, text, and comment nodes
@@ -2020,7 +2013,7 @@ QUnit.test( "remove() event cleaning ", function( assert ) {
cleanUp.remove();
} );
-QUnit.test( "remove() in document order #13779", function( assert ) {
+QUnit.test( "remove() in document order trac-13779", function( assert ) {
assert.expect( 1 );
var last,
@@ -2081,7 +2074,7 @@ QUnit.test( "detach() with filters", function( assert ) {
div.children().detach( "span:nth-child(2n)" );
assert.equal( div.text(), "13", "relative selector in detach" );
- if ( jQuery.find.compile ) {
+ if ( QUnit.jQuerySelectorsPos ) {
div = jQuery( markup );
div.children().detach( "span:first" );
assert.equal( div.text(), "234", "positional selector in detach" );
@@ -2089,8 +2082,8 @@ QUnit.test( "detach() with filters", function( assert ) {
div.children().detach( "span:last" );
assert.equal( div.text(), "123", "positional selector in detach" );
} else {
- assert.ok( "skip", "positional selectors not supported in selector-native" );
- assert.ok( "skip", "positional selectors not supported in selector-native" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
}
// using contents will get comments regular, text, and comment nodes
@@ -2211,7 +2204,7 @@ QUnit.test( "jQuery.cleanData", function( assert ) {
QUnit.test( "jQuery.cleanData eliminates all private data (gh-2127)", function( assert ) {
assert.expect( 3 );
- var div = jQuery( "
" ).appendTo( "#qunit-fixture" );
+ var div = jQuery( "
" ).appendTo( "#qunit-fixture" );
jQuery._data( div[ 0 ], "gh-2127", "testing" );
@@ -2231,7 +2224,7 @@ QUnit.test( "jQuery.cleanData eliminates all public data", function( assert ) {
assert.expect( 3 );
var key,
- div = jQuery( "
" );
+ div = jQuery( "
" );
div.data( "some", "data" );
assert.ok( !jQuery.isEmptyObject( jQuery.data( div[ 0 ] ) ), "Ensure some public data exists" );
@@ -2253,14 +2246,13 @@ QUnit.test( "domManip plain-text caching (trac-6779)", function( assert ) {
// DOM manipulation fails if added text matches an Object method
var i,
- $f = jQuery( "
" ).appendTo( "#qunit-fixture" ),
+ $f = jQuery( "
" ).appendTo( "#qunit-fixture" ),
bad = [ "start-", "toString", "hasOwnProperty", "append", "here&there!", "-end" ];
for ( i = 0; i < bad.length; i++ ) {
try {
$f.append( bad[ i ] );
- }
- catch ( e ) {}
+ } catch ( e ) {}
}
assert.equal( $f.text(), bad.join( "" ), "Cached strings that match Object properties" );
$f.remove();
@@ -2278,19 +2270,31 @@ QUnit.test( "domManip executes scripts containing html comments or CDATA (trac-9
""
].join( "\n" ) ).appendTo( "#qunit-fixture" );
+ // This test requires XHTML mode as CDATA is not recognized in HTML.
+ // jQuery( [
+ // ""
+ // ].join( "\n" ) ).appendTo( "#qunit-fixture" );
+
jQuery( [
""
].join( "\n" ) ).appendTo( "#qunit-fixture" );
+ // ES2015 in Annex B requires HTML-style comment delimiters (``) to act as
+ // single-line comment delimiters; i.e. they should be treated as `//`.
+ // See gh-4904
jQuery( [
""
].join( "\n" ) ).appendTo( "#qunit-fixture" );
} );
@@ -2315,7 +2319,61 @@ testIframe(
}
);
-QUnit.test( "jQuery.clone - no exceptions for object elements #9587", function( assert ) {
+testIframe(
+ "domManip executes external scripts in iframes in the iframes' context",
+ "manipulation/scripts-context.html",
+ function( assert, framejQuery, frameWindow, frameDocument ) {
+ assert.expect( 2 );
+
+ Globals.register( "finishTest" );
+
+ return new Promise( function( resolve ) {
+ window.finishTest = resolve;
+ jQuery( frameDocument.body ).append(
+ "" );
+ assert.ok( !window.scriptTest, "script executed in iframe context" );
+ assert.ok( frameWindow.scriptTest, "script executed in iframe context" );
+ } );
+ },
+
+ // The AJAX module is needed for jQuery._evalUrl.
+ QUnit[ includesModule( "ajax" ) ? "test" : "skip" ]
+);
+
+
+// We need to simulate cross-domain requests with the feature that
+// both 127.0.0.1 and localhost point to the mock http server.
+// Skip the the test if we are not in localhost but make sure we run
+// it in Karma.
+QUnit[
+ includesModule( "ajax" ) && ( window.__karma__ || location.hostname === "localhost" ) ?
+ "test" :
+ "skip"
+]( "jQuery.append with crossorigin attribute", function( assert ) {
+ assert.expect( 1 );
+
+ var done = assert.async(),
+ timeout;
+
+ Globals.register( "corsCallback" );
+ window.corsCallback = function( response ) {
+ assert.ok( typeof response.headers.origin === "string", "Origin header sent" );
+ window.clearTimeout( timeout );
+ done();
+ };
+
+ var src = baseURL + "mock.php?action=script&cors=1&callback=corsCallback";
+ src = src.replace( "localhost", "127.0.0.1" );
+ var html = "",
" "
].join( "" ) );
- scriptsIn.appendTo( jQuery( "
" ) );
+ scriptsIn.appendTo( jQuery( "
" ) );
objGlobal.ok = isOk;
scriptsOut = fixture.append( scriptsIn ).find( "script" );
@@ -2521,9 +2578,9 @@ QUnit.test( "script evaluation (#11795)", function( assert ) {
assert.deepEqual( fixture.children( "script" ).get(), scriptsOut.get(), "Scripts detached without reevaluation" );
objGlobal.ok = isOk;
- if ( jQuery.ajax ) {
+ if ( includesModule( "ajax" ) ) {
Globals.register( "testBar" );
- jQuery( "#qunit-fixture" ).append( "" );
+ jQuery( "#qunit-fixture" ).append( "" );
assert.strictEqual( window.testBar, "bar", "Global script evaluation" );
} else {
assert.ok( true, "No jQuery.ajax" );
@@ -2531,7 +2588,7 @@ QUnit.test( "script evaluation (#11795)", function( assert ) {
}
} );
-QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) {
+QUnit[ includesModule( "ajax" ) ? "test" : "skip" ]( "jQuery._evalUrl (trac-12838)", function( assert ) {
assert.expect( 5 );
@@ -2545,7 +2602,7 @@ QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) {
assert.equal( ( input.url || input ).slice( -1 ), expectedArgument, message );
expectedArgument++;
};
- jQuery( "#qunit-fixture" ).append( "" );
+ jQuery( "#qunit-fixture" ).append( "" );
assert.equal( expectedArgument, 3, "synchronous execution" );
message = "custom implementation";
@@ -2554,7 +2611,7 @@ QUnit.test( "jQuery._evalUrl (#12838)", function( assert ) {
jQuery.ajax = function( options ) {
assert.strictEqual( options, {}, "Unexpected call to jQuery.ajax" );
};
- jQuery( "#qunit-fixture" ).append( "" );
+ jQuery( "#qunit-fixture" ).append( "" );
jQuery.ajax = ajax;
jQuery._evalUrl = evalUrl;
@@ -2568,7 +2625,7 @@ QUnit.test( "jQuery.htmlPrefilter (gh-1747)", function( assert ) {
invocations = 0,
done = assert.async(),
htmlPrefilter = jQuery.htmlPrefilter,
- fixture = jQuery( "
" ).appendTo( "#qunit-fixture" ),
+ fixture = jQuery( "
" ).appendTo( "#qunit-fixture" ),
poison = "";
jQuery.htmlPrefilter = function( html ) {
@@ -2584,7 +2641,7 @@ QUnit.test( "jQuery.htmlPrefilter (gh-1747)", function( assert ) {
expectedArgument = "A-" + poison + "B-" + poison + poison + "C-";
fixture.html( expectedArgument );
- expectedArgument = "D-" + poison + "E-" + "" + poison + poison + "
" + "F-";
+ expectedArgument = "D-" + poison + "E-" + "" + poison + poison + "
" + "F-";
fixture.append( expectedArgument );
expectedArgument = poison;
@@ -2600,7 +2657,7 @@ QUnit.test( "jQuery.htmlPrefilter (gh-1747)", function( assert ) {
}, 100 );
} );
-QUnit.test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function( assert ) {
+QUnit.test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (trac-4087)", function( assert ) {
assert.expect( 10 );
@@ -2634,12 +2691,12 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig
} );
} );
-QUnit.test( "Index for function argument should be received (#13094)", function( assert ) {
+QUnit.test( "Index for function argument should be received (trac-13094)", function( assert ) {
assert.expect( 2 );
var i = 0;
- jQuery( "
" ).before( function( index ) {
+ jQuery( "
" ).before( function( index ) {
assert.equal( index, i++, "Index should be correct" );
} );
@@ -2656,7 +2713,7 @@ QUnit.test( "Make sure jQuery.fn.remove can work on elements in documentFragment
assert.equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" );
} );
-QUnit.test( "Make sure specific elements with content created correctly (#13232)", function( assert ) {
+QUnit.test( "Make sure specific elements with content created correctly (trac-13232)", function( assert ) {
assert.expect( 20 );
var results = [],
@@ -2665,7 +2722,7 @@ QUnit.test( "Make sure specific elements with content created correctly (#13232)
thead: "thead ",
tbody: "tbody ",
tfoot: "tfoot ",
- colgroup: " ",
+ colgroup: " ",
caption: "caption",
tr: "tr ",
th: "th",
@@ -2676,29 +2733,29 @@ QUnit.test( "Make sure specific elements with content created correctly (#13232)
jQuery.each( elems, function( name, value ) {
var html = "<" + name + ">" + value + "" + name + ">";
- assert.ok( jQuery.parseHTML( "<" + name + ">" + value + "" + name + ">" )[ 0 ].nodeName.toLowerCase() === name, name + " is created correctly" );
+ assert.strictEqual(
+ jQuery.parseHTML( "<" + name + ">" + value + "" + name + ">" )[ 0 ].nodeName.toLowerCase(),
+ name,
+ name + " is created correctly"
+ );
results.push( name );
args.push( html );
} );
- jQuery.fn.append.apply( jQuery( "
" ), args ).children().each( function( i ) {
- assert.ok( this.nodeName.toLowerCase() === results[ i ] );
+ jQuery.fn.append.apply( jQuery( "
" ), args ).children().each( function( i ) {
+ assert.strictEqual( this.nodeName.toLowerCase(), results[ i ] );
} );
} );
-QUnit.test( "Validate creation of multiple quantities of certain elements (#13818)", function( assert ) {
- assert.expect( 44 );
+QUnit.test( "Validate creation of multiple quantities of certain elements (trac-13818)", function( assert ) {
+ assert.expect( 22 );
var tags = [ "thead", "tbody", "tfoot", "colgroup", "col", "caption", "tr", "th", "td", "optgroup", "option" ];
jQuery.each( tags, function( index, tag ) {
- jQuery( "<" + tag + "/><" + tag + "/>" ).each( function() {
- assert.ok( this.nodeName.toLowerCase() === tag, tag + " empty elements created correctly" );
- } );
-
- jQuery( "<" + this + ">" + tag + "><" + tag + ">" + tag + ">" ).each( function() {
- assert.ok( this.nodeName.toLowerCase() === tag, tag + " elements with closing tag created correctly" );
+ jQuery( "<" + tag + ">" + tag + "><" + tag + ">" + tag + ">" ).each( function() {
+ assert.ok( this.nodeName.toLowerCase() === tag, tag + " elements created correctly" );
} );
} );
} );
@@ -2746,7 +2803,7 @@ QUnit.test( "Make sure tfoot element will not be appended to tbody element of ta
table.appendChild( document.createElement( "tbody" ) );
document.getElementById( "qunit-fixture" ).appendChild( table );
- jQuery( table ).append( " " );
+ jQuery( table ).append( " " );
// Lowercase and replace spaces to remove possible browser inconsistencies
html = table.innerHTML.toLowerCase().replace( /\s/g, "" );
@@ -2785,7 +2842,7 @@ QUnit.test( "Make sure col element is appended correctly", function( assert ) {
jQuery( table ).appendTo( "#qunit-fixture" );
- jQuery( " " ).prependTo( table );
+ jQuery( " " ).prependTo( table );
assert.strictEqual( table.find( "td" ).width(), 150 );
} );
@@ -2800,7 +2857,7 @@ QUnit.test( "Make sure tr is not appended to the wrong tbody (gh-3439)", functio
"",
newRow = "added ",
htmlExpected = htmlIn.replace( "", "" + newRow ),
- table = supportjQuery( "" ).html( htmlIn ).appendTo( "#qunit-fixture" )[ 0 ];
+ table = supportjQuery( "" ).html( htmlIn ).appendTo( "#qunit-fixture" )[ 0 ];
jQuery( table ).append( newRow );
@@ -2810,12 +2867,52 @@ QUnit.test( "Make sure tr is not appended to the wrong tbody (gh-3439)", functio
assert.strictEqual( htmlOut, htmlExpected );
} );
+[ true, false ].forEach( function( adoptedCase ) {
+ QUnit.testUnlessIE(
+ "Manip within content moved back & forth doesn't throw - " + (
+ adoptedCase ? "explicitly adopted" : "not explicitly adopted"
+ ) + " (gh-5147)",
+ function( assert ) {
+ assert.expect( 1 );
+
+ var fragment, diva, divb,
+ div = jQuery( "" +
+ "\n" +
+ "
\n" +
+ "
\n" +
+ "
" +
+ "" ),
+ template = jQuery( " " );
+
+ jQuery( "#qunit-fixture" )
+ .append( div )
+ .append( template );
+
+ fragment = template[ 0 ].content;
+ diva = div.find( ".a" );
+ divb = div.find( ".b" );
+
+ if ( adoptedCase ) {
+ document.adoptNode( fragment );
+ }
+
+ fragment.appendChild( div.children()[ 0 ] );
+ fragment.appendChild( div.children()[ 0 ] );
+
+ diva.insertBefore( divb );
+
+ assert.strictEqual( diva.siblings( ".b" ).length, 1,
+ "Insertion worked" );
+ }
+ );
+} );
+
QUnit.test( "Make sure tags with single-character names are found (gh-4124)", function( assert ) {
assert.expect( 1 );
var htmlOut,
htmlIn = "foo
",
- $el = jQuery( "
" );
+ $el = jQuery( "
" );
$el.html( htmlIn );
@@ -2825,8 +2922,10 @@ QUnit.test( "Make sure tags with single-character names are found (gh-4124)", fu
assert.strictEqual( htmlOut, htmlIn );
} );
-QUnit.test( "Insert script with data-URI (gh-1887)", function( assert ) {
+// The AJAX module is needed for jQuery._evalUrl.
+QUnit[ includesModule( "ajax" ) ? "test" : "skip" ]( "Insert script with data-URI (gh-1887)", function( assert ) {
assert.expect( 1 );
+
Globals.register( "testFoo" );
Globals.register( "testSrcFoo" );
@@ -2862,7 +2961,7 @@ QUnit.test( "Ignore content from unsuccessful responses (gh-4126)", function( as
try {
jQuery( "#qunit-fixture" ).append(
- "" );
+ "" );
assert.ok( true, "no error thrown from embedding script with unsuccessful-response src" );
} catch ( e ) {
throw e;
@@ -2883,38 +2982,25 @@ testIframe(
assert.equal( data, "", "No log request should be sent" );
supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done );
} );
- },
-
- // Support: Edge 18+, iOS 7-9 only, Android 4.0-4.4 only
- // Edge doesn't support nonce in non-inline scripts.
- // See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13246371/
- // Old iOS & Android Browser versions support script-src but not nonce, making this test
- // impossible to run. Browsers not supporting CSP at all are not a problem as they'll skip
- // script-src restrictions completely.
- QUnit[ /\bedge\/|iphone os [789]|android 4\./i.test( navigator.userAgent ) ? "skip" : "test" ]
+ }
);
testIframe(
- "Check if CSP nonce is preserved for external scripts with src attribute",
- "mock.php?action=cspNonce&test=external",
- function( assert, jQuery, window, document ) {
- var done = assert.async();
-
- assert.expect( 1 );
-
- supportjQuery.get( baseURL + "support/csp.log" ).done( function( data ) {
- assert.equal( data, "", "No log request should be sent" );
- supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done );
- } );
- },
-
- // Support: Edge 18+, iOS 7-9 only, Android 4.0-4.4 only
- // Edge doesn't support nonce in non-inline scripts.
- // See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13246371/
- // Old iOS & Android Browser versions support script-src but not nonce, making this test
- // impossible to run. Browsers not supporting CSP at all are not a problem as they'll skip
- // script-src restrictions completely.
- QUnit[ /\bedge\/|iphone os [789]|android 4\./i.test( navigator.userAgent ) ? "skip" : "test" ]
+ "Check if CSP nonce is preserved for external scripts with src attribute",
+ "mock.php?action=cspNonce&test=external",
+ function( assert, jQuery, window, document ) {
+ var done = assert.async();
+
+ assert.expect( 1 );
+
+ supportjQuery.get( baseURL + "support/csp.log" ).done( function( data ) {
+ assert.equal( data, "", "No log request should be sent" );
+ supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done );
+ } );
+ },
+
+ // The AJAX module is needed for jQuery._evalUrl.
+ QUnit[ includesModule( "ajax" ) ? "test" : "skip" ]
);
testIframe(
@@ -2929,13 +3015,89 @@ testIframe(
assert.equal( data, "", "No log request should be sent" );
supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done );
} );
- },
+ }
+);
+
+QUnit.test( "Sanitized HTML doesn't get unsanitized", function( assert ) {
+
+ var container,
+ counter = 0,
+ oldIos = /iphone os (?:8|9|10|11|12)_/i.test( navigator.userAgent ),
+ assertCount = oldIos ? 12 : 13,
+ done = assert.async( assertCount );
+
+ assert.expect( assertCount );
+
+ Globals.register( "xss" );
+ window.xss = sinon.spy();
+
+ container = jQuery( "
" );
+ container.appendTo( "#qunit-fixture" );
+
+ function test( htmlString ) {
+ var currCounter = counter,
+ div = jQuery( "
" );
+
+ counter++;
+
+ div.appendTo( container );
+ div.html( htmlString );
- // Support: Edge 18+, iOS 7-9 only, Android 4.0-4.4 only
- // Edge doesn't support nonce in non-inline scripts.
- // See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13246371/
- // Old iOS & Android Browser versions support script-src but not nonce, making this test
- // impossible to run. Browsers not supporting CSP at all are not a problem as they'll skip
- // script-src restrictions completely.
- QUnit[ /\bedge\/|iphone os [789]|android 4\./i.test( navigator.userAgent ) ? "skip" : "test" ]
+ setTimeout( function() {
+ assert.ok( window.xss.withArgs( currCounter ).notCalled,
+ "Insecure code wasn't executed, input: " + htmlString );
+ done();
+ }, 1000 );
+ }
+
+ // Note: below test cases need to invoke the xss function with consecutive
+ // decimal parameters for the assertion messages to be correct.
+ // Thanks to Masato Kinugawa from Cure53 for providing the following test cases.
+ test( " \">" );
+ test( " \n \">" );
+ test( "" );
+
+ // Support: iOS 8 - 12 only.
+ // Old iOS parses `` tags differently, executing this code. This is no
+ // different to native behavior on that OS, though, so just accept it.
+ if ( !oldIos ) {
+ test( " " );
+ }
+} );
+
+QUnit.test( "Works with invalid attempts to close the table wrapper", function( assert ) {
+ assert.expect( 3 );
+
+ // This test case attempts to close the tags which wrap input
+ // based on matching done in wrapMap which should be ignored.
+ var elem = jQuery( "
" );
+ assert.strictEqual( elem.length, 2, "Two elements created" );
+ assert.strictEqual( elem[ 0 ].nodeName.toLowerCase(), "td", "First element is td" );
+ assert.strictEqual( elem[ 1 ].nodeName.toLowerCase(), "td", "Second element is td" );
+} );
+
+// Test trustedTypes support in browsers where they're supported (currently Chrome 83+).
+// Browsers with no TrustedHTML support still run tests on object wrappers with
+// a proper `toString` function.
+testIframe(
+ "Basic TrustedHTML support (gh-4409)",
+ "mock.php?action=trustedHtml",
+ function( assert, jQuery, window, document, test ) {
+
+ assert.expect( 5 );
+
+ test.forEach( function( result ) {
+ assert.deepEqual( result.actual, result.expected, result.message );
+ } );
+ }
);
diff --git a/test/unit/offset.js b/test/unit/offset.js
index 2b63ccbd99..73ec8928fe 100644
--- a/test/unit/offset.js
+++ b/test/unit/offset.js
@@ -1,29 +1,23 @@
( function() {
-if ( !jQuery.fn.offset ) {
+if ( !includesModule( "offset" ) ) {
return;
}
-var supportsFixedPosition, supportsScroll, alwaysScrollable,
- forceScroll = supportjQuery( "
" ).css( { width: 2000, height: 2000 } ),
+var supportsScroll, alwaysScrollable,
+ forceScroll = supportjQuery( "
" ).css( { width: 2000, height: 2000 } ),
checkSupport = function( assert ) {
// Only run once
checkSupport = false;
- var checkFixed = supportjQuery( "
" )
- .css( { position: "fixed", top: "20px" } )
- .appendTo( "#qunit-fixture" );
- supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20;
- checkFixed.remove();
-
// Append forceScroll to the body instead of #qunit-fixture because the latter is hidden
forceScroll.appendTo( "body" );
window.scrollTo( 200, 200 );
supportsScroll = document.documentElement.scrollTop || document.body.scrollTop;
forceScroll.detach();
- // Support: iOS <=7
+ // Support: iOS <=7 - 12+
// Hijack the iframe test infrastructure to detect viewport scrollability
// for pages with position:fixed document element
var done = assert.async();
@@ -60,8 +54,8 @@ QUnit.module( "offset", { beforeEach: function( assert ) {
QUnit.test( "empty set", function( assert ) {
assert.expect( 2 );
- assert.strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
- assert.strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
+ assert.strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (trac-11962)" );
+ assert.strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (trac-11962)" );
} );
QUnit.test( "disconnected element", function( assert ) {
@@ -69,7 +63,7 @@ QUnit.test( "disconnected element", function( assert ) {
var result = jQuery( document.createElement( "div" ) ).offset();
- // These tests are solely for master/compat consistency
+ // These tests are solely for main/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
assert.equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
@@ -81,12 +75,12 @@ QUnit.test( "disconnected element", function( assert ) {
QUnit.test( "hidden (display: none) element", function( assert ) {
assert.expect( 4 );
- var node = jQuery( "
" ).appendTo( "#qunit-fixture" ),
result = node.offset();
node.remove();
- // These tests are solely for master/compat consistency
+ // These tests are solely for main/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
assert.equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
@@ -98,7 +92,7 @@ QUnit.test( "hidden (display: none) element", function( assert ) {
QUnit.test( "0 sized element", function( assert ) {
assert.expect( 4 );
- var node = jQuery( "
" ).appendTo( "#qunit-fixture" ),
result = node.offset();
node.remove();
@@ -112,7 +106,7 @@ QUnit.test( "0 sized element", function( assert ) {
QUnit.test( "hidden (visibility: hidden) element", function( assert ) {
assert.expect( 4 );
- var node = jQuery( "
" ).appendTo( "#qunit-fixture" ),
result = node.offset();
node.remove();
@@ -171,9 +165,9 @@ testIframe( "absolute", "offset/absolute.html", function( assert, $ ) {
// get offset tests
tests = [
- { "id": "#absolute-1", "top": 1, "left": 1 },
- { "id": "#absolute-1-1", "top": 5, "left": 5 },
- { "id": "#absolute-1-1-1", "top": 9, "left": 9 },
+ { "id": "#absolute-1", "top": 1, "left": 1 },
+ { "id": "#absolute-1-1", "top": 5, "left": 5 },
+ { "id": "#absolute-1-1-1", "top": 9, "left": 9 },
{ "id": "#absolute-2", "top": 20, "left": 20 }
];
jQuery.each( tests, function() {
@@ -183,9 +177,9 @@ testIframe( "absolute", "offset/absolute.html", function( assert, $ ) {
// get position
tests = [
- { "id": "#absolute-1", "top": 0, "left": 0 },
- { "id": "#absolute-1-1", "top": 1, "left": 1 },
- { "id": "#absolute-1-1-1", "top": 1, "left": 1 },
+ { "id": "#absolute-1", "top": 0, "left": 0 },
+ { "id": "#absolute-1-1", "top": 1, "left": 1 },
+ { "id": "#absolute-1-1-1", "top": 1, "left": 1 },
{ "id": "#absolute-2", "top": 19, "left": 19 }
];
jQuery.each( tests, function() {
@@ -193,7 +187,7 @@ testIframe( "absolute", "offset/absolute.html", function( assert, $ ) {
assert.equal( $( this.id ).position().left, this.left, "jQuery('" + this.id + "').position().left" );
} );
- // test #5781
+ // test trac-5781
offset = $( "#positionTest" ).offset( { "top": 10, "left": 10 } ).offset();
assert.equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
assert.equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
@@ -205,17 +199,17 @@ testIframe( "absolute", "offset/absolute.html", function( assert, $ ) {
{ "id": "#absolute-2", "top": -1, "left": -1 },
{ "id": "#absolute-2", "top": 19, "left": 19 },
{ "id": "#absolute-1-1-1", "top": 15, "left": 15 },
- { "id": "#absolute-1-1-1", "top": 5, "left": 5 },
+ { "id": "#absolute-1-1-1", "top": 5, "left": 5 },
{ "id": "#absolute-1-1-1", "top": -1, "left": -1 },
- { "id": "#absolute-1-1-1", "top": 9, "left": 9 },
+ { "id": "#absolute-1-1-1", "top": 9, "left": 9 },
{ "id": "#absolute-1-1", "top": 10, "left": 10 },
- { "id": "#absolute-1-1", "top": 0, "left": 0 },
+ { "id": "#absolute-1-1", "top": 0, "left": 0 },
{ "id": "#absolute-1-1", "top": -1, "left": -1 },
- { "id": "#absolute-1-1", "top": 5, "left": 5 },
- { "id": "#absolute-1", "top": 2, "left": 2 },
- { "id": "#absolute-1", "top": 0, "left": 0 },
+ { "id": "#absolute-1-1", "top": 5, "left": 5 },
+ { "id": "#absolute-1", "top": 2, "left": 2 },
+ { "id": "#absolute-1", "top": 0, "left": 0 },
{ "id": "#absolute-1", "top": -1, "left": -1 },
- { "id": "#absolute-1", "top": 1, "left": 1 }
+ { "id": "#absolute-1", "top": 1, "left": 1 }
];
jQuery.each( tests, function() {
$( this.id ).offset( { "top": this.top, "left": this.left } );
@@ -234,13 +228,13 @@ testIframe( "absolute", "offset/absolute.html", function( assert, $ ) {
$( this.id )
.offset( { "left": this.left + 2 } )
- .offset( { "top": this.top + 2 } );
+ .offset( { "top": this.top + 2 } );
assert.equal( $( this.id ).offset().top, this.top + 2, "Setting one property at a time." );
assert.equal( $( this.id ).offset().left, this.left + 2, "Setting one property at a time." );
$( this.id ).offset( { "top": this.top, "left": this.left, "using": function( props ) {
$( this ).css( {
- "top": props.top + 1,
+ "top": props.top + 1,
"left": props.left + 1
} );
} } );
@@ -254,8 +248,8 @@ testIframe( "relative", "offset/relative.html", function( assert, $ ) {
// get offset
var tests = [
- { "id": "#relative-1", "top": 7, "left": 7 },
- { "id": "#relative-1-1", "top": 15, "left": 15 },
+ { "id": "#relative-1", "top": 7, "left": 7 },
+ { "id": "#relative-1-1", "top": 15, "left": 15 },
{ "id": "#relative-2", "top": 142, "left": 27 },
{ "id": "#relative-2-1", "top": 149, "left": 52 }
];
@@ -266,8 +260,8 @@ testIframe( "relative", "offset/relative.html", function( assert, $ ) {
// get position
tests = [
- { "id": "#relative-1", "top": 6, "left": 6 },
- { "id": "#relative-1-1", "top": 5, "left": 5 },
+ { "id": "#relative-1", "top": 6, "left": 6 },
+ { "id": "#relative-1-1", "top": 5, "left": 5 },
{ "id": "#relative-2", "top": 141, "left": 26 },
{ "id": "#relative-2-1", "top": 5, "left": 5 }
];
@@ -278,18 +272,18 @@ testIframe( "relative", "offset/relative.html", function( assert, $ ) {
// set offset
tests = [
- { "id": "#relative-2", "top": 200, "left": 50 },
- { "id": "#relative-2", "top": 100, "left": 10 },
- { "id": "#relative-2", "top": -5, "left": -5 },
- { "id": "#relative-2", "top": 142, "left": 27 },
+ { "id": "#relative-2", "top": 200, "left": 50 },
+ { "id": "#relative-2", "top": 100, "left": 10 },
+ { "id": "#relative-2", "top": -5, "left": -5 },
+ { "id": "#relative-2", "top": 142, "left": 27 },
{ "id": "#relative-1-1", "top": 100, "left": 100 },
- { "id": "#relative-1-1", "top": 5, "left": 5 },
- { "id": "#relative-1-1", "top": -1, "left": -1 },
- { "id": "#relative-1-1", "top": 15, "left": 15 },
+ { "id": "#relative-1-1", "top": 5, "left": 5 },
+ { "id": "#relative-1-1", "top": -1, "left": -1 },
+ { "id": "#relative-1-1", "top": 15, "left": 15 },
{ "id": "#relative-1", "top": 100, "left": 100 },
- { "id": "#relative-1", "top": 0, "left": 0 },
- { "id": "#relative-1", "top": -1, "left": -1 },
- { "id": "#relative-1", "top": 7, "left": 7 }
+ { "id": "#relative-1", "top": 0, "left": 0 },
+ { "id": "#relative-1", "top": -1, "left": -1 },
+ { "id": "#relative-1", "top": 7, "left": 7 }
];
jQuery.each( tests, function() {
$( this.id ).offset( { "top": this.top, "left": this.left } );
@@ -298,7 +292,7 @@ testIframe( "relative", "offset/relative.html", function( assert, $ ) {
$( this.id ).offset( { "top": this.top, "left": this.left, "using": function( props ) {
$( this ).css( {
- "top": props.top + 1,
+ "top": props.top + 1,
"left": props.left + 1
} );
} } );
@@ -312,9 +306,9 @@ testIframe( "static", "offset/static.html", function( assert, $ ) {
// get offset
var tests = [
- { "id": "#static-1", "top": 7, "left": 7 },
- { "id": "#static-1-1", "top": 15, "left": 15 },
- { "id": "#static-1-1-1", "top": 23, "left": 23 },
+ { "id": "#static-1", "top": 7, "left": 7 },
+ { "id": "#static-1-1", "top": 15, "left": 15 },
+ { "id": "#static-1-1-1", "top": 23, "left": 23 },
{ "id": "#static-2", "top": 122, left: 7 }
];
jQuery.each( tests, function() {
@@ -324,9 +318,9 @@ testIframe( "static", "offset/static.html", function( assert, $ ) {
// get position
tests = [
- { "id": "#static-1", "top": 6, "left": 6 },
- { "id": "#static-1-1", "top": 14, "left": 14 },
- { "id": "#static-1-1-1", "top": 22, "left": 22 },
+ { "id": "#static-1", "top": 6, "left": 6 },
+ { "id": "#static-1-1", "top": 14, "left": 14 },
+ { "id": "#static-1-1-1", "top": 22, "left": 22 },
{ "id": "#static-2", "top": 121, "left": 6 }
];
jQuery.each( tests, function() {
@@ -338,20 +332,20 @@ testIframe( "static", "offset/static.html", function( assert, $ ) {
tests = [
{ "id": "#static-2", "top": 200, "left": 200 },
{ "id": "#static-2", "top": 100, "left": 100 },
- { "id": "#static-2", "top": -2, "left": -2 },
- { "id": "#static-2", "top": 121, "left": 6 },
- { "id": "#static-1-1-1", "top": 50, "left": 50 },
- { "id": "#static-1-1-1", "top": 10, "left": 10 },
- { "id": "#static-1-1-1", "top": -1, "left": -1 },
- { "id": "#static-1-1-1", "top": 22, "left": 22 },
- { "id": "#static-1-1", "top": 25, "left": 25 },
- { "id": "#static-1-1", "top": 10, "left": 10 },
- { "id": "#static-1-1", "top": -3, "left": -3 },
- { "id": "#static-1-1", "top": 14, "left": 14 },
- { "id": "#static-1", "top": 30, "left": 30 },
- { "id": "#static-1", "top": 2, "left": 2 },
- { "id": "#static-1", "top": -2, "left": -2 },
- { "id": "#static-1", "top": 7, "left": 7 }
+ { "id": "#static-2", "top": -2, "left": -2 },
+ { "id": "#static-2", "top": 121, "left": 6 },
+ { "id": "#static-1-1-1", "top": 50, "left": 50 },
+ { "id": "#static-1-1-1", "top": 10, "left": 10 },
+ { "id": "#static-1-1-1", "top": -1, "left": -1 },
+ { "id": "#static-1-1-1", "top": 22, "left": 22 },
+ { "id": "#static-1-1", "top": 25, "left": 25 },
+ { "id": "#static-1-1", "top": 10, "left": 10 },
+ { "id": "#static-1-1", "top": -3, "left": -3 },
+ { "id": "#static-1-1", "top": 14, "left": 14 },
+ { "id": "#static-1", "top": 30, "left": 30 },
+ { "id": "#static-1", "top": 2, "left": 2 },
+ { "id": "#static-1", "top": -2, "left": -2 },
+ { "id": "#static-1", "top": 7, "left": 7 }
];
jQuery.each( tests, function() {
$( this.id ).offset( { "top": this.top, "left": this.left } );
@@ -360,7 +354,7 @@ testIframe( "static", "offset/static.html", function( assert, $ ) {
$( this.id ).offset( { "top": this.top, "left": this.left, "using": function( props ) {
$( this ).css( {
- "top": props.top + 1,
+ "top": props.top + 1,
"left": props.left + 1
} );
} } );
@@ -400,69 +394,45 @@ testIframe( "fixed", "offset/fixed.html", function( assert, $, window ) {
assert.ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
- } else if ( window.supportsFixedPosition ) {
+ } else {
assert.equal( jQuery.isPlainObject( $( this.id ).offset() ), true, "jQuery('" + this.id + "').offset() is plain object" );
assert.equal( jQuery.isPlainObject( $( this.id ).position() ), true, "jQuery('" + this.id + "').position() is plain object" );
assert.equal( $( this.id ).offset().top, this.offsetTop, "jQuery('" + this.id + "').offset().top" );
assert.equal( $( this.id ).position().top, this.positionTop, "jQuery('" + this.id + "').position().top" );
assert.equal( $( this.id ).offset().left, this.offsetLeft, "jQuery('" + this.id + "').offset().left" );
assert.equal( $( this.id ).position().left, this.positionLeft, "jQuery('" + this.id + "').position().left" );
- } else {
-
- // need to have same number of assertions
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
}
} );
tests = [
{ "id": "#fixed-1", "top": 100, "left": 100 },
- { "id": "#fixed-1", "top": 0, "left": 0 },
- { "id": "#fixed-1", "top": -4, "left": -4 },
+ { "id": "#fixed-1", "top": 0, "left": 0 },
+ { "id": "#fixed-1", "top": -4, "left": -4 },
{ "id": "#fixed-2", "top": 200, "left": 200 },
- { "id": "#fixed-2", "top": 0, "left": 0 },
- { "id": "#fixed-2", "top": -5, "left": -5 }
+ { "id": "#fixed-2", "top": 0, "left": 0 },
+ { "id": "#fixed-2", "top": -5, "left": -5 }
];
jQuery.each( tests, function() {
- if ( window.supportsFixedPosition ) {
- $( this.id ).offset( { "top": this.top, "left": this.left } );
- assert.equal( $( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
- assert.equal( $( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
-
- $( this.id ).offset( { "top": this.top, "left": this.left, "using": function( props ) {
- $( this ).css( {
- "top": props.top + 1,
- "left": props.left + 1
- } );
- } } );
- assert.equal( $( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + ( this.top + 1 ) + ", using: fn })" );
- assert.equal( $( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + ( this.left + 1 ) + ", using: fn })" );
- } else {
+ $( this.id ).offset( { "top": this.top, "left": this.left } );
+ assert.equal( $( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
+ assert.equal( $( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
- // need to have same number of assertions
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- }
+ $( this.id ).offset( { "top": this.top, "left": this.left, "using": function( props ) {
+ $( this ).css( {
+ "top": props.top + 1,
+ "left": props.left + 1
+ } );
+ } } );
+ assert.equal( $( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + ( this.top + 1 ) + ", using: fn })" );
+ assert.equal( $( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + ( this.left + 1 ) + ", using: fn })" );
} );
// Bug 8316
$noTopLeft = $( "#fixed-no-top-left" );
- if ( window.supportsFixedPosition ) {
- assert.equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
- assert.equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
- } else {
- // need to have same number of assertions
- assert.ok( true, "Fixed position is not supported" );
- assert.ok( true, "Fixed position is not supported" );
- }
+ assert.equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
+ assert.equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
} );
testIframe( "table", "offset/table.html", function( assert, $ ) {
@@ -484,7 +454,7 @@ testIframe( "scroll", "offset/scroll.html", function( assert, $, win ) {
assert.equal( $( "#scroll-1-1" ).offset().top, 11, "jQuery('#scroll-1-1').offset().top" );
assert.equal( $( "#scroll-1-1" ).offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
- // These tests are solely for master/compat consistency
+ // These tests are solely for main/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
assert.equal( $( "#hidden" ).offset().top, 0, "Hidden elements do not subtract scroll" );
@@ -498,8 +468,8 @@ testIframe( "scroll", "offset/scroll.html", function( assert, $, win ) {
assert.equal( $( "#scroll-1-1" ).scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
// scroll method chaining
- assert.equal( $( "#scroll-1" ).scrollTop( undefined ).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" );
- assert.equal( $( "#scroll-1" ).scrollLeft( undefined ).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" );
+ assert.equal( $( "#scroll-1" ).scrollTop( undefined ).scrollTop(), 5, ".scrollTop(undefined) is chainable (trac-5571)" );
+ assert.equal( $( "#scroll-1" ).scrollLeft( undefined ).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (trac-5571)" );
win.name = "test";
@@ -546,10 +516,10 @@ testIframe( "body", "offset/body.html", function( assert, $ ) {
QUnit.test( "chaining", function( assert ) {
assert.expect( 3 );
- var coords = { "top": 1, "left": 1 };
+ var coords = { "top": 1, "left": 1 };
assert.equal( jQuery( "#absolute-1" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
assert.equal( jQuery( "#non-existent" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );
- assert.equal( jQuery( "#absolute-1" ).offset( undefined ).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" );
+ assert.equal( jQuery( "#absolute-1" ).offset( undefined ).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (trac-5571)" );
} );
// Test complex content under a variety of / positioning styles
@@ -586,17 +556,17 @@ QUnit.test( "chaining", function( assert ) {
// Initialize data about page elements
var expectations = {
- "documentElement": htmlProps( htmlPos ),
- "body": bodyProps( bodyPos ),
- "relative": divProps( "relative", "body" ),
+ "documentElement": htmlProps( htmlPos ),
+ "body": bodyProps( bodyPos ),
+ "relative": divProps( "relative", "body" ),
"relative-relative": divProps( "relative", "relative" ),
"relative-absolute": divProps( "absolute", "relative" ),
- "absolute": divProps( "absolute", "body" ),
+ "absolute": divProps( "absolute", "body" ),
"absolute-relative": divProps( "relative", "absolute" ),
"absolute-absolute": divProps( "absolute", "absolute" ),
- "fixed": divProps( "fixed" ),
- "fixed-relative": divProps( "relative", "fixed" ),
- "fixed-absolute": divProps( "absolute", "fixed" )
+ "fixed": divProps( "fixed" ),
+ "fixed-relative": divProps( "relative", "fixed" ),
+ "fixed-absolute": divProps( "absolute", "fixed" )
};
// Define position and offset expectations for page elements
@@ -622,6 +592,7 @@ QUnit.test( "chaining", function( assert ) {
// parent is not offsetParent); offset includes parent offset+border+padding
// static: same as relative
for ( ; parent; parent = expectations[ parent.parent ] ) {
+
// position:fixed
if ( props.style === "fixed" ) {
break;
@@ -660,25 +631,6 @@ QUnit.test( "chaining", function( assert ) {
}
} );
- // Support: IE<=10 only
- // Fudge the tests to work around .gBCR() erroneously including margins
- if ( /MSIE (?:9|10)\./.test( navigator.userAgent ) ) {
- expectations.documentElement.pos.top -= expectations.documentElement.marginTop -
- scrollTop;
- expectations.documentElement.offset.top -= expectations.documentElement.marginTop -
- scrollTop;
- expectations.documentElement.pos.left -= expectations.documentElement.marginLeft -
- scrollLeft;
- expectations.documentElement.offset.left -= expectations.documentElement.marginLeft -
- scrollLeft;
- if ( htmlPos !== "static" ) {
- delete expectations.documentElement;
- delete expectations.body;
- delete expectations.relative;
- delete expectations.absolute;
- }
- }
-
return expectations;
}
@@ -778,14 +730,14 @@ QUnit.test( "offsetParent", function( assert ) {
area.remove();
div = jQuery( "
" ).css( { "position": "absolute" } ).appendTo( "body" );
- assert.equal( div.offsetParent()[ 0 ], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" );
+ assert.equal( div.offsetParent()[ 0 ], document.documentElement, "Absolutely positioned div returns html as offset parent, see trac-12139" );
div.remove();
} );
-QUnit.test( "fractions (see #7730 and #7885)", function( assert ) {
+QUnit.test( "fractions (see trac-7730 and trac-7885)", function( assert ) {
assert.expect( 2 );
- jQuery( "body" ).append( "
" );
+ jQuery( "body" ).append( "
" );
var result,
expected = { "top": 1000, "left": 1000 },
@@ -803,10 +755,10 @@ QUnit.test( "fractions (see #7730 and #7885)", function( assert ) {
result = div.offset();
- // Support: Chrome <=45 - 46
+ // Support: Chrome <=45 - 73+
// In recent Chrome these values differ a little.
assert.ok( Math.abs( result.top - expected.top ) < 0.25, "Check top within 0.25 of expected" );
- assert.equal( result.left, expected.left, "Check left" );
+ assert.ok( Math.abs( result.left - expected.left ) < 0.25, "Check left within 0.25 of expected" );
div.remove();
} );
@@ -816,13 +768,10 @@ QUnit.test( "iframe scrollTop/Left (see gh-1945)", function( assert ) {
var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument;
- // Mobile Safari resize the iframe by its content meaning it's not possible to scroll
+ // Support: iOS <=8 - 12+
+ // Mobile Safari resizes the iframe by its content meaning it's not possible to scroll
// the iframe but only its parent element.
- // It seems (not confirmed) in android 4.0 it's not possible to scroll iframes from the code.
- if (
- /iphone os|ipad/i.test( navigator.userAgent ) ||
- /android 4\.0/i.test( navigator.userAgent )
- ) {
+ if ( /iphone os|ipad/i.test( navigator.userAgent ) ) {
assert.equal( true, true, "Can't scroll iframes in this environment" );
assert.equal( true, true, "Can't scroll iframes in this environment" );
diff --git a/test/unit/queue.js b/test/unit/queue.js
index 6c8ad762d3..ed9f261f83 100644
--- a/test/unit/queue.js
+++ b/test/unit/queue.js
@@ -1,5 +1,11 @@
QUnit.module( "queue", { afterEach: moduleTeardown } );
+( function() {
+
+if ( !includesModule( "queue" ) ) {
+ return;
+}
+
QUnit.test( "queue() with other types", function( assert ) {
var done = assert.async( 2 );
assert.expect( 14 );
@@ -35,7 +41,7 @@ QUnit.test( "queue() with other types", function( assert ) {
assert.equal( $div.queue( "foo" ).length, 4, "Testing queue length" );
- assert.equal( $div.queue( "foo", undefined ).queue( "foo" ).length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)" );
+ assert.equal( $div.queue( "foo", undefined ).queue( "foo" ).length, 4, ".queue('name',undefined) does nothing but is chainable (trac-5571)" );
$div.dequeue( "foo" );
@@ -82,7 +88,9 @@ QUnit.test( "queue() passes in the next item in the queue as a parameter to fx q
div.queue( function( next ) {
assert.equal( ++counter, 1, "Dequeueing" );
- setTimeout( function() { next(); }, 500 );
+ setTimeout( function() {
+ next();
+ }, 500 );
} ).queue( function( next ) {
assert.equal( ++counter, 2, "Next was called" );
next();
@@ -181,7 +189,9 @@ QUnit.test( "clearQueue() clears the fx queue", function( assert ) {
div.queue( function( next ) {
counter++;
var self = this;
- setTimeout( function() { jQuery( self ).clearQueue(); next(); }, 50 );
+ setTimeout( function() {
+ jQuery( self ).clearQueue(); next();
+ }, 50 );
} ).queue( function() {
counter++;
} );
@@ -235,7 +245,7 @@ QUnit.test( "fn.promise( \"queue\" ) - called whenever last queue function is de
foo.dequeue( "queue" );
} );
-if ( jQuery.fn.animate ) {
+if ( includesModule( "effects" ) ) {
QUnit.test( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", function( assert ) {
assert.expect( 2 );
@@ -271,64 +281,63 @@ QUnit.test( ".promise(obj)", function( assert ) {
assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" );
} );
-if ( jQuery.fn.stop ) {
- QUnit.test( "delay() can be stopped", function( assert ) {
- var done = assert.async();
- assert.expect( 3 );
- var storage = {};
- jQuery( {} )
- .queue( "alternate", function( next ) {
- storage.alt1 = true;
- assert.ok( true, "This first function was dequeued" );
- next();
- } )
- .delay( 1000, "alternate" )
- .queue( "alternate", function() {
- storage.alt2 = true;
- assert.ok( true, "The function was dequeued immediately, the delay was stopped" );
- } )
- .dequeue( "alternate" )
-
- // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
- .stop( "alternate", false, false )
-
- // this test
- .delay( 1 )
- .queue( function() {
- storage.default1 = true;
- assert.ok( false, "This queue should never run" );
- } )
-
- // stop( clearQueue ) should clear the queue
- .stop( true, false );
-
- assert.deepEqual( storage, { alt1: true, alt2: true }, "Queue ran the proper functions" );
+QUnit[ includesModule( "effects" ) ? "test" : "skip" ]( "delay() can be stopped", function( assert ) {
+ var done = assert.async();
+ assert.expect( 3 );
+ var storage = {};
+ jQuery( {} )
+ .queue( "alternate", function( next ) {
+ storage.alt1 = true;
+ assert.ok( true, "This first function was dequeued" );
+ next();
+ } )
+ .delay( 1000, "alternate" )
+ .queue( "alternate", function() {
+ storage.alt2 = true;
+ assert.ok( true, "The function was dequeued immediately, the delay was stopped" );
+ } )
+ .dequeue( "alternate" )
- setTimeout( function() {
- done();
- }, 1500 );
- } );
+ // stop( "alternate", false ) will NOT clear the queue, so it should automatically dequeue the next
+ .stop( "alternate", false, false )
- QUnit.test( "queue stop hooks", function( assert ) {
- assert.expect( 2 );
- var done = assert.async();
- var foo = jQuery( "#foo" );
+ // this test
+ .delay( 1 )
+ .queue( function() {
+ storage.default1 = true;
+ assert.ok( false, "This queue should never run" );
+ } )
- foo.queue( function( next, hooks ) {
- hooks.stop = function( gotoEnd ) {
- assert.equal( !!gotoEnd, false, "Stopped without gotoEnd" );
- };
- } );
- foo.stop();
+ // stop( clearQueue ) should clear the queue
+ .stop( true, false );
- foo.queue( function( next, hooks ) {
- hooks.stop = function( gotoEnd ) {
- assert.equal( gotoEnd, true, "Stopped with gotoEnd" );
- done();
- };
- } );
+ assert.deepEqual( storage, { alt1: true, alt2: true }, "Queue ran the proper functions" );
+
+ setTimeout( function() {
+ done();
+ }, 1500 );
+} );
+
+QUnit[ includesModule( "effects" ) ? "test" : "skip" ]( "queue stop hooks", function( assert ) {
+ assert.expect( 2 );
+ var done = assert.async();
+ var foo = jQuery( "#foo" );
- foo.stop( false, true );
+ foo.queue( function( next, hooks ) {
+ hooks.stop = function( gotoEnd ) {
+ assert.equal( !!gotoEnd, false, "Stopped without gotoEnd" );
+ };
} );
+ foo.stop();
+
+ foo.queue( function( next, hooks ) {
+ hooks.stop = function( gotoEnd ) {
+ assert.equal( gotoEnd, true, "Stopped with gotoEnd" );
+ done();
+ };
+ } );
+
+ foo.stop( false, true );
+} );
-} // if ( jQuery.fn.stop )
+} )();
diff --git a/test/unit/ready.js b/test/unit/ready.js
index d3396b1c49..a476528def 100644
--- a/test/unit/ready.js
+++ b/test/unit/ready.js
@@ -2,7 +2,7 @@ QUnit.module( "ready" );
( function() {
var notYetReady, noEarlyExecution,
- whenified = jQuery.when( jQuery.ready ),
+ whenified = jQuery.when && jQuery.when( jQuery.ready ),
promisified = Promise.resolve( jQuery.ready ),
start = new Date(),
order = [],
@@ -105,33 +105,33 @@ QUnit.module( "ready" );
} );
} );
- QUnit.test( "jQuery.when(jQuery.ready)", function( assert ) {
+ QUnit[ includesModule( "deferred" ) ? "test" : "skip" ]( "jQuery.when(jQuery.ready)", function( assert ) {
assert.expect( 2 );
- var done = jQuery.map( new Array( 2 ), function() { return assert.async(); } );
+ var done = assert.async( 2 );
whenified.then( function() {
assert.ok( jQuery.isReady, "jQuery.when Deferred resolved" );
- done.pop()();
+ done();
} );
jQuery.when( jQuery.ready ).then( function() {
assert.ok( jQuery.isReady, "jQuery.when Deferred resolved" );
- done.pop()();
+ done();
} );
} );
QUnit.test( "Promise.resolve(jQuery.ready)", function( assert ) {
assert.expect( 2 );
- var done = jQuery.map( new Array( 2 ), function() { return assert.async(); } );
+ var done = assert.async( 2 );
promisified.then( function() {
assert.ok( jQuery.isReady, "Native promised resolved" );
- done.pop()();
+ done();
} );
Promise.resolve( jQuery.ready ).then( function() {
assert.ok( jQuery.isReady, "Native promised resolved" );
- done.pop()();
+ done();
} );
} );
@@ -149,15 +149,18 @@ QUnit.module( "ready" );
} );
} );
- testIframe(
- "holdReady test needs to be a standalone test since it deals with DOM ready",
- "readywait.html",
- function( assert, jQuery, window, document, releaseCalled ) {
- assert.expect( 2 );
- var now = new Date();
- assert.ok( now - start >= 300, "Needs to have waited at least half a second" );
- assert.ok( releaseCalled, "The release function was called, which resulted in ready" );
- }
- );
+ // jQuery.holdReady is deprecated, skip the test if it was excluded.
+ if ( includesModule( "deprecated" ) ) {
+ testIframe(
+ "holdReady test needs to be a standalone test since it deals with DOM ready",
+ "readywait.html",
+ function( assert, jQuery, window, document, releaseCalled ) {
+ assert.expect( 2 );
+ var now = new Date();
+ assert.ok( now - start >= 300, "Needs to have waited at least half a second" );
+ assert.ok( releaseCalled, "The release function was called, which resulted in ready" );
+ }
+ );
+ }
} )();
diff --git a/test/unit/selector.js b/test/unit/selector.js
index f9c6ffc7a2..d6f28e25b9 100644
--- a/test/unit/selector.js
+++ b/test/unit/selector.js
@@ -1,30 +1,234 @@
-QUnit.module( "selector", { afterEach: moduleTeardown } );
+QUnit.module( "selector", {
+ beforeEach: function() {
+
+ // Playwright WebKit on macOS doesn't expose `Safari` in its user agent
+ // string; use the "AppleWebKit" token. This token is also present
+ // in the Chromium UA, but it is locked to an older version there.
+ // Modern WebKit (Safari 13+) locks it to `605.1.15`.
+ this.safari = /\bapplewebkit\/605\.1\.15\b/i.test( navigator.userAgent );
+ },
+ afterEach: moduleTeardown
+} );
+
+QUnit.test( "empty", function( assert ) {
+ assert.expect( 5 );
+
+ var form;
+
+ assert.strictEqual( jQuery( "" ).length, 0,
+ "Empty selector returns an empty array" );
-/**
- * This test page is for selector tests that require jQuery in order to do the selection
- */
+ assert.deepEqual( jQuery( "div", document.createTextNode( "" ) ).get(), [],
+ "Text element as context fails silently" );
+ form = document.getElementById( "form" );
+ assert.ok( !jQuery( form ).is( "" ), "Empty string passed to .is() does not match" );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.equal( jQuery( " " ).length, 0, "Empty selector returns an empty array" );
+ assert.equal( jQuery( "\t" ).length, 0, "Empty selector returns an empty array" );
+ } else {
+ assert.ok( "skip", "whitespace-only selector not supported in selector-native" );
+ assert.ok( "skip", "whitespace-only selector not supported in selector-native" );
+ }
+} );
+
+QUnit.test( "star", function( assert ) {
+ assert.expect( 2 );
+
+ var good, i,
+ all = jQuery( "*" );
+
+ assert.ok( all.length >= 30, "Select all" );
+ good = true;
+ for ( i = 0; i < all.length; i++ ) {
+ if ( all[ i ].nodeType === 8 ) {
+ good = false;
+ }
+ }
+ assert.ok( good, "Select all elements, no comment nodes" );
+} );
QUnit.test( "element", function( assert ) {
- assert.expect( 7 );
+ assert.expect( 37 );
- var fixture = document.getElementById( "qunit-fixture" );
+ var i, lengthtest, siblingTest, html,
+ fixture = document.getElementById( "qunit-fixture" );
assert.deepEqual( jQuery( "p", fixture ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a Node context." );
assert.deepEqual( jQuery( "p", "#qunit-fixture" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a selector context." );
assert.deepEqual( jQuery( "p", jQuery( "#qunit-fixture" ) ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a jQuery object context." );
assert.deepEqual( jQuery( "#qunit-fixture" ).find( "p" ).get(), q( "firstp", "ap", "sndp", "en", "sap", "first" ), "Finding elements with a context via .find()." );
- assert.ok( jQuery( "#length" ).length, "
cannot be found under IE, see #945" );
- assert.ok( jQuery( "#lengthtest input" ).length, "
cannot be found under IE, see #945" );
+ assert.ok( jQuery( "#length" ).length, "
cannot be found under IE, see trac-945" );
+ assert.ok( jQuery( "#lengthtest input" ).length, "
cannot be found under IE, see trac-945" );
- // #7533
+ // trac-7533
assert.equal( jQuery( "
" ).find( "p" ).length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" );
+
+ assert.equal( jQuery( "" ).length, 0, "Empty selector returns an empty array" );
+ assert.deepEqual( jQuery( "div", document.createTextNode( "" ) ).get(), [],
+ "Text element as context fails silently" );
+
+ assert.t( "Element Selector", "html", [ "html" ] );
+ assert.t( "Element Selector", "body", [ "body" ] );
+ assert.t( "Element Selector", "#qunit-fixture p", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+
+ assert.t( "Leading space", " #qunit-fixture p", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Leading tab", "\t#qunit-fixture p", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Leading carriage return", "\r#qunit-fixture p", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Leading line feed", "\n#qunit-fixture p", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Leading form feed", "\f#qunit-fixture p", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Trailing space", "#qunit-fixture p ", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Trailing tab", "#qunit-fixture p\t", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Trailing carriage return", "#qunit-fixture p\r",
+ [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Trailing line feed", "#qunit-fixture p\n", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Trailing form feed", "#qunit-fixture p\f", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+
+ assert.deepEqual(
+ jQuery( jQuery( "div ol" ) ).filter( "#qunit-fixture *" ).get(),
+ q( "empty", "listWithTabIndex" ),
+ "Parent Element"
+ );
+ assert.deepEqual(
+ jQuery( jQuery( "div\tol" ) ).filter( "#qunit-fixture *" ).get(),
+ q( "empty", "listWithTabIndex" ),
+ "Parent Element (non-space descendant combinator)"
+ );
+
+ // Check for unique-ness and sort order
+ assert.deepEqual( jQuery( "p, div p" ), jQuery( "p" ), "Check for duplicates: p, div p" );
+
+ jQuery( "
" ).prependTo( "#qunit-fixture" );
+ assert.t( "Checking sort order", "#qunit-fixture h2, #qunit-fixture h1", [ "h1", "h2", "h2-2" ] );
+
+ if ( QUnit.jQuerySelectorsPos ) {
+ assert.t( "Checking sort order", "#qunit-fixture h2:first, #qunit-fixture h1:first", [ "h1", "h2" ] );
+ } else {
+ assert.ok( "skip", "Positional selectors are not supported" );
+ }
+
+ assert.t( "Checking sort order", "#qunit-fixture p, #qunit-fixture p a",
+ [ "firstp", "simon1", "ap", "google", "groups", "anchor1", "mark", "sndp", "en", "yahoo",
+ "sap", "anchor2", "simon", "first" ] );
+
+ // Test Conflict ID
+ lengthtest = document.getElementById( "lengthtest" );
+ assert.deepEqual( jQuery( "#idTest", lengthtest ).get(), q( "idTest" ),
+ "Finding element with id of ID." );
+ assert.deepEqual( jQuery( "[name='id']", lengthtest ).get(), q( "idTest" ),
+ "Finding element with id of ID." );
+ assert.deepEqual( jQuery( "input[id='idTest']", lengthtest ).get(), q( "idTest" ),
+ "Finding elements with id of ID." );
+
+ siblingTest = document.getElementById( "siblingTest" );
+ assert.deepEqual( jQuery( "div em", siblingTest ).get(), [],
+ "Element-rooted QSA does not select based on document context" );
+ assert.deepEqual( jQuery( "div em, div em, div em:not(div em)", siblingTest ).get(), [],
+ "Element-rooted QSA does not select based on document context" );
+ assert.deepEqual( jQuery( "div em, em\\,", siblingTest ).get(), [],
+ "Escaped commas do not get treated with an id in element-rooted QSA" );
+
+ html = "";
+ for ( i = 0; i < 100; i++ ) {
+ html = "
" + html + "
";
+ }
+ html = jQuery( html ).appendTo( document.body );
+ assert.ok( !!jQuery( "body div div div" ).length,
+ "No stack or performance problems with large amounts of descendants" );
+ assert.ok( !!jQuery( "body>div div div" ).length,
+ "No stack or performance problems with large amounts of descendants" );
+ html.remove();
+
+ // Real use case would be using .watch in browsers with window.watch
+ // (see https://github.com/jquery/sizzle/pull/157)
+ q( "qunit-fixture" )[ 0 ].appendChild( document.createElement( "toString" ) ).id = "toString";
+ assert.t( "Element name matches Object.prototype property", "toString#toString", [ "toString" ] );
+} );
+
+QUnit.test( "XML Document Selectors", function( assert ) {
+ assert.expect( 11 );
+
+ var xml = createWithFriesXML();
+
+ assert.equal( jQuery( "foo_bar", xml ).length, 1, "Element Selector with underscore" );
+ assert.equal( jQuery( ".component", xml ).length, 1, "Class selector" );
+ assert.equal( jQuery( "[class*=component]", xml ).length, 1, "Attribute selector for class" );
+ assert.equal( jQuery( "property[name=prop2]", xml ).length, 1, "Attribute selector with name" );
+ assert.equal( jQuery( "[name=prop2]", xml ).length, 1, "Attribute selector with name" );
+ assert.equal( jQuery( "#seite1", xml ).length, 1, "Attribute selector with ID" );
+ assert.equal( jQuery( "component#seite1", xml ).length, 1, "Attribute selector with ID" );
+ assert.equal( jQuery( "component", xml ).filter( "#seite1" ).length, 1,
+ "Attribute selector filter with ID" );
+ assert.equal( jQuery( "meta property thing", xml ).length, 2,
+ "Descendent selector and dir caching" );
+ if ( QUnit.jQuerySelectors ) {
+ assert.ok( jQuery( xml.lastChild ).is( "soap\\:Envelope" ), "Check for namespaced element" );
+
+ xml = jQuery.parseXML( "
" );
+
+ assert.equal( jQuery( "elem:not(:has(*))", xml ).length, 1,
+ "Non-qSA path correctly handles numeric ids (jQuery trac-14142)" );
+ } else {
+ assert.ok( "skip", "namespaced elements not matching correctly in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ }
+} );
+
+QUnit.test( "broken selectors throw", function( assert ) {
+ assert.expect( 33 );
+
+ function broken( name, selector ) {
+ assert.throws( function() {
+ jQuery( selector );
+ }, name + ": " + selector );
+ }
+
+ broken( "Broken Selector", "[" );
+ broken( "Broken Selector", "(" );
+ broken( "Broken Selector", "{" );
+ broken( "Broken Selector", "<" );
+ broken( "Broken Selector", "()" );
+ broken( "Broken Selector", "<>" );
+ broken( "Broken Selector", "{}" );
+ broken( "Broken Selector", "," );
+ broken( "Broken Selector", ",a" );
+ broken( "Broken Selector", "a," );
+ broken( "Post-comma invalid selector", "*,:x" );
+ broken( "Identifier with bad escape", "foo\\\fbaz" );
+ broken( "Broken Selector", "[id=012345678901234567890123456789" );
+ broken( "Doesn't exist", ":visble" );
+ broken( "Nth-child", ":nth-child" );
+ broken( "Nth-child", ":nth-child(-)" );
+ 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)" );
+ broken( "Nth-last-last-child", ":nth-last-last-child(1)" );
+ broken( "First-last-child", ":first-last-child" );
+ broken( "Last-last-child", ":last-last-child" );
+ broken( "Only-last-child", ":only-last-child" );
+
+ // Make sure attribute value quoting works correctly. See: trac-6093
+ jQuery( "
" +
+ "
" )
+ .appendTo( "#qunit-fixture" );
+
+ broken( "Attribute equals non-value", "input[name=]" );
+ broken( "Attribute equals unquoted non-identifier", "input[name=foo.baz]" );
+ broken( "Attribute equals unquoted non-identifier", "input[name=foo[baz]]" );
+ broken( "Attribute equals bad string", "input[name=''double-quoted'']" );
+ broken( "Attribute equals bad string", "input[name='apostrophe'd']" );
} );
QUnit.test( "id", function( assert ) {
- assert.expect( 26 );
+ assert.expect( 35 );
- var a;
+ var fiddle, a, lengthtest;
assert.t( "ID Selector", "#body", [ "body" ] );
assert.t( "ID Selector w/ Element", "body#body", [ "body" ] );
@@ -37,25 +241,61 @@ QUnit.test( "id", function( assert ) {
assert.t( "Child ID selector using UTF8", "form > #台北", [ "台北" ] );
assert.t( "Escaped ID", "#foo\\:bar", [ "foo:bar" ] );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Escaped ID with descendant", "#foo\\:bar span:not(:input)", [ "foo_descendant" ] );
+ } else {
+ assert.ok( "skip", ":input not supported in selector-native" );
+ }
+
assert.t( "Escaped ID", "#test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
assert.t( "Descendant escaped ID", "div #foo\\:bar", [ "foo:bar" ] );
assert.t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
assert.t( "Child escaped ID", "form > #foo\\:bar", [ "foo:bar" ] );
assert.t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
- assert.t( "ID Selector, child ID present", "#form > #radio1", [ "radio1" ] ); // bug #267
+ fiddle = jQuery( "
" )
+ .appendTo( "#qunit-fixture" );
+
+ assert.deepEqual( jQuery( "> span", jQuery( "#fiddle\\\\Foo" )[ 0 ] ).get(),
+ q( [ "fiddleSpan" ] ), "Escaped ID as context" );
+
+ fiddle.remove();
+
+ assert.t( "ID Selector, child ID present", "#form > #radio1", [ "radio1" ] ); // bug trac-267
assert.t( "ID Selector, not an ancestor ID", "#form #first", [] );
assert.t( "ID Selector, not a child ID", "#form > #option1a", [] );
assert.t( "All Children of ID", "#foo > *", [ "sndp", "en", "sap" ] );
assert.t( "All Children of ID with no children", "#firstUL > *", [] );
+ assert.equal( jQuery( "#tName1" )[ 0 ].id, "tName1",
+ "ID selector with same value for a name attribute" );
+ assert.t( "ID selector non-existing but name attribute on an A tag", "#tName2", [] );
+ assert.t( "Leading ID selector non-existing but name attribute on an A tag", "#tName2 span", [] );
+ assert.t( "Leading ID selector existing, retrieving the child", "#tName1 span", [ "tName1-span" ] );
+ assert.equal( jQuery( "div > div #tName1" )[ 0 ].id, jQuery( "#tName1-span" )[ 0 ].parentNode.id,
+ "Ending with ID" );
+
a = jQuery( "
" ).appendTo( "#qunit-fixture" );
assert.t( "ID Selector contains backslash", "#backslash\\\\foo", [ "backslash\\foo" ] );
+ a.remove();
assert.t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", [ "lengthtest" ] );
- assert.t( "ID selector with non-existent ancestor", "#asdfasdf #foobar", [] ); // bug #986
+ // Run the above test again but with `jQuery.find` directly to avoid the jQuery
+ // quick path that avoids running the selector engine.
+ lengthtest = jQuery.find( "#lengthtest" );
+ assert.strictEqual(
+ lengthtest && lengthtest[ 0 ],
+ document.getElementById( "lengthtest" ),
+ "ID Selector on Form with an input that has a name of 'id' - no quick path (#lengthtest)"
+ );
+
+ assert.t( "ID selector with non-existent ancestor", "#asdfasdf #foobar", [] ); // bug trac-986
+
+ assert.deepEqual( jQuery( "div#form", document.body ).get(), [],
+ "ID selector within the context of another element" );
assert.t( "Underscore ID", "#types_all", [ "types_all" ] );
assert.t( "Dash ID", "#qunit-fixture", [ "qunit-fixture" ] );
@@ -64,16 +304,72 @@ QUnit.test( "id", function( assert ) {
} );
QUnit.test( "class", function( assert ) {
- assert.expect( 4 );
-
- assert.deepEqual( jQuery( ".blog", document.getElementsByTagName( "p" ) ).get(), q( "mark", "simon" ), "Finding elements with a context." );
- assert.deepEqual( jQuery( ".blog", "p" ).get(), q( "mark", "simon" ), "Finding elements with a context." );
- assert.deepEqual( jQuery( ".blog", jQuery( "p" ) ).get(), q( "mark", "simon" ), "Finding elements with a context." );
- assert.deepEqual( jQuery( "p" ).find( ".blog" ).get(), q( "mark", "simon" ), "Finding elements with a context." );
+ assert.expect( 32 );
+
+ assert.deepEqual( jQuery( ".blog", document.getElementsByTagName( "p" ) ).get(),
+ q( "mark", "simon" ), "Finding elements with a context." );
+ assert.deepEqual( jQuery( ".blog", "p" ).get(),
+ q( "mark", "simon" ), "Finding elements with a context." );
+ assert.deepEqual( jQuery( ".blog", jQuery( "p" ) ).get(),
+ q( "mark", "simon" ), "Finding elements with a context." );
+ assert.deepEqual( jQuery( "p" ).find( ".blog" ).get(),
+ q( "mark", "simon" ), "Finding elements with a context." );
+
+ assert.t( "Class Selector", ".blog", [ "mark", "simon" ] );
+ assert.t( "Class Selector", ".GROUPS", [ "groups" ] );
+ assert.t( "Class Selector", ".blog.link", [ "simon" ] );
+ assert.t( "Class Selector w/ Element", "a.blog", [ "mark", "simon" ] );
+ assert.t( "Parent Class Selector", "p .blog", [ "mark", "simon" ] );
+
+ assert.t( "Class selector using UTF8", ".台北Táiběi", [ "utf8class1" ] );
+ assert.t( "Class selector using UTF8", ".台北", [ "utf8class1", "utf8class2" ] );
+ assert.t( "Class selector using UTF8", ".台北Táiběi.台北", [ "utf8class1" ] );
+ assert.t( "Class selector using UTF8", ".台北Táiběi, .台北", [ "utf8class1", "utf8class2" ] );
+ assert.t( "Descendant class selector using UTF8", "div .台北Táiběi", [ "utf8class1" ] );
+ assert.t( "Child class selector using UTF8", "form > .台北Táiběi", [ "utf8class1" ] );
+
+ assert.t( "Escaped Class", ".foo\\:bar", [ "foo:bar" ] );
+ assert.t( "Escaped Class", ".test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
+ assert.t( "Descendant escaped Class", "div .foo\\:bar", [ "foo:bar" ] );
+ assert.t( "Descendant escaped Class", "div .test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
+ assert.t( "Child escaped Class", "form > .foo\\:bar", [ "foo:bar" ] );
+ assert.t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", [ "test.foo[5]bar" ] );
+
+ var div = document.createElement( "div" );
+ div.innerHTML = "
";
+ assert.deepEqual( jQuery( ".e", div ).get(), [ div.firstChild ], "Finding a second class." );
+
+ div.lastChild.className = "e";
+
+ assert.ok( !jQuery( div ).is( ".null" ),
+ ".null does not match an element with no class" );
+ assert.ok( !jQuery( div.firstChild ).is( ".null div" ),
+ ".null does not match an element with no class" );
+ div.className = "null";
+ assert.ok( jQuery( div ).is( ".null" ), ".null matches element with class 'null'" );
+ assert.ok( jQuery( div.firstChild ).is( ".null div" ),
+ "caching system respects DOM changes" );
+ assert.ok( !jQuery( document ).is( ".foo" ),
+ "testing class on document doesn't error" );
+ assert.ok( !jQuery( window ).is( ".foo" ), "testing class on window doesn't error" );
+
+ assert.deepEqual( jQuery( ".e", div ).get(), [ div.firstChild, div.lastChild ],
+ "Finding a modified class." );
+
+ div.lastChild.className += " hasOwnProperty toString";
+ assert.deepEqual( jQuery( ".e.hasOwnProperty.toString", div ).get(), [ div.lastChild ],
+ "Classes match Object.prototype properties" );
+
+ div = jQuery( "
" )[ 0 ];
+ assert.equal( jQuery( ".foo", div ).length, 1, "Class selector against SVG container" );
+ assert.equal( jQuery( ".foo", div.firstChild ).length, 1,
+ "Class selector directly against SVG" );
} );
QUnit.test( "name", function( assert ) {
- assert.expect( 5 );
+ assert.expect( 14 );
var form;
@@ -81,143 +377,299 @@ QUnit.test( "name", function( assert ) {
assert.t( "Name selector with single quotes", "input[name='action']", [ "text1" ] );
assert.t( "Name selector with double quotes", "input[name=\"action\"]", [ "text1" ] );
+ assert.t( "Name selector non-input", "[name=example]", [ "name-is-example" ] );
+ assert.t( "Name selector non-input", "[name=div]", [ "name-is-div" ] );
+ assert.t( "Name selector non-input", "*[name=iframe]", [ "iframe" ] );
+
assert.t( "Name selector for grouped input", "input[name='types[]']", [ "types_all", "types_anime", "types_movie" ] );
+ form = document.getElementById( "form" );
+ assert.deepEqual( jQuery( "input[name=action]", form ).get(), q( "text1" ),
+ "Name selector within the context of another element" );
+ assert.deepEqual( jQuery( "input[name='foo[bar]']", form ).get(), q( "hidden2" ),
+ "Name selector for grouped form element within the context of another element" );
+
form = jQuery( "
" ).appendTo( "body" );
- assert.equal( jQuery( "input", form[ 0 ] ).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
+ assert.equal( jQuery( "input", form[ 0 ] ).length, 1,
+ "Make sure that rooted queries on forms (with possible expandos) work." );
form.remove();
+
+ assert.t( "Find elements that have similar IDs", "[name=tName1]", [ "tName1ID" ] );
+ assert.t( "Find elements that have similar IDs", "[name=tName2]", [ "tName2ID" ] );
+ assert.t( "Find elements that have similar IDs", "#tName2ID", [ "tName2ID" ] );
+
+ assert.t( "Case-sensitivity", "[name=tname1]", [] );
} );
-QUnit.test( "selectors with comma", function( assert ) {
- assert.expect( 4 );
+QUnit.test( "comma-separated", function( assert ) {
+ assert.expect( 10 );
- var fixture = jQuery( "
" );
+ var fixture = jQuery( "
" );
assert.equal( fixture.find( "h2, div p" ).filter( "p" ).length, 2, "has to find two
" );
assert.equal( fixture.find( "h2, div p" ).filter( "h2" ).length, 1, "has to find one
" );
assert.equal( fixture.find( "h2 , div p" ).filter( "p" ).length, 2, "has to find two " );
assert.equal( fixture.find( "h2 , div p" ).filter( "h2" ).length, 1, "has to find one
" );
+ assert.equal( fixture.find( "h2 ,div p" ).filter( "p" ).length, 2, "has to find two " );
+ assert.equal( fixture.find( "h2 ,div p" ).filter( "h2" ).length, 1, "has to find one
" );
+ assert.equal( fixture.find( "h2,div p" ).filter( "p" ).length, 2, "has to find two " );
+ assert.equal( fixture.find( "h2,div p" ).filter( "h2" ).length, 1, "has to find one
" );
+ assert.equal( fixture.find( "h2\t,\rdiv p" ).filter( "p" ).length, 2, "has to find two " );
+ assert.equal( fixture.find( "h2\t,\rdiv p" ).filter( "h2" ).length, 1, "has to find one
" );
+} );
+
+QUnit.test( "comma-separated, only supported natively (gh-5177)", function( assert ) {
+ assert.expect( 5 );
+
+ var fixture = jQuery( "
" );
+
+ fixture.appendTo( "#qunit-fixture" );
+
+ assert.equal( fixture.find( "input:valid, span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid , span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid ,span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid,span" ).length, 2, "has to find two elements" );
+ assert.equal( fixture.find( "input:valid\t,\rspan" ).length, 2, "has to find two elements" );
} );
QUnit.test( "child and adjacent", function( assert ) {
- assert.expect( 27 );
+ assert.expect( 43 );
+
+ var siblingFirst, en, nothiddendiv;
assert.t( "Child", "p > a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
- assert.t( "Child", "p> a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
- assert.t( "Child", "p >a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
- assert.t( "Child", "p>a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
+ assert.t( "Child minus leading whitespace", "p> a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
+ assert.t( "Child minus trailing whitespace", "p >a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
+ assert.t( "Child minus whitespace", "p>a", [ "simon1", "google", "groups", "mark", "yahoo", "simon" ] );
assert.t( "Child w/ Class", "p > a.blog", [ "mark", "simon" ] );
assert.t( "All Children", "code > *", [ "anchor1", "anchor2" ] );
assert.selectInFixture( "All Grandchildren", "p > * > *", [ "anchor1", "anchor2" ] );
- assert.t( "Adjacent", "p + p", [ "ap", "en", "sap" ] );
- assert.t( "Adjacent", "p#firstp + p", [ "ap" ] );
- assert.t( "Adjacent", "p[lang=en] + p", [ "sap" ] );
- assert.t( "Adjacent", "a.GROUPS + code + a", [ "mark" ] );
+
+ assert.t( "Rooted tag adjacent", "#qunit-fixture a + a", [ "groups", "tName2ID" ] );
+ assert.t( "Rooted tag adjacent minus whitespace", "#qunit-fixture a+a", [ "groups", "tName2ID" ] );
+ assert.t( "Rooted tag adjacent minus leading whitespace", "#qunit-fixture a +a",
+ [ "groups", "tName2ID" ] );
+ assert.t( "Rooted tag adjacent minus trailing whitespace", "#qunit-fixture a+ a",
+ [ "groups", "tName2ID" ] );
+
+ assert.t( "Tag adjacent", "p + p", [ "ap", "en", "sap" ] );
+ assert.t( "#id adjacent", "#firstp + p", [ "ap" ] );
+ assert.t( "Tag#id adjacent", "p#firstp + p", [ "ap" ] );
+ assert.t( "Tag[attr] adjacent", "p[lang=en] + p", [ "sap" ] );
+ assert.t( "Tag.class adjacent", "a.GROUPS + code + a", [ "mark" ] );
+ assert.t( "Comma, Child, and Adjacent", "#qunit-fixture a + a, code > a",
+ [ "groups", "anchor1", "anchor2", "tName2ID" ] );
+
+ assert.t( "Element Preceded By", "#qunit-fixture p ~ div",
+ [ "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ] );
+ assert.t( "Element Preceded By", "#first ~ div",
+ [ "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ] );
assert.t( "Element Preceded By", "#groups ~ a", [ "mark" ] );
assert.t( "Element Preceded By", "#length ~ input", [ "idTest" ] );
assert.t( "Element Preceded By", "#siblingfirst ~ em", [ "siblingnext", "siblingthird" ] );
assert.t( "Element Preceded By (multiple)", "#siblingTest em ~ em ~ em ~ span", [ "siblingspan" ] );
- if ( jQuery.find.compile ) {
+ siblingFirst = document.getElementById( "siblingfirst" );
+
+ assert.deepEqual( jQuery( "+ em", siblingFirst ).get(), q( "siblingnext" ),
+ "Element Directly Preceded By with a context." );
+ assert.deepEqual( jQuery( "~ em", siblingFirst ).get(), q( "siblingnext", "siblingthird" ),
+ "Element Preceded By with a context." );
+
+ if ( QUnit.jQuerySelectorsPos ) {
+ assert.deepEqual( jQuery( "~ em:first", siblingFirst ).get(), q( "siblingnext" ),
+ "Element Preceded By positional with a context." );
+ } else {
+ assert.ok( "skip", "Positional selectors are not supported" );
+ }
+
+ en = document.getElementById( "en" );
+ assert.deepEqual( jQuery( "+ p, a", en ).get(), q( "yahoo", "sap" ),
+ "Compound selector with context, beginning with sibling test." );
+ assert.deepEqual( jQuery( "a, + p", en ).get(), q( "yahoo", "sap" ),
+ "Compound selector with context, containing sibling test." );
+
+ if ( QUnit.jQuerySelectors ) {
assert.t( "Element Preceded By, Containing", "#liveHandlerOrder ~ div em:contains('1')", [ "siblingfirst" ] );
assert.t( "Combinators are not skipped when mixing general and specific", "#siblingTest > em:contains('x') + em ~ span", [] );
- assert.equal( jQuery( "#listWithTabIndex li:eq(2) ~ li" ).length, 1, "Find by general sibling combinator (#8310)" );
} else {
assert.ok( "skip", ":contains not supported in selector-native" );
assert.ok( "skip", ":contains not supported in selector-native" );
- assert.ok( "skip", ":eq not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectorsPos ) {
+ assert.equal( jQuery( "#listWithTabIndex li:eq(2) ~ li" ).length, 1, "Find by general sibling combinator (trac-8310)" );
+
+ nothiddendiv = document.getElementById( "nothiddendiv" );
+ assert.deepEqual( jQuery( "> :first", nothiddendiv ).get(), q( "nothiddendivchild" ),
+ "Verify child context positional selector" );
+ assert.deepEqual( jQuery( "> :eq(0)", nothiddendiv ).get(), q( "nothiddendivchild" ),
+ "Verify child context positional selector" );
+ assert.deepEqual( jQuery( "> *:first", nothiddendiv ).get(), q( "nothiddendivchild" ),
+ "Verify child context positional selector" );
+ } else {
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
}
assert.t( "Multiple combinators selects all levels", "#siblingTest em *", [ "siblingchild", "siblinggrandchild", "siblinggreatgrandchild" ] );
assert.t( "Multiple combinators selects all levels", "#siblingTest > em *", [ "siblingchild", "siblinggrandchild", "siblinggreatgrandchild" ] );
assert.t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", [ "siblingspan" ] );
- assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for next test is found via ID (#8310)" );
- assert.equal( jQuery( "#__sizzle__" ).length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" );
- assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for previous test is still found via ID (#8310)" );
+ assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for next test is found via ID (trac-8310)" );
+ assert.equal( jQuery( "#__sizzle__" ).length, 0, "Make sure the temporary id assigned by sizzle is cleared out (trac-8310)" );
+ assert.equal( jQuery( "#listWithTabIndex" ).length, 1, "Parent div for previous test is still found via ID (trac-8310)" );
assert.t( "Verify deep class selector", "div.blah > p > a", [] );
assert.t( "No element deep selector", "div.foo > span > a", [] );
assert.t( "Non-existent ancestors", ".fototab > .thumbnails > a", [] );
} );
-QUnit.test( "attributes", function( assert ) {
- assert.expect( 54 );
+QUnit.test( "attributes - existence", function( assert ) {
+ assert.expect( 7 );
+
+ assert.t( "On element", "#qunit-fixture a[title]", [ "google" ] );
+ assert.t( "On element (whitespace ignored)", "#qunit-fixture a[ title ]", [ "google" ] );
+ assert.t( "On element (case-insensitive)", "#qunit-fixture a[TITLE]", [ "google" ] );
+ assert.t( "On any element", "#qunit-fixture *[title]", [ "google" ] );
+ assert.t( "On implicit element", "#qunit-fixture [title]", [ "google" ] );
+ assert.t( "Boolean", "#select2 option[selected]", [ "option2d" ] );
+ assert.t( "For attribute on label", "form label[for]", [ "label-for" ] );
+} );
+
+QUnit.test( "attributes - equals", function( assert ) {
+ assert.expect( 20 );
- var attrbad, div, withScript;
+ var withScript;
- assert.t( "Find elements with a tabindex attribute", "[tabindex]", [ "listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex" ] );
+ assert.t( "Identifier", "#qunit-fixture a[rel=bookmark]", [ "simon1" ] );
+ assert.t( "Identifier with underscore", "input[id=types_all]", [ "types_all" ] );
+ assert.t( "String", "#qunit-fixture a[rel='bookmark']", [ "simon1" ] );
+ assert.t( "String (whitespace ignored)", "#qunit-fixture a[ rel = 'bookmark' ]", [ "simon1" ] );
+ assert.t( "Non-identifier string", "#qunit-fixture a[href='https://www.google.com/']", [ "google" ] );
+ assert.t( "Empty string", "#select1 option[value='']", [ "option1a" ] );
- assert.t( "Attribute Exists", "#qunit-fixture a[title]", [ "google" ] );
- assert.t( "Attribute Exists (case-insensitive)", "#qunit-fixture a[TITLE]", [ "google" ] );
- assert.t( "Attribute Exists", "#qunit-fixture *[title]", [ "google" ] );
- assert.t( "Attribute Exists", "#qunit-fixture [title]", [ "google" ] );
- assert.t( "Attribute Exists", "#qunit-fixture a[ title ]", [ "google" ] );
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Number",
+ "#qunit-fixture option[value=1]",
+ [ "option1b", "option2b", "option3b", "option4b", "option5c" ] );
+ assert.t( "negative number",
+ "#qunit-fixture li[tabIndex=-1]", [ "foodWithNegativeTabIndex" ] );
+ } else {
+ assert.ok( "skip", "Number value not supported in selector-native" );
+ assert.ok( "skip", "Negative number value not supported in selector-native" );
+ }
- assert.t( "Boolean attribute exists", "#select2 option[selected]", [ "option2d" ] );
- assert.t( "Boolean attribute equals", "#select2 option[selected='selected']", [ "option2d" ] );
+ assert.t( "Non-ASCII identifier", "span[lang=中文]", [ "台北" ] );
- assert.t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", [ "simon1" ] );
- assert.t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", [ "simon1" ] );
- assert.t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", [ "simon1" ] );
- assert.t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", [ "google" ] );
- assert.t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", [ "simon1" ] );
- assert.t( "Attribute Equals Number", "#qunit-fixture option[value='1']", [ "option1b", "option2b", "option3b", "option4b", "option5c" ] );
- assert.t( "Attribute Equals Number", "#qunit-fixture li[tabIndex='-1']", [ "foodWithNegativeTabIndex" ] );
+ assert.t( "input[type=text]", "#form input[type=text]", [ "text1", "text2", "hidden2", "name" ] );
+ assert.t( "input[type=search]", "#form input[type=search]", [ "search" ] );
- document.getElementById( "anchor2" ).href = "#2";
- assert.t( "href Attribute", "p a[href^='#']", [ "anchor2" ] );
- assert.t( "href Attribute", "p a[href*='#']", [ "simon1", "anchor2" ] );
+ withScript = supportjQuery( "
" );
+ assert.ok( withScript.find( "#moretests script[src]" ).has( "script" ), "script[src] (jQuery trac-13777)" );
- assert.t( "for Attribute", "form label[for]", [ "label-for" ] );
+ assert.t( "Boolean attribute equals name", "#select2 option[selected='selected']", [ "option2d" ] );
assert.t( "for Attribute in form", "#form [for=action]", [ "label-for" ] );
+ assert.t( "Grouped Form Elements - name", "input[name='foo[bar]']", [ "hidden2" ] );
+ assert.t( "Value", "input[value=Test]", [ "text1", "text2" ] );
+
+ assert.deepEqual(
+ jQuery( "input[data-comma='0,1']" ).get(),
+ q( "el12087" ),
+ "Without context, single-quoted attribute containing ','" );
+ assert.deepEqual(
+ jQuery( "input[data-comma=\"0,1\"]" ).get(),
+ q( "el12087" ),
+ "Without context, double-quoted attribute containing ','" );
+ assert.deepEqual(
+ jQuery( "input[data-comma='0,1']", document.getElementById( "t12087" ) ).get(),
+ q( "el12087" ),
+ "With context, single-quoted attribute containing ','" );
+ assert.deepEqual(
+ jQuery( "input[data-comma=\"0,1\"]", document.getElementById( "t12087" ) ).get(),
+ q( "el12087" ),
+ "With context, double-quoted attribute containing ','" );
+} );
+
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "attributes - does not equal", function( assert ) {
+ assert.expect( 2 );
+
+ assert.t( "string", "#ap a[hreflang!='en']", [ "google", "groups", "anchor1" ] );
+ assert.t( "Empty values", "#select1 option[value!='']", [ "option1b", "option1c", "option1d" ] );
+} );
+
+QUnit.test( "attributes - starts with", function( assert ) {
+ assert.expect( 4 );
+
+ assert.t( "string (whitespace ignored)", "a[href ^= 'https://www']", [ "google", "yahoo" ] );
+ assert.t( "href starts with hash", "p a[href^='#']", [ "anchor2" ] );
+ assert.t( "string containing '['", "input[name^='foo[']", [ "hidden2" ] );
+ assert.t( "string containing '[' ... ']'", "input[name^='foo[bar]']", [ "hidden2" ] );
+} );
+
+QUnit.test( "attributes - contains", function( assert ) {
+ assert.expect( 4 );
+
+ assert.t( "string (whitespace ignored)", "a[href *= 'google']", [ "google", "groups" ] );
+ assert.t( "string like '[' ... ']']", "input[name*='[bar]']", [ "hidden2" ] );
+ assert.t( "string containing '['...']", "input[name*='foo[bar]']", [ "hidden2" ] );
+ assert.t( "href contains hash", "p a[href*='#']", [ "simon1", "anchor2" ] );
+} );
+
+QUnit.test( "attributes - ends with", function( assert ) {
+ assert.expect( 4 );
- assert.t( "Attribute containing []", "input[name^='foo[']", [ "hidden2" ] );
- assert.t( "Attribute containing []", "input[name^='foo[bar]']", [ "hidden2" ] );
- assert.t( "Attribute containing []", "input[name*='[bar]']", [ "hidden2" ] );
- assert.t( "Attribute containing []", "input[name$='bar]']", [ "hidden2" ] );
- assert.t( "Attribute containing []", "input[name$='[bar]']", [ "hidden2" ] );
+ assert.t( "string (whitespace ignored)", "a[href $= 'org/']", [ "mark" ] );
+ assert.t( "string ending with ']'", "input[name$='bar]']", [ "hidden2" ] );
+ assert.t( "string like '[' ... ']'", "input[name$='[bar]']", [ "hidden2" ] );
assert.t( "Attribute containing []", "input[name$='foo[bar]']", [ "hidden2" ] );
- assert.t( "Attribute containing []", "input[name*='foo[bar]']", [ "hidden2" ] );
+} );
- assert.t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type='hidden']", [ "radio1", "radio2", "hidden1" ] );
- assert.t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=\"hidden\"]", [ "radio1", "radio2", "hidden1" ] );
- assert.t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=hidden]", [ "radio1", "radio2", "hidden1" ] );
+QUnit.test( "attributes - whitespace list includes", function( assert ) {
+ assert.expect( 3 );
- assert.t( "Attribute selector using UTF8", "span[lang=中文]", [ "台北" ] );
+ assert.t( "string found at the beginning",
+ "input[data-15233~='foo']",
+ [ "t15233-single", "t15233-double", "t15233-double-tab", "t15233-double-nl", "t15233-triple" ] );
+ assert.t( "string found in the middle",
+ "input[data-15233~='bar']",
+ [ "t15233-double", "t15233-double-tab", "t15233-double-nl", "t15233-triple" ] );
+ assert.t( "string found at the end", "input[data-15233~='baz']", [ "t15233-triple" ] );
+} );
- assert.t( "Attribute Begins With", "a[href ^= 'http://www']", [ "google", "yahoo" ] );
- assert.t( "Attribute Ends With", "a[href $= 'org/']", [ "mark" ] );
- assert.t( "Attribute Contains", "a[href *= 'google']", [ "google", "groups" ] );
+QUnit.test( "attributes - hyphen-prefix matches", function( assert ) {
+ assert.expect( 3 );
- if ( jQuery.find.compile ) {
- assert.t( "Empty values", "#select1 option[value!='']", [ "option1b", "option1c", "option1d" ] );
- assert.t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", [ "google", "groups", "anchor1" ] );
- assert.t( "Select options via :selected", "#select1 option:selected", [ "option1a" ] );
- assert.t( "Select options via :selected", "#select2 option:selected", [ "option2d" ] );
- assert.t( "Select options via :selected", "#select3 option:selected", [ "option3b", "option3c" ] );
- assert.t( "Select options via :selected", "select[name='select2'] option:selected", [ "option2d" ] );
- } else {
- assert.ok( "skip", "!= not supported in selector-native" );
- assert.ok( "skip", "!= not supported in selector-native" );
- assert.ok( "skip", ":selected not supported in selector-native" );
- assert.ok( "skip", ":selected not supported in selector-native" );
- assert.ok( "skip", ":selected not supported in selector-native" );
- assert.ok( "skip", ":selected not supported in selector-native" );
- }
+ assert.t( "string", "#names-group span[id|='name']", [ "name-is-example", "name-is-div" ] );
+ assert.t( "string containing hyphen",
+ "#names-group span[id|='name-is']",
+ [ "name-is-example", "name-is-div" ] );
+ assert.t( "string ending with hyphen", "#names-group span[id|='name-is-']", [] );
+} );
- assert.t( "Empty values", "#select1 option[value='']", [ "option1a" ] );
+QUnit.test( "attributes - special characters", function( assert ) {
+ assert.expect( 16 );
+ var attrbad;
+ var div = document.createElement( "div" );
- assert.t( "Grouped Form Elements", "input[name='foo[bar]']", [ "hidden2" ] );
+ // trac-3729
+ div.innerHTML = "
";
+ assert.deepEqual( jQuery( "[xml\\:test]", div ).get(),
+ [ div.firstChild ],
+ "attribute name containing colon" );
- // Make sure attribute value quoting works correctly. See jQuery #6093; #6428; #13894
- // Use seeded results to bypass querySelectorAll optimizations
+ // Make sure attribute value quoting works correctly.
+ // See jQuery trac-6093; trac-6428; trac-13894.
+ // Use seeded results to bypass querySelectorAll optimizations.
attrbad = jQuery(
" " +
" " +
" " +
+ " " +
" " +
" " +
" " +
@@ -226,15 +678,76 @@ QUnit.test( "attributes", function( assert ) {
" "
).appendTo( "#qunit-fixture" ).get();
- assert.t( "Underscores don't need escaping", "input[id=types_all]", [ "types_all" ] );
- assert.t( "input[type=text]", "#form input[type=text]", [ "text1", "text2", "hidden2", "name" ] );
- assert.t( "input[type=search]", "#form input[type=search]", [ "search" ] );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[name=foo\\ bar]" ).get(),
+ q( "attrbad_space" ),
+ "identifier containing space" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[name=foo\\.baz]" ).get(),
+ q( "attrbad_dot" ),
+ "identifier containing dot" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[name=foo\\[baz\\]]" ).get(),
+ q( "attrbad_brackets" ),
+ "identifier containing brackets" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='foo_baz\\']']" ).get(),
+ q( "attrbad_injection" ),
+ "string containing quote and right bracket" );
+
+ assert.deepEqual( jQuery( attrbad ).filter( "input[value=\\30 \\30\\37 ]" ).get(),
+ q( "attrbad_leading_digits" ),
+ "identifier containing escaped leading digits with whitespace termination" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[value=\\00003007]" ).get(),
+ q( "attrbad_leading_digits" ),
+ "identifier containing escaped leading digits without whitespace termination" );
+
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\'']" ).get(),
+ q( "attrbad_quote" ),
+ "string containing quote" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\\\']" ).get(),
+ q( "attrbad_backslash" ),
+ "string containing backslash" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\\\\\'']" ).get(),
+ q( "attrbad_backslash_quote" ),
+ "string containing backslash and quote" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\\\\\\\']" ).get(),
+ q( "attrbad_backslash_backslash" ),
+ "string containing adjacent backslashes" );
+
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\5C\\\\']" ).get(),
+ q( "attrbad_backslash_backslash" ),
+ "string containing numeric-escape backslash and backslash" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\5C \\\\']" ).get(),
+ q( "attrbad_backslash_backslash" ),
+ "string containing numeric-escape-with-trailing-space backslash and backslash" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\5C\t\\\\']" ).get(),
+ q( "attrbad_backslash_backslash" ),
+ "string containing numeric-escape-with-trailing-tab backslash and backslash" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\04e00']" ).get(),
+ q( "attrbad_unicode" ),
+ "Long numeric escape (BMP)" );
+
+ document.getElementById( "attrbad_unicode" ).setAttribute( "data-attr", "\uD834\uDF06A" );
+ assert.deepEqual( jQuery( attrbad ).filter( "input[data-attr='\\01D306A']" ).get(),
+ q( "attrbad_unicode" ),
+ "Long numeric escape (non-BMP)" );
+} );
+
+QUnit.test( "attributes - others", function( assert ) {
+ assert.expect( 14 );
+
+ var div = document.getElementById( "foo" );
+
+ assert.t( "Find elements with a tabindex attribute", "[tabindex]", [ "listWithTabIndex", "foodWithNegativeTabIndex", "linkWithTabIndex", "linkWithNegativeTabIndex", "linkWithNoHrefWithTabIndex", "linkWithNoHrefWithNegativeTabIndex" ] );
- withScript = supportjQuery( "
" );
- assert.ok( withScript.find( "#moretests script[src]" ).has( "script" ), "script[src] (jQuery #13777)" );
+ assert.t( "Selector list with multiple quoted attribute-equals",
+ "#form input[type='radio'], #form input[type='hidden']",
+ [ "radio1", "radio2", "hidden1" ] );
+ assert.t( "Selector list with differently-quoted attribute-equals",
+ "#form input[type='radio'], #form input[type=\"hidden\"]",
+ [ "radio1", "radio2", "hidden1" ] );
+ assert.t( "Selector list with quoted and unquoted attribute-equals",
+ "#form input[type='radio'], #form input[type=hidden]",
+ [ "radio1", "radio2", "hidden1" ] );
- div = document.getElementById( "foo" );
assert.t( "Object.prototype property \"constructor\" (negative)", "[constructor]", [] );
assert.t( "Gecko Object.prototype property \"watch\" (negative)", "[watch]", [] );
div.setAttribute( "constructor", "foo" );
@@ -242,15 +755,617 @@ QUnit.test( "attributes", function( assert ) {
assert.t( "Object.prototype property \"constructor\"", "[constructor='foo']", [ "foo" ] );
assert.t( "Gecko Object.prototype property \"watch\"", "[watch='bar']", [ "foo" ] );
- assert.t( "Value attribute is retrieved correctly", "input[value=Test]", [ "text1", "text2" ] );
+ // trac-11115
+ assert.ok( jQuery( " " ).prop( "checked", false ).is( "[checked]" ),
+ "[checked] selects by attribute (positive)"
+ );
+ assert.ok( !jQuery( " " ).prop( "checked", true ).is( "[checked]" ),
+ "[checked] selects by attribute (negative)"
+ );
+
+ assert.t( "empty name", "[name='']", [ "name-empty" ] );
+ assert.t( "prefixed empty name", "#empty-name-parent [name='']", [ "name-empty" ] );
+
+ var emptyNameContainer = jQuery( ".empty-name-container" );
+ assert.deepEqual( emptyNameContainer.find( "[name='']" ).get(),
+ q( "name-empty" ),
+ "empty name with context" );
+ assert.deepEqual( emptyNameContainer.find( "#empty-name-parent [name='']" ).get(),
+ q( "name-empty" ),
+ "prefixed empty name with context" );
+} );
+
+QUnit.test( "pseudo - (parent|empty)", function( assert ) {
+ assert.expect( 3 );
+ assert.t( "Empty", "#qunit-fixture ul:empty", [ "firstUL" ] );
+ assert.t( "Empty with comment node", "#qunit-fixture ol:empty", [ "empty" ] );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Is A Parent", "#qunit-fixture p:parent",
+ [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ } else {
+ assert.ok( "skip", ":parent not supported in selector-native" );
+ }
+} );
+
+QUnit.test( "pseudo - (first|last|only)-(child|of-type)", function( assert ) {
+ assert.expect( 12 );
+
+ assert.t( "First Child", "#qunit-fixture p:first-child", [ "firstp", "sndp" ] );
+ assert.t( "First Child (leading id)", "#qunit-fixture p:first-child", [ "firstp", "sndp" ] );
+ assert.t( "First Child (leading class)", ".nothiddendiv div:first-child", [ "nothiddendivchild" ] );
+ assert.t( "First Child (case-insensitive)", "#qunit-fixture p:FIRST-CHILD", [ "firstp", "sndp" ] );
+
+ assert.t( "Last Child", "#qunit-fixture p:last-child", [ "sap" ] );
+ assert.t( "Last Child (leading id)", "#qunit-fixture a:last-child", [ "simon1", "anchor1", "mark", "yahoo", "anchor2", "simon", "liveLink1", "liveLink2" ] );
+
+ assert.t( "Only Child", "#qunit-fixture a:only-child", [ "simon1", "anchor1", "yahoo", "anchor2", "liveLink1", "liveLink2" ] );
+
+ assert.t( "First-of-type", "#qunit-fixture > p:first-of-type", [ "firstp" ] );
+ assert.t( "Last-of-type", "#qunit-fixture > p:last-of-type", [ "first" ] );
+ assert.t( "Only-of-type", "#qunit-fixture > :only-of-type", [ "name+value", "firstUL", "empty", "floatTest", "iframe", "table", "last" ] );
+
+ // Verify that the child position isn't being cached improperly
+ var secondChildren = jQuery( "p:nth-child(2)" ).before( "
" );
+
+ assert.t( "No longer second child", "p:nth-child(2)", [] );
+ secondChildren.prev().remove();
+ assert.t( "Restored second child", "p:nth-child(2)", [ "ap", "en" ] );
+} );
+
+QUnit.test( "pseudo - nth-child", function( assert ) {
+ assert.expect( 30 );
+
+ assert.t( "Nth-child", "p:nth-child(1)", [ "firstp", "sndp" ] );
+ assert.t( "Nth-child (with whitespace)", "p:nth-child( 1 )", [ "firstp", "sndp" ] );
+ assert.t( "Nth-child (case-insensitive)", "#form #select1 option:NTH-child(3)", [ "option1c" ] );
+ assert.t( "Not nth-child", "#qunit-fixture p:not(:nth-child(1))", [ "ap", "en", "sap", "first" ] );
+
+ assert.t( "Nth-child(2)", "#qunit-fixture form#form > *:nth-child(2)", [ "text1" ] );
+ assert.t( "Nth-child(2)", "#qunit-fixture form#form > :nth-child(2)", [ "text1" ] );
+
+ assert.t( "Nth-child(-1)", "#form #select1 option:nth-child(-1)", [] );
+ assert.t( "Nth-child(3)", "#form #select1 option:nth-child(3)", [ "option1c" ] );
+ assert.t( "Nth-child(0n+3)", "#form #select1 option:nth-child(0n+3)", [ "option1c" ] );
+ assert.t( "Nth-child(1n+0)", "#form #select1 option:nth-child(1n+0)", [ "option1a", "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-child(1n)", "#form #select1 option:nth-child(1n)", [ "option1a", "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-child(n)", "#form #select1 option:nth-child(n)", [ "option1a", "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-child(even)", "#form #select1 option:nth-child(even)", [ "option1b", "option1d" ] );
+ assert.t( "Nth-child(odd)", "#form #select1 option:nth-child(odd)", [ "option1a", "option1c" ] );
+ assert.t( "Nth-child(2n)", "#form #select1 option:nth-child(2n)", [ "option1b", "option1d" ] );
+ assert.t( "Nth-child(2n+1)", "#form #select1 option:nth-child(2n+1)", [ "option1a", "option1c" ] );
+ assert.t( "Nth-child(2n + 1)", "#form #select1 option:nth-child(2n + 1)", [ "option1a", "option1c" ] );
+ assert.t( "Nth-child(+2n + 1)", "#form #select1 option:nth-child(+2n + 1)", [ "option1a", "option1c" ] );
+ assert.t( "Nth-child(3n)", "#form #select1 option:nth-child(3n)", [ "option1c" ] );
+ assert.t( "Nth-child(3n+1)", "#form #select1 option:nth-child(3n+1)", [ "option1a", "option1d" ] );
+ assert.t( "Nth-child(3n+2)", "#form #select1 option:nth-child(3n+2)", [ "option1b" ] );
+ assert.t( "Nth-child(3n+3)", "#form #select1 option:nth-child(3n+3)", [ "option1c" ] );
+ assert.t( "Nth-child(3n-1)", "#form #select1 option:nth-child(3n-1)", [ "option1b" ] );
+ assert.t( "Nth-child(3n-2)", "#form #select1 option:nth-child(3n-2)", [ "option1a", "option1d" ] );
+ assert.t( "Nth-child(3n-3)", "#form #select1 option:nth-child(3n-3)", [ "option1c" ] );
+ assert.t( "Nth-child(3n+0)", "#form #select1 option:nth-child(3n+0)", [ "option1c" ] );
+ assert.t( "Nth-child(-1n+3)", "#form #select1 option:nth-child(-1n+3)", [ "option1a", "option1b", "option1c" ] );
+ assert.t( "Nth-child(-n+3)", "#form #select1 option:nth-child(-n+3)", [ "option1a", "option1b", "option1c" ] );
+ assert.t( "Nth-child(-1n + 3)", "#form #select1 option:nth-child(-1n + 3)", [ "option1a", "option1b", "option1c" ] );
+
+ if ( QUnit.jQuerySelectors || this.safari ) {
+ assert.deepEqual(
+ jQuery( [ document.createElement( "a" ) ].concat( q( "ap" ) ) )
+ .filter( ":nth-child(n)" )
+ .get(),
+ q( "ap" ),
+ "Seeded nth-child"
+ );
+ } else {
+
+ // Support: Chrome 75+, Firefox 67+
+ // Some browsers mark disconnected elements as matching `:nth-child(n)`
+ // so let's skip the test.
+ assert.ok( "skip", "disconnected elements match ':nth-child(n)' in Chrome/Firefox" );
+ }
+} );
+
+QUnit.test( "pseudo - nth-last-child", function( assert ) {
+ assert.expect( 30 );
+
+ jQuery( "#qunit-fixture" ).append( "" );
+ assert.t( "Nth-last-child", "form:nth-last-child(5)", [ "nth-last-child-form" ] );
+ assert.t( "Nth-last-child (with whitespace)", "form:nth-last-child( 5 )", [ "nth-last-child-form" ] );
+
+
+ assert.t( "Nth-last-child (case-insensitive)", "#form #select1 option:NTH-last-child(3)", [ "option1b" ] );
+ assert.t( "Not nth-last-child", "#qunit-fixture p:not(:nth-last-child(1))", [ "firstp", "ap", "sndp", "en", "first" ] );
+
+ assert.t( "Nth-last-child(-1)", "#form #select1 option:nth-last-child(-1)", [] );
+ assert.t( "Nth-last-child(3)", "#form #select1 :nth-last-child(3)", [ "option1b" ] );
+ assert.t( "Nth-last-child(3)", "#form #select1 *:nth-last-child(3)", [ "option1b" ] );
+ assert.t( "Nth-last-child(3)", "#form #select1 option:nth-last-child(3)", [ "option1b" ] );
+ assert.t( "Nth-last-child(0n+3)", "#form #select1 option:nth-last-child(0n+3)", [ "option1b" ] );
+ assert.t( "Nth-last-child(1n+0)", "#form #select1 option:nth-last-child(1n+0)", [ "option1a", "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-last-child(1n)", "#form #select1 option:nth-last-child(1n)", [ "option1a", "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-last-child(n)", "#form #select1 option:nth-last-child(n)", [ "option1a", "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-last-child(even)", "#form #select1 option:nth-last-child(even)", [ "option1a", "option1c" ] );
+ assert.t( "Nth-last-child(odd)", "#form #select1 option:nth-last-child(odd)", [ "option1b", "option1d" ] );
+ assert.t( "Nth-last-child(2n)", "#form #select1 option:nth-last-child(2n)", [ "option1a", "option1c" ] );
+ assert.t( "Nth-last-child(2n+1)", "#form #select1 option:nth-last-child(2n+1)", [ "option1b", "option1d" ] );
+ assert.t( "Nth-last-child(2n + 1)", "#form #select1 option:nth-last-child(2n + 1)", [ "option1b", "option1d" ] );
+ assert.t( "Nth-last-child(+2n + 1)", "#form #select1 option:nth-last-child(+2n + 1)", [ "option1b", "option1d" ] );
+ assert.t( "Nth-last-child(3n)", "#form #select1 option:nth-last-child(3n)", [ "option1b" ] );
+ assert.t( "Nth-last-child(3n+1)", "#form #select1 option:nth-last-child(3n+1)", [ "option1a", "option1d" ] );
+ assert.t( "Nth-last-child(3n+2)", "#form #select1 option:nth-last-child(3n+2)", [ "option1c" ] );
+ assert.t( "Nth-last-child(3n+3)", "#form #select1 option:nth-last-child(3n+3)", [ "option1b" ] );
+ assert.t( "Nth-last-child(3n-1)", "#form #select1 option:nth-last-child(3n-1)", [ "option1c" ] );
+ assert.t( "Nth-last-child(3n-2)", "#form #select1 option:nth-last-child(3n-2)", [ "option1a", "option1d" ] );
+ assert.t( "Nth-last-child(3n-3)", "#form #select1 option:nth-last-child(3n-3)", [ "option1b" ] );
+ assert.t( "Nth-last-child(3n+0)", "#form #select1 option:nth-last-child(3n+0)", [ "option1b" ] );
+ assert.t( "Nth-last-child(-1n+3)", "#form #select1 option:nth-last-child(-1n+3)", [ "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-last-child(-n+3)", "#form #select1 option:nth-last-child(-n+3)", [ "option1b", "option1c", "option1d" ] );
+ assert.t( "Nth-last-child(-1n + 3)", "#form #select1 option:nth-last-child(-1n + 3)", [ "option1b", "option1c", "option1d" ] );
+
+ if ( QUnit.jQuerySelectors || this.safari ) {
+ assert.deepEqual(
+ jQuery( [ document.createElement( "a" ) ].concat( q( "ap" ) ) )
+ .filter( ":nth-last-child(n)" )
+ .get(),
+ q( "ap" ),
+ "Seeded nth-last-child"
+ );
+ } else {
+
+ // Support: Chrome 75+, Firefox 67+
+ // Some browsers mark disconnected elements as matching `:nth-last-child(n)`
+ // so let's skip the test.
+ assert.ok( "skip", "disconnected elements match ':nth-last-child(n)' in Chrome/Firefox" );
+ }
+} );
+
+QUnit.test( "pseudo - nth-of-type", function( assert ) {
+ assert.expect( 9 );
+ assert.t( "Nth-of-type(-1)", ":nth-of-type(-1)", [] );
+ assert.t( "Nth-of-type(3)", "#ap :nth-of-type(3)", [ "mark" ] );
+ assert.t( "Nth-of-type(n)", "#ap :nth-of-type(n)", [ "google", "groups", "code1", "anchor1", "mark" ] );
+ assert.t( "Nth-of-type(0n+3)", "#ap :nth-of-type(0n+3)", [ "mark" ] );
+ assert.t( "Nth-of-type(2n)", "#ap :nth-of-type(2n)", [ "groups" ] );
+ assert.t( "Nth-of-type(even)", "#ap :nth-of-type(even)", [ "groups" ] );
+ assert.t( "Nth-of-type(2n+1)", "#ap :nth-of-type(2n+1)", [ "google", "code1", "anchor1", "mark" ] );
+ assert.t( "Nth-of-type(odd)", "#ap :nth-of-type(odd)", [ "google", "code1", "anchor1", "mark" ] );
+ assert.t( "Nth-of-type(-n+2)", "#qunit-fixture > :nth-of-type(-n+2)", [ "firstp", "ap", "foo", "nothiddendiv", "name+value", "firstUL", "empty", "form", "floatTest", "iframe", "lengthtest", "table", "last" ] );
+} );
+
+QUnit.test( "pseudo - nth-last-of-type", function( assert ) {
+ assert.expect( 9 );
+ assert.t( "Nth-last-of-type(-1)", ":nth-last-of-type(-1)", [] );
+ assert.t( "Nth-last-of-type(3)", "#ap :nth-last-of-type(3)", [ "google" ] );
+ assert.t( "Nth-last-of-type(n)", "#ap :nth-last-of-type(n)", [ "google", "groups", "code1", "anchor1", "mark" ] );
+ assert.t( "Nth-last-of-type(0n+3)", "#ap :nth-last-of-type(0n+3)", [ "google" ] );
+ assert.t( "Nth-last-of-type(2n)", "#ap :nth-last-of-type(2n)", [ "groups" ] );
+ assert.t( "Nth-last-of-type(even)", "#ap :nth-last-of-type(even)", [ "groups" ] );
+ assert.t( "Nth-last-of-type(2n+1)", "#ap :nth-last-of-type(2n+1)", [ "google", "code1", "anchor1", "mark" ] );
+ assert.t( "Nth-last-of-type(odd)", "#ap :nth-last-of-type(odd)", [ "google", "code1", "anchor1", "mark" ] );
+ assert.t( "Nth-last-of-type(-n+2)", "#qunit-fixture > :nth-last-of-type(-n+2)", [ "ap", "name+value", "first", "firstUL", "empty", "floatTest", "iframe", "table", "testForm", "disabled-tests", "siblingTest", "fx-test-group", "last" ] );
+} );
+
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "pseudo - has", function( assert ) {
+ assert.expect( 4 );
+
+ assert.t( "Basic test", "p:has(a)", [ "firstp", "ap", "en", "sap" ] );
+ assert.t( "Basic test (irrelevant whitespace)", "p:has( a )", [ "firstp", "ap", "en", "sap" ] );
+ assert.t( "Nested with overlapping candidates",
+ "#qunit-fixture div:has(div:has(div:not([id])))",
+ [ "moretests", "t2037", "fx-test-group", "fx-queue" ] );
+
+ // Support: Safari 15.4+, Chrome 105+
+ // `qSA` in Safari/Chrome throws for `:has()` with only unsupported arguments
+ // but if you add a supported arg to the list, it will run and just potentially
+ // return no results. Make sure this is accounted for. (gh-5098)
+ // Note: Chrome 105 has this behavior only in 105.0.5195.125 or newer;
+ // initially it shipped with a fully forgiving parsing in `:has()`.
+ assert.t( "Nested with list arguments",
+ "#qunit-fixture div:has(faketag, div:has(faketag, div:not([id])))",
+ [ "moretests", "t2037", "fx-test-group", "fx-queue" ] );
+} );
+
+QUnit[ QUnit.jQuerySelectors ? "test" : "skip" ]( "pseudo - contains", function( assert ) {
+ assert.expect( 9 );
+
+ var gh335 = document.getElementById( "qunit-fixture" ).appendChild(
+ document.createElement( "mark" ) );
+ gh335.id = "gh-335";
+ gh335.appendChild( document.createTextNode( "raw line 1\nline 2" ) );
+
+ assert.ok( jQuery( "a:contains('')" ).length, "empty string" );
+ assert.t( "unquoted argument", "a:contains(Google)", [ "google", "groups" ] );
+ assert.t( "unquoted argument with whitespace", "a:contains(Google Groups)", [ "groups" ] );
+ assert.t( "quoted argument with whitespace and parentheses",
+ "a:contains('Google Groups (Link)')", [ "groups" ] );
+ assert.t( "quoted argument with double quotes and parentheses",
+ "a:contains(\"(Link)\")", [ "groups" ] );
+ assert.t( "unquoted argument with whitespace and paired parentheses",
+ "a:contains(Google Groups (Link))", [ "groups" ] );
+ assert.t( "unquoted argument with paired parentheses", "a:contains((Link))", [ "groups" ] );
+ assert.t( "quoted argument with CSS escapes",
+ "span:contains(\"\\\"'\\53F0 \\5317 Ta\\301 ibe\\30C i\")",
+ [ "utf8class1" ] );
+
+ assert.t( "collapsed whitespace", "mark:contains('line 1\\A line')", [ "gh-335" ] );
+} );
+
+QUnit.test( "pseudo - misc", function( assert ) {
+ assert.expect( 32 );
+
+ var select, tmp, input;
+
+ jQuery( "
" ).prependTo( "#qunit-fixture" );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Headers", "#qunit-fixture :header", [ "h1", "h2", "h2-2" ] );
+ assert.t( "Headers(case-insensitive)", "#qunit-fixture :Header", [ "h1", "h2", "h2-2" ] );
+ } else {
+ assert.ok( "skip", ":header not supported in selector-native" );
+ assert.ok( "skip", ":header not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Multiple matches with the same context (cache check)",
+ "#form select:has(option:first-child:contains('o'))",
+ [ "select1", "select2", "select3", "select4" ]
+ );
+ assert.ok( jQuery( "#qunit-fixture :not(:has(:has(*)))" ).length, "All not grandparents" );
+
+ select = document.getElementById( "select1" );
+ assert.ok( jQuery( select ).is( ":has(option)" ), "Has Option Matches" );
+ } else {
+ assert.ok( "skip", ":has not supported in selector-native" );
+ assert.ok( "skip", ":has not supported in selector-native" );
+ assert.ok( "skip", ":has not supported in selector-native" );
+ }
+
+ tmp = document.createElement( "div" );
+ tmp.id = "tmp_input";
+ document.body.appendChild( tmp );
+
+ jQuery.each( [ "button", "submit", "reset" ], function( i, type ) {
+ var els = jQuery(
+ "
test "
+ .replace( /%/g, type )
+ ).appendTo( tmp );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Input Buttons :" + type, "#tmp_input :" + type, [ "input_" + type, "button_" + type ] );
+
+ assert.ok( jQuery( els[ 0 ] ).is( ":" + type ), "Input Matches :" + type );
+ assert.ok( jQuery( els[ 1 ] ).is( ":" + type ), "Button Matches :" + type );
+ } else {
+ assert.ok( "skip", ":" + type + " not supported in selector-native" );
+ assert.ok( "skip", ":" + type + " not supported in selector-native" );
+ assert.ok( "skip", ":" + type + " not supported in selector-native" );
+ }
+ } );
+
+ document.body.removeChild( tmp );
+
+ // Recreate tmp
+ tmp = document.createElement( "div" );
+ tmp.id = "tmp_input";
+ tmp.innerHTML = "
Hello I am focusable. ";
+
+ // Setting tabIndex should make the element focusable
+ // https://html.spec.whatwg.org/#the-tabindex-attribute
+ document.body.appendChild( tmp );
+ tmp.tabIndex = 0;
+ tmp.focus();
+ if ( document.activeElement !== tmp || ( document.hasFocus && !document.hasFocus() ) ||
+ ( document.querySelectorAll && !document.querySelectorAll( "div:focus" ).length ) ) {
+ assert.ok( true, "The div was not focused. Skip checking the :focus match." );
+ assert.ok( true, "The div was not focused. Skip checking the :focus match." );
+ } else {
+ assert.t( "tabIndex element focused", ":focus", [ "tmp_input" ] );
+ assert.ok( jQuery( tmp ).is( ":focus" ), ":focus matches tabIndex div" );
+ }
+
+ // Blur tmp
+ tmp.blur();
+ document.body.focus();
+ assert.ok( !jQuery( tmp ).is( ":focus" ), ":focus doesn't match tabIndex div" );
+ document.body.removeChild( tmp );
+
+ // Input focus/active
+ input = document.createElement( "input" );
+ input.type = "text";
+ input.id = "focus-input";
+
+ document.body.appendChild( input );
+ input.focus();
+
+ // Inputs can't be focused unless the document has focus
+ if ( document.activeElement !== input || ( document.hasFocus && !document.hasFocus() ) ||
+ ( document.querySelectorAll && !document.querySelectorAll( "input:focus" ).length ) ) {
+ assert.ok( true, "The input was not focused. Skip checking the :focus match." );
+ assert.ok( true, "The input was not focused. Skip checking the :focus match." );
+ } else {
+ assert.t( "Element focused", "input:focus", [ "focus-input" ] );
+ assert.ok( jQuery( input ).is( ":focus" ), ":focus matches" );
+ }
+
+ input.blur();
+
+ // When IE is out of focus, blur does not work. Force it here.
+ if ( document.activeElement === input ) {
+ document.body.focus();
+ }
+
+ assert.ok( !jQuery( input ).is( ":focus" ), ":focus doesn't match" );
+ document.body.removeChild( input );
+
+
+ assert.deepEqual(
+ jQuery( "[id='select1'] *:not(:last-child), [id='select2'] *:not(:last-child)", q( "qunit-fixture" )[ 0 ] ).get(),
+ q( "option1a", "option1b", "option1c", "option2a", "option2b", "option2c" ),
+ "caching system tolerates recursive selection"
+ );
+
+ if ( QUnit.jQuerySelectors ) {
+
+ // Tokenization edge cases
+ assert.t( "Sequential pseudos", "#qunit-fixture p:has(:contains(mark)):has(code)", [ "ap" ] );
+ assert.t( "Sequential pseudos", "#qunit-fixture p:has(:contains(mark)):has(code):contains(This link)", [ "ap" ] );
+
+ assert.t( "Pseudo argument containing ')'", "p:has(>a.GROUPS[src!=')'])", [ "ap" ] );
+ assert.t( "Pseudo argument containing ')'", "p:has(>a.GROUPS[src!=')'])", [ "ap" ] );
+ assert.t( "Pseudo followed by token containing ')'", "p:contains(id=\"foo\")[id!=\\)]", [ "sndp" ] );
+ assert.t( "Pseudo followed by token containing ')'", "p:contains(id=\"foo\")[id!=')']", [ "sndp" ] );
+
+ assert.t( "Multi-pseudo", "#ap:has(*), #ap:has(*)", [ "ap" ] );
+ assert.t( "Multi-pseudo with leading nonexistent id", "#nonexistent:has(*), #ap:has(*)", [ "ap" ] );
+
+ assert.t( "Tokenization stressor", "a[class*=blog]:not(:has(*, :contains(!)), :contains(!)), br:contains(]), p:contains(]):not(.qunit-source), :not(:empty):not(:parent):not(.qunit-source)", [ "ap", "mark", "yahoo", "simon" ] );
+ } else {
+ assert.ok( "skip", ":has not supported in selector-native" );
+ assert.ok( "skip", ":has not supported in selector-native" );
+
+ assert.ok( "skip", ":has not supported in selector-native" );
+ assert.ok( "skip", ":has not supported in selector-native" );
+ assert.ok( "skip", ":contains not supported in selector-native" );
+ assert.ok( "skip", ":contains not supported in selector-native" );
+
+ assert.ok( "skip", ":has not supported in selector-native" );
+ assert.ok( "skip", ":has supported in selector-native" );
+
+ assert.ok( "skip", ":has not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectorsPos ) {
+ assert.t( "Multi-positional", "#ap:gt(0), #ap:lt(1)", [ "ap" ] );
+ assert.t( "Multi-positional with leading nonexistent id", "#nonexistent:gt(0), #ap:lt(1)", [ "ap" ] );
+ } else {
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ }
+} );
+
+QUnit.test( "pseudo - :not", function( assert ) {
+ assert.expect( 43 );
+
+ assert.t( "Not", "a.blog:not(.link)", [ "mark" ] );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Not - multiple", "#form option:not(:contains(Nothing),#option1b,:selected)", [ "option1c", "option1d", "option2b", "option2c", "option3d", "option3e", "option4e", "option5b", "option5c" ] );
+ assert.t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c" ] );
+ } else {
+ assert.ok( "skip", ":contains not supported in selector-native" );
+ assert.ok( "skip", ":selected not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectorsPos ) {
+ assert.t( ":not() with :first", "#foo p:not(:first) .link", [ "simon" ] );
+ } else {
+ assert.ok( "skip", "Positional selectors are not supported" );
+ }
+
+ assert.t( ":not() failing interior", "#qunit-fixture p:not(.foo)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not() failing interior", "#qunit-fixture p:not(#blargh)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+
+ if ( QUnit.jQuerySelectors || !QUnit.isIE ) {
+ assert.t( ":not() failing interior", "#qunit-fixture p:not(div.foo)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not() failing interior", "#qunit-fixture p:not(p.foo)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not() failing interior", "#qunit-fixture p:not(div#blargh)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not() failing interior", "#qunit-fixture p:not(p#blargh)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ } else {
+
+ // Support: IE 11+
+ // IE doesn't support `:not(complex selector)`.
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ }
+
+ assert.t( ":not Multiple", "#qunit-fixture p:not(a)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not Multiple", "#qunit-fixture p:not( a )", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not Multiple", "#qunit-fixture p:not( p )", [] );
+ assert.t( ":not Multiple", "p:not(p)", [] );
+
+ if ( QUnit.jQuerySelectors || !QUnit.isIE ) {
+ assert.t( ":not Multiple", "#qunit-fixture p:not(a, b)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not Multiple", "#qunit-fixture p:not(a, b, div)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( ":not Multiple", "p:not(a,p)", [] );
+ assert.t( ":not Multiple", "p:not(p,a)", [] );
+ assert.t( ":not Multiple", "p:not(a,p,b)", [] );
+ } else {
+
+ // Support: IE 11+
+ // IE doesn't support `:not(complex selector)`.
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( ":not Multiple", ":input:not(:image,:input,:submit)", [] );
+ assert.t( ":not Multiple", "#qunit-fixture p:not(:has(a), :nth-child(1))", [ "first" ] );
+ } else {
+ assert.ok( "skip", ":image, :input, :submit not supported in selector-native" );
+ assert.ok( "skip", ":has not supported in selector-native" );
+ }
+
+ assert.t( "No element not selector", ".container div:not(.excluded) div", [] );
+
+ assert.t( ":not() Existing attribute", "#form select:not([multiple])", [ "select1", "select2", "select5" ] );
+ assert.t( ":not() Equals attribute", "#form select:not([name=select1])", [ "select2", "select3", "select4", "select5" ] );
+ assert.t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", [ "select2", "select3", "select4", "select5" ] );
+
+ assert.t( ":not() Multiple Class", "#foo a:not(.blog)", [ "yahoo", "anchor2" ] );
+ assert.t( ":not() Multiple Class", "#foo a:not(.link)", [ "yahoo", "anchor2" ] );
+
+ if ( QUnit.jQuerySelectors || !QUnit.isIE ) {
+ assert.t( ":not() Multiple Class", "#foo a:not(.blog.link)", [ "yahoo", "anchor2" ] );
+ } else {
+
+ // Support: IE 11+
+ // IE doesn't support `:not(complex selector)`.
+ assert.ok( "skip", ":not(complex selector) not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( ":not chaining (compound)", "#qunit-fixture div[id]:not(:has(div, span)):not(:has(*))", [ "nothiddendivchild", "divWithNoTabIndex", "fx-tests" ] );
+ assert.t( ":not chaining (with attribute)", "#qunit-fixture form[id]:not([action$='formaction']):not(:button)", [ "lengthtest", "name-tests", "testForm", "disabled-tests" ] );
+ assert.t( ":not chaining (colon in attribute)", "#qunit-fixture form[id]:not([action='form:action']):not(:button)", [ "form", "lengthtest", "name-tests", "testForm", "disabled-tests" ] );
+ assert.t( ":not chaining (colon in attribute and nested chaining)", "#qunit-fixture form[id]:not([action='form:action']:button):not(:input)", [ "form", "lengthtest", "name-tests", "testForm", "disabled-tests" ] );
+ assert.t( ":not chaining", "#form select:not(.select1):contains(Nothing) > option:not(option)", [] );
+ } else {
+ assert.ok( "skip", ":has not supported in selector-native" );
+ assert.ok( "skip", ":button not supported in selector-native" );
+ assert.ok( "skip", ":button not supported in selector-native" );
+ assert.ok( "skip", ":button not supported in selector-native" );
+ assert.ok( "skip", ":contains not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectorsPos ) {
+ assert.t( "positional :not()", "#foo p:not(:last)", [ "sndp", "en" ] );
+ assert.t( "positional :not() prefix", "#foo p:not(:last) a", [ "yahoo" ] );
+ assert.t( "compound positional :not()", "#foo p:not(:first, :last)", [ "en" ] );
+ assert.t( "compound positional :not()", "#foo p:not(:first, :even)", [ "en" ] );
+ assert.t( "compound positional :not()", "#foo p:not(:first, :odd)", [ "sap" ] );
+ assert.t( "reordered compound positional :not()", "#foo p:not(:odd, :first)", [ "sap" ] );
+
+ assert.t( "positional :not() with pre-filter", "#foo p:not([id]:first)", [ "en", "sap" ] );
+ assert.t( "positional :not() with post-filter", "#foo p:not(:first[id])", [ "en", "sap" ] );
+ assert.t( "positional :not() with pre-filter", "#foo p:not([lang]:first)", [ "sndp", "sap" ] );
+ assert.t( "positional :not() with post-filter", "#foo p:not(:first[lang])", [ "sndp", "en", "sap" ] );
+ } else {
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ assert.ok( "skip", "Positional selectors are not supported" );
+ }
+} );
+
+QUnit[ QUnit.jQuerySelectorsPos ? "test" : "skip" ]( "pseudo - position", function( assert ) {
+ assert.expect( 34 );
+
+ assert.t( "First element", "#qunit-fixture p:first", [ "firstp" ] );
+ assert.t( "First element(case-insensitive)", "#qunit-fixture p:fiRst", [ "firstp" ] );
+ assert.t( "nth Element", "#qunit-fixture p:nth(1)", [ "ap" ] );
+ assert.t( "First Element", "#qunit-fixture p:first", [ "firstp" ] );
+ assert.t( "Last Element", "p:last", [ "first" ] );
+ assert.t( "Even Elements", "#qunit-fixture p:even", [ "firstp", "sndp", "sap" ] );
+ assert.t( "Odd Elements", "#qunit-fixture p:odd", [ "ap", "en", "first" ] );
+ assert.t( "Position Equals", "#qunit-fixture p:eq(1)", [ "ap" ] );
+ assert.t( "Position Equals (negative)", "#qunit-fixture p:eq(-1)", [ "first" ] );
+ assert.t( "Position Greater Than", "#qunit-fixture p:gt(0)", [ "ap", "sndp", "en", "sap", "first" ] );
+ assert.t( "Position Less Than", "#qunit-fixture p:lt(3)", [ "firstp", "ap", "sndp" ] );
+ assert.t( "Position Less Than Big Number", "#qunit-fixture p:lt(9007199254740991)", [ "firstp", "ap", "sndp", "en", "sap", "first" ] );
+
+ assert.t( "Check position filtering", "div#nothiddendiv:eq(0)", [ "nothiddendiv" ] );
+ assert.t( "Check position filtering", "div#nothiddendiv:last", [ "nothiddendiv" ] );
+ assert.t( "Check position filtering", "div#nothiddendiv:not(:gt(0))", [ "nothiddendiv" ] );
+ assert.t( "Check position filtering", "#foo > :not(:first)", [ "en", "sap" ] );
+ assert.t( "Check position filtering", "#qunit-fixture select > :not(:gt(2))", [ "option1a", "option1b", "option1c" ] );
+ assert.t( "Check position filtering", "#qunit-fixture select:lt(2) :not(:first)", [ "option1b", "option1c", "option1d", "option2a", "option2b", "option2c", "option2d" ] );
+ assert.t( "Check position filtering", "div.nothiddendiv:eq(0)", [ "nothiddendiv" ] );
+ assert.t( "Check position filtering", "div.nothiddendiv:last", [ "nothiddendiv" ] );
+ assert.t( "Check position filtering", "div.nothiddendiv:not(:lt(0))", [ "nothiddendiv" ] );
+
+ assert.t( "Check element position", "#qunit-fixture div div:eq(0)", [ "nothiddendivchild" ] );
+ assert.t( "Check element position", "#select1 option:eq(3)", [ "option1d" ] );
+ assert.t( "Check element position", "#qunit-fixture div div:eq(10)", [ "no-clone-exception" ] );
+ assert.t( "Check element position", "#qunit-fixture div div:first", [ "nothiddendivchild" ] );
+ assert.t( "Check element position", "#qunit-fixture div > div:first", [ "nothiddendivchild" ] );
+ assert.t( "Check element position", "#qunit-fixture div:first a:first", [ "yahoo" ] );
+ assert.t( "Check element position", "#qunit-fixture div:first > p:first", [ "sndp" ] );
+ assert.t( "Check element position", "div#nothiddendiv:first > div:first", [ "nothiddendivchild" ] );
+ assert.t( "Chained pseudo after a pos pseudo", "#listWithTabIndex li:eq(0):contains(Rice)", [ "foodWithNegativeTabIndex" ] );
+
+ assert.t( "Check sort order with POS and comma", "#qunit-fixture em>em>em>em:first-child,div>em:first", [ "siblingfirst", "siblinggreatgrandchild" ] );
+
+ assert.t( "Isolated position", "#qunit-fixture :last", [ "last" ] );
+
+ assert.deepEqual(
+ jQuery( "#qunit-fixture > p" ).filter( "*:lt(2) + *" ).get(),
+ q( "ap" ),
+ "Seeded pos with trailing relative" );
+
+ // jQuery trac-12526
+ var context = jQuery( "#qunit-fixture" ).append( "
" )[ 0 ];
+ assert.deepEqual( jQuery( ":last", context ).get(), q( "jquery12526" ),
+ "Post-manipulation positional" );
+} );
+
+QUnit.test( "pseudo - form", function( assert ) {
+ assert.expect( 16 );
+
+ var extraTexts = jQuery( "
" ).appendTo( "#form" );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Form element :radio", "#form :radio", [ "radio1", "radio2" ] );
+ assert.t( "Form element :checkbox", "#form :checkbox", [ "check1", "check2" ] );
+ assert.t( "Form element :text", "#form :text", [ "text1", "text2", "hidden2", "name", "impliedText", "capitalText" ] );
+ assert.t( "Form element :radio:checked", "#form :radio:checked", [ "radio2" ] );
+ assert.t( "Form element :checkbox:checked", "#form :checkbox:checked", [ "check1" ] );
+ assert.t( "Form element :radio:checked, :checkbox:checked", "#form :radio:checked, #form :checkbox:checked", [ "radio2", "check1" ] );
+ } else {
+ assert.ok( "skip", ":radio not supported in selector-native" );
+ assert.ok( "skip", ":checkbox not supported in selector-native" );
+ assert.ok( "skip", ":text not supported in selector-native" );
+ assert.ok( "skip", ":radio not supported in selector-native" );
+ assert.ok( "skip", ":checkbox not supported in selector-native" );
+ assert.ok( "skip", ":radio not supported in selector-native" );
+ }
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Selected option element",
+ "#form option:selected",
+ [ "option1a", "option2d", "option3b", "option3c", "option4b", "option4c", "option4d",
+ "option5a" ] );
+ assert.t( "Select options via :selected", "#select1 option:selected", [ "option1a" ] );
+ assert.t( "Select options via :selected", "#select2 option:selected", [ "option2d" ] );
+ assert.t( "Select options via :selected", "#select3 option:selected", [ "option3b", "option3c" ] );
+ assert.t( "Select options via :selected", "select[name='select2'] option:selected", [ "option2d" ] );
+ } else {
+ assert.ok( "skip", ":selected not supported in selector-native" );
+ assert.ok( "skip", ":selected not supported in selector-native" );
+ assert.ok( "skip", ":selected not supported in selector-native" );
+ assert.ok( "skip", ":selected not supported in selector-native" );
+ assert.ok( "skip", ":selected not supported in selector-native" );
+ }
- if ( jQuery.find.compile ) {
+ if ( QUnit.jQuerySelectors ) {
+ assert.t( "Form element :input", "#form :input", [ "text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "search", "button", "area1", "select1", "select2", "select3", "select4", "select5", "impliedText", "capitalText" ] );
- // #12600
+ // trac-12600
assert.ok(
jQuery( "
" )
- .prop( "value", "option" )
- .is( ":input[value='12600']" ),
+ .prop( "value", "option" )
+ .is( ":input[value='12600']" ),
":input[value=foo] selects select by attribute"
);
@@ -260,26 +1375,386 @@ QUnit.test( "attributes", function( assert ) {
} else {
assert.ok( "skip", ":input not supported in selector-native" );
assert.ok( "skip", ":input not supported in selector-native" );
+ assert.ok( "skip", ":input not supported in selector-native" );
}
+ assert.t( "Selected option elements are also :checked", "#form option:checked",
+ [ "option1a", "option2d", "option3b", "option3c", "option4b", "option4c", "option4d",
+ "option5a" ] );
+ assert.t( "Hidden inputs are still :enabled",
+ "#hidden1:enabled",
+ [ "hidden1" ] );
- // #11115
- assert.ok( jQuery( "
" ).prop( "checked", false ).is( "[checked]" ),
- "[checked] selects by attribute (positive)"
+ extraTexts.remove();
+} );
+
+QUnit.test( "pseudo - :(dis|en)abled, explicitly disabled", function( assert ) {
+ assert.expect( 2 );
+
+ // Set a meaningless disabled property on a common ancestor
+ var container = document.getElementById( "disabled-tests" );
+ container.disabled = true;
+
+ // Support: IE 6 - 11
+ // Unset the property where it is not meaningless
+ if ( document.getElementById( "enabled-input" ).isDisabled ) {
+ container.disabled = undefined;
+ }
+
+ assert.t(
+ "Explicitly disabled elements",
+ "#enabled-fieldset :disabled",
+ [ "disabled-input", "disabled-textarea", "disabled-button",
+ "disabled-select", "disabled-optgroup", "disabled-option" ]
);
- assert.ok( !jQuery( "
" ).prop( "checked", true ).is( "[checked]" ),
- "[checked] selects by attribute (negative)"
+
+ assert.t(
+ "Enabled elements",
+ "#enabled-fieldset :enabled",
+ [ "enabled-input", "enabled-textarea", "enabled-button",
+ "enabled-select", "enabled-optgroup", "enabled-option" ]
+ );
+} );
+
+QUnit.test( "pseudo - :(dis|en)abled, optgroup and option", function( assert ) {
+ assert.expect( 2 );
+
+ assert.t(
+ ":disabled",
+ "#disabled-select-inherit :disabled, #enabled-select-inherit :disabled",
+ [ "disabled-optgroup-inherit", "disabled-optgroup-option", "en_disabled-optgroup-inherit",
+ "en_disabled-optgroup-option" ]
+ );
+
+ assert.t(
+ ":enabled",
+ "#disabled-select-inherit :enabled, #enabled-select-inherit :enabled",
+ [ "enabled-optgroup-inherit", "enabled-optgroup-option", "enabled-select-option" ]
+ );
+} );
+
+QUnit.test( "pseudo - fieldset:(dis|en)abled", function( assert ) {
+ assert.expect( 2 );
+
+ assert.t( "Disabled fieldset", "fieldset:disabled", [ "disabled-fieldset" ] );
+ assert.t( "Enabled fieldset", "fieldset:enabled", [ "enabled-fieldset" ] );
+} );
+
+QUnit.test( "pseudo - :disabled by ancestry", function( assert ) {
+ assert.expect( 1 );
+
+ assert.t(
+ "Inputs inherit disabled from fieldset",
+ "#disabled-fieldset :disabled",
+ [ "disabled-fieldset-input", "disabled-fieldset-textarea",
+ "disabled-fieldset-button" ]
+ );
+} );
+
+QUnit.test( "pseudo - a:(dis|en)abled", function( assert ) {
+ assert.expect( 2 );
+
+ var enabled, disabled,
+ container = jQuery( "
" );
+
+ container.appendTo( "#qunit-fixture" );
+
+ enabled = container.find( "a:enabled" );
+ disabled = container.find( "a:disabled" );
+
+ assert.strictEqual( enabled.length, 0, ":enabled doesn't match anchor elements" );
+ assert.strictEqual( disabled.length, 0, ":disabled doesn't match anchor elements" );
+} );
+
+QUnit.test( "pseudo - :target and :root", function( assert ) {
+ assert.expect( 2 );
+
+ // Target
+ var oldHash,
+ $link = jQuery( "
" ).attr( {
+ href: "#",
+ id: "new-link"
+ } ).appendTo( "#qunit-fixture" );
+
+ oldHash = window.location.hash;
+ window.location.hash = "new-link";
+
+ assert.t( ":target", ":target", [ "new-link" ] );
+
+ $link.remove();
+ window.location.hash = oldHash;
+
+ // Root
+ assert.equal( jQuery( ":root" )[ 0 ], document.documentElement, ":root selector" );
+} );
+
+QUnit.test( "pseudo - :lang", function( assert ) {
+ assert.expect( QUnit.jQuerySelectors ? 104 : 54 );
+
+ var docElem = document.documentElement,
+ docXmlLang = docElem.getAttribute( "xml:lang" ),
+ docLang = docElem.lang,
+ foo = document.getElementById( "foo" ),
+ anchor = document.getElementById( "anchor2" ),
+ xml = createWithFriesXML(),
+ testLang = function( text, elem, container, lang, extra ) {
+ var message,
+ full = lang + "-" + extra;
+
+ message = "lang=" + lang + " " + text;
+ container.setAttribute( container.ownerDocument.documentElement.nodeName === "HTML" ? "lang" : "xml:lang", lang );
+ assertMatch( message, elem, ":lang(" + lang + ")" );
+ assertMatch( message, elem, ":lang(" + mixCase( lang ) + ")" );
+ assertNoMatch( message, elem, ":lang(" + full + ")" );
+ assertNoMatch( message, elem, ":lang(" + mixCase( full ) + ")" );
+ assertNoMatch( message, elem, ":lang(" + lang + "-)" );
+ assertNoMatch( message, elem, ":lang(" + full + "-)" );
+ assertNoMatch( message, elem, ":lang(" + lang + "glish)" );
+ assertNoMatch( message, elem, ":lang(" + full + "glish)" );
+
+ message = "lang=" + full + " " + text;
+ container.setAttribute( container.ownerDocument.documentElement.nodeName === "HTML" ? "lang" : "xml:lang", full );
+ assertMatch( message, elem, ":lang(" + lang + ")" );
+ assertMatch( message, elem, ":lang(" + mixCase( lang ) + ")" );
+ assertMatch( message, elem, ":lang(" + full + ")" );
+ assertMatch( message, elem, ":lang(" + mixCase( full ) + ")" );
+ assertNoMatch( message, elem, ":lang(" + lang + "-)" );
+ assertNoMatch( message, elem, ":lang(" + full + "-)" );
+ assertNoMatch( message, elem, ":lang(" + lang + "glish)" );
+ assertNoMatch( message, elem, ":lang(" + full + "glish)" );
+ },
+ mixCase = function( str ) {
+ var ret = str.split( "" ),
+ i = ret.length;
+ while ( i-- ) {
+ if ( i & 1 ) {
+ ret[ i ] = ret[ i ].toUpperCase();
+ }
+ }
+ return ret.join( "" );
+ },
+ assertMatch = function( text, elem, selector ) {
+ assert.ok( jQuery( elem ).is( selector ), text + " match " + selector );
+ },
+ assertNoMatch = function( text, elem, selector ) {
+ assert.ok( !jQuery( elem ).is( selector ), text + " fail " + selector );
+ };
+
+ // Prefixing and inheritance
+ assert.ok( jQuery( docElem ).is( ":lang(" + docElem.lang + ")" ), "starting :lang" );
+ testLang( "document", anchor, docElem, "en", "us" );
+ testLang( "grandparent", anchor, anchor.parentNode.parentNode, "yue", "hk" );
+ assert.ok( !jQuery( anchor ).is( ":lang(en), :lang(en-us)" ),
+ ":lang does not look above an ancestor with specified lang" );
+ testLang( "self", anchor, anchor, "es", "419" );
+ assert.ok(
+ !jQuery( anchor ).is( ":lang(en), :lang(en-us), :lang(yue), :lang(yue-hk)" ),
+ ":lang does not look above self with specified lang"
+ );
+
+ // Searching by language tag
+ anchor.parentNode.parentNode.lang = "arab";
+ anchor.parentNode.lang = anchor.parentNode.id = "ara-sa";
+ anchor.lang = "ara";
+ assert.deepEqual( jQuery( ":lang(ara)", foo ).get(), [ anchor.parentNode, anchor ], "Find by :lang" );
+
+ // Selector validity
+ anchor.parentNode.lang = "ara";
+ anchor.lang = "ara\\b";
+ assert.deepEqual( jQuery( ":lang(ara\\b)", foo ).get(), [], ":lang respects backslashes" );
+
+ // Support: Firefox 114+
+ // Firefox 114+ no longer match on backslashes in `:lang()`, even when escaped.
+ // It is an intentional change as `:lang()` parameters are supposed to be valid
+ // BCP 47 strings. Therefore, we won't attempt to patch it.
+ // We'll keep this test here until other browsers match the behavior.
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=1839747#c1
+ // See https://github.com/w3c/csswg-drafts/issues/8720#issuecomment-1509242961
+ //
+ // assert.deepEqual( jQuery( ":lang(ara\\\\b)", foo ).get(), [ anchor ],
+ // ":lang respects escaped backslashes" );
+
+ assert.throws( function() {
+ jQuery( "#qunit-fixture:lang(c++)" );
+ }, ":lang value must be a valid identifier" );
+
+ if ( QUnit.jQuerySelectors ) {
+
+ // XML
+ foo = jQuery( "response", xml )[ 0 ];
+ anchor = jQuery( "#seite1", xml )[ 0 ];
+ testLang( "XML document", anchor, xml.documentElement, "en", "us" );
+ testLang( "XML grandparent", anchor, foo, "yue", "hk" );
+ assert.ok( !jQuery( anchor ).is( ":lang(en), :lang(en-us)" ),
+ "XML :lang does not look above an ancestor with specified lang" );
+ testLang( "XML self", anchor, anchor, "es", "419" );
+ assert.ok(
+ !jQuery( anchor ).is( ":lang(en), :lang(en-us), :lang(yue), :lang(yue-hk)" ),
+ "XML :lang does not look above self with specified lang" );
+ }
+
+ // Cleanup
+ if ( docXmlLang == null ) {
+ docElem.removeAttribute( "xml:lang" );
+ } else {
+ docElem.setAttribute( "xml:lang", docXmlLang );
+ }
+ docElem.lang = docLang;
+} );
+
+QUnit.test( "context", function( assert ) {
+ assert.expect( 21 );
+
+ var context,
+ selector = ".blog",
+ expected = q( "mark", "simon" ),
+ iframe = document.getElementById( "iframe" ),
+ iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
+
+ assert.deepEqual( jQuery( selector, document ).get(), expected, "explicit document context" );
+ assert.deepEqual( jQuery( selector ).get(), expected, "unspecified context becomes document" );
+ assert.deepEqual( jQuery( selector, undefined ).get(), expected,
+ "undefined context becomes document" );
+ assert.deepEqual( jQuery( selector, null ).get(), expected, "null context becomes document" );
+
+ iframeDoc.open();
+ iframeDoc.write( "
bar
" );
+ iframeDoc.close();
+ expected = [ iframeDoc.getElementById( "foo" ) ];
+ assert.deepEqual( jQuery( "p", iframeDoc ).get(), expected, "Other document context (simple)" );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.deepEqual( jQuery( "p:contains(ar)", iframeDoc ).get(), expected,
+ "Other document context (complex)" );
+ } else {
+ assert.ok( "skip", ":contains not supported in selector-native" );
+ }
+
+ assert.deepEqual( jQuery( "span", iframeDoc ).get(), [],
+ "Other document context (simple, no results)" );
+ assert.deepEqual( jQuery( "* span", iframeDoc ).get(), [],
+ "Other document context (complex, no results)" );
+
+ context = document.getElementById( "nothiddendiv" );
+ assert.deepEqual( jQuery( "*", context ).get(), q( "nothiddendivchild" ), "
context" );
+
+ assert.deepEqual( jQuery( "* > *", context ).get(), [], "
context (no results)" );
+
+ context.removeAttribute( "id" );
+ assert.deepEqual( jQuery( "*", context ).get(), q( "nothiddendivchild" ), "no-id element context" );
+
+ if ( QUnit.jQuerySelectors ) {
+ assert.deepEqual( jQuery( "* > *", context ).get(), [], "no-id element context (no results)" );
+ } else {
+ assert.ok( "skip", ":contains not supported in selector-native" );
+ }
+
+ assert.strictEqual( context.getAttribute( "id" ) || "", "", "id not added by no-id selection" );
+
+ context = document.getElementById( "lengthtest" );
+ assert.deepEqual( jQuery( "input", context ).get(), q( "length", "idTest" ), "