Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1535)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client_unittest.cc

Issue 2155783002: Batch pageload metrics pingbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tbansal comment Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client_unittest.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client_unittest.cc
index 852a69b7d002110a9b63232f6b1b2cc66704a7ed..7cf2c1e40f6db81377f2a52525793b983fbec834 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client_unittest.cc
@@ -133,20 +133,21 @@ TEST_F(DataReductionProxyPingbackClientTest, VerifyPingbackContent) {
pingback_client()->OverrideRandom(true, 0.5f);
pingback_client()->SetPingbackReportingFraction(1.0f);
base::Time current_time = base::Time::UnixEpoch();
pingback_client()->set_current_time(current_time);
CreateAndSendPingback();
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
EXPECT_EQ(test_fetcher->upload_content_type(), "application/x-protobuf");
RecordPageloadMetricsRequest batched_request;
batched_request.ParseFromString(test_fetcher->upload_data());
+ EXPECT_EQ(batched_request.pageloads_size(), 1);
EXPECT_EQ(current_time, protobuf_parser::TimestampToTime(
batched_request.metrics_sent_time()));
PageloadMetrics pageload_metrics = batched_request.pageloads(0);
EXPECT_EQ(
timing().navigation_start,
protobuf_parser::TimestampToTime(pageload_metrics.first_request_time()));
EXPECT_EQ(timing().response_start.value(),
protobuf_parser::DurationToTimeDelta(
pageload_metrics.time_to_first_byte()));
EXPECT_EQ(
@@ -159,33 +160,92 @@ TEST_F(DataReductionProxyPingbackClientTest, VerifyPingbackContent) {
protobuf_parser::DurationToTimeDelta(
pageload_metrics.time_to_first_contentful_paint()));
EXPECT_EQ(kSessionKey, pageload_metrics.session_key());
EXPECT_EQ(kFakeURL, pageload_metrics.first_request_url());
test_fetcher->delegate()->OnURLFetchComplete(test_fetcher);
histogram_tester().ExpectUniqueSample(kHistogramSucceeded, true, 1);
EXPECT_FALSE(factory()->GetFetcherByID(0));
}
-TEST_F(DataReductionProxyPingbackClientTest, SendTwoPingbacks) {
+TEST_F(DataReductionProxyPingbackClientTest, VerifyTwoPingbacksBatchedContent) {
Init();
EXPECT_FALSE(factory()->GetFetcherByID(0));
pingback_client()->OverrideRandom(true, 0.5f);
pingback_client()->SetPingbackReportingFraction(1.0f);
- CreateAndSendPingback();
+ base::Time current_time = base::Time::UnixEpoch();
+ pingback_client()->set_current_time(current_time);
+ // First pingback
CreateAndSendPingback();
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
+ // Two more pingbacks batched together.
+ CreateAndSendPingback();
+ histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 2);
+ CreateAndSendPingback();
+ histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 3);
+
+ // Ignore the first pingback.
net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
test_fetcher->delegate()->OnURLFetchComplete(test_fetcher);
histogram_tester().ExpectUniqueSample(kHistogramSucceeded, true, 1);
+
+ // Check the state of the second pingback.
+ test_fetcher = factory()->GetFetcherByID(0);
+ EXPECT_EQ(test_fetcher->upload_content_type(), "application/x-protobuf");
+ RecordPageloadMetricsRequest batched_request;
+ batched_request.ParseFromString(test_fetcher->upload_data());
+ EXPECT_EQ(batched_request.pageloads_size(), 2);
+ EXPECT_EQ(current_time, protobuf_parser::TimestampToTime(
+ batched_request.metrics_sent_time()));
+
+ // Verify the content of both pingbacks.
+ for (size_t i = 0; i < 2; ++i) {
+ PageloadMetrics pageload_metrics = batched_request.pageloads(i);
+ EXPECT_EQ(timing().navigation_start,
+ protobuf_parser::TimestampToTime(
+ pageload_metrics.first_request_time()));
+ EXPECT_EQ(timing().response_start.value(),
+ protobuf_parser::DurationToTimeDelta(
+ pageload_metrics.time_to_first_byte()));
+ EXPECT_EQ(timing().load_event_start.value(),
+ protobuf_parser::DurationToTimeDelta(
+ pageload_metrics.page_load_time()));
+ EXPECT_EQ(timing().first_image_paint.value(),
+ protobuf_parser::DurationToTimeDelta(
+ pageload_metrics.time_to_first_image_paint()));
+ EXPECT_EQ(timing().first_contentful_paint.value(),
+ protobuf_parser::DurationToTimeDelta(
+ pageload_metrics.time_to_first_contentful_paint()));
+
+ EXPECT_EQ(kSessionKey, pageload_metrics.session_key());
+ EXPECT_EQ(kFakeURL, pageload_metrics.first_request_url());
+ }
+
+ test_fetcher->delegate()->OnURLFetchComplete(test_fetcher);
+ histogram_tester().ExpectUniqueSample(kHistogramSucceeded, true, 2);
+ EXPECT_FALSE(factory()->GetFetcherByID(0));
+}
+
+TEST_F(DataReductionProxyPingbackClientTest, SendTwoPingbacks) {
+ Init();
+ EXPECT_FALSE(factory()->GetFetcherByID(0));
+ pingback_client()->OverrideRandom(true, 0.5f);
+ pingback_client()->SetPingbackReportingFraction(1.0f);
+ CreateAndSendPingback();
+ histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 1);
+ CreateAndSendPingback();
histogram_tester().ExpectUniqueSample(kHistogramAttempted, true, 2);
+
+ net::TestURLFetcher* test_fetcher = factory()->GetFetcherByID(0);
+ test_fetcher->delegate()->OnURLFetchComplete(test_fetcher);
+ histogram_tester().ExpectUniqueSample(kHistogramSucceeded, true, 1);
EXPECT_TRUE(factory()->GetFetcherByID(0));
test_fetcher = factory()->GetFetcherByID(0);
test_fetcher->delegate()->OnURLFetchComplete(test_fetcher);
histogram_tester().ExpectUniqueSample(kHistogramSucceeded, true, 2);
EXPECT_FALSE(factory()->GetFetcherByID(0));
histogram_tester().ExpectTotalCount(kHistogramAttempted, 2);
}
TEST_F(DataReductionProxyPingbackClientTest, NoPingbackSent) {
Init();

Powered by Google App Engine
This is Rietveld 408576698