sendKeysToElement should append, not prepend, keys

RESOLVED FIXED in Firefox 43

Status

defect
RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: ato, Assigned: ato)

Tracking

(Blocks 1 bug, {pi-marionette-server})

unspecified
mozilla43
Points:
---

Firefox Tracking Flags

(firefox43 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

4 years ago
sendKeysToElement prepends input to text fields rather than appending it.  This is because element.focus() in https://dxr.mozilla.org/mozilla-central/source/testing/marionette/sendkeys.js?from=marionette%2Fsendkeys.js#131 places the cursor at the beginning of the input field.

After focussing the element we should move the cursor to the end before we synthesise the key events.

More information about the original reported incident can be found in a wires bug: https://github.com/jgraham/wires/issues/19
(Assignee)

Updated

4 years ago
(Assignee)

Comment 1

4 years ago
A fun fact is that I ran into the same issue years ago when I implemented OperaDriver.  The relevant code is here: https://github.com/operasoftware/operaprestodriver/blob/master/src/com/opera/core/systems/OperaWebElement.java#L238
(Assignee)

Comment 2

4 years ago
The relevant piece of information is:

    // When a TEXTAREA element is focused it returns the cursor to the last position was at, or
    // places it last.  INPUT @type="text" (or any other textual input element) places the caret at
    // the beginning.  Because of this we are forced to move the caret to the end of the input
    // field.  We do this by setting the selection range through JavaScript, which should move the
    // cursor to the end of the field upon the next focus event.
(Assignee)

Comment 3

4 years ago
The move caret to end atom:

    function() {
        return function() {
            function a(d) {
                d.setSelectionRange(d.value.length, d.value.length)
            }
            var b = ["_"],
                c = this;
            !(b[0] in c) && c.execScript && c.execScript("var " + b[0]);
            for (var e; b.length && (e = b.shift());) !b.length && void 0 !== a ? c[e] = a : c = c[e] ? c[e] : c[e] = {};;
            return this._.apply(null, arguments);
        }.apply({
            navigator: typeof window != undefined ? window.navigator : null
        }, argument + s);
    }
(Assignee)

Comment 5

4 years ago
Bug 1203074: Move caret to end of textual input field before sending keys

When a TEXTAREA element is focused it returns the cursor to the last
position was at, or places it last.  INPUT @type="text" (or any other
textual input element) places the caret at the beginning.  Because of
this we move the caret to the end of the input field.  The next time
the element is focussed, the cursor should move to the end.

r=jgriffin
Attachment #8658723 - Flags: review?(jgriffin)
(Assignee)

Updated

4 years ago
Assignee: nobody → ato
Status: NEW → ASSIGNED
Comment on attachment 8658723 [details]
MozReview Request: Bug 1203074: Move caret to end of textual input field before sending keys

https://reviewboard.mozilla.org/r/18681/#review16707

lgtm
Attachment #8658723 - Flags: review?(jgriffin) → review+
This only seems to care about text and text area. Input elements with a control type of text should all handle this. see https://html.spec.whatwg.org/multipage/forms.html#the-input-element.
(Assignee)

Comment 9

4 years ago
(In reply to David Burns :automatedtester from comment #8)
> This only seems to care about text and text area. Input elements with a
> control type of text should all handle this. see
> https://html.spec.whatwg.org/multipage/forms.html#the-input-element.

It makes sense to default to moving the caret since a textual control is the fallback, and create a blacklist of alternate non-textual control types supported by Firefox where should should not attempt to move it.

Filed bug 1203540 fro this.
sorry had to back this out for test failures like https://treeherder.mozilla.org/logviewer.html#?job_id=13889604&repo=mozilla-inbound
Flags: needinfo?(ato)
(Assignee)

Comment 12

4 years ago
Comment on attachment 8658723 [details]
MozReview Request: Bug 1203074: Move caret to end of textual input field before sending keys

Bug 1203074: Move caret to end of textual input field before sending keys

When a TEXTAREA element is focused it returns the cursor to the last
position was at, or places it last.  INPUT @type="text" (or any other
textual input element) places the caret at the beginning.  Because of
this we move the caret to the end of the input field.  The next time
the element is focussed, the cursor should move to the end.

The layout touch caret tests relied on the caret being left in its
previous position.  This patch addresses that by using the advanced user
interaction API for these test cases.

r=jgriffin
(Assignee)

Comment 13

4 years ago
Comment on attachment 8658723 [details]
MozReview Request: Bug 1203074: Move caret to end of textual input field before sending keys

jgriffin: Mind taking another look?  I had to make some changes to the layout/base/tests/marionette/test_touchcaret.py tests.
Flags: needinfo?(ato)
Attachment #8658723 - Flags: review+ → review?(jgriffin)
Comment on attachment 8658723 [details]
MozReview Request: Bug 1203074: Move caret to end of textual input field before sending keys

https://reviewboard.mozilla.org/r/18681/#review17469
Attachment #8658723 - Flags: review?(jgriffin) → review+
https://hg.mozilla.org/mozilla-central/rev/86bd982df1f9
Status: ASSIGNED → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
You need to log in before you can comment on or make changes to this bug.