Chromium Code Reviews| 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 50bb13080974e15c3bee83b7b25ec70830f0ec82..8711bc22062ab1d0bd5ba125f92f7fcc06bc7f0a 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 |
| @@ -42,32 +42,44 @@ static const char kFakeURL[] = "http://www.google.com/"; |
| // Controls whether a pingback is sent or not. |
| class TestDataReductionProxyPingbackClient |
| : public DataReductionProxyPingbackClient { |
| public: |
| TestDataReductionProxyPingbackClient( |
| net::URLRequestContextGetter* url_request_context_getter) |
| : DataReductionProxyPingbackClient(url_request_context_getter), |
| should_override_random_(false), |
| override_value_(0.0f) {} |
| + // Overrides the random behavior in DataReductionProxyPingbackClient. If |
|
tbansal1
2016/07/15 17:44:04
s/random behavior/behavior of random float generat
RyanSturm
2016/07/15 18:16:03
Done.
|
| + // |should_override_random| is true, the typically random value that is |
| + // compared with reporting fraction will deterministically be |
| + // |override_value|. |
| void OverrideRandom(bool should_override_random, float override_value) { |
| should_override_random_ = should_override_random; |
| override_value_ = override_value; |
| } |
| + // Sets the time used for the metrics reporting time. |
| + void set_current_time(base::Time current_time) { |
| + current_time_ = current_time; |
| + } |
| + |
| private: |
| float GenerateRandomFloat() const override { |
| if (should_override_random_) |
| return override_value_; |
| return DataReductionProxyPingbackClient::GenerateRandomFloat(); |
| } |
| + base::Time CurrentTime() const override { return current_time_; } |
| + |
| + base::Time current_time_; |
| bool should_override_random_; |
|
tbansal1
2016/07/15 17:44:04
Try to keep them in order. e.g., randomness relate
RyanSturm
2016/07/15 18:16:03
Done.
|
| float override_value_; |
| }; |
| class DataReductionProxyPingbackClientTest : public testing::Test { |
| public: |
| DataReductionProxyPingbackClientTest() |
| : timing_(base::Time::FromJsTime(1500), |
| base::Optional<base::TimeDelta>( |
| base::TimeDelta::FromMilliseconds(1600)), |
| @@ -111,26 +123,30 @@ class DataReductionProxyPingbackClientTest : public testing::Test { |
| net::TestURLFetcherFactory factory_; |
| DataReductionProxyPageLoadTiming timing_; |
| base::HistogramTester histogram_tester_; |
| }; |
| TEST_F(DataReductionProxyPingbackClientTest, VerifyPingbackContent) { |
| Init(); |
| EXPECT_FALSE(factory()->GetFetcherByID(0)); |
| 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(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( |
| timing().load_event_start.value(), |
| protobuf_parser::DurationToTimeDelta(pageload_metrics.page_load_time())); |