author Kris Maglione <>
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:

  <meta charset="utf-8">
  <title>Test for Bug 829606</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript">

  /** Test for Bug 829606 **/
   * This test checks that setting .value on an text field (input or textarea)
   * doesn't scroll the field to its beginning.


  var gTestRunner = null;

  async function test(aElementName)
    var element = document.getElementsByTagName(aElementName)[0];

    var baseSnapshot = await snapshotWindow(window);

    // This is a sanity check.
    var s2 = await snapshotWindow(window);
    var results = compareSnapshots(baseSnapshot, await snapshotWindow(window), true);
    ok(results[0], "sanity check: screenshots should be the same");

    element.selectionStart = element.selectionEnd = element.value.length;

    setTimeout(function() {

      requestAnimationFrame(async function() {
        var selectionAtTheEndSnapshot = await snapshotWindow(window);
        results = compareSnapshots(baseSnapshot, selectionAtTheEndSnapshot, false);
        ok(results[0], "after appending a character, string should have changed");

        element.value = element.value;
        var tmpSnapshot = await snapshotWindow(window);

        results = compareSnapshots(baseSnapshot, tmpSnapshot, false);
        ok(results[0], "re-settig the value should change nothing");

        results = compareSnapshots(selectionAtTheEndSnapshot, tmpSnapshot, true);
        ok(results[0], "re-settig the value should change nothing");

        element.selectionStart = element.selectionEnd = 0;
    }, 0);

  // This test checks that when a textarea has a long list of values and the
  // textarea's value is then changed, the values are shown correctly.
  async function testCorrectUpdateOnScroll()
    var textarea = document.createElement('textarea');
    textarea.rows = 5;
    textarea.cols = 10;
    textarea.value = 'a\nb\nc\nd';

    var baseSnapshot = await snapshotWindow(window);

    textarea.value = '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n';
    textarea.selectionStart = textarea.selectionEnd = textarea.value.length;

    var fullSnapshot = await snapshotWindow(window);
    var results = compareSnapshots(baseSnapshot, fullSnapshot, false);
    ok(results[0], "sanity check: screenshots should not be the same");

    textarea.value = 'a\nb\nc\nd';

    var tmpSnapshot = await snapshotWindow(window);
    results = compareSnapshots(baseSnapshot, tmpSnapshot, true);
    ok(results[0], "textarea view should look like the beginning");

    setTimeout(function() {;
    }, 0);

  function* runTest()
    yield undefined;
    yield undefined;
    yield undefined;

  gTestRunner = runTest();

  SimpleTest.waitForFocus(function() {;

<a target="_blank" href="">Mozilla Bug 829606</a>
<p id="display"></p>
<div id="content">
  <textarea rows='1' cols='5' style='-moz-appearance:none;'>this is a \n long text</textarea>
  <input size='5' value="this is a very long text" style='-moz-appearance:none;'>
<pre id="test">