| 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 <stddef.h> | 5 #include <stddef.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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 scoped_ptr<WebSocket> CreateWebSocket(const GURL& url, | 90 scoped_ptr<WebSocket> CreateWebSocket(const GURL& url, |
| 91 WebSocketListener* listener) { | 91 WebSocketListener* listener) { |
| 92 int error; | 92 int error; |
| 93 scoped_ptr<WebSocket> sock(new WebSocket(url, listener)); | 93 scoped_ptr<WebSocket> sock(new WebSocket(url, listener)); |
| 94 base::RunLoop run_loop; | 94 base::RunLoop run_loop; |
| 95 sock->Connect(base::Bind(&OnConnectFinished, &run_loop, &error)); | 95 sock->Connect(base::Bind(&OnConnectFinished, &run_loop, &error)); |
| 96 loop_.task_runner()->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), | 96 loop_.task_runner()->PostDelayedTask(FROM_HERE, run_loop.QuitClosure(), |
| 97 base::TimeDelta::FromSeconds(10)); | 97 base::TimeDelta::FromSeconds(10)); |
| 98 run_loop.Run(); | 98 run_loop.Run(); |
| 99 if (error == net::OK) | 99 if (error == net::OK) |
| 100 return sock.Pass(); | 100 return sock; |
| 101 return scoped_ptr<WebSocket>(); | 101 return scoped_ptr<WebSocket>(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 scoped_ptr<WebSocket> CreateConnectedWebSocket(WebSocketListener* listener) { | 104 scoped_ptr<WebSocket> CreateConnectedWebSocket(WebSocketListener* listener) { |
| 105 return CreateWebSocket(server_.web_socket_url(), listener); | 105 return CreateWebSocket(server_.web_socket_url(), listener); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void SendReceive(const std::vector<std::string>& messages) { | 108 void SendReceive(const std::vector<std::string>& messages) { |
| 109 Listener listener(messages); | 109 Listener listener(messages); |
| 110 scoped_ptr<WebSocket> sock(CreateConnectedWebSocket(&listener)); | 110 scoped_ptr<WebSocket> sock(CreateConnectedWebSocket(&listener)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 SendReceive(messages); | 193 SendReceive(messages); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(WebSocketTest, SendReceiveMultiple) { | 196 TEST_F(WebSocketTest, SendReceiveMultiple) { |
| 197 std::vector<std::string> messages; | 197 std::vector<std::string> messages; |
| 198 messages.push_back("1"); | 198 messages.push_back("1"); |
| 199 messages.push_back("2"); | 199 messages.push_back("2"); |
| 200 messages.push_back("3"); | 200 messages.push_back("3"); |
| 201 SendReceive(messages); | 201 SendReceive(messages); |
| 202 } | 202 } |
| OLD | NEW |