Commit f5502729 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[ContentIndex] Re-enable UKM browsertest.

There are metrics that rely on the background recording service, which in
turn uses the history service that runs on its own thread.

That caused that test to be flaky, so this fix creates a test-only
closure that is run after the metric has been recorded to make it
determenistic.

Bug: 998049
Change-Id: I88ead36796ef07fadf348e1da686b5b200c17509
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1783152Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693143}
parent 0dc0a830
...@@ -270,13 +270,7 @@ IN_PROC_BROWSER_TEST_F(ContentIndexTest, UserDeletedEntryDispatchesEvent) { ...@@ -270,13 +270,7 @@ IN_PROC_BROWSER_TEST_F(ContentIndexTest, UserDeletedEntryDispatchesEvent) {
EXPECT_TRUE(GetAllItems().empty()); EXPECT_TRUE(GetAllItems().empty());
} }
// Flaky almost universally. http://crbug.com/998049 IN_PROC_BROWSER_TEST_F(ContentIndexTest, MetricsCollected) {
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
#define MAYBE_MetricsCollected DISABLED_MetricsCollected
#else
#define MAYBE_MetricsCollected MetricsCollected
#endif
IN_PROC_BROWSER_TEST_F(ContentIndexTest, MAYBE_MetricsCollected) {
// Inititally there is no content. // Inititally there is no content.
{ {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
...@@ -290,10 +284,23 @@ IN_PROC_BROWSER_TEST_F(ContentIndexTest, MAYBE_MetricsCollected) { ...@@ -290,10 +284,23 @@ IN_PROC_BROWSER_TEST_F(ContentIndexTest, MAYBE_MetricsCollected) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ukm::TestAutoSetUkmRecorder ukm_recorder; ukm::TestAutoSetUkmRecorder ukm_recorder;
RunScript("AddContent('my-id-1')"); {
RunScript("AddContent('my-id-2')"); base::RunLoop run_loop;
base::RunLoop() ukm_recorder.SetOnAddEntryCallback(
.RunUntilIdle(); // Wait for the provider to get the content. ukm::builders::ContentIndex_Added::kEntryName,
run_loop.QuitClosure());
RunScript("AddContent('my-id-1')");
run_loop.Run();
}
{
base::RunLoop run_loop;
ukm_recorder.SetOnAddEntryCallback(
ukm::builders::ContentIndex_Added::kEntryName,
run_loop.QuitClosure());
RunScript("AddContent('my-id-2')");
run_loop.Run();
}
histogram_tester.ExpectBucketCount( histogram_tester.ExpectBucketCount(
"ContentIndex.ContentAdded", blink::mojom::ContentCategory::ARTICLE, 2); "ContentIndex.ContentAdded", blink::mojom::ContentCategory::ARTICLE, 2);
...@@ -317,9 +324,13 @@ IN_PROC_BROWSER_TEST_F(ContentIndexTest, MAYBE_MetricsCollected) { ...@@ -317,9 +324,13 @@ IN_PROC_BROWSER_TEST_F(ContentIndexTest, MAYBE_MetricsCollected) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ukm::TestAutoSetUkmRecorder ukm_recorder; ukm::TestAutoSetUkmRecorder ukm_recorder;
base::RunLoop run_loop;
ukm_recorder.SetOnAddEntryCallback(
ukm::builders::ContentIndex_DeletedByUser::kEntryName,
run_loop.QuitClosure());
provider()->RemoveItem(offline_items().at("my-id-1").id); provider()->RemoveItem(offline_items().at("my-id-1").id);
EXPECT_EQ(RunScript("waitForMessageFromServiceWorker()"), "my-id-1"); EXPECT_EQ(RunScript("waitForMessageFromServiceWorker()"), "my-id-1");
base::RunLoop().RunUntilIdle(); run_loop.Run();
histogram_tester.ExpectBucketCount("ContentIndex.ContentDeleteEvent.Find", histogram_tester.ExpectBucketCount("ContentIndex.ContentDeleteEvent.Find",
blink::ServiceWorkerStatusCode::kOk, 1); blink::ServiceWorkerStatusCode::kOk, 1);
......
...@@ -34,7 +34,7 @@ class ContentIndexMetrics { ...@@ -34,7 +34,7 @@ class ContentIndexMetrics {
void RecordContentOpened(content::WebContents* web_contents, void RecordContentOpened(content::WebContents* web_contents,
blink::mojom::ContentCategory category); blink::mojom::ContentCategory category);
// Records when a Content UIndex entry is deleted by a user. // Records when a Content Index entry is deleted by a user.
void RecordContentDeletedByUser(const url::Origin& origin); void RecordContentDeletedByUser(const url::Origin& origin);
// Records the number of Content Index entries available when requested. // Records the number of Content Index entries available when requested.
......
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