]> source.dussan.org Git - jquery.git/commitdiff
CSS:Tests: Fix tests & support tests under CSS Zoom (3.x version)
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 3 Jun 2024 16:15:39 +0000 (18:15 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Jun 2024 16:15:39 +0000 (18:15 +0200)
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 gh-5489
Closes gh-5496
Ref gh-5495

src/css/support.js
test/data/support/zoom.html [new file with mode: 0644]
test/unit/css.js
test/unit/support.js

index 8838f0bc1cc13a592459bd34bb0c9acc9497c869..0a730593d29e981ec2ae01bef34e3fd371ccd4be 100644 (file)
@@ -151,9 +151,9 @@ define( [
                                }
 
                                trStyle = window.getComputedStyle( tr );
-                               reliableTrDimensionsVal = ( parseInt( trStyle.height, 10 ) +
-                                       parseInt( trStyle.borderTopWidth, 10 ) +
-                                       parseInt( trStyle.borderBottomWidth, 10 ) ) === tr.offsetHeight;
+                               reliableTrDimensionsVal = ( Math.round( parseFloat( trStyle.height ) ) +
+                                       Math.round( parseFloat( trStyle.borderTopWidth ) ) +
+                                       Math.round( parseFloat( trStyle.borderBottomWidth ) ) ) === tr.offsetHeight;
 
                                documentElement.removeChild( table );
                        }
diff --git a/test/data/support/zoom.html b/test/data/support/zoom.html
new file mode 100644 (file)
index 0000000..318b834
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+       <meta charset="utf-8" />
+       <style>
+               html {
+                       zoom: 2.1;
+               }
+       </style>
+</head>
+<body>
+       <div>
+               <script src="../../jquery.js"></script>
+               <script src="../iframeTest.js"></script>
+               <script src="getComputedSupport.js"></script>
+       </div>
+       <script>
+               startIframeTest(
+                       getComputedStyle( document.documentElement ),
+                       getComputedSupport( jQuery.support )
+               );
+       </script>
+</body>
+</html>
index 2603e73d9b27ba65b8503a4b7513fd92cb792f87..851c5f68fcff4dadfa4adcb540b80acd43178500 100644 (file)
@@ -1396,8 +1396,20 @@ testIframe(
        "css/cssWidthBrowserZoom.html",
        function( assert, jQuery, window, document, widthBeforeSet, widthAfterSet ) {
                assert.expect( 2 );
-               assert.strictEqual( widthBeforeSet, "100px", "elem.css('width') works correctly with browser zoom" );
-               assert.strictEqual( widthAfterSet, "100px", "elem.css('width', val) works correctly with browser zoom" );
+
+               // Support: Firefox 126+
+               // Newer Firefox implements CSS zoom in a way it affects
+               // those values slightly.
+               assert.ok( /^100(?:|\.0\d*)px$/.test( widthBeforeSet ), "elem.css('width') works correctly with browser zoom" );
+
+               // Support: Firefox 126 only
+               // In Firefox 126 only, CSS zoom affects `offsetWidth`. Since the issue
+               // is fixed in v127, let's just skip the test in v126.
+               if ( /\bfirefox\/126\.\d\b/i.test( navigator.userAgent ) ) {
+                       assert.ok( true, "elem.css('width', val) works incorrectly with browser zoom in Firefox 126 and we accept that" );
+               } else {
+                       assert.ok( /^100(?:|\.0\d*)px$/.test( widthAfterSet ), "elem.css('width', val) works correctly with browser zoom" );
+               }
        }
 );
 
index 8ea87bab8054b74e0c0e2a7b3bec6f2c24770cba..0a65d29f3b83b273bc8e5464fbaff76b6f7f0c22 100644 (file)
@@ -66,6 +66,26 @@ testIframe(
        }
 );
 
+testIframe(
+       "Verify correctness of support tests with CSS zoom on the root element",
+       "support/zoom.html",
+       function( assert, jQuery, window, document, htmlStyle, support ) {
+               assert.expect( 1 );
+
+               // Support: Firefox 126 only
+               // In Firefox 126 only, CSS zoom affects `offsetWidth`, causing
+               // the `scrollboxSize` support test to fail. Accept that.
+               if ( /\bfirefox\/126\.\d\b/i.test( navigator.userAgent ) ) {
+                       assert.deepEqual( jQuery.extend( {}, support ),
+                               jQuery.extend( {}, computedSupport, { scrollboxSize: false } ),
+                               "Same support properties except for `scrollboxSize`" );
+               } else {
+                       assert.deepEqual( jQuery.extend( {}, support ), computedSupport,
+                               "Same support properties" );
+               }
+       }
+);
+
 ( function() {
        var browserKey, expected,
                userAgent = window.navigator.userAgent,