8000 CSS:Tests: Fix tests & support tests under CSS Zoom · mgol/jquery@f163b3d · GitHub
[go: up one dir, main page]

Skip to content

Commit f163b3d

Browse files
committed
CSS:Tests: Fix tests & support tests under CSS Zoom
Firefox 126+ implements CSS zoom in a way it affects width computed style very slightly (`100.008px` instead of `100px`); accept that difference. Also, skip the width setter under zoom test in Firefox 126 completely - that version has CSS zoom affecting `offsetWidth` values. This has been fixed in Firefox 127 so it's not worth working around it. Add a test for support tests resolving the same under CSS zoom & without one. That test uncovered Chrome failing the `reliableTrDimensions` support test under zoom; the test has been fixed. Fixes jquerygh-5489 Closes jquerygh-5496 Ref jquerygh-5495
1 parent 37bded3 commit f163b3d

File tree

4 files changed

+74
-5
lines changed

4 files changed

+74
-5
lines changed

src/css/support.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,22 @@ define( [
151151
}
152152

153153
trStyle = window.getComputedStyle( tr );
154-
reliableTrDimensionsVal = ( parseInt( trStyle.height, 10 ) +
155-
parseInt( trStyle.borderTopWidth, 10 ) +
156-
parseInt( trStyle.borderBottomWidth, 10 ) ) === tr.offsetHeight;
154+
window.console.log(
155+
[
156+
trStyle.height,
157+
trStyle.borderTopWidth,
158+
trStyle.borderBottomWidth
159+
],
160+
[
161+
Math.round( parseFloat( trStyle.height ) ),
162+
Math.round( parseFloat( trStyle.borderTopWidth ) ),
163+
Math.round( parseFloat( trStyle.borderBottomWidth ) )
164+
],
165+
tr.offsetHeight
166+
);
167+
reliableTrDimensionsVal = ( Math.round( parseFloat( trStyle.height ) ) +
168+
Math.round( parseFloat( trStyle.borderTopWidth ) ) +
169+
Math.round( parseFloat( trStyle.borderBottomWidth ) ) ) === tr.offsetHeight;
157170

158171
documentElement.removeChild( table );
159172
}

test/data/support/zoom.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<style>
6+
html {
7+
zoom: 2.1;
8+
}
9+
</style>
10+
</head>
11+
<body>
12+
<div>
13+
<script src="../../jquery.js"></script>
14+
<script src="../iframeTest.js"></script>
15+
<script src="getComputedSupport.js"></script>
16+
</div>
17+
<script>
18+
startIframeTest(
19+
getComputedStyle( document.documentElement ),
20+
getComputedSupport( jQuery.support )
21+
);
22+
</script>
23+
</body>
24+
</html>

test/unit/css.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,20 @@ testIframe(
13961396
"css/cssWidthBrowserZoom.html",
13971397
function( assert, jQuery, window, document, widthBeforeSet, widthAfterSet ) {
13981398
assert.expect( 2 );
1399-
assert.strictEqual( widthBeforeSet, "100px", "elem.css('width') works correctly with browser zoom" );
1400-
assert.strictEqual( widthAfterSet, "100px", "elem.css('width', val) works correctly with browser zoom" );
1399+
1400+
// Support: Firefox 126+
1401+
// Newer Firefox implements CSS zoom in a way it affects
1402+
// those values slightly.
1403+
assert.ok( /^100(?:|\.0\d*)px$/.test( widthBeforeSet ), "elem.css('width') works correctly with browser zoom" );
1404+
1405+
// Support: Firefox 126 only
1406+
// In Firefox 126 only, CSS zoom affects `offsetWidth`. Since the issue
1407+
// is fixed in v127, let's just skip the test in v126.
1408+
if ( /\bfirefox\/126\.\d\b/i.test( navigator.userAgent ) ) {
1409+
assert.ok( true, "elem.css('width', val) works incorrectly with browser zoom in Firefox 126 and we accept that" );
1410+
} else {
1411+
assert.ok( /^100(?:|\.0\d*)px$/.test( widthAfterSet ), "elem.css('width', val) works correctly with browser zoom" );
1412+
}
14011413
}
14021414
);
14031415

test/unit/support.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ testIframe(
6666
}
6767
);
6868

69+
testIframe(
70+
"Verify correctness of support tests with CSS zoom on the root element",
71+
"support/zoom.html",
72+
function( assert, jQuery, window, document, htmlStyle, support ) {
73+
assert.expect( 1 );
74+
75+
// Support: Firefox 126 only
76+
// In Firefox 126 only, CSS zoom affects `offsetWidth`, causing
77+
// the `scrollboxSize` support test to fail. Accept that.
78+
if ( /\bfirefox\/126\.\d\b/i.test( navigator.userAgent ) ) {
79+
assert.deepEqual( jQuery.extend( {}, support ),
80+
jQuery.extend( {}, computedSupport, { scrollboxSize: false } ),
81+
"Same support properties except for `scrollboxSize`" );
82+
} else {
83+
assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
84+
"Same support properties" );
85+
}
86+
}
87+
);
88+
6989
( function() {
7090
var browserKey, expected,
7191
userAgent = window.navigator.userAgent,

0 commit comments

Comments
 (0)
0