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

Side by Side Diff: content/browser/loader/resource_loader_unittest.cc

Issue 2183153002: NQE: Move ECT to net:: namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, also fixed comnpilation error Created 4 years, 4 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 24 matching lines...) Expand all
35 #include "content/test/test_content_browser_client.h" 35 #include "content/test/test_content_browser_client.h"
36 #include "content/test/test_web_contents.h" 36 #include "content/test/test_web_contents.h"
37 #include "ipc/ipc_message.h" 37 #include "ipc/ipc_message.h"
38 #include "net/base/chunked_upload_data_stream.h" 38 #include "net/base/chunked_upload_data_stream.h"
39 #include "net/base/io_buffer.h" 39 #include "net/base/io_buffer.h"
40 #include "net/base/mock_file_stream.h" 40 #include "net/base/mock_file_stream.h"
41 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
42 #include "net/base/request_priority.h" 42 #include "net/base/request_priority.h"
43 #include "net/base/upload_bytes_element_reader.h" 43 #include "net/base/upload_bytes_element_reader.h"
44 #include "net/cert/x509_certificate.h" 44 #include "net/cert/x509_certificate.h"
45 #include "net/nqe/effective_connection_type.h"
45 #include "net/nqe/network_quality_estimator.h" 46 #include "net/nqe/network_quality_estimator.h"
46 #include "net/ssl/client_cert_store.h" 47 #include "net/ssl/client_cert_store.h"
47 #include "net/ssl/ssl_cert_request_info.h" 48 #include "net/ssl/ssl_cert_request_info.h"
48 #include "net/ssl/ssl_private_key.h" 49 #include "net/ssl/ssl_private_key.h"
49 #include "net/test/cert_test_util.h" 50 #include "net/test/cert_test_util.h"
50 #include "net/test/embedded_test_server/embedded_test_server.h" 51 #include "net/test/embedded_test_server/embedded_test_server.h"
51 #include "net/test/test_data_directory.h" 52 #include "net/test/test_data_directory.h"
52 #include "net/url_request/url_request.h" 53 #include "net/url_request/url_request.h"
53 #include "net/url_request/url_request_filter.h" 54 #include "net/url_request/url_request_filter.h"
54 #include "net/url_request/url_request_interceptor.h" 55 #include "net/url_request/url_request_interceptor.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 defer_request_on_will_start_(false), 278 defer_request_on_will_start_(false),
278 expect_reads_(true), 279 expect_reads_(true),
279 cancel_on_read_completed_(false), 280 cancel_on_read_completed_(false),
280 defer_eof_(false), 281 defer_eof_(false),
281 received_on_will_read_(false), 282 received_on_will_read_(false),
282 received_eof_(false), 283 received_eof_(false),
283 received_response_completed_(false), 284 received_response_completed_(false),
284 received_request_redirected_(false), 285 received_request_redirected_(false),
285 total_bytes_downloaded_(0), 286 total_bytes_downloaded_(0),
286 observed_effective_connection_type_( 287 observed_effective_connection_type_(
287 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {} 288 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {}
288 289
289 // If true, defers the resource load in OnWillStart. 290 // If true, defers the resource load in OnWillStart.
290 void set_defer_request_on_will_start(bool defer_request_on_will_start) { 291 void set_defer_request_on_will_start(bool defer_request_on_will_start) {
291 defer_request_on_will_start_ = defer_request_on_will_start; 292 defer_request_on_will_start_ = defer_request_on_will_start;
292 } 293 }
293 294
294 // If true, expect OnWillRead / OnReadCompleted pairs for handling 295 // If true, expect OnWillRead / OnReadCompleted pairs for handling
295 // data. Otherwise, expect OnDataDownloaded. 296 // data. Otherwise, expect OnDataDownloaded.
296 void set_expect_reads(bool expect_reads) { expect_reads_ = expect_reads; } 297 void set_expect_reads(bool expect_reads) { expect_reads_ = expect_reads; }
297 298
(...skipping 12 matching lines...) Expand all
310 } 311 }
311 bool received_response_completed() const { 312 bool received_response_completed() const {
312 return received_response_completed_; 313 return received_response_completed_;
313 } 314 }
314 bool received_request_redirected() const { 315 bool received_request_redirected() const {
315 return received_request_redirected_; 316 return received_request_redirected_;
316 } 317 }
317 const net::URLRequestStatus& status() const { return status_; } 318 const net::URLRequestStatus& status() const { return status_; }
318 int total_bytes_downloaded() const { return total_bytes_downloaded_; } 319 int total_bytes_downloaded() const { return total_bytes_downloaded_; }
319 320
320 net::NetworkQualityEstimator::EffectiveConnectionType 321 net::EffectiveConnectionType observed_effective_connection_type() const {
321 observed_effective_connection_type() const {
322 return observed_effective_connection_type_; 322 return observed_effective_connection_type_;
323 } 323 }
324 324
325 void Resume() { 325 void Resume() {
326 controller()->Resume(); 326 controller()->Resume();
327 } 327 }
328 328
329 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 329 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
330 ResourceResponse* response, 330 ResourceResponse* response,
331 bool* defer) override { 331 bool* defer) override {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 scoped_refptr<ResourceResponse> redirect_response_; 428 scoped_refptr<ResourceResponse> redirect_response_;
429 bool received_on_will_read_; 429 bool received_on_will_read_;
430 bool received_eof_; 430 bool received_eof_;
431 bool received_response_completed_; 431 bool received_response_completed_;
432 bool received_request_redirected_; 432 bool received_request_redirected_;
433 net::URLRequestStatus status_; 433 net::URLRequestStatus status_;
434 int total_bytes_downloaded_; 434 int total_bytes_downloaded_;
435 base::RunLoop deferred_run_loop_; 435 base::RunLoop deferred_run_loop_;
436 base::RunLoop response_completed_run_loop_; 436 base::RunLoop response_completed_run_loop_;
437 std::unique_ptr<base::RunLoop> wait_for_progress_run_loop_; 437 std::unique_ptr<base::RunLoop> wait_for_progress_run_loop_;
438 net::NetworkQualityEstimator::EffectiveConnectionType 438 net::EffectiveConnectionType observed_effective_connection_type_;
439 observed_effective_connection_type_;
440 }; 439 };
441 440
442 // Test browser client that captures calls to SelectClientCertificates and 441 // Test browser client that captures calls to SelectClientCertificates and
443 // records the arguments of the most recent call for later inspection. 442 // records the arguments of the most recent call for later inspection.
444 class SelectCertificateBrowserClient : public TestContentBrowserClient { 443 class SelectCertificateBrowserClient : public TestContentBrowserClient {
445 public: 444 public:
446 SelectCertificateBrowserClient() : call_count_(0) {} 445 SelectCertificateBrowserClient() : call_count_(0) {}
447 446
448 // Waits until the first call to SelectClientCertificate. 447 // Waits until the first call to SelectClientCertificate.
449 void WaitForSelectCertificate() { 448 void WaitForSelectCertificate() {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 base::Passed(std::unique_ptr<net::FileStream>()), nullptr)); 527 base::Passed(std::unique_ptr<net::FileStream>()), nullptr));
529 } 528 }
530 529
531 } // namespace 530 } // namespace
532 531
533 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator { 532 class TestNetworkQualityEstimator : public net::NetworkQualityEstimator {
534 public: 533 public:
535 TestNetworkQualityEstimator() 534 TestNetworkQualityEstimator()
536 : net::NetworkQualityEstimator(nullptr, 535 : net::NetworkQualityEstimator(nullptr,
537 std::map<std::string, std::string>()), 536 std::map<std::string, std::string>()),
538 type_(net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 537 type_(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {}
539 }
540 ~TestNetworkQualityEstimator() override {} 538 ~TestNetworkQualityEstimator() override {}
541 539
542 net::NetworkQualityEstimator::EffectiveConnectionType 540 net::EffectiveConnectionType GetEffectiveConnectionType() const override {
543 GetEffectiveConnectionType() const override {
544 return type_; 541 return type_;
545 } 542 }
546 543
547 void set_effective_connection_type( 544 void set_effective_connection_type(net::EffectiveConnectionType type) {
548 net::NetworkQualityEstimator::EffectiveConnectionType type) {
549 type_ = type; 545 type_ = type;
550 } 546 }
551 547
552 private: 548 private:
553 net::NetworkQualityEstimator::EffectiveConnectionType type_; 549 net::EffectiveConnectionType type_;
554 550
555 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator); 551 DISALLOW_COPY_AND_ASSIGN(TestNetworkQualityEstimator);
556 }; 552 };
557 553
558 class ResourceLoaderTest : public testing::Test, 554 class ResourceLoaderTest : public testing::Test,
559 public ResourceLoaderDelegate { 555 public ResourceLoaderDelegate {
560 protected: 556 protected:
561 ResourceLoaderTest() 557 ResourceLoaderTest()
562 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 558 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
563 test_url_request_context_(true), 559 test_url_request_context_(true),
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 1180
1185 EXPECT_EQ(kTestCertError, deserialized.cert_status); 1181 EXPECT_EQ(kTestCertError, deserialized.cert_status);
1186 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status); 1182 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status);
1187 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits); 1183 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits);
1188 } 1184 }
1189 1185
1190 class EffectiveConnectionTypeResourceLoaderTest : public ResourceLoaderTest { 1186 class EffectiveConnectionTypeResourceLoaderTest : public ResourceLoaderTest {
1191 public: 1187 public:
1192 void VerifyEffectiveConnectionType( 1188 void VerifyEffectiveConnectionType(
1193 bool is_main_frame, 1189 bool is_main_frame,
1194 net::NetworkQualityEstimator::EffectiveConnectionType set_type, 1190 net::EffectiveConnectionType set_type,
1195 net::NetworkQualityEstimator::EffectiveConnectionType expected_type) { 1191 net::EffectiveConnectionType expected_type) {
1196 network_quality_estimator()->set_effective_connection_type(set_type); 1192 network_quality_estimator()->set_effective_connection_type(set_type);
1197 1193
1198 // Start the request and wait for it to finish. 1194 // Start the request and wait for it to finish.
1199 std::unique_ptr<net::URLRequest> request( 1195 std::unique_ptr<net::URLRequest> request(
1200 resource_context_.GetRequestContext()->CreateRequest( 1196 resource_context_.GetRequestContext()->CreateRequest(
1201 test_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */)); 1197 test_url(), net::DEFAULT_PRIORITY, nullptr /* delegate */));
1202 SetUpResourceLoader(std::move(request), is_main_frame); 1198 SetUpResourceLoader(std::move(request), is_main_frame);
1203 1199
1204 // Send the request and wait until it completes. 1200 // Send the request and wait until it completes.
1205 loader_->StartRequest(); 1201 loader_->StartRequest();
1206 raw_ptr_resource_handler_->WaitForResponseComplete(); 1202 raw_ptr_resource_handler_->WaitForResponseComplete();
1207 ASSERT_EQ(net::URLRequestStatus::SUCCESS, 1203 ASSERT_EQ(net::URLRequestStatus::SUCCESS,
1208 raw_ptr_to_request_->status().status()); 1204 raw_ptr_to_request_->status().status());
1209 1205
1210 EXPECT_EQ(expected_type, 1206 EXPECT_EQ(expected_type,
1211 raw_ptr_resource_handler_->observed_effective_connection_type()); 1207 raw_ptr_resource_handler_->observed_effective_connection_type());
1212 } 1208 }
1213 }; 1209 };
1214 1210
1215 // Tests that the effective connection type is set on main frame requests. 1211 // Tests that the effective connection type is set on main frame requests.
1216 TEST_F(EffectiveConnectionTypeResourceLoaderTest, Slow2G) { 1212 TEST_F(EffectiveConnectionTypeResourceLoaderTest, Slow2G) {
1217 VerifyEffectiveConnectionType( 1213 VerifyEffectiveConnectionType(true, net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
1218 true, net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, 1214 net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1219 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1220 } 1215 }
1221 1216
1222 // Tests that the effective connection type is set on main frame requests. 1217 // Tests that the effective connection type is set on main frame requests.
1223 TEST_F(EffectiveConnectionTypeResourceLoaderTest, 3G) { 1218 TEST_F(EffectiveConnectionTypeResourceLoaderTest, 3G) {
1224 VerifyEffectiveConnectionType( 1219 VerifyEffectiveConnectionType(true, net::EFFECTIVE_CONNECTION_TYPE_3G,
1225 true, net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G, 1220 net::EFFECTIVE_CONNECTION_TYPE_3G);
1226 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G);
1227 } 1221 }
1228 1222
1229 // Tests that the effective connection type is not set on non-main frame 1223 // Tests that the effective connection type is not set on non-main frame
1230 // requests. 1224 // requests.
1231 TEST_F(EffectiveConnectionTypeResourceLoaderTest, NotAMainFrame) { 1225 TEST_F(EffectiveConnectionTypeResourceLoaderTest, NotAMainFrame) {
1232 VerifyEffectiveConnectionType( 1226 VerifyEffectiveConnectionType(false, net::EFFECTIVE_CONNECTION_TYPE_3G,
1233 false, net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_3G, 1227 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1234 net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN);
1235 } 1228 }
1236 1229
1237 } // namespace content 1230 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_loader.cc ('k') | content/child/weburlresponse_extradata_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698