2d.state.saverestore.textBaseline.html (2297B)
1 <!DOCTYPE html> 2 <!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. --> 3 <meta charset="UTF-8"> 4 <title>Canvas test: 2d.state.saverestore.textBaseline</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/html/canvas/resources/canvas-tests.js"></script> 8 <link rel="stylesheet" href="/html/canvas/resources/canvas-tests.css"> 9 10 <h1>2d.state.saverestore.textBaseline</h1> 11 12 <script> 13 14 test(t => { 15 const canvas = document.createElement('canvas'); 16 canvas.width = 300; 17 canvas.height = 150; 18 const ctx = canvas.getContext('2d'); 19 20 const old = ctx.textBaseline; 21 ctx.save(); 22 ctx.textBaseline = "bottom"; 23 ctx.restore(); 24 _assertSame(ctx.textBaseline, old, "ctx.textBaseline", "old"); 25 }, "save()/restore() restores textBaseline, for a canvas of size (300, 150)."); 26 27 test(t => { 28 const canvas = document.createElement('canvas'); 29 canvas.width = 300; 30 canvas.height = 150; 31 const ctx = canvas.getContext('2d'); 32 33 ctx.textBaseline = "bottom"; 34 const old = ctx.textBaseline; 35 // We're not interested in failures caused by get(set(x)) != x (e.g. 36 // from rounding), so compare against `old` instead of "bottom". 37 ctx.save(); 38 _assertSame(ctx.textBaseline, old, "ctx.textBaseline", "old"); 39 ctx.restore(); 40 }, "save() does not modify textBaseline, for a canvas of size (300, 150)."); 41 42 test(t => { 43 const canvas = document.createElement('canvas'); 44 canvas.width = 0; 45 canvas.height = 0; 46 const ctx = canvas.getContext('2d'); 47 48 const old = ctx.textBaseline; 49 ctx.save(); 50 ctx.textBaseline = "bottom"; 51 ctx.restore(); 52 _assertSame(ctx.textBaseline, old, "ctx.textBaseline", "old"); 53 }, "save()/restore() restores textBaseline, for a canvas of size (0, 0)."); 54 55 test(t => { 56 const canvas = document.createElement('canvas'); 57 canvas.width = 0; 58 canvas.height = 0; 59 const ctx = canvas.getContext('2d'); 60 61 ctx.textBaseline = "bottom"; 62 const old = ctx.textBaseline; 63 // We're not interested in failures caused by get(set(x)) != x (e.g. 64 // from rounding), so compare against `old` instead of "bottom". 65 ctx.save(); 66 _assertSame(ctx.textBaseline, old, "ctx.textBaseline", "old"); 67 ctx.restore(); 68 }, "save() does not modify textBaseline, for a canvas of size (0, 0)."); 69 70 </script>