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

Unified Diff: net/socket_stream/socket_stream_unittest.cc

Issue 16874005: Merge r205158 (SocketStream uses a weak ptr to URLRequestContext) (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1500/src/
Patch Set: Created 7 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_job.h ('k') | net/url_request/url_request_context.h » ('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
===================================================================
--- net/socket_stream/socket_stream_unittest.cc (revision 207753)
+++ net/socket_stream/socket_stream_unittest.cc (working copy)
@@ -924,4 +924,66 @@
EXPECT_EQ(OK, test_callback.WaitForResult());
}
+// A test for the WeakPtr workaround patch which should be deleted
+// in the future.
+TEST_F(SocketStreamTest, ContextDestroyedBeforeDoBeforeConnect) {
+ TestCompletionCallback test_callback;
+
+ scoped_ptr<SocketStreamEventRecorder> delegate(
+ new SocketStreamEventRecorder(test_callback.callback()));
+
+ scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext);
+ TestSocketStreamNetworkDelegate network_delegate;
+ network_delegate.SetBeforeConnectResult(OK);
+ 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.get());
+
+ socket_stream->Connect();
+ context.reset();
+
+ ASSERT_EQ(0U, delegate->GetSeenEvents().size());
+
+ test_callback.WaitForResult();
+
+ const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents();
+ ASSERT_EQ(1U, events.size());
+
+ EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type);
+}
+
+// A test for the WeakPtr workaround patch which should be deleted
+// in the future.
+TEST_F(SocketStreamTest, SocketStreamResetBeforeDoBeforeConnect) {
+ TestCompletionCallback test_callback;
+
+ scoped_ptr<SocketStreamEventRecorder> delegate(
+ new SocketStreamEventRecorder(test_callback.callback()));
+
+ scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext);
+ TestSocketStreamNetworkDelegate network_delegate;
+ network_delegate.SetBeforeConnectResult(OK);
+ 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.get());
+
+ socket_stream->Connect();
+ socket_stream = NULL;
+ context.reset();
+
+ ASSERT_EQ(0U, delegate->GetSeenEvents().size());
+ test_callback.WaitForResult();
+
+ const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents();
+ ASSERT_EQ(1U, events.size());
+
+ EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type);
+}
+
} // namespace net
« no previous file with comments | « net/socket_stream/socket_stream_job.h ('k') | net/url_request/url_request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698