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

Side by Side Diff: net/socket_stream/socket_stream_unittest.cc

Issue 10541046: Adds NetworkDelegate::NotifyBeforeSocketStreamConnect() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comments Created 8 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
« no previous file with comments | « net/socket_stream/socket_stream.cc ('k') | net/url_request/url_request_context_builder.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/socket_stream/socket_stream.h" 5 #include "net/socket_stream/socket_stream.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 class TestURLRequestContextWithProxy : public TestURLRequestContext { 181 class TestURLRequestContextWithProxy : public TestURLRequestContext {
182 public: 182 public:
183 explicit TestURLRequestContextWithProxy(const std::string& proxy) 183 explicit TestURLRequestContextWithProxy(const std::string& proxy)
184 : TestURLRequestContext(true) { 184 : TestURLRequestContext(true) {
185 context_storage_.set_proxy_service(net::ProxyService::CreateFixed(proxy)); 185 context_storage_.set_proxy_service(net::ProxyService::CreateFixed(proxy));
186 Init(); 186 Init();
187 } 187 }
188 virtual ~TestURLRequestContextWithProxy() {} 188 virtual ~TestURLRequestContextWithProxy() {}
189 }; 189 };
190 190
191 class TestSocketStreamNetworkDelegate : public TestNetworkDelegate {
192 public:
193 TestSocketStreamNetworkDelegate()
194 : before_connect_result_(net::OK) {}
195 virtual ~TestSocketStreamNetworkDelegate() {}
196
197 virtual int OnBeforeSocketStreamConnect(
198 net::SocketStream* stream,
199 const net::CompletionCallback& callback) OVERRIDE {
200 return before_connect_result_;
201 }
202
203 void SetBeforeConnectResult(int result) {
204 before_connect_result_ = result;
205 }
206
207 private:
208 int before_connect_result_;
209 };
210
191 } // namespace 211 } // namespace
192 212
193 namespace net { 213 namespace net {
194 214
195 class SocketStreamTest : public PlatformTest { 215 class SocketStreamTest : public PlatformTest {
196 public: 216 public:
197 virtual ~SocketStreamTest() {} 217 virtual ~SocketStreamTest() {}
198 virtual void SetUp() { 218 virtual void SetUp() {
199 mock_socket_factory_.reset(); 219 mock_socket_factory_.reset();
200 handshake_request_ = kWebSocketHandshakeRequest; 220 handshake_request_ = kWebSocketHandshakeRequest;
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 ASSERT_EQ(4U, events.size()); 659 ASSERT_EQ(4U, events.size());
640 660
641 EXPECT_EQ(SocketStreamEvent::EVENT_START_OPEN_CONNECTION, 661 EXPECT_EQ(SocketStreamEvent::EVENT_START_OPEN_CONNECTION,
642 events[0].event_type); 662 events[0].event_type);
643 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type); 663 EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type);
644 EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[2].event_type); 664 EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[2].event_type);
645 EXPECT_EQ(net::ERR_ABORTED, events[2].error_code); 665 EXPECT_EQ(net::ERR_ABORTED, events[2].error_code);
646 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[3].event_type); 666 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[3].event_type);
647 } 667 }
648 668
669 TEST_F(SocketStreamTest, BeforeConnectFailed) {
670 TestCompletionCallback test_callback;
671
672 scoped_ptr<SocketStreamEventRecorder> delegate(
673 new SocketStreamEventRecorder(test_callback.callback()));
674
675 TestURLRequestContext context;
676 TestSocketStreamNetworkDelegate network_delegate;
677 network_delegate.SetBeforeConnectResult(ERR_ACCESS_DENIED);
678 context.set_network_delegate(&network_delegate);
679
680 scoped_refptr<SocketStream> socket_stream(
681 new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
682
683 socket_stream->set_context(&context);
684
685 socket_stream->Connect();
686
687 test_callback.WaitForResult();
688
689 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents();
690 ASSERT_EQ(2U, events.size());
691
692 EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[0].event_type);
693 EXPECT_EQ(net::ERR_ACCESS_DENIED, events[0].error_code);
694 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[1].event_type);
695 }
696
649 } // namespace net 697 } // namespace net
OLDNEW
« no previous file with comments | « net/socket_stream/socket_stream.cc ('k') | net/url_request/url_request_context_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698