[common][canvas-html5] Sync test case with web-platform-tests/wpt. 03/320803/2
authorYang Hehua <hehua.yang@samsung.com>
Fri, 7 Mar 2025 09:26:21 +0000 (17:26 +0800)
committerYang Hehua <hehua.yang@samsung.com>
Fri, 7 Mar 2025 09:47:20 +0000 (17:47 +0800)
Change-Id: I06ea9694d048167708df63778fce3fd0ec684e47
Signed-off-by: Yang Hehua <hehua.yang@samsung.com>
common/tct-canvas-html5-tests/canvas/canvas2d_measureText_basic.html
common/tct-canvas-html5-tests/canvas/w3c/COPYING

index 21a0f058bee3b096b9eba4028e6cfe904d3955f9..45469e21b5b3455c610a65b824ed31e4df59578c 100755 (executable)
@@ -29,21 +29,44 @@ Authors:
     <script src="../resources/testharness.js"></script>
     <script src="../resources/testharnessreport.js"></script>
     <script src="support/canvas.js"></script>
+    <script src="common/canvas-tests.js"></script>
+
+    <style>
+      @font-face {
+        font-family: CanvasTest;
+        src: url("fonts/CanvasTest.ttf");
+      }
+    </style>
   </head>
   <body>
     <div id="log"></div>
+    <p class="desc">The width of character is same as font used</p>
+    <span style="font-family: CanvasTest; position: absolute; visibility: hidden">A</span>
+    <p class="output">Actual output:</p>
+
     <canvas id="canvas" width="300" height="200" style="border:1px solid #c3c3c3; font-kerning:none;">
       Your browser does not support the canvas element.
     </canvas>
+
     <script>
-    test( function () {
+      promise_test(async t => {
         var canvas = document.getElementById("canvas");
-        ctx = canvas.getContext("2d");
-        tm1 = ctx.measureText("f");
-        tm = ctx.measureText("fff")
-        // font shape has been changed, UX changed font file on some TV branch
-        assert_equals(parseFloat(tm.width.toFixed(4)), parseFloat((tm1.width * 3).toFixed(4)), "the fixed 4 float is not equal");
-      });
+        var ctx = canvas.getContext("2d");
+
+        await document.fonts.ready;
+        ctx.font = '50px CanvasTest';
+        var tm = ctx.measureText('A');
+        if (tm.width === null || tm.width === undefined) {
+          throw new Error('measureText returned null or undefined');
+        }
+        _assertSame(tm.width, 50, "ctx.measureText('A').width", "50");
+        _assertSame(ctx.measureText('A').width, 50, "ctx.measureText('A').width", "50");
+        _assertSame(ctx.measureText('AA').width, 100, "ctx.measureText('AA').width", "100");
+        _assertSame(ctx.measureText('ABCD').width, 200, "ctx.measureText('ABCD').width", "200");
+
+        ctx.font = '100px CanvasTest';
+        _assertSame(ctx.measureText('A').width, 100, "ctx.measureText('A').width", "100");
+      }, "The width of character is same as font used");
     </script>
   </body>
 </html>
index 1248f2fab07fd5686242d4f0d957e599a94e65ef..dafe6017174a95377165f8e190214a5f2728c57c 100755 (executable)
@@ -83,6 +83,11 @@ canvas_complexshapes_ispointInpath_001.htm
 
   + <div id="log"></div>
 
+
+canvas/canvas2d_measureText_basic.html
+  changes come from: https://github.com/web-platform-tests/wpt/blob/master/html/canvas/element/text/2d.text.measure.width.basic.html
+
+
 These tests are copyright by W3C and/or the author listed in the test
 file. The tests are dual-licensed under the W3C Test Suite License:
 http://www.w3.org/Consortium/Legal/2008/04-testsuite-license