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; ...@@ -31,6 +31,7 @@ import android.view.WindowManager;
import android.view.autofill.AutofillId; import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue; import android.view.autofill.AutofillValue;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -547,8 +548,24 @@ public class AwAutofillTest { ...@@ -547,8 +548,24 @@ public class AwAutofillTest {
public static final int NO_FORM_SUBMISSION = -1; 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; mTest = test;
mWebServer = webServer;
initDeltaSamples(); initDeltaSamples();
} }
...@@ -575,8 +592,8 @@ public class AwAutofillTest { ...@@ -575,8 +592,8 @@ public class AwAutofillTest {
return value; return value;
} }
public void triggerAutofill(TestWebServer webServer) throws Throwable { public void triggerAutofill() throws Throwable {
final String url = webServer.setResponse(FILE, DATA, null); final String url = mWebServer.setResponse(FILE, DATA, null);
mTest.loadUrlSync(url); mTest.loadUrlSync(url);
mTest.executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); mTest.executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); mTest.dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
...@@ -715,25 +732,12 @@ public class AwAutofillTest { ...@@ -715,25 +732,12 @@ public class AwAutofillTest {
assertEquals(0, mAutofillWebViewCreatedByAppContext.getDelta()); 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 @Rule
public AwActivityTestRule mRule = new AwActivityTestRule(); public AwActivityTestRule mRule = new AwActivityTestRule();
private TestWebServer mWebServer;
private AwTestContainerView mTestContainerView; private AwTestContainerView mTestContainerView;
private AwAutofillTestClient mContentsClient; private AwAutofillTestClient mContentsClient;
private CallbackHelper mCallbackHelper = new CallbackHelper(); private CallbackHelper mCallbackHelper = new CallbackHelper();
...@@ -745,8 +749,9 @@ public class AwAutofillTest { ...@@ -745,8 +749,9 @@ public class AwAutofillTest {
private AwAutofillSessionUMATestHelper mUMATestHelper; private AwAutofillSessionUMATestHelper mUMATestHelper;
@Before @Before
public void setUp() { public void setUp() throws Exception {
mUMATestHelper = new AwAutofillSessionUMATestHelper(this); mWebServer = TestWebServer.start();
mUMATestHelper = new AwAutofillSessionUMATestHelper(this, mWebServer);
mContentsClient = new AwAutofillTestClient(); mContentsClient = new AwAutofillTestClient();
mTestContainerView = mRule.createAwTestContainerViewOnMainSync( mTestContainerView = mRule.createAwTestContainerViewOnMainSync(
mContentsClient, false, new TestDependencyFactory() { mContentsClient, false, new TestDependencyFactory() {
...@@ -762,6 +767,11 @@ public class AwAutofillTest { ...@@ -762,6 +767,11 @@ public class AwAutofillTest {
AwActivityTestRule.enableJavaScriptOnUiThread(mAwContents); AwActivityTestRule.enableJavaScriptOnUiThread(mAwContents);
} }
@After
public void tearDown() {
mWebServer.shutdown();
}
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
...@@ -785,15 +795,13 @@ public class AwAutofillTest { ...@@ -785,15 +795,13 @@ public class AwAutofillTest {
} }
private void internalTestTriggerTest() throws Throwable { private void internalTestTriggerTest() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>" final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<input type='text' id='text1' name='username'" + "<input type='text' id='text1' name='username'"
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>" + " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
+ "<input type='submit'>" + "<input type='submit'>"
+ "</form></body></html>"; + "</form></body></html>";
try {
int cnt = 0; int cnt = 0;
final String url = webServer.setResponse(FILE, data, null); final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "text1"); DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "text1");
// Note that we currently depend on keyboard app's behavior. // Note that we currently depend on keyboard app's behavior.
...@@ -806,16 +814,12 @@ public class AwAutofillTest { ...@@ -806,16 +814,12 @@ public class AwAutofillTest {
executeJavaScriptAndWaitForResult("document.getElementById('text1').blur();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').blur();");
waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VIEW_EXITED}); waitForCallbackAndVerifyTypes(cnt, new Integer[] {AUTOFILL_VIEW_EXITED});
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testBasicAutofill() throws Throwable { public void testBasicAutofill() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>" final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<label>User Name:</label>" + "<label>User Name:</label>"
+ "<input type='text' id='text1' name='name' maxlength='30'" + "<input type='text' id='text1' name='name' maxlength='30'"
...@@ -832,9 +836,8 @@ public class AwAutofillTest { ...@@ -832,9 +836,8 @@ public class AwAutofillTest {
+ "<input type='image' id='image1'>" + "<input type='image' id='image1'>"
+ "</form></body></html>"; + "</form></body></html>";
final int totalControls = 4; // text1, checkbox1, select1, textarea1 final int totalControls = 4; // text1, checkbox1, select1, textarea1
try {
int cnt = 0; int cnt = 0;
final String url = webServer.setResponse(FILE, data, null); final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
...@@ -847,15 +850,13 @@ public class AwAutofillTest { ...@@ -847,15 +850,13 @@ public class AwAutofillTest {
// Verify form filled correctly in ViewStructure. // Verify form filled correctly in ViewStructure.
URL pageURL = new URL(url); URL pageURL = new URL(url);
String webDomain = String webDomain = new URL(pageURL.getProtocol(), pageURL.getHost(), pageURL.getPort(), "/")
new URL(pageURL.getProtocol(), pageURL.getHost(), pageURL.getPort(), "/")
.toString(); .toString();
assertEquals(webDomain, viewStructure.getWebDomain()); assertEquals(webDomain, viewStructure.getWebDomain());
// WebView shouldn't set class name. // WebView shouldn't set class name.
assertNull(viewStructure.getClassName()); assertNull(viewStructure.getClassName());
Bundle extras = viewStructure.getExtras(); Bundle extras = viewStructure.getExtras();
assertEquals( assertEquals("AwAutofillTest", extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_NAME"));
"AwAutofillTest", extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_NAME"));
assertTrue(0 < extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_VERSION").length()); assertTrue(0 < extras.getCharSequence("VIRTUAL_STRUCTURE_PROVIDER_VERSION").length());
TestViewStructure.AwHtmlInfo htmlInfoForm = viewStructure.getHtmlInfo(); TestViewStructure.AwHtmlInfo htmlInfoForm = viewStructure.getHtmlInfo();
assertEquals("form", htmlInfoForm.getTag()); assertEquals("form", htmlInfoForm.getTag());
...@@ -941,35 +942,30 @@ public class AwAutofillTest { ...@@ -941,35 +942,30 @@ public class AwAutofillTest {
String value0 = String value0 =
executeJavaScriptAndWaitForResult("document.getElementById('text1').value;"); executeJavaScriptAndWaitForResult("document.getElementById('text1').value;");
assertEquals("\"example@example.com\"", value0); assertEquals("\"example@example.com\"", value0);
String value1 = executeJavaScriptAndWaitForResult( String value1 =
"document.getElementById('checkbox1').value;"); executeJavaScriptAndWaitForResult("document.getElementById('checkbox1').value;");
assertEquals("\"on\"", value1); assertEquals("\"on\"", value1);
String value2 = String value2 =
executeJavaScriptAndWaitForResult("document.getElementById('select1').value;"); executeJavaScriptAndWaitForResult("document.getElementById('select1').value;");
assertEquals("\"2\"", value2); assertEquals("\"2\"", value2);
String value3 = executeJavaScriptAndWaitForResult( String value3 =
"document.getElementById('textarea1').value;"); executeJavaScriptAndWaitForResult("document.getElementById('textarea1').value;");
assertEquals("\"aaa\"", value3); assertEquals("\"aaa\"", value3);
ArrayList<Pair<Integer, AutofillValue>> changedValues = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> changedValues = getChangedValues();
assertEquals("example@example.com", changedValues.get(0).second.getTextValue()); assertEquals("example@example.com", changedValues.get(0).second.getTextValue());
assertTrue(changedValues.get(1).second.getToggleValue()); assertTrue(changedValues.get(1).second.getToggleValue());
assertEquals(1, changedValues.get(2).second.getListValue()); assertEquals(1, changedValues.get(2).second.getListValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testNotifyVirtualValueChanged() throws Throwable { public void testNotifyVirtualValueChanged() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>" final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<input type='text' id='text1' name='username'" + "<input type='text' id='text1' name='username'"
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>" + " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
+ "</form></body></html>"; + "</form></body></html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
int cnt = 0; int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
...@@ -992,22 +988,17 @@ public class AwAutofillTest { ...@@ -992,22 +988,17 @@ public class AwAutofillTest {
assertEquals("a", values.get(0).second.getTextValue()); assertEquals("a", values.get(0).second.getTextValue());
assertEquals("ab", values.get(1).second.getTextValue()); assertEquals("ab", values.get(1).second.getTextValue());
assertEquals(values.get(0).first, values.get(1).first); assertEquals(values.get(0).first, values.get(1).first);
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testJavascriptNotTriggerNotifyVirtualValueChanged() throws Throwable { public void testJavascriptNotTriggerNotifyVirtualValueChanged() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>" final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<input type='text' id='text1' name='username'" + "<input type='text' id='text1' name='username'"
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>" + " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
+ "</form></body></html>"; + "</form></body></html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
int cnt = 0; int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
...@@ -1034,16 +1025,12 @@ public class AwAutofillTest { ...@@ -1034,16 +1025,12 @@ public class AwAutofillTest {
assertEquals("a", values.get(0).second.getTextValue()); assertEquals("a", values.get(0).second.getTextValue());
assertEquals("cb", values.get(1).second.getTextValue()); assertEquals("cb", values.get(1).second.getTextValue());
assertEquals(values.get(0).first, values.get(1).first); assertEquals(values.get(0).first, values.get(1).first);
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testCommit() throws Throwable { public void testCommit() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = final String data =
"<html><head></head><body><form action='a.html' name='formname' id='formid'>" "<html><head></head><body><form action='a.html' name='formname' id='formid'>"
+ "<input type='text' id='text1' name='username'" + "<input type='text' id='text1' name='username'"
...@@ -1051,8 +1038,7 @@ public class AwAutofillTest { ...@@ -1051,8 +1038,7 @@ public class AwAutofillTest {
+ "<input type='password' id='passwordid' name='passwordname'" + "<input type='password' id='passwordid' name='passwordname'"
+ "<input type='submit'>" + "<input type='submit'>"
+ "</form></body></html>"; + "</form></body></html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
int cnt = 0; int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
...@@ -1071,16 +1057,12 @@ public class AwAutofillTest { ...@@ -1071,16 +1057,12 @@ public class AwAutofillTest {
// Submit form. // Submit form.
executeJavaScriptAndWaitForResult("document.getElementById('formid').submit();"); executeJavaScriptAndWaitForResult("document.getElementById('formid').submit();");
waitForCallbackAndVerifyTypes(cnt, waitForCallbackAndVerifyTypes(cnt,
new Integer[] { new Integer[] {AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues(); ArrayList<Pair<Integer, AutofillValue>> values = getChangedValues();
assertEquals(2, values.size()); assertEquals(2, values.size());
assertEquals("a", values.get(0).second.getTextValue()); assertEquals("a", values.get(0).second.getTextValue());
assertEquals("b", values.get(1).second.getTextValue()); assertEquals("b", values.get(1).second.getTextValue());
assertEquals(SubmissionSource.FORM_SUBMISSION, mSubmissionSource); assertEquals(SubmissionSource.FORM_SUBMISSION, mSubmissionSource);
} finally {
webServer.shutdown();
}
} }
@Test @Test
...@@ -1100,7 +1082,6 @@ public class AwAutofillTest { ...@@ -1100,7 +1082,6 @@ public class AwAutofillTest {
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testMovingToOtherForm() throws Throwable { public void testMovingToOtherForm() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = final String data =
"<html><head></head><body><form action='a.html' name='formname' id='formid'>" "<html><head></head><body><form action='a.html' name='formname' id='formid'>"
+ "<input type='text' id='text1' name='username'" + "<input type='text' id='text1' name='username'"
...@@ -1111,9 +1092,8 @@ public class AwAutofillTest { ...@@ -1111,9 +1092,8 @@ public class AwAutofillTest {
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>" + " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
+ "<input type='submit'>" + "<input type='submit'>"
+ "</form></body></html>"; + "</form></body></html>";
try {
int cnt = 0; int cnt = 0;
final String url = webServer.setResponse(FILE, data, null); final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
...@@ -1125,9 +1105,6 @@ public class AwAutofillTest { ...@@ -1125,9 +1105,6 @@ public class AwAutofillTest {
waitForCallbackAndVerifyTypes(cnt, waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED,
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED}); AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED});
} finally {
webServer.shutdown();
}
} }
/** /**
...@@ -1139,7 +1116,6 @@ public class AwAutofillTest { ...@@ -1139,7 +1116,6 @@ public class AwAutofillTest {
public void testSwitchFromIFrame() throws Throwable { public void testSwitchFromIFrame() throws Throwable {
// we intentionally load main frame and iframe from the same URL and make both have the // 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 // 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'>" final String data = "<html><head></head><body><form name='formname' id='formid'>"
+ "<input type='text' id='text1' name='username'" + "<input type='text' id='text1' name='username'"
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>" + " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
...@@ -1152,8 +1128,7 @@ public class AwAutofillTest { ...@@ -1152,8 +1128,7 @@ public class AwAutofillTest {
+ " autofocus>" + " autofocus>"
+ "<input type='submit'></form>" + "<input type='submit'></form>"
+ "</body></html>"; + "</body></html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
mContentsClient.setShouldInterceptRequestImpl( mContentsClient.setShouldInterceptRequestImpl(
new AwAutofillTestClient.ShouldInterceptRequestImpl() { new AwAutofillTestClient.ShouldInterceptRequestImpl() {
private int mCallCount; private int mCallCount;
...@@ -1205,9 +1180,6 @@ public class AwAutofillTest { ...@@ -1205,9 +1180,6 @@ public class AwAutofillTest {
assertEquals("false", assertEquals("false",
executeJavaScriptAndWaitForResult( executeJavaScriptAndWaitForResult(
"document.getElementById('myframe').contentDocument.hasFocus()")); "document.getElementById('myframe').contentDocument.hasFocus()"));
} finally {
webServer.shutdown();
}
} }
/** /**
...@@ -1218,26 +1190,20 @@ public class AwAutofillTest { ...@@ -1218,26 +1190,20 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testTouchingPasswordFieldTriggerQuery() throws Throwable { public void testTouchingPasswordFieldTriggerQuery() throws Throwable {
int cnt = 0; int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = final String data =
"<html><head></head><body><form action='a.html' name='formname' id='formid'>" "<html><head></head><body><form action='a.html' name='formname' id='formid'>"
+ "<input type='password' id='passwordid' name='passwordname'" + "<input type='password' id='passwordid' name='passwordname'"
+ "<input type='submit'>" + "<input type='submit'>"
+ "</form></body></html>"; + "</form></body></html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
} finally {
webServer.shutdown();
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "passwordid"); DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "passwordid");
// Note that we currently depend on keyboard app's behavior. // Note that we currently depend on keyboard app's behavior.
// TODO(changwan): mock out IME interaction. // TODO(changwan): mock out IME interaction.
Assert.assertTrue( Assert.assertTrue(DOMUtils.clickNode(mTestContainerView.getWebContents(), "passwordid"));
DOMUtils.clickNode(mTestContainerView.getWebContents(), "passwordid"));
cnt += waitForCallbackAndVerifyTypes( cnt += waitForCallbackAndVerifyTypes(
cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED}); cnt, new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED});
} }
}
/** /**
* This test is verifying the session is still alive after navigation. * This test is verifying the session is still alive after navigation.
...@@ -1247,7 +1213,6 @@ public class AwAutofillTest { ...@@ -1247,7 +1213,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testSessionAliveAfterNavigation() throws Throwable { public void testSessionAliveAfterNavigation() throws Throwable {
int cnt = 0; int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>" final String data = "<!DOCTYPE html>"
+ "<html>" + "<html>"
+ "<body>" + "<body>"
...@@ -1263,9 +1228,8 @@ public class AwAutofillTest { ...@@ -1263,9 +1228,8 @@ public class AwAutofillTest {
+ "<body>" + "<body>"
+ "</body>" + "</body>"
+ "</html>"; + "</html>";
try { mWebServer.setResponse("/success.html", success, null);
webServer.setResponse("/success.html", success, null); final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
...@@ -1273,12 +1237,8 @@ public class AwAutofillTest { ...@@ -1273,12 +1237,8 @@ public class AwAutofillTest {
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED}); new Integer[] {AUTOFILL_CANCEL, 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[] {AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
AUTOFILL_VALUE_CHANGED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
assertEquals(SubmissionSource.PROBABLY_FORM_SUBMITTED, mSubmissionSource); assertEquals(SubmissionSource.PROBABLY_FORM_SUBMITTED, mSubmissionSource);
} finally {
webServer.shutdown();
}
} }
/** /**
...@@ -1290,7 +1250,6 @@ public class AwAutofillTest { ...@@ -1290,7 +1250,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testNoSubmissionWithoutFillingForm() throws Throwable { public void testNoSubmissionWithoutFillingForm() throws Throwable {
int cnt = 0; int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>" final String data = "<!DOCTYPE html>"
+ "<html>" + "<html>"
+ "<body>" + "<body>"
...@@ -1306,16 +1265,12 @@ public class AwAutofillTest { ...@@ -1306,16 +1265,12 @@ public class AwAutofillTest {
+ "<body>" + "<body>"
+ "</body>" + "</body>"
+ "</html>"; + "</html>";
try { final String successUrl = mWebServer.setResponse("/success.html", success, null);
final String successUrl = webServer.setResponse("/success.html", success, null); final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; "); executeJavaScriptAndWaitForResult("window.location.href = 'success.html'; ");
// There is no callback. AUTOFILL_CANCEL shouldn't be invoked. // There is no callback. AUTOFILL_CANCEL shouldn't be invoked.
assertEquals(0, getCallbackCount()); assertEquals(0, getCallbackCount());
} finally {
webServer.shutdown();
}
} }
@Test @Test
...@@ -1326,7 +1281,6 @@ public class AwAutofillTest { ...@@ -1326,7 +1281,6 @@ public class AwAutofillTest {
public void public void
testSelectControlChangeNotification() throws Throwable { testSelectControlChangeNotification() throws Throwable {
int cnt = 0; int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>" final String data = "<!DOCTYPE html>"
+ "<html>" + "<html>"
+ "<body>" + "<body>"
...@@ -1337,8 +1291,7 @@ public class AwAutofillTest { ...@@ -1337,8 +1291,7 @@ public class AwAutofillTest {
+ "</form>" + "</form>"
+ "</body>" + "</body>"
+ "</html>"; + "</html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
...@@ -1356,9 +1309,6 @@ public class AwAutofillTest { ...@@ -1356,9 +1309,6 @@ public class AwAutofillTest {
assertEquals(1, values.size()); assertEquals(1, values.size());
assertTrue(values.get(0).second.isList()); assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue()); assertEquals(1, values.get(0).second.getListValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
...@@ -1369,7 +1319,6 @@ public class AwAutofillTest { ...@@ -1369,7 +1319,6 @@ public class AwAutofillTest {
public void public void
testSelectControlChangeStartAutofillSession() throws Throwable { testSelectControlChangeStartAutofillSession() throws Throwable {
int cnt = 0; int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>" final String data = "<!DOCTYPE html>"
+ "<html>" + "<html>"
+ "<body>" + "<body>"
...@@ -1380,8 +1329,7 @@ public class AwAutofillTest { ...@@ -1380,8 +1329,7 @@ public class AwAutofillTest {
+ "</form>" + "</form>"
+ "</body>" + "</body>"
+ "</html>"; + "</html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
// Change select control first shall start autofill session. // Change select control first shall start autofill session.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
...@@ -1407,9 +1355,6 @@ public class AwAutofillTest { ...@@ -1407,9 +1355,6 @@ public class AwAutofillTest {
// The field has no scroll, should always be zero. // The field has no scroll, should always be zero.
assertEquals(0, viewStructure.getChild(1).getDimensScrollX()); assertEquals(0, viewStructure.getChild(1).getDimensScrollX());
assertEquals(0, viewStructure.getChild(1).getDimensScrollY()); assertEquals(0, viewStructure.getChild(1).getDimensScrollY());
} finally {
webServer.shutdown();
}
} }
@Test @Test
...@@ -1417,7 +1362,6 @@ public class AwAutofillTest { ...@@ -1417,7 +1362,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUserInitiatedJavascriptSelectControlChangeNotification() throws Throwable { public void testUserInitiatedJavascriptSelectControlChangeNotification() throws Throwable {
int cnt = 0; int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>" final String data = "<!DOCTYPE html>"
+ "<html>" + "<html>"
+ "<body>" + "<body>"
...@@ -1433,8 +1377,7 @@ public class AwAutofillTest { ...@@ -1433,8 +1377,7 @@ public class AwAutofillTest {
+ "</form>" + "</form>"
+ "</body>" + "</body>"
+ "</html>"; + "</html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
// Change select control first shall start autofill session. // Change select control first shall start autofill session.
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_SPACE);
...@@ -1444,9 +1387,6 @@ public class AwAutofillTest { ...@@ -1444,9 +1387,6 @@ public class AwAutofillTest {
assertEquals(1, values.size()); assertEquals(1, values.size());
assertTrue(values.get(0).second.isList()); assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue()); assertEquals(1, values.get(0).second.getListValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
...@@ -1454,7 +1394,6 @@ public class AwAutofillTest { ...@@ -1454,7 +1394,6 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testJavascriptNotTriggerSelectControlChangeNotification() throws Throwable { public void testJavascriptNotTriggerSelectControlChangeNotification() throws Throwable {
int cnt = 0; int cnt = 0;
TestWebServer webServer = TestWebServer.start();
final String data = "<!DOCTYPE html>" final String data = "<!DOCTYPE html>"
+ "<html>" + "<html>"
+ "<body onload='myFunction();'>" + "<body onload='myFunction();'>"
...@@ -1470,8 +1409,7 @@ public class AwAutofillTest { ...@@ -1470,8 +1409,7 @@ public class AwAutofillTest {
+ "</form>" + "</form>"
+ "</body>" + "</body>"
+ "</html>"; + "</html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
// There is no good way to verify no callback occurred, we just simulate user trigger // 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 // the autofill and verify autofill is only triggered once, then this proves javascript
...@@ -1485,16 +1423,12 @@ public class AwAutofillTest { ...@@ -1485,16 +1423,12 @@ public class AwAutofillTest {
assertEquals(1, values.size()); assertEquals(1, values.size());
assertTrue(values.get(0).second.isList()); assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue()); assertEquals(1, values.get(0).second.getListValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUaAutofillHints() throws Throwable { public void testUaAutofillHints() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>" final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<label for=\"frmAddressB\">Address</label>" + "<label for=\"frmAddressB\">Address</label>"
+ "<input name=\"bill-address\" id=\"frmAddressB\">" + "<input name=\"bill-address\" id=\"frmAddressB\">"
...@@ -1510,9 +1444,8 @@ public class AwAutofillTest { ...@@ -1510,9 +1444,8 @@ public class AwAutofillTest {
+ "<input type='submit'>" + "<input type='submit'>"
+ "</form></body></html>"; + "</form></body></html>";
final int totalControls = 6; final int totalControls = 6;
try {
int cnt = 0; int cnt = 0;
final String url = webServer.setResponse(FILE, data, null); final String url = mWebServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('frmAddressB').select();"); executeJavaScriptAndWaitForResult("document.getElementById('frmAddressB').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A); dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
...@@ -1546,18 +1479,13 @@ public class AwAutofillTest { ...@@ -1546,18 +1479,13 @@ public class AwAutofillTest {
TestViewStructure child5 = viewStructure.getChild(5); TestViewStructure child5 = viewStructure.getChild(5);
TestViewStructure.AwHtmlInfo htmlInfo5 = child5.getHtmlInfo(); TestViewStructure.AwHtmlInfo htmlInfo5 = child5.getHtmlInfo();
assertEquals("ADDRESS_HOME_COUNTRY", htmlInfo5.getAttribute("ua-autofill-hints")); assertEquals("ADDRESS_HOME_COUNTRY", htmlInfo5.getAttribute("ua-autofill-hints"));
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserChangeFormFormSubmitted() throws Throwable { public void testUMAUserSelectSuggestionUserChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion(); mUMATestHelper.simulateUserSelectSuggestion();
...@@ -1567,87 +1495,65 @@ public class AwAutofillTest { ...@@ -1567,87 +1495,65 @@ public class AwAutofillTest {
mUMATestHelper.getSessionValue()); mUMATestHelper.getSessionValue());
assertEquals( assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue()); AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserChangeFormNoFormSubmitted() throws Throwable { public void testUMAUserSelectSuggestionUserChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion(); mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.simulateUserChangeField(); mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession(); mUMATestHelper.startNewSession();
assertEquals( assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue()); mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserSelectNotSuggestionUserChangeFormNoFormSubmitted() throws Throwable { public void testUMAUserSelectNotSuggestionUserChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start();
try {
int count = mUMATestHelper.getHistogramSampleCount( int count = mUMATestHelper.getHistogramSampleCount(
AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME); AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME);
mUMATestHelper.triggerAutofill(webServer); mUMATestHelper.triggerAutofill();
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.simulateUserChangeField(); mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession(); mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA assertEquals(
.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED, AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue()); mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
assertEquals(count + 1, assertEquals(count + 1,
mUMATestHelper.getHistogramSampleCount( mUMATestHelper.getHistogramSampleCount(
AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME)); AutofillProviderUMA.UMA_AUTOFILL_SUGGESTION_TIME));
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserNotSelectSuggestionUserChangeFormFormSubmitted() throws Throwable { public void testUMAUserNotSelectSuggestionUserChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.simulateUserChangeField(); mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm(); mUMATestHelper.submitForm();
assertEquals( assertEquals(AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue()); mUMATestHelper.getSessionValue());
assertEquals( assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue()); AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMANoSuggestionUserChangeFormNoFormSubmitted() throws Throwable { public void testUMANoSuggestionUserChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.simulateUserChangeField(); mUMATestHelper.simulateUserChangeField();
mUMATestHelper.startNewSession(); mUMATestHelper.startNewSession();
...@@ -1656,18 +1562,13 @@ public class AwAutofillTest { ...@@ -1656,18 +1562,13 @@ public class AwAutofillTest {
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedNonAutofilledField(); mUMATestHelper.verifyUserChangedNonAutofilledField();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMANoSuggestionUserChangeFormFormSubmitted() throws Throwable { public void testUMANoSuggestionUserChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.simulateUserChangeField(); mUMATestHelper.simulateUserChangeField();
mUMATestHelper.submitForm(); mUMATestHelper.submitForm();
...@@ -1676,62 +1577,46 @@ public class AwAutofillTest { ...@@ -1676,62 +1577,46 @@ public class AwAutofillTest {
assertEquals( assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue()); AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedNonAutofilledField(); mUMATestHelper.verifyUserChangedNonAutofilledField();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserNotChangeFormFormSubmitted() throws Throwable { public void testUMAUserSelectSuggestionUserNotChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion(); mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.submitForm(); mUMATestHelper.submitForm();
assertEquals( assertEquals(AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue()); mUMATestHelper.getSessionValue());
assertEquals( assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue()); AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm(); mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserSelectSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable { public void testUMAUserSelectSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion(); mUMATestHelper.simulateUserSelectSuggestion();
mUMATestHelper.startNewSession(); mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA assertEquals(
.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED, AutofillProviderUMA.USER_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
mUMATestHelper.getSessionValue()); mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm(); mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserSelectNotSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable { public void testUMAUserSelectNotSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.startNewSession(); mUMATestHelper.startNewSession();
...@@ -1741,39 +1626,29 @@ public class AwAutofillTest { ...@@ -1741,39 +1626,29 @@ public class AwAutofillTest {
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm(); mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserNotSelectSuggestionUserNotChangeFormFormSubmitted() throws Throwable { public void testUMAUserNotSelectSuggestionUserNotChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.submitForm(); mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA assertEquals(
.USER_NOT_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED, AutofillProviderUMA.USER_NOT_SELECT_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
mUMATestHelper.getSessionValue()); mUMATestHelper.getSessionValue());
assertEquals( assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue()); AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm(); mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMANoSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable { public void testUMANoSuggestionUserNotChangeFormNoFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.startNewSession(); mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED, assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_NO_FORM_SUBMITTED,
...@@ -1781,18 +1656,13 @@ public class AwAutofillTest { ...@@ -1781,18 +1656,13 @@ public class AwAutofillTest {
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm(); mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMANoSuggestionUserNotChangeFormFormSubmitted() throws Throwable { public void testUMANoSuggestionUserNotChangeFormFormSubmitted() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
mUMATestHelper.submitForm(); mUMATestHelper.submitForm();
assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED, assertEquals(AutofillProviderUMA.NO_SUGGESTION_USER_NOT_CHANGE_FORM_FORM_SUBMITTED,
...@@ -1800,26 +1670,18 @@ public class AwAutofillTest { ...@@ -1800,26 +1670,18 @@ public class AwAutofillTest {
assertEquals( assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue()); AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserDidntChangeForm(); mUMATestHelper.verifyUserDidntChangeForm();
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMANoCallbackFromFramework() throws Throwable { public void testUMANoCallbackFromFramework() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
mUMATestHelper.startNewSession(); mUMATestHelper.startNewSession();
assertEquals(AutofillProviderUMA.NO_CALLBACK_FORM_FRAMEWORK, assertEquals(
mUMATestHelper.getSessionValue()); AutofillProviderUMA.NO_CALLBACK_FORM_FRAMEWORK, mUMATestHelper.getSessionValue());
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
...@@ -1827,39 +1689,27 @@ public class AwAutofillTest { ...@@ -1827,39 +1689,27 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAAutofillDisabled() throws Throwable { public void testUMAAutofillDisabled() throws Throwable {
mTestAutofillManagerWrapper.setDisabled(); mTestAutofillManagerWrapper.setDisabled();
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
mUMATestHelper.verifyAutofillDisabled(); mUMATestHelper.verifyAutofillDisabled();
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAAutofillEnabled() throws Throwable { public void testUMAAutofillEnabled() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
mUMATestHelper.verifyAutofillEnabled(); mUMATestHelper.verifyAutofillEnabled();
assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION, assertEquals(AwAutofillSessionUMATestHelper.NO_FORM_SUBMISSION,
mUMATestHelper.getSubmissionSourceValue()); mUMATestHelper.getSubmissionSourceValue());
} finally {
webServer.shutdown();
}
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
public void testUMAUserChangeAutofilledField() throws Throwable { public void testUMAUserChangeAutofilledField() throws Throwable {
TestWebServer webServer = TestWebServer.start(); mUMATestHelper.triggerAutofill();
try {
mUMATestHelper.triggerAutofill(webServer);
invokeOnProvideAutoFillVirtualStructure(); invokeOnProvideAutoFillVirtualStructure();
invokeOnInputUIShown(); invokeOnInputUIShown();
mUMATestHelper.simulateUserSelectSuggestion(); mUMATestHelper.simulateUserSelectSuggestion();
...@@ -1870,9 +1720,6 @@ public class AwAutofillTest { ...@@ -1870,9 +1720,6 @@ public class AwAutofillTest {
assertEquals( assertEquals(
AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue()); AutofillProviderUMA.FORM_SUBMISSION, mUMATestHelper.getSubmissionSourceValue());
mUMATestHelper.verifyUserChangedAutofilledField(); mUMATestHelper.verifyUserChangedAutofilledField();
} finally {
webServer.shutdown();
}
} }
@Test @Test
...@@ -1887,13 +1734,11 @@ public class AwAutofillTest { ...@@ -1887,13 +1734,11 @@ public class AwAutofillTest {
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
@FlakyTest(message = "crbug.com/1033179") @FlakyTest(message = "crbug.com/1033179")
public void testPageScrollTriggerViewExitAndEnter() throws Throwable { public void testPageScrollTriggerViewExitAndEnter() throws Throwable {
TestWebServer webServer = TestWebServer.start();
final String data = "<html><head></head><body><form action='a.html' name='formname'>" final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<input type='text' id='text1' name='username'" + "<input type='text' id='text1' name='username'"
+ " placeholder='placeholder@placeholder.com' autocomplete='username name'>" + " placeholder='placeholder@placeholder.com' autocomplete='username name'>"
+ "</form><p style='height: 100vh'>Hello</p></body></html>"; + "</form><p style='height: 100vh'>Hello</p></body></html>";
try { final String url = mWebServer.setResponse(FILE, data, null);
final String url = webServer.setResponse(FILE, data, null);
loadUrlSync(url); loadUrlSync(url);
int cnt = 0; int cnt = 0;
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();"); executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
...@@ -1915,12 +1760,9 @@ public class AwAutofillTest { ...@@ -1915,12 +1760,9 @@ public class AwAutofillTest {
} }
// Check if NotifyVirtualValueChanged() called again and with extra AUTOFILL_VIEW_EXITED // Check if NotifyVirtualValueChanged() called again and with extra AUTOFILL_VIEW_EXITED
// and AUTOFILL_VIEW_ENTERED // and AUTOFILL_VIEW_ENTERED
expectedValues.addAll(Arrays.asList( expectedValues.addAll(
AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED)); Arrays.asList(AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED, AUTOFILL_VALUE_CHANGED));
waitForCallbackAndVerifyTypes(cnt, expectedValues.toArray(new Integer[0])); waitForCallbackAndVerifyTypes(cnt, expectedValues.toArray(new Integer[0]));
} finally {
webServer.shutdown();
}
} }
private void scrollToBottom() { 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