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

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

Issue 1017453005: Add support for ProxyResolverErrorObserver to ProxyResolverMojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 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 "net/proxy/mock_proxy_resolver.h" 7 #include "net/proxy/mock_proxy_resolver.h"
8 #include "net/proxy/proxy_resolver_error_observer.h"
8 #include "net/test/event_waiter.h" 9 #include "net/test/event_waiter.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #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/binding.h"
11 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h" 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
12 13
13 namespace net { 14 namespace net {
14 namespace { 15 namespace {
15 16
16 class FakeProxyResolver : public MockAsyncProxyResolverExpectsBytes { 17 class FakeProxyResolver : public MockAsyncProxyResolverExpectsBytes {
17 public: 18 public:
(...skipping 22 matching lines...) Expand all
40 new MojoProxyResolverFactoryImpl( 41 new MojoProxyResolverFactoryImpl(
41 base::Bind(&MojoProxyResolverFactoryImplTest::CreateFakeProxyResolver, 42 base::Bind(&MojoProxyResolverFactoryImplTest::CreateFakeProxyResolver,
42 base::Unretained(this)), 43 base::Unretained(this)),
43 mojo::GetProxy(&factory_)); 44 mojo::GetProxy(&factory_));
44 } 45 }
45 46
46 void OnConnectionError() override { waiter_.NotifyEvent(CONNECTION_ERROR); } 47 void OnConnectionError() override { waiter_.NotifyEvent(CONNECTION_ERROR); }
47 48
48 scoped_ptr<ProxyResolver> CreateFakeProxyResolver( 49 scoped_ptr<ProxyResolver> CreateFakeProxyResolver(
49 HostResolver* host_resolver, 50 HostResolver* host_resolver,
51 scoped_ptr<ProxyResolverErrorObserver> error_observer,
50 const ProxyResolver::LoadStateChangedCallback& callback) { 52 const ProxyResolver::LoadStateChangedCallback& callback) {
51 EXPECT_TRUE(host_resolver); 53 EXPECT_TRUE(host_resolver);
54 EXPECT_TRUE(error_observer);
52 instances_created_++; 55 instances_created_++;
53 waiter_.NotifyEvent(RESOLVER_CREATED); 56 waiter_.NotifyEvent(RESOLVER_CREATED);
54 return make_scoped_ptr(new FakeProxyResolver(base::Bind( 57 return make_scoped_ptr(new FakeProxyResolver(base::Bind(
55 &MojoProxyResolverFactoryImplTest::OnFakeProxyInstanceDestroyed, 58 &MojoProxyResolverFactoryImplTest::OnFakeProxyInstanceDestroyed,
56 base::Unretained(this)))); 59 base::Unretained(this))));
57 } 60 }
58 61
59 void OnFakeProxyInstanceDestroyed() { 62 void OnFakeProxyInstanceDestroyed() {
60 instances_destroyed_++; 63 instances_destroyed_++;
61 waiter_.NotifyEvent(RESOLVER_DESTROYED); 64 waiter_.NotifyEvent(RESOLVER_DESTROYED);
62 } 65 }
63 66
64 interfaces::ProxyResolverFactoryPtr factory_; 67 interfaces::ProxyResolverFactoryPtr factory_;
65 68
66 int instances_created_ = 0; 69 int instances_created_ = 0;
67 int instances_destroyed_ = 0; 70 int instances_destroyed_ = 0;
68 71
69 EventWaiter<Event> waiter_; 72 EventWaiter<Event> waiter_;
70 }; 73 };
71 74
72 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectHostResolver) { 75 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectHostResolver) {
73 interfaces::ProxyResolverPtr proxy_resolver; 76 interfaces::ProxyResolverPtr proxy_resolver;
74 interfaces::HostResolverPtr host_resolver; 77 interfaces::HostResolverPtr host_resolver;
75 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request = 78 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request =
76 mojo::GetProxy(&host_resolver); 79 mojo::GetProxy(&host_resolver);
80 interfaces::ProxyResolverErrorObserverPtr error_observer;
81 mojo::GetProxy(&error_observer);
77 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver), 82 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver),
78 host_resolver.Pass()); 83 host_resolver.Pass(), error_observer.Pass());
79 proxy_resolver.set_error_handler(this); 84 proxy_resolver.set_error_handler(this);
80 waiter_.WaitForEvent(RESOLVER_CREATED); 85 waiter_.WaitForEvent(RESOLVER_CREATED);
81 EXPECT_EQ(1, instances_created_); 86 EXPECT_EQ(1, instances_created_);
82 EXPECT_EQ(0, instances_destroyed_); 87 EXPECT_EQ(0, instances_destroyed_);
83 host_resolver_request = mojo::InterfaceRequest<interfaces::HostResolver>(); 88 host_resolver_request = mojo::InterfaceRequest<interfaces::HostResolver>();
84 waiter_.WaitForEvent(CONNECTION_ERROR); 89 waiter_.WaitForEvent(CONNECTION_ERROR);
85 EXPECT_EQ(1, instances_created_); 90 EXPECT_EQ(1, instances_created_);
86 EXPECT_EQ(1, instances_destroyed_); 91 EXPECT_EQ(1, instances_destroyed_);
87 } 92 }
88 93
89 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectProxyResolverClient) { 94 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectProxyResolverClient) {
90 interfaces::ProxyResolverPtr proxy_resolver; 95 interfaces::ProxyResolverPtr proxy_resolver;
91 interfaces::HostResolverPtr host_resolver; 96 interfaces::HostResolverPtr host_resolver;
92 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request = 97 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request =
93 mojo::GetProxy(&host_resolver); 98 mojo::GetProxy(&host_resolver);
94 mojo::Binding<interfaces::HostResolver> binding(nullptr, &host_resolver); 99 mojo::Binding<interfaces::HostResolver> binding(nullptr, &host_resolver);
95 binding.set_error_handler(this); 100 binding.set_error_handler(this);
101 interfaces::ProxyResolverErrorObserverPtr error_observer;
102 mojo::GetProxy(&error_observer);
96 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver), 103 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver),
97 host_resolver.Pass()); 104 host_resolver.Pass(), error_observer.Pass());
98 waiter_.WaitForEvent(RESOLVER_CREATED); 105 waiter_.WaitForEvent(RESOLVER_CREATED);
99 EXPECT_EQ(1, instances_created_); 106 EXPECT_EQ(1, instances_created_);
100 EXPECT_EQ(0, instances_destroyed_); 107 EXPECT_EQ(0, instances_destroyed_);
101 proxy_resolver.reset(); 108 proxy_resolver.reset();
102 waiter_.WaitForEvent(CONNECTION_ERROR); 109 waiter_.WaitForEvent(CONNECTION_ERROR);
103 EXPECT_EQ(1, instances_created_); 110 EXPECT_EQ(1, instances_created_);
104 EXPECT_EQ(1, instances_destroyed_); 111 EXPECT_EQ(1, instances_destroyed_);
105 } 112 }
106 113
107 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectBoth) { 114 TEST_F(MojoProxyResolverFactoryImplTest, DisconnectBoth) {
108 interfaces::ProxyResolverPtr proxy_resolver; 115 interfaces::ProxyResolverPtr proxy_resolver;
109 interfaces::HostResolverPtr host_resolver; 116 interfaces::HostResolverPtr host_resolver;
110 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request = 117 mojo::InterfaceRequest<interfaces::HostResolver> host_resolver_request =
111 mojo::GetProxy(&host_resolver); 118 mojo::GetProxy(&host_resolver);
119 interfaces::ProxyResolverErrorObserverPtr error_observer;
120 mojo::GetProxy(&error_observer);
112 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver), 121 factory_->CreateResolver(mojo::GetProxy(&proxy_resolver),
113 host_resolver.Pass()); 122 host_resolver.Pass(), error_observer.Pass());
114 waiter_.WaitForEvent(RESOLVER_CREATED); 123 waiter_.WaitForEvent(RESOLVER_CREATED);
115 EXPECT_EQ(1, instances_created_); 124 EXPECT_EQ(1, instances_created_);
116 EXPECT_EQ(0, instances_destroyed_); 125 EXPECT_EQ(0, instances_destroyed_);
117 proxy_resolver.reset(); 126 proxy_resolver.reset();
118 host_resolver_request = mojo::InterfaceRequest<interfaces::HostResolver>(); 127 host_resolver_request = mojo::InterfaceRequest<interfaces::HostResolver>();
119 waiter_.WaitForEvent(RESOLVER_DESTROYED); 128 waiter_.WaitForEvent(RESOLVER_DESTROYED);
120 EXPECT_EQ(1, instances_created_); 129 EXPECT_EQ(1, instances_created_);
121 EXPECT_EQ(1, instances_destroyed_); 130 EXPECT_EQ(1, instances_destroyed_);
122 } 131 }
123 132
124 } // namespace net 133 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698