Commit 44bdf4ba authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

Refactor AwAutofillTest

1) Move WebServer instantiation and shutdown into setUp() and tearDown()
2) UMATestHelper to have mWebServer
3) Move field block to the beginning of UMATestHelper
4) Reformatting due to git cl format

This makes the test more readable at the expense of doing additional
WebServer setUp/shutDown for a couple of test cases.

Otherwise, there is no other logic change.

Bug: 1065160
Test: AwAutofillTest test time remains the same. Doesn't seem to add new test flakiness.
Change-Id: Ideb659a20b4fb9bf998f8701c8ee6a8e182c9aae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128985
Commit-Queue: Changwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarTao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756501}
parent 124a48bd
......@@ -31,6 +31,7 @@ import android.view.WindowManager;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -547,8 +548,24 @@ public class AwAutofillTest {
public static final int NO_FORM_SUBMISSION = -1;
public AwAutofillSessionUMATestHelper(AwAutofillTest test) {
private int mCnt;
private AwAutofillTest mTest;
private TestWebServer mWebServer;
private volatile Integer mSessionValue;
private HashMap<MetricsUtils.HistogramDelta, Integer> mSessionDelta;
private MetricsUtils.HistogramDelta mAutofillWebViewViewEnabled;
private MetricsUtils.HistogramDelta mAutofillWebViewViewDisabled;
private MetricsUtils.HistogramDelta mUserChangedAutofilledField;
private MetricsUtils.HistogramDelta mUserChangedNonAutofilledField;
private MetricsUtils.HistogramDelta mAutofillWebViewCreatedByActivityContext;
private MetricsUtils.HistogramDelta mAutofillWebViewCreatedByAppContext;
private volatile Integer mSourceValue;
private HashMap<MetricsUtils.HistogramDelta, Integer> mSubmissionSourceDelta;
private volatile Integer mHistogramSimpleCount;
public AwAutofillSessionUMATestHelper(AwAutofillTest test, TestWebServer webServer) {
mTest = test;
mWebServer = webServer;
initDeltaSamples();
}
......@@ -575,8 +592,8 @@ public class AwAutofillTest {
return value;
}
public void triggerAutofill(TestWebServer webServer) throws Throwable {
final String url = webServer.setResponse(FILE, DATA, null);
public void triggerAutofill() throws Throwable {
final String url = mWebServer.setResponse(FILE, DATA, null);
mTest.loadUrlSync(url);
mTest.executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
......@@ -715,25 +732,12 @@ public class AwAutofillTest {
assertEquals(0, mAutofillWebViewCreatedByAppContext.getDelta());
});
}
private int mCnt;
private AwAutofillTest mTest;
private volatile Integer mSessionValue;
private HashMap<MetricsUtils.HistogramDelta, Integer> mSessionDelta;
private MetricsUtils.HistogramDelta mAutofillWebViewViewEnabled;
private MetricsUtils.HistogramDelta mAutofillWebViewViewDisabled;
private MetricsUtils.HistogramDelta mUserChangedAutofilledField;
private MetricsUtils.HistogramDelta mUserChangedNonAutofilledField;
private MetricsUtils.HistogramDelta mAutofillWebViewCreatedByActivityContext;
private MetricsUtils.HistogramDelta mAutofillWebViewCreatedByAppContext;
private volatile Integer mSourceValue;
private HashMap<MetricsUtils.HistogramDelta, Integer> mSubmissionSourceDelta;
private volatile Integer mHistogramSimpleCount;
}
@Rule
public AwActivityTestRule mRule = new AwActivityTestRule();
private TestWebServer mWebServer;
private AwTestContainerView mTestContainerView;
private AwAutofillTestClient mContentsClient;
private CallbackHelper mCallbackHelper = new CallbackHelper();
......@@ -745,8 +749,9 @@ public class AwAutofillTest {
private AwAutofillSessionUMATestHelper mUMATestHelper;
@Before
public void setUp() {
mUMATestHelper = new AwAutofillSessionUMATestHelper(this);
public void setUp() throws Exception {
mWebServer = TestWebServer.start();
mUMATestHelper = new AwAutofillSessionUMATestHelper(this, mWebServer);
mContentsClient = new AwAutofillTestClient();
mTestContainerView = mRule.createAwTestContainerViewOnMainSync(
mContentsClient, false, new TestDependencyFactory() {
......@@ -762,6 +767,11 @@ public class AwAutofillTest {
AwActivityTestRule.enableJavaScriptOnUiThread(mAwContents);
}
@After
public void tearDown() {
mWebServer.shutdown();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
......@@ -785,37 +795,31 @@ public class AwAutofillTest {
}
private void internalTestTriggerTest() 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'>"
+ "<input type='submit'>"
+ "</form></body></html>";
try {
int cnt = 0;
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "text1");
// Note that we currently depend on keyboard app's behavior.
// TODO(changwan): mock out IME interaction.
Assert.assertTrue(DOMUtils.clickNode(mTestContainerView.getWebContents(), "text1"));
cnt += waitForCallbackAndVerifyTypes(
cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED});
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
executeJavaScriptAndWaitForResult("document.getElementById('text1').blur();");
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VIEW_EXITED});
} finally {
webServer.shutdown();
}
int cnt = 0;
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "text1");
// Note that we currently depend on keyboard app's behavior.
// TODO(changwan): mock out IME interaction.
Assert.assertTrue(DOMUtils.clickNode(mTestContainerView.getWebContents(), "text1"));
cnt += waitForCallbackAndVerifyTypes(
cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED});
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
executeJavaScriptAndWaitForResult("document.getElementById('text1').blur();");
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VIEW_EXITED});
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testBasicAutofill() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<label>User Name:</label>"
+ "<input type='text' id='text1' name='name' maxlength='30'"
......@@ -832,218 +836,201 @@ public class AwAutofillTest {
+ "<input type='image' id='image1'>"
+ "</form></body></html>";
final int totalControls = 4; // text1, checkbox1, select1, textarea1
try {
int cnt = 0;
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(totalControls, viewStructure.getChildCount());
// Verify form filled correctly in ViewStructure.
URL pageURL = new URL(url);
String webDomain =
new URL(pageURL.getProtocol(), pageURL.getHost(), pageURL.getPort(), "/")
.toString();
assertEquals(webDomain, viewStructure.getWebDomain());
// WebView shouldn't set class name.
assertNull(viewStructure.getClassName());
Bundle extras = viewStructure.getExtras();
assertEquals(
"AwAutofillTest", extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_NAME"));
assertTrue(0 < extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_VERSION").length());
TestViewStructure.AwHtmlInfo htmlInfoForm = viewStructure.getHtmlInfo();
assertEquals("form", htmlInfoForm.getTag());
assertEquals("formname", htmlInfoForm.getAttribute("name"));
// Verify input text control filled correctly in ViewStructure.
TestViewStructure child0 = viewStructure.getChild(0);
assertEquals(View.AUTOFILL_TYPE_TEXT, child0.getAutofillType());
assertEquals("placeholder@placeholder.com", child0.getHint());
assertEquals("name", child0.getAutofillHints()[0]);
assertEquals("given-name", child0.getAutofillHints()[1]);
assertFalse(child0.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child0.getDimensScrollX());
assertEquals(0, child0.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo0 = child0.getHtmlInfo();
assertEquals("text", htmlInfo0.getAttribute("type"));
assertEquals("text1", htmlInfo0.getAttribute("id"));
assertEquals("name", htmlInfo0.getAttribute("name"));
assertEquals("User Name:", htmlInfo0.getAttribute("label"));
assertEquals("30", htmlInfo0.getAttribute("maxlength"));
assertEquals("NAME_FIRST", htmlInfo0.getAttribute("ua-autofill-hints"));
// Verify checkbox control filled correctly in ViewStructure.
TestViewStructure child1 = viewStructure.getChild(1);
assertEquals(View.AUTOFILL_TYPE_TOGGLE, child1.getAutofillType());
assertEquals("", child1.getHint());
assertNull(child1.getAutofillHints());
assertFalse(child1.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child1.getDimensScrollX());
assertEquals(0, child1.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo1 = child1.getHtmlInfo();
assertEquals("checkbox", htmlInfo1.getAttribute("type"));
assertEquals("checkbox1", htmlInfo1.getAttribute("id"));
assertEquals("showpassword", htmlInfo1.getAttribute("name"));
assertEquals("", htmlInfo1.getAttribute("label"));
assertNull(htmlInfo1.getAttribute("maxlength"));
assertNull(htmlInfo1.getAttribute("ua-autofill-hints"));
// Verify select control filled correctly in ViewStructure.
TestViewStructure child2 = viewStructure.getChild(2);
assertEquals(View.AUTOFILL_TYPE_LIST, child2.getAutofillType());
assertEquals("", child2.getHint());
assertNull(child2.getAutofillHints());
assertFalse(child2.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child2.getDimensScrollX());
assertEquals(0, child2.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo2 = child2.getHtmlInfo();
assertEquals("month", htmlInfo2.getAttribute("name"));
assertEquals("select1", htmlInfo2.getAttribute("id"));
CharSequence[] options = child2.getAutofillOptions();
assertEquals("Jan", options[0]);
assertEquals("Feb", options[1]);
// Verify textarea control is filled correctly in ViewStructure.
TestViewStructure child3 = viewStructure.getChild(3);
assertEquals(View.AUTOFILL_TYPE_TEXT, child3.getAutofillType());
assertEquals("", child3.getHint());
assertNull(child3.getAutofillHints());
assertFalse(child3.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child3.getDimensScrollX());
assertEquals(0, child3.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo3 = child3.getHtmlInfo();
assertEquals("textarea1", htmlInfo3.getAttribute("name"));
// Autofill form and verify filled values.
SparseArray<AutofillValue> values = new SparseArray<AutofillValue>();
values.append(child0.getId(), AutofillValue.forText("example@example.com"));
values.append(child1.getId(), AutofillValue.forToggle(true));
values.append(child2.getId(), AutofillValue.forList(1));
values.append(child3.getId(), AutofillValue.forText("aaa"));
cnt = getCallbackCount();
clearChangedValues();
invokeAutofill(values);
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED,
AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED});
// Verify form filled by Javascript
String value0 =
executeJavaScriptAndWaitForResult("document.getElementById('text1').value;");
assertEquals("\"example@example.com\"", value0);
String value1 = executeJavaScriptAndWaitForResult(
"document.getElementById('checkbox1').value;");
assertEquals("\"on\"", value1);
String value2 =
executeJavaScriptAndWaitForResult("document.getElementById('select1').value;");
assertEquals("\"2\"", value2);
String value3 = executeJavaScriptAndWaitForResult(
"document.getElementById('textarea1').value;");
assertEquals("\"aaa\"", value3);
ArrayList<Pair<Integer, AutofillValue>> changedValues = getChangedValues();
assertEquals("example@example.com", changedValues.get(0).second.getTextValue());
assertTrue(changedValues.get(1).second.getToggleValue());
assertEquals(1, changedValues.get(2).second.getListValue());
} finally {
webServer.shutdown();
}
int cnt = 0;
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(totalControls, viewStructure.getChildCount());
// Verify form filled correctly in ViewStructure.
URL pageURL = new URL(url);
String webDomain = new URL(pageURL.getProtocol(), pageURL.getHost(), pageURL.getPort(), "/")
.toString();
assertEquals(webDomain, viewStructure.getWebDomain());
// WebView shouldn't set class name.
assertNull(viewStructure.getClassName());
Bundle extras = viewStructure.getExtras();
assertEquals("AwAutofillTest", extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_NAME"));
assertTrue(0 < extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_VERSION").length());
TestViewStructure.AwHtmlInfo htmlInfoForm = viewStructure.getHtmlInfo();
assertEquals("form", htmlInfoForm.getTag());
assertEquals("formname", htmlInfoForm.getAttribute("name"));
// Verify input text control filled correctly in ViewStructure.
TestViewStructure child0 = viewStructure.getChild(0);
assertEquals(View.AUTOFILL_TYPE_TEXT, child0.getAutofillType());
assertEquals("placeholder@placeholder.com", child0.getHint());
assertEquals("name", child0.getAutofillHints()[0]);
assertEquals("given-name", child0.getAutofillHints()[1]);
assertFalse(child0.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child0.getDimensScrollX());
assertEquals(0, child0.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo0 = child0.getHtmlInfo();
assertEquals("text", htmlInfo0.getAttribute("type"));
assertEquals("text1", htmlInfo0.getAttribute("id"));
assertEquals("name", htmlInfo0.getAttribute("name"));
assertEquals("User Name:", htmlInfo0.getAttribute("label"));
assertEquals("30", htmlInfo0.getAttribute("maxlength"));
assertEquals("NAME_FIRST", htmlInfo0.getAttribute("ua-autofill-hints"));
// Verify checkbox control filled correctly in ViewStructure.
TestViewStructure child1 = viewStructure.getChild(1);
assertEquals(View.AUTOFILL_TYPE_TOGGLE, child1.getAutofillType());
assertEquals("", child1.getHint());
assertNull(child1.getAutofillHints());
assertFalse(child1.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child1.getDimensScrollX());
assertEquals(0, child1.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo1 = child1.getHtmlInfo();
assertEquals("checkbox", htmlInfo1.getAttribute("type"));
assertEquals("checkbox1", htmlInfo1.getAttribute("id"));
assertEquals("showpassword", htmlInfo1.getAttribute("name"));
assertEquals("", htmlInfo1.getAttribute("label"));
assertNull(htmlInfo1.getAttribute("maxlength"));
assertNull(htmlInfo1.getAttribute("ua-autofill-hints"));
// Verify select control filled correctly in ViewStructure.
TestViewStructure child2 = viewStructure.getChild(2);
assertEquals(View.AUTOFILL_TYPE_LIST, child2.getAutofillType());
assertEquals("", child2.getHint());
assertNull(child2.getAutofillHints());
assertFalse(child2.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child2.getDimensScrollX());
assertEquals(0, child2.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo2 = child2.getHtmlInfo();
assertEquals("month", htmlInfo2.getAttribute("name"));
assertEquals("select1", htmlInfo2.getAttribute("id"));
CharSequence[] options = child2.getAutofillOptions();
assertEquals("Jan", options[0]);
assertEquals("Feb", options[1]);
// Verify textarea control is filled correctly in ViewStructure.
TestViewStructure child3 = viewStructure.getChild(3);
assertEquals(View.AUTOFILL_TYPE_TEXT, child3.getAutofillType());
assertEquals("", child3.getHint());
assertNull(child3.getAutofillHints());
assertFalse(child3.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child3.getDimensScrollX());
assertEquals(0, child3.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo3 = child3.getHtmlInfo();
assertEquals("textarea1", htmlInfo3.getAttribute("name"));
// Autofill form and verify filled values.
SparseArray<AutofillValue> values = new SparseArray<AutofillValue>();
values.append(child0.getId(), AutofillValue.forText("example@example.com"));
values.append(child1.getId(), AutofillValue.forToggle(true));
values.append(child2.getId(), AutofillValue.forList(1));
values.append(child3.getId(), AutofillValue.forText("aaa"));
cnt = getCallbackCount();
clearChangedValues();
invokeAutofill(values);
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED,
AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED});
// Verify form filled by Javascript
String value0 =
executeJavaScriptAndWaitForResult("document.getElementById('text1').value;");
assertEquals("\"example@example.com\"", value0);
String value1 =
executeJavaScriptAndWaitForResult("document.getElementById('checkbox1').value;");
assertEquals("\"on\"", value1);
String value2 =
executeJavaScriptAndWaitForResult("document.getElementById('select1').value;");
assertEquals("\"2\"", value2);
String value3 =
executeJavaScriptAndWaitForResult("document.getElementById('textarea1').value;");
assertEquals("\"aaa\"", value3);
ArrayList<Pair<Integer, AutofillValue>> changedValues = getChangedValues();
assertEquals("example@example.com", changedValues.get(0).second.getTextValue());
assertTrue(changedValues.get(1).second.getToggleValue());
assertEquals(1, changedValues.get(2).second.getListValue());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testNotifyVirtualValueChanged() 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></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);
final String url = mWebServer.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});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
// Check if NotifyVirtualValueChanged() called and value is 'a'.
assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue());
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
// Check if NotifyVirtualValueChanged() called again, first value is 'a',
// second value is 'ab', and both time has the same id.
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
values = getChangedValues();
assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue());
assertEquals("ab", values.get(1).second.getTextValue());
assertEquals(values.get(0).first, values.get(1).first);
} finally {
webServer.shutdown();
}
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
// Check if NotifyVirtualValueChanged() called and value is 'a'.
assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue());
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
// Check if NotifyVirtualValueChanged() called again, first value is 'a',
// second value is 'ab', and both time has the same id.
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
values = getChangedValues();
assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue());
assertEquals("ab", values.get(1).second.getTextValue());
assertEquals(values.get(0).first, values.get(1).first);
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testJavascriptNotTriggerNotifyVirtualValueChanged() 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></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});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
// Check if NotifyVirtualValueChanged() called and value is 'a'.
assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue());
executeJavaScriptAndWaitForResult("document.getElementById('text1').value='c';");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// There is no AUTOFILL_CANCEL from Android P.
assertEquals(2, getCallbackCount());
} else {
assertEquals(3, getCallbackCount());
}
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
// Check if NotifyVirtualValueChanged() called one more time and value is 'cb', this
// means javascript change didn't trigger the NotifyVirtualValueChanged().
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
values = getChangedValues();
assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue());
assertEquals("cb", values.get(1).second.getTextValue());
assertEquals(values.get(0).first, values.get(1).first);
} finally {
webServer.shutdown();
}
final String url = mWebServer.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});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
// Check if NotifyVirtualValueChanged() called and value is 'a'.
assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue());
executeJavaScriptAndWaitForResult("document.getElementById('text1').value='c';");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// There is no AUTOFILL_CANCEL from Android P.
assertEquals(2, getCallbackCount());
} else {
assertEquals(3, getCallbackCount());
}
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
// Check if NotifyVirtualValueChanged() called one more time and value is 'cb', this
// means javascript change didn't trigger the NotifyVirtualValueChanged().
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
values = getChangedValues();
assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue());
assertEquals("cb", values.get(1).second.getTextValue());
assertEquals(values.get(0).first, values.get(1).first);
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testCommit() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data =
"<html><head></head><body><form action='a.html' name='formname' id='formid'>"
+ "<input type='text' id='text1' name='username'"
......@@ -1051,36 +1038,31 @@ public class AwAutofillTest {
+ "<input type='password' id='passwordid' name='passwordname'"
+ "<input type='submit'>"
+ "</form></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});
invokeOnProvideAutoFillVirtualStructure();
// Fill the password.
executeJavaScriptAndWaitForResult("document.getElementById('passwordid').select();");
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
clearChangedValues();
// Submit form.
executeJavaScriptAndWaitForResult("document.getElementById('formid').submit();");
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue());
assertEquals("b", values.get(1).second.getTextValue());
assertEquals(SubmissionSource.FORM_SUBMISSION, mSubmissionSource);
} finally {
webServer.shutdown();
}
final String url = mWebServer.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});
invokeOnProvideAutoFillVirtualStructure();
// Fill the password.
executeJavaScriptAndWaitForResult("document.getElementById('passwordid').select();");
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VALUE_CHANGED});
clearChangedValues();
// Submit form.
executeJavaScriptAndWaitForResult("document.getElementById('formid').submit();");
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue());
assertEquals("b", values.get(1).second.getTextValue());
assertEquals(SubmissionSource.FORM_SUBMISSION, mSubmissionSource);
}
@Test
......@@ -1100,7 +1082,6 @@ public class AwAutofillTest {
@SmallTest
@Feature({"AndroidWebView"})
public void testMovingToOtherForm() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data =
"<html><head></head><body><form action='a.html' name='formname' id='formid'>"
+ "<input type='text' id='text1' name='username'"
......@@ -1111,23 +1092,19 @@ public class AwAutofillTest {
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
+ "<input type='submit'>"
+ "</form></body></html>";
try {
int cnt = 0;
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// Move to form2, cancel() should be called again.
executeJavaScriptAndWaitForResult("document.getElementById('text2').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED,
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
} finally {
webServer.shutdown();
}
int cnt = 0;
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// Move to form2, cancel() should be called again.
executeJavaScriptAndWaitForResult("document.getElementById('text2').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED,
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
}
/**
......@@ -1139,7 +1116,6 @@ public class AwAutofillTest {
public void testSwitchFromIFrame() throws Throwable {
// we intentionally load main frame and iframe from the same URL and make both have the
// similar form, so the new session is triggered by frame change
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form name='formname' id='formid'>"
+ "<input type='text' id='text1' name='username'"
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
......@@ -1152,62 +1128,58 @@ public class AwAutofillTest {
+ " autofocus>"
+ "<input type='submit'></form>"
+ "</body></html>";
try {
final String url = webServer.setResponse(FILE, data, null);
mContentsClient.setShouldInterceptRequestImpl(
new AwAutofillTestClient.ShouldInterceptRequestImpl() {
private int mCallCount;
@Override
public AwWebResourceResponse shouldInterceptRequest(
AwWebResourceRequest request) {
try {
if (url.equals(request.url)) {
// Only intercept the iframe's request.
if (mCallCount == 1) {
final String encoding = "UTF-8";
return new AwWebResourceResponse("text/html", encoding,
new ByteArrayInputStream(
iframeData.getBytes(encoding)));
}
mCallCount++;
final String url = mWebServer.setResponse(FILE, data, null);
mContentsClient.setShouldInterceptRequestImpl(
new AwAutofillTestClient.ShouldInterceptRequestImpl() {
private int mCallCount;
@Override
public AwWebResourceResponse shouldInterceptRequest(
AwWebResourceRequest request) {
try {
if (url.equals(request.url)) {
// Only intercept the iframe's request.
if (mCallCount == 1) {
final String encoding = "UTF-8";
return new AwWebResourceResponse("text/html", encoding,
new ByteArrayInputStream(
iframeData.getBytes(encoding)));
}
return null;
} catch (Exception e) {
throw new RuntimeException(e);
mCallCount++;
}
return null;
} catch (Exception e) {
throw new RuntimeException(e);
}
});
loadUrlSync(url);
// Trigger the autofill in iframe.
int count = clearEventQueueAndGetCallCount();
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Verify autofill session triggered.
count += waitForCallbackAndVerifyTypes(count,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// Verify focus is in iframe.
assertEquals("true",
executeJavaScriptAndWaitForResult(
"document.getElementById('myframe').contentDocument.hasFocus()"));
// Move focus to the main frame form.
clearChangedValues();
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// The new session starts because cancel() has been called.
waitForCallbackAndVerifyTypes(count,
new Integer[] {AUTOFILL_VIEW_EXITED, AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED,
AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue());
// Verify focus isn't in iframe now.
assertEquals("false",
executeJavaScriptAndWaitForResult(
"document.getElementById('myframe').contentDocument.hasFocus()"));
} finally {
webServer.shutdown();
}
}
});
loadUrlSync(url);
// Trigger the autofill in iframe.
int count = clearEventQueueAndGetCallCount();
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Verify autofill session triggered.
count += waitForCallbackAndVerifyTypes(count,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// Verify focus is in iframe.
assertEquals("true",
executeJavaScriptAndWaitForResult(
"document.getElementById('myframe').contentDocument.hasFocus()"));
// Move focus to the main frame form.
clearChangedValues();
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// The new session starts because cancel() has been called.
waitForCallbackAndVerifyTypes(count,
new Integer[] {AUTOFILL_VIEW_EXITED, AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED,
AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertEquals("a", values.get(0).second.getTextValue());
// Verify focus isn't in iframe now.
assertEquals("false",
executeJavaScriptAndWaitForResult(
"document.getElementById('myframe').contentDocument.hasFocus()"));
}
/**
......@@ -1218,25 +1190,19 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"})
public void testTouchingPasswordFieldTriggerQuery() throws Throwable {
int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data =
"<html><head></head><body><form action='a.html' name='formname' id='formid'>"
+ "<input type='password' id='passwordid' name='passwordname'"
+ "<input type='submit'>"
+ "</form></body></html>";
try {
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
} finally {
webServer.shutdown();
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "passwordid");
// Note that we currently depend on keyboard app's behavior.
// TODO(changwan): mock out IME interaction.
Assert.assertTrue(
DOMUtils.clickNode(mTestContainerView.getWebContents(), "passwordid"));
cnt += waitForCallbackAndVerifyTypes(
cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED});
}
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "passwordid");
// Note that we currently depend on keyboard app's behavior.
// TODO(changwan): mock out IME interaction.
Assert.assertTrue(DOMUtils.clickNode(mTestContainerView.getWebContents(), "passwordid"));
cnt += waitForCallbackAndVerifyTypes(
cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED});
}
/**
......@@ -1247,7 +1213,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"})
public void testSessionAliveAfterNavigation() throws Throwable {
int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>"
+ "<html>"
+ "<body>"
......@@ -1263,22 +1228,17 @@ public class AwAutofillTest {
+ "<body>"
+ "</body>"
+ "</html>";
try {
webServer.setResponse("/success.html", success, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; ");
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
assertEquals(SubmissionSource.PROBABLY_FORM_SUBMITTED, mSubmissionSource);
} finally {
webServer.shutdown();
}
mWebServer.setResponse("/success.html", success, null);
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; ");
waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
assertEquals(SubmissionSource.PROBABLY_FORM_SUBMITTED, mSubmissionSource);
}
/**
......@@ -1290,7 +1250,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"})
public void testNoSubmissionWithoutFillingForm() throws Throwable {
int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>"
+ "<html>"
+ "<body>"
......@@ -1306,16 +1265,12 @@ public class AwAutofillTest {
+ "<body>"
+ "</body>"
+ "</html>";
try {
final String successUrl = webServer.setResponse("/success.html", success, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; ");
// There is no callback. AUTOFILL_CANCEL shouldn't be invoked.
assertEquals(0, getCallbackCount());
} finally {
webServer.shutdown();
}
final String successUrl = mWebServer.setResponse("/success.html", success, null);
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; ");
// There is no callback. AUTOFILL_CANCEL shouldn't be invoked.
assertEquals(0, getCallbackCount());
}
@Test
......@@ -1326,7 +1281,6 @@ public class AwAutofillTest {
public void
testSelectControlChangeNotification() throws Throwable {
int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>"
+ "<html>"
+ "<body>"
......@@ -1337,28 +1291,24 @@ public class AwAutofillTest {
+ "</form>"
+ "</body>"
+ "</html>";
try {
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
clearChangedValues();
executeJavaScriptAndWaitForResult("document.getElementById('color').focus();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
// Use key B to select 'blue'.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
} finally {
webServer.shutdown();
}
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
clearChangedValues();
executeJavaScriptAndWaitForResult("document.getElementById('color').focus();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
// Use key B to select 'blue'.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
}
@Test
......@@ -1369,7 +1319,6 @@ public class AwAutofillTest {
public void
testSelectControlChangeStartAutofillSession() throws Throwable {
int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>"
+ "<html>"
+ "<body>"
......@@ -1380,36 +1329,32 @@ public class AwAutofillTest {
+ "</form>"
+ "</body>"
+ "</html>";
try {
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
// Change select control first shall start autofill session.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
// Use key B to select 'blue'.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
// Verify the autofill session started by select control has dimens filled.
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(2, viewStructure.getChildCount());
assertFalse(viewStructure.getChild(0).getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, viewStructure.getChild(0).getDimensScrollX());
assertEquals(0, viewStructure.getChild(0).getDimensScrollY());
assertFalse(viewStructure.getChild(1).getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, viewStructure.getChild(1).getDimensScrollX());
assertEquals(0, viewStructure.getChild(1).getDimensScrollY());
} finally {
webServer.shutdown();
}
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
// Change select control first shall start autofill session.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
// Use key B to select 'blue'.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
// Verify the autofill session started by select control has dimens filled.
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(2, viewStructure.getChildCount());
assertFalse(viewStructure.getChild(0).getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, viewStructure.getChild(0).getDimensScrollX());
assertEquals(0, viewStructure.getChild(0).getDimensScrollY());
assertFalse(viewStructure.getChild(1).getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, viewStructure.getChild(1).getDimensScrollX());
assertEquals(0, viewStructure.getChild(1).getDimensScrollY());
}
@Test
......@@ -1417,7 +1362,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"})
public void testUserInitiatedJavascriptSelectControlChangeNotification() throws Throwable {
int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>"
+ "<html>"
+ "<body>"
......@@ -1433,20 +1377,16 @@ public class AwAutofillTest {
+ "</form>"
+ "</body>"
+ "</html>";
try {
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
// Change select control first shall start autofill session.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
} finally {
webServer.shutdown();
}
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
// Change select control first shall start autofill session.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
}
@Test
......@@ -1454,7 +1394,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"})
public void testJavascriptNotTriggerSelectControlChangeNotification() throws Throwable {
int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>"
+ "<html>"
+ "<body onload='myFunction();'>"
......@@ -1470,31 +1409,26 @@ public class AwAutofillTest {
+ "</form>"
+ "</body>"
+ "</html>";
try {
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
// There is no good way to verify no callback occurred, we just simulate user trigger
// the autofill and verify autofill is only triggered once, then this proves javascript
// didn't trigger the autofill, since
// testUserInitiatedJavascriptSelectControlChangeNotification verified user's triggering
// work.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
} finally {
webServer.shutdown();
}
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
// There is no good way to verify no callback occurred, we just simulate user trigger
// the autofill and verify autofill is only triggered once, then this proves javascript
// didn't trigger the autofill, since
// testUserInitiatedJavascriptSelectControlChangeNotification verified user's triggering
// work.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(1, values.size());
assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUaAutofillHints() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<label for=\"frmAddressB\">Address</label>"
+ "<input name=\"bill-address\" id=\"frmAddressB\">"
......@@ -1510,316 +1444,244 @@ public class AwAutofillTest {
+ "<input type='submit'>"
+ "</form></body></html>";
final int totalControls = 6;
try {
int cnt = 0;
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('frmAddressB').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(totalControls, viewStructure.getChildCount());
TestViewStructure child0 = viewStructure.getChild(0);
TestViewStructure.AwHtmlInfo htmlInfo0 = child0.getHtmlInfo();
assertEquals("ADDRESS_HOME_LINE1", htmlInfo0.getAttribute("ua-autofill-hints"));
TestViewStructure child1 = viewStructure.getChild(1);
TestViewStructure.AwHtmlInfo htmlInfo1 = child1.getHtmlInfo();
assertEquals("ADDRESS_HOME_CITY", htmlInfo1.getAttribute("ua-autofill-hints"));
TestViewStructure child2 = viewStructure.getChild(2);
TestViewStructure.AwHtmlInfo htmlInfo2 = child2.getHtmlInfo();
assertEquals("ADDRESS_HOME_STATE", htmlInfo2.getAttribute("ua-autofill-hints"));
TestViewStructure child3 = viewStructure.getChild(3);
TestViewStructure.AwHtmlInfo htmlInfo3 = child3.getHtmlInfo();
assertEquals("ADDRESS_HOME_ZIP", htmlInfo3.getAttribute("ua-autofill-hints"));
TestViewStructure child4 = viewStructure.getChild(4);
TestViewStructure.AwHtmlInfo htmlInfo4 = child4.getHtmlInfo();
assertNull(htmlInfo4.getAttribute("ua-autofill-hints"));
TestViewStructure child5 = viewStructure.getChild(5);
TestViewStructure.AwHtmlInfo htmlInfo5 = child5.getHtmlInfo();
assertEquals("ADDRESS_HOME_COUNTRY", htmlInfo5.getAttribute("ua-autofill-hints"));
} finally {
webServer.shutdown();
}
int cnt = 0;
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('frmAddressB').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(totalControls, viewStructure.getChildCount());
TestViewStructure child0 = viewStructure.getChild(0);
TestViewStructure.AwHtmlInfo htmlInfo0 = child0.getHtmlInfo();
assertEquals("ADDRESS_HOME_LINE1", htmlInfo0.getAttribute("ua-autofill-hints"));
TestViewStructure child1 = viewStructure.getChild(1);
TestViewStructure.AwHtmlInfo htmlInfo1 = child1.getHtmlInfo();
assertEquals("ADDRESS_HOME_CITY", htmlInfo1.getAttribute("ua-autofill-hints"));
TestViewStructure child2 = viewStructure.getChild(2);
TestViewStructure.AwHtmlInfo htmlInfo2 = child2.getHtmlInfo();
assertEquals("ADDRESS_HOME_STATE", htmlInfo2.getAttribute("ua-autofill-hints"));
TestViewStructure child3 = viewStructure.getChild(3);
TestViewStructure.AwHtmlInfo htmlInfo3 = child3.getHtmlInfo();
assertEquals("ADDRESS_HOME_ZIP", htmlInfo3.getAttribute("ua-autofill-hints"));
TestViewStructure child4 = viewStructure.getChild(4);
TestViewStructure.AwHtmlInfo htmlInfo4 = child4.getHtmlInfo();
assertNull(htmlInfo4.getAttribute("ua-autofill-hints"));
TestViewStructure child5 = viewStructure.getChild(5);
TestViewStructure.AwHtmlInfo htmlInfo5 = child5.getHtmlInfo();
assertEquals("ADDRESS_HOME_COUNTRY", htmlInfo5.getAttribute("ua-autofill-hints"));
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession();
assertEquals(
AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserSelectNotSuggestionUserChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
int count = mUMATestHelper.getHistogramSampleCount(
AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME);
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA
.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
assertEquals(count + 1,
mUMATestHelper.getHistogramSampleCount(
AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME));
} finally {
webServer.shutdown();
}
int count = mUMATestHelper.getHistogramSampleCount(
AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME);
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession();
assertEquals(
AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
assertEquals(count + 1,
mUMATestHelper.getHistogramSampleCount(
AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME));
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserNotSelectSuggestionUserChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm();
assertEquals(
AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMANoSuggestionUserChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedNonAutofilledField();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedNonAutofilledField();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMANoSuggestionUserChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedNonAutofilledField();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedNonAutofilledField();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserNotChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.submitForm();
assertEquals(
AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA
.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.startNewSession();
assertEquals(
AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserSelectNotSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA
.USER_NOT_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA
.USER_NOT_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserNotSelectSuggestionUserNotChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA
.USER_NOT_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.submitForm();
assertEquals(
AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMANoSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMANoSuggestionUserNotChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm();
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMANoCallbackFromFramework() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.NO_CALLBACK_FORM_FRAMEWORK,
mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
mUMATestHelper.startNewSession();
assertEquals(
AutofillProviderUMA.NO_CALLBACK_FORM_FRAMEWORK, mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
}
@Test
......@@ -1827,52 +1689,37 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"})
public void testUMAAutofillDisabled() throws Throwable {
mTestAutofillManagerWrapper.setDisabled();
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
mUMATestHelper.verifyAutofillDisabled();
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
mUMATestHelper.verifyAutofillDisabled();
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAAutofillEnabled() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
mUMATestHelper.verifyAutofillEnabled();
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
mUMATestHelper.verifyAutofillEnabled();
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUMAUserChangeAutofilledField() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.simulateUserChangeAutofilledField();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedAutofilledField();
} finally {
webServer.shutdown();
}
mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.simulateUserChangeAutofilledField();
mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue());
assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedAutofilledField();
}
@Test
......@@ -1887,40 +1734,35 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"})
@FlakyTest(message = "crbug.com/1033179")
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});
final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url);
int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
// Moved view, the position change trigger additional AUTOFILL_VIEW_EXITED and
// AUTOFILL_VIEW_ENTERED.
scrollToBottom();
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
List<Integer> expectedValues = new ArrayList<>();
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
// On Android version below P scroll triggers additional
// AUTOFILL_VIEW_ENTERED (@see AutofillProviderImpl#onTextFieldDidScroll).
if (VERSION.SDK_INT < Build.VERSION_CODES.P) {
expectedValues.add(AUTOFILL_VIEW_ENTERED);
}
// Check if NotifyVirtualValueChanged() called again and with extra AUTOFILL_VIEW_EXITED
// and AUTOFILL_VIEW_ENTERED
expectedValues.addAll(Arrays.asList(
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED));
waitForCallbackAndVerifyTypes(cnt, expectedValues.toArray(new Integer[0]));
} finally {
webServer.shutdown();
}
// Moved view, the position change trigger additional AUTOFILL_VIEW_EXITED and
// AUTOFILL_VIEW_ENTERED.
scrollToBottom();
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_B);
List<Integer> expectedValues = new ArrayList<>();
// On Android version below P scroll triggers additional
// AUTOFILL_VIEW_ENTERED (@see AutofillProviderImpl#onTextFieldDidScroll).
if (VERSION.SDK_INT < Build.VERSION_CODES.P) {
expectedValues.add(AUTOFILL_VIEW_ENTERED);
}
// Check if NotifyVirtualValueChanged() called again and with extra AUTOFILL_VIEW_EXITED
// and AUTOFILL_VIEW_ENTERED
expectedValues.addAll(
Arrays.asList(AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED));
waitForCallbackAndVerifyTypes(cnt, expectedValues.toArray(new Integer[0]));
}
private void scrollToBottom() {
......
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