OLD | NEW |
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 "net/proxy/mojo_proxy_resolver_factory_impl.h" | 5 #include "net/proxy/mojo_proxy_resolver_factory_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "mojo/public/cpp/bindings/binding.h" | 11 #include "mojo/public/cpp/bindings/binding.h" |
12 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
13 #include "net/proxy/mock_proxy_resolver.h" | 13 #include "net/proxy/mock_proxy_resolver.h" |
14 #include "net/proxy/proxy_resolver_v8_tracing.h" | 14 #include "net/proxy/proxy_resolver_v8_tracing.h" |
15 #include "net/test/event_waiter.h" | 15 #include "net/test/event_waiter.h" |
| 16 #include "net/test/gtest_util.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
17 | 19 |
| 20 using net::test::IsError; |
| 21 using net::test::IsOk; |
| 22 |
18 namespace net { | 23 namespace net { |
19 namespace { | 24 namespace { |
20 | 25 |
21 const char kScriptData[] = "FooBarBaz"; | 26 const char kScriptData[] = "FooBarBaz"; |
22 | 27 |
23 class FakeProxyResolver : public ProxyResolverV8Tracing { | 28 class FakeProxyResolver : public ProxyResolverV8Tracing { |
24 public: | 29 public: |
25 explicit FakeProxyResolver(const base::Closure& on_destruction) | 30 explicit FakeProxyResolver(const base::Closure& on_destruction) |
26 : on_destruction_(on_destruction) {} | 31 : on_destruction_(on_destruction) {} |
27 | 32 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 EXPECT_EQ(0, instances_destroyed_); | 150 EXPECT_EQ(0, instances_destroyed_); |
146 ASSERT_EQ(1u, mock_factory_->requests_handled()); | 151 ASSERT_EQ(1u, mock_factory_->requests_handled()); |
147 TestCompletionCallback create_callback; | 152 TestCompletionCallback create_callback; |
148 create_callback_ = create_callback.callback(); | 153 create_callback_ = create_callback.callback(); |
149 ASSERT_TRUE(mock_factory_->pending_request()); | 154 ASSERT_TRUE(mock_factory_->pending_request()); |
150 mock_factory_->pending_request()->resolver->reset( | 155 mock_factory_->pending_request()->resolver->reset( |
151 new FakeProxyResolver(base::Bind( | 156 new FakeProxyResolver(base::Bind( |
152 &MojoProxyResolverFactoryImplTest::OnFakeProxyInstanceDestroyed, | 157 &MojoProxyResolverFactoryImplTest::OnFakeProxyInstanceDestroyed, |
153 base::Unretained(this)))); | 158 base::Unretained(this)))); |
154 mock_factory_->pending_request()->callback.Run(OK); | 159 mock_factory_->pending_request()->callback.Run(OK); |
155 EXPECT_EQ(OK, create_callback.WaitForResult()); | 160 EXPECT_THAT(create_callback.WaitForResult(), IsOk()); |
156 proxy_resolver.reset(); | 161 proxy_resolver.reset(); |
157 waiter_.WaitForEvent(RESOLVER_DESTROYED); | 162 waiter_.WaitForEvent(RESOLVER_DESTROYED); |
158 EXPECT_EQ(1, instances_destroyed_); | 163 EXPECT_EQ(1, instances_destroyed_); |
159 } | 164 } |
160 | 165 |
161 TEST_F(MojoProxyResolverFactoryImplTest, Error) { | 166 TEST_F(MojoProxyResolverFactoryImplTest, Error) { |
162 interfaces::ProxyResolverPtr proxy_resolver; | 167 interfaces::ProxyResolverPtr proxy_resolver; |
163 interfaces::ProxyResolverFactoryRequestClientPtr client_ptr; | 168 interfaces::ProxyResolverFactoryRequestClientPtr client_ptr; |
164 mojo::Binding<ProxyResolverFactoryRequestClient> client_binding( | 169 mojo::Binding<ProxyResolverFactoryRequestClient> client_binding( |
165 this, mojo::GetProxy(&client_ptr)); | 170 this, mojo::GetProxy(&client_ptr)); |
166 factory_->CreateResolver(mojo::String::From(kScriptData), | 171 factory_->CreateResolver(mojo::String::From(kScriptData), |
167 mojo::GetProxy(&proxy_resolver), | 172 mojo::GetProxy(&proxy_resolver), |
168 std::move(client_ptr)); | 173 std::move(client_ptr)); |
169 proxy_resolver.set_connection_error_handler( | 174 proxy_resolver.set_connection_error_handler( |
170 base::Bind(&MojoProxyResolverFactoryImplTest::OnConnectionError, | 175 base::Bind(&MojoProxyResolverFactoryImplTest::OnConnectionError, |
171 base::Unretained(this))); | 176 base::Unretained(this))); |
172 waiter_.WaitForEvent(RESOLVER_CREATED); | 177 waiter_.WaitForEvent(RESOLVER_CREATED); |
173 EXPECT_EQ(0, instances_destroyed_); | 178 EXPECT_EQ(0, instances_destroyed_); |
174 ASSERT_EQ(1u, mock_factory_->requests_handled()); | 179 ASSERT_EQ(1u, mock_factory_->requests_handled()); |
175 TestCompletionCallback create_callback; | 180 TestCompletionCallback create_callback; |
176 create_callback_ = create_callback.callback(); | 181 create_callback_ = create_callback.callback(); |
177 ASSERT_TRUE(mock_factory_->pending_request()); | 182 ASSERT_TRUE(mock_factory_->pending_request()); |
178 mock_factory_->pending_request()->callback.Run(ERR_PAC_SCRIPT_FAILED); | 183 mock_factory_->pending_request()->callback.Run(ERR_PAC_SCRIPT_FAILED); |
179 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, create_callback.WaitForResult()); | 184 EXPECT_THAT(create_callback.WaitForResult(), IsError(ERR_PAC_SCRIPT_FAILED)); |
180 } | 185 } |
181 | 186 |
182 TEST_F(MojoProxyResolverFactoryImplTest, | 187 TEST_F(MojoProxyResolverFactoryImplTest, |
183 DisconnectClientDuringResolverCreation) { | 188 DisconnectClientDuringResolverCreation) { |
184 interfaces::ProxyResolverPtr proxy_resolver; | 189 interfaces::ProxyResolverPtr proxy_resolver; |
185 interfaces::ProxyResolverFactoryRequestClientPtr client_ptr; | 190 interfaces::ProxyResolverFactoryRequestClientPtr client_ptr; |
186 mojo::Binding<ProxyResolverFactoryRequestClient> client_binding( | 191 mojo::Binding<ProxyResolverFactoryRequestClient> client_binding( |
187 this, mojo::GetProxy(&client_ptr)); | 192 this, mojo::GetProxy(&client_ptr)); |
188 factory_->CreateResolver(mojo::String::From(kScriptData), | 193 factory_->CreateResolver(mojo::String::From(kScriptData), |
189 mojo::GetProxy(&proxy_resolver), | 194 mojo::GetProxy(&proxy_resolver), |
(...skipping 24 matching lines...) Expand all Loading... |
214 base::Bind(&MojoProxyResolverFactoryImplTest::OnConnectionError, | 219 base::Bind(&MojoProxyResolverFactoryImplTest::OnConnectionError, |
215 base::Unretained(this))); | 220 base::Unretained(this))); |
216 waiter_.WaitForEvent(RESOLVER_CREATED); | 221 waiter_.WaitForEvent(RESOLVER_CREATED); |
217 EXPECT_EQ(0, instances_destroyed_); | 222 EXPECT_EQ(0, instances_destroyed_); |
218 ASSERT_EQ(1u, mock_factory_->requests_handled()); | 223 ASSERT_EQ(1u, mock_factory_->requests_handled()); |
219 factory_.reset(); | 224 factory_.reset(); |
220 waiter_.WaitForEvent(CONNECTION_ERROR); | 225 waiter_.WaitForEvent(CONNECTION_ERROR); |
221 } | 226 } |
222 | 227 |
223 } // namespace net | 228 } // namespace net |
OLD | NEW |