| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/domain_reliability/monitor.h" | 5 #include "components/domain_reliability/monitor.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 class DomainReliabilityMonitorTest : public testing::Test { | 29 class DomainReliabilityMonitorTest : public testing::Test { |
| 30 protected: | 30 protected: |
| 31 typedef DomainReliabilityMonitor::RequestInfo RequestInfo; | 31 typedef DomainReliabilityMonitor::RequestInfo RequestInfo; |
| 32 | 32 |
| 33 DomainReliabilityMonitorTest() | 33 DomainReliabilityMonitorTest() |
| 34 : bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 34 : bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 35 url_request_context_getter_(new net::TestURLRequestContextGetter( | 35 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 36 base::MessageLoopProxy::current())), | 36 base::MessageLoopProxy::current())), |
| 37 time_(new MockTime()), | 37 time_(new MockTime()), |
| 38 monitor_(url_request_context_getter_->GetURLRequestContext(), | 38 monitor_(url_request_context_getter_->GetURLRequestContext(), |
| 39 "test-reporter", |
| 39 scoped_ptr<MockableTime>(time_)), | 40 scoped_ptr<MockableTime>(time_)), |
| 40 context_(monitor_.AddContextForTesting(CreateConfig())) {} | 41 context_(monitor_.AddContextForTesting(CreateConfig())) {} |
| 41 | 42 |
| 42 static scoped_ptr<const DomainReliabilityConfig> CreateConfig() { | 43 static scoped_ptr<const DomainReliabilityConfig> CreateConfig() { |
| 43 DomainReliabilityConfig* config = new DomainReliabilityConfig(); | 44 DomainReliabilityConfig* config = new DomainReliabilityConfig(); |
| 44 | 45 |
| 45 DomainReliabilityConfig::Resource* resource; | 46 DomainReliabilityConfig::Resource* resource; |
| 46 | 47 |
| 47 resource = new DomainReliabilityConfig::Resource(); | 48 resource = new DomainReliabilityConfig::Resource(); |
| 48 resource->name = "always_report"; | 49 resource->name = "always_report"; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 79 RequestInfo MakeRequestInfo() { | 80 RequestInfo MakeRequestInfo() { |
| 80 RequestInfo request; | 81 RequestInfo request; |
| 81 request.status = net::URLRequestStatus(); | 82 request.status = net::URLRequestStatus(); |
| 82 request.response_code = 200; | 83 request.response_code = 200; |
| 83 request.was_cached = false; | 84 request.was_cached = false; |
| 84 request.load_flags = 0; | 85 request.load_flags = 0; |
| 85 request.is_upload = false; | 86 request.is_upload = false; |
| 86 return request; | 87 return request; |
| 87 } | 88 } |
| 88 | 89 |
| 89 bool CheckNoBeacons(int index) { | 90 bool CheckNoBeacons(size_t index) { |
| 90 BeaconVector beacons; | 91 BeaconVector beacons; |
| 91 int successful, failed; | 92 unsigned successful, failed; |
| 92 context_->GetQueuedDataForTesting(index, &beacons, &successful, &failed); | 93 context_->GetQueuedDataForTesting(index, &beacons, &successful, &failed); |
| 93 return beacons.empty() && successful == 0 && failed == 0; | 94 return beacons.empty() && successful == 0 && failed == 0; |
| 94 } | 95 } |
| 95 | 96 |
| 96 void OnRequestLegComplete(const RequestInfo& info) { | 97 void OnRequestLegComplete(const RequestInfo& info) { |
| 97 monitor_.OnRequestLegComplete(info); | 98 monitor_.OnRequestLegComplete(info); |
| 98 } | 99 } |
| 99 | 100 |
| 100 content::TestBrowserThreadBundle bundle_; | 101 content::TestBrowserThreadBundle bundle_; |
| 101 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 102 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 EXPECT_TRUE(CheckNoBeacons(0)); | 150 EXPECT_TRUE(CheckNoBeacons(0)); |
| 150 EXPECT_TRUE(CheckNoBeacons(1)); | 151 EXPECT_TRUE(CheckNoBeacons(1)); |
| 151 } | 152 } |
| 152 | 153 |
| 153 TEST_F(DomainReliabilityMonitorTest, AddBakedInConfigs) { | 154 TEST_F(DomainReliabilityMonitorTest, AddBakedInConfigs) { |
| 154 // AddBakedInConfigs DCHECKs that the baked-in configs parse correctly, so | 155 // AddBakedInConfigs DCHECKs that the baked-in configs parse correctly, so |
| 155 // this unittest will fail if someone tries to add an invalid config to the | 156 // this unittest will fail if someone tries to add an invalid config to the |
| 156 // source tree. | 157 // source tree. |
| 157 monitor_.AddBakedInConfigs(); | 158 monitor_.AddBakedInConfigs(); |
| 158 | 159 |
| 160 // Count the number of baked-in configs. |
| 159 size_t num_baked_in_configs = 0; | 161 size_t num_baked_in_configs = 0; |
| 160 for (const char* const* p = kBakedInJsonConfigs; *p; ++p) | 162 for (const char* const* p = kBakedInJsonConfigs; *p; ++p) |
| 161 ++num_baked_in_configs; | 163 ++num_baked_in_configs; |
| 162 | 164 |
| 163 // The monitor should have contexts for all of the baked-in configs, plus the | 165 // The monitor should have contexts for all of the baked-in configs, plus the |
| 164 // test one added in the test constructor. | 166 // test one added in the test constructor. |
| 165 EXPECT_EQ(num_baked_in_configs + 1, monitor_.contexts_size_for_testing()); | 167 EXPECT_EQ(num_baked_in_configs + 1, monitor_.contexts_size_for_testing()); |
| 166 } | 168 } |
| 167 | 169 |
| 168 } // namespace domain_reliability | 170 } // namespace domain_reliability |
| OLD | NEW |