Commit 0eabe530 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

Autofill: send the visibility to Autofill service.

Directly use the result of FormFieldData.IsVisible(), since it is
hard to detect if a field visible to the end user or not, the
result could be false positive, but once it is set to INVISIBLE,
it isn't visible to the user.

Bug: 1110041
Change-Id: Ie745ababf98ce0e195c7cd603fa16665656d5918
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2324996Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792889}
parent f4c74ea1
......@@ -405,7 +405,13 @@ public class AwAutofillTest {
public void setTransformation(Matrix matrix) {}
@Override
public void setVisibility(int visibility) {}
public void setVisibility(int visibility) {
mVisibility = visibility;
}
public int getVisibility() {
return mVisibility;
}
@Override
public void setSelected(boolean state) {}
......@@ -448,6 +454,8 @@ public class AwAutofillTest {
private int mDimensScrollX;
private int mDimensScrollY;
private Bundle mBundle;
// Initializes to the value AutofillProvider will never use.
private int mVisibility = View.GONE;
}
// crbug.com/776230: On Android L, declaring variables of unsupported classes causes an error.
......@@ -1936,6 +1944,32 @@ public class AwAutofillTest {
assertNull(mAutofillProvider.getDatalistPopupForTesting());
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testVisibility() throws Throwable {
final String data = "<html><head></head><body><form action='a.html' name='formname'>"
+ "<input type='text' id='text1' name='username'>"
+ "<input type='text' name='email' id='text2' style='display: none;'/>"
+ "</form></body></html>";
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_SESSION_STARTED,
AUTOFILL_VALUE_CHANGED});
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(2, viewStructure.getChildCount());
// Verifies the visibility set correctly.
assertEquals(View.VISIBLE, viewStructure.getChild(0).getVisibility());
assertEquals(View.INVISIBLE, viewStructure.getChild(1).getVisibility());
}
private void pollJavascriptResult(String script, String expectedResult) throws Throwable {
AwActivityTestRule.pollInstrumentationThread(() -> {
try {
......
......@@ -62,7 +62,7 @@ ScopedJavaLocalRef<jobject> FormFieldDataAndroid::GetJavaPeer() {
IsChecked(field_ptr_->check_status), field_ptr_->max_length,
jheuristic_type, field_ptr_->bounds.x(), field_ptr_->bounds.y(),
field_ptr_->bounds.right(), field_ptr_->bounds.bottom(),
jdatalist_values, jdatalist_labels);
jdatalist_values, jdatalist_labels, field_ptr_->IsVisible());
java_ref_ = JavaObjectWeakGlobalRef(env, obj);
}
return obj;
......
......@@ -107,6 +107,7 @@ public class AutofillProvider {
// Field has no scroll.
child.setDimens((int) bounds.left, (int) bounds.top, 0 /* scrollX*/,
0 /* scrollY */, (int) bounds.width(), (int) bounds.height());
child.setVisibility(field.mVisible ? View.VISIBLE : View.INVISIBLE);
ViewStructure.HtmlInfo.Builder builder =
child.newHtmlInfoBuilder("input")
......
......@@ -49,6 +49,7 @@ public class FormFieldData {
public final String mHeuristicType;
public final String[] mDatalistValues;
public final String[] mDatalistLabels;
public final boolean mVisible;
// The bounds in the viewport's coordinates
private final RectF mBounds;
......@@ -66,7 +67,7 @@ public class FormFieldData {
boolean shouldAutocomplete, String placeholder, String type, String id,
String[] optionValues, String[] optionContents, boolean isCheckField, boolean isChecked,
int maxLength, String heuristicType, float left, float top, float right, float bottom,
String[] datalistValues, String[] datalistLabels) {
String[] datalistValues, String[] datalistLabels, boolean visible) {
mName = name;
mLabel = label;
mValue = value;
......@@ -92,6 +93,7 @@ public class FormFieldData {
mMaxLength = maxLength;
mHeuristicType = heuristicType;
mBounds = new RectF(left, top, right, bottom);
mVisible = visible;
}
public @ControlType int getControlType() {
......@@ -154,9 +156,11 @@ public class FormFieldData {
String autocompleteAttr, boolean shouldAutocomplete, String placeholder, String type,
String id, String[] optionValues, String[] optionContents, boolean isCheckField,
boolean isChecked, int maxLength, String heuristicType, float left, float top,
float right, float bottom, String[] datalistValues, String[] datalistLabels) {
float right, float bottom, String[] datalistValues, String[] datalistLabels,
boolean visible) {
return new FormFieldData(name, label, value, autocompleteAttr, shouldAutocomplete,
placeholder, type, id, optionValues, optionContents, isCheckField, isChecked,
maxLength, heuristicType, left, top, right, bottom, datalistValues, datalistLabels);
maxLength, heuristicType, left, top, right, bottom, datalistValues, datalistLabels,
visible);
}
}
......@@ -84,10 +84,10 @@ public class AutofillProviderTest {
ArrayList<FormFieldData> fields = new ArrayList<FormFieldData>(1);
fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null,
null, null, null, false, false, 0, null, 10 /* left */, 20 /* top */,
300 /* right */, 60 /*bottom*/, null, null));
300 /* right */, 60 /*bottom*/, null, null, true));
fields.add(FormFieldData.createFormFieldData(null, null, null, null, false, null, null,
null, null, null, false, false, 0, null, 20 /* left */, 100 /* top */,
400 /* right */, 200 /*bottom*/, null, null));
400 /* right */, 200 /*bottom*/, null, null, true));
FormData formData = new FormData(null, null, fields);
mAutofillProvider.transformFormFieldToContainViewCoordinates(formData);
RectF result = formData.mFields.get(0).getBoundsInContainerViewCoordinates();
......
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