Correct default Selectionstart and SelectionEnd

This commit is contained in:
paavininanda 2018-02-06 22:33:12 +05:30
parent e19bab84cf
commit b2c1f89b93
8 changed files with 144 additions and 87 deletions

View file

@ -27,7 +27,7 @@ fn test_set_content_ignores_max_length() {
Lines::Single, DOMString::from(""), DummyClipboardContext::new(""), Some(1), None, SelectionDirection::None
);
textinput.set_content(DOMString::from("mozilla rocks"));
textinput.set_content(DOMString::from("mozilla rocks"), true);
assert_eq!(textinput.get_content(), DOMString::from("mozilla rocks"));
}
@ -492,7 +492,7 @@ fn test_textinput_set_content() {
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
assert_eq!(textinput.get_content(), "abc\nde\nf");
textinput.set_content(DOMString::from("abc\nf"));
textinput.set_content(DOMString::from("abc\nf"), true);
assert_eq!(textinput.get_content(), "abc\nf");
assert_eq!(textinput.edit_point.line, 0);
@ -500,7 +500,7 @@ fn test_textinput_set_content() {
textinput.adjust_horizontal(3, Selection::Selected);
assert_eq!(textinput.edit_point.line, 0);
assert_eq!(textinput.edit_point.index, 3);
textinput.set_content(DOMString::from("de"));
textinput.set_content(DOMString::from("de"), true);
assert_eq!(textinput.get_content(), "de");
assert_eq!(textinput.edit_point.line, 0);
assert_eq!(textinput.edit_point.index, 2);
@ -637,6 +637,10 @@ fn test_textinput_unicode_handling() {
fn test_selection_bounds() {
let mut textinput = text_input(Lines::Single, "abcdef");
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_origin_or_edit_point());
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_start());
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_end());
textinput.set_selection_range(2, 5, SelectionDirection::Forward);
assert_eq!(TextPoint { line: 0, index: 2 }, textinput.selection_origin_or_edit_point());
assert_eq!(TextPoint { line: 0, index: 2 }, textinput.selection_start());

View file

@ -328172,6 +328172,12 @@
{}
]
],
"html/semantics/forms/textfieldselection/defaultSelection.html": [
[
"/html/semantics/forms/textfieldselection/defaultSelection.html",
{}
]
],
"html/semantics/forms/textfieldselection/select-event.html": [
[
"/html/semantics/forms/textfieldselection/select-event.html",
@ -558275,6 +558281,10 @@
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"support"
],
"html/semantics/forms/textfieldselection/defaultSelection.html": [
"c9568da864127d49974b970809312c953fb347b1",
"testharness"
],
"html/semantics/forms/textfieldselection/original-id.json": [
"14a6f0077d512837c24931a2a9723e11d1d7a1c7",
"support"

View file

@ -1,4 +0,0 @@
[setSelectionRange.html]
[setSelectionRange on line boundaries]
expected: FAIL

View file

@ -0,0 +1,35 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<textarea>g</textarea>
<input type="text" value="foo">
</input>
<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() {
let textarea = document.querySelector('input');
assert_equals(textarea.selectionStart, 0);
assert_equals(textarea.selectionEnd, 0);
}, "Default selectionStart and selectionEnd for input");
test(function() {
let textarea = document.querySelector('textarea');
textarea.value="g";
assert_equals(textarea.selectionStart, 0);
assert_equals(textarea.selectionEnd, 0);
}, "selectionStart and selectionEnd do not change when same value set again");
test(function() {
let textarea = document.querySelector('textarea');
textarea.value="G";
assert_equals(textarea.selectionStart, 1);
assert_equals(textarea.selectionEnd, 1);
}, "selectionStart and selectionEnd change when value changed to upper case");
</script>