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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc

Issue 1933653004: Reset the Lo-Fi main frame state when there is a new main frame request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: check data_reduction_proxy_io_data_ Created 4 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/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 15 matching lines...) Expand all
26 #include "net/base/load_flags.h" 26 #include "net/base/load_flags.h"
27 #include "net/proxy/proxy_server.h" 27 #include "net/proxy/proxy_server.h"
28 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
29 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
30 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "url/gurl.h" 32 #include "url/gurl.h"
33 33
34 namespace { 34 namespace {
35 const char kChromeProxyHeader[] = "chrome-proxy"; 35 const char kChromeProxyHeader[] = "chrome-proxy";
36 const char kOtherProxy[] = "testproxy:17";
37 36
38 const char kVersion[] = "0.1.2.3"; 37 const char kVersion[] = "0.1.2.3";
39 const char kExpectedBuild[] = "2"; 38 const char kExpectedBuild[] = "2";
40 const char kExpectedPatch[] = "3"; 39 const char kExpectedPatch[] = "3";
41 const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768"; 40 const char kExpectedCredentials[] = "96bd72ec4a050ba60981743d41787768";
42 const char kExpectedSession[] = "0-1633771873-1633771873-1633771873"; 41 const char kExpectedSession[] = "0-1633771873-1633771873-1633771873";
43 42
44 const char kTestKey2[] = "test-key2"; 43 const char kTestKey2[] = "test-key2";
45 const char kExpectedCredentials2[] = "c911fdb402f578787562cf7f00eda972"; 44 const char kExpectedCredentials2[] = "c911fdb402f578787562cf7f00eda972";
46 const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873"; 45 const char kExpectedSession2[] = "0-1633771873-1633771873-1633771873";
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 147 }
149 148
150 TestDataReductionProxyParams* params() { 149 TestDataReductionProxyParams* params() {
151 return test_context_->config()->test_params(); 150 return test_context_->config()->test_params();
152 } 151 }
153 152
154 TestDataReductionProxyRequestOptions* request_options() { 153 TestDataReductionProxyRequestOptions* request_options() {
155 return request_options_.get(); 154 return request_options_.get();
156 } 155 }
157 156
158 void VerifyExpectedHeader(const std::string& proxy_uri, 157 void VerifyExpectedHeader(const std::string& expected_header) {
159 const std::string& expected_header) {
160 test_context_->RunUntilIdle(); 158 test_context_->RunUntilIdle();
161 net::HttpRequestHeaders headers; 159 net::HttpRequestHeaders headers;
162 request_options_->MaybeAddRequestHeader( 160 request_options_->AddRequestHeader(&headers);
163 proxy_uri.empty() ? net::ProxyServer()
164 : net::ProxyServer::FromURI(
165 proxy_uri, net::ProxyServer::SCHEME_HTTP),
166 &headers);
167 if (expected_header.empty()) { 161 if (expected_header.empty()) {
168 EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader)); 162 EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader));
169 return; 163 return;
170 } 164 }
171 EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader)); 165 EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
172 std::string header_value; 166 std::string header_value;
173 headers.GetHeader(kChromeProxyHeader, &header_value); 167 headers.GetHeader(kChromeProxyHeader, &header_value);
174 EXPECT_EQ(expected_header, header_value); 168 EXPECT_EQ(expected_header, header_value);
175 } 169 }
176 170
(...skipping 22 matching lines...) Expand all
199 "d7c1c34ef6b90303b01c48a6c1db6419", std::string(), 193 "d7c1c34ef6b90303b01c48a6c1db6419", std::string(),
200 kClientStr, kExpectedBuild, kExpectedPatch, 194 kClientStr, kExpectedBuild, kExpectedPatch,
201 std::vector<std::string>(), &expected_header2); 195 std::vector<std::string>(), &expected_header2);
202 196
203 CreateRequestOptions(kVersion); 197 CreateRequestOptions(kVersion);
204 test_context_->RunUntilIdle(); 198 test_context_->RunUntilIdle();
205 199
206 // Now set a key. 200 // Now set a key.
207 request_options()->SetKeyOnIO(kTestKey2); 201 request_options()->SetKeyOnIO(kTestKey2);
208 202
209 // Don't write headers if the proxy is invalid. 203 // Write headers.
210 VerifyExpectedHeader(std::string(), std::string()); 204 VerifyExpectedHeader(expected_header);
211
212 // Don't write headers with a valid proxy, that's not a data reduction proxy.
213 VerifyExpectedHeader(kOtherProxy, std::string());
214
215 // Write headers with a valid data reduction proxy.
216 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header);
217 205
218 // Fast forward 24 hours. The header should be the same. 206 // Fast forward 24 hours. The header should be the same.
219 request_options()->set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60)); 207 request_options()->set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60));
220 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); 208 VerifyExpectedHeader(expected_header);
221 209
222 // Fast forward one more second. The header should be new. 210 // Fast forward one more second. The header should be new.
223 request_options()->set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60 + 1)); 211 request_options()->set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60 + 1));
224 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header2); 212 VerifyExpectedHeader(expected_header2);
225 } 213 }
226 214
227 TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationIgnoresEmptyKey) { 215 TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationIgnoresEmptyKey) {
228 std::string expected_header; 216 std::string expected_header;
229 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), 217 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(),
230 kClientStr, kExpectedBuild, kExpectedPatch, 218 kClientStr, kExpectedBuild, kExpectedPatch,
231 std::vector<std::string>(), &expected_header); 219 std::vector<std::string>(), &expected_header);
232 CreateRequestOptions(kVersion); 220 CreateRequestOptions(kVersion);
233 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); 221 VerifyExpectedHeader(expected_header);
234 222
235 // Now set an empty key. The auth handler should ignore that, and the key 223 // Now set an empty key. The auth handler should ignore that, and the key
236 // remains |kTestKey|. 224 // remains |kTestKey|.
237 request_options()->SetKeyOnIO(std::string()); 225 request_options()->SetKeyOnIO(std::string());
238 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); 226 VerifyExpectedHeader(expected_header);
239 } 227 }
240 228
241 TEST_F(DataReductionProxyRequestOptionsTest, SecureSession) { 229 TEST_F(DataReductionProxyRequestOptionsTest, SecureSession) {
242 std::string expected_header; 230 std::string expected_header;
243 SetHeaderExpectations(std::string(), std::string(), kSecureSession, 231 SetHeaderExpectations(std::string(), std::string(), kSecureSession,
244 kClientStr, kExpectedBuild, kExpectedPatch, 232 kClientStr, kExpectedBuild, kExpectedPatch,
245 std::vector<std::string>(), &expected_header); 233 std::vector<std::string>(), &expected_header);
246 234
247 CreateRequestOptions(kVersion); 235 CreateRequestOptions(kVersion);
248 request_options()->SetSecureSession(kSecureSession); 236 request_options()->SetSecureSession(kSecureSession);
249 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); 237 VerifyExpectedHeader(expected_header);
250 } 238 }
251 239
252 TEST_F(DataReductionProxyRequestOptionsTest, ParseExperiments) { 240 TEST_F(DataReductionProxyRequestOptionsTest, ParseExperiments) {
253 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 241 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
254 data_reduction_proxy::switches::kDataReductionProxyExperiment, 242 data_reduction_proxy::switches::kDataReductionProxyExperiment,
255 "staging,\"foo,bar\""); 243 "staging,\"foo,bar\"");
256 std::vector<std::string> expected_experiments; 244 std::vector<std::string> expected_experiments;
257 expected_experiments.push_back("staging"); 245 expected_experiments.push_back("staging");
258 expected_experiments.push_back("\"foo,bar\""); 246 expected_experiments.push_back("\"foo,bar\"");
259 std::string expected_header; 247 std::string expected_header;
260 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), 248 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(),
261 kClientStr, kExpectedBuild, kExpectedPatch, 249 kClientStr, kExpectedBuild, kExpectedPatch,
262 expected_experiments, &expected_header); 250 expected_experiments, &expected_header);
263 251
264 CreateRequestOptions(kVersion); 252 CreateRequestOptions(kVersion);
265 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); 253 VerifyExpectedHeader(expected_header);
266 } 254 }
267 255
268 TEST_F(DataReductionProxyRequestOptionsTest, ParseExperimentsFromFieldTrial) { 256 TEST_F(DataReductionProxyRequestOptionsTest, ParseExperimentsFromFieldTrial) {
269 const char kFieldTrialGroupFoo[] = "enabled_foo"; 257 const char kFieldTrialGroupFoo[] = "enabled_foo";
270 const char kFieldTrialGroupBar[] = "enabled_bar"; 258 const char kFieldTrialGroupBar[] = "enabled_bar";
271 const char kExperimentFoo[] = "foo"; 259 const char kExperimentFoo[] = "foo";
272 const char kExperimentBar[] = "bar"; 260 const char kExperimentBar[] = "bar";
273 const struct { 261 const struct {
274 std::string field_trial_group; 262 std::string field_trial_group;
275 std::string command_line_experiment; 263 std::string command_line_experiment;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 params::GetServerExperimentsFieldTrialName(), test.field_trial_group); 299 params::GetServerExperimentsFieldTrialName(), test.field_trial_group);
312 300
313 if (!test.expected_experiment.empty()) 301 if (!test.expected_experiment.empty())
314 expected_experiments.push_back(test.expected_experiment); 302 expected_experiments.push_back(test.expected_experiment);
315 303
316 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), 304 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(),
317 kClientStr, kExpectedBuild, kExpectedPatch, 305 kClientStr, kExpectedBuild, kExpectedPatch,
318 expected_experiments, &expected_header); 306 expected_experiments, &expected_header);
319 307
320 CreateRequestOptions(kVersion); 308 CreateRequestOptions(kVersion);
321 VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); 309 VerifyExpectedHeader(expected_header);
322 } 310 }
323 } 311 }
324 312
325 TEST_F(DataReductionProxyRequestOptionsTest, GetSessionKeyFromRequestHeaders) { 313 TEST_F(DataReductionProxyRequestOptionsTest, GetSessionKeyFromRequestHeaders) {
326 const struct { 314 const struct {
327 std::string chrome_proxy_header_key; 315 std::string chrome_proxy_header_key;
328 std::string chrome_proxy_header_value; 316 std::string chrome_proxy_header_value;
329 std::string expected_session_key; 317 std::string expected_session_key;
330 } tests[] = { 318 } tests[] = {
331 {"chrome-proxy", "something=something_else, s=123, key=value", "123"}, 319 {"chrome-proxy", "something=something_else, s=123, key=value", "123"},
(...skipping 20 matching lines...) Expand all
352 340
353 std::string session_key = 341 std::string session_key =
354 request_options()->GetSessionKeyFromRequestHeaders(request_headers); 342 request_options()->GetSessionKeyFromRequestHeaders(request_headers);
355 EXPECT_EQ(test.expected_session_key, session_key) 343 EXPECT_EQ(test.expected_session_key, session_key)
356 << test.chrome_proxy_header_key << ":" 344 << test.chrome_proxy_header_key << ":"
357 << test.chrome_proxy_header_value; 345 << test.chrome_proxy_header_value;
358 } 346 }
359 } 347 }
360 348
361 } // namespace data_reduction_proxy 349 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698