OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 // TODO(ellyjones): Remove once http://crbug.com/523296 is fixed. | 6 // TODO(ellyjones): Remove once http://crbug.com/523296 is fixed. |
7 #if defined(OS_IOS) && !TARGET_IPHONE_SIMULATOR | 7 #if defined(OS_IOS) && !TARGET_IPHONE_SIMULATOR |
8 #include "base/ios/ios_util.h" | 8 #include "base/ios/ios_util.h" |
9 #endif | 9 #endif |
10 #include "base/sync_socket.h" | 10 #include "base/sync_socket.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 ASSERT_TRUE(socket_b->Close()); | 82 ASSERT_TRUE(socket_b->Close()); |
83 } | 83 } |
84 | 84 |
85 template <class SocketType> | 85 template <class SocketType> |
86 void NormalSendReceivePeek() { | 86 void NormalSendReceivePeek() { |
87 SocketType socket_a, socket_b; | 87 SocketType socket_a, socket_b; |
88 ASSERT_TRUE(SocketType::CreatePair(&socket_a, &socket_b)); | 88 ASSERT_TRUE(SocketType::CreatePair(&socket_a, &socket_b)); |
89 SendReceivePeek(&socket_a, &socket_b); | 89 SendReceivePeek(&socket_a, &socket_b); |
90 } | 90 } |
91 | 91 |
| 92 template <class SocketType> |
| 93 void ClonedSendReceivePeek() { |
| 94 SocketType socket_a, socket_b; |
| 95 ASSERT_TRUE(SocketType::CreatePair(&socket_a, &socket_b)); |
| 96 |
| 97 // Create new SyncSockets from the paired handles. |
| 98 SocketType socket_c(socket_a.handle()), socket_d(socket_b.handle()); |
| 99 SendReceivePeek(&socket_c, &socket_d); |
| 100 } |
| 101 |
92 } // namespace | 102 } // namespace |
93 | 103 |
94 TEST(SyncSocket, NormalSendReceivePeek) { | 104 TEST(SyncSocket, NormalSendReceivePeek) { |
95 NormalSendReceivePeek<base::SyncSocket>(); | 105 NormalSendReceivePeek<base::SyncSocket>(); |
96 } | 106 } |
97 | 107 |
| 108 TEST(SyncSocket, ClonedSendReceivePeek) { |
| 109 ClonedSendReceivePeek<base::SyncSocket>(); |
| 110 } |
| 111 |
98 TEST(CancelableSyncSocket, NormalSendReceivePeek) { | 112 TEST(CancelableSyncSocket, NormalSendReceivePeek) { |
99 NormalSendReceivePeek<base::CancelableSyncSocket>(); | 113 NormalSendReceivePeek<base::CancelableSyncSocket>(); |
100 } | 114 } |
101 | 115 |
| 116 TEST(CancelableSyncSocket, ClonedSendReceivePeek) { |
| 117 ClonedSendReceivePeek<base::CancelableSyncSocket>(); |
| 118 } |
| 119 |
102 TEST(CancelableSyncSocket, CancelReceiveShutdown) { | 120 TEST(CancelableSyncSocket, CancelReceiveShutdown) { |
103 // TODO(ellyjones): This test fails on iOS 7 devices. http://crbug.com/523296 | 121 // TODO(ellyjones): This test fails on iOS 7 devices. http://crbug.com/523296 |
104 #if defined(OS_IOS) && !TARGET_IPHONE_SIMULATOR | 122 #if defined(OS_IOS) && !TARGET_IPHONE_SIMULATOR |
105 if (!base::ios::IsRunningOnIOS8OrLater()) | 123 if (!base::ios::IsRunningOnIOS8OrLater()) |
106 return; | 124 return; |
107 #endif | 125 #endif |
108 base::CancelableSyncSocket socket_a, socket_b; | 126 base::CancelableSyncSocket socket_a, socket_b; |
109 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&socket_a, &socket_b)); | 127 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&socket_a, &socket_b)); |
110 | 128 |
111 base::TimeTicks start = base::TimeTicks::Now(); | 129 base::TimeTicks start = base::TimeTicks::Now(); |
112 HangingReceiveThread thread(&socket_b); | 130 HangingReceiveThread thread(&socket_b); |
113 ASSERT_TRUE(socket_b.Shutdown()); | 131 ASSERT_TRUE(socket_b.Shutdown()); |
114 thread.Stop(); | 132 thread.Stop(); |
115 | 133 |
116 // Ensure the receive didn't just timeout. | 134 // Ensure the receive didn't just timeout. |
117 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(), | 135 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(), |
118 kReceiveTimeoutInMilliseconds); | 136 kReceiveTimeoutInMilliseconds); |
119 | 137 |
120 ASSERT_TRUE(socket_a.Close()); | 138 ASSERT_TRUE(socket_a.Close()); |
121 ASSERT_TRUE(socket_b.Close()); | 139 ASSERT_TRUE(socket_b.Close()); |
122 } | 140 } |
OLD | NEW |