Fix #14084: attach the test div to documentElement, not body.

This commit is contained in:
Michał Gołębiowski 2013-08-22 00:33:57 +02:00
parent dfaee326e6
commit 776012b8b3
4 changed files with 66 additions and 43 deletions

View File

@ -5,3 +5,5 @@ test/data/badjson.js
test/data/json_obj.js
test/data/readywaitasset.js
test/data/readywaitloader.js
test/data/support/csp.js
test/data/support/getComputedSupport.js

View File

@ -6,7 +6,11 @@ define([
], function( jQuery ) {
jQuery.support = (function( support ) {
var input = document.createElement("input"),
var container, marginDiv, divStyle,
// Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box",
docElem = document.documentElement,
input = document.createElement("input"),
fragment = document.createDocumentFragment(),
div = document.createElement("div"),
select = document.createElement("select"),
@ -27,6 +31,10 @@ jQuery.support = (function( support ) {
// Support: IE9, IE10
support.optSelected = opt.selected;
// This is hard-coded to true for compatibility reasons,
// all supported browsers passed the test.
support.boxSizing = true;
// Will be defined later
support.reliableMarginRight = true;
support.boxSizingReliable = true;
@ -67,53 +75,35 @@ jQuery.support = (function( support ) {
div.cloneNode( true ).style.backgroundClip = "";
support.clearCloneStyle = div.style.backgroundClip === "content-box";
// Run tests that need a body at doc ready
jQuery(function() {
var container, marginDiv,
// Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box",
body = document.getElementsByTagName("body")[ 0 ];
container = document.createElement("div");
container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";
if ( !body ) {
// Return for frameset docs that don't have a body
return;
}
// Check box-sizing and margin behavior.
docElem.appendChild( container ).appendChild( div );
div.innerHTML = "";
// Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%";
container = document.createElement("div");
container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";
// Use window.getComputedStyle because jsdom on node.js will break without it.
if ( window.getComputedStyle ) {
divStyle = window.getComputedStyle( div, null );
support.pixelPosition = ( divStyle || {} ).top !== "1%";
support.boxSizingReliable = ( divStyle || { width: "4px" } ).width === "4px";
// Check box-sizing and margin behavior.
body.appendChild( container ).appendChild( div );
div.innerHTML = "";
// Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%";
// Support: Android 2.3
// Check if div with explicit width and no margin-right incorrectly
// gets computed margin-right based on width of container. (#3333)
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
marginDiv = div.appendChild( document.createElement( "div" ) );
marginDiv.style.cssText = div.style.cssText = divReset;
marginDiv.style.marginRight = marginDiv.style.width = "0";
div.style.width = "1px";
// Workaround failing boxSizing test due to offsetWidth returning wrong value
// with some non-1 values of body zoom, ticket #13543
jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() {
support.boxSizing = div.offsetWidth === 4;
});
support.reliableMarginRight =
!parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
}
// Use window.getComputedStyle because jsdom on node.js will break without it.
if ( window.getComputedStyle ) {
support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
// Support: Android 2.3
// Check if div with explicit width and no margin-right incorrectly
// gets computed margin-right based on width of container. (#3333)
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
marginDiv = div.appendChild( document.createElement("div") );
marginDiv.style.cssText = div.style.cssText = divReset;
marginDiv.style.marginRight = marginDiv.style.width = "0";
div.style.width = "1px";
support.reliableMarginRight =
!parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
}
body.removeChild( container );
});
docElem.removeChild( container );
return support;
})( {} );

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
#test {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 100px;
height: 100px;
padding: 10px;
}
</style>
</head>
<body>
<div id="test"></div>
<script src="../../jquery.js"></script>
<script>
var testWidth = jQuery( "#test" ).css( 'width' );
jQuery(function() {
window.parent.iframeCallback( testWidth );
});
</script>
</body>
</html>

View File

@ -797,6 +797,11 @@ test("css('width') and css('height') should respect box-sizing, see #11004", fun
equal( el_dis.css("height"), el_dis.css("height", el_dis.css("height")).css("height"), "css('height') is not respecting box-sizing for disconnected element, see #11004");
});
testIframeWithCallback( "css('width') should works correctly before document ready", "css/cssWidthBeforeDocReady.html", function( cssWidthBeforeDocReady ) {
expect( 1 );
strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" );
});
test("certain css values of 'normal' should be convertable to a number, see #8627", function() {
expect ( 2 );