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 "content/browser/renderer_host/websocket_dispatcher_host.h" | 5 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 static const int kMagicRenderProcessId = 506116062; | 26 static const int kMagicRenderProcessId = 506116062; |
27 | 27 |
28 class WebSocketDispatcherHostTest; | 28 class WebSocketDispatcherHostTest; |
29 | 29 |
30 // A mock of WebsocketHost which records received messages. | 30 // A mock of WebsocketHost which records received messages. |
31 class MockWebSocketHost : public WebSocketHost { | 31 class MockWebSocketHost : public WebSocketHost { |
32 public: | 32 public: |
33 MockWebSocketHost(int routing_id, | 33 MockWebSocketHost(int routing_id, |
34 WebSocketDispatcherHost* dispatcher, | 34 WebSocketDispatcherHost* dispatcher, |
35 net::URLRequestContext* url_request_context, | 35 net::URLRequestContext* url_request_context, |
| 36 int delay_in_ms, |
36 WebSocketDispatcherHostTest* owner); | 37 WebSocketDispatcherHostTest* owner); |
37 | 38 |
38 ~MockWebSocketHost() override {} | 39 ~MockWebSocketHost() override {} |
39 | 40 |
40 bool OnMessageReceived(const IPC::Message& message) override { | 41 bool OnMessageReceived(const IPC::Message& message) override { |
41 received_messages_.push_back(message); | 42 received_messages_.push_back(message); |
42 return true; | 43 return true; |
43 } | 44 } |
44 | 45 |
45 void GoAway() override; | 46 void GoAway() override; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 std::vector<MockWebSocketHost*> mock_hosts_; | 83 std::vector<MockWebSocketHost*> mock_hosts_; |
83 std::vector<int> gone_hosts_; | 84 std::vector<int> gone_hosts_; |
84 | 85 |
85 base::WeakPtrFactory<WebSocketDispatcherHostTest> weak_ptr_factory_; | 86 base::WeakPtrFactory<WebSocketDispatcherHostTest> weak_ptr_factory_; |
86 | 87 |
87 private: | 88 private: |
88 net::URLRequestContext* OnGetRequestContext() { | 89 net::URLRequestContext* OnGetRequestContext() { |
89 return NULL; | 90 return NULL; |
90 } | 91 } |
91 | 92 |
92 WebSocketHost* CreateWebSocketHost(int routing_id) { | 93 WebSocketHost* CreateWebSocketHost(int routing_id, int delay_in_ms) { |
93 MockWebSocketHost* host = | 94 MockWebSocketHost* host = new MockWebSocketHost( |
94 new MockWebSocketHost(routing_id, dispatcher_host_.get(), NULL, this); | 95 routing_id, dispatcher_host_.get(), NULL, delay_in_ms, this); |
95 mock_hosts_.push_back(host); | 96 mock_hosts_.push_back(host); |
96 return host; | 97 return host; |
97 } | 98 } |
98 }; | 99 }; |
99 | 100 |
100 MockWebSocketHost::MockWebSocketHost( | 101 MockWebSocketHost::MockWebSocketHost( |
101 int routing_id, | 102 int routing_id, |
102 WebSocketDispatcherHost* dispatcher, | 103 WebSocketDispatcherHost* dispatcher, |
103 net::URLRequestContext* url_request_context, | 104 net::URLRequestContext* url_request_context, |
| 105 int delay_in_ms, |
104 WebSocketDispatcherHostTest* owner) | 106 WebSocketDispatcherHostTest* owner) |
105 : WebSocketHost(routing_id, dispatcher, url_request_context), | 107 : WebSocketHost(routing_id, dispatcher, url_request_context, delay_in_ms), |
106 owner_(owner->GetWeakPtr()) {} | 108 owner_(owner->GetWeakPtr()) {} |
107 | 109 |
108 void MockWebSocketHost::GoAway() { | 110 void MockWebSocketHost::GoAway() { |
109 if (owner_) | 111 if (owner_) |
110 owner_->GoAway(routing_id()); | 112 owner_->GoAway(routing_id()); |
111 } | 113 } |
112 | 114 |
113 TEST_F(WebSocketDispatcherHostTest, Construct) { | 115 TEST_F(WebSocketDispatcherHostTest, Construct) { |
114 // Do nothing. | 116 // Do nothing. |
115 } | 117 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 ASSERT_EQ(2u, gone_hosts_.size()); | 212 ASSERT_EQ(2u, gone_hosts_.size()); |
211 // The gone_hosts_ ordering is not predictable because it depends on the | 213 // The gone_hosts_ ordering is not predictable because it depends on the |
212 // hash_map ordering. | 214 // hash_map ordering. |
213 std::sort(gone_hosts_.begin(), gone_hosts_.end()); | 215 std::sort(gone_hosts_.begin(), gone_hosts_.end()); |
214 EXPECT_EQ(123, gone_hosts_[0]); | 216 EXPECT_EQ(123, gone_hosts_[0]); |
215 EXPECT_EQ(456, gone_hosts_[1]); | 217 EXPECT_EQ(456, gone_hosts_[1]); |
216 } | 218 } |
217 | 219 |
218 } // namespace | 220 } // namespace |
219 } // namespace content | 221 } // namespace content |
OLD | NEW |