3 if ( !jQuery
.fn
.width
) {
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 #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 #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" );
272 $div
.css( { "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" } );
274 div
= jQuery( "<div>" );
276 // Temporarily require 0 for backwards compat - should be auto
277 assert
.equal( div
.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
282 QUnit
.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert
) {
286 var $divNormal
= jQuery( "<div>" ).css( { "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
287 $divChild
= $divNormal
.clone(),
288 $divUnconnected
= $divNormal
.clone(),
289 $divHiddenParent
= jQuery( "<div>" ).css( "display", "none" ).append( $divChild
).appendTo( "body" );
290 $divNormal
.appendTo( "body" );
292 // tests that child div of a hidden div works the same as a normal div
293 assert
.equal( $divChild
.width(), $divNormal
.width(), "child of a hidden element width() is wrong see #9441" );
294 assert
.equal( $divChild
.innerWidth(), $divNormal
.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
295 assert
.equal( $divChild
.outerWidth(), $divNormal
.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
296 assert
.equal( $divChild
.outerWidth( true ), $divNormal
.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
298 assert
.equal( $divChild
.height(), $divNormal
.height(), "child of a hidden element height() is wrong see #9441" );
299 assert
.equal( $divChild
.innerHeight(), $divNormal
.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
300 assert
.equal( $divChild
.outerHeight(), $divNormal
.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
301 assert
.equal( $divChild
.outerHeight( true ), $divNormal
.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
303 // tests that child div of an unconnected div works the same as a normal div
304 assert
.equal( $divUnconnected
.width(), $divNormal
.width(), "unconnected element width() is wrong see #9441" );
305 assert
.equal( $divUnconnected
.innerWidth(), $divNormal
.innerWidth(), "unconnected element innerWidth() is wrong see #9441" );
306 assert
.equal( $divUnconnected
.outerWidth(), $divNormal
.outerWidth(), "unconnected element outerWidth() is wrong see #9441" );
307 assert
.equal( $divUnconnected
.outerWidth( true ), $divNormal
.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
309 assert
.equal( $divUnconnected
.height(), $divNormal
.height(), "unconnected element height() is wrong see #9441" );
310 assert
.equal( $divUnconnected
.innerHeight(), $divNormal
.innerHeight(), "unconnected element innerHeight() is wrong see #9441" );
311 assert
.equal( $divUnconnected
.outerHeight(), $divNormal
.outerHeight(), "unconnected element outerHeight() is wrong see #9441" );
312 assert
.equal( $divUnconnected
.outerHeight( true ), $divNormal
.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #9300" );
315 $divHiddenParent
.remove();
319 QUnit
.test( "getting dimensions shouldn't modify runtimeStyle see #9233", function( assert
) {
322 var $div
= jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
324 runtimeStyle
= div
.runtimeStyle
;
326 if ( runtimeStyle
) {
327 div
.runtimeStyle
.marginLeft
= "12em";
328 div
.runtimeStyle
.left
= "11em";
331 $div
.outerWidth( true );
333 if ( runtimeStyle
) {
334 assert
.equal( div
.runtimeStyle
.left
, "11em", "getting dimensions modifies runtimeStyle, see #9233" );
336 assert
.ok( true, "this browser doesn't support runtimeStyle, see #9233" );
342 QUnit
.test( "table dimensions", function( assert
) {
345 var table
= jQuery( "<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>" ).appendTo( "#qunit-fixture" ),
346 tdElem
= table
.find( "td" ).first(),
347 colElem
= table
.find( "col" ).first().width( 300 );
349 table
.find( "td" ).css( { "margin": 0, "padding": 0 } );
351 assert
.equal( tdElem
.width(), tdElem
.width(), "width() doesn't alter dimension values of empty cells, see #11293" );
352 assert
.equal( colElem
.width(), 300, "col elements have width(), see #12243" );
355 QUnit
.test( "SVG dimensions (basic content-box)", function( assert
) {
358 var svg
= jQuery( "<svg style='width: 100px; height: 100px;'></svg>" ).appendTo( "#qunit-fixture" );
360 assert
.equal( svg
.width(), 100 );
361 assert
.equal( svg
.height(), 100 );
363 assert
.equal( svg
.innerWidth(), 100 );
364 assert
.equal( svg
.innerHeight(), 100 );
366 assert
.equal( svg
.outerWidth(), 100 );
367 assert
.equal( svg
.outerHeight(), 100 );
369 assert
.equal( svg
.outerWidth( true ), 100 );
370 assert
.equal( svg
.outerHeight( true ), 100 );
375 QUnit
.test( "SVG dimensions (content-box)", function( assert
) {
378 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" );
380 assert
.equal( svg
.width(), 100 );
381 assert
.equal( svg
.height(), 100 );
383 assert
.equal( svg
.innerWidth(), 104 );
384 assert
.equal( svg
.innerHeight(), 104 );
386 assert
.equal( svg
.outerWidth(), 106 );
387 assert
.equal( svg
.outerHeight(), 106 );
389 assert
.equal( svg
.outerWidth( true ), 112 );
390 assert
.equal( svg
.outerHeight( true ), 112 );
395 QUnit
.test( "SVG dimensions (border-box)", function( assert
) {
398 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" );
400 assert
.equal( svg
.width(), 94, "width" );
401 assert
.equal( svg
.height(), 94, "height" );
403 assert
.equal( svg
.innerWidth(), 98, "innerWidth" );
404 assert
.equal( svg
.innerHeight(), 98, "innerHeight" );
406 assert
.equal( svg
.outerWidth(), 100, "outerWidth" );
407 assert
.equal( svg
.outerHeight(), 100, "outerHeight" );
409 assert
.equal( svg
.outerWidth( true ), 106, "outerWidth( true )" );
410 assert
.equal( svg
.outerHeight( true ), 106, "outerHeight( true )" );
415 QUnit
.test( "box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert
) {
419 var $divNormal
= jQuery( "<div>" ).css( { "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" } ),
420 $divChild
= $divNormal
.clone(),
421 $divUnconnected
= $divNormal
.clone(),
422 $divHiddenParent
= jQuery( "<div>" ).css( "display", "none" ).append( $divChild
).appendTo( "body" );
423 $divNormal
.appendTo( "body" );
425 // tests that child div of a hidden div works the same as a normal div
426 assert
.equal( $divChild
.width(), $divNormal
.width(), "child of a hidden element width() is wrong see #10413" );
427 assert
.equal( $divChild
.innerWidth(), $divNormal
.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" );
428 assert
.equal( $divChild
.outerWidth(), $divNormal
.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
429 assert
.equal( $divChild
.outerWidth( true ), $divNormal
.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
431 assert
.equal( $divChild
.height(), $divNormal
.height(), "child of a hidden element height() is wrong see #10413" );
432 assert
.equal( $divChild
.innerHeight(), $divNormal
.innerHeight(), "child of a hidden element innerHeight() is wrong see #10413" );
433 assert
.equal( $divChild
.outerHeight(), $divNormal
.outerHeight(), "child of a hidden element outerHeight() is wrong see #10413" );
434 assert
.equal( $divChild
.outerHeight( true ), $divNormal
.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
436 // tests that child div of an unconnected div works the same as a normal div
437 assert
.equal( $divUnconnected
.width(), $divNormal
.width(), "unconnected element width() is wrong see #10413" );
438 assert
.equal( $divUnconnected
.innerWidth(), $divNormal
.innerWidth(), "unconnected element innerWidth() is wrong see #10413" );
439 assert
.equal( $divUnconnected
.outerWidth(), $divNormal
.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
440 assert
.equal( $divUnconnected
.outerWidth( true ), $divNormal
.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
442 assert
.equal( $divUnconnected
.height(), $divNormal
.height(), "unconnected element height() is wrong see #10413" );
443 assert
.equal( $divUnconnected
.innerHeight(), $divNormal
.innerHeight(), "unconnected element innerHeight() is wrong see #10413" );
444 assert
.equal( $divUnconnected
.outerHeight(), $divNormal
.outerHeight(), "unconnected element outerHeight() is wrong see #10413" );
445 assert
.equal( $divUnconnected
.outerHeight( true ), $divNormal
.outerHeight( true ), "unconnected element outerHeight( true ) is wrong see #10413" );
448 $divHiddenParent
.remove();
452 QUnit
.test( "passing undefined is a setter #5571", function( assert
) {
454 assert
.equal( jQuery( "#nothiddendiv" ).height( 30 ).height( undefined ).height(), 30, ".height(undefined) is chainable (#5571)" );
455 assert
.equal( jQuery( "#nothiddendiv" ).height( 30 ).innerHeight( undefined ).height(), 30, ".innerHeight(undefined) is chainable (#5571)" );
456 assert
.equal( jQuery( "#nothiddendiv" ).height( 30 ).outerHeight( undefined ).height(), 30, ".outerHeight(undefined) is chainable (#5571)" );
457 assert
.equal( jQuery( "#nothiddendiv" ).width( 30 ).width( undefined ).width(), 30, ".width(undefined) is chainable (#5571)" );
460 QUnit
.test( "setters with and without box-sizing:border-box", function( assert
) {
461 assert
.expect( 120 );
463 var parent
= jQuery( "#foo" ).css( { width
: "200px", height
: "200px", "font-size": "16px" } ),
464 el_bb
= jQuery( "<div style='margin:5px;padding:1px;border:2px solid black;box-sizing:border-box;'></div>" ).appendTo( parent
),
465 el
= jQuery( "<div style='margin:5px;padding:1px;border:2px solid black;'></div>" ).appendTo( parent
),
466 el_bb_np
= jQuery( "<div style='margin:5px; padding:0px; border:0px solid green;box-sizing:border-box;'></div>" ).appendTo( parent
),
467 el_np
= jQuery( "<div style='margin:5px; padding:0px; border:0px solid green;'></div>" ).appendTo( parent
);
470 "number": { set: 100, expected
: 100 },
471 "em": { set: "10em", expected
: 160 },
472 "percentage": { set: "50%", expected
: 100 }
473 }, function( units
, values
) {
474 assert
.equal( el_bb
.width( values
.set ).width(), values
.expected
, "test border-box width(" + units
+ ") by roundtripping" );
475 assert
.equal( el_bb
.innerWidth( values
.set ).width(), values
.expected
- 2, "test border-box innerWidth(" + units
+ ") by roundtripping" );
476 assert
.equal( el_bb
.outerWidth( values
.set ).width(), values
.expected
- 6, "test border-box outerWidth(" + units
+ ") by roundtripping" );
477 assert
.equal( el_bb
.outerWidth( values
.set, false ).width(), values
.expected
- 6, "test border-box outerWidth(" + units
+ ", false) by roundtripping" );
478 assert
.equal( el_bb
.outerWidth( values
.set, true ).width(), values
.expected
- 16, "test border-box outerWidth(" + units
+ ", true) by roundtripping" );
480 assert
.equal( el_bb
.height( values
.set ).height(), values
.expected
, "test border-box height(" + units
+ ") by roundtripping" );
481 assert
.equal( el_bb
.innerHeight( values
.set ).height(), values
.expected
- 2, "test border-box innerHeight(" + units
+ ") by roundtripping" );
482 assert
.equal( el_bb
.outerHeight( values
.set ).height(), values
.expected
- 6, "test border-box outerHeight(" + units
+ ") by roundtripping" );
483 assert
.equal( el_bb
.outerHeight( values
.set, false ).height(), values
.expected
- 6, "test border-box outerHeight(" + units
+ ", false) by roundtripping" );
484 assert
.equal( el_bb
.outerHeight( values
.set, true ).height(), values
.expected
- 16, "test border-box outerHeight(" + units
+ ", true) by roundtripping" );
486 assert
.equal( el
.width( values
.set ).width(), values
.expected
, "test non-border-box width(" + units
+ ") by roundtripping" );
487 assert
.equal( el
.innerWidth( values
.set ).width(), values
.expected
- 2, "test non-border-box innerWidth(" + units
+ ") by roundtripping" );
488 assert
.equal( el
.outerWidth( values
.set ).width(), values
.expected
- 6, "test non-border-box outerWidth(" + units
+ ") by roundtripping" );
489 assert
.equal( el
.outerWidth( values
.set, false ).width(), values
.expected
- 6, "test non-border-box outerWidth(" + units
+ ", false) by roundtripping" );
490 assert
.equal( el
.outerWidth( values
.set, true ).width(), values
.expected
- 16, "test non-border-box outerWidth(" + units
+ ", true) by roundtripping" );
492 assert
.equal( el
.height( values
.set ).height(), values
.expected
, "test non-border-box height(" + units
+ ") by roundtripping" );
493 assert
.equal( el
.innerHeight( values
.set ).height(), values
.expected
- 2, "test non-border-box innerHeight(" + units
+ ") by roundtripping" );
494 assert
.equal( el
.outerHeight( values
.set ).height(), values
.expected
- 6, "test non-border-box outerHeight(" + units
+ ") by roundtripping" );
495 assert
.equal( el
.outerHeight( values
.set, false ).height(), values
.expected
- 6, "test non-border-box outerHeight(" + units
+ ", false) by roundtripping" );
496 assert
.equal( el
.outerHeight( values
.set, true ).height(), values
.expected
- 16, "test non-border-box outerHeight(" + units
+ ", true) by roundtripping" );
498 assert
.equal( el_bb_np
.width( values
.set ).width(), values
.expected
, "test border-box width and negative padding(" + units
+ ") by roundtripping" );
499 assert
.equal( el_bb_np
.innerWidth( values
.set ).width(), values
.expected
, "test border-box innerWidth and negative padding(" + units
+ ") by roundtripping" );
500 assert
.equal( el_bb_np
.outerWidth( values
.set ).width(), values
.expected
, "test border-box outerWidth and negative padding(" + units
+ ") by roundtripping" );
501 assert
.equal( el_bb_np
.outerWidth( values
.set, false ).width(), values
.expected
, "test border-box outerWidth and negative padding(" + units
+ ", false) by roundtripping" );
502 assert
.equal( el_bb_np
.outerWidth( values
.set, true ).width(), values
.expected
- 10, "test border-box outerWidth and negative padding(" + units
+ ", true) by roundtripping" );
504 assert
.equal( el_bb_np
.height( values
.set ).height(), values
.expected
, "test border-box height and negative padding(" + units
+ ") by roundtripping" );
505 assert
.equal( el_bb_np
.innerHeight( values
.set ).height(), values
.expected
, "test border-box innerHeight and negative padding(" + units
+ ") by roundtripping" );
506 assert
.equal( el_bb_np
.outerHeight( values
.set ).height(), values
.expected
, "test border-box outerHeight and negative padding(" + units
+ ") by roundtripping" );
507 assert
.equal( el_bb_np
.outerHeight( values
.set, false ).height(), values
.expected
, "test border-box outerHeight and negative padding(" + units
+ ", false) by roundtripping" );
508 assert
.equal( el_bb_np
.outerHeight( values
.set, true ).height(), values
.expected
- 10, "test border-box outerHeight and negative padding(" + units
+ ", true) by roundtripping" );
510 assert
.equal( el_np
.width( values
.set ).width(), values
.expected
, "test non-border-box width and negative padding(" + units
+ ") by roundtripping" );
511 assert
.equal( el_np
.innerWidth( values
.set ).width(), values
.expected
, "test non-border-box innerWidth and negative padding(" + units
+ ") by roundtripping" );
512 assert
.equal( el_np
.outerWidth( values
.set ).width(), values
.expected
, "test non-border-box outerWidth and negative padding(" + units
+ ") by roundtripping" );
513 assert
.equal( el_np
.outerWidth( values
.set, false ).width(), values
.expected
, "test non-border-box outerWidth and negative padding(" + units
+ ", false) by roundtripping" );
514 assert
.equal( el_np
.outerWidth( values
.set, true ).width(), values
.expected
- 10, "test non-border-box outerWidth and negative padding(" + units
+ ", true) by roundtripping" );
516 assert
.equal( el_np
.height( values
.set ).height(), values
.expected
, "test non-border-box height and negative padding(" + units
+ ") by roundtripping" );
517 assert
.equal( el_np
.innerHeight( values
.set ).height(), values
.expected
, "test non-border-box innerHeight and negative padding(" + units
+ ") by roundtripping" );
518 assert
.equal( el_np
.outerHeight( values
.set ).height(), values
.expected
, "test non-border-box outerHeight and negative padding(" + units
+ ") by roundtripping" );
519 assert
.equal( el_np
.outerHeight( values
.set, false ).height(), values
.expected
, "test non-border-box outerHeight and negative padding(" + units
+ ", false) by roundtripping" );
520 assert
.equal( el_np
.outerHeight( values
.set, true ).height(), values
.expected
- 10, "test non-border-box outerHeight and negative padding(" + units
+ ", true) by roundtripping" );
525 "window vs. large document",
526 "dimensions/documentLarge.html",
527 function( assert
, jQuery
, window
, document
) {
530 assert
.ok( jQuery( document
).height() > jQuery( window
).height(), "document height is larger than window height" );
531 assert
.ok( jQuery( document
).width() > jQuery( window
).width(), "document width is larger than window width" );
535 QUnit
.test( "allow modification of coordinates argument (gh-1848)", function( assert
) {
539 element
= jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
541 element
.offset( function( index
, coords
) {
547 offsetTop
= element
.offset().top
;
548 assert
.ok( Math
.abs( offsetTop
- 100 ) < 0.02,
549 "coordinates are modified (got offset.top: " + offsetTop
+ ")" );
552 QUnit
.test( "outside view position (gh-2836)", function( assert
) {
554 // This test ported from gh-2836 example
559 "<div id=div-gh-2836>",
567 stop
= assert
.async();
569 parent
= jQuery( html
);
570 parent
.appendTo( "#qunit-fixture" );
572 parent
.one( "scroll", function() {
573 var pos
= parent
.find( "div" ).eq( 3 ).position();
575 assert
.strictEqual( pos
.top
, -100 );
579 parent
.scrollTop( 400 );
582 QUnit
.test( "width/height on element with transform (gh-3193)", function( assert
) {
586 var $elem
= jQuery( "<div style='width: 200px; height: 200px; transform: scale(2);' />" )
587 .appendTo( "#qunit-fixture" );
589 assert
.equal( $elem
.width(), 200, "Width ignores transforms" );
590 assert
.equal( $elem
.height(), 200, "Height ignores transforms" );
593 QUnit
.test( "width/height on an inline element with no explicitly-set dimensions (gh-3571)", function( assert
) {
596 var $elem
= jQuery( "<span style='border: 2px solid black;padding: 1px;margin: 3px;'>Hello, I'm some text.</span>" ).appendTo( "#qunit-fixture" );
598 jQuery
.each( [ "Width", "Height" ], function( i
, method
) {
599 var val
= $elem
[ method
.toLowerCase() ]();
600 assert
.notEqual( val
, 0, method
+ " should not be zero on inline element." );
601 assert
.equal( $elem
[ "inner" + method
](), val
+ 2, "inner" + method
+ " should include padding" );
602 assert
.equal( $elem
[ "outer" + method
](), val
+ 6, "outer" + method
+ " should include padding and border" );
603 assert
.equal( $elem
[ "outer" + method
]( true ), val
+ 12, "outer" + method
+ "(true) should include padding, border, and margin" );
607 QUnit
.test( "width/height on an inline element with percentage dimensions (gh-3611)",
611 jQuery( "<div id='gh3611' style='width: 100px;'>" +
612 "<span style='width: 100%; padding: 0 5px'>text</span>" +
613 "</div>" ).appendTo( "#qunit-fixture" );
615 var $elem
= jQuery( "#gh3611 span" ),
616 actualWidth
= $elem
[ 0 ].getBoundingClientRect().width
,
617 marginWidth
= $elem
.outerWidth( true ),
618 borderWidth
= $elem
.outerWidth(),
619 paddingWidth
= $elem
.innerWidth(),
620 contentWidth
= $elem
.width();
622 assert
.equal( Math
.round( borderWidth
), Math
.round( actualWidth
),
623 ".outerWidth(): " + borderWidth
+ " approximates " + actualWidth
);
624 assert
.equal( marginWidth
, borderWidth
, ".outerWidth(true) matches .outerWidth()" );
625 assert
.equal( paddingWidth
, borderWidth
, ".innerWidth() matches .outerWidth()" );
626 assert
.equal( contentWidth
, borderWidth
- 10, ".width() excludes padding" );
630 QUnit
.test( "width/height on a table row with phantom borders (gh-3698)", function( assert
) {
633 jQuery( "<table id='gh3698' style='border-collapse: separate; border-spacing: 0;'><tbody>" +
634 "<tr style='margin: 0; border: 10px solid black; padding: 0'>" +
635 "<td style='margin: 0; border: 0; padding: 0; height: 42px; width: 42px;'></td>" +
637 "</tbody></table>" ).appendTo( "#qunit-fixture" );
639 var $elem
= jQuery( "#gh3698 tr" );
641 jQuery
.each( [ "Width", "Height" ], function( i
, method
) {
642 assert
.equal( $elem
[ "outer" + method
](), 42,
643 "outer" + method
+ " should match content dimensions" );
644 assert
.equal( $elem
[ "outer" + method
]( true ), 42,
645 "outer" + method
+ "(true) should match content dimensions" );
649 QUnit
.test( "interaction with scrollbars (gh-3589)", function( assert
) {
654 updater = function( adjustment
) {
655 return function( i
, old
) {
656 return old
+ adjustment
;
659 parent
= jQuery( "<div/>" )
660 .css( { position
: "absolute", width
: "1000px", height
: "1000px" } )
661 .appendTo( "#qunit-fixture" ),
662 fraction
= jQuery
.support
.boxSizingReliable() ?
663 jQuery( "<div style='width:4.5px;'/>" ).appendTo( parent
).width() % 1 :
667 size
= 100 + fraction
,
668 plainBox
= jQuery( "<div />" )
670 "box-sizing": "content-box",
671 position
: "absolute",
676 contentBox
= plainBox
679 border
: borderWidth
+ "px solid blue",
680 padding
: padding
+ "px"
682 borderBox
= contentBox
684 .css( { "box-sizing": "border-box" } ),
685 relativeBorderBox
= borderBox
687 .css( { position
: "relative" } ),
689 [ plainBox
[ 0 ], contentBox
[ 0 ], borderBox
[ 0 ], relativeBorderBox
[ 0 ] ]
690 ).appendTo( parent
),
692 // Support: IE 9 only
693 // Computed width seems to report content width even with "box-sizing: border-box", and
694 // "overflow: scroll" actually _shrinks_ the element (gh-3699).
696 borderBox
.clone().css( { overflow
: "auto" } ).appendTo( parent
)[ 0 ].offsetWidth
-
697 borderBox
[ 0 ].offsetWidth
;
699 if ( borderBoxLoss
> 0 ) {
700 borderBox
[ 0 ].style
.width
= ( size
+ borderBoxLoss
) + "px";
701 borderBox
[ 0 ].style
.height
= ( size
+ borderBoxLoss
) + "px";
704 for ( i
= 0; i
< 3; i
++ ) {
706 suffix
= " after increasing inner* by " + i
;
708 $boxes
.innerWidth( updater( i
) ).innerHeight( updater( i
) );
709 } else if ( i
=== 2 ) {
710 suffix
= " after increasing outer* by " + i
;
712 $boxes
.outerWidth( updater( i
) ).outerHeight( updater( i
) );
715 assert
.equal( plainBox
.innerWidth(), size
,
716 "plain content-box innerWidth includes scroll gutter" + suffix
);
717 assert
.equal( plainBox
.innerHeight(), size
,
718 "plain content-box innerHeight includes scroll gutter" + suffix
);
719 assert
.equal( plainBox
.outerWidth(), size
,
720 "plain content-box outerWidth includes scroll gutter" + suffix
);
721 assert
.equal( plainBox
.outerHeight(), size
,
722 "plain content-box outerHeight includes scroll gutter" + suffix
);
724 assert
.equal( contentBox
.innerWidth(), size
+ 2 * padding
,
725 "content-box innerWidth includes scroll gutter" + suffix
);
726 assert
.equal( contentBox
.innerHeight(), size
+ 2 * padding
,
727 "content-box innerHeight includes scroll gutter" + suffix
);
728 assert
.equal( contentBox
.outerWidth(), size
+ 2 * padding
+ 2 * borderWidth
,
729 "content-box outerWidth includes scroll gutter" + suffix
);
730 assert
.equal( contentBox
.outerHeight(), size
+ 2 * padding
+ 2 * borderWidth
,
731 "content-box outerHeight includes scroll gutter" + suffix
);
733 assert
.equal( borderBox
.innerWidth(), size
- 2 * borderWidth
,
734 "border-box innerWidth includes scroll gutter" + suffix
);
735 assert
.equal( borderBox
.innerHeight(), size
- 2 * borderWidth
,
736 "border-box innerHeight includes scroll gutter" + suffix
);
737 assert
.equal( borderBox
.outerWidth(), size
,
738 "border-box outerWidth includes scroll gutter" + suffix
);
739 assert
.equal( borderBox
.outerHeight(), size
,
740 "border-box outerHeight includes scroll gutter" + suffix
);
742 assert
.equal( relativeBorderBox
.innerWidth(), size
- 2 * borderWidth
,
743 "relative border-box innerWidth includes scroll gutter" + suffix
);
744 assert
.equal( relativeBorderBox
.innerHeight(), size
- 2 * borderWidth
,
745 "relative border-box innerHeight includes scroll gutter" + suffix
);
746 assert
.equal( relativeBorderBox
.outerWidth(), size
,
747 "relative border-box outerWidth includes scroll gutter" + suffix
);
748 assert
.equal( relativeBorderBox
.outerHeight(), size
,
749 "relative border-box outerHeight includes scroll gutter" + suffix
);
753 QUnit
.test( "outerWidth/Height for table cells and textarea with border-box in IE 11 (gh-4102)", function( assert
) {
755 var $table
= jQuery( "<table class='border-box' style='border-collapse: separate' />" ).appendTo( "#qunit-fixture" ),
756 $thead
= jQuery( "<thead />" ).appendTo( $table
),
757 $firstTh
= jQuery( "<th style='width: 200px;padding: 5px' />" ),
758 $secondTh
= jQuery( "<th style='width: 190px;padding: 5px' />" ),
759 $thirdTh
= jQuery( "<th style='width: 180px;padding: 5px' />" ),
761 // Support: Firefox 63, Edge 16-17, Android 8, iOS 7-11
762 // These browsers completely ignore the border-box and height settings
763 // The computed height is instead just line-height + border
764 // Either way, what we're doing in css.js is correct
765 $td
= jQuery( "<td style='height: 20px;padding: 5px;border: 1px solid;line-height:18px'>text</td>" ),
767 $tbody
= jQuery( "<tbody />" ).appendTo( $table
),
768 $textarea
= jQuery( "<textarea style='height: 0;padding: 2px;border: 1px solid;box-sizing: border-box' />" ).appendTo( "#qunit-fixture" );
770 jQuery( "<tr />" ).appendTo( $thead
).append( $firstTh
);
771 jQuery( "<tr />" ).appendTo( $thead
).append( $secondTh
);
772 jQuery( "<tr />" ).appendTo( $thead
).append( $thirdTh
);
773 jQuery( "<tr><td></td></tr>" ).appendTo( $tbody
).append( $td
);
775 assert
.strictEqual( $firstTh
.outerWidth(), 200, "First th has outerWidth 200." );
776 assert
.strictEqual( $secondTh
.outerWidth(), 200, "Second th has outerWidth 200." );
777 assert
.strictEqual( $thirdTh
.outerWidth(), 200, "Third th has outerWidth 200." );
779 // Support: Android 4.0-4.3 only
780 // Android Browser disregards td's box-sizing, treating it like it was content-box.
781 // Unlike in IE, offsetHeight shares the same issue so there's no easy way to workaround
782 // the issue without incurring high size penalty. Let's at least check we get the size
783 // as the browser sees it.
784 if ( /android 4\.[0-3]/i.test( navigator
.userAgent
) ) {
785 assert
.ok( [ 30, 32 ].indexOf( $td
.outerHeight() ) > -1,
786 "outerHeight of td with border-box should include padding." );
788 assert
.strictEqual( $td
.outerHeight(), 30, "outerHeight of td with border-box should include padding." );
790 assert
.strictEqual( $textarea
.outerHeight(), 6, "outerHeight of textarea with border-box should include padding and border." );