tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

2d.state.saverestore.imageSmoothingEnabled.html (1642B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>CanvasRenderingContext2D imageSmoothingEnabled save/restore test</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#image-smoothing">
      7 <script>
      8 function createTestImage() {
      9  var image = document.createElement('canvas');
     10  var imgctx = image.getContext('2d');
     11  imgctx.fillStyle = "#F00";
     12  imgctx.fillRect(0, 0, 2, 2);
     13  imgctx.fillStyle = "#0F0";
     14  imgctx.fillRect(0, 0, 1, 1);
     15  return image;
     16 }
     17 
     18 test(function() {
     19  var ctx = document.createElement('canvas').getContext('2d');
     20  ctx.save();
     21  ctx.imageSmoothingEnabled = false;
     22  ctx.restore();
     23  assert_equals(ctx.imageSmoothingEnabled, true);
     24 }, "Test that restore() undoes any modifications to imageSmoothingEnabled.");
     25 
     26 test(function() {
     27  var ctx = document.createElement('canvas').getContext('2d');
     28  ctx.imageSmoothingEnabled = false;
     29  var old = ctx.imageSmoothingEnabled;
     30  ctx.save();
     31  assert_equals(ctx.imageSmoothingEnabled, old);
     32  ctx.restore();
     33 }, "Test that save() doesn't modify the values of imageSmoothingEnabled.");
     34 
     35 test(function() {
     36  var ctx = document.createElement('canvas').getContext('2d');
     37  ctx.imageSmoothingEnabled = false;
     38  ctx.save();
     39  ctx.imageSmoothingEnabled = true;
     40  ctx.restore();
     41  var image = createTestImage();
     42  ctx.scale(10, 10);
     43  ctx.drawImage(image, 0, 0);
     44  var pixels = ctx.getImageData(0, 0, 1, 1).data;
     45  assert_array_equals(pixels, [0, 255, 0, 255]);
     46 }, "Test that restoring actually changes smoothing and not just the attribute value.");
     47 </script>