OLD | NEW |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!doctype html> |
2 <html> | 2 <script src="../../resources/testharness.js"></script> |
3 <head> | 3 <script src="../../resources/testharnessreport.js"></script> |
4 <script src="../../resources/js-test.js"></script> | 4 <script src="../assert_selection.js"></script> |
5 <script src="resources/js-test-selection-shared.js"></script> | 5 <script> |
6 </head> | 6 // TODO(editing-dev): Once http://crbug.com/736253 fixed, we should use |
7 <body> | 7 // |chrome.pointerActionSequence()| instead of |eventSender|. |
8 <p id="description"></p> | 8 const kSample = [ |
9 <div id="console"></div> | 9 '<div id="first">one <span id="start"></span>two three</div>', |
10 <script src="script-tests/shift-click.js"></script> | 10 '<div id="second">four <span id="end"></span>five six</div>', |
11 </body> | 11 ].join(''); |
12 </html> | 12 |
13 function doTest(behavior) { | |
14 assert_exists(window, 'eventSender', 'This test requires eventSender.'); | |
15 assert_exists(window, 'internals', 'This test requires internals.'); | |
16 | |
17 function doDrag(selection) { | |
18 const document = selection.document; | |
19 const start = document.getElementById('start'); | |
20 const end = document.getElementById('end'); | |
21 | |
22 // Reset selection granularity | |
23 eventSender.leapForward(1000); | |
24 eventSender.mouseMoveTo(0, 0); | |
25 eventSender.mouseDown(); | |
26 eventSender.leapForward(1000); | |
27 | |
28 // Double-click select to get around eventSender bug where it won't select | |
29 // text just using single-click. | |
30 eventSender.mouseMoveTo(selection.computeLeft(start), | |
31 selection.computeTop(start)); | |
32 eventSender.mouseDown(); | |
33 eventSender.mouseUp(); | |
34 eventSender.mouseDown(); | |
35 eventSender.mouseMoveTo(selection.computeLeft(end), | |
36 selection.computeTop(end)); | |
37 eventSender.mouseUp(); | |
38 } | |
39 | |
40 function doShiftClick(selection, target, offsetX) { | |
41 const document = selection.document; | |
42 const parent = target.parentNode; | |
43 eventSender.mouseMoveTo(selection.computeLeft(target) + offsetX, | |
44 selection.computeTop(target)); | |
45 eventSender.mouseDown(0, ['shiftKey']); | |
46 eventSender.mouseUp(0, ['shiftKey']); | |
47 } | |
48 | |
49 internals.settings.setEditingBehavior(behavior); | |
50 | |
51 assert_selection( | |
52 kSample, | |
53 selection => doDrag(selection), | |
54 [ | |
55 '<div id="first">one <span id="start"></span>^two three</div>', | |
56 '<div id="second">four <span id="end"></span>five| six</div>', | |
57 ].join(''), | |
58 `${behavior}-1: Drag start to end`); | |
59 | |
60 assert_selection( | |
61 kSample, | |
62 selection => { | |
63 const second = selection.document.getElementById('second'); | |
64 doDrag(selection); | |
65 doShiftClick(selection, second, second.offsetWidth); | |
66 }, | |
67 [ | |
68 '<div id="first">one <span id="start"></span>^two three</div>', | |
69 '<div id="second">four <span id="end"></span>five six|</div>', | |
70 ].join(''), | |
71 `${behavior}-2: Shift click second`); | |
72 | |
73 assert_selection( | |
74 kSample, | |
75 selection => { | |
76 const end = selection.document.getElementById('end'); | |
77 const second = selection.document.getElementById('second'); | |
78 doDrag(selection); | |
79 doShiftClick(selection, second, second.offsetWidth); | |
80 doShiftClick(selection, end, 0); | |
81 }, | |
82 [ | |
83 '<div id="first">one <span id="start"></span>^two three</div>', | |
84 '<div id="second">four <span id="end"></span>five| six</div>', | |
85 ].join(''), | |
86 `${behavior}-3: Shift click end`); | |
87 | |
88 // These two fail on Mac due to https://wkb.ug/36256. | |
yoichio
2017/06/30 01:55:56
This link doesn't work could you use original one?
yosin_UTC9
2017/06/30 08:30:02
Done.
It could be http://wkb.ug/36256, which use
| |
89 // In the first shiftClick call, the space after five is selected and | |
90 // shouldn't be. In the second shiftClick call, "six" is selected and | |
91 // shouldn't be. | |
92 assert_selection( | |
93 kSample, | |
94 selection => { | |
95 const end = selection.document.getElementById('end'); | |
96 const first = selection.document.getElementById('first'); | |
97 const second = selection.document.getElementById('second'); | |
98 doDrag(selection); | |
99 doShiftClick(selection, second, second.offsetWidth); | |
100 doShiftClick(selection, end, 0); | |
101 doShiftClick(selection, first, 0); | |
102 }, | |
103 behavior === 'mac' | |
104 ? [ | |
105 '<div id="first">|one <span id="start"></span>two three</div>', | |
106 '<div id="second">four <span id="end"></span>five ^six</div>', | |
107 ].join('') | |
108 : [ | |
109 '<div id="first">|one <span id="start"></span>two^ three</div>', | |
110 '<div id="second">four <span id="end"></span>five six</div>', | |
111 ].join(''), | |
112 `${behavior}-4: Shift click first`); | |
113 | |
114 assert_selection( | |
115 kSample, | |
116 selection => { | |
117 const end = selection.document.getElementById('end'); | |
118 const first = selection.document.getElementById('first'); | |
119 const second = selection.document.getElementById('second'); | |
120 const start = selection.document.getElementById('start'); | |
121 doDrag(selection); | |
122 doShiftClick(selection, second, second.offsetWidth); | |
123 doShiftClick(selection, end, 0); | |
124 doShiftClick(selection, first, 0); | |
125 doShiftClick(selection, start, 0); | |
126 }, | |
127 behavior === 'mac' | |
128 ? [ | |
129 '<div id="first">one <span id="start"></span>|two three</div>', | |
130 '<div id="second">four <span id="end"></span>five six^</div>', | |
131 ].join('') | |
132 : [ | |
133 '<div id="first">one <span id="start"></span>^two| three</div>', | |
134 '<div id="second">four <span id="end"></span>five six</div>', | |
135 ].join(''), | |
136 `${behavior}-5: Shift click start`); | |
137 } | |
138 | |
139 for (const behavior of ['mac', 'win']) { | |
140 test(() => doTest(behavior), | |
141 `${behavior}: Expand selection with Shift+Click`); | |
142 } | |
143 </script> | |
OLD | NEW |