Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: LayoutTests/editing/caret/caret-direction-auto.html

Issue 541823003: Move caret to correct position when dir=auto (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Compile fix for Windows Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/editing/caret/caret-direction-auto-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/editing/caret/caret-direction-auto.html
diff --git a/LayoutTests/editing/caret/caret-direction-auto.html b/LayoutTests/editing/caret/caret-direction-auto.html
new file mode 100644
index 0000000000000000000000000000000000000000..bc1d3fca57b4787ed9d42d24de66027d778260ad
--- /dev/null
+++ b/LayoutTests/editing/caret/caret-direction-auto.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<script src="../../resources/js-test.js"></script>
+<textarea id="textarea" dir="auto" style="font-size: 20px; width: 20ex; border: solid thin black; padding: 10px;">&#x05d0;!</textarea>
+<script>
+description('Tests various scenarios for caret position when direction is auto');
+
+var text = document.getElementById('textarea');
+var beforeCaretPos, afterCaretPos;
+text.focus();
+shouldBeEqualToString('textarea.value', 'א!');
+
+debug('1. Caret is at right if text is in LTR direction');
+beforeCaretPos = textInputController.firstRectForCharacterRange(0, 3);
+testRunner.execCommand('MoveToEndOfLine');
+document.execCommand('InsertLineBreak');
+document.execCommand('InsertText', false, 'hello');
+afterCaretPos = textInputController.firstRectForCharacterRange(4, 5);
+shouldBeEqualToString('textarea.value', 'א!\nhello');
+debug('Compares lines if they are different');
+shouldNotBe('beforeCaretPos[1]', 'afterCaretPos[1]');
+debug('New text is in LTR direction, start of caret will differ');
+shouldBeGreaterThan('beforeCaretPos[0]', 'afterCaretPos[0]');
+
+debug('2. Addition of RTL text in middle of LTR text, caret moves to the left of the line.');
+beforeCaretPos = afterCaretPos;
+document.execCommand('InsertText', false, '\u05d0\u05d0');
+afterCaretPos = textInputController.firstRectForCharacterRange(4, 7);
+shouldBeEqualToString('textarea.value', 'א!\nhelloאא');
+debug('RTL text added will be move caret to start of position where hello begins');
+shouldBe('beforeCaretPos[0]', 'afterCaretPos[0]+afterCaretPos[2]');
+
+debug('3. Adding LTR text after RTL should move caret towards right.');
+beforeCaretPos = afterCaretPos;
+document.execCommand('InsertText', false, 'bye');
+afterCaretPos = textInputController.firstRectForCharacterRange(4, 10);
+shouldBeEqualToString('textarea.value', 'א!\nhelloאאbye');
+debug('Start position of caret is same');
+shouldBe('beforeCaretPos[0]+beforeCaretPos[2]', 'afterCaretPos[0]');
+debug('But end position differs');
+shouldNotBe('beforeCaretPos[0]+beforeCaretPos[2]', 'afterCaretPos[0]+afterCaretPos[2]');
+
+debug('4. Adding space, caret should move caret');
+beforeCaretPos = afterCaretPos;
+document.execCommand('InsertText', false, ' ');
+afterCaretPos = textInputController.firstRectForCharacterRange(4, 11);
+shouldBeEqualToString('textarea.value', 'א!\nhelloאאbye ');
+shouldBeGreaterThan('afterCaretPos[0]+afterCaretPos[2]', 'beforeCaretPos[0]+beforeCaretPos[2]');
+
+</script>
« no previous file with comments | « no previous file | LayoutTests/editing/caret/caret-direction-auto-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698