content/canvas/test/test_2d.imageSmoothing.html
author L. David Baron <dbaron@dbaron.org>
Wed, 06 May 2009 13:46:04 -0700
changeset 28048 8f7b73d88f6bbedec99c6c8ef48b243ab922d05c
parent 20227 c6e54a6530ec542a08e6660cd2d2da4193ea756b
permissions -rw-r--r--
Switch HTML mochitests from using MochiKit.js to packed.js. (Bug 490955) r=sayrer

<!DOCTYPE HTML>
<html>
<head>
<title>Canvas test: 2d.imageRenderingQuality</title>
<script src="/MochiKit/packed.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript">

var _deferred = false;

function setup() {
  var c2 = document.getElementById("c2");
  var cx2 = c2.getContext("2d");

  cx2.fillStyle = "red";
  cx2.fillRect(0, 0, 2, 2);

  cx2.fillStyle = "rgb(0,255,0)";
  cx2.fillRect(0, 0, 1, 1);
}

function f() {
  setup();

  var c = document.getElementById("c");
  var c2 = document.getElementById("c2");

  var cx = c.getContext("2d");

  ok(cx.mozImageSmoothingEnabled == true, "initial mozImageSmoothingEnabled is true");

  // check that mozImageSmoothingEnabled is part of the context
  cx.save();
  cx.mozImageSmoothingEnabled = false;
  ok(cx.mozImageSmoothingEnabled == false, "mozImageSmoothingEnabled is false after setting");
  cx.restore();
  ok(cx.mozImageSmoothingEnabled == true, "mozImageSmoothingEnabled is true after restore");

  // check that false works
  cx.mozImageSmoothingEnabled = false;

  cx.scale(10,10);
  cx.drawImage(c2, 0, 0);

  // this should be all red
  var data = cx.getImageData(9, 9, 1, 1);
  var pixels = data.data;
  ok (pixels[0] == 0 &&
      pixels[1] == 255 &&
      pixels[2] == 0 &&
      pixels[3] == 255,
      "pixel is " + pixels.toSource() + " (expected [0,255,0,255])");

  if (!_deferred) SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
MochiKit.DOM.addLoadEvent(f);
</script>
</head>
<body>
<canvas id="c" width="10" height="10"></canvas><br>
<canvas style="visibility: hidden" id="c2" width="2" height="2"></canvas>
</body>
</html>