Commit 47bcc5fa authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

WebLayer/WebView autofill: Properly handle webpage reload

Currently WebLayer/WebView's shared autofill implementation doesn't
properly reset state on webpage reload. This results in buggy behavior
as the implementation treats the user's session after reload as a
continuation of the before-reload session rather than a new session
(see [1] for details).

This CL fixes the problem by having AutofillProviderAndroid reset its
state on receiving a notification to do so from ContentAutofillDriver.
This notification is made when a different-documentation navigation is
made. As detailed in [1], a reload is always treated as a
different-document navigation by //content.

We also add a test of that autofill starts a new session in this case,
which fails without the change made in this CL.

To manually verify: Go to accounts.google.com in WebLayer Shell, focus
on the username field to trigger the autofill popup, reload the page,
focus on the username field again, and verify that the autofill popup
triggers again.

[1] https://docs.google.com/document/d/1tyQ5XQLssIoa1AIPJ9WjOnW6-lPZpmpSrxkf5-6HYgc/edit#heading=h.u1hpn0gmjp2e (internal-only, apologies)

Bug: 1117563
Change-Id: If6f95aa1fea9dccf0f24a860758fd323d9714c2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409492Reviewed-by: default avatarMichael Bai <michaelbai@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810107}
parent 0c6e904f
......@@ -983,6 +983,42 @@ public class AwAutofillTest {
assertEquals(1, changedValues.get(2).second.getListValue());
}
/**
* This test is verifying that a user interacting with a form after reloading a webpage
* triggers a new autofill session rather than continuing a session that was started before the
* reload. This is necessary to ensure that autofill is properly triggered in this case (see
* crbug.com/1117563 for details).
*/
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testAutofillTriggersAfterReload() throws Throwable {
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>";
final String url = mWebServer.setResponse(FILE, data, null);
int cnt = 0;
loadUrlSync(url);
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "text1");
// TODO(changwan): mock out IME interaction.
Assert.assertTrue(DOMUtils.clickNode(mTestContainerView.getWebContents(), "text1"));
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_ENTERED, AUTOFILL_SESSION_STARTED});
// Reload the page and check that the user clicking on the same form field ends the current
// autofill session and starts a new session.
loadUrlSync(url);
DOMUtils.waitForNonZeroNodeBounds(mAwContents.getWebContents(), "text1");
// TODO(changwan): mock out IME interaction.
Assert.assertTrue(DOMUtils.clickNode(mTestContainerView.getWebContents(), "text1"));
cnt += waitForCallbackAndVerifyTypes(cnt,
new Integer[] {AUTOFILL_CANCEL, AUTOFILL_VIEW_EXITED, AUTOFILL_VIEW_ENTERED,
AUTOFILL_SESSION_STARTED});
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
......
......@@ -360,6 +360,8 @@ void AutofillProviderAndroid::Reset(AutofillHandlerProxy* handler) {
if (check_submission_ && form_.get())
FireSuccessfulSubmission(pending_submission_source_);
Reset();
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
......
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