Bug 164077

Summary: iOS autocorrection does not trigger an input event of inputType "insertReplacementText"
Product: WebKit Reporter: Wenson Hsieh <wenson_hsieh>
Component: UI EventsAssignee: Wenson Hsieh <wenson_hsieh>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, enrica, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 163112    
Attachments:
Description Flags
Patch
simon.fraser: review+
[For EWS] Fix DRT and implement feedback
none
[For EWS] Fix iOS OpenSource build.
none
Patch for landing none

Description Wenson Hsieh 2016-10-27 14:00:42 PDT
With input events on:
- Start typing something in an editable area (e.g. “tes”). The candidate bar on iOS should show an autocompletion candidate (e.g. “test” or “testing”)
- Select the candidate
- Observe that `beforeinput` and `input` events of type “insertText” were fired, when they should really be of type “insertReplacementText”.
Comment 1 Wenson Hsieh 2016-10-27 14:01:30 PDT
<rdar://problem/28987810>
Comment 2 Wenson Hsieh 2016-10-28 15:16:46 PDT
Created attachment 293229 [details]
Patch
Comment 3 Simon Fraser (smfr) 2016-10-28 15:29:38 PDT
Comment on attachment 293229 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=293229&action=review

> Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:260
> +    ASSERT(index >= 0 && index < 3);

This should not assert if it's possible for the JS to send in arbitrary values, but ideally it would trigger an error if too big.

> Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:283
> +    float offsetX = (index * 2 + 1) * CGRectGetWidth(predictionViewFrame) / 6;
> +    float offsetY = CGRectGetHeight(webView.window.frame) - CGRectGetHeight([UIKeyboardPredictionView activeInstance].superview.frame) + CGRectGetHeight(predictionViewFrame) / 2;
> +    [[HIDEventGenerator sharedHIDEventGenerator] tap:CGPointMake(offsetX, offsetY) completionBlock:^{
> +        if (m_context)
> +            m_context->asyncTaskComplete(callbackID);
> +    }];

Seems fragile in the face of UI changes, but oh well.

> LayoutTests/fast/events/ios/before-input-events-prevent-candidate-insertion.html:16
> +            uiController.singleTapAtPoint(100, 50, function() {});

You should get the coordinates via getBoundingClientRect, like other tests.

> LayoutTests/fast/events/ios/input-events-insert-replacement-text.html:16
> +            uiController.singleTapAtPoint(100, 100, function() {});

Ditto.
Comment 4 Wenson Hsieh 2016-10-28 16:41:06 PDT
Created attachment 293244 [details]
[For EWS] Fix DRT and implement feedback
Comment 5 Wenson Hsieh 2016-10-28 16:43:44 PDT
Comment on attachment 293229 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=293229&action=review

>> Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:260
>> +    ASSERT(index >= 0 && index < 3);
> 
> This should not assert if it's possible for the JS to send in arbitrary values, but ideally it would trigger an error if too big.

Yes, this is reasonable. There are a few other places where we should use exceptions (e.g. typeCharacterUsingHardwareKeyboard with an invalid string, or zoomToScale with a negative scale). I'll file a followup to make these throw exceptions on receiving bad arguments.

>> Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm:283
>> +    }];
> 
> Seems fragile in the face of UI changes, but oh well.

I agree :(
Since we want to eventually test using the software keyboard as well, we should reach out to the keyboards team and see if we can get any SPI to make this more robust.

>> LayoutTests/fast/events/ios/before-input-events-prevent-candidate-insertion.html:16
>> +            uiController.singleTapAtPoint(100, 50, function() {});
> 
> You should get the coordinates via getBoundingClientRect, like other tests.

Sounds good! Done.

>> LayoutTests/fast/events/ios/input-events-insert-replacement-text.html:16
>> +            uiController.singleTapAtPoint(100, 100, function() {});
> 
> Ditto.

Done.
Comment 6 Wenson Hsieh 2016-10-28 17:08:12 PDT
Created attachment 293249 [details]
[For EWS] Fix iOS OpenSource build.
Comment 7 Wenson Hsieh 2016-10-28 17:33:24 PDT
Created attachment 293257 [details]
Patch for landing
Comment 8 WebKit Commit Bot 2016-10-28 18:09:06 PDT
Comment on attachment 293257 [details]
Patch for landing

Clearing flags on attachment: 293257

Committed r208090: <http://trac.webkit.org/changeset/208090>
Comment 9 Wenson Hsieh 2016-10-28 22:19:04 PDT
Build fix in r208094