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/data_reduction_proxy/core/common/data_reduction_proxy_event
_store.h" | 5 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_event
_store.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 new DataReductionProxyEventCreator(event_store_.get())); | 35 new DataReductionProxyEventCreator(event_store_.get())); |
36 } | 36 } |
37 | 37 |
38 net::TestNetLogEntry GetSingleEntry() const { | 38 net::TestNetLogEntry GetSingleEntry() const { |
39 net::TestNetLogEntry::List entries; | 39 net::TestNetLogEntry::List entries; |
40 net_log_->GetEntries(&entries); | 40 net_log_->GetEntries(&entries); |
41 EXPECT_EQ(1u, entries.size()); | 41 EXPECT_EQ(1u, entries.size()); |
42 return entries[0]; | 42 return entries[0]; |
43 } | 43 } |
44 | 44 |
| 45 net::TestNetLogEntry GetLatestEntry() const { |
| 46 net::TestNetLogEntry::List entries; |
| 47 net_log_->GetEntries(&entries); |
| 48 return entries.back(); |
| 49 } |
| 50 |
45 DataReductionProxyEventStore* event_store() { return event_store_.get(); } | 51 DataReductionProxyEventStore* event_store() { return event_store_.get(); } |
46 | 52 |
47 DataReductionProxyEventCreator* event_creator() { | 53 DataReductionProxyEventCreator* event_creator() { |
48 return event_creator_.get(); | 54 return event_creator_.get(); |
49 } | 55 } |
50 | 56 |
51 net::TestNetLog* net_log() { return net_log_.get(); } | 57 net::TestNetLog* net_log() { return net_log_.get(); } |
52 | 58 |
53 const net::BoundNetLog& bound_net_log() { | 59 const net::BoundNetLog& bound_net_log() { |
54 return bound_net_log_; | 60 return bound_net_log_; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 event_creator()->EndSecureProxyCheck(bound_net_log(), 0, net::HTTP_OK, true); | 156 event_creator()->EndSecureProxyCheck(bound_net_log(), 0, net::HTTP_OK, true); |
151 EXPECT_EQ(1u, event_count()); | 157 EXPECT_EQ(1u, event_count()); |
152 EXPECT_EQ(1u, net_log()->GetSize()); | 158 EXPECT_EQ(1u, net_log()->GetSize()); |
153 net::TestNetLogEntry entry = GetSingleEntry(); | 159 net::TestNetLogEntry entry = GetSingleEntry(); |
154 EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST, | 160 EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST, |
155 entry.type); | 161 entry.type); |
156 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_SUCCESS, | 162 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_SUCCESS, |
157 secure_proxy_check_state()); | 163 secure_proxy_check_state()); |
158 } | 164 } |
159 | 165 |
| 166 TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheckFailed) { |
| 167 const struct { |
| 168 const char* test_case; |
| 169 int net_error; |
| 170 int http_response_code; |
| 171 bool secure_proxy_check_succeeded; |
| 172 bool expected_proxy_check_succeeded; |
| 173 } tests[] = { |
| 174 { |
| 175 "Succeeded", net::OK, net::HTTP_OK, true, true, |
| 176 }, |
| 177 { |
| 178 "Net failure", net::ERR_CONNECTION_RESET, -1, false, false, |
| 179 }, |
| 180 { |
| 181 "HTTP failure", net::OK, net::HTTP_NOT_FOUND, false, false, |
| 182 }, |
| 183 { |
| 184 "Bad content", net::OK, net::HTTP_OK, false, false, |
| 185 }, |
| 186 }; |
| 187 size_t expected_event_count = 0; |
| 188 EXPECT_EQ(expected_event_count, net_log()->GetSize()); |
| 189 EXPECT_EQ(expected_event_count++, event_count()); |
| 190 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_UNKNOWN, |
| 191 secure_proxy_check_state()); |
| 192 for (const auto& test : tests) { |
| 193 event_creator()->EndSecureProxyCheck(bound_net_log(), test.net_error, |
| 194 test.http_response_code, |
| 195 test.secure_proxy_check_succeeded); |
| 196 EXPECT_EQ(expected_event_count, net_log()->GetSize()) << test.test_case; |
| 197 EXPECT_EQ(expected_event_count++, event_count()) << test.test_case; |
| 198 net::TestNetLogEntry entry = GetLatestEntry(); |
| 199 EXPECT_EQ(net::NetLog::TYPE_DATA_REDUCTION_PROXY_CANARY_REQUEST, entry.type) |
| 200 << test.test_case; |
| 201 EXPECT_EQ(test.secure_proxy_check_succeeded |
| 202 ? DataReductionProxyEventStorageDelegate::CHECK_SUCCESS |
| 203 : DataReductionProxyEventStorageDelegate::CHECK_FAILED, |
| 204 secure_proxy_check_state()) |
| 205 << test.test_case; |
| 206 } |
| 207 } |
| 208 |
160 } // namespace data_reduction_proxy | 209 } // namespace data_reduction_proxy |
OLD | NEW |