Skip to content

Commit

Permalink
Bug 1442901 [wpt PR 9799] - Add first batch of tests for content chan…
Browse files Browse the repository at this point in the history
…ge selection update, a=testonly

Automatic update from web-platform-testsAdd first batch of tests for selection update

These tests already show differences between eg. Firefox and
Chrome, and show what seems to be browser bugs.

Follows whatwg/html#3472.

wpt-commits: 05d6e35a439546add8dc619c4641ae83551249f8
wpt-pr: 9799
wpt-commits: 05d6e35a439546add8dc619c4641ae83551249f8
wpt-pr: 9799
  • Loading branch information
emanchado authored and jgraham committed Mar 31, 2018
1 parent 73048b8 commit 3e240b1
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
10 changes: 10 additions & 0 deletions testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -331928,6 +331928,12 @@
{}
]
],
"html/semantics/forms/textfieldselection/selection-start-end-extra.html": [
[
"/html/semantics/forms/textfieldselection/selection-start-end-extra.html",
{}
]
],
"html/semantics/forms/textfieldselection/selection-start-end.html": [
[
"/html/semantics/forms/textfieldselection/selection-start-end.html",
Expand Down Expand Up @@ -564425,6 +564431,10 @@
"db63d0d1eedec810d4c7e1b38789be457e06e985",
"testharness"
],
"html/semantics/forms/textfieldselection/selection-start-end-extra.html": [
"d50596ef2b907db30e6121ba7a5d98c887cdc2b2",
"testharness"
],
"html/semantics/forms/textfieldselection/selection-start-end.html": [
"6bef6943accb6677e9f466df6cc5ad267b01680f",
"testharness"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<form id="form"><input id="form-input" type="text" value="abc" /></form>
<script>
// * Should we test setting the dirty flag in any way that isn't
// setting the value?
// * How to simulate users typing?

test(function() {
var el = document.createElement("textarea");
assert_equals(el.selectionStart, 0);
assert_equals(el.selectionEnd, 0);
el.defaultValue = "123";
assert_equals(el.value.length, 3);
assert_equals(el.selectionStart, 3);
assert_equals(el.selectionEnd, 3);
}, "Setting defaultValue in a textarea should move the cursor to the end");

test(function() {
var el = document.createElement("textarea");
el.value = "abcdef";
assert_equals(el.selectionStart, 6);
assert_equals(el.selectionEnd, 6);
el.defaultValue = "123";
assert_equals(el.value.length, 6);
assert_equals(el.selectionStart, 6);
assert_equals(el.selectionEnd, 6);
}, "Setting defaultValue in a textarea with a value should NOT make any difference");

test(function() {
var el = document.createElement("textarea");
el.appendChild(document.createTextNode("abcdef"));
assert_equals(el.selectionStart, 6);
assert_equals(el.selectionEnd, 6);
el.textContent = "abcdef123456";
assert_equals(el.selectionStart, 12);
assert_equals(el.selectionEnd, 12);
}, "Setting textContent in a textarea should move selection{Start,End} to the end");

test(function() {
var el = document.createElement("textarea");
el.appendChild(document.createTextNode("abcdef"));
assert_equals(el.selectionStart, 6);
assert_equals(el.selectionEnd, 6);
el.appendChild(document.createTextNode("123456"));
assert_equals(el.selectionStart, 12);
assert_equals(el.selectionEnd, 12);
}, "Adding children to a textarea should move selection{Start,End} to the end");

test(function() {
var el = document.createElement("textarea");
el.appendChild(document.createTextNode("abcdef"));
el.appendChild(document.createTextNode("123"));
assert_equals(el.selectionStart, 9);
assert_equals(el.selectionEnd, 9);

el.removeChild(el.firstChild);
assert_equals(el.selectionStart, 3);
assert_equals(el.selectionEnd, 3);
}, "Removing children from a textarea should update selection{Start,End}");

test(function() {
var el = document.createElement("textarea");
el.textContent = "abcdef\nwhatevs";
el.selectionStart = 3;
el.selectionEnd = 5;

el.textContent = "abcdef\r\nwhatevs";
assert_equals(el.selectionStart, 3);
assert_equals(el.selectionEnd, 5);
}, "Setting the same value (with different newlines) in a textarea should NOT update selection{Start,End}");

test(function() {
var el = document.createElement("textarea");
el.defaultValue = "123";
assert_equals(el.value.length, 3);
assert_equals(el.selectionStart, 3);
assert_equals(el.selectionEnd, 3);
el.value = "12";
assert_equals(el.value.length, 2);
assert_equals(el.selectionStart, 2);
assert_equals(el.selectionEnd, 2);
}, "Setting value to a shorter string than defaultValue should correct the cursor position");

test(function() {
var el = document.createElement("input");
el.type = "text";
el.value = "http://example.com ";
assert_equals(el.selectionStart, 21);
assert_equals(el.selectionEnd, 21);
el.type = "url";
assert_equals(el.selectionStart, 18);
assert_equals(el.selectionEnd, 18);
}, "Shortening value by turning the input type into 'url' should correct selection{Start,End}");

test(function() {
var el = document.createElement("input");
el.type = "text";
el.value = "#123456xx";
assert_equals(el.selectionStart, 9);
assert_equals(el.selectionEnd, 9);
el.type = "color";
el.type = "text";
assert_equals(el.selectionStart, 7);
assert_equals(el.selectionEnd, 7);
}, "Shortening value by turning the input type into 'color' and back to 'text' should correct selection{Start,End}");

test(function() {
var form = document.getElementById("form");
var el = document.getElementById("form-input");

el.value = "abcde";
assert_equals(el.value.length, 5);
form.reset();
assert_equals(el.value.length, 3);
assert_equals(el.selectionStart, 3);
assert_equals(el.selectionEnd, 3);
}, "Resetting a value to a shorter string than defaultValue should correct the cursor position");
</script>

0 comments on commit 3e240b1

Please sign in to comment.