Bug 1385926 - Add a test to ensure that the selection is always collapsed to the end after setting the value of input and textarea elements using the DOM API; r=masayuki
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 31 Jul 2017 17:55:30 -0400
changeset 420874 6add1a4978edf718046d4b4ec8c28c09848b57ee
parent 420873 6e7e4865a47763f853d672567b08d3fcf443ac15
child 420875 51ffb9283f0c7c00e08eb8c39b33fbee218c370d
child 420900 c5e543b0dfaaf508c6f57816ee8dc2fb70ab2301
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1385926
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1385926 - Add a test to ensure that the selection is always collapsed to the end after setting the value of input and textarea elements using the DOM API; r=masayuki
testing/web-platform/tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
--- a/testing/web-platform/tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
+++ b/testing/web-platform/tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
@@ -87,9 +87,32 @@ for (var data of elemData) {
     el.selectionEnd = 6;
     el.setRangeText("xyz");
     el.defaultValue = "set range text";
     assert_equals(el.value, sometext.slice(0, 4) + "xyz" + sometext.slice(6),
                   "Calling setRangeText should set the value dirty flag");
   }, `value dirty flag behavior after setRangeText on ${data.desc}`);
 }
 
+for (var tag of ['input', 'textarea']) {
+  test(function() {
+    var el = document.createElement(tag);
+    document.body.appendChild(el);
+    this.add_cleanup(() => el.remove());
+    el.value = "";
+    assert_equals(el.selectionStart, el.value.length,
+                 "element.selectionStart should be value.length");
+    assert_equals(el.selectionEnd, el.value.length,
+                  "element.selectionEnd should be value.length");
+    el.value = "foo";
+    assert_equals(el.selectionStart, el.value.length,
+                 "element.selectionStart should be value.length");
+    assert_equals(el.selectionEnd, el.value.length,
+                  "element.selectionEnd should be value.length");
+    el.value = "foobar";
+    assert_equals(el.selectionStart, el.value.length,
+                 "element.selectionStart should be value.length");
+    assert_equals(el.selectionEnd, el.value.length,
+                  "element.selectionEnd should be value.length");
+  }, `selection is always collapsed to the end after setting values on ${tag}`);
+}
+
 </script>