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

Unified Diff: components/domain_reliability/context_unittest.cc

Issue 691053003: Domain Reliability: Mark beacons from previous networks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Context unittest Created 6 years, 1 month 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
« no previous file with comments | « components/domain_reliability/context.cc ('k') | components/domain_reliability/monitor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/domain_reliability/context_unittest.cc
diff --git a/components/domain_reliability/context_unittest.cc b/components/domain_reliability/context_unittest.cc
index c54322b8e541a61a94bd1fcbf99057898e2c9b25..326e98ba81dc9b0cd1720e51cee0f79197412de2 100644
--- a/components/domain_reliability/context_unittest.cc
+++ b/components/domain_reliability/context_unittest.cc
@@ -39,7 +39,8 @@ DomainReliabilityBeacon MakeBeacon(MockableTime* time) {
class DomainReliabilityContextTest : public testing::Test {
protected:
DomainReliabilityContextTest()
- : dispatcher_(&time_),
+ : last_network_change_time_(time_.NowTicks()),
+ dispatcher_(&time_),
params_(MakeTestSchedulerParams()),
uploader_(base::Bind(&DomainReliabilityContextTest::OnUploadRequest,
base::Unretained(this))),
@@ -47,10 +48,16 @@ class DomainReliabilityContextTest : public testing::Test {
context_(&time_,
params_,
upload_reporter_string_,
+ &last_network_change_time_,
&dispatcher_,
&uploader_,
MakeTestConfig().Pass()),
- upload_pending_(false) {}
+ upload_pending_(false) {
+ // Make sure that the last network change does not overlap requests
+ // made in test cases, which start 250ms in the past (see |MakeBeacon|).
+ last_network_change_time_ = time_.NowTicks();
+ time_.Advance(base::TimeDelta::FromSeconds(1));
+ }
TimeDelta min_delay() const { return params_.minimum_upload_delay; }
TimeDelta max_delay() const { return params_.maximum_upload_delay; }
@@ -90,6 +97,7 @@ class DomainReliabilityContextTest : public testing::Test {
}
MockTime time_;
+ base::TimeTicks last_network_change_time_;
DomainReliabilityDispatcher dispatcher_;
DomainReliabilityScheduler::Params params_;
MockUploader uploader_;
@@ -186,5 +194,42 @@ TEST_F(DomainReliabilityContextTest, ReportUpload) {
EXPECT_TRUE(CheckCounts(1, 0, 0));
}
+TEST_F(DomainReliabilityContextTest, ReportUpload_NetworkChanged) {
+ GURL url("http://example/always_report");
+ DomainReliabilityBeacon beacon = MakeBeacon(&time_);
+ context_.OnBeacon(url, beacon);
+
+ BeaconVector beacons;
+ context_.GetQueuedBeaconsForTesting(&beacons);
+ EXPECT_EQ(1u, beacons.size());
+ EXPECT_TRUE(CheckCounts(0, 1, 0));
+ EXPECT_TRUE(CheckCounts(1, 0, 0));
+
+ // N.B.: Assumes max_delay is 5 minutes.
+ const char* kExpectedReport = "{"
+ "\"config_version\":\"1\","
+ "\"entries\":[{\"domain\":\"localhost\","
+ "\"http_response_code\":200,\"network_changed\":true,"
+ "\"protocol\":\"HTTP\",\"request_age_ms\":300250,"
+ "\"request_elapsed_ms\":250,\"resource\":\"always_report\","
+ "\"server_ip\":\"127.0.0.1\",\"status\":\"ok\"}],"
+ "\"reporter\":\"test-reporter\","
+ "\"resources\":[{\"failed_requests\":0,\"name\":\"always_report\","
+ "\"successful_requests\":1}]}";
+
+ // Simulate a network change after the request but before the upload.
+ last_network_change_time_ = time_.NowTicks();
+ time_.Advance(max_delay());
+
+ EXPECT_TRUE(upload_pending());
+ EXPECT_EQ(kExpectedReport, upload_report());
+ EXPECT_EQ(GURL("https://exampleuploader/upload"), upload_url());
+ CallUploadCallback(true);
+
+ EXPECT_TRUE(CheckNoBeacons());
+ EXPECT_TRUE(CheckCounts(0, 0, 0));
+ EXPECT_TRUE(CheckCounts(1, 0, 0));
+}
+
} // namespace
} // namespace domain_reliability
« no previous file with comments | « components/domain_reliability/context.cc ('k') | components/domain_reliability/monitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698