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

Side by Side Diff: components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc

Issue 1873263002: Convert //components/data_reduction_proxy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/content/browser/content_lofi_decider.h " 5 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h "
6 6
megjablon 2016/04/12 21:55:35 #include <memory>
dcheng 2016/04/12 22:38:34 Done.
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 context_.Init(); 68 context_.Init();
69 69
70 test_context_ = DataReductionProxyTestContext::Builder() 70 test_context_ = DataReductionProxyTestContext::Builder()
71 .WithClient(kClient) 71 .WithClient(kClient)
72 .WithMockClientSocketFactory(&mock_socket_factory_) 72 .WithMockClientSocketFactory(&mock_socket_factory_)
73 .WithURLRequestContext(&context_) 73 .WithURLRequestContext(&context_)
74 .Build(); 74 .Build();
75 75
76 data_reduction_proxy_network_delegate_.reset( 76 data_reduction_proxy_network_delegate_.reset(
77 new DataReductionProxyNetworkDelegate( 77 new DataReductionProxyNetworkDelegate(
78 scoped_ptr<net::NetworkDelegate>(new net::NetworkDelegateImpl()), 78 std::unique_ptr<net::NetworkDelegate>(
79 new net::NetworkDelegateImpl()),
79 test_context_->config(), 80 test_context_->config(),
80 test_context_->io_data()->request_options(), 81 test_context_->io_data()->request_options(),
81 test_context_->configurator())); 82 test_context_->configurator()));
82 83
83 data_reduction_proxy_network_delegate_->InitIODataAndUMA( 84 data_reduction_proxy_network_delegate_->InitIODataAndUMA(
84 test_context_->io_data(), test_context_->io_data()->bypass_stats()); 85 test_context_->io_data(), test_context_->io_data()->bypass_stats());
85 86
86 context_.set_network_delegate(data_reduction_proxy_network_delegate_.get()); 87 context_.set_network_delegate(data_reduction_proxy_network_delegate_.get());
87 88
88 scoped_ptr<data_reduction_proxy::ContentLoFiDecider> 89 std::unique_ptr<data_reduction_proxy::ContentLoFiDecider>
89 data_reduction_proxy_lofi_decider( 90 data_reduction_proxy_lofi_decider(
90 new data_reduction_proxy::ContentLoFiDecider()); 91 new data_reduction_proxy::ContentLoFiDecider());
91 test_context_->io_data()->set_lofi_decider( 92 test_context_->io_data()->set_lofi_decider(
92 std::move(data_reduction_proxy_lofi_decider)); 93 std::move(data_reduction_proxy_lofi_decider));
93 } 94 }
94 95
95 scoped_ptr<net::URLRequest> CreateRequest(bool is_using_lofi) { 96 std::unique_ptr<net::URLRequest> CreateRequest(bool is_using_lofi) {
96 scoped_ptr<net::URLRequest> request = context_.CreateRequest( 97 std::unique_ptr<net::URLRequest> request = context_.CreateRequest(
97 GURL("http://www.google.com/"), net::IDLE, &delegate_); 98 GURL("http://www.google.com/"), net::IDLE, &delegate_);
98 99
99 content::ResourceRequestInfo::AllocateForTesting( 100 content::ResourceRequestInfo::AllocateForTesting(
100 request.get(), content::RESOURCE_TYPE_SUB_FRAME, NULL, -1, -1, -1, 101 request.get(), content::RESOURCE_TYPE_SUB_FRAME, NULL, -1, -1, -1,
101 false, // is_main_frame 102 false, // is_main_frame
102 false, // parent_is_main_frame 103 false, // parent_is_main_frame
103 false, // allow_download 104 false, // allow_download
104 false, // is_async 105 false, // is_async
105 is_using_lofi); 106 is_using_lofi);
106 107
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 header_value.find( 156 header_value.find(
156 chrome_proxy_lo_fi_ignore_preview_blacklist_directive()) != 157 chrome_proxy_lo_fi_ignore_preview_blacklist_directive()) !=
157 std::string::npos); 158 std::string::npos);
158 } 159 }
159 160
160 protected: 161 protected:
161 base::MessageLoopForIO message_loop_; 162 base::MessageLoopForIO message_loop_;
162 net::MockClientSocketFactory mock_socket_factory_; 163 net::MockClientSocketFactory mock_socket_factory_;
163 net::TestURLRequestContext context_; 164 net::TestURLRequestContext context_;
164 net::TestDelegate delegate_; 165 net::TestDelegate delegate_;
165 scoped_ptr<DataReductionProxyTestContext> test_context_; 166 std::unique_ptr<DataReductionProxyTestContext> test_context_;
166 scoped_ptr<DataReductionProxyNetworkDelegate> 167 std::unique_ptr<DataReductionProxyNetworkDelegate>
167 data_reduction_proxy_network_delegate_; 168 data_reduction_proxy_network_delegate_;
168 }; 169 };
169 170
170 TEST_F(ContentLoFiDeciderTest, LoFiFlags) { 171 TEST_F(ContentLoFiDeciderTest, LoFiFlags) {
171 // Enable Lo-Fi. 172 // Enable Lo-Fi.
172 const struct { 173 const struct {
173 bool is_using_lofi; 174 bool is_using_lofi;
174 bool is_using_previews; 175 bool is_using_previews;
175 } tests[] = { 176 } tests[] = {
176 {false, false}, {true, false}, {false, true}, {true, true}, 177 {false, false}, {true, false}, {false, true}, {true, true},
177 }; 178 };
178 179
179 for (size_t i = 0; i < arraysize(tests); ++i) { 180 for (size_t i = 0; i < arraysize(tests); ++i) {
180 scoped_ptr<net::URLRequest> request = CreateRequest(tests[i].is_using_lofi); 181 std::unique_ptr<net::URLRequest> request =
182 CreateRequest(tests[i].is_using_lofi);
181 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 183 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
182 command_line->InitFromArgv(command_line->argv()); 184 command_line->InitFromArgv(command_line->argv());
183 if (tests[i].is_using_previews) { 185 if (tests[i].is_using_previews) {
184 command_line->AppendSwitch( 186 command_line->AppendSwitch(
185 switches::kEnableDataReductionProxyLoFiPreview); 187 switches::kEnableDataReductionProxyLoFiPreview);
186 } 188 }
187 189
188 // No flags or field trials. The Lo-Fi header should not be added. 190 // No flags or field trials. The Lo-Fi header should not be added.
189 net::HttpRequestHeaders headers; 191 net::HttpRequestHeaders headers;
190 NotifyBeforeSendProxyHeaders(&headers, request.get(), true); 192 NotifyBeforeSendProxyHeaders(&headers, request.get(), true);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 250 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
249 "Enabled"); 251 "Enabled");
250 // Enable Lo-Fi. 252 // Enable Lo-Fi.
251 const struct { 253 const struct {
252 bool is_using_lofi; 254 bool is_using_lofi;
253 } tests[] = { 255 } tests[] = {
254 {false}, {true}, 256 {false}, {true},
255 }; 257 };
256 258
257 for (size_t i = 0; i < arraysize(tests); ++i) { 259 for (size_t i = 0; i < arraysize(tests); ++i) {
258 scoped_ptr<net::URLRequest> request = CreateRequest(tests[i].is_using_lofi); 260 std::unique_ptr<net::URLRequest> request =
261 CreateRequest(tests[i].is_using_lofi);
259 net::HttpRequestHeaders headers; 262 net::HttpRequestHeaders headers;
260 NotifyBeforeSendProxyHeaders(&headers, request.get(), true); 263 NotifyBeforeSendProxyHeaders(&headers, request.get(), true);
261 VerifyLoFiHeader(tests[i].is_using_lofi, headers); 264 VerifyLoFiHeader(tests[i].is_using_lofi, headers);
262 VerifyLoFiPreviewHeader(false, headers); 265 VerifyLoFiPreviewHeader(false, headers);
263 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 266 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
264 } 267 }
265 } 268 }
266 269
267 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) { 270 TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) {
268 base::FieldTrialList field_trial_list(nullptr); 271 base::FieldTrialList field_trial_list(nullptr);
269 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 272 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
270 "Control"); 273 "Control");
271 // Enable Lo-Fi. 274 // Enable Lo-Fi.
272 const struct { 275 const struct {
273 bool is_using_lofi; 276 bool is_using_lofi;
274 } tests[] = { 277 } tests[] = {
275 {false}, {true}, 278 {false}, {true},
276 }; 279 };
277 280
278 for (size_t i = 0; i < arraysize(tests); ++i) { 281 for (size_t i = 0; i < arraysize(tests); ++i) {
279 scoped_ptr<net::URLRequest> request = CreateRequest(tests[i].is_using_lofi); 282 std::unique_ptr<net::URLRequest> request =
283 CreateRequest(tests[i].is_using_lofi);
280 net::HttpRequestHeaders headers; 284 net::HttpRequestHeaders headers;
281 NotifyBeforeSendProxyHeaders(&headers, request.get(), true); 285 NotifyBeforeSendProxyHeaders(&headers, request.get(), true);
282 VerifyLoFiHeader(false, headers); 286 VerifyLoFiHeader(false, headers);
283 VerifyLoFiPreviewHeader(false, headers); 287 VerifyLoFiPreviewHeader(false, headers);
284 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 288 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
285 } 289 }
286 } 290 }
287 291
288 TEST_F(ContentLoFiDeciderTest, LoFiPreviewFieldTrial) { 292 TEST_F(ContentLoFiDeciderTest, LoFiPreviewFieldTrial) {
289 base::FieldTrialList field_trial_list(nullptr); 293 base::FieldTrialList field_trial_list(nullptr);
290 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 294 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
291 "Enabled_Preview"); 295 "Enabled_Preview");
292 // Enable Lo-Fi. 296 // Enable Lo-Fi.
293 const struct { 297 const struct {
294 bool is_using_lofi; 298 bool is_using_lofi;
295 bool is_main_frame; 299 bool is_main_frame;
296 } tests[] = { 300 } tests[] = {
297 {false, false}, {true, false}, {false, true}, {true, true}, 301 {false, false}, {true, false}, {false, true}, {true, true},
298 }; 302 };
299 303
300 for (size_t i = 0; i < arraysize(tests); ++i) { 304 for (size_t i = 0; i < arraysize(tests); ++i) {
301 scoped_ptr<net::URLRequest> request = CreateRequest(tests[i].is_using_lofi); 305 std::unique_ptr<net::URLRequest> request =
306 CreateRequest(tests[i].is_using_lofi);
302 if (tests[i].is_main_frame) 307 if (tests[i].is_main_frame)
303 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME); 308 request->SetLoadFlags(request->load_flags() | net::LOAD_MAIN_FRAME);
304 net::HttpRequestHeaders headers; 309 net::HttpRequestHeaders headers;
305 NotifyBeforeSendProxyHeaders(&headers, request.get(), true); 310 NotifyBeforeSendProxyHeaders(&headers, request.get(), true);
306 VerifyLoFiHeader(false, headers); 311 VerifyLoFiHeader(false, headers);
307 VerifyLoFiPreviewHeader(tests[i].is_using_lofi && tests[i].is_main_frame, 312 VerifyLoFiPreviewHeader(tests[i].is_using_lofi && tests[i].is_main_frame,
308 headers); 313 headers);
309 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers); 314 VerifyLoFiIgnorePreviewBlacklistHeader(false, headers);
310 } 315 }
311 } 316 }
(...skipping 29 matching lines...) Expand all
341 } 346 }
342 347
343 if (tests[i].auto_lofi_control_group) { 348 if (tests[i].auto_lofi_control_group) {
344 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 349 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
345 "Control"); 350 "Control");
346 } 351 }
347 352
348 test_context_->config()->SetNetworkProhibitivelySlow( 353 test_context_->config()->SetNetworkProhibitivelySlow(
349 tests[i].network_prohibitively_slow); 354 tests[i].network_prohibitively_slow);
350 355
351 scoped_ptr<net::URLRequest> request = 356 std::unique_ptr<net::URLRequest> request =
352 CreateRequest(tests[i].network_prohibitively_slow); 357 CreateRequest(tests[i].network_prohibitively_slow);
353 net::HttpRequestHeaders headers; 358 net::HttpRequestHeaders headers;
354 NotifyBeforeSendProxyHeaders(&headers, request.get(), true); 359 NotifyBeforeSendProxyHeaders(&headers, request.get(), true);
355 360
356 VerifyLoFiHeader(expect_lofi_header, headers); 361 VerifyLoFiHeader(expect_lofi_header, headers);
357 } 362 }
358 } 363 }
359 364
360 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) { 365 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) {
361 const struct { 366 const struct {
(...skipping 29 matching lines...) Expand all
391 396
392 base::FieldTrialList field_trial_list(nullptr); 397 base::FieldTrialList field_trial_list(nullptr);
393 if (tests[i].auto_lofi_enabled_group) { 398 if (tests[i].auto_lofi_enabled_group) {
394 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 399 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
395 "Enabled"); 400 "Enabled");
396 } 401 }
397 402
398 test_context_->config()->SetNetworkProhibitivelySlow( 403 test_context_->config()->SetNetworkProhibitivelySlow(
399 tests[i].network_prohibitively_slow); 404 tests[i].network_prohibitively_slow);
400 405
401 scoped_ptr<net::URLRequest> request = 406 std::unique_ptr<net::URLRequest> request =
402 CreateRequest(tests[i].network_prohibitively_slow); 407 CreateRequest(tests[i].network_prohibitively_slow);
403 net::HttpRequestHeaders headers; 408 net::HttpRequestHeaders headers;
404 NotifyBeforeSendProxyHeaders(&headers, request.get(), true); 409 NotifyBeforeSendProxyHeaders(&headers, request.get(), true);
405 410
406 VerifyLoFiHeader(expect_lofi_header, headers); 411 VerifyLoFiHeader(expect_lofi_header, headers);
407 } 412 }
408 } 413 }
409 414
410 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) { 415 TEST_F(ContentLoFiDeciderTest, ProxyIsNotDataReductionProxy) {
411 base::FieldTrialList field_trial_list(nullptr); 416 base::FieldTrialList field_trial_list(nullptr);
412 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), 417 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
413 "Enabled"); 418 "Enabled");
414 // Enable Lo-Fi. 419 // Enable Lo-Fi.
415 const struct { 420 const struct {
416 bool is_using_lofi; 421 bool is_using_lofi;
417 } tests[] = { 422 } tests[] = {
418 {false}, {true}, 423 {false}, {true},
419 }; 424 };
420 425
421 for (size_t i = 0; i < arraysize(tests); ++i) { 426 for (size_t i = 0; i < arraysize(tests); ++i) {
422 scoped_ptr<net::URLRequest> request = CreateRequest(tests[i].is_using_lofi); 427 std::unique_ptr<net::URLRequest> request =
428 CreateRequest(tests[i].is_using_lofi);
423 net::HttpRequestHeaders headers; 429 net::HttpRequestHeaders headers;
424 NotifyBeforeSendProxyHeaders(&headers, request.get(), false); 430 NotifyBeforeSendProxyHeaders(&headers, request.get(), false);
425 std::string header_value; 431 std::string header_value;
426 headers.GetHeader(chrome_proxy_header(), &header_value); 432 headers.GetHeader(chrome_proxy_header(), &header_value);
427 EXPECT_EQ(std::string::npos, 433 EXPECT_EQ(std::string::npos,
428 header_value.find(chrome_proxy_lo_fi_directive())); 434 header_value.find(chrome_proxy_lo_fi_directive()));
429 } 435 }
430 } 436 }
431 437
432 } // namespace data_reduction_roxy 438 } // namespace data_reduction_roxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698