| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "content/browser/websockets/websocket_manager.h" | 9 #include "content/browser/websockets/websocket_manager.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 #include "url/origin.h" | 14 #include "url/origin.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // This number is unlikely to occur by chance. | 19 // This number is unlikely to occur by chance. |
| 20 static const int kMagicRenderProcessId = 506116062; | 20 static const int kMagicRenderProcessId = 506116062; |
| 21 | 21 |
| 22 class TestWebSocketImpl : public WebSocketImpl { | 22 class TestWebSocketImpl : public WebSocketImpl { |
| 23 public: | 23 public: |
| 24 TestWebSocketImpl(Delegate* delegate, | 24 TestWebSocketImpl(Delegate* delegate, |
| 25 blink::mojom::WebSocketRequest request, | 25 blink::mojom::WebSocketRequest request, |
| 26 int process_id, |
| 26 int frame_id, | 27 int frame_id, |
| 27 base::TimeDelta delay) | 28 base::TimeDelta delay) |
| 28 : WebSocketImpl(delegate, std::move(request), frame_id, delay) {} | 29 : WebSocketImpl(delegate, |
| 30 std::move(request), |
| 31 process_id, |
| 32 frame_id, |
| 33 delay) {} |
| 29 | 34 |
| 30 base::TimeDelta delay() const { return delay_; } | 35 base::TimeDelta delay() const { return delay_; } |
| 31 | 36 |
| 32 void SimulateConnectionError() { | 37 void SimulateConnectionError() { |
| 33 OnConnectionError(); | 38 OnConnectionError(); |
| 34 } | 39 } |
| 35 }; | 40 }; |
| 36 | 41 |
| 37 class TestWebSocketManager : public WebSocketManager { | 42 class TestWebSocketManager : public WebSocketManager { |
| 38 public: | 43 public: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 num_previous_succeeded_connections_; | 59 num_previous_succeeded_connections_; |
| 55 } | 60 } |
| 56 | 61 |
| 57 void DoCreateWebSocket(blink::mojom::WebSocketRequest request) { | 62 void DoCreateWebSocket(blink::mojom::WebSocketRequest request) { |
| 58 WebSocketManager::DoCreateWebSocket(MSG_ROUTING_NONE, std::move(request)); | 63 WebSocketManager::DoCreateWebSocket(MSG_ROUTING_NONE, std::move(request)); |
| 59 } | 64 } |
| 60 | 65 |
| 61 private: | 66 private: |
| 62 WebSocketImpl* CreateWebSocketImpl(WebSocketImpl::Delegate* delegate, | 67 WebSocketImpl* CreateWebSocketImpl(WebSocketImpl::Delegate* delegate, |
| 63 blink::mojom::WebSocketRequest request, | 68 blink::mojom::WebSocketRequest request, |
| 69 int process_id, |
| 64 int frame_id, | 70 int frame_id, |
| 65 base::TimeDelta delay) override { | 71 base::TimeDelta delay) override { |
| 66 TestWebSocketImpl* impl = | 72 TestWebSocketImpl* impl = new TestWebSocketImpl( |
| 67 new TestWebSocketImpl(delegate, std::move(request), frame_id, delay); | 73 delegate, std::move(request), process_id, frame_id, delay); |
| 68 // We keep a vector of sockets here to track their creation order. | 74 // We keep a vector of sockets here to track their creation order. |
| 69 sockets_.push_back(impl); | 75 sockets_.push_back(impl); |
| 70 return impl; | 76 return impl; |
| 71 } | 77 } |
| 72 | 78 |
| 73 void OnLostConnectionToClient(WebSocketImpl* impl) override { | 79 void OnLostConnectionToClient(WebSocketImpl* impl) override { |
| 74 auto it = std::find(sockets_.begin(), sockets_.end(), | 80 auto it = std::find(sockets_.begin(), sockets_.end(), |
| 75 static_cast<TestWebSocketImpl*>(impl)); | 81 static_cast<TestWebSocketImpl*>(impl)); |
| 76 ASSERT_TRUE(it != sockets_.end()); | 82 ASSERT_TRUE(it != sockets_.end()); |
| 77 sockets_.erase(it); | 83 sockets_.erase(it); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 239 |
| 234 AddMultipleChannels(1); | 240 AddMultipleChannels(1); |
| 235 | 241 |
| 236 EXPECT_EQ(1, websocket_manager()->num_pending_connections()); | 242 EXPECT_EQ(1, websocket_manager()->num_pending_connections()); |
| 237 EXPECT_EQ(255, websocket_manager()->num_failed_connections()); | 243 EXPECT_EQ(255, websocket_manager()->num_failed_connections()); |
| 238 EXPECT_EQ(0, websocket_manager()->num_succeeded_connections()); | 244 EXPECT_EQ(0, websocket_manager()->num_succeeded_connections()); |
| 239 } | 245 } |
| 240 | 246 |
| 241 } // namespace | 247 } // namespace |
| 242 } // namespace content | 248 } // namespace content |
| OLD | NEW |