Commit 38dc6a29 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

[AW Autofill] Not send view Exit/Enter if no position change.

To prevent unnecessary view Exit/Enter notification, we stopped
send them if the position wasn't change.

Bug: 1005545
Change-Id: I378a4ca0516ab636dc21eb72a1149613cabbe386
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1812238Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699865}
parent 0d8a20d8
...@@ -331,10 +331,12 @@ public class AwAutofillProvider extends AutofillProvider { ...@@ -331,10 +331,12 @@ public class AwAutofillProvider extends AutofillProvider {
// the position could be changed. // the position could be changed.
int virtualId = mRequest.getVirtualId(sIndex); int virtualId = mRequest.getVirtualId(sIndex);
Rect absBound = transformToWindowBounds(new RectF(x, y, x + width, y + height)); Rect absBound = transformToWindowBounds(new RectF(x, y, x + width, y + height));
mAutofillManager.notifyVirtualViewExited(mContainerView, virtualId); if (!focusField.absBound.equals(absBound)) {
mAutofillManager.notifyVirtualViewEntered(mContainerView, virtualId, absBound); mAutofillManager.notifyVirtualViewExited(mContainerView, virtualId);
// Update focus field position. mAutofillManager.notifyVirtualViewEntered(mContainerView, virtualId, absBound);
mRequest.setFocusField(new FocusField(focusField.fieldIndex, absBound)); // Update focus field position.
mRequest.setFocusField(new FocusField(focusField.fieldIndex, absBound));
}
} }
notifyVirtualValueChanged(index); notifyVirtualValueChanged(index);
mAutofillUMA.onUserChangeFieldValue(mRequest.getField(sIndex).hasPreviouslyAutofilled()); mAutofillUMA.onUserChangeFieldValue(mRequest.getField(sIndex).hasPreviouslyAutofilled());
......
...@@ -557,8 +557,7 @@ public class AwAutofillTest { ...@@ -557,8 +557,7 @@ public class AwAutofillTest {
mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time. // Note that we currently call ENTER/EXIT one more time.
mCnt += mTest.waitForCallbackAndVerifyTypes(mCnt, mCnt += mTest.waitForCallbackAndVerifyTypes(mCnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
} }
public void simulateUserSelectSuggestion() throws Throwable { public void simulateUserSelectSuggestion() throws Throwable {
...@@ -582,9 +581,8 @@ public class AwAutofillTest { ...@@ -582,9 +581,8 @@ public class AwAutofillTest {
public void simulateUserChangeAutofilledField() throws Throwable { public void simulateUserChangeAutofilledField() throws Throwable {
mTest.executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); mTest.executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B); mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
mCnt += mTest.waitForCallbackAndVerifyTypes(mCnt, mCnt += mTest.waitForCallbackAndVerifyTypes(
new Integer[] { mCnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
} }
public void submitForm() throws Throwable { public void submitForm() throws Throwable {
...@@ -606,9 +604,8 @@ public class AwAutofillTest { ...@@ -606,9 +604,8 @@ public class AwAutofillTest {
public void simulateUserChangeField() throws Throwable { public void simulateUserChangeField() throws Throwable {
mTest.executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); mTest.executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B); mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
mCnt += mTest.waitForCallbackAndVerifyTypes(mCnt, mCnt += mTest.waitForCallbackAndVerifyTypes(
new Integer[] { mCnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
} }
private void initDeltaSamples() { private void initDeltaSamples() {
...@@ -780,10 +777,7 @@ public class AwAutofillTest { ...@@ -780,10 +777,7 @@ public class AwAutofillTest {
cnt += waitForCallbackAndVerifyTypes( cnt += waitForCallbackAndVerifyTypes(
cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED}); cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED});
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time. waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
executeJavaScriptAndWaitForResult("document.getElementById('text1').blur();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').blur();");
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VIEW_EXITED}); waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VIEW_EXITED});
...@@ -819,10 +813,8 @@ public class AwAutofillTest { ...@@ -819,10 +813,8 @@ public class AwAutofillTest {
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time.
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure; TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure); assertNotNull(viewStructure);
...@@ -938,10 +930,8 @@ public class AwAutofillTest { ...@@ -938,10 +930,8 @@ public class AwAutofillTest {
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time.
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
// Check if NotifyVirtualValueChanged() called and value is 'a'. // Check if NotifyVirtualValueChanged() called and value is 'a'.
assertEquals(1, values.size()); assertEquals(1, values.size());
...@@ -951,9 +941,7 @@ public class AwAutofillTest { ...@@ -951,9 +941,7 @@ public class AwAutofillTest {
// Check if NotifyVirtualValueChanged() called again, first value is 'a', // Check if NotifyVirtualValueChanged() called again, first value is 'a',
// second value is 'ab', and both time has the same id. // second value is 'ab', and both time has the same id.
waitForCallbackAndVerifyTypes(cnt, waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
values = getChangedValues(); values = getChangedValues();
assertEquals(2, values.size()); assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue()); assertEquals("a", values.get(0).second.getTextValue());
...@@ -979,10 +967,8 @@ public class AwAutofillTest { ...@@ -979,10 +967,8 @@ public class AwAutofillTest {
int cnt = 0; int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time.
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
// Check if NotifyVirtualValueChanged() called and value is 'a'. // Check if NotifyVirtualValueChanged() called and value is 'a'.
assertEquals(1, values.size()); assertEquals(1, values.size());
...@@ -990,16 +976,14 @@ public class AwAutofillTest { ...@@ -990,16 +976,14 @@ public class AwAutofillTest {
executeJavaScriptAndWaitForResult("document.getElementById('text1').value='c';"); executeJavaScriptAndWaitForResult("document.getElementById('text1').value='c';");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// There is no AUTOFILL_CANCEL from Android P. // There is no AUTOFILL_CANCEL from Android P.
assertEquals(4, getCallbackCount()); assertEquals(2, getCallbackCount());
} else { } else {
assertEquals(5, getCallbackCount()); assertEquals(3, getCallbackCount());
} }
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
// Check if NotifyVirtualValueChanged() called one more time and value is 'cb', this // Check if NotifyVirtualValueChanged() called one more time and value is 'cb', this
// means javascript change didn't trigger the NotifyVirtualValueChanged(). // means javascript change didn't trigger the NotifyVirtualValueChanged().
waitForCallbackAndVerifyTypes(cnt, waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
values = getChangedValues(); values = getChangedValues();
assertEquals(2, values.size()); assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue()); assertEquals("a", values.get(0).second.getTextValue());
...@@ -1028,10 +1012,8 @@ public class AwAutofillTest { ...@@ -1028,10 +1012,8 @@ public class AwAutofillTest {
int cnt = 0; int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time.
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
// Fill the password. // Fill the password.
executeJavaScriptAndWaitForResult("document.getElementById('passwordid').select();"); executeJavaScriptAndWaitForResult("document.getElementById('passwordid').select();");
...@@ -1039,9 +1021,7 @@ public class AwAutofillTest { ...@@ -1039,9 +1021,7 @@ public class AwAutofillTest {
new Integer[] { new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED}); AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
clearChangedValues(); clearChangedValues();
// Submit form. // Submit form.
executeJavaScriptAndWaitForResult("document.getElementById('formid').submit();"); executeJavaScriptAndWaitForResult("document.getElementById('formid').submit();");
...@@ -1067,10 +1047,8 @@ public class AwAutofillTest { ...@@ -1067,10 +1047,8 @@ public class AwAutofillTest {
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Cancel called for the first query. // Cancel called for the first query.
// Note that we currently call ENTER/EXIT one more time.
waitForCallbackAndVerifyTypes(cnt, waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
} }
@Test @Test
...@@ -1094,10 +1072,8 @@ public class AwAutofillTest { ...@@ -1094,10 +1072,8 @@ public class AwAutofillTest {
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time.
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// Move to form2, cancel() should be called again. // Move to form2, cancel() should be called again.
executeJavaScriptAndWaitForResult("document.getElementById('text2').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text2').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
...@@ -1164,8 +1140,7 @@ public class AwAutofillTest { ...@@ -1164,8 +1140,7 @@ public class AwAutofillTest {
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Verify autofill session triggered. // Verify autofill session triggered.
count += waitForCallbackAndVerifyTypes(count, count += waitForCallbackAndVerifyTypes(count,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// Verify focus is in iframe. // Verify focus is in iframe.
assertEquals("true", assertEquals("true",
executeJavaScriptAndWaitForResult( executeJavaScriptAndWaitForResult(
...@@ -1177,7 +1152,7 @@ public class AwAutofillTest { ...@@ -1177,7 +1152,7 @@ public class AwAutofillTest {
// The new session starts because cancel() has been called. // The new session starts because cancel() has been called.
waitForCallbackAndVerifyTypes(count, waitForCallbackAndVerifyTypes(count,
new Integer[] {AUTOFILL_VIEW_EXITED, AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, new Integer[] {AUTOFILL_VIEW_EXITED, AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED,
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED}); AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size()); assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue()); assertEquals("a", values.get(0).second.getTextValue());
...@@ -1249,10 +1224,8 @@ public class AwAutofillTest { ...@@ -1249,10 +1224,8 @@ public class AwAutofillTest {
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time.
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; "); executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; ");
waitForCallbackAndVerifyTypes(cnt, waitForCallbackAndVerifyTypes(cnt,
new Integer[] { new Integer[] {
...@@ -1322,8 +1295,7 @@ public class AwAutofillTest { ...@@ -1322,8 +1295,7 @@ public class AwAutofillTest {
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
clearChangedValues(); clearChangedValues();
executeJavaScriptAndWaitForResult("document.getElementById('color').focus();"); executeJavaScriptAndWaitForResult("document.getElementById('color').focus();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER);
...@@ -1365,8 +1337,7 @@ public class AwAutofillTest { ...@@ -1365,8 +1337,7 @@ public class AwAutofillTest {
// Use key B to select 'blue'. // Use key B to select 'blue'.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size()); assertEquals(1, values.size());
assertTrue(values.get(0).second.isList()); assertTrue(values.get(0).second.isList());
...@@ -1402,8 +1373,7 @@ public class AwAutofillTest { ...@@ -1402,8 +1373,7 @@ public class AwAutofillTest {
// Change select control first shall start autofill session. // Change select control first shall start autofill session.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER);
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size()); assertEquals(1, values.size());
assertTrue(values.get(0).second.isList()); assertTrue(values.get(0).second.isList());
...@@ -1444,8 +1414,7 @@ public class AwAutofillTest { ...@@ -1444,8 +1414,7 @@ public class AwAutofillTest {
// work. // work.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_DPAD_CENTER);
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size()); assertEquals(1, values.size());
assertTrue(values.get(0).second.isList()); assertTrue(values.get(0).second.isList());
...@@ -1481,10 +1450,8 @@ public class AwAutofillTest { ...@@ -1481,10 +1450,8 @@ public class AwAutofillTest {
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('frmAddressB').select();"); executeJavaScriptAndWaitForResult("document.getElementById('frmAddressB').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Note that we currently call ENTER/EXIT one more time.
cnt += waitForCallbackAndVerifyTypes(cnt, cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VIEW_EXITED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure; TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure); assertNotNull(viewStructure);
...@@ -1839,6 +1806,45 @@ public class AwAutofillTest { ...@@ -1839,6 +1806,45 @@ public class AwAutofillTest {
mUMATestHelper.verifyWebViewCreatedByActivityContext(); mUMATestHelper.verifyWebViewCreatedByActivityContext();
} }
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testPageScrollTriggerViewExitAndEnter() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<input type='text' id='text1' name='username'"
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
+ "</form><p style='height: 100vh'>Hello</p></body></html>";
try {
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// Moved view, the position change trigger additional AUTOFILL_VIEW_EXITED and
// AUTOFILL_VIEW_ENTERED.
scrollToBottom();
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
// Check if NotifyVirtualValueChanged() called again and with extra AUTOFILL_VIEW_EXITED
// and AUTOFILL_VIEW_ENTERED
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
} finally {
webServer.shutdown();
}
}
private void scrollToBottom() {
TestThreadUtils.runOnUiThreadBlocking(
() -> { mTestContainerView.scrollTo(0, mTestContainerView.getHeight()); });
}
private void loadUrlSync(String url) throws Exception { private void loadUrlSync(String url) throws Exception {
mRule.loadUrlSync( mRule.loadUrlSync(
mTestContainerView.getAwContents(), mContentsClient.getOnPageFinishedHelper(), url); mTestContainerView.getAwContents(), mContentsClient.getOnPageFinishedHelper(), url);
......
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