OLD | NEW |
| (Empty) |
1 description("Tests that shift+clicking does the platform correct behavior."); | |
2 | |
3 var first = document.createElement('div'); | |
4 first.innerHTML = 'one <span id="start"></span>two three'; | |
5 document.body.appendChild(first); | |
6 | |
7 var second = document.createElement('div'); | |
8 second.innerHTML = 'four <span id="end"></span>five six'; | |
9 document.body.appendChild(second); | |
10 | |
11 var start = document.getElementById('start'); | |
12 var end = document.getElementById('end'); | |
13 | |
14 function shiftClick(x, y, expected) | |
15 { | |
16 eventSender.mouseMoveTo(x, y); | |
17 eventSender.mouseDown(0, ['shiftKey']); | |
18 eventSender.mouseUp(0, ['shiftKey']); | |
19 assertSelectionString(expected); | |
20 } | |
21 | |
22 function assertSelectionString(expected) | |
23 { | |
24 if (window.getSelection().toString() == expected) | |
25 testPassed('window.getSelection().toString() is correct'); | |
26 else | |
27 testFailed('window.getSelection().toString() is "' + window.getSelection
().toString() + '" and should be "' + expected + '"'); | |
28 } | |
29 | |
30 function assertSelectionOrder(direction) | |
31 { | |
32 var expectedPosition; | |
33 if (direction == 'forward') | |
34 expectedPosition = Node.DOCUMENT_POSITION_FOLLOWING; | |
35 else if (direction == 'backward') | |
36 expectedPosition = Node.DOCUMENT_POSITION_PRECEDING; | |
37 | |
38 var sel = window.getSelection(); | |
39 if (sel.anchorNode.compareDocumentPosition(sel.focusNode) == expectedPositio
n) | |
40 testPassed("Selection direction is correct."); | |
41 else | |
42 testFailed("Selection direction is not correct. Expected a " + direction
+ " selection." + selectionAsString(sel)); | |
43 } | |
44 | |
45 function runShiftClickTest(editingBehavior) | |
46 { | |
47 internals.settings.setEditingBehavior(editingBehavior); | |
48 | |
49 // Double-click select to get around eventSender bug where it won't select | |
50 // text just using single-click. | |
51 eventSender.mouseMoveTo(start.offsetLeft, start.offsetTop); | |
52 eventSender.mouseDown(); | |
53 eventSender.mouseUp(); | |
54 eventSender.mouseDown(); | |
55 | |
56 eventSender.mouseMoveTo(end.offsetLeft, end.offsetTop); | |
57 eventSender.mouseUp(); | |
58 | |
59 assertSelectionString('two three\nfour five'); | |
60 assertSelectionOrder('forward'); | |
61 | |
62 shiftClick(second.offsetLeft + second.offsetWidth, second.offsetTop, 'two th
ree\nfour five six'); | |
63 assertSelectionOrder('forward'); | |
64 | |
65 shiftClick(end.offsetLeft, end.offsetTop, 'two three\nfour five'); | |
66 assertSelectionOrder('forward'); | |
67 | |
68 // These two fail on Mac due to https://bugs.webkit.org/show_bug.cgi?id=3625
6. | |
69 // In the first shiftClick call, the space after five is selected and should
n't be. | |
70 // In the second shiftClick call, "six" is selected and shouldn't be. | |
71 if (editingBehavior == "mac") | |
72 shiftClick(first.offsetLeft, first.offsetTop, 'one two three\nfour five'
); | |
73 else | |
74 shiftClick(first.offsetLeft, first.offsetTop, 'one two'); | |
75 assertSelectionOrder('backward'); | |
76 | |
77 if (editingBehavior == "mac") | |
78 shiftClick(start.offsetLeft, start.offsetTop, 'two three\nfour five'); | |
79 else | |
80 shiftClick(start.offsetLeft, start.offsetTop, 'two'); | |
81 | |
82 // FIXME: The selection direction is incorrect on Win/Linux here. It should
be backward. | |
83 assertSelectionOrder('backward'); | |
84 } | |
85 | |
86 if (window.eventSender && window.internals) { | |
87 runShiftClickTest("mac"); | |
88 runShiftClickTest("win"); | |
89 } | |
90 | |
91 var successfullyParsed = true; | |
OLD | NEW |