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

Side by Side Diff: components/domain_reliability/monitor_unittest.cc

Issue 252613002: Domain Reliability: More security review. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: s/&*config/config.get()/g Created 6 years, 7 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 unified diff | Download patch
OLDNEW
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
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
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
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
Ryan Sleevi 2014/05/05 19:16:03 There's no tests for OnBeforeRedirect here, which
Deprecated (see juliatuttle) 2014/05/06 18:52:03 There aren't any for OnComplete, either! I was try
Ryan Sleevi 2014/05/06 19:06:25 Not off the top of my head. However, what you're
168 } // namespace domain_reliability 170 } // namespace domain_reliability
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698