OLD | NEW |
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 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 delegate->set_socket_stream(socket_stream); | 955 delegate->set_socket_stream(socket_stream); |
956 // The delegate pointer will become invalid during the test. Set it to NULL to | 956 // The delegate pointer will become invalid during the test. Set it to NULL to |
957 // avoid holding a dangling pointer. | 957 // avoid holding a dangling pointer. |
958 delegate = NULL; | 958 delegate = NULL; |
959 | 959 |
960 socket_stream->Connect(); | 960 socket_stream->Connect(); |
961 | 961 |
962 EXPECT_EQ(OK, test_callback.WaitForResult()); | 962 EXPECT_EQ(OK, test_callback.WaitForResult()); |
963 } | 963 } |
964 | 964 |
965 // A test for the WeakPtr workaround patch which should be deleted | |
966 // in the future. | |
967 TEST_F(SocketStreamTest, ContextDestroyedBeforeDoBeforeConnect) { | |
968 TestCompletionCallback test_callback; | |
969 | |
970 scoped_ptr<SocketStreamEventRecorder> delegate( | |
971 new SocketStreamEventRecorder(test_callback.callback())); | |
972 | |
973 scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext); | |
974 TestSocketStreamNetworkDelegate network_delegate; | |
975 network_delegate.SetBeforeConnectResult(OK); | |
976 context->set_network_delegate(&network_delegate); | |
977 | |
978 scoped_refptr<SocketStream> socket_stream( | |
979 new SocketStream(GURL("ws://example.com/demo"), delegate.get())); | |
980 | |
981 socket_stream->set_context(context.get()); | |
982 | |
983 socket_stream->Connect(); | |
984 context.reset(); | |
985 | |
986 ASSERT_EQ(0U, delegate->GetSeenEvents().size()); | |
987 | |
988 test_callback.WaitForResult(); | |
989 | |
990 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); | |
991 ASSERT_EQ(1U, events.size()); | |
992 | |
993 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type); | |
994 } | |
995 | |
996 // A test for the WeakPtr workaround patch which should be deleted | |
997 // in the future. | |
998 TEST_F(SocketStreamTest, SocketStreamResetBeforeDoBeforeConnect) { | |
999 TestCompletionCallback test_callback; | |
1000 | |
1001 scoped_ptr<SocketStreamEventRecorder> delegate( | |
1002 new SocketStreamEventRecorder(test_callback.callback())); | |
1003 | |
1004 scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext); | |
1005 TestSocketStreamNetworkDelegate network_delegate; | |
1006 network_delegate.SetBeforeConnectResult(OK); | |
1007 context->set_network_delegate(&network_delegate); | |
1008 | |
1009 scoped_refptr<SocketStream> socket_stream( | |
1010 new SocketStream(GURL("ws://example.com/demo"), delegate.get())); | |
1011 | |
1012 socket_stream->set_context(context.get()); | |
1013 | |
1014 socket_stream->Connect(); | |
1015 socket_stream = NULL; | |
1016 context.reset(); | |
1017 | |
1018 ASSERT_EQ(0U, delegate->GetSeenEvents().size()); | |
1019 test_callback.WaitForResult(); | |
1020 | |
1021 const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); | |
1022 ASSERT_EQ(1U, events.size()); | |
1023 | |
1024 EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type); | |
1025 } | |
1026 | |
1027 } // namespace net | 965 } // namespace net |
OLD | NEW |