| 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 <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/message_loop/message_loop_proxy.h" | |
| 11 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 13 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 15 #include "chrome/test/chromedriver/net/sync_websocket_impl.h" | 14 #include "chrome/test/chromedriver/net/sync_websocket_impl.h" |
| 16 #include "chrome/test/chromedriver/net/test_http_server.h" | 15 #include "chrome/test/chromedriver/net/test_http_server.h" |
| 17 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 16 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 class SyncWebSocketImplTest : public testing::Test { | 22 class SyncWebSocketImplTest : public testing::Test { |
| 24 protected: | 23 protected: |
| 25 SyncWebSocketImplTest() | 24 SyncWebSocketImplTest() |
| 26 : client_thread_("ClientThread"), | 25 : client_thread_("ClientThread"), |
| 27 long_timeout_(base::TimeDelta::FromMinutes(1)) {} | 26 long_timeout_(base::TimeDelta::FromMinutes(1)) {} |
| 28 ~SyncWebSocketImplTest() override {} | 27 ~SyncWebSocketImplTest() override {} |
| 29 | 28 |
| 30 void SetUp() override { | 29 void SetUp() override { |
| 31 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 30 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 32 ASSERT_TRUE(client_thread_.StartWithOptions(options)); | 31 ASSERT_TRUE(client_thread_.StartWithOptions(options)); |
| 33 context_getter_ = new URLRequestContextGetter( | 32 context_getter_ = new URLRequestContextGetter(client_thread_.task_runner()); |
| 34 client_thread_.message_loop_proxy()); | |
| 35 ASSERT_TRUE(server_.Start()); | 33 ASSERT_TRUE(server_.Start()); |
| 36 } | 34 } |
| 37 | 35 |
| 38 void TearDown() override { server_.Stop(); } | 36 void TearDown() override { server_.Stop(); } |
| 39 | 37 |
| 40 base::Thread client_thread_; | 38 base::Thread client_thread_; |
| 41 TestHttpServer server_; | 39 TestHttpServer server_; |
| 42 scoped_refptr<URLRequestContextGetter> context_getter_; | 40 scoped_refptr<URLRequestContextGetter> context_getter_; |
| 43 const base::TimeDelta long_timeout_; | 41 const base::TimeDelta long_timeout_; |
| 44 }; | 42 }; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 ASSERT_TRUE(sock.Connect(server_.web_socket_url())); | 153 ASSERT_TRUE(sock.Connect(server_.web_socket_url())); |
| 156 ASSERT_FALSE(sock.HasNextMessage()); | 154 ASSERT_FALSE(sock.HasNextMessage()); |
| 157 ASSERT_TRUE(sock.Send("3")); | 155 ASSERT_TRUE(sock.Send("3")); |
| 158 std::string message; | 156 std::string message; |
| 159 ASSERT_EQ( | 157 ASSERT_EQ( |
| 160 SyncWebSocket::kOk, | 158 SyncWebSocket::kOk, |
| 161 sock.ReceiveNextMessage(&message, long_timeout_)); | 159 sock.ReceiveNextMessage(&message, long_timeout_)); |
| 162 ASSERT_STREQ("3", message.c_str()); | 160 ASSERT_STREQ("3", message.c_str()); |
| 163 ASSERT_FALSE(sock.HasNextMessage()); | 161 ASSERT_FALSE(sock.HasNextMessage()); |
| 164 } | 162 } |
| OLD | NEW |