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

Side by Side Diff: LayoutTests/fast/forms/setrangetext-within-events.html

Issue 1049233003: Keep the selection of the text field when changed by JS. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../../resources/testharness.js"></script>
3 <script src="../../resources/testharnessreport.js"></script>
4 <script>
5 async_test(function(t) {
6 window.onload = t.step_func(function() {
7 if (window.eventSender) {
yosin_UTC9 2015/07/13 03:47:22 nit: Could you use early return pattern?
Miyoung Shin(g) 2015/07/13 04:23:49 Done.
8 doSetSelectionRange('focus');
9 doSetSelectionRange('mousedown');
10 doSetSelectionRange('mouseup');
11 doSetSelectionRange('click');
12 t.done();
13 }
14 });
15
16 function doSetSelectionRange(eventType) {
17 var textfield = document.getElementById('textfield');
18 textfield.setSelectionRange(0, 1);
19 var tx = textfield.offsetLeft + 4;
20 var ty = textfield.offsetTop + 4;
21
22 textfield.addEventListener(eventType, setSelectionRange);
23 eventSender.mouseMoveTo(tx, ty);
24 eventSender.mouseDown();
25 eventSender.mouseUp();
26 if (eventType === 'mousedown') {
27 assert_equals(textfield.selectionStart, 0);
28 assert_equals(textfield.selectionEnd, 0);
29 } else {
30 assert_equals(textfield.selectionStart, 0);
31 assert_equals(textfield.selectionEnd, 5);
32 }
33
34 eventSender.leapForward(1000);
35 eventSender.mouseMoveTo(textfield.offsetLeft , textfield.offsetTop);
36 eventSender.mouseDown();
37 eventSender.mouseUp();
38 textfield.blur();
39
40 assert_equals(textfield.selectionStart, 0);
41 assert_equals(textfield.selectionEnd, 0);
42 textfield.removeEventListener(eventType, setSelectionRange);
43 }
44
45 function setSelectionRange(e) {
46 var textfield = document.getElementById('textfield');
47 textfield.setSelectionRange(0, textfield.value.length);
48 }
49 }, "This tests the selection of the text field after setSelectionRange is called .");
50 </script>
51 <input type="text" value="value" id="textfield"></input>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698