3 if ( !includesModule( "dimensions" ) ) {
7 QUnit
.module( "dimensions", { afterEach
: moduleTeardown
} );
20 ======== local reference =======
21 pass and fn can be used to test passing functions to setters
22 See testWidth below for an example
24 pass( value, assert );
25 This function returns whatever value is passed in
28 Returns a function that returns the value
31 function testWidth( val
, assert
) {
35 $div
= jQuery( "#nothiddendiv" );
36 $div
.width( val( 30 ) );
37 assert
.equal( $div
.width(), 30, "Test set to 30 correctly" );
38 $div
.css( "display", "none" );
39 assert
.equal( $div
.width(), 30, "Test hidden div" );
40 $div
.css( "display", "" );
41 $div
.width( val( -1 ) ); // handle negative numbers by setting to 0 trac-11604
42 assert
.equal( $div
.width(), 0, "Test negative width normalized to 0" );
43 $div
.css( "padding", "20px" );
44 assert
.equal( $div
.width(), 0, "Test padding specified with pixels" );
45 $div
.css( "border", "2px solid #fff" );
46 assert
.equal( $div
.width(), 0, "Test border specified with pixels" );
48 $div
.css( { "display": "", "border": "", "padding": "" } );
50 jQuery( "#nothiddendivchild" ).css( { "width": 20, "padding": "3px", "border": "2px solid #fff" } );
51 assert
.equal( jQuery( "#nothiddendivchild" ).width(), 20, "Test child width with border and padding" );
52 jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "width": "" } );
55 assert
.equal( $empty
.width( val( 10 ) ), $empty
, "Make sure that setting a width on an empty set returns the set." );
56 assert
.strictEqual( $empty
.width(), undefined, "Make sure 'undefined' is returned on an empty set" );
58 assert
.equal( jQuery( window
).width(), document
.documentElement
.clientWidth
, "Window width is equal to width reported by window/document." );
61 QUnit
.test( "width()", function( assert
) {
62 testWidth( pass
, assert
);
65 QUnit
.test( "width(Function)", function( assert
) {
66 testWidth( fn
, assert
);
69 QUnit
.test( "width(Function(args))", function( assert
) {
72 var $div
= jQuery( "#nothiddendiv" );
73 $div
.width( 30 ).width( function( i
, width
) {
74 assert
.equal( width
, 30, "Make sure previous value is correct." );
78 assert
.equal( $div
.width(), 31, "Make sure value was modified correctly." );
81 function testHeight( val
, assert
) {
86 $div
= jQuery( "#nothiddendiv" );
87 $div
.height( val( 30 ) );
88 assert
.equal( $div
.height(), 30, "Test set to 30 correctly" );
89 $div
.css( "display", "none" );
90 assert
.equal( $div
.height(), 30, "Test hidden div" );
91 $div
.css( "display", "" );
92 $div
.height( val( -1 ) ); // handle negative numbers by setting to 0 trac-11604
93 assert
.equal( $div
.height(), 0, "Test negative height normalized to 0" );
94 $div
.css( "padding", "20px" );
95 assert
.equal( $div
.height(), 0, "Test padding specified with pixels" );
96 $div
.css( "border", "2px solid #fff" );
97 assert
.equal( $div
.height(), 0, "Test border specified with pixels" );
99 $div
.css( { "display": "", "border": "", "padding": "", "height": "1px" } );
101 jQuery( "#nothiddendivchild" ).css( { "height": 20, "padding": "3px", "border": "2px solid #fff" } );
102 assert
.equal( jQuery( "#nothiddendivchild" ).height(), 20, "Test child height with border and padding" );
103 jQuery( "#nothiddendiv, #nothiddendivchild" ).css( { "border": "", "padding": "", "height": "" } );
105 blah
= jQuery( "blah" );
106 assert
.equal( blah
.height( val( 10 ) ), blah
, "Make sure that setting a height on an empty set returns the set." );
107 assert
.strictEqual( blah
.height(), undefined, "Make sure 'undefined' is returned on an empty set" );
109 assert
.equal( jQuery( window
).height(), document
.documentElement
.clientHeight
, "Window width is equal to width reported by window/document." );
112 QUnit
.test( "height()", function( assert
) {
113 testHeight( pass
, assert
);
116 QUnit
.test( "height(Function)", function( assert
) {
117 testHeight( fn
, assert
);
120 QUnit
.test( "height(Function(args))", function( assert
) {
123 var $div
= jQuery( "#nothiddendiv" );
124 $div
.height( 30 ).height( function( i
, height
) {
125 assert
.equal( height
, 30, "Make sure previous value is correct." );
129 assert
.equal( $div
.height(), 31, "Make sure value was modified correctly." );
132 QUnit
.test( "innerWidth()", function( assert
) {
136 $win
= jQuery( window
),
137 $doc
= jQuery( document
);
139 assert
.equal( jQuery( window
).innerWidth(), $win
.width(), "Test on window" );
140 assert
.equal( jQuery( document
).innerWidth(), $doc
.width(), "Test on document" );
141 assert
.strictEqual( jQuery().innerWidth(), undefined, "Test on empty set" );
143 $div
= jQuery( "#nothiddendiv" );
146 "border": "2px solid #fff",
150 assert
.equal( $div
.innerWidth(), 30, "Test with margin and border" );
151 $div
.css( "padding", "20px" );
152 assert
.equal( $div
.innerWidth(), 70, "Test with margin, border and padding" );
153 $div
.css( "display", "none" );
154 assert
.equal( $div
.innerWidth(), 70, "Test hidden div" );
157 $div
.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
159 div
= jQuery( "<div>" );
161 // Temporarily require 0 for backwards compat - should be auto
162 assert
.equal( div
.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
167 QUnit
.test( "innerHeight()", function( assert
) {
171 $win
= jQuery( window
),
172 $doc
= jQuery( document
);
174 assert
.equal( jQuery( window
).innerHeight(), $win
.height(), "Test on window" );
175 assert
.equal( jQuery( document
).innerHeight(), $doc
.height(), "Test on document" );
176 assert
.strictEqual( jQuery().innerHeight(), undefined, "Test on empty set" );
178 $div
= jQuery( "#nothiddendiv" );
181 "border": "2px solid #fff",
185 assert
.equal( $div
.innerHeight(), 30, "Test with margin and border" );
186 $div
.css( "padding", "20px" );
187 assert
.equal( $div
.innerHeight(), 70, "Test with margin, border and padding" );
188 $div
.css( "display", "none" );
189 assert
.equal( $div
.innerHeight(), 70, "Test hidden div" );
192 $div
.css( { "display": "", "border": "", "padding": "", "width": "", "height": "" } );
194 div
= jQuery( "<div>" );
196 // Temporarily require 0 for backwards compat - should be auto
197 assert
.equal( div
.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
202 QUnit
.test( "outerWidth()", function( assert
) {
206 $win
= jQuery( window
),
207 $doc
= jQuery( document
),
208 winwidth
= $win
.prop( "innerWidth" );
210 assert
.equal( jQuery( window
).outerWidth(), winwidth
, "Test on window without margin option" );
211 assert
.equal( jQuery( window
).outerWidth( true ), winwidth
, "Test on window with margin option" );
212 assert
.equal( jQuery( document
).outerWidth(), $doc
.width(), "Test on document without margin option" );
213 assert
.equal( jQuery( document
).outerWidth( true ), $doc
.width(), "Test on document with margin option" );
214 assert
.strictEqual( jQuery().outerWidth(), undefined, "Test on empty set" );
216 $div
= jQuery( "#nothiddendiv" );
217 $div
.css( "width", 30 );
219 assert
.equal( $div
.outerWidth(), 30, "Test with only width set" );
220 $div
.css( "padding", "20px" );
221 assert
.equal( $div
.outerWidth(), 70, "Test with padding" );
222 $div
.css( "border", "2px solid #fff" );
223 assert
.equal( $div
.outerWidth(), 74, "Test with padding and border" );
224 $div
.css( "margin", "10px" );
225 assert
.equal( $div
.outerWidth(), 74, "Test with padding, border and margin without margin option" );
226 $div
.css( "position", "absolute" );
227 assert
.equal( $div
.outerWidth( true ), 94, "Test with padding, border and margin with margin option" );
228 $div
.css( "display", "none" );
229 assert
.equal( $div
.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" );
232 $div
.css( { "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" } );
234 div
= jQuery( "<div>" );
236 // Temporarily require 0 for backwards compat - should be auto
237 assert
.equal( div
.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
242 QUnit
.test( "outerHeight()", function( assert
) {
246 $win
= jQuery( window
),
247 $doc
= jQuery( document
),
248 winheight
= $win
.prop( "innerHeight" );
250 assert
.equal( jQuery( window
).outerHeight(), winheight
, "Test on window without margin option" );
251 assert
.equal( jQuery( window
).outerHeight( true ), winheight
, "Test on window with margin option" );
252 assert
.equal( jQuery( document
).outerHeight(), $doc
.height(), "Test on document without margin option" );
253 assert
.equal( jQuery( document
).outerHeight( true ), $doc
.height(), "Test on document with margin option" );
254 assert
.strictEqual( jQuery().outerHeight(), undefined, "Test on empty set" );
256 $div
= jQuery( "#nothiddendiv" );
257 $div
.css( "height", 30 );
259 assert
.equal( $div
.outerHeight(), 30, "Test with only height set" );
260 $div
.css( "padding", "20px" );
261 assert
.equal( $div
.outerHeight(), 70, "Test with padding" );
262 $div
.css( "border", "2px solid #fff" );
263 assert
.equal( $div
.outerHeight(), 74, "Test with padding and border" );
264 $div
.css( "margin", "10px" );
265 assert
.equal( $div
.outerHeight(), 74, "Test with padding, border and margin without margin option" );
266 $div
.css( "position", "absolute" );
267 assert
.equal( $div
.outerHeight( true ), 94, "Test with padding, border and margin with margin option" );
268 $div
.css( "display", "none" );
269 assert
.equal( $div
.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" );
271 $div
.css( "display", "" );
272 $div
.css( "margin", "-10px" );
273 assert
.equal( $div
.outerHeight(), 74, "Test with padding, border and negative margin without margin option" );
274 assert
.equal( $div
.outerHeight( true ), 54, "Test with padding, border and negative margin with margin option" );
277 $div
.css( { "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" } );
279 div
= jQuery( "<div>" );
281 // Temporarily require 0 for backwards compat - should be auto
282 assert
.equal( div
.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
287 QUnit
.test( "fractional getters", function( assert
) {
290 var elem
= jQuery( "<div>" ).css( {
293 border
: "10px solid white",
298 elem
.appendTo( "#qunit-fixture" );
300 assert
.strictEqual( elem
.width(), 10.5, "width supports fractions" );
301 assert
.strictEqual( elem
.innerWidth(), 14.5, "innerWidth supports fractions" );
302 assert
.strictEqual( elem
.outerWidth(), 34.5, "outerWidth supports fractions" );
303 assert
.strictEqual( elem
.outerWidth( true ), 40.5, "outerWidth( true ) supports fractions" );
305 assert
.strictEqual( elem
.height(), 20.5, "height supports fractions" );
306 assert
.strictEqual( elem
.innerHeight(), 24.5, "innerHeight supports fractions" );
307 assert
.strictEqual( elem
.outerHeight(), 44.5, "outerHeight supports fractions" );
308 assert
.strictEqual( elem
.outerHeight( true ), 50.5, "outerHeight( true ) supports fractions" );
311 QUnit
.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see trac-9441 trac-9300", function( assert
) {
315 var $divNormal
= jQuery( "<div>" ).css( { "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
316 $divChild
= $divNormal
.clone(),
317 $divUnconnected
= $divNormal
.clone(),
318 $divHiddenParent
= jQuery( "<div>" ).css( "display", "none" ).append( $divChild
).appendTo( "body" );
319 $divNormal
.appendTo( "body" );
321 // tests that child div of a hidden div works the same as a normal div
322 assert
.equal( $divChild
.width(), $divNormal
.width(), "child of a hidden element width() is wrong see trac-9441" );
323 assert
.equal( $divChild
.innerWidth(), $divNormal
.innerWidth(), "child of a hidden element innerWidth() is wrong see trac-9441" );
324 assert
.equal( $divChild
.outerWidth(), $divNormal
.outerWidth(), "child of a hidden element outerWidth() is wrong see trac-9441" );
325 assert
.equal( $divChild
.outerWidth( true ), $divNormal
.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see trac-9300" );
327 assert
.equal( $divChild
.height(), $divNormal
.height(), "child of a hidden element height() is wrong see trac-9441" );
328 assert
.equal( $divChild
.innerHeight(), $divNormal
.innerHeight(), "child of a hidden element innerHeight() is wrong see trac-9441" );
329 assert
.equal( $divChild
.outerHeight(), $divNormal
.outerHeight(), "child of a hidden element outerHeight() is wrong see trac-9441" );
330 assert
.equal( $divChild
.outerHeight( true ), $divNormal
.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see trac-9300" );
332 // tests that child div of an unconnected div works the same as a normal div
333 assert
.equal( $divUnconnected
.width(), $divNormal
.width(), "unconnected element width() is wrong see trac-9441" );
334 assert
.equal( $divUnconnected
.innerWidth(), $divNormal
.innerWidth(), "unconnected element innerWidth() is wrong see trac-9441" );
335 assert
.equal( $divUnconnected
.outerWidth(), $divNormal
.outerWidth(), "unconnected element outerWidth() is wrong see trac-9441" );
336 assert
.equal( $divUnconnected
.outerWidth( true ), $divNormal
.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see trac-9300" );
338 assert
.equal( $divUnconnected
.height(), $divNormal
.height(), "unconnected element height() is wrong see trac-9441" );
339 assert
.equal( $divUnconnected
.innerHeight(), $divNormal
.innerHeight(), "unconnected element innerHeight() is wrong see trac-9441" );
340 assert
.equal( $divUnconnected
.outerHeight(), $divNormal
.outerHeight(), "unconnected element outerHeight() is wrong see trac-9441" );
341 assert
.equal( $divUnconnected
.outerHeight( true ), $divNormal
.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see trac-9300" );
344 $divHiddenParent
.remove();
348 QUnit
.test( "getting dimensions shouldn't modify runtimeStyle see trac-9233", function( assert
) {
351 var $div
= jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
353 runtimeStyle
= div
.runtimeStyle
;
355 if ( runtimeStyle
) {
356 div
.runtimeStyle
.marginLeft
= "12em";
357 div
.runtimeStyle
.left
= "11em";
360 $div
.outerWidth( true );
362 if ( runtimeStyle
) {
363 assert
.equal( div
.runtimeStyle
.left
, "11em", "getting dimensions modifies runtimeStyle, see trac-9233" );
365 assert
.ok( true, "this browser doesn't support runtimeStyle, see trac-9233" );
371 QUnit
.test( "table dimensions", function( assert
) {
374 var table
= jQuery( "<table><colgroup><col></col><col></col></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>" ).appendTo( "#qunit-fixture" ),
375 tdElem
= table
.find( "td" ).first(),
376 colElem
= table
.find( "col" ).first().width( 300 );
378 table
.find( "td" ).css( { "margin": 0, "padding": 0 } );
380 assert
.equal( tdElem
.width(), tdElem
.width(), "width() doesn't alter dimension values of empty cells, see trac-11293" );
381 assert
.equal( colElem
.width(), 300, "col elements have width(), see trac-12243" );
384 QUnit
.test( "SVG dimensions (basic content-box)", function( assert
) {
387 var svg
= jQuery( "<svg style='width: 100px; height: 100px;'></svg>" ).appendTo( "#qunit-fixture" );
389 assert
.equal( svg
.width(), 100 );
390 assert
.equal( svg
.height(), 100 );
392 assert
.equal( svg
.innerWidth(), 100 );
393 assert
.equal( svg
.innerHeight(), 100 );
395 assert
.equal( svg
.outerWidth(), 100 );
396 assert
.equal( svg
.outerHeight(), 100 );
398 assert
.equal( svg
.outerWidth( true ), 100 );
399 assert
.equal( svg
.outerHeight( true ), 100 );
404 QUnit
.test( "SVG dimensions (content-box)", function( assert
) {
407 var svg
= jQuery( "<svg style='width: 100px; height: 100px; box-sizing: content-box; border: 1px solid white; padding: 2px; margin: 3px'></svg>" ).appendTo( "#qunit-fixture" );
409 assert
.equal( svg
.width(), 100 );
410 assert
.equal( svg
.height(), 100 );
412 assert
.equal( svg
.innerWidth(), 104 );
413 assert
.equal( svg
.innerHeight(), 104 );
415 assert
.equal( svg
.outerWidth(), 106 );
416 assert
.equal( svg
.outerHeight(), 106 );
418 assert
.equal( svg
.outerWidth( true ), 112 );
419 assert
.equal( svg
.outerHeight( true ), 112 );
424 QUnit
.test( "SVG dimensions (border-box)", function( assert
) {
427 var svg
= jQuery( "<svg style='width: 100px; height: 100px; box-sizing: border-box; border: 1px solid white; padding: 2px; margin: 3px'></svg>" ).appendTo( "#qunit-fixture" );
429 assert
.equal( svg
.width(), 94, "width" );
430 assert
.equal( svg
.height(), 94, "height" );
432 assert
.equal( svg
.innerWidth(), 98, "innerWidth" );
433 assert
.equal( svg
.innerHeight(), 98, "innerHeight" );
435 assert
.equal( svg
.outerWidth(), 100, "outerWidth" );
436 assert
.equal( svg
.outerHeight(), 100, "outerHeight" );
438 assert
.equal( svg
.outerWidth( true ), 106, "outerWidth( true )" );
439 assert
.equal( svg
.outerHeight( true ), 106, "outerHeight( true )" );
444 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
) {
448 var $divNormal
= jQuery( "<div>" ).css( { "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
449 $divChild
= $divNormal
.clone(),
450 $divUnconnected
= $divNormal
.clone(),
451 $divHiddenParent
= jQuery( "<div>" ).css( "display", "none" ).append( $divChild
).appendTo( "body" );
452 $divNormal
.appendTo( "body" );
454 // tests that child div of a hidden div works the same as a normal div
455 assert
.equal( $divChild
.width(), $divNormal
.width(), "child of a hidden element width() is wrong see trac-10413" );
456 assert
.equal( $divChild
.innerWidth(), $divNormal
.innerWidth(), "child of a hidden element innerWidth() is wrong see trac-10413" );
457 assert
.equal( $divChild
.outerWidth(), $divNormal
.outerWidth(), "child of a hidden element outerWidth() is wrong see trac-10413" );
458 assert
.equal( $divChild
.outerWidth( true ), $divNormal
.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see trac-10413" );
460 assert
.equal( $divChild
.height(), $divNormal
.height(), "child of a hidden element height() is wrong see trac-10413" );
461 assert
.equal( $divChild
.innerHeight(), $divNormal
.innerHeight(), "child of a hidden element innerHeight() is wrong see trac-10413" );
462 assert
.equal( $divChild
.outerHeight(), $divNormal
.outerHeight(), "child of a hidden element outerHeight() is wrong see trac-10413" );
463 assert
.equal( $divChild
.outerHeight( true ), $divNormal
.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see trac-10413" );
465 // tests that child div of an unconnected div works the same as a normal div
466 assert
.equal( $divUnconnected
.width(), $divNormal
.width(), "unconnected element width() is wrong see trac-10413" );
467 assert
.equal( $divUnconnected
.innerWidth(), $divNormal
.innerWidth(), "unconnected element innerWidth() is wrong see trac-10413" );
468 assert
.equal( $divUnconnected
.outerWidth(), $divNormal
.outerWidth(), "unconnected element outerWidth() is wrong see trac-10413" );
469 assert
.equal( $divUnconnected
.outerWidth( true ), $divNormal
.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see trac-10413" );
471 assert
.equal( $divUnconnected
.height(), $divNormal
.height(), "unconnected element height() is wrong see trac-10413" );
472 assert
.equal( $divUnconnected
.innerHeight(), $divNormal
.innerHeight(), "unconnected element innerHeight() is wrong see trac-10413" );
473 assert
.equal( $divUnconnected
.outerHeight(), $divNormal
.outerHeight(), "unconnected element outerHeight() is wrong see trac-10413" );
474 assert
.equal( $divUnconnected
.outerHeight( true ), $divNormal
.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see trac-10413" );
477 $divHiddenParent
.remove();
481 QUnit
.test( "passing undefined is a setter trac-5571", function( assert
) {
483 assert
.equal( jQuery( "#nothiddendiv" ).height( 30 ).height( undefined ).height(), 30, ".height(undefined) is chainable (trac-5571)" );
484 assert
.equal( jQuery( "#nothiddendiv" ).height( 30 ).innerHeight( undefined ).height(), 30, ".innerHeight(undefined) is chainable (trac-5571)" );
485 assert
.equal( jQuery( "#nothiddendiv" ).height( 30 ).outerHeight( undefined ).height(), 30, ".outerHeight(undefined) is chainable (trac-5571)" );
486 assert
.equal( jQuery( "#nothiddendiv" ).width( 30 ).width( undefined ).width(), 30, ".width(undefined) is chainable (trac-5571)" );
489 QUnit
.test( "setters with and without box-sizing:border-box", function( assert
) {
490 assert
.expect( 120 );
492 var parent
= jQuery( "#foo" ).css( { width
: "200px", height
: "200px", "font-size": "16px" } ),
493 el_bb
= jQuery( "<div style='margin:5px;padding:1px;border:2px solid black;box-sizing:border-box;'></div>" ).appendTo( parent
),
494 el
= jQuery( "<div style='margin:5px;padding:1px;border:2px solid black;'></div>" ).appendTo( parent
),
495 el_bb_np
= jQuery( "<div style='margin:5px; padding:0px; border:0px solid green;box-sizing:border-box;'></div>" ).appendTo( parent
),
496 el_np
= jQuery( "<div style='margin:5px; padding:0px; border:0px solid green;'></div>" ).appendTo( parent
);
499 "number": { set: 100, expected
: 100 },
500 "em": { set: "10em", expected
: 160 },
501 "percentage": { set: "50%", expected
: 100 }
502 }, function( units
, values
) {
503 assert
.equal( el_bb
.width( values
.set ).width(), values
.expected
, "test border-box width(" + units
+ ") by roundtripping" );
504 assert
.equal( el_bb
.innerWidth( values
.set ).width(), values
.expected
- 2, "test border-box innerWidth(" + units
+ ") by roundtripping" );
505 assert
.equal( el_bb
.outerWidth( values
.set ).width(), values
.expected
- 6, "test border-box outerWidth(" + units
+ ") by roundtripping" );
506 assert
.equal( el_bb
.outerWidth( values
.set, false ).width(), values
.expected
- 6, "test border-box outerWidth(" + units
+ ", false) by roundtripping" );
507 assert
.equal( el_bb
.outerWidth( values
.set, true ).width(), values
.expected
- 16, "test border-box outerWidth(" + units
+ ", true) by roundtripping" );
509 assert
.equal( el_bb
.height( values
.set ).height(), values
.expected
, "test border-box height(" + units
+ ") by roundtripping" );
510 assert
.equal( el_bb
.innerHeight( values
.set ).height(), values
.expected
- 2, "test border-box innerHeight(" + units
+ ") by roundtripping" );
511 assert
.equal( el_bb
.outerHeight( values
.set ).height(), values
.expected
- 6, "test border-box outerHeight(" + units
+ ") by roundtripping" );
512 assert
.equal( el_bb
.outerHeight( values
.set, false ).height(), values
.expected
- 6, "test border-box outerHeight(" + units
+ ", false) by roundtripping" );
513 assert
.equal( el_bb
.outerHeight( values
.set, true ).height(), values
.expected
- 16, "test border-box outerHeight(" + units
+ ", true) by roundtripping" );
515 assert
.equal( el
.width( values
.set ).width(), values
.expected
, "test non-border-box width(" + units
+ ") by roundtripping" );
516 assert
.equal( el
.innerWidth( values
.set ).width(), values
.expected
- 2, "test non-border-box innerWidth(" + units
+ ") by roundtripping" );
517 assert
.equal( el
.outerWidth( values
.set ).width(), values
.expected
- 6, "test non-border-box outerWidth(" + units
+ ") by roundtripping" );
518 assert
.equal( el
.outerWidth( values
.set, false ).width(), values
.expected
- 6, "test non-border-box outerWidth(" + units
+ ", false) by roundtripping" );
519 assert
.equal( el
.outerWidth( values
.set, true ).width(), values
.expected
- 16, "test non-border-box outerWidth(" + units
+ ", true) by roundtripping" );
521 assert
.equal( el
.height( values
.set ).height(), values
.expected
, "test non-border-box height(" + units
+ ") by roundtripping" );
522 assert
.equal( el
.innerHeight( values
.set ).height(), values
.expected
- 2, "test non-border-box innerHeight(" + units
+ ") by roundtripping" );
523 assert
.equal( el
.outerHeight( values
.set ).height(), values
.expected
- 6, "test non-border-box outerHeight(" + units
+ ") by roundtripping" );
524 assert
.equal( el
.outerHeight( values
.set, false ).height(), values
.expected
- 6, "test non-border-box outerHeight(" + units
+ ", false) by roundtripping" );
525 assert
.equal( el
.outerHeight( values
.set, true ).height(), values
.expected
- 16, "test non-border-box outerHeight(" + units
+ ", true) by roundtripping" );
527 assert
.equal( el_bb_np
.width( values
.set ).width(), values
.expected
, "test border-box width and negative padding(" + units
+ ") by roundtripping" );
528 assert
.equal( el_bb_np
.innerWidth( values
.set ).width(), values
.expected
, "test border-box innerWidth and negative padding(" + units
+ ") by roundtripping" );
529 assert
.equal( el_bb_np
.outerWidth( values
.set ).width(), values
.expected
, "test border-box outerWidth and negative padding(" + units
+ ") by roundtripping" );
530 assert
.equal( el_bb_np
.outerWidth( values
.set, false ).width(), values
.expected
, "test border-box outerWidth and negative padding(" + units
+ ", false) by roundtripping" );
531 assert
.equal( el_bb_np
.outerWidth( values
.set, true ).width(), values
.expected
- 10, "test border-box outerWidth and negative padding(" + units
+ ", true) by roundtripping" );
533 assert
.equal( el_bb_np
.height( values
.set ).height(), values
.expected
, "test border-box height and negative padding(" + units
+ ") by roundtripping" );
534 assert
.equal( el_bb_np
.innerHeight( values
.set ).height(), values
.expected
, "test border-box innerHeight and negative padding(" + units
+ ") by roundtripping" );
535 assert
.equal( el_bb_np
.outerHeight( values
.set ).height(), values
.expected
, "test border-box outerHeight and negative padding(" + units
+ ") by roundtripping" );
536 assert
.equal( el_bb_np
.outerHeight( values
.set, false ).height(), values
.expected
, "test border-box outerHeight and negative padding(" + units
+ ", false) by roundtripping" );
537 assert
.equal( el_bb_np
.outerHeight( values
.set, true ).height(), values
.expected
- 10, "test border-box outerHeight and negative padding(" + units
+ ", true) by roundtripping" );
539 assert
.equal( el_np
.width( values
.set ).width(), values
.expected
, "test non-border-box width and negative padding(" + units
+ ") by roundtripping" );
540 assert
.equal( el_np
.innerWidth( values
.set ).width(), values
.expected
, "test non-border-box innerWidth and negative padding(" + units
+ ") by roundtripping" );
541 assert
.equal( el_np
.outerWidth( values
.set ).width(), values
.expected
, "test non-border-box outerWidth and negative padding(" + units
+ ") by roundtripping" );
542 assert
.equal( el_np
.outerWidth( values
.set, false ).width(), values
.expected
, "test non-border-box outerWidth and negative padding(" + units
+ ", false) by roundtripping" );
543 assert
.equal( el_np
.outerWidth( values
.set, true ).width(), values
.expected
- 10, "test non-border-box outerWidth and negative padding(" + units
+ ", true) by roundtripping" );
545 assert
.equal( el_np
.height( values
.set ).height(), values
.expected
, "test non-border-box height and negative padding(" + units
+ ") by roundtripping" );
546 assert
.equal( el_np
.innerHeight( values
.set ).height(), values
.expected
, "test non-border-box innerHeight and negative padding(" + units
+ ") by roundtripping" );
547 assert
.equal( el_np
.outerHeight( values
.set ).height(), values
.expected
, "test non-border-box outerHeight and negative padding(" + units
+ ") by roundtripping" );
548 assert
.equal( el_np
.outerHeight( values
.set, false ).height(), values
.expected
, "test non-border-box outerHeight and negative padding(" + units
+ ", false) by roundtripping" );
549 assert
.equal( el_np
.outerHeight( values
.set, true ).height(), values
.expected
- 10, "test non-border-box outerHeight and negative padding(" + units
+ ", true) by roundtripping" );
554 "window vs. large document",
555 "dimensions/documentLarge.html",
556 function( assert
, jQuery
, window
, document
) {
559 assert
.ok( jQuery( document
).height() > jQuery( window
).height(), "document height is larger than window height" );
560 assert
.ok( jQuery( document
).width() > jQuery( window
).width(), "document width is larger than window width" );
564 QUnit
.test( "allow modification of coordinates argument (gh-1848)", function( assert
) {
568 element
= jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
570 element
.offset( function( index
, coords
) {
576 offsetTop
= element
.offset().top
;
577 assert
.ok( Math
.abs( offsetTop
- 100 ) < 0.02,
578 "coordinates are modified (got offset.top: " + offsetTop
+ ")" );
581 QUnit
.test( "outside view position (gh-2836)", function( assert
) {
583 // This test ported from gh-2836 example
588 "<div id=div-gh-2836>",
596 stop
= assert
.async();
598 parent
= jQuery( html
);
599 parent
.appendTo( "#qunit-fixture" );
601 parent
.one( "scroll", function() {
602 var pos
= parent
.find( "div" ).eq( 3 ).position();
604 assert
.strictEqual( pos
.top
, -100 );
608 parent
.scrollTop( 400 );
611 QUnit
.test( "width/height on element with transform (gh-3193)", function( assert
) {
615 var $elem
= jQuery( "<div style='width: 200px; height: 200px; transform: scale(2);'></div>" )
616 .appendTo( "#qunit-fixture" );
618 assert
.equal( $elem
.width(), 200, "Width ignores transforms" );
619 assert
.equal( $elem
.height(), 200, "Height ignores transforms" );
622 QUnit
.test( "width/height on an inline element with no explicitly-set dimensions (gh-3571)", function( assert
) {
625 var $elem
= jQuery( "<span style='border: 2px solid black;padding: 1px;margin: 3px;'>Hello, I'm some text.</span>" ).appendTo( "#qunit-fixture" );
627 jQuery
.each( [ "Width", "Height" ], function( i
, method
) {
628 var val
= $elem
[ method
.toLowerCase() ]();
629 assert
.notEqual( val
, 0, method
+ " should not be zero on inline element." );
630 assert
.equal( $elem
[ "inner" + method
](), val
+ 2, "inner" + method
+ " should include padding" );
631 assert
.equal( $elem
[ "outer" + method
](), val
+ 6, "outer" + method
+ " should include padding and border" );
632 assert
.equal( $elem
[ "outer" + method
]( true ), val
+ 12, "outer" + method
+ "(true) should include padding, border, and margin" );
636 QUnit
.test( "width/height on an inline element with percentage dimensions (gh-3611)",
640 jQuery( "<div id='gh3611' style='width: 100px;'>" +
641 "<span style='width: 100%; padding: 0 5px'>text</span>" +
642 "</div>" ).appendTo( "#qunit-fixture" );
644 var $elem
= jQuery( "#gh3611 span" ),
645 actualWidth
= $elem
[ 0 ].getBoundingClientRect().width
,
646 marginWidth
= $elem
.outerWidth( true ),
647 borderWidth
= $elem
.outerWidth(),
648 paddingWidth
= $elem
.innerWidth(),
649 contentWidth
= $elem
.width();
651 assert
.equal( Math
.round( borderWidth
), Math
.round( actualWidth
),
652 ".outerWidth(): " + borderWidth
+ " approximates " + actualWidth
);
653 assert
.equal( marginWidth
, borderWidth
, ".outerWidth(true) matches .outerWidth()" );
654 assert
.equal( paddingWidth
, borderWidth
, ".innerWidth() matches .outerWidth()" );
655 assert
.equal( contentWidth
, borderWidth
- 10, ".width() excludes padding" );
660 "width/height on a table row with phantom borders (gh-3698)", function( assert
) {
663 jQuery( "<table id='gh3698' style='border-collapse: separate; border-spacing: 0;'><tbody>" +
664 "<tr style='margin: 0; border: 10px solid black; padding: 0'>" +
665 "<td style='margin: 0; border: 0; padding: 0; height: 42px; width: 42px;'></td>" +
667 "</tbody></table>" ).appendTo( "#qunit-fixture" );
669 var $elem
= jQuery( "#gh3698 tr" );
671 jQuery
.each( [ "Width", "Height" ], function( i
, method
) {
672 assert
.equal( $elem
[ "outer" + method
](), 42,
673 "outer" + method
+ " should match content dimensions" );
674 assert
.equal( $elem
[ "outer" + method
]( true ), 42,
675 "outer" + method
+ "(true) should match content dimensions" );
679 QUnit
.test( "interaction with scrollbars (gh-3589)", function( assert
) {
684 updater = function( adjustment
) {
685 return function( i
, old
) {
686 return old
+ adjustment
;
689 parent
= jQuery( "<div></div>" )
690 .css( { position
: "absolute", width
: "1000px", height
: "1000px" } )
691 .appendTo( "#qunit-fixture" ),
693 // Workarounds for IE kill fractional output here.
694 fraction
= document
.documentMode
? 0 : 0.5,
697 size
= 100 + fraction
,
698 plainBox
= jQuery( "<div></div>" )
700 "box-sizing": "content-box",
701 position
: "absolute",
706 contentBox
= plainBox
709 border
: borderWidth
+ "px solid blue",
710 padding
: padding
+ "px"
712 borderBox
= contentBox
714 .css( { "box-sizing": "border-box" } ),
715 relativeBorderBox
= borderBox
717 .css( { position
: "relative" } ),
719 [ plainBox
[ 0 ], contentBox
[ 0 ], borderBox
[ 0 ], relativeBorderBox
[ 0 ] ]
720 ).appendTo( parent
);
722 for ( i
= 0; i
< 3; i
++ ) {
724 suffix
= " after increasing inner* by " + i
;
726 $boxes
.innerWidth( updater( i
) ).innerHeight( updater( i
) );
727 } else if ( i
=== 2 ) {
728 suffix
= " after increasing outer* by " + i
;
730 $boxes
.outerWidth( updater( i
) ).outerHeight( updater( i
) );
733 assert
.equal( plainBox
.innerWidth(), size
,
734 "plain content-box innerWidth includes scroll gutter" + suffix
);
735 assert
.equal( plainBox
.innerHeight(), size
,
736 "plain content-box innerHeight includes scroll gutter" + suffix
);
737 assert
.equal( plainBox
.outerWidth(), size
,
738 "plain content-box outerWidth includes scroll gutter" + suffix
);
739 assert
.equal( plainBox
.outerHeight(), size
,
740 "plain content-box outerHeight includes scroll gutter" + suffix
);
742 assert
.equal( contentBox
.innerWidth(), size
+ 2 * padding
,
743 "content-box innerWidth includes scroll gutter" + suffix
);
744 assert
.equal( contentBox
.innerHeight(), size
+ 2 * padding
,
745 "content-box innerHeight includes scroll gutter" + suffix
);
746 assert
.equal( contentBox
.outerWidth(), size
+ 2 * padding
+ 2 * borderWidth
,
747 "content-box outerWidth includes scroll gutter" + suffix
);
748 assert
.equal( contentBox
.outerHeight(), size
+ 2 * padding
+ 2 * borderWidth
,
749 "content-box outerHeight includes scroll gutter" + suffix
);
751 assert
.equal( borderBox
.innerWidth(), size
- 2 * borderWidth
,
752 "border-box innerWidth includes scroll gutter" + suffix
);
753 assert
.equal( borderBox
.innerHeight(), size
- 2 * borderWidth
,
754 "border-box innerHeight includes scroll gutter" + suffix
);
755 assert
.equal( borderBox
.outerWidth(), size
,
756 "border-box outerWidth includes scroll gutter" + suffix
);
757 assert
.equal( borderBox
.outerHeight(), size
,
758 "border-box outerHeight includes scroll gutter" + suffix
);
760 assert
.equal( relativeBorderBox
.innerWidth(), size
- 2 * borderWidth
,
761 "relative border-box innerWidth includes scroll gutter" + suffix
);
762 assert
.equal( relativeBorderBox
.innerHeight(), size
- 2 * borderWidth
,
763 "relative border-box innerHeight includes scroll gutter" + suffix
);
764 assert
.equal( relativeBorderBox
.outerWidth(), size
,
765 "relative border-box outerWidth includes scroll gutter" + suffix
);
766 assert
.equal( relativeBorderBox
.outerHeight(), size
,
767 "relative border-box outerHeight includes scroll gutter" + suffix
);
771 QUnit
.test( "outerWidth/Height for table cells and textarea with border-box in IE 11 (gh-4102)", function( assert
) {
773 var $table
= jQuery( "<table class='border-box' style='border-collapse: separate'></table>" ).appendTo( "#qunit-fixture" ),
774 $thead
= jQuery( "<thead></thead>" ).appendTo( $table
),
775 $firstTh
= jQuery( "<th style='width: 200px;padding: 5px'></th>" ),
776 $secondTh
= jQuery( "<th style='width: 190px;padding: 5px'></th>" ),
777 $thirdTh
= jQuery( "<th style='width: 180px;padding: 5px'></th>" ),
779 // Most browsers completely ignore the border-box and height settings.
780 // The computed height is instead just line-height + border.
781 // Either way, what we're doing in css.js is correct.
782 $td
= jQuery( "<td style='height: 20px;padding: 5px;border: 1px solid;line-height:18px'>text</td>" ),
784 $tbody
= jQuery( "<tbody></tbody>" ).appendTo( $table
),
785 $textarea
= jQuery( "<textarea style='height: 0;padding: 2px;border: 1px solid;box-sizing: border-box'></textarea>" ).appendTo( "#qunit-fixture" );
787 jQuery( "<tr></tr>" ).appendTo( $thead
).append( $firstTh
);
788 jQuery( "<tr></tr>" ).appendTo( $thead
).append( $secondTh
);
789 jQuery( "<tr></tr>" ).appendTo( $thead
).append( $thirdTh
);
790 jQuery( "<tr><td></td></tr>" ).appendTo( $tbody
).append( $td
);
792 assert
.strictEqual( $firstTh
.outerWidth(), 200, "First th has outerWidth 200." );
793 assert
.strictEqual( $secondTh
.outerWidth(), 200, "Second th has outerWidth 200." );
794 assert
.strictEqual( $thirdTh
.outerWidth(), 200, "Third th has outerWidth 200." );
795 assert
.strictEqual( $td
.outerHeight(), 30, "outerHeight of td with border-box should include padding." );
796 assert
.strictEqual( $textarea
.outerHeight(), 6, "outerHeight of textarea with border-box should include padding and border." );