There are some problems with existing WebView IME test.
First off, the example is misleading. Creating a selection range in
JavaScript is not straightforward and is not representative of what
WebView developers should be doing. Focusing on editor is a better use
case.
Also, it was flaky in some old device that we deprecated. As found in
crbug.com/621049, we actually need to wait for document focus before
we can focus on content-editable body.
The reason is that Android's view focus gets propagated to the renderer
process as input message while JavaScript execution gets propagated to
the renderer process as frame message, so JavaScript may be executed
before document gets focused, and focusing on content-editable body
is an invalid operation when document isn't yet focused. I suspect that
this is the reason why some OEM email client was using selection range
trick in the first place.
Finally, we were testing against real input method, which can be another
cause of flakiness, so it's fixed by a fake input method manager.