diff options
author | Hugo Thiessard <hugo.thiessard@etu.u-bordeaux.fr> | 2015-08-30 18:59:15 +0200 |
---|---|---|
committer | Hugo Thiessard <hugo.thiessard@etu.u-bordeaux.fr> | 2015-08-31 09:10:34 +0200 |
commit | 6a2ae236d409d221d005726ff8326edc97e9b266 (patch) | |
tree | 0395867037d7eb950439e543d57de3589bb5e03c /tests/unit/script/textinput.rs | |
parent | 7dda183022f9bee8b4bdffe8b4cf31e09b885d94 (diff) | |
download | servo-6a2ae236d409d221d005726ff8326edc97e9b266.tar.gz servo-6a2ae236d409d221d005726ff8326edc97e9b266.zip |
Issue #7365 : test for cursor position after clearing selection
Diffstat (limited to 'tests/unit/script/textinput.rs')
-rw-r--r-- | tests/unit/script/textinput.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/script/textinput.rs b/tests/unit/script/textinput.rs index 313ab62fe0a..13cb138949c 100644 --- a/tests/unit/script/textinput.rs +++ b/tests/unit/script/textinput.rs @@ -205,3 +205,57 @@ fn test_clipboard_paste() { textinput.handle_keydown_aux(Key::V, MODIFIERS); assert_eq!(textinput.get_content(), "abcdefg"); } + +#[test] +fn test_textinput_cursor_position_correct_after_clearing_selection() { + let mut textinput = TextInput::new(Lines::Single, "abcdef".to_owned(), DummyClipboardContext::new("")); + + // Single line - Forward + textinput.adjust_horizontal(3, Selection::Selected); + textinput.adjust_horizontal(1, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 3); + + textinput.adjust_horizontal(-3, Selection::NotSelected); + textinput.adjust_horizontal(3, Selection::Selected); + textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 3); + + // Single line - Backward + textinput.adjust_horizontal(-3, Selection::NotSelected); + textinput.adjust_horizontal(3, Selection::Selected); + textinput.adjust_horizontal(-1, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 0); + + textinput.adjust_horizontal(-3, Selection::NotSelected); + textinput.adjust_horizontal(3, Selection::Selected); + textinput.adjust_horizontal_by_one(Direction::Backward, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 0); + + + let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned(), DummyClipboardContext::new("")); + + // Multiline - Forward + textinput.adjust_horizontal(4, Selection::Selected); + textinput.adjust_horizontal(1, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 0); + assert_eq!(textinput.edit_point.line, 1); + + textinput.adjust_horizontal(-4, Selection::NotSelected); + textinput.adjust_horizontal(4, Selection::Selected); + textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 0); + assert_eq!(textinput.edit_point.line, 1); + + // Multiline - Backward + textinput.adjust_horizontal(-4, Selection::NotSelected); + textinput.adjust_horizontal(4, Selection::Selected); + textinput.adjust_horizontal(-1, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 0); + assert_eq!(textinput.edit_point.line, 0); + + textinput.adjust_horizontal(-4, Selection::NotSelected); + textinput.adjust_horizontal(4, Selection::Selected); + textinput.adjust_horizontal_by_one(Direction::Backward, Selection::NotSelected); + assert_eq!(textinput.edit_point.index, 0); + assert_eq!(textinput.edit_point.line, 0); +} |