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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "net/log/test_net_log.h" | 28 #include "net/log/test_net_log.h" |
29 #include "net/log/test_net_log_entry.h" | 29 #include "net/log/test_net_log_entry.h" |
30 #include "net/proxy/proxy_server.h" | 30 #include "net/proxy/proxy_server.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 namespace data_reduction_proxy { | 33 namespace data_reduction_proxy { |
34 | 34 |
35 class DataReductionProxyEventStoreTest : public testing::Test { | 35 class DataReductionProxyEventStoreTest : public testing::Test { |
36 public: | 36 public: |
37 DataReductionProxyEventStoreTest() : net_log_(new net::TestNetLog()) { | 37 DataReductionProxyEventStoreTest() : net_log_(new net::TestNetLog()) { |
38 bound_net_log_ = net::BoundNetLog::Make( | 38 net_log_with_source_ = net::NetLogWithSource::Make( |
39 net_log_.get(), net::NetLogSourceType::DATA_REDUCTION_PROXY); | 39 net_log_.get(), net::NetLogSourceType::DATA_REDUCTION_PROXY); |
40 } | 40 } |
41 | 41 |
42 void SetUp() override { | 42 void SetUp() override { |
43 event_store_.reset(new DataReductionProxyEventStore()); | 43 event_store_.reset(new DataReductionProxyEventStore()); |
44 event_creator_.reset( | 44 event_creator_.reset( |
45 new DataReductionProxyEventCreator(event_store_.get())); | 45 new DataReductionProxyEventCreator(event_store_.get())); |
46 } | 46 } |
47 | 47 |
48 net::TestNetLogEntry GetSingleEntry() const { | 48 net::TestNetLogEntry GetSingleEntry() const { |
(...skipping 10 matching lines...) Expand all Loading... |
59 } | 59 } |
60 | 60 |
61 DataReductionProxyEventStore* event_store() { return event_store_.get(); } | 61 DataReductionProxyEventStore* event_store() { return event_store_.get(); } |
62 | 62 |
63 DataReductionProxyEventCreator* event_creator() { | 63 DataReductionProxyEventCreator* event_creator() { |
64 return event_creator_.get(); | 64 return event_creator_.get(); |
65 } | 65 } |
66 | 66 |
67 net::TestNetLog* net_log() { return net_log_.get(); } | 67 net::TestNetLog* net_log() { return net_log_.get(); } |
68 | 68 |
69 const net::BoundNetLog& bound_net_log() { | 69 const net::NetLogWithSource& net_log_with_source() { |
70 return bound_net_log_; | 70 return net_log_with_source_; |
71 } | 71 } |
72 | 72 |
73 size_t event_count() const { return event_store_->stored_events_.size(); } | 73 size_t event_count() const { return event_store_->stored_events_.size(); } |
74 | 74 |
75 DataReductionProxyEventStorageDelegate::SecureProxyCheckState | 75 DataReductionProxyEventStorageDelegate::SecureProxyCheckState |
76 secure_proxy_check_state() const { | 76 secure_proxy_check_state() const { |
77 return event_store_->secure_proxy_check_state_; | 77 return event_store_->secure_proxy_check_state_; |
78 } | 78 } |
79 | 79 |
80 base::Value* last_bypass_event() const { | 80 base::Value* last_bypass_event() const { |
81 return event_store_->last_bypass_event_.get(); | 81 return event_store_->last_bypass_event_.get(); |
82 } | 82 } |
83 | 83 |
84 private: | 84 private: |
85 std::unique_ptr<net::TestNetLog> net_log_; | 85 std::unique_ptr<net::TestNetLog> net_log_; |
86 std::unique_ptr<DataReductionProxyEventStore> event_store_; | 86 std::unique_ptr<DataReductionProxyEventStore> event_store_; |
87 std::unique_ptr<DataReductionProxyEventCreator> event_creator_; | 87 std::unique_ptr<DataReductionProxyEventCreator> event_creator_; |
88 net::BoundNetLog bound_net_log_; | 88 net::NetLogWithSource net_log_with_source_; |
89 }; | 89 }; |
90 | 90 |
91 TEST_F(DataReductionProxyEventStoreTest, TestAddProxyEnabledEvent) { | 91 TEST_F(DataReductionProxyEventStoreTest, TestAddProxyEnabledEvent) { |
92 EXPECT_EQ(0u, event_count()); | 92 EXPECT_EQ(0u, event_count()); |
93 std::vector<net::ProxyServer> proxies_for_http; | 93 std::vector<net::ProxyServer> proxies_for_http; |
94 event_creator()->AddProxyEnabledEvent(net_log(), false, proxies_for_http); | 94 event_creator()->AddProxyEnabledEvent(net_log(), false, proxies_for_http); |
95 EXPECT_EQ(1u, event_count()); | 95 EXPECT_EQ(1u, event_count()); |
96 net::TestNetLogEntry entry = GetSingleEntry(); | 96 net::TestNetLogEntry entry = GetSingleEntry(); |
97 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_ENABLED, entry.type); | 97 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_ENABLED, entry.type); |
98 } | 98 } |
99 | 99 |
100 TEST_F(DataReductionProxyEventStoreTest, TestAddProxyDisabledEvent) { | 100 TEST_F(DataReductionProxyEventStoreTest, TestAddProxyDisabledEvent) { |
101 EXPECT_EQ(0u, event_count()); | 101 EXPECT_EQ(0u, event_count()); |
102 event_creator()->AddProxyDisabledEvent(net_log()); | 102 event_creator()->AddProxyDisabledEvent(net_log()); |
103 EXPECT_EQ(1u, event_count()); | 103 EXPECT_EQ(1u, event_count()); |
104 net::TestNetLogEntry entry = GetSingleEntry(); | 104 net::TestNetLogEntry entry = GetSingleEntry(); |
105 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_ENABLED, entry.type); | 105 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_ENABLED, entry.type); |
106 } | 106 } |
107 | 107 |
108 TEST_F(DataReductionProxyEventStoreTest, TestAddBypassActionEvent) { | 108 TEST_F(DataReductionProxyEventStoreTest, TestAddBypassActionEvent) { |
109 EXPECT_EQ(0u, event_count()); | 109 EXPECT_EQ(0u, event_count()); |
110 EXPECT_EQ(nullptr, last_bypass_event()); | 110 EXPECT_EQ(nullptr, last_bypass_event()); |
111 event_creator()->AddBypassActionEvent( | 111 event_creator()->AddBypassActionEvent( |
112 bound_net_log(), BYPASS_ACTION_TYPE_BYPASS, "GET", GURL(), false, | 112 net_log_with_source(), BYPASS_ACTION_TYPE_BYPASS, "GET", GURL(), false, |
113 base::TimeDelta::FromMinutes(1)); | 113 base::TimeDelta::FromMinutes(1)); |
114 EXPECT_EQ(1u, event_count()); | 114 EXPECT_EQ(1u, event_count()); |
115 net::TestNetLogEntry entry = GetSingleEntry(); | 115 net::TestNetLogEntry entry = GetSingleEntry(); |
116 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_BYPASS_REQUESTED, | 116 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_BYPASS_REQUESTED, |
117 entry.type); | 117 entry.type); |
118 EXPECT_NE(nullptr, last_bypass_event()); | 118 EXPECT_NE(nullptr, last_bypass_event()); |
119 } | 119 } |
120 | 120 |
121 TEST_F(DataReductionProxyEventStoreTest, TestAddBypassTypeEvent) { | 121 TEST_F(DataReductionProxyEventStoreTest, TestAddBypassTypeEvent) { |
122 EXPECT_EQ(0u, event_count()); | 122 EXPECT_EQ(0u, event_count()); |
123 EXPECT_EQ(nullptr, last_bypass_event()); | 123 EXPECT_EQ(nullptr, last_bypass_event()); |
124 event_creator()->AddBypassTypeEvent(bound_net_log(), BYPASS_EVENT_TYPE_LONG, | 124 event_creator()->AddBypassTypeEvent(net_log_with_source(), |
125 "GET", GURL(), false, | 125 BYPASS_EVENT_TYPE_LONG, "GET", GURL(), |
126 base::TimeDelta::FromMinutes(1)); | 126 false, base::TimeDelta::FromMinutes(1)); |
127 EXPECT_EQ(1u, event_count()); | 127 EXPECT_EQ(1u, event_count()); |
128 EXPECT_EQ(1u, net_log()->GetSize()); | 128 EXPECT_EQ(1u, net_log()->GetSize()); |
129 net::TestNetLogEntry entry = GetSingleEntry(); | 129 net::TestNetLogEntry entry = GetSingleEntry(); |
130 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_BYPASS_REQUESTED, | 130 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_BYPASS_REQUESTED, |
131 entry.type); | 131 entry.type); |
132 EXPECT_NE(nullptr, last_bypass_event()); | 132 EXPECT_NE(nullptr, last_bypass_event()); |
133 } | 133 } |
134 | 134 |
135 TEST_F(DataReductionProxyEventStoreTest, TestAddProxyFallbackEvent) { | 135 TEST_F(DataReductionProxyEventStoreTest, TestAddProxyFallbackEvent) { |
136 EXPECT_EQ(0u, event_count()); | 136 EXPECT_EQ(0u, event_count()); |
137 event_creator()->AddProxyFallbackEvent(net_log(), "bad_proxy", | 137 event_creator()->AddProxyFallbackEvent(net_log(), "bad_proxy", |
138 net::ERR_PROXY_CONNECTION_FAILED); | 138 net::ERR_PROXY_CONNECTION_FAILED); |
139 EXPECT_EQ(1u, event_count()); | 139 EXPECT_EQ(1u, event_count()); |
140 net::TestNetLogEntry entry = GetSingleEntry(); | 140 net::TestNetLogEntry entry = GetSingleEntry(); |
141 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_FALLBACK, entry.type); | 141 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_FALLBACK, entry.type); |
142 } | 142 } |
143 | 143 |
144 TEST_F(DataReductionProxyEventStoreTest, TestBeginSecureProxyCheck) { | 144 TEST_F(DataReductionProxyEventStoreTest, TestBeginSecureProxyCheck) { |
145 EXPECT_EQ(0u, event_count()); | 145 EXPECT_EQ(0u, event_count()); |
146 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_UNKNOWN, | 146 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_UNKNOWN, |
147 secure_proxy_check_state()); | 147 secure_proxy_check_state()); |
148 event_creator()->BeginSecureProxyCheck(bound_net_log(), GURL()); | 148 event_creator()->BeginSecureProxyCheck(net_log_with_source(), GURL()); |
149 EXPECT_EQ(1u, event_count()); | 149 EXPECT_EQ(1u, event_count()); |
150 EXPECT_EQ(1u, net_log()->GetSize()); | 150 EXPECT_EQ(1u, net_log()->GetSize()); |
151 net::TestNetLogEntry entry = GetSingleEntry(); | 151 net::TestNetLogEntry entry = GetSingleEntry(); |
152 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_CANARY_REQUEST, | 152 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_CANARY_REQUEST, |
153 entry.type); | 153 entry.type); |
154 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_PENDING, | 154 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_PENDING, |
155 secure_proxy_check_state()); | 155 secure_proxy_check_state()); |
156 } | 156 } |
157 | 157 |
158 TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheck) { | 158 TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheck) { |
159 EXPECT_EQ(0u, event_count()); | 159 EXPECT_EQ(0u, event_count()); |
160 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_UNKNOWN, | 160 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_UNKNOWN, |
161 secure_proxy_check_state()); | 161 secure_proxy_check_state()); |
162 event_creator()->EndSecureProxyCheck(bound_net_log(), 0, net::HTTP_OK, true); | 162 event_creator()->EndSecureProxyCheck(net_log_with_source(), 0, net::HTTP_OK, |
| 163 true); |
163 EXPECT_EQ(1u, event_count()); | 164 EXPECT_EQ(1u, event_count()); |
164 EXPECT_EQ(1u, net_log()->GetSize()); | 165 EXPECT_EQ(1u, net_log()->GetSize()); |
165 net::TestNetLogEntry entry = GetSingleEntry(); | 166 net::TestNetLogEntry entry = GetSingleEntry(); |
166 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_CANARY_REQUEST, | 167 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_CANARY_REQUEST, |
167 entry.type); | 168 entry.type); |
168 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_SUCCESS, | 169 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_SUCCESS, |
169 secure_proxy_check_state()); | 170 secure_proxy_check_state()); |
170 } | 171 } |
171 | 172 |
172 TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheckFailed) { | 173 TEST_F(DataReductionProxyEventStoreTest, TestEndSecureProxyCheckFailed) { |
(...skipping 16 matching lines...) Expand all Loading... |
189 { | 190 { |
190 "Bad content", net::OK, net::HTTP_OK, false, false, | 191 "Bad content", net::OK, net::HTTP_OK, false, false, |
191 }, | 192 }, |
192 }; | 193 }; |
193 size_t expected_event_count = 0; | 194 size_t expected_event_count = 0; |
194 EXPECT_EQ(expected_event_count, net_log()->GetSize()); | 195 EXPECT_EQ(expected_event_count, net_log()->GetSize()); |
195 EXPECT_EQ(expected_event_count++, event_count()); | 196 EXPECT_EQ(expected_event_count++, event_count()); |
196 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_UNKNOWN, | 197 EXPECT_EQ(DataReductionProxyEventStorageDelegate::CHECK_UNKNOWN, |
197 secure_proxy_check_state()); | 198 secure_proxy_check_state()); |
198 for (const auto& test : tests) { | 199 for (const auto& test : tests) { |
199 event_creator()->EndSecureProxyCheck(bound_net_log(), test.net_error, | 200 event_creator()->EndSecureProxyCheck(net_log_with_source(), test.net_error, |
200 test.http_response_code, | 201 test.http_response_code, |
201 test.secure_proxy_check_succeeded); | 202 test.secure_proxy_check_succeeded); |
202 EXPECT_EQ(expected_event_count, net_log()->GetSize()) << test.test_case; | 203 EXPECT_EQ(expected_event_count, net_log()->GetSize()) << test.test_case; |
203 EXPECT_EQ(expected_event_count++, event_count()) << test.test_case; | 204 EXPECT_EQ(expected_event_count++, event_count()) << test.test_case; |
204 net::TestNetLogEntry entry = GetLatestEntry(); | 205 net::TestNetLogEntry entry = GetLatestEntry(); |
205 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_CANARY_REQUEST, | 206 EXPECT_EQ(net::NetLogEventType::DATA_REDUCTION_PROXY_CANARY_REQUEST, |
206 entry.type) | 207 entry.type) |
207 << test.test_case; | 208 << test.test_case; |
208 EXPECT_EQ(test.secure_proxy_check_succeeded | 209 EXPECT_EQ(test.secure_proxy_check_succeeded |
209 ? DataReductionProxyEventStorageDelegate::CHECK_SUCCESS | 210 ? DataReductionProxyEventStorageDelegate::CHECK_SUCCESS |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 sanitized_event->SetString("method", "GET"); | 292 sanitized_event->SetString("method", "GET"); |
292 | 293 |
293 bypass_event->Set("params", std::move(bypass_params)); | 294 bypass_event->Set("params", std::move(bypass_params)); |
294 std::string sanitized_output; | 295 std::string sanitized_output; |
295 base::JSONWriter::Write(*sanitized_event.get(), &sanitized_output); | 296 base::JSONWriter::Write(*sanitized_event.get(), &sanitized_output); |
296 event_store()->AddAndSetLastBypassEvent(std::move(bypass_event), 0); | 297 event_store()->AddAndSetLastBypassEvent(std::move(bypass_event), 0); |
297 EXPECT_EQ(sanitized_output, event_store()->SanitizedLastBypassEvent()); | 298 EXPECT_EQ(sanitized_output, event_store()->SanitizedLastBypassEvent()); |
298 } | 299 } |
299 | 300 |
300 } // namespace data_reduction_proxy | 301 } // namespace data_reduction_proxy |
OLD | NEW |