Commit 188e3ae5 authored by bcwhite's avatar bcwhite Committed by Commit bot

Use polling to check focused node instead of sleep.

BUG=477632

Review URL: https://codereview.chromium.org/1143443002

Cr-Commit-Position: refs/heads/master@{#329713}
parent 4d79d02a
......@@ -331,7 +331,16 @@ public class ImeTest extends ContentShellTestBase {
assertWaitForKeyboardStatus(false);
DOMUtils.focusNode(mWebContents, "textarea");
assertWaitForKeyboardStatus(true);
Thread.sleep(50);
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
try {
return "textarea".equals(DOMUtils.getFocusedNode(mWebContents));
} catch (Exception e) {
return false;
}
}
}));
mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);
......@@ -623,6 +632,16 @@ public class ImeTest extends ContentShellTestBase {
assertWaitForKeyboardStatus(false);
DOMUtils.focusNode(mWebContents, "textarea");
assertWaitForKeyboardStatus(true);
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
try {
return "textarea".equals(DOMUtils.getFocusedNode(mWebContents));
} catch (Exception e) {
return false;
}
}
}));
mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);
......
......@@ -152,6 +152,27 @@ public class DOMUtils {
JavaScriptUtils.executeJavaScriptAndWaitForResult(webContents, sb.toString());
}
/**
* Get the id of the currently focused node.
*/
public static String getFocusedNode(WebContents webContents)
throws InterruptedException, TimeoutException {
StringBuilder sb = new StringBuilder();
sb.append("(function() {");
sb.append(" var node = document.activeElement;");
sb.append(" if (!node) return null;");
sb.append(" return node.id;");
sb.append("})();");
String id = JavaScriptUtils.executeJavaScriptAndWaitForResult(webContents, sb.toString());
// String results from JavaScript includes surrounding quotes. Remove them.
if (id != null && id.length() >= 2 && id.charAt(0) == '"') {
id = id.substring(1, id.length() - 1);
}
return id;
}
/**
* Click a DOM node by its id.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment