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

Side by Side Diff: net/proxy/proxy_script_fetcher_impl_unittest.cc

Issue 2881613002: Allow use of Mojo/V8 ProxyResolvers with URLRequestContextBuilder. (Closed)
Patch Set: Missed some ENABLE_MOJOs Created 3 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
« no previous file with comments | « net/BUILD.gn ('k') | net/proxy/proxy_service_mojo_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/proxy/proxy_script_fetcher_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 21 matching lines...) Expand all
32 #include "net/http/http_cache.h" 32 #include "net/http/http_cache.h"
33 #include "net/http/http_network_session.h" 33 #include "net/http/http_network_session.h"
34 #include "net/http/http_server_properties_impl.h" 34 #include "net/http/http_server_properties_impl.h"
35 #include "net/http/http_transaction_factory.h" 35 #include "net/http/http_transaction_factory.h"
36 #include "net/http/transport_security_state.h" 36 #include "net/http/transport_security_state.h"
37 #include "net/net_features.h" 37 #include "net/net_features.h"
38 #include "net/socket/client_socket_pool_manager.h" 38 #include "net/socket/client_socket_pool_manager.h"
39 #include "net/socket/transport_client_socket_pool.h" 39 #include "net/socket/transport_client_socket_pool.h"
40 #include "net/ssl/ssl_config_service_defaults.h" 40 #include "net/ssl/ssl_config_service_defaults.h"
41 #include "net/test/embedded_test_server/embedded_test_server.h" 41 #include "net/test/embedded_test_server/embedded_test_server.h"
42 #include "net/test/embedded_test_server/embedded_test_server_connection_listener .h" 42 #include "net/test/embedded_test_server/simple_connection_listener.h"
43 #include "net/test/gtest_util.h" 43 #include "net/test/gtest_util.h"
44 #include "net/url_request/url_request_context_storage.h" 44 #include "net/url_request/url_request_context_storage.h"
45 #include "net/url_request/url_request_file_job.h" 45 #include "net/url_request/url_request_file_job.h"
46 #include "net/url_request/url_request_job_factory_impl.h" 46 #include "net/url_request/url_request_job_factory_impl.h"
47 #include "net/url_request/url_request_test_util.h" 47 #include "net/url_request/url_request_test_util.h"
48 #include "testing/gmock/include/gmock/gmock.h" 48 #include "testing/gmock/include/gmock/gmock.h"
49 #include "testing/gtest/include/gtest/gtest.h" 49 #include "testing/gtest/include/gtest/gtest.h"
50 #include "testing/platform_test.h" 50 #include "testing/platform_test.h"
51 51
52 #if !BUILDFLAG(DISABLE_FILE_SUPPORT) 52 #if !BUILDFLAG(DISABLE_FILE_SUPPORT)
(...skipping 14 matching lines...) Expand all
67 namespace { 67 namespace {
68 68
69 const base::FilePath::CharType kDocRoot[] = 69 const base::FilePath::CharType kDocRoot[] =
70 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest"); 70 FILE_PATH_LITERAL("net/data/proxy_script_fetcher_unittest");
71 71
72 struct FetchResult { 72 struct FetchResult {
73 int code; 73 int code;
74 base::string16 text; 74 base::string16 text;
75 }; 75 };
76 76
77 // Waits for the specified number of connection attempts to be seen.
78 class WaitForConnectionsListener
79 : public test_server::EmbeddedTestServerConnectionListener {
80 public:
81 explicit WaitForConnectionsListener(int expected_num_connections)
82 : expected_num_connections_(expected_num_connections),
83 task_runner_(base::SequencedTaskRunnerHandle::Get()) {}
84
85 void AcceptedSocket(const StreamSocket& socket) override {
86 ++seen_connections_;
87 EXPECT_LE(seen_connections_, expected_num_connections_);
88 if (expected_num_connections_ == seen_connections_)
89 task_runner_->PostTask(FROM_HERE, run_loop_.QuitClosure());
90 }
91
92 void ReadFromSocket(const StreamSocket& socket, int rv) override {}
93
94 void Wait() { run_loop_.Run(); }
95
96 private:
97 int seen_connections_ = 0;
98 int expected_num_connections_;
99
100 scoped_refptr<base::SequencedTaskRunner> task_runner_;
101
102 base::RunLoop run_loop_;
103
104 DISALLOW_COPY_AND_ASSIGN(WaitForConnectionsListener);
105 };
106
107 // A non-mock URL request which can access http:// and file:// urls, in the case 77 // A non-mock URL request which can access http:// and file:// urls, in the case
108 // the tests were built with file support. 78 // the tests were built with file support.
109 class RequestContext : public URLRequestContext { 79 class RequestContext : public URLRequestContext {
110 public: 80 public:
111 RequestContext() : storage_(this) { 81 RequestContext() : storage_(this) {
112 ProxyConfig no_proxy; 82 ProxyConfig no_proxy;
113 storage_.set_host_resolver( 83 storage_.set_host_resolver(
114 std::unique_ptr<HostResolver>(new MockHostResolver)); 84 std::unique_ptr<HostResolver>(new MockHostResolver));
115 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier)); 85 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier));
116 storage_.set_transport_security_state( 86 storage_.set_transport_security_state(
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 506 }
537 507
538 // Makes sure that a request gets through when the socket pool is full, so 508 // Makes sure that a request gets through when the socket pool is full, so
539 // ProxyScriptFetcherImpl can use the same URLRequestContext as everything else. 509 // ProxyScriptFetcherImpl can use the same URLRequestContext as everything else.
540 TEST_F(ProxyScriptFetcherImplTest, Priority) { 510 TEST_F(ProxyScriptFetcherImplTest, Priority) {
541 // Enough requests to exceed the per-pool limit, which is also enough to 511 // Enough requests to exceed the per-pool limit, which is also enough to
542 // exceed the per-group limit. 512 // exceed the per-group limit.
543 int num_requests = 10 + ClientSocketPoolManager::max_sockets_per_pool( 513 int num_requests = 10 + ClientSocketPoolManager::max_sockets_per_pool(
544 HttpNetworkSession::NORMAL_SOCKET_POOL); 514 HttpNetworkSession::NORMAL_SOCKET_POOL);
545 515
546 WaitForConnectionsListener connection_listener(num_requests); 516 net::test_server::SimpleConnectionListener connection_listener(
517 num_requests, net::test_server::SimpleConnectionListener::
518 FAIL_ON_ADDITIONAL_CONNECTIONS);
547 test_server_.SetConnectionListener(&connection_listener); 519 test_server_.SetConnectionListener(&connection_listener);
548 ASSERT_TRUE(test_server_.Start()); 520 ASSERT_TRUE(test_server_.Start());
549 521
550 std::vector<std::unique_ptr<ProxyScriptFetcherImpl>> pac_fetchers; 522 std::vector<std::unique_ptr<ProxyScriptFetcherImpl>> pac_fetchers;
551 523
552 TestCompletionCallback callback; 524 TestCompletionCallback callback;
553 base::string16 text; 525 base::string16 text;
554 for (int i = 0; i < num_requests; i++) { 526 for (int i = 0; i < num_requests; i++) {
555 std::unique_ptr<ProxyScriptFetcherImpl> pac_fetcher = 527 std::unique_ptr<ProxyScriptFetcherImpl> pac_fetcher =
556 base::MakeUnique<ProxyScriptFetcherImpl>(&context_); 528 base::MakeUnique<ProxyScriptFetcherImpl>(&context_);
557 GURL url(test_server_.GetURL("/hung")); 529 GURL url(test_server_.GetURL("/hung"));
558 // Fine to use the same string and callback for all of these, as they should 530 // Fine to use the same string and callback for all of these, as they should
559 // all hang. 531 // all hang.
560 int result = pac_fetcher->Fetch(url, &text, callback.callback()); 532 int result = pac_fetcher->Fetch(url, &text, callback.callback());
561 EXPECT_THAT(result, IsError(ERR_IO_PENDING)); 533 EXPECT_THAT(result, IsError(ERR_IO_PENDING));
562 pac_fetchers.push_back(std::move(pac_fetcher)); 534 pac_fetchers.push_back(std::move(pac_fetcher));
563 } 535 }
564 536
565 connection_listener.Wait(); 537 connection_listener.WaitForConnections();
566 // None of the callbacks should have been invoked - all jobs should still be 538 // None of the callbacks should have been invoked - all jobs should still be
567 // hung. 539 // hung.
568 EXPECT_FALSE(callback.have_result()); 540 EXPECT_FALSE(callback.have_result());
569 541
570 // Need to shut down the server before |connection_listener| is destroyed. 542 // Need to shut down the server before |connection_listener| is destroyed.
571 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); 543 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete());
572 } 544 }
573 545
574 TEST_F(ProxyScriptFetcherImplTest, OnShutdown) { 546 TEST_F(ProxyScriptFetcherImplTest, OnShutdown) {
575 ASSERT_TRUE(test_server_.Start()); 547 ASSERT_TRUE(test_server_.Start());
(...skipping 30 matching lines...) Expand all
606 TestCompletionCallback callback; 578 TestCompletionCallback callback;
607 int result = pac_fetcher.Fetch(test_server_.GetURL("/hung"), &text, 579 int result = pac_fetcher.Fetch(test_server_.GetURL("/hung"), &text,
608 callback.callback()); 580 callback.callback());
609 EXPECT_THAT(result, IsError(ERR_CONTEXT_SHUT_DOWN)); 581 EXPECT_THAT(result, IsError(ERR_CONTEXT_SHUT_DOWN));
610 EXPECT_EQ(0u, context_.url_requests().size()); 582 EXPECT_EQ(0u, context_.url_requests().size());
611 } 583 }
612 584
613 } // namespace 585 } // namespace
614 586
615 } // namespace net 587 } // namespace net
OLDNEW
« no previous file with comments | « net/BUILD.gn ('k') | net/proxy/proxy_service_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698