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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/forms/setrangetext-within-events.html
diff --git a/LayoutTests/fast/forms/setrangetext-within-events.html b/LayoutTests/fast/forms/setrangetext-within-events.html
new file mode 100644
index 0000000000000000000000000000000000000000..761206cabb223ec8771c5ba42ff9994fe32056d2
--- /dev/null
+++ b/LayoutTests/fast/forms/setrangetext-within-events.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+async_test(function(t) {
+ window.onload = t.step_func(function() {
+ 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.
+ doSetSelectionRange('focus');
+ doSetSelectionRange('mousedown');
+ doSetSelectionRange('mouseup');
+ doSetSelectionRange('click');
+ t.done();
+ }
+ });
+
+ function doSetSelectionRange(eventType) {
+ var textfield = document.getElementById('textfield');
+ textfield.setSelectionRange(0, 1);
+ var tx = textfield.offsetLeft + 4;
+ var ty = textfield.offsetTop + 4;
+
+ textfield.addEventListener(eventType, setSelectionRange);
+ eventSender.mouseMoveTo(tx, ty);
+ eventSender.mouseDown();
+ eventSender.mouseUp();
+ if (eventType === 'mousedown') {
+ assert_equals(textfield.selectionStart, 0);
+ assert_equals(textfield.selectionEnd, 0);
+ } else {
+ assert_equals(textfield.selectionStart, 0);
+ assert_equals(textfield.selectionEnd, 5);
+ }
+
+ eventSender.leapForward(1000);
+ eventSender.mouseMoveTo(textfield.offsetLeft , textfield.offsetTop);
+ eventSender.mouseDown();
+ eventSender.mouseUp();
+ textfield.blur();
+
+ assert_equals(textfield.selectionStart, 0);
+ assert_equals(textfield.selectionEnd, 0);
+ textfield.removeEventListener(eventType, setSelectionRange);
+ }
+
+ function setSelectionRange(e) {
+ var textfield = document.getElementById('textfield');
+ textfield.setSelectionRange(0, textfield.value.length);
+ }
+}, "This tests the selection of the text field after setSelectionRange is called.");
+</script>
+<input type="text" value="value" id="textfield"></input>

Powered by Google App Engine
This is Rietveld 408576698