Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / selection / selection-extend-should-not-move-across-caret-on-mac.html
blob97d13eabdee6b8a8ef1d85ba405e1bc23fb9b797
1 <!DOCTYPE html>
3 <p>
4 On Mac when word-selecting backwards starting with the
5 caret on the middle of a word and then word-selecting forward, the
6 caret is left in the same place where it was, instead of directly selecting to the end
7 of the word (which is windows/unix behavior).
8 </p>
10 <div id="test-div" contenteditable=true>
11 line 1<br>
12 line 2<br>
13 line 3
14 </div>
16 <script>
17 function editingTest(behavior) {
18 if (window.testRunner && window.internals) {
19 testRunner.dumpAsText();
20 internals.settings.setEditingBehavior(behavior);
23 function getSetCaretFunction(node, container, offset) {
24 return function () {
25 var selection = window.getSelection();
26 selection.empty();
28 var range = document.createRange();
29 range.setStart(container, offset);
30 selection.addRange(range);
34 function runTest(firstDirection, secondDirection, granularity, expectedText, setCaret) {
35 var selection = window.getSelection();
36 setCaret();
37 selection.modify("extend", firstDirection, granularity);
38 selection.modify("extend", secondDirection, granularity);
39 var s = selection.toString();
40 document.write("Extend " + firstDirection + " and then " + secondDirection + " by " + granularity + ": ");
41 document.write(s === expectedText ? "PASS" : 'FAIL: expected "' + escape(expectedText) + '", got "' + escape(s) + '"');
42 document.write("<br>");
45 var node = document.getElementById("test-div");
46 var children = node.childNodes;
48 var wordCaretFunction = getSetCaretFunction(node, children[2], children[2].data.search("ne 2"));
50 document.write(behavior + ":<br>");
51 runTest("backward", "forward", "word", behavior == "mac" ? "" : behavior == "win" ? "ne " : "ne", getSetCaretFunction(node, children[2], children[2].data.search("ne 2")));
52 runTest("forward", "backward", "word", behavior == "mac" ? "" : "li", getSetCaretFunction(node, children[2], children[2].data.search("ne 2")));
53 runTest("backward", "forward", "line", behavior == "mac" ? "" : "1\nline ", getSetCaretFunction(node, children[0], children[0].data.search("1")));
54 runTest("forward", "backward", "line", behavior == "mac" ? "" : "2\nline ", getSetCaretFunction(node, children[4], children[4].data.search("3")));
55 runTest("backward", "forward", "paragraph", behavior == "mac" ? "" : "1\nline ", getSetCaretFunction(node, children[0], children[0].data.search("1")));
56 runTest("forward", "backward", "paragraph", behavior == "mac" ? "" : "2\nline ", getSetCaretFunction(node, children[4], children[4].data.search("3")));
59 editingTest("mac");
60 editingTest("win");
61 editingTest("unix");
62 editingTest("android");
64 var node = document.getElementById("test-div");
65 node.parentNode.removeChild(node);
66 </script>