mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Tests: Improve offset test setup and labels
Hopefully this fixes iOS testing: http://swarm.jquery.org/job/5226
Ref 1d2df772b4
Closes gh-3641
This commit is contained in:
parent
a16339b893
commit
9e121482a5
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
window.startIframeTest = function() {
|
window.startIframeTest = function() {
|
||||||
var args = Array.prototype.slice.call( arguments );
|
var args = Array.prototype.slice.call( arguments );
|
||||||
|
|
||||||
|
@ -236,6 +236,7 @@ this.testIframe = function( title, fileName, func ) {
|
|||||||
var iframe;
|
var iframe;
|
||||||
var done = assert.async();
|
var done = assert.async();
|
||||||
|
|
||||||
|
// Test iframes are expected to invoke this via startIframeTest (cf. iframeTest.js)
|
||||||
window.iframeCallback = function() {
|
window.iframeCallback = function() {
|
||||||
var args = Array.prototype.slice.call( arguments );
|
var args = Array.prototype.slice.call( arguments );
|
||||||
|
|
||||||
|
@ -4,28 +4,45 @@ if ( !jQuery.fn.offset ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportsScroll, supportsFixedPosition,
|
var supportsFixedPosition, supportsScroll, alwaysScrollable,
|
||||||
forceScroll = jQuery( "<div/>" ).css( { width: 2000, height: 2000 } ),
|
forceScroll = supportjQuery( "<div/>" ).css( { width: 2000, height: 2000 } ),
|
||||||
checkSupport = function() {
|
checkSupport = function( assert ) {
|
||||||
|
|
||||||
// Only run once
|
// Only run once
|
||||||
checkSupport = false;
|
checkSupport = false;
|
||||||
|
|
||||||
var checkFixed = jQuery( "<div/>" ).css( { position: "fixed", top: "20px" } ).appendTo( "#qunit-fixture" );
|
var checkFixed = supportjQuery( "<div/>" )
|
||||||
|
.css( { position: "fixed", top: "20px" } )
|
||||||
|
.appendTo( "#qunit-fixture" );
|
||||||
|
supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20;
|
||||||
|
checkFixed.remove();
|
||||||
|
|
||||||
// Must append to body because #qunit-fixture is hidden and elements inside it don't have a scrollTop
|
// Append forceScroll to the body instead of #qunit-fixture because the latter is hidden
|
||||||
forceScroll.appendTo( "body" );
|
forceScroll.appendTo( "body" );
|
||||||
window.scrollTo( 200, 200 );
|
window.scrollTo( 200, 200 );
|
||||||
supportsScroll = document.documentElement.scrollTop || document.body.scrollTop;
|
supportsScroll = document.documentElement.scrollTop || document.body.scrollTop;
|
||||||
forceScroll.detach();
|
forceScroll.detach();
|
||||||
|
|
||||||
supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20;
|
// Support: iOS <=7
|
||||||
checkFixed.remove();
|
// Hijack the iframe test infrastructure to detect viewport scrollability
|
||||||
|
// for pages with position:fixed document element
|
||||||
|
var done = assert.async(),
|
||||||
|
$iframe = supportjQuery( "<iframe/>" )
|
||||||
|
.css( { position: "absolute", width: "50px", left: "-60px" } )
|
||||||
|
.attr( "src", url( "./data/offset/boxes.html" ) );
|
||||||
|
window.iframeCallback = function( $, win, doc ) {
|
||||||
|
doc.documentElement.style.position = "fixed";
|
||||||
|
alwaysScrollable = win.pageXOffset !== 0;
|
||||||
|
window.iframeCallback = undefined;
|
||||||
|
$iframe.remove();
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
$iframe.appendTo( document.body );
|
||||||
};
|
};
|
||||||
|
|
||||||
QUnit.module( "offset", { setup: function() {
|
QUnit.module( "offset", { setup: function( assert ) {
|
||||||
if ( typeof checkSupport === "function" ) {
|
if ( typeof checkSupport === "function" ) {
|
||||||
checkSupport();
|
checkSupport( assert );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force a scroll value on the main window to ensure incorrect results
|
// Force a scroll value on the main window to ensure incorrect results
|
||||||
@ -532,29 +549,7 @@ QUnit.test( "chaining", function( assert ) {
|
|||||||
512, 256, 1024, 512, 2048, 1024, position,
|
512, 256, 1024, 512, 2048, 1024, position,
|
||||||
position !== "fixed" && "documentElement" );
|
position !== "fixed" && "documentElement" );
|
||||||
},
|
},
|
||||||
viewportScroll = { top: 2, left: 1 },
|
viewportScroll = { top: 2, left: 1 };
|
||||||
|
|
||||||
alwaysScrollable = false;
|
|
||||||
|
|
||||||
// Support: iOS <=7
|
|
||||||
// Detect viewport scrollability for pages with position:fixed document element
|
|
||||||
( function() {
|
|
||||||
var $iframe = jQuery( "<iframe/>" )
|
|
||||||
.css( { position: "absolute", width: "50px", left: "-60px" } )
|
|
||||||
.attr( "src", url( "./data/offset/boxes.html" ) );
|
|
||||||
|
|
||||||
// Hijack the iframe test infrastructure
|
|
||||||
window.iframeCallback = function( $, win, doc ) {
|
|
||||||
doc.documentElement.style.position = "fixed";
|
|
||||||
alwaysScrollable = win.pageXOffset !== 0;
|
|
||||||
window.iframeCallback = undefined;
|
|
||||||
$iframe.remove();
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
$iframe.appendTo( document.body );
|
|
||||||
return;
|
|
||||||
} )();
|
|
||||||
|
|
||||||
function getExpectations( htmlPos, bodyPos ) {
|
function getExpectations( htmlPos, bodyPos ) {
|
||||||
|
|
||||||
@ -676,7 +671,8 @@ QUnit.test( "chaining", function( assert ) {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
supportjQuery.extend( {}, $( "#" + id ).offset() ),
|
supportjQuery.extend( {}, $( "#" + id ).offset() ),
|
||||||
descriptor.offset,
|
descriptor.offset,
|
||||||
"jQuery('#" + id + "').offset()" );
|
"jQuery('#" + id + "').offset(): top " + descriptor.offset.top +
|
||||||
|
", left " + descriptor.offset.left );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Verify expected relative position
|
// Verify expected relative position
|
||||||
@ -684,7 +680,8 @@ QUnit.test( "chaining", function( assert ) {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
supportjQuery.extend( {}, $( "#" + id ).position() ),
|
supportjQuery.extend( {}, $( "#" + id ).position() ),
|
||||||
descriptor.pos,
|
descriptor.pos,
|
||||||
"jQuery('#" + id + "').position()" );
|
"jQuery('#" + id + "').position(): top " + descriptor.pos.top +
|
||||||
|
", left " + descriptor.pos.left );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Verify that values round-trip
|
// Verify that values round-trip
|
||||||
|
Loading…
Reference in New Issue
Block a user