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

Side by Side Diff: chrome/test/chromedriver/net/sync_websocket_impl_unittest.cc

Issue 2021393004: Migrate WaitableEvent to enum-based constructor in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@WEvent_enums
Patch Set: Split out custom changes to thread_watcher_unittest.cc Created 4 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 unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 SyncWebSocket::kOk, 69 SyncWebSocket::kOk,
70 sock.ReceiveNextMessage(&message, long_timeout())); 70 sock.ReceiveNextMessage(&message, long_timeout()));
71 ASSERT_STREQ("hi", message.c_str()); 71 ASSERT_STREQ("hi", message.c_str());
72 } 72 }
73 73
74 TEST_F(SyncWebSocketImplTest, SendReceiveTimeout) { 74 TEST_F(SyncWebSocketImplTest, SendReceiveTimeout) {
75 SyncWebSocketImpl sock(context_getter_.get()); 75 SyncWebSocketImpl sock(context_getter_.get());
76 76
77 // The server might reply too quickly so that the response will be received 77 // The server might reply too quickly so that the response will be received
78 // before we call ReceiveNextMessage; we must prevent it. 78 // before we call ReceiveNextMessage; we must prevent it.
79 base::WaitableEvent server_reply_allowed(false, false); 79 base::WaitableEvent server_reply_allowed(
80 base::WaitableEvent::ResetPolicy::AUTOMATIC,
81 base::WaitableEvent::InitialState::NOT_SIGNALED);
80 server_.SetMessageCallback(base::Bind( 82 server_.SetMessageCallback(base::Bind(
81 &base::WaitableEvent::Wait, base::Unretained(&server_reply_allowed))); 83 &base::WaitableEvent::Wait, base::Unretained(&server_reply_allowed)));
82 84
83 ASSERT_TRUE(sock.Connect(server_.web_socket_url())); 85 ASSERT_TRUE(sock.Connect(server_.web_socket_url()));
84 ASSERT_TRUE(sock.Send("hi")); 86 ASSERT_TRUE(sock.Send("hi"));
85 std::string message; 87 std::string message;
86 ASSERT_EQ( 88 ASSERT_EQ(
87 SyncWebSocket::kTimeout, 89 SyncWebSocket::kTimeout,
88 sock.ReceiveNextMessage( 90 sock.ReceiveNextMessage(
89 &message, Timeout(base::TimeDelta()))); 91 &message, Timeout(base::TimeDelta())));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ASSERT_TRUE(sock.Connect(server_.web_socket_url())); 170 ASSERT_TRUE(sock.Connect(server_.web_socket_url()));
169 ASSERT_FALSE(sock.HasNextMessage()); 171 ASSERT_FALSE(sock.HasNextMessage());
170 ASSERT_TRUE(sock.Send("3")); 172 ASSERT_TRUE(sock.Send("3"));
171 std::string message; 173 std::string message;
172 ASSERT_EQ( 174 ASSERT_EQ(
173 SyncWebSocket::kOk, 175 SyncWebSocket::kOk,
174 sock.ReceiveNextMessage(&message, long_timeout())); 176 sock.ReceiveNextMessage(&message, long_timeout()));
175 ASSERT_STREQ("3", message.c_str()); 177 ASSERT_STREQ("3", message.c_str());
176 ASSERT_FALSE(sock.HasNextMessage()); 178 ASSERT_FALSE(sock.HasNextMessage());
177 } 179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698