| 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 23 matching lines...) Expand all Loading... |
| 34 static const size_t kAlwaysReportIndex = 0u; | 34 static const size_t kAlwaysReportIndex = 0u; |
| 35 static const size_t kNeverReportIndex = 1u; | 35 static const size_t kNeverReportIndex = 1u; |
| 36 | 36 |
| 37 scoped_refptr<net::HttpResponseHeaders> MakeHttpResponseHeaders( | 37 scoped_refptr<net::HttpResponseHeaders> MakeHttpResponseHeaders( |
| 38 const std::string& headers) { | 38 const std::string& headers) { |
| 39 return scoped_refptr<net::HttpResponseHeaders>( | 39 return scoped_refptr<net::HttpResponseHeaders>( |
| 40 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders( | 40 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders( |
| 41 headers.c_str(), headers.length()))); | 41 headers.c_str(), headers.length()))); |
| 42 } | 42 } |
| 43 | 43 |
| 44 static scoped_ptr<const DomainReliabilityConfig> MakeConfig() { | |
| 45 DomainReliabilityConfig* config = new DomainReliabilityConfig(); | |
| 46 | |
| 47 DomainReliabilityConfig::Resource* resource; | |
| 48 | |
| 49 resource = new DomainReliabilityConfig::Resource(); | |
| 50 resource->name = "always_report"; | |
| 51 resource->url_patterns.push_back( | |
| 52 new std::string("http://example/always_report")); | |
| 53 resource->success_sample_rate = 1.0; | |
| 54 resource->failure_sample_rate = 1.0; | |
| 55 EXPECT_TRUE(resource->IsValid()); | |
| 56 config->resources.push_back(resource); | |
| 57 | |
| 58 resource = new DomainReliabilityConfig::Resource(); | |
| 59 resource->name = "never_report"; | |
| 60 resource->url_patterns.push_back( | |
| 61 new std::string("http://example/never_report")); | |
| 62 resource->success_sample_rate = 0.0; | |
| 63 resource->failure_sample_rate = 0.0; | |
| 64 EXPECT_TRUE(resource->IsValid()); | |
| 65 config->resources.push_back(resource); | |
| 66 | |
| 67 DomainReliabilityConfig::Collector* collector; | |
| 68 collector = new DomainReliabilityConfig::Collector(); | |
| 69 collector->upload_url = GURL("https://example/upload"); | |
| 70 EXPECT_TRUE(collector->IsValid()); | |
| 71 config->collectors.push_back(collector); | |
| 72 | |
| 73 config->version = "1"; | |
| 74 config->valid_until = 1234567890.0; | |
| 75 config->domain = "example"; | |
| 76 EXPECT_TRUE(config->IsValid()); | |
| 77 | |
| 78 return scoped_ptr<const DomainReliabilityConfig>(config); | |
| 79 } | |
| 80 | |
| 81 } // namespace | 44 } // namespace |
| 82 | 45 |
| 83 class DomainReliabilityMonitorTest : public testing::Test { | 46 class DomainReliabilityMonitorTest : public testing::Test { |
| 84 protected: | 47 protected: |
| 85 typedef DomainReliabilityMonitor::RequestInfo RequestInfo; | 48 typedef DomainReliabilityMonitor::RequestInfo RequestInfo; |
| 86 | 49 |
| 87 DomainReliabilityMonitorTest() | 50 DomainReliabilityMonitorTest() |
| 88 : bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 51 : bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 89 url_request_context_getter_(new net::TestURLRequestContextGetter( | 52 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 90 base::MessageLoopProxy::current())), | 53 base::MessageLoopProxy::current())), |
| 91 time_(new MockTime()), | 54 time_(new MockTime()), |
| 92 monitor_(url_request_context_getter_->GetURLRequestContext(), | 55 monitor_(url_request_context_getter_->GetURLRequestContext(), |
| 93 "test-reporter", | 56 "test-reporter", |
| 94 scoped_ptr<MockableTime>(time_)), | 57 scoped_ptr<MockableTime>(time_)), |
| 95 context_(monitor_.AddContextForTesting(MakeConfig())) {} | 58 context_(monitor_.AddContextForTesting(MakeTestConfig())) {} |
| 96 | 59 |
| 97 static RequestInfo MakeRequestInfo() { | 60 static RequestInfo MakeRequestInfo() { |
| 98 RequestInfo request; | 61 RequestInfo request; |
| 99 request.status = net::URLRequestStatus(); | 62 request.status = net::URLRequestStatus(); |
| 100 request.status.set_status(net::URLRequestStatus::SUCCESS); | 63 request.status.set_status(net::URLRequestStatus::SUCCESS); |
| 101 request.status.set_error(net::OK); | 64 request.status.set_error(net::OK); |
| 102 request.response_info.socket_address = | 65 request.response_info.socket_address = |
| 103 net::HostPortPair::FromString("12.34.56.78:80"); | 66 net::HostPortPair::FromString("12.34.56.78:80"); |
| 104 request.response_info.headers = MakeHttpResponseHeaders( | 67 request.response_info.headers = MakeHttpResponseHeaders( |
| 105 "HTTP/1.1 200 OK\n\n"); | 68 "HTTP/1.1 200 OK\n\n"); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 285 |
| 323 monitor_.ClearBrowsingData(CLEAR_CONTEXTS); | 286 monitor_.ClearBrowsingData(CLEAR_CONTEXTS); |
| 324 | 287 |
| 325 // Clearing contexts should leave the monitor with none. | 288 // Clearing contexts should leave the monitor with none. |
| 326 EXPECT_EQ(0u, monitor_.contexts_size_for_testing()); | 289 EXPECT_EQ(0u, monitor_.contexts_size_for_testing()); |
| 327 } | 290 } |
| 328 | 291 |
| 329 } // namespace | 292 } // namespace |
| 330 | 293 |
| 331 } // namespace domain_reliability | 294 } // namespace domain_reliability |
| OLD | NEW |