dom/html/test/test_bug613019.html
author Thomas Wisniewski <wisniewskit@gmail.com>
Sat, 06 Aug 2016 11:59:08 -0400
changeset 308655 e2bb8f329f10
child 310013 f4d0e045901e
permissions -rw-r--r--
Bug 613019 - Track whether the last input/textarea change was done interactively, and enable the commented-out maxLength tracking code. r=mrbkap

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=613019
-->
<head>
  <title>Test for Bug 613019</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613019">Mozilla Bug 613019</a>
<div id="content">
  <input type="text" maxlength="2" style="width:200px" value="Test">
  <textarea maxlength="2" style="width:200px">Test</textarea>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 613019 **/

function testInteractivityOfValidityStates(elem) {
  // verify that user interactivity is necessary for validity state to apply.
  is(elem.value, "Test", "Element has incorrect starting value.");
  is(elem.validity.tooLong, false, "Element should not be tooLong.");

  elem.focus();

  synthesizeKey("VK_BACK_SPACE", {});
  is(elem.value, "Tes", "Element value was not changed correctly.");
  is(elem.validity.tooLong, true, "Element should still be tooLong.");

  synthesizeKey("VK_BACK_SPACE", {});
  is(elem.value, "Te", "Element value was not changed correctly.");
  is(elem.validity.tooLong, false, "Element should no longer be tooLong.");

  elem.value = "Test";
  is(elem.validity.tooLong, false,
     "Element should not be tooLong after non-interactive value change.");
}

function test() {
  window.getSelection().removeAllRanges();
  testInteractivityOfValidityStates(document.querySelector("input[type=text]"));
  testInteractivityOfValidityStates(document.querySelector("textarea"));
  SimpleTest.finish();
}

window.onload = function() {
  SimpleTest.waitForExplicitFinish();
  setTimeout(test, 0);
};

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