Commit b786bf5b authored by Yi Gu's avatar Yi Gu Committed by Commit Bot

[WebOTP] Fix flaky test AutofillMetricsTest.FrameHasNoForm

The test used to count on base::StatisticsRecorder::FindHistogram() to
test the metric is not logged. However, FindHistogram() is static and it
may observe values from previous test runs.

The proper way should be using ExpectTotalCount(0) [1] which takes this
situation into consideration.

[1] https://source.chromium.org/chromium/chromium/src/+/master:base/test/metrics/histogram_tester.cc;l=70

Bug: 1132038
Change-Id: I3134c6bccba0670a583e3ec97972a358f68fef9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2430123
Commit-Queue: Dominic Battré <battre@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810579}
parent 987b261e
...@@ -10421,16 +10421,9 @@ TEST_F(AutofillMetricsTest, ...@@ -10421,16 +10421,9 @@ TEST_F(AutofillMetricsTest,
// Verify that we don't log Autofill.WebOTP.OneTimeCode.FromAutocomplete if the // Verify that we don't log Autofill.WebOTP.OneTimeCode.FromAutocomplete if the
// frame has no form. // frame has no form.
TEST_F(AutofillMetricsTest, FrameHasNoForm) { TEST_F(AutofillMetricsTest, FrameHasNoForm) {
#if defined(OS_IOS) && !TARGET_IPHONE_SIMULATOR base::HistogramTester histogram_tester;
// TODO(crbug.com/1127005): Test is failing on iOS 12 device.
if (!base::ios::IsRunningOnOrLater(13, 0, 0)) {
return;
}
#endif
autofill_manager_.reset(); autofill_manager_.reset();
EXPECT_FALSE(base::StatisticsRecorder::FindHistogram( histogram_tester.ExpectTotalCount("Autofill.WebOTP.OneTimeCode.FromAutocomplete", 0);
"Autofill.WebOTP.OneTimeCode.FromAutocomplete"));
} }
// Verify that we correctly log metrics if a frame has // Verify that we correctly log metrics if a frame has
......
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