Add tests for Autofill.WebView.SubmissionSource
This CL also deprecates the DOM_MUTATION_AFTER_AUTOFILL bucket, as it can occur only in relation with password manager. Password manager is not available in webview. Bug: b/319219926 Change-Id: I2a7c7d2e282e9fe69c95f92c66f6ef425019d6b2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5253759 Commit-Queue: Jan Keitel <jkeitel@google.com> Commit-Queue: Theo Cristea <theocristea@google.com> Reviewed-by: Jihad Hanna <jihadghanna@google.com> Reviewed-by: Jan Keitel <jkeitel@google.com> Cr-Commit-Position: refs/heads/main@{#1255507}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f963a45f1f
commit
a4096b21b5
android_webview/javatests/src/org/chromium/android_webview/test
components/android_autofill/browser/java/src/org/chromium/components/autofill
@ -329,6 +329,16 @@ public class AwAutofillTest extends AwParameterizedTest {
|
||||
mCnt, new Integer[] {AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT});
|
||||
}
|
||||
|
||||
public void reload() throws Throwable {
|
||||
mTest.executeJavaScriptAndWaitForResult("location.reload();");
|
||||
mCnt +=
|
||||
mTest.waitForCallbackAndVerifyTypes(
|
||||
mCnt,
|
||||
new Integer[] {
|
||||
AUTOFILL_VIEW_EXITED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT
|
||||
});
|
||||
}
|
||||
|
||||
public void startNewSession() throws Throwable {
|
||||
// Start a new session by moving focus to another form.
|
||||
mTest.executeJavaScriptAndWaitForResult("document.getElementById('text2').select();");
|
||||
@ -2233,6 +2243,200 @@ public class AwAutofillTest extends AwParameterizedTest {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests recording of the `PROBABLY_FORM_SUBMITTED` bucket for the
|
||||
* "Autofill.WebView.SubmissionSource" histogram. This event is fired on a navigation not
|
||||
* resulting from a link click (in this case the test uses a reload).
|
||||
*/
|
||||
@Test
|
||||
@SmallTest
|
||||
@Feature({"AndroidWebView"})
|
||||
public void testUMAFormSubmissionProbablyFormSubmitted() throws Throwable {
|
||||
var histograms =
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return HistogramWatcher.newBuilder()
|
||||
.expectIntRecord(
|
||||
AutofillProviderUMA.UMA_AUTOFILL_SUBMISSION_SOURCE,
|
||||
AutofillProviderUMA.PROBABLY_FORM_SUBMITTED)
|
||||
.build();
|
||||
});
|
||||
mUMATestHelper.triggerAutofill();
|
||||
invokeOnProvideAutoFillVirtualStructure();
|
||||
mUMATestHelper.reload();
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
histograms.assertExpected();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests recording of the `FRAME_DETACHED` bucket for the "Autofill.WebView.SubmissionSource"
|
||||
* histogram. This event is fired when a non-main frame is detached.
|
||||
*/
|
||||
@Test
|
||||
@SmallTest
|
||||
@Feature({"AndroidWebView"})
|
||||
public void testUMAFormSubmissionFrameDetached() throws Throwable {
|
||||
var histograms =
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return HistogramWatcher.newBuilder()
|
||||
.expectIntRecord(
|
||||
AutofillProviderUMA.UMA_AUTOFILL_SUBMISSION_SOURCE,
|
||||
AutofillProviderUMA.FRAME_DETACHED)
|
||||
.build();
|
||||
});
|
||||
loadHTML(
|
||||
"""
|
||||
<div id='parent'>
|
||||
<iframe id='frame' srcdoc='<input id="username">'></iframe>
|
||||
</div>""");
|
||||
|
||||
int cnt = 0;
|
||||
executeJavaScriptAndWaitForResult(
|
||||
"""
|
||||
var iframe = document.getElementById('frame');
|
||||
var frame_doc = iframe.contentDocument;
|
||||
frame_doc.getElementById('username').select();""");
|
||||
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
|
||||
cnt +=
|
||||
waitForCallbackAndVerifyTypes(
|
||||
cnt,
|
||||
new Integer[] {
|
||||
AUTOFILL_CANCEL,
|
||||
AUTOFILL_VIEW_ENTERED,
|
||||
AUTOFILL_SESSION_STARTED,
|
||||
AUTOFILL_VALUE_CHANGED
|
||||
});
|
||||
invokeOnProvideAutoFillVirtualStructure();
|
||||
executeJavaScriptAndWaitForResult(
|
||||
"document.getElementById('parent').removeChild(document.getElementById('frame'));");
|
||||
cnt +=
|
||||
waitForCallbackAndVerifyTypes(
|
||||
cnt,
|
||||
new Integer[] {
|
||||
AUTOFILL_VIEW_EXITED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT
|
||||
});
|
||||
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
histograms.assertExpected();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests recording of the `SAME_DOCUMENT_NAVIGATION` bucket for the
|
||||
* "Autofill.WebView.SubmissionSource" histogram. This event is fired when clicking a link that
|
||||
* jumps through the same document and the tracked element disappears.
|
||||
*/
|
||||
@Test
|
||||
@SmallTest
|
||||
@Feature({"AndroidWebView"})
|
||||
public void testUMAFormSubmissionSameDocumentNavigation() throws Throwable {
|
||||
var histograms =
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return HistogramWatcher.newBuilder()
|
||||
.expectIntRecord(
|
||||
AutofillProviderUMA.UMA_AUTOFILL_SUBMISSION_SOURCE,
|
||||
AutofillProviderUMA.SAME_DOCUMENT_NAVIGATION)
|
||||
.build();
|
||||
});
|
||||
|
||||
loadHTML(
|
||||
"""
|
||||
<input id='username'>
|
||||
<a id='link' href='#destination'></a>
|
||||
<div id='destination'></div>""");
|
||||
|
||||
int cnt = 0;
|
||||
executeJavaScriptAndWaitForResult("document.getElementById('username').select();");
|
||||
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
|
||||
cnt +=
|
||||
waitForCallbackAndVerifyTypes(
|
||||
cnt,
|
||||
new Integer[] {
|
||||
AUTOFILL_CANCEL,
|
||||
AUTOFILL_VIEW_ENTERED,
|
||||
AUTOFILL_SESSION_STARTED,
|
||||
AUTOFILL_VALUE_CHANGED
|
||||
});
|
||||
invokeOnProvideAutoFillVirtualStructure();
|
||||
executeJavaScriptAndWaitForResult(
|
||||
"""
|
||||
document.getElementById('link').click();
|
||||
document.getElementById('username').remove();""");
|
||||
cnt +=
|
||||
waitForCallbackAndVerifyTypes(
|
||||
cnt,
|
||||
new Integer[] {
|
||||
AUTOFILL_VIEW_EXITED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT
|
||||
});
|
||||
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
histograms.assertExpected();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests recording of the `XHR_SUCCEEDED` bucket for the "Autofill.WebView.SubmissionSource"
|
||||
* histogram. This event is fired when a successful XHR request occurs and the tracked element
|
||||
* disappears.
|
||||
*/
|
||||
@Test
|
||||
@SmallTest
|
||||
@Feature({"AndroidWebView"})
|
||||
public void testUMAFormSubmissionXHRSucceeded() throws Throwable {
|
||||
var histograms =
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
return HistogramWatcher.newBuilder()
|
||||
.expectIntRecord(
|
||||
AutofillProviderUMA.UMA_AUTOFILL_SUBMISSION_SOURCE,
|
||||
AutofillProviderUMA.XHR_SUCCEEDED)
|
||||
.build();
|
||||
});
|
||||
|
||||
loadHTML("<input id='username'>");
|
||||
|
||||
int cnt = 0;
|
||||
executeJavaScriptAndWaitForResult("document.getElementById('username').select();");
|
||||
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
|
||||
cnt +=
|
||||
waitForCallbackAndVerifyTypes(
|
||||
cnt,
|
||||
new Integer[] {
|
||||
AUTOFILL_CANCEL,
|
||||
AUTOFILL_VIEW_ENTERED,
|
||||
AUTOFILL_SESSION_STARTED,
|
||||
AUTOFILL_VALUE_CHANGED
|
||||
});
|
||||
invokeOnProvideAutoFillVirtualStructure();
|
||||
|
||||
final String xhrUrl = mWebServer.setEmptyResponse(FILE);
|
||||
executeJavaScriptAndWaitForResult(
|
||||
String.format(
|
||||
"""
|
||||
document.getElementById('username').remove();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '%s', true);
|
||||
xhr.send(null);""",
|
||||
xhrUrl));
|
||||
cnt +=
|
||||
waitForCallbackAndVerifyTypes(
|
||||
cnt,
|
||||
new Integer[] {
|
||||
AUTOFILL_VIEW_EXITED, AUTOFILL_VALUE_CHANGED, AUTOFILL_COMMIT
|
||||
});
|
||||
|
||||
TestThreadUtils.runOnUiThreadBlocking(
|
||||
() -> {
|
||||
histograms.assertExpected();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
@RequiresRestart("https://crbug.com/1422936")
|
||||
|
@ -102,6 +102,8 @@ public class AutofillProviderUMA {
|
||||
// public static final int DEPRECATED_DOM_MUTATION_AFTER_XHR = 3;
|
||||
public static final int PROBABLY_FORM_SUBMITTED = 4;
|
||||
public static final int FORM_SUBMISSION = 5;
|
||||
// This bucket is not recorded at the moment because it can only be recorded in relation with
|
||||
// password manager (which doesn't exist in web view).
|
||||
public static final int DOM_MUTATION_AFTER_AUTOFILL = 6;
|
||||
public static final int SUBMISSION_SOURCE_HISTOGRAM_COUNT = 7;
|
||||
|
||||
|
Reference in New Issue
Block a user