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

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

Issue 918933002: Implement utility-side proxy resolver factory Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-resolver-mojo
Patch Set: Created 5 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/proxy/mojo_proxy_resolver_factory_impl.h"
6
7 #include "net/proxy/mock_proxy_resolver.h"
8 #include "net/test/event_waiter.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
11 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
12
13 namespace net {
14 namespace {
15
16 class FakeProxyResolver : public MockAsyncProxyResolverExpectsBytes {
17 public:
18 explicit FakeProxyResolver(const base::Closure& on_destruction)
19 : on_destruction_(on_destruction) {}
20
21 ~FakeProxyResolver() override { on_destruction_.Run(); }
22
23 private:
24 const base::Closure on_destruction_;
25 };
26
27 } // namespace
28
29 class MojoProxyResolverFactoryImplTest : public testing::Test,
30 public mojo::ErrorHandler {
31 protected:
32 enum Event {
33 NONE,
34 RESOLVER_CREATED,
35 CONNECTION_ERROR,
36 };
37
38 void SetUp() override {
39 new MojoProxyResolverFactoryImpl(
40 base::Bind(&MojoProxyResolverFactoryImplTest::CreateFakeProxyResolver,
41 base::Unretained(this)),
42 mojo::GetProxy(&factory_));
43 }
44
45 void OnConnectionError() override { waiter_.NotifyEvent(CONNECTION_ERROR); }
46
47 scoped_ptr<ProxyResolver> CreateFakeProxyResolver(
48 HostResolver* host_resolver) {
49 EXPECT_TRUE(host_resolver);
50 instances_created_++;
51 waiter_.NotifyEvent(RESOLVER_CREATED);
52 return make_scoped_ptr(new FakeProxyResolver(base::Bind(
53 &MojoProxyResolverFactoryImplTest::OnFakeProxyInstanceDestroyed,
54 base::Unretained(this))));
55 }
56
57 void OnFakeProxyInstanceDestroyed() { instances_destroyed_++; }
58
59 interfaces::ProxyResolverFactoryPtr factory_;
60
61 int instances_created_ = 0;
62 int instances_destroyed_ = 0;
63
64 EventWaiter<Event> waiter_;
65 };
66
67 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectHostResolver) {
68 interfaces::ProxyResolverPtr proxy_resolver;
69 interfaces::HostResolverPtr host_resolver;
70 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request =
71 mojo::GetProxy(&host_resolver);
72 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver),
73 host_resolver.Pass());
74 proxy_resolver.set_error_handler(this);
75 waiter_.WaitForEvent(RESOLVER_CREATED);
76 EXPECT_EQ(1, instances_created_);
77 EXPECT_EQ(0, instances_destroyed_);
78 host_resolver_request = mojo::InterfaceRequest<interfaces::HostResolver>();
79 waiter_.WaitForEvent(CONNECTION_ERROR);
80 EXPECT_EQ(1, instances_created_);
81 EXPECT_EQ(1, instances_destroyed_);
82 }
83
84 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectProxyResolverClient) {
85 interfaces::ProxyResolverPtr proxy_resolver;
86 interfaces::HostResolverPtr host_resolver;
87 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request =
88 mojo::GetProxy(&host_resolver);
89 mojo::Binding<interfaces::HostResolver> binding(nullptr, &host_resolver);
90 binding.set_error_handler(this);
91 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver),
92 host_resolver.Pass());
93 waiter_.WaitForEvent(RESOLVER_CREATED);
94 EXPECT_EQ(1, instances_created_);
95 EXPECT_EQ(0, instances_destroyed_);
96 proxy_resolver.reset();
97 waiter_.WaitForEvent(CONNECTION_ERROR);
98 EXPECT_EQ(1, instances_created_);
99 EXPECT_EQ(1, instances_destroyed_);
100 }
101
102 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698