| 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 917   delegate->set_socket_stream(socket_stream); | 917   delegate->set_socket_stream(socket_stream); | 
| 918   // The delegate pointer will become invalid during the test. Set it to NULL to | 918   // The delegate pointer will become invalid during the test. Set it to NULL to | 
| 919   // avoid holding a dangling pointer. | 919   // avoid holding a dangling pointer. | 
| 920   delegate = NULL; | 920   delegate = NULL; | 
| 921 | 921 | 
| 922   socket_stream->Connect(); | 922   socket_stream->Connect(); | 
| 923 | 923 | 
| 924   EXPECT_EQ(OK, test_callback.WaitForResult()); | 924   EXPECT_EQ(OK, test_callback.WaitForResult()); | 
| 925 } | 925 } | 
| 926 | 926 | 
| 927 // A test for the WeakPtr workaround patch which should be deleted |  | 
| 928 // in the future. |  | 
| 929 TEST_F(SocketStreamTest, ContextDestroyedBeforeDoBeforeConnect) { |  | 
| 930   TestCompletionCallback test_callback; |  | 
| 931 |  | 
| 932   scoped_ptr<SocketStreamEventRecorder> delegate( |  | 
| 933       new SocketStreamEventRecorder(test_callback.callback())); |  | 
| 934 |  | 
| 935   scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext); |  | 
| 936   TestSocketStreamNetworkDelegate network_delegate; |  | 
| 937   network_delegate.SetBeforeConnectResult(OK); |  | 
| 938   context->set_network_delegate(&network_delegate); |  | 
| 939 |  | 
| 940   scoped_refptr<SocketStream> socket_stream( |  | 
| 941       new SocketStream(GURL("ws://example.com/demo"), delegate.get())); |  | 
| 942 |  | 
| 943   socket_stream->set_context(context.get()); |  | 
| 944 |  | 
| 945   socket_stream->Connect(); |  | 
| 946   context.reset(); |  | 
| 947 |  | 
| 948   ASSERT_EQ(0U, delegate->GetSeenEvents().size()); |  | 
| 949 |  | 
| 950   test_callback.WaitForResult(); |  | 
| 951 |  | 
| 952   const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); |  | 
| 953   ASSERT_EQ(1U, events.size()); |  | 
| 954 |  | 
| 955   EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type); |  | 
| 956 } |  | 
| 957 |  | 
| 958 // A test for the WeakPtr workaround patch which should be deleted |  | 
| 959 // in the future. |  | 
| 960 TEST_F(SocketStreamTest, SocketStreamResetBeforeDoBeforeConnect) { |  | 
| 961   TestCompletionCallback test_callback; |  | 
| 962 |  | 
| 963   scoped_ptr<SocketStreamEventRecorder> delegate( |  | 
| 964       new SocketStreamEventRecorder(test_callback.callback())); |  | 
| 965 |  | 
| 966   scoped_ptr<TestURLRequestContext> context(new TestURLRequestContext); |  | 
| 967   TestSocketStreamNetworkDelegate network_delegate; |  | 
| 968   network_delegate.SetBeforeConnectResult(OK); |  | 
| 969   context->set_network_delegate(&network_delegate); |  | 
| 970 |  | 
| 971   scoped_refptr<SocketStream> socket_stream( |  | 
| 972       new SocketStream(GURL("ws://example.com/demo"), delegate.get())); |  | 
| 973 |  | 
| 974   socket_stream->set_context(context.get()); |  | 
| 975 |  | 
| 976   socket_stream->Connect(); |  | 
| 977   socket_stream = NULL; |  | 
| 978   context.reset(); |  | 
| 979 |  | 
| 980   ASSERT_EQ(0U, delegate->GetSeenEvents().size()); |  | 
| 981   test_callback.WaitForResult(); |  | 
| 982 |  | 
| 983   const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents(); |  | 
| 984   ASSERT_EQ(1U, events.size()); |  | 
| 985 |  | 
| 986   EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[0].event_type); |  | 
| 987 } |  | 
| 988 |  | 
| 989 }  // namespace net | 927 }  // namespace net | 
| OLD | NEW | 
|---|