Skip to content
Permalink
Browse files

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

  • Loading branch information
mgol committed Aug 21, 2013
1 parent dfaee32 commit 776012b8b3898fad2e0727880f1dc4af5c7b33c1
Showing with 70 additions and 47 deletions.
  1. +2 −0 .jshintignore
  2. +37 −47 src/support.js
  3. +26 −0 test/data/css/cssWidthBeforeDocReady.html
  4. +5 −0 test/unit/css.js
@@ -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
@@ -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 ];

if ( !body ) {
// Return for frameset docs that don't have a body
return;
}

container = document.createElement("div");
container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";
container = document.createElement("div");
container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";

// 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%";

// 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";

// 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 );
}

// 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%";

// 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;
});

// 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;
})( {} );
@@ -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>
@@ -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 );

0 comments on commit 776012b

Please sign in to comment.
You can’t perform that action at this time.