Adding tests with DRY coding technique

This commit is contained in:
paavininanda 2018-02-15 01:34:58 +05:30
parent b1d3d6f632
commit 06f0ad1be7
2 changed files with 19 additions and 26 deletions

View file

@ -558282,7 +558282,7 @@
"support" "support"
], ],
"html/semantics/forms/textfieldselection/defaultSelection.html": [ "html/semantics/forms/textfieldselection/defaultSelection.html": [
"c9568da864127d49974b970809312c953fb347b1", "f49a2316f73094a7a0b27d810453f40ef029636b",
"testharness" "testharness"
], ],
"html/semantics/forms/textfieldselection/original-id.json": [ "html/semantics/forms/textfieldselection/original-id.json": [

View file

@ -3,33 +3,26 @@
<title></title> <title></title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<textarea>g</textarea> <textarea>foo</textarea>
<input type="text" value="foo"> <input type="text" value="foo"></input>
</input>
<script> <script>
test(function() {
let textarea = document.querySelector('textarea');
assert_equals(textarea.selectionStart, 0);
assert_equals(textarea.selectionEnd, 0);
}, "Default selectionStart and selectionEnd for textarea");
test(function() { for (let el of [document.querySelector("textarea"), document.querySelector("input")]) {
let textarea = document.querySelector('input'); test(function() {
assert_equals(textarea.selectionStart, 0); assert_equals(el.selectionStart, 0);
assert_equals(textarea.selectionEnd, 0); assert_equals(el.selectionEnd, 0);
}, "Default selectionStart and selectionEnd for input"); }, `Default selectionStart and selectionEnd for ${el}`);
test(function() { test(function() {
let textarea = document.querySelector('textarea'); el.value="foo";
textarea.value="g"; assert_equals(el.selectionStart, 0);
assert_equals(textarea.selectionStart, 0); assert_equals(el.selectionEnd, 0);
assert_equals(textarea.selectionEnd, 0); }, `selectionStart and selectionEnd do not change when same value set again for ${el}`);
}, "selectionStart and selectionEnd do not change when same value set again");
test(function() { test(function() {
let textarea = document.querySelector('textarea'); el.value="Foo";
textarea.value="G"; assert_equals(el.selectionStart, 3);
assert_equals(textarea.selectionStart, 1); assert_equals(el.selectionEnd, 3);
assert_equals(textarea.selectionEnd, 1); }, `selectionStart and selectionEnd change when value changed to upper case for ${el}`);
}, "selectionStart and selectionEnd change when value changed to upper case"); }
</script> </script>