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

Side by Side Diff: net/url_request/url_request_context_builder_mojo_unittest.cc

Issue 2919423002: Make URLRequestContextBuilderV8 Mojo-only. (Closed)
Patch Set: Response to comments, fix net Mojo tests on Android, change chrome/utility workaround approach Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/url_request/url_request_context_builder_v8.h" 5 #include "net/url_request/url_request_context_builder_mojo.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "net/base/host_port_pair.h" 9 #include "net/base/host_port_pair.h"
10 #include "net/proxy/proxy_config.h" 10 #include "net/proxy/proxy_config.h"
11 #include "net/proxy/proxy_config_service_fixed.h" 11 #include "net/proxy/proxy_config_service_fixed.h"
12 #include "net/proxy/test_mojo_proxy_resolver_factory.h"
12 #include "net/test/embedded_test_server/embedded_test_server.h" 13 #include "net/test/embedded_test_server/embedded_test_server.h"
13 #include "net/test/embedded_test_server/http_request.h" 14 #include "net/test/embedded_test_server/http_request.h"
14 #include "net/test/embedded_test_server/http_response.h" 15 #include "net/test/embedded_test_server/http_response.h"
15 #include "net/test/embedded_test_server/simple_connection_listener.h" 16 #include "net/test/embedded_test_server/simple_connection_listener.h"
16 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" 17 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_test_util.h" 20 #include "net/url_request/url_request_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/platform_test.h" 22 #include "testing/platform_test.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 #ifdef ENABLE_NET_MOJO
25 #include "net/proxy/test_mojo_proxy_resolver_factory.h"
26 #endif
27
28 namespace net { 25 namespace net {
29 26
30 namespace { 27 namespace {
31 28
32 const char kPacPath[] = "/super.pac"; 29 const char kPacPath[] = "/super.pac";
33 30
34 // When kPacPath is requested, returns a PAC script that uses the test server 31 // When kPacPath is requested, returns a PAC script that uses the test server
35 // itself as the proxy. 32 // itself as the proxy.
36 std::unique_ptr<test_server::HttpResponse> HandlePacRequest( 33 std::unique_ptr<test_server::HttpResponse> HandlePacRequest(
37 const test_server::HttpRequest& request) { 34 const test_server::HttpRequest& request) {
38 if (request.relative_url != kPacPath) 35 if (request.relative_url != kPacPath)
39 return nullptr; 36 return nullptr;
40 std::unique_ptr<test_server::BasicHttpResponse> response = 37 std::unique_ptr<test_server::BasicHttpResponse> response =
41 base::MakeUnique<test_server::BasicHttpResponse>(); 38 base::MakeUnique<test_server::BasicHttpResponse>();
42 response->set_content(base::StringPrintf( 39 response->set_content(base::StringPrintf(
43 "function FindProxyForURL(url, host) { return 'PROXY %s;'; }", 40 "function FindProxyForURL(url, host) { return 'PROXY %s;'; }",
44 HostPortPair::FromURL(request.base_url).ToString().c_str())); 41 HostPortPair::FromURL(request.base_url).ToString().c_str()));
45 response->set_content_type("text/html"); 42 response->set_content_type("text/html");
46 return std::move(response); 43 return std::move(response);
47 } 44 }
48 45
49 class URLRequestContextBuilderV8Test : public PlatformTest { 46 class URLRequestContextBuilderMojoTest : public PlatformTest {
50 protected: 47 protected:
51 URLRequestContextBuilderV8Test() { 48 URLRequestContextBuilderMojoTest() {
52 test_server_.RegisterRequestHandler(base::Bind(&HandlePacRequest)); 49 test_server_.RegisterRequestHandler(base::Bind(&HandlePacRequest));
53 test_server_.AddDefaultHandlers( 50 test_server_.AddDefaultHandlers(
54 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 51 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
55 } 52 }
56 53
57 EmbeddedTestServer test_server_; 54 EmbeddedTestServer test_server_;
58 URLRequestContextBuilderV8 builder_; 55 URLRequestContextBuilderMojo builder_;
59 }; 56 };
60 57
61 TEST_F(URLRequestContextBuilderV8Test, V8InProcess) { 58 TEST_F(URLRequestContextBuilderMojoTest, MojoProxyResolver) {
62 EXPECT_TRUE(test_server_.Start()); 59 EXPECT_TRUE(test_server_.Start());
60 TestMojoProxyResolverFactory::GetInstance()->set_resolver_created(false);
63 61
64 builder_.set_proxy_config_service(base::MakeUnique<ProxyConfigServiceFixed>( 62 builder_.set_proxy_config_service(base::MakeUnique<ProxyConfigServiceFixed>(
65 ProxyConfig::CreateFromCustomPacURL(test_server_.GetURL(kPacPath)))); 63 ProxyConfig::CreateFromCustomPacURL(test_server_.GetURL(kPacPath))));
64 builder_.set_mojo_proxy_resolver_factory(
65 TestMojoProxyResolverFactory::GetInstance());
66
66 std::unique_ptr<URLRequestContext> context(builder_.Build()); 67 std::unique_ptr<URLRequestContext> context(builder_.Build());
67
68 TestDelegate delegate; 68 TestDelegate delegate;
69 std::unique_ptr<URLRequest> request(context->CreateRequest( 69 std::unique_ptr<URLRequest> request(context->CreateRequest(
70 GURL("http://hats:12345/echoheader?Foo"), DEFAULT_PRIORITY, &delegate, 70 GURL("http://hats:12345/echoheader?Foo"), DEFAULT_PRIORITY, &delegate,
71 TRAFFIC_ANNOTATION_FOR_TESTS)); 71 TRAFFIC_ANNOTATION_FOR_TESTS));
72 request->SetExtraRequestHeaderByName("Foo", "Bar", false); 72 request->SetExtraRequestHeaderByName("Foo", "Bar", false);
73 request->Start(); 73 request->Start();
74 base::RunLoop().Run(); 74 base::RunLoop().Run();
75 EXPECT_EQ("Bar", delegate.data_received()); 75 EXPECT_EQ("Bar", delegate.data_received());
76
77 // Make sure that the Mojo factory was used.
78 EXPECT_TRUE(TestMojoProxyResolverFactory::GetInstance()->resolver_created());
76 } 79 }
77 80
78 // Makes sure that pending PAC requests are correctly shutdown during teardown. 81 // Makes sure that pending PAC requests are correctly shut down during teardown.
79 TEST_F(URLRequestContextBuilderV8Test, V8InProcessShutdownWithHungRequest) { 82 TEST_F(URLRequestContextBuilderMojoTest, ShutdownWithHungRequest) {
80 test_server::SimpleConnectionListener connection_listener( 83 test_server::SimpleConnectionListener connection_listener(
81 1, test_server::SimpleConnectionListener::FAIL_ON_ADDITIONAL_CONNECTIONS); 84 1, test_server::SimpleConnectionListener::FAIL_ON_ADDITIONAL_CONNECTIONS);
82 test_server_.SetConnectionListener(&connection_listener); 85 test_server_.SetConnectionListener(&connection_listener);
83 EXPECT_TRUE(test_server_.Start()); 86 EXPECT_TRUE(test_server_.Start());
84 87
85 builder_.set_proxy_config_service(base::MakeUnique<ProxyConfigServiceFixed>( 88 builder_.set_proxy_config_service(base::MakeUnique<ProxyConfigServiceFixed>(
86 ProxyConfig::CreateFromCustomPacURL(test_server_.GetURL("/hung")))); 89 ProxyConfig::CreateFromCustomPacURL(test_server_.GetURL("/hung"))));
90 builder_.set_mojo_proxy_resolver_factory(
91 TestMojoProxyResolverFactory::GetInstance());
87 92
88 std::unique_ptr<URLRequestContext> context(builder_.Build()); 93 std::unique_ptr<URLRequestContext> context(builder_.Build());
89 TestDelegate delegate; 94 TestDelegate delegate;
90 std::unique_ptr<URLRequest> request(context->CreateRequest( 95 std::unique_ptr<URLRequest> request(context->CreateRequest(
91 GURL("http://hats:12345/echoheader?Foo"), DEFAULT_PRIORITY, &delegate, 96 GURL("http://hats:12345/echoheader?Foo"), DEFAULT_PRIORITY, &delegate,
92 TRAFFIC_ANNOTATION_FOR_TESTS)); 97 TRAFFIC_ANNOTATION_FOR_TESTS));
93 request->Start(); 98 request->Start();
94 connection_listener.WaitForConnections(); 99 connection_listener.WaitForConnections();
95 100
101 // Tearing down the URLRequestContext should not cause an AssertNoURLRequests
102 // failure.
103 request.reset();
104 context.reset();
105
96 // Have to shut down the test server before |connection_listener| falls out of 106 // Have to shut down the test server before |connection_listener| falls out of
97 // scope. 107 // scope.
98 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete()); 108 EXPECT_TRUE(test_server_.ShutdownAndWaitUntilComplete());
99
100 // Tearing down the URLRequestContext should not cause an AssertNoURLRequests
101 // failure.
102 } 109 }
103 110
104 #ifdef ENABLE_NET_MOJO
105 TEST_F(URLRequestContextBuilderV8Test, MojoProxyResolver) {
106 EXPECT_TRUE(test_server_.Start());
107 TestMojoProxyResolverFactory::GetInstance()->set_resolver_created(false);
108
109 builder_.set_proxy_config_service(base::MakeUnique<ProxyConfigServiceFixed>(
110 ProxyConfig::CreateFromCustomPacURL(test_server_.GetURL(kPacPath))));
111 builder_.set_mojo_proxy_resolver_factory(
112 TestMojoProxyResolverFactory::GetInstance());
113
114 std::unique_ptr<URLRequestContext> context(builder_.Build());
115 TestDelegate delegate;
116 std::unique_ptr<URLRequest> request(context->CreateRequest(
117 GURL("http://hats:12345/echoheader?Foo"), DEFAULT_PRIORITY, &delegate,
118 TRAFFIC_ANNOTATION_FOR_TESTS));
119 request->SetExtraRequestHeaderByName("Foo", "Bar", false);
120 request->Start();
121 base::RunLoop().Run();
122 EXPECT_EQ("Bar", delegate.data_received());
123
124 // Make sure that the Mojo factory was used.
125 EXPECT_TRUE(TestMojoProxyResolverFactory::GetInstance()->resolver_created());
126 }
127 #endif // ENABLE_NET_MOJO
128
129 } // namespace 111 } // namespace
130 112
131 } // namespace net 113 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_context_builder_mojo.cc ('k') | net/url_request/url_request_context_builder_v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698