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

Side by Side Diff: base/sync_socket_unittest.cc

Issue 1350493002: Check for CloseHandle failures even when not debugging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK to CHECK Created 5 years, 3 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 unified diff | Download patch
OLDNEW
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
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
102 } // namespace 92 } // namespace
103 93
104 TEST(SyncSocket, NormalSendReceivePeek) { 94 TEST(SyncSocket, NormalSendReceivePeek) {
105 NormalSendReceivePeek<base::SyncSocket>(); 95 NormalSendReceivePeek<base::SyncSocket>();
106 } 96 }
107 97
108 TEST(SyncSocket, ClonedSendReceivePeek) {
109 ClonedSendReceivePeek<base::SyncSocket>();
110 }
111
112 TEST(CancelableSyncSocket, NormalSendReceivePeek) { 98 TEST(CancelableSyncSocket, NormalSendReceivePeek) {
113 NormalSendReceivePeek<base::CancelableSyncSocket>(); 99 NormalSendReceivePeek<base::CancelableSyncSocket>();
114 } 100 }
115 101
116 TEST(CancelableSyncSocket, ClonedSendReceivePeek) {
117 ClonedSendReceivePeek<base::CancelableSyncSocket>();
118 }
119
120 TEST(CancelableSyncSocket, CancelReceiveShutdown) { 102 TEST(CancelableSyncSocket, CancelReceiveShutdown) {
121 // TODO(ellyjones): This test fails on iOS 7 devices. http://crbug.com/523296 103 // TODO(ellyjones): This test fails on iOS 7 devices. http://crbug.com/523296
122 #if defined(OS_IOS) && !TARGET_IPHONE_SIMULATOR 104 #if defined(OS_IOS) && !TARGET_IPHONE_SIMULATOR
123 if (!base::ios::IsRunningOnIOS8OrLater()) 105 if (!base::ios::IsRunningOnIOS8OrLater())
124 return; 106 return;
125 #endif 107 #endif
126 base::CancelableSyncSocket socket_a, socket_b; 108 base::CancelableSyncSocket socket_a, socket_b;
127 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&socket_a, &socket_b)); 109 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&socket_a, &socket_b));
128 110
129 base::TimeTicks start = base::TimeTicks::Now(); 111 base::TimeTicks start = base::TimeTicks::Now();
130 HangingReceiveThread thread(&socket_b); 112 HangingReceiveThread thread(&socket_b);
131 ASSERT_TRUE(socket_b.Shutdown()); 113 ASSERT_TRUE(socket_b.Shutdown());
132 thread.Stop(); 114 thread.Stop();
133 115
134 // Ensure the receive didn't just timeout. 116 // Ensure the receive didn't just timeout.
135 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(), 117 ASSERT_LT((base::TimeTicks::Now() - start).InMilliseconds(),
136 kReceiveTimeoutInMilliseconds); 118 kReceiveTimeoutInMilliseconds);
137 119
138 ASSERT_TRUE(socket_a.Close()); 120 ASSERT_TRUE(socket_a.Close());
139 ASSERT_TRUE(socket_b.Close()); 121 ASSERT_TRUE(socket_b.Close());
140 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698