dom/base/test/test_bug682592.html
author Kris Maglione <maglione.k@gmail.com>
Mon, 12 Aug 2019 12:56:25 -0700
changeset 488077 4b826e607ca87939b656b62836721973c67dac71
parent 469641 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Bug 1573254: Part 2 - Update tests to await snapshotWindow when necessary. r=mccr8 This fixes several tests which snapshot remote windows under Fission. It also changes some other arbitrary tests that don't use remote windows, which I changed before I gave up on having an always-async API. Differential Revision: https://phabricator.services.mozilla.com/D41630

<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=682592
-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
    <title>Test for bug 682592</title>
    <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
<iframe id="iframe-ref"></iframe>
<iframe id="iframe-test"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 682592 **/

/* 
   We want to check that bidi is detected correctly. So, we have a reference
   document where ltr is set explicitely with <bdo> element. Then, we compare
   it with test document.

   In mozilla, once bidi has been detected in a document, document always
   consider it's in bidi mode. So, if one fragment enables bidi correctly, and
   we create or update a fragment in the same document, that operation may not
   enable bidi by itself, but it will not be detected. So, we need to have new
   document for each test.

   So, instead of many diferent reftests, this mochitest implements a
   reftest-like. It creates reference text fragments in reference iframe, test
   text fragments in test iframe, and compare the documents. Then, it reloads
   test iframe. Reference iframe does not need to be reloaded between tests.
   It's ok (and maybe, desired) to keep bidi always enabled in that document. 
*/

SimpleTest.waitForExplicitFinish();
SimpleTest.requestLongerTimeout(3);
if (navigator.platform.startsWith("Linux arm")) { /* bugs 982875, 999429 */
  SimpleTest.expectAssertions(0, 4);
}

var page = `<!DOCTYPE html>
<html><meta charset='UTF-8'><body><p id="content"></p></body></html>`;
var refFrame = document.getElementById("iframe-ref")
var testFrame = document.getElementById("iframe-test");

refFrame.addEventListener("load", function() {
  testFrame.addEventListener("load", async function() {
    let {done} = tests.next();
    if (!done) {
      ok(compareSnapshots(await snapshotWindow(testFrame.contentWindow), 
                          await snapshotWindow(refFrame.contentWindow), true)[0], 
         "bidi is not detected correctly");

      testFrame.contentWindow.location.reload();
    } else {
      SimpleTest.finish();
    }
  });
  testFrame.srcdoc = page;
});
refFrame.srcdoc = page;

var rtl = "עִבְרִית";
var non8bit =  "ʃ";
var is8bit = "a";

// concats aStr aNumber of times
function strMult(aStr, aNumber) {
  if (aNumber === 0) {
    return "";
  }
  return strMult(aStr, aNumber - 1) + aStr;
}

function* runTests () {
  var ltr = "", prefix = null;
  var refContainer = refFrame.contentDocument.getElementById('content');
  var testContainer, textNode;
  var i = 0;

  // 8bit chars + bidi
  for (i = 0; i <= 16; i++) {
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    testContainer.innerHTML = ltr + rtl;
    yield undefined;
  }

  // non-8bit char + 8bit chars + bidi
  for (i = 0; i <= 16; i++) {
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    testContainer.innerHTML = ltr + rtl;
    yield undefined;
  }

  // appendData
  for (i = 0; i <= 16; i++) {
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode("");
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  for (i = 0; i <= 16; i++) {
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode("");
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  // appendData with 8bit prefix
  for (i = 0; i <= 16; i++) {
    prefix = is8bit;
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  for (i = 0; i <= 16; i++) {
    prefix = is8bit;
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  // appendData with non-8bit prefix
  for (i = 0; i <= 16; i++) {
    prefix = non8bit;
    ltr = strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }

  for (i = 0; i <= 16; i++) {
    prefix = non8bit;
    ltr = non8bit + strMult(is8bit, i);
    refContainer.innerHTML = prefix + ltr + '<bdo dir="rtl">' + rtl + '</bdo>';
    testContainer = testFrame.contentDocument.getElementById('content');
    textNode = document.createTextNode(prefix);
    testContainer.appendChild(textNode);
    textNode.appendData(ltr + rtl);
    yield undefined;
  }
};

var tests = runTests();

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