Tests: Partially use new qunit interface

http://qunitjs.com/upgrade-guide-2.x/

For most of the boring work was used
https://github.com/apsdehal/qunit-migrate package

However, it can't update local qunit helpers, plus in some places
old QUnit.asyncTest signature is still used

Ref b930d14ce6
Fixes gh-2540
This commit is contained in:
Oleg Gaidarenko
2015-09-03 04:46:31 +03:00
parent c530661629
commit 4543815eed
24 changed files with 6640 additions and 6116 deletions

View File

@@ -24,7 +24,7 @@ var supportsScroll, supportsFixedPosition,
checkFixed.remove();
};
module( "offset", { setup: function() {
QUnit.module( "offset", { setup: function() {
if ( typeof checkSupport === "function" ) {
checkSupport();
}
@@ -43,26 +43,26 @@ module( "offset", { setup: function() {
the iframe window and the "jQuery" symbol is used to access any static methods.
*/
test( "empty set", function() {
expect( 2 );
strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
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)" );
} );
test( "disconnected element", function() {
expect( 2 );
QUnit.test( "disconnected element", function( assert ) {
assert.expect( 2 );
var result = jQuery( document.createElement( "div" ) ).offset();
// These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
assert.equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
assert.equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
} );
test( "hidden (display: none) element", function() {
expect( 2 );
QUnit.test( "hidden (display: none) element", function( assert ) {
assert.expect( 2 );
var node = jQuery( "<div style='display: none' />" ).appendTo( "#qunit-fixture" ),
result = node.offset();
@@ -72,12 +72,12 @@ test( "hidden (display: none) element", function() {
// These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
assert.equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
assert.equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
} );
testIframe( "offset/absolute", "absolute", function( $, iframe ) {
expect( 4 );
testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert ) {
assert.expect( 4 );
var doc = iframe.document,
tests;
@@ -87,8 +87,8 @@ testIframe( "offset/absolute", "absolute", function( $, iframe ) {
{ "id": "#absolute-1", "top": 1, "left": 1 }
];
jQuery.each( tests, function() {
equal( jQuery( this[ "id" ], doc ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
equal( jQuery( this[ "id" ], doc ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
assert.equal( jQuery( this[ "id" ], doc ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
assert.equal( jQuery( this[ "id" ], doc ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
@@ -96,13 +96,13 @@ testIframe( "offset/absolute", "absolute", function( $, iframe ) {
{ "id": "#absolute-1", "top": 0, "left": 0 }
];
jQuery.each( tests, function() {
equal( jQuery( this[ "id" ], doc ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
equal( jQuery( this[ "id" ], doc ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
assert.equal( jQuery( this[ "id" ], doc ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
assert.equal( jQuery( this[ "id" ], doc ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
} );
} );
testIframe( "offset/absolute", "absolute", function( $ ) {
expect( 178 );
testIframe( "offset/absolute", "absolute", function( $, window, document, assert ) {
assert.expect( 178 );
var tests, offset;
@@ -114,8 +114,8 @@ testIframe( "offset/absolute", "absolute", function( $ ) {
{ "id": "#absolute-2", "top": 20, "left": 20 }
];
jQuery.each( tests, function() {
equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
@@ -126,14 +126,14 @@ testIframe( "offset/absolute", "absolute", function( $ ) {
{ "id": "#absolute-2", "top": 19, "left": 19 }
];
jQuery.each( tests, function() {
equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
} );
// test #5781
offset = $( "#positionTest" ).offset( { "top": 10, "left": 10 } ).offset();
equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
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." );
// set offset
tests = [
@@ -156,24 +156,24 @@ testIframe( "offset/absolute", "absolute", function( $ ) {
];
jQuery.each( tests, function() {
$( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ 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" ] + " })" );
var top = this[ "top" ], left = this[ "left" ];
$( this[ "id" ] ).offset( function( i, val ) {
equal( val.top, top, "Verify incoming top position." );
equal( val.left, left, "Verify incoming top position." );
assert.equal( val.top, top, "Verify incoming top position." );
assert.equal( val.left, left, "Verify incoming top position." );
return { "top": top + 1, "left": left + 1 };
} );
equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + " })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + " })" );
assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + " })" );
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + " })" );
$( this[ "id" ] )
.offset( { "left": this[ "left" ] + 2 } )
.offset( { "top": this[ "top" ] + 2 } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 2, "Setting one property at a time." );
equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 2, "Setting one property at a time." );
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( {
@@ -181,13 +181,13 @@ testIframe( "offset/absolute", "absolute", function( $ ) {
"left": props.left + 1
} );
} } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
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 })" );
} );
} );
testIframe( "offset/relative", "relative", function( $ ) {
expect( 60 );
testIframe( "offset/relative", "relative", function( $, window, document, assert ) {
assert.expect( 60 );
var tests;
@@ -198,8 +198,8 @@ testIframe( "offset/relative", "relative", function( $ ) {
{ "id": "#relative-2", "top": 142, "left": 27 }
];
jQuery.each( tests, function() {
equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
@@ -209,8 +209,8 @@ testIframe( "offset/relative", "relative", function( $ ) {
{ "id": "#relative-2", "top": 141, "left": 26 }
];
jQuery.each( tests, function() {
equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').position().top" );
assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').position().left" );
} );
// set offset
@@ -230,8 +230,8 @@ testIframe( "offset/relative", "relative", function( $ ) {
];
jQuery.each( tests, function() {
$( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ 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( {
@@ -239,13 +239,13 @@ testIframe( "offset/relative", "relative", function( $ ) {
"left": props.left + 1
} );
} } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
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 })" );
} );
} );
testIframe( "offset/static", "static", function( $ ) {
expect( 80 );
testIframe( "offset/static", "static", function( $, window, document, assert ) {
assert.expect( 80 );
var tests;
@@ -257,8 +257,8 @@ testIframe( "offset/static", "static", function( $ ) {
{ "id": "#static-2", "top": 122, left: 7 }
];
jQuery.each( tests, function() {
equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
assert.equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset().top" );
assert.equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset().left" );
} );
// get position
@@ -269,8 +269,8 @@ testIframe( "offset/static", "static", function( $ ) {
{ "id": "#static-2", "top": 121, "left": 6 }
];
jQuery.each( tests, function() {
equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "top" ] + "').position().top" );
equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "left" ] + "').position().left" );
assert.equal( $( this[ "id" ] ).position().top, this[ "top" ], "jQuery('" + this[ "top" ] + "').position().top" );
assert.equal( $( this[ "id" ] ).position().left, this[ "left" ], "jQuery('" + this[ "left" ] + "').position().left" );
} );
// set offset
@@ -294,8 +294,8 @@ testIframe( "offset/static", "static", function( $ ) {
];
jQuery.each( tests, function() {
$( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ 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( {
@@ -303,13 +303,13 @@ testIframe( "offset/static", "static", function( $ ) {
"left": props.left + 1
} );
} } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
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 })" );
} );
} );
testIframe( "offset/fixed", "fixed", function( $ ) {
expect( 34 );
testIframe( "offset/fixed", "fixed", function( $, window, document, assert ) {
assert.expect( 34 );
var tests, $noTopLeft;
@@ -332,23 +332,23 @@ testIframe( "offset/fixed", "fixed", function( $ ) {
jQuery.each( tests, function() {
if ( !window.supportsScroll ) {
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
} else if ( window.supportsFixedPosition ) {
equal( $( this[ "id" ] ).offset().top, this[ "offsetTop" ], "jQuery('" + this[ "id" ] + "').offset().top" );
equal( $( this[ "id" ] ).position().top, this[ "positionTop" ], "jQuery('" + this[ "id" ] + "').position().top" );
equal( $( this[ "id" ] ).offset().left, this[ "offsetLeft" ], "jQuery('" + this[ "id" ] + "').offset().left" );
equal( $( this[ "id" ] ).position().left, this[ "positionLeft" ], "jQuery('" + this[ "id" ] + "').position().left" );
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
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
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" );
}
} );
@@ -364,8 +364,8 @@ testIframe( "offset/fixed", "fixed", function( $ ) {
jQuery.each( tests, function() {
if ( window.supportsFixedPosition ) {
$( this[ "id" ] ).offset( { "top": this[ "top" ], "left": this[ "left" ] } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ], "jQuery('" + this[ "id" ] + "').offset({ top: " + this[ "top" ] + " })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ], "jQuery('" + this[ "id" ] + "').offset({ 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( {
@@ -373,178 +373,178 @@ testIframe( "offset/fixed", "fixed", function( $ ) {
"left": props.left + 1
} );
} } );
equal( $( this[ "id" ] ).offset().top, this[ "top" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ top: " + ( this[ "top" ] + 1 ) + ", using: fn })" );
equal( $( this[ "id" ] ).offset().left, this[ "left" ] + 1, "jQuery('" + this[ "id" ] + "').offset({ left: " + ( this[ "left" ] + 1 ) + ", using: fn })" );
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 {
// need to have same number of assertions
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
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" );
}
} );
// Bug 8316
$noTopLeft = $( "#fixed-no-top-left" );
if ( window.supportsFixedPosition ) {
equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
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
ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
assert.ok( true, "Fixed position is not supported" );
}
} );
testIframe( "offset/table", "table", function( $ ) {
expect( 4 );
testIframe( "offset/table", "table", function( $, window, document, assert ) {
assert.expect( 4 );
equal( $( "#table-1" ).offset().top, 6, "jQuery('#table-1').offset().top" );
equal( $( "#table-1" ).offset().left, 6, "jQuery('#table-1').offset().left" );
assert.equal( $( "#table-1" ).offset().top, 6, "jQuery('#table-1').offset().top" );
assert.equal( $( "#table-1" ).offset().left, 6, "jQuery('#table-1').offset().left" );
equal( $( "#th-1" ).offset().top, 10, "jQuery('#th-1').offset().top" );
equal( $( "#th-1" ).offset().left, 10, "jQuery('#th-1').offset().left" );
assert.equal( $( "#th-1" ).offset().top, 10, "jQuery('#th-1').offset().top" );
assert.equal( $( "#th-1" ).offset().left, 10, "jQuery('#th-1').offset().left" );
} );
testIframe( "offset/scroll", "scroll", function( $, win ) {
expect( 30 );
testIframe( "offset/scroll", "scroll", function( $, win, doc, assert ) {
assert.expect( 30 );
// If we're going to bastardize the tests, let's just DO it
var ie = /msie 8/i.test( navigator.userAgent );
if ( ie ) {
ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
assert.ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
} else {
equal( $( "#scroll-1" ).offset().top, 7, "jQuery('#scroll-1').offset().top" );
assert.equal( $( "#scroll-1" ).offset().top, 7, "jQuery('#scroll-1').offset().top" );
}
equal( $( "#scroll-1" ).offset().left, 7, "jQuery('#scroll-1').offset().left" );
assert.equal( $( "#scroll-1" ).offset().left, 7, "jQuery('#scroll-1').offset().left" );
if ( ie ) {
ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
assert.ok( true, "TestSwarm's iframe has hosed this test in oldIE, we surrender" );
} else {
equal( $( "#scroll-1-1" ).offset().top, 11, "jQuery('#scroll-1-1').offset().top" );
assert.equal( $( "#scroll-1-1" ).offset().top, 11, "jQuery('#scroll-1-1').offset().top" );
}
equal( $( "#scroll-1-1" ).offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
assert.equal( $( "#scroll-1-1" ).offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
// These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat
equal( $( "#hidden" ).offset().top, 0, "Hidden elements do not subtract scroll" );
equal( $( "#hidden" ).offset().left, 0, "Hidden elements do not subtract scroll" );
assert.equal( $( "#hidden" ).offset().top, 0, "Hidden elements do not subtract scroll" );
assert.equal( $( "#hidden" ).offset().left, 0, "Hidden elements do not subtract scroll" );
// scroll offset tests .scrollTop/Left
equal( $( "#scroll-1" ).scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
equal( $( "#scroll-1" ).scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
assert.equal( $( "#scroll-1" ).scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
assert.equal( $( "#scroll-1" ).scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
equal( $( "#scroll-1-1" ).scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
equal( $( "#scroll-1-1" ).scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
assert.equal( $( "#scroll-1-1" ).scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
assert.equal( $( "#scroll-1-1" ).scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
// scroll method chaining
equal( $( "#scroll-1" ).scrollTop( undefined ).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" );
equal( $( "#scroll-1" ).scrollLeft( undefined ).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" );
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)" );
win.name = "test";
if ( !window.supportsScroll ) {
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
assert.ok( true, "Browser doesn't support scroll position." );
} else {
equal( $( win ).scrollTop(), 1000, "jQuery(window).scrollTop()" );
equal( $( win ).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
assert.equal( $( win ).scrollTop(), 1000, "jQuery(window).scrollTop()" );
assert.equal( $( win ).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
equal( $( win.document ).scrollTop(), 1000, "jQuery(document).scrollTop()" );
equal( $( win.document ).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
assert.equal( $( win.document ).scrollTop(), 1000, "jQuery(document).scrollTop()" );
assert.equal( $( win.document ).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
}
// test jQuery using parent window/document
// jQuery reference here is in the iframe
window.scrollTo( 0, 0 );
equal( $( window ).scrollTop(), 0, "jQuery(window).scrollTop() other window" );
equal( $( window ).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
equal( $( document ).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
equal( $( document ).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
assert.equal( $( window ).scrollTop(), 0, "jQuery(window).scrollTop() other window" );
assert.equal( $( window ).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
assert.equal( $( document ).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
assert.equal( $( document ).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
// Tests scrollTop/Left with empty jquery objects
notEqual( $().scrollTop( 100 ), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
notEqual( $().scrollLeft( 100 ), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
notEqual( $().scrollTop( null ), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
notEqual( $().scrollLeft( null ), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
assert.notEqual( $().scrollTop( 100 ), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
assert.notEqual( $().scrollLeft( 100 ), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
assert.notEqual( $().scrollTop( null ), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
assert.notEqual( $().scrollLeft( null ), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
assert.strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
assert.strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
// Tests position after parent scrolling (#15239)
$( "#scroll-1" ).scrollTop( 0 );
$( "#scroll-1" ).scrollLeft( 0 );
equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
$( "#scroll-1" ).scrollTop( 5 );
$( "#scroll-1" ).scrollLeft( 5 );
equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
assert.equal( $( "#scroll-1-1" ).position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
assert.equal( $( "#scroll-1-1" ).position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
} );
testIframe( "offset/body", "body", function( $ ) {
expect( 4 );
testIframe( "offset/body", "body", function( $, window, document, assert ) {
assert.expect( 4 );
equal( $( "body" ).offset().top, 1, "jQuery('#body').offset().top" );
equal( $( "body" ).offset().left, 1, "jQuery('#body').offset().left" );
equal( $( "#firstElement" ).position().left, 5, "$('#firstElement').position().left" );
equal( $( "#firstElement" ).position().top, 5, "$('#firstElement').position().top" );
assert.equal( $( "body" ).offset().top, 1, "jQuery('#body').offset().top" );
assert.equal( $( "body" ).offset().left, 1, "jQuery('#body').offset().left" );
assert.equal( $( "#firstElement" ).position().left, 5, "$('#firstElement').position().left" );
assert.equal( $( "#firstElement" ).position().top, 5, "$('#firstElement').position().top" );
} );
test( "chaining", function() {
expect( 3 );
QUnit.test( "chaining", function( assert ) {
assert.expect( 3 );
var coords = { "top": 1, "left": 1 };
equal( jQuery( "#absolute-1" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
equal( jQuery( "#non-existent" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );
equal( jQuery( "#absolute-1" ).offset( undefined ).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" );
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)" );
} );
test( "offsetParent", function() {
expect( 13 );
QUnit.test( "offsetParent", function( assert ) {
assert.expect( 13 );
var body, header, div, area;
body = jQuery( "body" ).offsetParent();
equal( body.length, 1, "Only one offsetParent found." );
equal( body[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
assert.equal( body.length, 1, "Only one offsetParent found." );
assert.equal( body[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
header = jQuery( "#qunit" ).offsetParent();
equal( header.length, 1, "Only one offsetParent found." );
equal( header[ 0 ], document.documentElement, "The html element is the offsetParent of #qunit." );
assert.equal( header.length, 1, "Only one offsetParent found." );
assert.equal( header[ 0 ], document.documentElement, "The html element is the offsetParent of #qunit." );
div = jQuery( "#nothiddendivchild" ).offsetParent();
equal( div.length, 1, "Only one offsetParent found." );
equal( div[ 0 ], document.getElementById( "qunit-fixture" ), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
assert.equal( div.length, 1, "Only one offsetParent found." );
assert.equal( div[ 0 ], document.getElementById( "qunit-fixture" ), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
jQuery( "#nothiddendiv" ).css( "position", "relative" );
div = jQuery( "#nothiddendivchild" ).offsetParent();
equal( div.length, 1, "Only one offsetParent found." );
equal( div[ 0 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." );
assert.equal( div.length, 1, "Only one offsetParent found." );
assert.equal( div[ 0 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." );
div = jQuery( "body, #nothiddendivchild" ).offsetParent();
equal( div.length, 2, "Two offsetParent found." );
equal( div[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
equal( div[ 1 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." );
assert.equal( div.length, 2, "Two offsetParent found." );
assert.equal( div[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
assert.equal( div[ 1 ], jQuery( "#nothiddendiv" )[ 0 ], "The div is the offsetParent." );
area = jQuery( "#imgmap area" ).offsetParent();
equal( area[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
assert.equal( area[ 0 ], document.documentElement, "The html element is the offsetParent of the body." );
div = jQuery( "<div>" ).css( { "position": "absolute" } ).appendTo( "body" );
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 #12139" );
div.remove();
} );
test( "fractions (see #7730 and #7885)", function() {
expect( 2 );
QUnit.test( "fractions (see #7730 and #7885)", function( assert ) {
assert.expect( 2 );
jQuery( "body" ).append( "<div id='fractions'/>" );
@@ -564,14 +564,14 @@ test( "fractions (see #7730 and #7885)", function() {
result = div.offset();
equal( result.top, expected.top, "Check top" );
equal( result.left, expected.left, "Check left" );
assert.equal( result.top, expected.top, "Check top" );
assert.equal( result.left, expected.left, "Check left" );
div.remove();
} );
test( "iframe scrollTop/Left (see gh-1945)", function() {
expect( 2 );
QUnit.test( "iframe scrollTop/Left (see gh-1945)", function( assert ) {
assert.expect( 2 );
var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument;
@@ -581,8 +581,8 @@ test( "iframe scrollTop/Left (see gh-1945)", function() {
if ( /iphone os/i.test( navigator.userAgent ) ||
/android 2\.3/i.test( navigator.userAgent ) ||
/android 4\.0/i.test( navigator.userAgent ) ) {
equal( true, true, "Can't scroll iframes in this environment" );
equal( true, true, "Can't scroll iframes in this environment" );
assert.equal( true, true, "Can't scroll iframes in this environment" );
assert.equal( true, true, "Can't scroll iframes in this environment" );
} else {
@@ -599,8 +599,8 @@ test( "iframe scrollTop/Left (see gh-1945)", function() {
jQuery( ifDoc ).scrollTop( 200 );
jQuery( ifDoc ).scrollLeft( 500 );
equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" );
equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" );
assert.equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" );
assert.equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" );
}
} );