| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/reporting/reporting_delivery_agent.h" | 5 #include "net/reporting/reporting_delivery_agent.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/test/simple_test_tick_clock.h" | 11 #include "base/test/simple_test_tick_clock.h" |
| 12 #include "base/test/values_test_util.h" | 12 #include "base/test/values_test_util.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/timer/mock_timer.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "net/base/backoff_entry.h" | 16 #include "net/base/backoff_entry.h" |
| 16 #include "net/reporting/reporting_cache.h" | 17 #include "net/reporting/reporting_cache.h" |
| 17 #include "net/reporting/reporting_report.h" | 18 #include "net/reporting/reporting_report.h" |
| 18 #include "net/reporting/reporting_test_util.h" | 19 #include "net/reporting/reporting_test_util.h" |
| 19 #include "net/reporting/reporting_uploader.h" | 20 #include "net/reporting/reporting_uploader.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 #include "url/origin.h" | 23 #include "url/origin.h" |
| 23 | 24 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 policy.endpoint_backoff_policy.maximum_backoff_ms = -1; | 36 policy.endpoint_backoff_policy.maximum_backoff_ms = -1; |
| 36 policy.endpoint_backoff_policy.entry_lifetime_ms = 0; | 37 policy.endpoint_backoff_policy.entry_lifetime_ms = 0; |
| 37 policy.endpoint_backoff_policy.always_use_initial_delay = false; | 38 policy.endpoint_backoff_policy.always_use_initial_delay = false; |
| 38 UsePolicy(policy); | 39 UsePolicy(policy); |
| 39 } | 40 } |
| 40 | 41 |
| 41 base::TimeTicks tomorrow() { | 42 base::TimeTicks tomorrow() { |
| 42 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); | 43 return tick_clock()->NowTicks() + base::TimeDelta::FromDays(1); |
| 43 } | 44 } |
| 44 | 45 |
| 45 const std::vector<std::unique_ptr<TestReportingUploader::PendingUpload>>& | |
| 46 pending_uploads() { | |
| 47 return uploader()->pending_uploads(); | |
| 48 } | |
| 49 | |
| 50 const GURL kUrl_ = GURL("https://origin/path"); | 46 const GURL kUrl_ = GURL("https://origin/path"); |
| 51 const url::Origin kOrigin_ = url::Origin(GURL("https://origin/")); | 47 const url::Origin kOrigin_ = url::Origin(GURL("https://origin/")); |
| 52 const GURL kEndpoint_ = GURL("https://endpoint/"); | 48 const GURL kEndpoint_ = GURL("https://endpoint/"); |
| 53 const std::string kGroup_ = "group"; | 49 const std::string kGroup_ = "group"; |
| 54 const std::string kType_ = "type"; | 50 const std::string kType_ = "type"; |
| 55 }; | 51 }; |
| 56 | 52 |
| 57 TEST_F(ReportingDeliveryAgentTest, SuccessfulUpload) { | 53 TEST_F(ReportingDeliveryAgentTest, SuccessfulUpload) { |
| 58 static const int kAgeMillis = 12345; | 54 static const int kAgeMillis = 12345; |
| 59 | 55 |
| 60 base::DictionaryValue body; | 56 base::DictionaryValue body; |
| 61 body.SetString("key", "value"); | 57 body.SetString("key", "value"); |
| 62 | 58 |
| 63 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, | 59 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, |
| 64 kGroup_, tomorrow()); | 60 kGroup_, tomorrow()); |
| 65 cache()->AddReport(kUrl_, kGroup_, kType_, body.CreateDeepCopy(), | 61 cache()->AddReport(kUrl_, kGroup_, kType_, body.CreateDeepCopy(), |
| 66 tick_clock()->NowTicks(), 0); | 62 tick_clock()->NowTicks(), 0); |
| 67 | 63 |
| 68 tick_clock()->Advance(base::TimeDelta::FromMilliseconds(kAgeMillis)); | 64 tick_clock()->Advance(base::TimeDelta::FromMilliseconds(kAgeMillis)); |
| 69 | 65 |
| 70 delivery_agent()->SendReports(); | 66 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 67 delivery_timer()->Fire(); |
| 71 | 68 |
| 72 ASSERT_EQ(1u, pending_uploads().size()); | 69 ASSERT_EQ(1u, pending_uploads().size()); |
| 73 EXPECT_EQ(kEndpoint_, pending_uploads()[0]->url()); | 70 EXPECT_EQ(kEndpoint_, pending_uploads()[0]->url()); |
| 74 { | 71 { |
| 75 auto value = pending_uploads()[0]->GetValue(); | 72 auto value = pending_uploads()[0]->GetValue(); |
| 76 | 73 |
| 77 base::ListValue* list; | 74 base::ListValue* list; |
| 78 ASSERT_TRUE(value->GetAsList(&list)); | 75 ASSERT_TRUE(value->GetAsList(&list)); |
| 79 EXPECT_EQ(1u, list->GetSize()); | 76 EXPECT_EQ(1u, list->GetSize()); |
| 80 | 77 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 97 // TODO(juliatuttle): Check that BackoffEntry was informed of success. | 94 // TODO(juliatuttle): Check that BackoffEntry was informed of success. |
| 98 } | 95 } |
| 99 | 96 |
| 100 TEST_F(ReportingDeliveryAgentTest, FailedUpload) { | 97 TEST_F(ReportingDeliveryAgentTest, FailedUpload) { |
| 101 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, | 98 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, |
| 102 kGroup_, tomorrow()); | 99 kGroup_, tomorrow()); |
| 103 cache()->AddReport(kUrl_, kGroup_, kType_, | 100 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 104 base::MakeUnique<base::DictionaryValue>(), | 101 base::MakeUnique<base::DictionaryValue>(), |
| 105 tick_clock()->NowTicks(), 0); | 102 tick_clock()->NowTicks(), 0); |
| 106 | 103 |
| 107 delivery_agent()->SendReports(); | 104 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 105 delivery_timer()->Fire(); |
| 108 | 106 |
| 109 ASSERT_EQ(1u, pending_uploads().size()); | 107 ASSERT_EQ(1u, pending_uploads().size()); |
| 110 pending_uploads()[0]->Complete(ReportingUploader::Outcome::FAILURE); | 108 pending_uploads()[0]->Complete(ReportingUploader::Outcome::FAILURE); |
| 111 | 109 |
| 112 // Failed upload should increment reports' attempts. | 110 // Failed upload should increment reports' attempts. |
| 113 std::vector<const ReportingReport*> reports; | 111 std::vector<const ReportingReport*> reports; |
| 114 cache()->GetReports(&reports); | 112 cache()->GetReports(&reports); |
| 115 ASSERT_EQ(1u, reports.size()); | 113 ASSERT_EQ(1u, reports.size()); |
| 116 EXPECT_EQ(1, reports[0]->attempts); | 114 EXPECT_EQ(1, reports[0]->attempts); |
| 117 | 115 |
| 118 // Since endpoint is now failing, an upload won't be started despite a pending | 116 // Since endpoint is now failing, an upload won't be started despite a pending |
| 119 // report. | 117 // report. |
| 120 ASSERT_TRUE(pending_uploads().empty()); | 118 ASSERT_TRUE(pending_uploads().empty()); |
| 121 delivery_agent()->SendReports(); | 119 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 120 delivery_timer()->Fire(); |
| 122 EXPECT_TRUE(pending_uploads().empty()); | 121 EXPECT_TRUE(pending_uploads().empty()); |
| 123 } | 122 } |
| 124 | 123 |
| 125 TEST_F(ReportingDeliveryAgentTest, RemoveEndpointUpload) { | 124 TEST_F(ReportingDeliveryAgentTest, RemoveEndpointUpload) { |
| 126 static const url::Origin kDifferentOrigin(GURL("https://origin2/")); | 125 static const url::Origin kDifferentOrigin(GURL("https://origin2/")); |
| 127 | 126 |
| 128 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, | 127 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, |
| 129 kGroup_, tomorrow()); | 128 kGroup_, tomorrow()); |
| 130 cache()->SetClient(kDifferentOrigin, kEndpoint_, | 129 cache()->SetClient(kDifferentOrigin, kEndpoint_, |
| 131 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); | 130 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); |
| 132 ASSERT_TRUE(FindClientInCache(cache(), kOrigin_, kEndpoint_)); | 131 ASSERT_TRUE(FindClientInCache(cache(), kOrigin_, kEndpoint_)); |
| 133 ASSERT_TRUE(FindClientInCache(cache(), kDifferentOrigin, kEndpoint_)); | 132 ASSERT_TRUE(FindClientInCache(cache(), kDifferentOrigin, kEndpoint_)); |
| 134 | 133 |
| 135 cache()->AddReport(kUrl_, kGroup_, kType_, | 134 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 136 base::MakeUnique<base::DictionaryValue>(), | 135 base::MakeUnique<base::DictionaryValue>(), |
| 137 tick_clock()->NowTicks(), 0); | 136 tick_clock()->NowTicks(), 0); |
| 138 | 137 |
| 139 delivery_agent()->SendReports(); | 138 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 139 delivery_timer()->Fire(); |
| 140 | 140 |
| 141 ASSERT_EQ(1u, pending_uploads().size()); | 141 ASSERT_EQ(1u, pending_uploads().size()); |
| 142 pending_uploads()[0]->Complete(ReportingUploader::Outcome::REMOVE_ENDPOINT); | 142 pending_uploads()[0]->Complete(ReportingUploader::Outcome::REMOVE_ENDPOINT); |
| 143 | 143 |
| 144 // "Remove endpoint" upload should remove endpoint from *all* origins and | 144 // "Remove endpoint" upload should remove endpoint from *all* origins and |
| 145 // increment reports' attempts. | 145 // increment reports' attempts. |
| 146 std::vector<const ReportingReport*> reports; | 146 std::vector<const ReportingReport*> reports; |
| 147 cache()->GetReports(&reports); | 147 cache()->GetReports(&reports); |
| 148 ASSERT_EQ(1u, reports.size()); | 148 ASSERT_EQ(1u, reports.size()); |
| 149 EXPECT_EQ(1, reports[0]->attempts); | 149 EXPECT_EQ(1, reports[0]->attempts); |
| 150 | 150 |
| 151 EXPECT_FALSE(FindClientInCache(cache(), kOrigin_, kEndpoint_)); | 151 EXPECT_FALSE(FindClientInCache(cache(), kOrigin_, kEndpoint_)); |
| 152 EXPECT_FALSE(FindClientInCache(cache(), kDifferentOrigin, kEndpoint_)); | 152 EXPECT_FALSE(FindClientInCache(cache(), kDifferentOrigin, kEndpoint_)); |
| 153 | 153 |
| 154 // Since endpoint is now failing, an upload won't be started despite a pending | 154 // Since endpoint is now failing, an upload won't be started despite a pending |
| 155 // report. | 155 // report. |
| 156 delivery_agent()->SendReports(); | 156 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 157 delivery_timer()->Fire(); |
| 157 EXPECT_TRUE(pending_uploads().empty()); | 158 EXPECT_TRUE(pending_uploads().empty()); |
| 158 } | 159 } |
| 159 | 160 |
| 160 TEST_F(ReportingDeliveryAgentTest, ConcurrentRemove) { | 161 TEST_F(ReportingDeliveryAgentTest, ConcurrentRemove) { |
| 161 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, | 162 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, |
| 162 kGroup_, tomorrow()); | 163 kGroup_, tomorrow()); |
| 163 cache()->AddReport(kUrl_, kGroup_, kType_, | 164 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 164 base::MakeUnique<base::DictionaryValue>(), | 165 base::MakeUnique<base::DictionaryValue>(), |
| 165 tick_clock()->NowTicks(), 0); | 166 tick_clock()->NowTicks(), 0); |
| 166 | 167 |
| 167 delivery_agent()->SendReports(); | 168 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 169 delivery_timer()->Fire(); |
| 168 ASSERT_EQ(1u, pending_uploads().size()); | 170 ASSERT_EQ(1u, pending_uploads().size()); |
| 169 | 171 |
| 170 // Remove the report while the upload is running. | 172 // Remove the report while the upload is running. |
| 171 std::vector<const ReportingReport*> reports; | 173 std::vector<const ReportingReport*> reports; |
| 172 cache()->GetReports(&reports); | 174 cache()->GetReports(&reports); |
| 173 EXPECT_EQ(1u, reports.size()); | 175 EXPECT_EQ(1u, reports.size()); |
| 174 | 176 |
| 175 const ReportingReport* report = reports[0]; | 177 const ReportingReport* report = reports[0]; |
| 176 EXPECT_FALSE(cache()->IsReportDoomedForTesting(report)); | 178 EXPECT_FALSE(cache()->IsReportDoomedForTesting(report)); |
| 177 | 179 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 202 cache()->SetClient(kDifferentOrigin, kEndpoint_, | 204 cache()->SetClient(kDifferentOrigin, kEndpoint_, |
| 203 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); | 205 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); |
| 204 | 206 |
| 205 cache()->AddReport(kUrl_, kGroup_, kType_, | 207 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 206 base::MakeUnique<base::DictionaryValue>(), | 208 base::MakeUnique<base::DictionaryValue>(), |
| 207 tick_clock()->NowTicks(), 0); | 209 tick_clock()->NowTicks(), 0); |
| 208 cache()->AddReport(kDifferentUrl, kGroup_, kType_, | 210 cache()->AddReport(kDifferentUrl, kGroup_, kType_, |
| 209 base::MakeUnique<base::DictionaryValue>(), | 211 base::MakeUnique<base::DictionaryValue>(), |
| 210 tick_clock()->NowTicks(), 0); | 212 tick_clock()->NowTicks(), 0); |
| 211 | 213 |
| 212 delivery_agent()->SendReports(); | 214 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 215 delivery_timer()->Fire(); |
| 213 ASSERT_EQ(1u, pending_uploads().size()); | 216 ASSERT_EQ(1u, pending_uploads().size()); |
| 214 | 217 |
| 215 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); | 218 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); |
| 216 EXPECT_EQ(0u, pending_uploads().size()); | 219 EXPECT_EQ(0u, pending_uploads().size()); |
| 217 } | 220 } |
| 218 | 221 |
| 219 // Test that the agent won't start a second upload to the same endpoint (even | 222 // Test that the agent won't start a second upload to the same endpoint (even |
| 220 // for a different origin) while one is pending, but will once it is no longer | 223 // for a different origin) while one is pending, but will once it is no longer |
| 221 // pending. | 224 // pending. |
| 222 TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToEndpoint) { | 225 TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToEndpoint) { |
| 223 static const GURL kDifferentUrl("https://origin2/path"); | 226 static const GURL kDifferentUrl("https://origin2/path"); |
| 224 static const url::Origin kDifferentOrigin(kDifferentUrl); | 227 static const url::Origin kDifferentOrigin(kDifferentUrl); |
| 225 | 228 |
| 226 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, | 229 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, |
| 227 kGroup_, tomorrow()); | 230 kGroup_, tomorrow()); |
| 228 cache()->SetClient(kDifferentOrigin, kEndpoint_, | 231 cache()->SetClient(kDifferentOrigin, kEndpoint_, |
| 229 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); | 232 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); |
| 230 | 233 |
| 231 cache()->AddReport(kUrl_, kGroup_, kType_, | 234 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 232 base::MakeUnique<base::DictionaryValue>(), | 235 base::MakeUnique<base::DictionaryValue>(), |
| 233 tick_clock()->NowTicks(), 0); | 236 tick_clock()->NowTicks(), 0); |
| 234 | 237 |
| 235 delivery_agent()->SendReports(); | 238 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 239 delivery_timer()->Fire(); |
| 236 EXPECT_EQ(1u, pending_uploads().size()); | 240 EXPECT_EQ(1u, pending_uploads().size()); |
| 237 | 241 |
| 238 cache()->AddReport(kDifferentUrl, kGroup_, kType_, | 242 cache()->AddReport(kDifferentUrl, kGroup_, kType_, |
| 239 base::MakeUnique<base::DictionaryValue>(), | 243 base::MakeUnique<base::DictionaryValue>(), |
| 240 tick_clock()->NowTicks(), 0); | 244 tick_clock()->NowTicks(), 0); |
| 241 | 245 |
| 242 delivery_agent()->SendReports(); | 246 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 247 delivery_timer()->Fire(); |
| 243 ASSERT_EQ(1u, pending_uploads().size()); | 248 ASSERT_EQ(1u, pending_uploads().size()); |
| 244 | 249 |
| 245 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); | 250 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); |
| 246 EXPECT_EQ(0u, pending_uploads().size()); | 251 EXPECT_EQ(0u, pending_uploads().size()); |
| 247 | 252 |
| 248 delivery_agent()->SendReports(); | 253 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 254 delivery_timer()->Fire(); |
| 249 ASSERT_EQ(1u, pending_uploads().size()); | 255 ASSERT_EQ(1u, pending_uploads().size()); |
| 250 | 256 |
| 251 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); | 257 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); |
| 252 EXPECT_EQ(0u, pending_uploads().size()); | 258 EXPECT_EQ(0u, pending_uploads().size()); |
| 253 } | 259 } |
| 254 | 260 |
| 255 // Test that the agent won't start a second upload for an (origin, group) while | 261 // Test that the agent won't start a second upload for an (origin, group) while |
| 256 // one is pending, even if a different endpoint is available, but will once the | 262 // one is pending, even if a different endpoint is available, but will once the |
| 257 // original delivery is complete and the (origin, group) is no longer pending. | 263 // original delivery is complete and the (origin, group) is no longer pending. |
| 258 TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToGroup) { | 264 TEST_F(ReportingDeliveryAgentTest, SerializeUploadsToGroup) { |
| 259 static const GURL kDifferentEndpoint("https://endpoint2/"); | 265 static const GURL kDifferentEndpoint("https://endpoint2/"); |
| 260 | 266 |
| 261 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, | 267 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, |
| 262 kGroup_, tomorrow()); | 268 kGroup_, tomorrow()); |
| 263 cache()->SetClient(kOrigin_, kDifferentEndpoint, | 269 cache()->SetClient(kOrigin_, kDifferentEndpoint, |
| 264 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); | 270 ReportingClient::Subdomains::EXCLUDE, kGroup_, tomorrow()); |
| 265 | 271 |
| 266 cache()->AddReport(kUrl_, kGroup_, kType_, | 272 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 267 base::MakeUnique<base::DictionaryValue>(), | 273 base::MakeUnique<base::DictionaryValue>(), |
| 268 tick_clock()->NowTicks(), 0); | 274 tick_clock()->NowTicks(), 0); |
| 269 | 275 |
| 270 delivery_agent()->SendReports(); | 276 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 277 delivery_timer()->Fire(); |
| 271 EXPECT_EQ(1u, pending_uploads().size()); | 278 EXPECT_EQ(1u, pending_uploads().size()); |
| 272 | 279 |
| 273 cache()->AddReport(kUrl_, kGroup_, kType_, | 280 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 274 base::MakeUnique<base::DictionaryValue>(), | 281 base::MakeUnique<base::DictionaryValue>(), |
| 275 tick_clock()->NowTicks(), 0); | 282 tick_clock()->NowTicks(), 0); |
| 276 | 283 |
| 277 delivery_agent()->SendReports(); | 284 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 285 delivery_timer()->Fire(); |
| 278 ASSERT_EQ(1u, pending_uploads().size()); | 286 ASSERT_EQ(1u, pending_uploads().size()); |
| 279 | 287 |
| 280 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); | 288 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); |
| 281 EXPECT_EQ(0u, pending_uploads().size()); | 289 EXPECT_EQ(0u, pending_uploads().size()); |
| 282 | 290 |
| 283 delivery_agent()->SendReports(); | 291 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 292 delivery_timer()->Fire(); |
| 284 ASSERT_EQ(1u, pending_uploads().size()); | 293 ASSERT_EQ(1u, pending_uploads().size()); |
| 285 | 294 |
| 286 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); | 295 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); |
| 287 EXPECT_EQ(0u, pending_uploads().size()); | 296 EXPECT_EQ(0u, pending_uploads().size()); |
| 288 } | 297 } |
| 289 | 298 |
| 290 // Tests that the agent will start parallel uploads to different groups within | 299 // Tests that the agent will start parallel uploads to different groups within |
| 291 // the same origin. | 300 // the same origin. |
| 292 TEST_F(ReportingDeliveryAgentTest, ParallelizeUploadsAcrossGroups) { | 301 TEST_F(ReportingDeliveryAgentTest, ParallelizeUploadsAcrossGroups) { |
| 293 static const GURL kDifferentEndpoint("https://endpoint2/"); | 302 static const GURL kDifferentEndpoint("https://endpoint2/"); |
| 294 static const std::string kDifferentGroup("group2"); | 303 static const std::string kDifferentGroup("group2"); |
| 295 | 304 |
| 296 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, | 305 cache()->SetClient(kOrigin_, kEndpoint_, ReportingClient::Subdomains::EXCLUDE, |
| 297 kGroup_, tomorrow()); | 306 kGroup_, tomorrow()); |
| 298 cache()->SetClient(kOrigin_, kDifferentEndpoint, | 307 cache()->SetClient(kOrigin_, kDifferentEndpoint, |
| 299 ReportingClient::Subdomains::EXCLUDE, kDifferentGroup, | 308 ReportingClient::Subdomains::EXCLUDE, kDifferentGroup, |
| 300 tomorrow()); | 309 tomorrow()); |
| 301 | 310 |
| 302 cache()->AddReport(kUrl_, kGroup_, kType_, | 311 cache()->AddReport(kUrl_, kGroup_, kType_, |
| 303 base::MakeUnique<base::DictionaryValue>(), | 312 base::MakeUnique<base::DictionaryValue>(), |
| 304 tick_clock()->NowTicks(), 0); | 313 tick_clock()->NowTicks(), 0); |
| 305 cache()->AddReport(kUrl_, kDifferentGroup, kType_, | 314 cache()->AddReport(kUrl_, kDifferentGroup, kType_, |
| 306 base::MakeUnique<base::DictionaryValue>(), | 315 base::MakeUnique<base::DictionaryValue>(), |
| 307 tick_clock()->NowTicks(), 0); | 316 tick_clock()->NowTicks(), 0); |
| 308 | 317 |
| 309 delivery_agent()->SendReports(); | 318 EXPECT_TRUE(delivery_timer()->IsRunning()); |
| 319 delivery_timer()->Fire(); |
| 310 ASSERT_EQ(2u, pending_uploads().size()); | 320 ASSERT_EQ(2u, pending_uploads().size()); |
| 311 | 321 |
| 312 pending_uploads()[1]->Complete(ReportingUploader::Outcome::SUCCESS); | 322 pending_uploads()[1]->Complete(ReportingUploader::Outcome::SUCCESS); |
| 313 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); | 323 pending_uploads()[0]->Complete(ReportingUploader::Outcome::SUCCESS); |
| 314 EXPECT_EQ(0u, pending_uploads().size()); | 324 EXPECT_EQ(0u, pending_uploads().size()); |
| 315 } | 325 } |
| 316 | 326 |
| 317 } // namespace | 327 } // namespace |
| 318 } // namespace net | 328 } // namespace net |
| OLD | NEW |