layout/base/tests/test_font_inflation_reftests.html
author Scott Johnson <sjohnson@mozilla.com>
Fri, 02 Mar 2012 11:25:33 -0600
changeset 88355 e4006a8627b6b3981663689577629d8c748bb75a
parent 85842 6d180635060d2f324fdace497c98bad8fea91a23
child 90543 164c27136716da933ab0f7cd5d16adeccc492d16
permissions -rw-r--r--
Bug 705446: Disable font inflation for preformatted text. [r=dbaron]

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=627842
-->
<head>
  <title>Font size inflation reftests</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style type="text/css">
    canvas { border: 1px solid green }
  </style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=627842">Mozilla Bug 627842</a>
<pre id="test">
<script type="application/javascript; version=1.7">

/** Test for font size inflation **/

var gTests = [
  // IMPORTANT NOTE: For these tests, the test and reference are not
  // snapshotted in the same way.  The REFERENCE (second file) is
  // snapshotted with no unusual pref settings, whereas the TEST (first
  // file) has font inflation set to 15 em per line.


  "== text-1.html text-1-ref.html",
  "== text-2.html text-2-ref.html",
  "== text-3.html text-3-ref.html",
  "== text-4.html text-4-ref.html",
  "== decoration-1.html decoration-1-ref.html",
  "== bullet-1.html bullet-1-ref.html",
  "== bullet-2.html bullet-2-ref.html",
  "== input-text-1.html input-text-1-ref.html",
  "== input-text-2.html input-text-2-ref.html",
  "== input-text-3.html input-text-3-ref.html",
  "== textarea-1.html textarea-1-ref.html",
  "== textarea-2.html textarea-2-ref.html",
  "== textarea-3.html textarea-3-ref.html",
  "== css-transform-1.html css-transform-1-ref.html",
  "== css-transform-2.html css-transform-2-ref.html",
  "== container-with-clamping.html container-with-clamping-ref.html",
  "!= video-1.html about:blank", // crashtest
  "== intrinsic-min-1.html intrinsic-min-1-ref.html",
  "== intrinsic-max-1.html intrinsic-max-1-ref.html",
  "== intrinsic-fit-1a.html intrinsic-fit-1a-ref.html",
  "== intrinsic-fit-1b.html intrinsic-fit-1b-ref.html",
  "== intrinsic-fit-1c.html intrinsic-fit-1c-ref.html",
  "== intrinsic-fit-2a.html intrinsic-fit-1a-ref.html",
  "== intrinsic-fit-2b.html intrinsic-fit-1b-ref.html",
  "== intrinsic-fit-2c.html intrinsic-fit-1c-ref.html",
  "== select-listbox-1.html select-listbox-1-ref.html",
  "!= select-listbox-1.html select-listbox-1.html",
  "== select-combobox-1.html select-combobox-1-ref.html",
  "!= select-combobox-1.html select-combobox-1.html",
  "== select-listbox-2.html select-listbox-2-ref.html",
  "!= select-listbox-2.html select-listbox-2.html",
  "== select-combobox-2.html select-combobox-2-ref.html",
  "!= select-combobox-2.html select-combobox-2.html",
  "!= input-checkbox.html input-checkbox.html",
  "!= input-radio.html input-radio.html",
  "== disable-fontinfl-on-mobile.html disable-fontinfl-on-mobile-ref.html",
  "== disable-fontinfl-on-mobile-2.html disable-fontinfl-on-mobile-ref.html",
  "== disable-fontinfl-on-mobile-3.html disable-fontinfl-on-mobile-ref.html",
  "== disable-fontinfl-on-mobile-4.html disable-fontinfl-on-mobile-ref.html",
  "== preformatted-text.html preformatted-text-ref.html",
];

// Maintain a reference count of how many things we're waiting for until
// we can say the tests are done.
var gDelayCount = 0;
function AddFinishDependency()
  { ++gDelayCount; }
function RemoveFinishDependency()
  { if (--gDelayCount == 0) nextPhase(); }

function takeSnapshot(iframe_element)
{
  return snapshotWindow(iframe_element.contentWindow, false);
}

function startIframe(url)
{
  AddFinishDependency();
  var element = document.createElement("iframe");
  element.addEventListener("load", handleLoad, false);
  // smaller than normal reftests, but enough for these
  element.setAttribute("style", "width: 600px; height: 100px");
  element.src = "font-inflation/" + url;
  document.body.appendChild(element);
  function handleLoad(event)
  {
    RemoveFinishDependency();
  }
  return element;
}

SimpleTest.waitForExplicitFinish();

var gPhase = 0;

function nextPhase() {
  switch (gPhase) {
    case 0:
      SpecialPowers.setIntPref("font.size.inflation.emPerLine", 15);
      for (var i = 0; i < gTests.length; ++i) {
        let splitData = gTests[i].split(" ");
        let testData =
          { op: splitData[0], test: splitData[1], reference: splitData[2] };
        gTests[i] = testData;
        testData.testframe = startIframe(testData.test);
      }
      break;
    case 1:
      for (var i = 0; i < gTests.length; ++i) {
        var testData = gTests[i];
        testData.testshot = takeSnapshot(testData.testframe);
        testData.testframe.parentNode.removeChild(testData.testframe);
      }
      SpecialPowers.setIntPref("font.size.inflation.emPerLine", 0);
      for (var i = 0; i < gTests.length; ++i) {
        var testData = gTests[i];
        testData.refframe = startIframe(testData.reference);
      }
      break;
    case 2:
      for (var i = 0; i < gTests.length; ++i) {
        var testData = gTests[i];
        testData.refshot = takeSnapshot(testData.refframe);
        testData.refframe.parentNode.removeChild(testData.refframe);
        assertSnapshots(testData.testshot, testData.refshot,
                        testData.op == "==",
                        testData.test, testData.reference);
      }
      SimpleTest.finish();
      return;
  }
  ++gPhase;
}

nextPhase();

</script>
</pre>
</body>
</html>