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

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

Issue 2149193002: Sending the time of the pingback request in the request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo 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 50bb13080974e15c3bee83b7b25ec70830f0ec82..852a69b7d002110a9b63232f6b1b2cc66704a7ed 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
@@ -40,36 +40,50 @@ static const char kFakeURL[] = "http://www.google.com/";
} // namespace
// 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) {}
+ override_value_(0.0f),
+ current_time_(base::Time::Now()) {}
+ // Overrides the bahvior of the random float generator in
+ // DataReductionProxyPingbackClient.
+ // If |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_; }
+
bool should_override_random_;
float override_value_;
+ base::Time current_time_;
};
class DataReductionProxyPingbackClientTest : public testing::Test {
public:
DataReductionProxyPingbackClientTest()
: timing_(base::Time::FromJsTime(1500),
base::Optional<base::TimeDelta>(
base::TimeDelta::FromMilliseconds(1600)),
base::Optional<base::TimeDelta>(
base::TimeDelta::FromMilliseconds(1700)),
@@ -111,26 +125,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()));

Powered by Google App Engine
This is Rietveld 408576698