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/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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), | 325 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
326 kClientStr, kExpectedBuild, kExpectedPatch, kPageId, | 326 kClientStr, kExpectedBuild, kExpectedPatch, kPageId, |
327 expected_experiments, &expected_header); | 327 expected_experiments, &expected_header); |
328 | 328 |
329 CreateRequestOptions(kVersion); | 329 CreateRequestOptions(kVersion); |
330 VerifyExpectedHeader(expected_header, kPageIdValue); | 330 VerifyExpectedHeader(expected_header, kPageIdValue); |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
| 334 TEST_F(DataReductionProxyRequestOptionsTest, TestExperimentPrecedence) { |
| 335 // Tests that combinations of configurations that trigger "exp=" directive in |
| 336 // the Chrome-Proxy header have the right precendence, and only append a value |
| 337 // for the highest priority value. |
| 338 |
| 339 // Field trial has the lowest priority. |
| 340 std::map<std::string, std::string> server_experiment; |
| 341 server_experiment["exp"] = "foo"; |
| 342 ASSERT_TRUE(variations::AssociateVariationParams( |
| 343 params::GetServerExperimentsFieldTrialName(), "enabled", |
| 344 server_experiment)); |
| 345 |
| 346 base::FieldTrialList field_trial_list(nullptr); |
| 347 base::FieldTrialList::CreateFieldTrial( |
| 348 params::GetServerExperimentsFieldTrialName(), "enabled"); |
| 349 std::vector<std::string> expected_experiments; |
| 350 expected_experiments.push_back("foo"); |
| 351 std::string expected_header; |
| 352 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
| 353 kClientStr, kExpectedBuild, kExpectedPatch, kPageId, |
| 354 expected_experiments, &expected_header); |
| 355 CreateRequestOptions(kVersion); |
| 356 VerifyExpectedHeader(expected_header, kPageIdValue); |
| 357 |
| 358 // "ignore_preview_blacklist" has the next lowest priority. |
| 359 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 360 switches::kDataReductionProxyLoFi, |
| 361 switches::kDataReductionProxyLoFiValueAlwaysOn); |
| 362 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 363 switches::kEnableDataReductionProxyLitePage); |
| 364 expected_experiments.clear(); |
| 365 expected_experiments.push_back(chrome_proxy_lite_page_ignore_blacklist()); |
| 366 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
| 367 kClientStr, kExpectedBuild, kExpectedPatch, kPageId, |
| 368 expected_experiments, &expected_header); |
| 369 CreateRequestOptions(kVersion); |
| 370 VerifyExpectedHeader(expected_header, kPageIdValue); |
| 371 |
| 372 // Setting the experiment explicitly has the highest priority. |
| 373 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 374 data_reduction_proxy::switches::kDataReductionProxyExperiment, "bar"); |
| 375 expected_experiments.clear(); |
| 376 expected_experiments.push_back("bar"); |
| 377 SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
| 378 kClientStr, kExpectedBuild, kExpectedPatch, kPageId, |
| 379 expected_experiments, &expected_header); |
| 380 CreateRequestOptions(kVersion); |
| 381 VerifyExpectedHeader(expected_header, kPageIdValue); |
| 382 } |
| 383 |
334 TEST_F(DataReductionProxyRequestOptionsTest, GetSessionKeyFromRequestHeaders) { | 384 TEST_F(DataReductionProxyRequestOptionsTest, GetSessionKeyFromRequestHeaders) { |
335 const struct { | 385 const struct { |
336 std::string chrome_proxy_header_key; | 386 std::string chrome_proxy_header_key; |
337 std::string chrome_proxy_header_value; | 387 std::string chrome_proxy_header_value; |
338 std::string expected_session_key; | 388 std::string expected_session_key; |
339 } tests[] = { | 389 } tests[] = { |
340 {"chrome-proxy", "something=something_else, s=123, key=value", "123"}, | 390 {"chrome-proxy", "something=something_else, s=123, key=value", "123"}, |
341 {"chrome-proxy", "something=something_else, s= 123 456 , key=value", | 391 {"chrome-proxy", "something=something_else, s= 123 456 , key=value", |
342 "123 456"}, | 392 "123 456"}, |
343 {"chrome-proxy", "something=something_else, s=123456, key=value", | 393 {"chrome-proxy", "something=something_else, s=123456, key=value", |
(...skipping 30 matching lines...) Expand all Loading... |
374 DCHECK_EQ(3u, request_options()->GeneratePageId()); | 424 DCHECK_EQ(3u, request_options()->GeneratePageId()); |
375 | 425 |
376 request_options()->SetSecureSession("blah"); | 426 request_options()->SetSecureSession("blah"); |
377 | 427 |
378 DCHECK_EQ(1u, request_options()->GeneratePageId()); | 428 DCHECK_EQ(1u, request_options()->GeneratePageId()); |
379 DCHECK_EQ(2u, request_options()->GeneratePageId()); | 429 DCHECK_EQ(2u, request_options()->GeneratePageId()); |
380 DCHECK_EQ(3u, request_options()->GeneratePageId()); | 430 DCHECK_EQ(3u, request_options()->GeneratePageId()); |
381 } | 431 } |
382 | 432 |
383 } // namespace data_reduction_proxy | 433 } // namespace data_reduction_proxy |
OLD | NEW |