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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket_stream/socket_stream_unittest.cc
diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc
index 76bb379d1d9f9f6e924aa3f10a1e191152316956..cc93035c7212523fe178f8036925d1072d51d64d 100644
--- a/net/socket_stream/socket_stream_unittest.cc
+++ b/net/socket_stream/socket_stream_unittest.cc
@@ -188,6 +188,26 @@ class TestURLRequestContextWithProxy : public TestURLRequestContext {
virtual ~TestURLRequestContextWithProxy() {}
};
+class TestSocketStreamNetworkDelegate : public TestNetworkDelegate {
+ public:
+ TestSocketStreamNetworkDelegate()
+ : before_connect_result_(net::OK) {}
+ virtual ~TestSocketStreamNetworkDelegate() {}
+
+ virtual int OnBeforeSocketStreamConnect(
+ net::SocketStream* stream,
+ const net::CompletionCallback& callback) OVERRIDE {
+ return before_connect_result_;
+ }
+
+ void SetBeforeConnectResult(int result) {
+ before_connect_result_ = result;
+ }
+
+ private:
+ int before_connect_result_;
+};
+
} // namespace
namespace net {
@@ -646,4 +666,32 @@ TEST_F(SocketStreamTest, SecureProxyConnect) {
EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[3].event_type);
}
+TEST_F(SocketStreamTest, BeforeConnectFailed) {
+ TestCompletionCallback test_callback;
+
+ scoped_ptr<SocketStreamEventRecorder> delegate(
+ new SocketStreamEventRecorder(test_callback.callback()));
+
+ TestURLRequestContext context;
+ TestSocketStreamNetworkDelegate network_delegate;
+ network_delegate.SetBeforeConnectResult(ERR_ACCESS_DENIED);
+ context.set_network_delegate(&network_delegate);
+
+ scoped_refptr<SocketStream> socket_stream(
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
+
+ socket_stream->Connect();
+
+ test_callback.WaitForResult();
+
+ const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents();
+ ASSERT_EQ(2U, events.size());
+
+ EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[0].event_type);
+ EXPECT_EQ(net::ERR_ACCESS_DENIED, events[0].error_code);
+ EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[1].event_type);
+}
+
} // namespace net
« 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