summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_textarea_set_value_no_scroll.html
blob: 8c3855960b020df04b8af7a49bb293be3ab60dca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=829606
-->
<head>
  <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.
   */

  SimpleTest.waitForExplicitFinish();

  var gTestRunner = null;

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

    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() {
      sendString('f');

      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;
        element.blur();

        gTestRunner.next();
      });
    }, 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';
    document.getElementById('content').appendChild(textarea);

    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() {
      gTestRunner.next();
    }, 0);
  }

  function* runTest()
  {
    test('input');
    yield undefined;
    test('textarea');
    yield undefined;
    testCorrectUpdateOnScroll();
    yield undefined;
    SimpleTest.finish();
  }

  gTestRunner = runTest();

  SimpleTest.waitForFocus(function() {
    gTestRunner.next();
  });;

  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=829606">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;'>
</div>
<pre id="test">
</pre>
</body>
</html>