OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shared_worker/shared_worker_service_impl.h" | 5 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <tuple> | 13 #include <tuple> |
14 | 14 |
15 #include "base/atomic_sequence_num.h" | 15 #include "base/atomic_sequence_num.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "content/browser/message_port_message_filter.h" | 21 #include "base/synchronization/waitable_event.h" |
22 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 22 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
23 #include "content/browser/shared_worker/worker_storage_partition.h" | 23 #include "content/browser/shared_worker/worker_storage_partition.h" |
24 #include "content/common/message_port_messages.h" | |
25 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
26 #include "content/common/worker_messages.h" | 25 #include "content/common/worker_messages.h" |
27 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
28 #include "content/public/test/test_browser_context.h" | 27 #include "content/public/test/test_browser_context.h" |
29 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
30 #include "content/public/test/test_utils.h" | 29 #include "content/public/test/test_utils.h" |
31 #include "ipc/ipc_sync_message.h" | 30 #include "ipc/ipc_sync_message.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
33 | 32 |
34 namespace content { | 33 namespace content { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 std::vector<int> SharedWorkerServiceImplTest::s_worker_dependency_removed_ids_; | 104 std::vector<int> SharedWorkerServiceImplTest::s_worker_dependency_removed_ids_; |
106 base::Lock SharedWorkerServiceImplTest::s_lock_; | 105 base::Lock SharedWorkerServiceImplTest::s_lock_; |
107 std::set<int> SharedWorkerServiceImplTest::s_running_process_id_set_; | 106 std::set<int> SharedWorkerServiceImplTest::s_running_process_id_set_; |
108 | 107 |
109 namespace { | 108 namespace { |
110 | 109 |
111 static const int kProcessIDs[] = {100, 101, 102}; | 110 static const int kProcessIDs[] = {100, 101, 102}; |
112 static const unsigned long long kDocumentIDs[] = {200, 201, 202}; | 111 static const unsigned long long kDocumentIDs[] = {200, 201, 202}; |
113 static const int kRenderFrameRouteIDs[] = {300, 301, 302}; | 112 static const int kRenderFrameRouteIDs[] = {300, 301, 302}; |
114 | 113 |
115 class MockMessagePortMessageFilter : public MessagePortMessageFilter { | 114 void BlockingReadFromMessagePort(MessagePort port, base::string16* message) { |
116 public: | 115 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL, |
117 MockMessagePortMessageFilter( | 116 base::WaitableEvent::InitialState::NOT_SIGNALED); |
118 const NextRoutingIDCallback& callback, | 117 port.SetCallback( |
119 std::vector<std::unique_ptr<IPC::Message>>* message_queue) | 118 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
120 : MessagePortMessageFilter(callback), message_queue_(message_queue) {} | 119 event.Wait(); |
121 | 120 |
122 bool Send(IPC::Message* message) override { | 121 std::vector<MessagePort> should_be_empty; |
123 std::unique_ptr<IPC::Message> owned(message); | 122 EXPECT_TRUE(port.GetMessage(message, &should_be_empty)); |
124 if (!message_queue_) | 123 EXPECT_TRUE(should_be_empty.empty()); |
125 return false; | 124 } |
126 message_queue_->push_back(std::move(owned)); | |
127 return true; | |
128 } | |
129 | |
130 void Close() { | |
131 message_queue_ = nullptr; | |
132 OnChannelClosing(); | |
133 } | |
134 | |
135 private: | |
136 ~MockMessagePortMessageFilter() override {} | |
137 std::vector<std::unique_ptr<IPC::Message>>* message_queue_; | |
138 }; | |
139 | 125 |
140 class MockSharedWorkerMessageFilter : public SharedWorkerMessageFilter { | 126 class MockSharedWorkerMessageFilter : public SharedWorkerMessageFilter { |
141 public: | 127 public: |
142 MockSharedWorkerMessageFilter( | 128 MockSharedWorkerMessageFilter( |
143 int render_process_id, | 129 int render_process_id, |
144 ResourceContext* resource_context, | 130 ResourceContext* resource_context, |
145 const WorkerStoragePartition& partition, | 131 const WorkerStoragePartition& partition, |
146 MessagePortMessageFilter* message_port_filter, | 132 const SharedWorkerMessageFilter::NextRoutingIDCallback& callback, |
147 std::vector<std::unique_ptr<IPC::Message>>* message_queue) | 133 std::vector<std::unique_ptr<IPC::Message>>* message_queue) |
148 : SharedWorkerMessageFilter(render_process_id, | 134 : SharedWorkerMessageFilter(render_process_id, |
149 resource_context, | 135 resource_context, |
150 partition, | 136 partition, |
151 message_port_filter), | 137 callback), |
152 message_queue_(message_queue) {} | 138 message_queue_(message_queue) {} |
153 | 139 |
154 bool Send(IPC::Message* message) override { | 140 bool Send(IPC::Message* message) override { |
155 std::unique_ptr<IPC::Message> owned(message); | 141 std::unique_ptr<IPC::Message> owned(message); |
156 if (!message_queue_) | 142 if (!message_queue_) |
157 return false; | 143 return false; |
158 message_queue_->push_back(std::move(owned)); | 144 message_queue_->push_back(std::move(owned)); |
159 return true; | 145 return true; |
160 } | 146 } |
161 | 147 |
162 void Close() { | 148 void Close() { |
163 message_queue_ = nullptr; | 149 message_queue_ = nullptr; |
164 OnChannelClosing(); | 150 OnChannelClosing(); |
165 } | 151 } |
166 | 152 |
167 private: | 153 private: |
168 ~MockSharedWorkerMessageFilter() override {} | 154 ~MockSharedWorkerMessageFilter() override {} |
169 std::vector<std::unique_ptr<IPC::Message>>* message_queue_; | 155 std::vector<std::unique_ptr<IPC::Message>>* message_queue_; |
170 }; | 156 }; |
171 | 157 |
172 class MockRendererProcessHost { | 158 class MockRendererProcessHost { |
173 public: | 159 public: |
174 MockRendererProcessHost(int process_id, | 160 MockRendererProcessHost(int process_id, |
175 ResourceContext* resource_context, | 161 ResourceContext* resource_context, |
176 const WorkerStoragePartition& partition) | 162 const WorkerStoragePartition& partition) |
177 : process_id_(process_id), | 163 : process_id_(process_id), |
178 message_filter_(new MockMessagePortMessageFilter( | 164 worker_filter_(new MockSharedWorkerMessageFilter( |
| 165 process_id, |
| 166 resource_context, |
| 167 partition, |
179 base::Bind(&base::AtomicSequenceNumber::GetNext, | 168 base::Bind(&base::AtomicSequenceNumber::GetNext, |
180 base::Unretained(&next_routing_id_)), | 169 base::Unretained(&next_routing_id_)), |
181 &queued_messages_)), | 170 &queued_messages_)) { |
182 worker_filter_(new MockSharedWorkerMessageFilter(process_id, | |
183 resource_context, | |
184 partition, | |
185 message_filter_.get(), | |
186 &queued_messages_)) { | |
187 SharedWorkerServiceImplTest::RegisterRunningProcessID(process_id); | 171 SharedWorkerServiceImplTest::RegisterRunningProcessID(process_id); |
188 } | 172 } |
189 | 173 |
190 ~MockRendererProcessHost() { | 174 ~MockRendererProcessHost() { |
191 SharedWorkerServiceImplTest::UnregisterRunningProcessID(process_id_); | 175 SharedWorkerServiceImplTest::UnregisterRunningProcessID(process_id_); |
192 message_filter_->Close(); | |
193 worker_filter_->Close(); | 176 worker_filter_->Close(); |
194 } | 177 } |
195 | 178 |
196 bool OnMessageReceived(IPC::Message* message) { | 179 bool OnMessageReceived(IPC::Message* message) { |
197 std::unique_ptr<IPC::Message> msg(message); | 180 std::unique_ptr<IPC::Message> msg(message); |
198 const bool ret = message_filter_->OnMessageReceived(*message) || | 181 const bool ret = worker_filter_->OnMessageReceived(*message); |
199 worker_filter_->OnMessageReceived(*message); | |
200 if (message->is_sync()) { | 182 if (message->is_sync()) { |
201 CHECK(!queued_messages_.empty()); | 183 CHECK(!queued_messages_.empty()); |
202 std::unique_ptr<IPC::Message> response_msg( | 184 std::unique_ptr<IPC::Message> response_msg( |
203 queued_messages_.back().release()); | 185 queued_messages_.back().release()); |
204 queued_messages_.pop_back(); | 186 queued_messages_.pop_back(); |
205 IPC::SyncMessage* sync_msg = static_cast<IPC::SyncMessage*>(message); | 187 IPC::SyncMessage* sync_msg = static_cast<IPC::SyncMessage*>(message); |
206 std::unique_ptr<IPC::MessageReplyDeserializer> reply_serializer( | 188 std::unique_ptr<IPC::MessageReplyDeserializer> reply_serializer( |
207 sync_msg->GetReplyDeserializer()); | 189 sync_msg->GetReplyDeserializer()); |
208 bool result = reply_serializer->SerializeOutputParameters(*response_msg); | 190 bool result = reply_serializer->SerializeOutputParameters(*response_msg); |
209 CHECK(result); | 191 CHECK(result); |
(...skipping 11 matching lines...) Expand all Loading... |
221 } | 203 } |
222 | 204 |
223 void FastShutdownIfPossible() { | 205 void FastShutdownIfPossible() { |
224 SharedWorkerServiceImplTest::UnregisterRunningProcessID(process_id_); | 206 SharedWorkerServiceImplTest::UnregisterRunningProcessID(process_id_); |
225 } | 207 } |
226 | 208 |
227 private: | 209 private: |
228 const int process_id_; | 210 const int process_id_; |
229 std::vector<std::unique_ptr<IPC::Message>> queued_messages_; | 211 std::vector<std::unique_ptr<IPC::Message>> queued_messages_; |
230 base::AtomicSequenceNumber next_routing_id_; | 212 base::AtomicSequenceNumber next_routing_id_; |
231 scoped_refptr<MockMessagePortMessageFilter> message_filter_; | |
232 scoped_refptr<MockSharedWorkerMessageFilter> worker_filter_; | 213 scoped_refptr<MockSharedWorkerMessageFilter> worker_filter_; |
233 }; | 214 }; |
234 | 215 |
235 void CreateMessagePortPair(MockRendererProcessHost* renderer, | |
236 int* route_1, | |
237 int* port_1, | |
238 int* route_2, | |
239 int* port_2) { | |
240 EXPECT_TRUE(renderer->OnMessageReceived( | |
241 new MessagePortHostMsg_CreateMessagePort(route_1, port_1))); | |
242 EXPECT_TRUE(renderer->OnMessageReceived( | |
243 new MessagePortHostMsg_CreateMessagePort(route_2, port_2))); | |
244 EXPECT_TRUE(renderer->OnMessageReceived( | |
245 new MessagePortHostMsg_Entangle(*port_1, *port_2))); | |
246 EXPECT_TRUE(renderer->OnMessageReceived( | |
247 new MessagePortHostMsg_Entangle(*port_2, *port_1))); | |
248 } | |
249 | |
250 void PostCreateWorker(MockRendererProcessHost* renderer, | 216 void PostCreateWorker(MockRendererProcessHost* renderer, |
251 const std::string& url, | 217 const std::string& url, |
252 const std::string& name, | 218 const std::string& name, |
253 unsigned long long document_id, | 219 unsigned long long document_id, |
254 int render_frame_route_id, | 220 int render_frame_route_id, |
255 ViewHostMsg_CreateWorker_Reply* reply) { | 221 ViewHostMsg_CreateWorker_Reply* reply) { |
256 ViewHostMsg_CreateWorker_Params params; | 222 ViewHostMsg_CreateWorker_Params params; |
257 params.url = GURL(url); | 223 params.url = GURL(url); |
258 params.name = base::ASCIIToUTF16(name); | 224 params.name = base::ASCIIToUTF16(name); |
259 params.content_security_policy = base::string16(); | 225 params.content_security_policy = base::string16(); |
260 params.security_policy_type = blink::WebContentSecurityPolicyTypeReport; | 226 params.security_policy_type = blink::WebContentSecurityPolicyTypeReport; |
261 params.document_id = document_id; | 227 params.document_id = document_id; |
262 params.render_frame_route_id = render_frame_route_id; | 228 params.render_frame_route_id = render_frame_route_id; |
263 params.creation_context_type = | 229 params.creation_context_type = |
264 blink::WebSharedWorkerCreationContextTypeSecure; | 230 blink::WebSharedWorkerCreationContextTypeSecure; |
265 EXPECT_TRUE( | 231 EXPECT_TRUE( |
266 renderer->OnMessageReceived(new ViewHostMsg_CreateWorker(params, reply))); | 232 renderer->OnMessageReceived(new ViewHostMsg_CreateWorker(params, reply))); |
267 } | 233 } |
268 | 234 |
269 class MockSharedWorkerConnector { | 235 class MockSharedWorkerConnector { |
270 public: | 236 public: |
271 MockSharedWorkerConnector(MockRendererProcessHost* renderer_host) | 237 MockSharedWorkerConnector(MockRendererProcessHost* renderer_host) |
272 : renderer_host_(renderer_host), | 238 : renderer_host_(renderer_host) {} |
273 temporary_remote_port_route_id_(0), | |
274 remote_port_id_(0), | |
275 local_port_route_id_(0), | |
276 local_port_id_(0) {} | |
277 void Create(const std::string& url, | 239 void Create(const std::string& url, |
278 const std::string& name, | 240 const std::string& name, |
279 unsigned long long document_id, | 241 unsigned long long document_id, |
280 int render_frame_route_id) { | 242 int render_frame_route_id) { |
281 CreateMessagePortPair(renderer_host_, | |
282 &temporary_remote_port_route_id_, | |
283 &remote_port_id_, | |
284 &local_port_route_id_, | |
285 &local_port_id_); | |
286 PostCreateWorker(renderer_host_, url, name, document_id, | 243 PostCreateWorker(renderer_host_, url, name, document_id, |
287 render_frame_route_id, &create_worker_reply_); | 244 render_frame_route_id, &create_worker_reply_); |
288 } | 245 } |
289 void SendQueueMessages() { | |
290 EXPECT_TRUE(renderer_host_->OnMessageReceived( | |
291 new MessagePortHostMsg_QueueMessages(remote_port_id_))); | |
292 } | |
293 void SendPostMessage(const std::string& data) { | |
294 const std::vector<int> empty_ports; | |
295 EXPECT_TRUE( | |
296 renderer_host_->OnMessageReceived(new MessagePortHostMsg_PostMessage( | |
297 local_port_id_, base::ASCIIToUTF16(data), empty_ports))); | |
298 } | |
299 void SendConnect() { | 246 void SendConnect() { |
| 247 mojo::MessagePipe message_pipe; |
| 248 local_port_ = MessagePort(std::move(message_pipe.handle0)); |
| 249 |
300 EXPECT_TRUE( | 250 EXPECT_TRUE( |
301 renderer_host_->OnMessageReceived(new ViewHostMsg_ConnectToWorker( | 251 renderer_host_->OnMessageReceived(new ViewHostMsg_ConnectToWorker( |
302 create_worker_reply_.route_id, remote_port_id_))); | 252 create_worker_reply_.route_id, |
| 253 MessagePort(std::move(message_pipe.handle1))))); |
303 } | 254 } |
304 void SendSendQueuedMessages( | 255 MessagePort local_port() { return local_port_; } |
305 const std::vector<QueuedMessage>& queued_messages) { | |
306 EXPECT_TRUE(renderer_host_->OnMessageReceived( | |
307 new MessagePortHostMsg_SendQueuedMessages(remote_port_id_, | |
308 queued_messages))); | |
309 } | |
310 int temporary_remote_port_route_id() { | |
311 return temporary_remote_port_route_id_; | |
312 } | |
313 int remote_port_id() { return remote_port_id_; } | |
314 int local_port_route_id() { return local_port_route_id_; } | |
315 int local_port_id() { return local_port_id_; } | |
316 int route_id() { return create_worker_reply_.route_id; } | 256 int route_id() { return create_worker_reply_.route_id; } |
317 blink::WebWorkerCreationError creation_error() { | 257 blink::WebWorkerCreationError creation_error() { |
318 return create_worker_reply_.error; | 258 return create_worker_reply_.error; |
319 } | 259 } |
320 | |
321 private: | 260 private: |
322 MockRendererProcessHost* renderer_host_; | 261 MockRendererProcessHost* renderer_host_; |
323 int temporary_remote_port_route_id_; | 262 MessagePort local_port_; |
324 int remote_port_id_; | |
325 int local_port_route_id_; | |
326 int local_port_id_; | |
327 ViewHostMsg_CreateWorker_Reply create_worker_reply_; | 263 ViewHostMsg_CreateWorker_Reply create_worker_reply_; |
328 }; | 264 }; |
329 | 265 |
330 void CheckWorkerProcessMsgCreateWorker( | 266 void CheckWorkerProcessMsgCreateWorker( |
331 MockRendererProcessHost* renderer_host, | 267 MockRendererProcessHost* renderer_host, |
332 const std::string& expected_url, | 268 const std::string& expected_url, |
333 const std::string& expected_name, | 269 const std::string& expected_name, |
334 blink::WebContentSecurityPolicyType expected_security_policy_type, | 270 blink::WebContentSecurityPolicyType expected_security_policy_type, |
335 int* route_id) { | 271 int* route_id) { |
336 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); | 272 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); |
(...skipping 19 matching lines...) Expand all Loading... |
356 uint32_t expected_feature) { | 292 uint32_t expected_feature) { |
357 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); | 293 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); |
358 EXPECT_EQ(ViewMsg_CountFeatureOnSharedWorker::ID, msg->type()); | 294 EXPECT_EQ(ViewMsg_CountFeatureOnSharedWorker::ID, msg->type()); |
359 EXPECT_EQ(connector->route_id(), msg->routing_id()); | 295 EXPECT_EQ(connector->route_id(), msg->routing_id()); |
360 ViewMsg_CountFeatureOnSharedWorker::Param params; | 296 ViewMsg_CountFeatureOnSharedWorker::Param params; |
361 EXPECT_TRUE(ViewMsg_CountFeatureOnSharedWorker::Read(msg.get(), ¶ms)); | 297 EXPECT_TRUE(ViewMsg_CountFeatureOnSharedWorker::Read(msg.get(), ¶ms)); |
362 uint32_t feature = std::get<0>(params); | 298 uint32_t feature = std::get<0>(params); |
363 EXPECT_EQ(expected_feature, feature); | 299 EXPECT_EQ(expected_feature, feature); |
364 } | 300 } |
365 | 301 |
366 void CheckMessagePortMsgMessagesQueued(MockRendererProcessHost* renderer_host, | |
367 MockSharedWorkerConnector* connector) { | |
368 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); | |
369 EXPECT_EQ(MessagePortMsg_MessagesQueued::ID, msg->type()); | |
370 EXPECT_EQ(connector->temporary_remote_port_route_id(), msg->routing_id()); | |
371 } | |
372 | |
373 void CheckWorkerMsgConnect(MockRendererProcessHost* renderer_host, | 302 void CheckWorkerMsgConnect(MockRendererProcessHost* renderer_host, |
374 int expected_msg_route_id, | 303 int expected_msg_route_id, |
375 int expected_sent_message_port_id, | 304 int* connection_request_id, |
376 int* routing_id) { | 305 MessagePort* port) { |
377 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); | 306 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); |
378 EXPECT_EQ(WorkerMsg_Connect::ID, msg->type()); | 307 EXPECT_EQ(WorkerMsg_Connect::ID, msg->type()); |
379 EXPECT_EQ(expected_msg_route_id, msg->routing_id()); | 308 EXPECT_EQ(expected_msg_route_id, msg->routing_id()); |
380 WorkerMsg_Connect::Param params; | 309 WorkerMsg_Connect::Param params; |
381 EXPECT_TRUE(WorkerMsg_Connect::Read(msg.get(), ¶ms)); | 310 EXPECT_TRUE(WorkerMsg_Connect::Read(msg.get(), ¶ms)); |
382 int port_id = std::get<0>(params); | 311 *connection_request_id = std::get<0>(params); |
383 *routing_id = std::get<1>(params); | 312 *port = std::get<1>(params); |
384 EXPECT_EQ(expected_sent_message_port_id, port_id); | |
385 } | |
386 | |
387 void CheckMessagePortMsgMessage(MockRendererProcessHost* renderer_host, | |
388 int expected_msg_route_id, | |
389 std::string expected_data) { | |
390 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); | |
391 EXPECT_EQ(MessagePortMsg_Message::ID, msg->type()); | |
392 EXPECT_EQ(expected_msg_route_id, msg->routing_id()); | |
393 MessagePortMsg_Message::Param params; | |
394 EXPECT_TRUE(MessagePortMsg_Message::Read(msg.get(), ¶ms)); | |
395 base::string16 data = std::get<0>(params); | |
396 EXPECT_EQ(base::ASCIIToUTF16(expected_data), data); | |
397 } | 313 } |
398 | 314 |
399 void CheckViewMsgWorkerConnected(MockRendererProcessHost* renderer_host, | 315 void CheckViewMsgWorkerConnected(MockRendererProcessHost* renderer_host, |
400 MockSharedWorkerConnector* connector, | 316 MockSharedWorkerConnector* connector, |
401 std::set<uint32_t> expected_used_features) { | 317 std::set<uint32_t> expected_used_features) { |
402 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); | 318 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); |
403 EXPECT_EQ(ViewMsg_WorkerConnected::ID, msg->type()); | 319 EXPECT_EQ(ViewMsg_WorkerConnected::ID, msg->type()); |
404 EXPECT_EQ(connector->route_id(), msg->routing_id()); | 320 EXPECT_EQ(connector->route_id(), msg->routing_id()); |
405 ViewMsg_WorkerConnected::Param params; | 321 ViewMsg_WorkerConnected::Param params; |
406 EXPECT_TRUE(ViewMsg_WorkerConnected::Read(msg.get(), ¶ms)); | 322 EXPECT_TRUE(ViewMsg_WorkerConnected::Read(msg.get(), ¶ms)); |
407 std::set<uint32_t> used_features = std::get<0>(params); | 323 std::set<uint32_t> used_features = std::get<0>(params); |
408 EXPECT_EQ(expected_used_features, used_features); | 324 EXPECT_EQ(expected_used_features, used_features); |
409 } | 325 } |
410 | 326 |
411 } // namespace | 327 } // namespace |
412 | 328 |
413 TEST_F(SharedWorkerServiceImplTest, BasicTest) { | 329 TEST_F(SharedWorkerServiceImplTest, BasicTest) { |
414 std::unique_ptr<MockRendererProcessHost> renderer_host( | 330 std::unique_ptr<MockRendererProcessHost> renderer_host( |
415 new MockRendererProcessHost(kProcessIDs[0], | 331 new MockRendererProcessHost(kProcessIDs[0], |
416 browser_context_->GetResourceContext(), | 332 browser_context_->GetResourceContext(), |
417 *partition_.get())); | 333 *partition_.get())); |
418 std::unique_ptr<MockSharedWorkerConnector> connector( | 334 std::unique_ptr<MockSharedWorkerConnector> connector( |
419 new MockSharedWorkerConnector(renderer_host.get())); | 335 new MockSharedWorkerConnector(renderer_host.get())); |
420 int worker_route_id; | 336 int worker_route_id; |
421 int worker_msg_port_route_id; | |
422 | 337 |
423 // SharedWorkerConnector creates two message ports and sends | 338 // Sends ViewHostMsg_CreateWorker. |
424 // ViewHostMsg_CreateWorker. | |
425 connector->Create("http://example.com/w.js", | 339 connector->Create("http://example.com/w.js", |
426 "name", | 340 "name", |
427 kDocumentIDs[0], | 341 kDocumentIDs[0], |
428 kRenderFrameRouteIDs[0]); | 342 kRenderFrameRouteIDs[0]); |
429 // We need to go to UI thread to call ReserveRenderProcessOnUI(). | |
430 RunAllPendingInMessageLoop(); | 343 RunAllPendingInMessageLoop(); |
431 EXPECT_EQ(2U, renderer_host->QueuedMessageCount()); | 344 EXPECT_EQ(2U, renderer_host->QueuedMessageCount()); |
432 // WorkerProcessMsg_CreateWorker should be sent to the renderer in which | 345 // WorkerProcessMsg_CreateWorker should be sent to the renderer in which |
433 // SharedWorker will be created. | 346 // SharedWorker will be created. |
434 CheckWorkerProcessMsgCreateWorker(renderer_host.get(), | 347 CheckWorkerProcessMsgCreateWorker(renderer_host.get(), |
435 "http://example.com/w.js", | 348 "http://example.com/w.js", |
436 "name", | 349 "name", |
437 blink::WebContentSecurityPolicyTypeReport, | 350 blink::WebContentSecurityPolicyTypeReport, |
438 &worker_route_id); | 351 &worker_route_id); |
439 // ViewMsg_WorkerCreated(1) should be sent back to SharedWorkerConnector side. | 352 // ViewMsg_WorkerCreated(1) should be sent back to SharedWorkerConnector side. |
440 CheckViewMsgWorkerCreated(renderer_host.get(), connector.get()); | 353 CheckViewMsgWorkerCreated(renderer_host.get(), connector.get()); |
441 | 354 |
442 // SharedWorkerConnector side sends MessagePortHostMsg_QueueMessages in | |
443 // WebSharedWorkerProxy::connect. | |
444 connector->SendQueueMessages(); | |
445 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); | |
446 // MessagePortMsg_MessagesQueued(2) should be sent back to | |
447 // SharedWorkerConnector side. | |
448 CheckMessagePortMsgMessagesQueued(renderer_host.get(), connector.get()); | |
449 | |
450 // When SharedWorkerConnector receives ViewMsg_WorkerCreated(1), it sends | 355 // When SharedWorkerConnector receives ViewMsg_WorkerCreated(1), it sends |
451 // WorkerMsg_Connect wrapped in ViewHostMsg_ForwardToWorker. | 356 // WorkerMsg_Connect via ViewHostMsg_ConnectToWorker. |
452 connector->SendConnect(); | 357 connector->SendConnect(); |
453 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); | 358 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); |
454 // WorkerMsg_Connect should be sent to SharedWorker side. | 359 // WorkerMsg_Connect should be sent to SharedWorker side. |
455 CheckWorkerMsgConnect(renderer_host.get(), | 360 int worker_msg_connection_request_id; |
456 worker_route_id, | 361 MessagePort worker_msg_port; |
457 connector->remote_port_id(), | 362 CheckWorkerMsgConnect(renderer_host.get(), worker_route_id, |
458 &worker_msg_port_route_id); | 363 &worker_msg_connection_request_id, &worker_msg_port); |
459 | |
460 // When SharedWorkerConnector receives MessagePortMsg_MessagesQueued(2), it | |
461 // sends MessagePortHostMsg_SendQueuedMessages. | |
462 std::vector<QueuedMessage> empty_messages; | |
463 connector->SendSendQueuedMessages(empty_messages); | |
464 EXPECT_EQ(0U, renderer_host->QueuedMessageCount()); | |
465 | 364 |
466 // SharedWorker sends WorkerHostMsg_WorkerReadyForInspection in | 365 // SharedWorker sends WorkerHostMsg_WorkerReadyForInspection in |
467 // EmbeddedSharedWorkerStub::WorkerReadyForInspection(). | 366 // EmbeddedSharedWorkerStub::WorkerReadyForInspection(). |
468 EXPECT_TRUE(renderer_host->OnMessageReceived( | 367 EXPECT_TRUE(renderer_host->OnMessageReceived( |
469 new WorkerHostMsg_WorkerReadyForInspection(worker_route_id))); | 368 new WorkerHostMsg_WorkerReadyForInspection(worker_route_id))); |
470 EXPECT_EQ(0U, renderer_host->QueuedMessageCount()); | 369 EXPECT_EQ(0U, renderer_host->QueuedMessageCount()); |
471 | 370 |
472 // SharedWorker sends WorkerHostMsg_WorkerScriptLoaded in | 371 // SharedWorker sends WorkerHostMsg_WorkerScriptLoaded in |
473 // EmbeddedSharedWorkerStub::workerScriptLoaded(). | 372 // EmbeddedSharedWorkerStub::workerScriptLoaded(). |
474 EXPECT_TRUE(renderer_host->OnMessageReceived( | 373 EXPECT_TRUE(renderer_host->OnMessageReceived( |
475 new WorkerHostMsg_WorkerScriptLoaded(worker_route_id))); | 374 new WorkerHostMsg_WorkerScriptLoaded(worker_route_id))); |
476 EXPECT_EQ(0U, renderer_host->QueuedMessageCount()); | 375 EXPECT_EQ(0U, renderer_host->QueuedMessageCount()); |
477 | 376 |
478 // SharedWorker sends WorkerHostMsg_WorkerConnected in | 377 // SharedWorker sends WorkerHostMsg_WorkerConnected in |
479 // EmbeddedSharedWorkerStub::workerScriptLoaded(). | 378 // EmbeddedSharedWorkerStub::workerScriptLoaded(). |
480 EXPECT_TRUE( | 379 EXPECT_TRUE( |
481 renderer_host->OnMessageReceived(new WorkerHostMsg_WorkerConnected( | 380 renderer_host->OnMessageReceived(new WorkerHostMsg_WorkerConnected( |
482 connector->remote_port_id(), worker_route_id))); | 381 worker_msg_connection_request_id, worker_route_id))); |
483 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); | 382 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); |
484 // ViewMsg_WorkerConnected should be sent to SharedWorkerConnector side. | 383 // ViewMsg_WorkerConnected should be sent to SharedWorkerConnector side. |
485 CheckViewMsgWorkerConnected(renderer_host.get(), connector.get(), | 384 CheckViewMsgWorkerConnected(renderer_host.get(), connector.get(), |
486 std::set<uint32_t>()); | 385 std::set<uint32_t>()); |
487 | 386 |
488 // When SharedWorkerConnector side sends MessagePortHostMsg_PostMessage, | 387 // Verify that |worker_msg_port| corresponds to |connector->local_port()|. |
489 // SharedWorker side shuold receive MessagePortMsg_Message. | 388 base::string16 expected_message(base::ASCIIToUTF16("test1")); |
490 connector->SendPostMessage("test1"); | 389 connector->local_port().PostMessage(expected_message, |
491 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); | 390 std::vector<MessagePort>()); |
492 CheckMessagePortMsgMessage( | 391 base::string16 received_message; |
493 renderer_host.get(), worker_msg_port_route_id, "test1"); | 392 BlockingReadFromMessagePort(worker_msg_port, &received_message); |
494 | 393 EXPECT_EQ(expected_message, received_message); |
495 // When SharedWorker side sends MessagePortHostMsg_PostMessage, | |
496 // SharedWorkerConnector side shuold receive MessagePortMsg_Message. | |
497 const std::vector<int> empty_ports; | |
498 EXPECT_TRUE( | |
499 renderer_host->OnMessageReceived(new MessagePortHostMsg_PostMessage( | |
500 connector->remote_port_id(), | |
501 base::ASCIIToUTF16("test2"), empty_ports))); | |
502 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); | |
503 CheckMessagePortMsgMessage( | |
504 renderer_host.get(), connector->local_port_route_id(), "test2"); | |
505 | 394 |
506 // SharedWorker sends WorkerHostMsg_CountFeature in | 395 // SharedWorker sends WorkerHostMsg_CountFeature in |
507 // EmbeddedSharedWorkerStub::CountFeature(). | 396 // EmbeddedSharedWorkerStub::CountFeature(). |
508 uint32_t feature1 = 124; | 397 uint32_t feature1 = 124; |
509 EXPECT_TRUE(renderer_host->OnMessageReceived( | 398 EXPECT_TRUE(renderer_host->OnMessageReceived( |
510 new WorkerHostMsg_CountFeature(worker_route_id, feature1))); | 399 new WorkerHostMsg_CountFeature(worker_route_id, feature1))); |
511 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); | 400 EXPECT_EQ(1U, renderer_host->QueuedMessageCount()); |
512 // ViewMsg_CountFeature should be sent to SharedWorkerConnector side. | 401 // ViewMsg_CountFeature should be sent to SharedWorkerConnector side. |
513 CheckViewMsgCountFeature(renderer_host.get(), connector.get(), feature1); | 402 CheckViewMsgCountFeature(renderer_host.get(), connector.get(), feature1); |
514 // A message should be sent only one time per feature. | 403 // A message should be sent only one time per feature. |
(...skipping 16 matching lines...) Expand all Loading... |
531 | 420 |
532 TEST_F(SharedWorkerServiceImplTest, TwoRendererTest) { | 421 TEST_F(SharedWorkerServiceImplTest, TwoRendererTest) { |
533 // The first renderer host. | 422 // The first renderer host. |
534 std::unique_ptr<MockRendererProcessHost> renderer_host0( | 423 std::unique_ptr<MockRendererProcessHost> renderer_host0( |
535 new MockRendererProcessHost(kProcessIDs[0], | 424 new MockRendererProcessHost(kProcessIDs[0], |
536 browser_context_->GetResourceContext(), | 425 browser_context_->GetResourceContext(), |
537 *partition_.get())); | 426 *partition_.get())); |
538 std::unique_ptr<MockSharedWorkerConnector> connector0( | 427 std::unique_ptr<MockSharedWorkerConnector> connector0( |
539 new MockSharedWorkerConnector(renderer_host0.get())); | 428 new MockSharedWorkerConnector(renderer_host0.get())); |
540 int worker_route_id; | 429 int worker_route_id; |
541 int worker_msg_port_route_id1; | |
542 | 430 |
543 // SharedWorkerConnector creates two message ports and sends | 431 // Sends ViewHostMsg_CreateWorker. |
544 // ViewHostMsg_CreateWorker. | |
545 connector0->Create("http://example.com/w.js", | 432 connector0->Create("http://example.com/w.js", |
546 "name", | 433 "name", |
547 kDocumentIDs[0], | 434 kDocumentIDs[0], |
548 kRenderFrameRouteIDs[0]); | 435 kRenderFrameRouteIDs[0]); |
549 // We need to go to UI thread to call ReserveRenderProcessOnUI(). | |
550 RunAllPendingInMessageLoop(); | 436 RunAllPendingInMessageLoop(); |
551 EXPECT_EQ(2U, renderer_host0->QueuedMessageCount()); | 437 EXPECT_EQ(2U, renderer_host0->QueuedMessageCount()); |
552 // WorkerProcessMsg_CreateWorker should be sent to the renderer in which | 438 // WorkerProcessMsg_CreateWorker should be sent to the renderer in which |
553 // SharedWorker will be created. | 439 // SharedWorker will be created. |
554 CheckWorkerProcessMsgCreateWorker(renderer_host0.get(), | 440 CheckWorkerProcessMsgCreateWorker(renderer_host0.get(), |
555 "http://example.com/w.js", | 441 "http://example.com/w.js", |
556 "name", | 442 "name", |
557 blink::WebContentSecurityPolicyTypeReport, | 443 blink::WebContentSecurityPolicyTypeReport, |
558 &worker_route_id); | 444 &worker_route_id); |
559 // ViewMsg_WorkerCreated(1) should be sent back to SharedWorkerConnector side. | 445 // ViewMsg_WorkerCreated(1) should be sent back to SharedWorkerConnector side. |
560 CheckViewMsgWorkerCreated(renderer_host0.get(), connector0.get()); | 446 CheckViewMsgWorkerCreated(renderer_host0.get(), connector0.get()); |
561 | 447 |
562 // SharedWorkerConnector side sends MessagePortHostMsg_QueueMessages in | |
563 // WebSharedWorkerProxy::connect. | |
564 connector0->SendQueueMessages(); | |
565 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | |
566 // MessagePortMsg_MessagesQueued(2) should be sent back to | |
567 // SharedWorkerConnector side. | |
568 CheckMessagePortMsgMessagesQueued(renderer_host0.get(), connector0.get()); | |
569 | |
570 // When SharedWorkerConnector receives ViewMsg_WorkerCreated(1), it sends | 448 // When SharedWorkerConnector receives ViewMsg_WorkerCreated(1), it sends |
571 // WorkerMsg_Connect wrapped in ViewHostMsg_ForwardToWorker. | 449 // WorkerMsg_Connect wrapped in ViewHostMsg_ForwardToWorker. |
572 connector0->SendConnect(); | 450 connector0->SendConnect(); |
573 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | 451 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); |
574 // WorkerMsg_Connect should be sent to SharedWorker side. | 452 // WorkerMsg_Connect should be sent to SharedWorker side. |
575 CheckWorkerMsgConnect(renderer_host0.get(), | 453 int worker_msg_connection_request_id1; |
576 worker_route_id, | 454 MessagePort worker_msg_port1; |
577 connector0->remote_port_id(), | 455 CheckWorkerMsgConnect(renderer_host0.get(), worker_route_id, |
578 &worker_msg_port_route_id1); | 456 &worker_msg_connection_request_id1, &worker_msg_port1); |
579 | |
580 // When SharedWorkerConnector receives MessagePortMsg_MessagesQueued(2), it | |
581 // sends MessagePortHostMsg_SendQueuedMessages. | |
582 std::vector<QueuedMessage> empty_messages; | |
583 connector0->SendSendQueuedMessages(empty_messages); | |
584 EXPECT_EQ(0U, renderer_host0->QueuedMessageCount()); | |
585 | 457 |
586 // SharedWorker sends WorkerHostMsg_WorkerReadyForInspection in | 458 // SharedWorker sends WorkerHostMsg_WorkerReadyForInspection in |
587 // EmbeddedSharedWorkerStub::WorkerReadyForInspection(). | 459 // EmbeddedSharedWorkerStub::WorkerReadyForInspection(). |
588 EXPECT_TRUE(renderer_host0->OnMessageReceived( | 460 EXPECT_TRUE(renderer_host0->OnMessageReceived( |
589 new WorkerHostMsg_WorkerReadyForInspection(worker_route_id))); | 461 new WorkerHostMsg_WorkerReadyForInspection(worker_route_id))); |
590 EXPECT_EQ(0U, renderer_host0->QueuedMessageCount()); | 462 EXPECT_EQ(0U, renderer_host0->QueuedMessageCount()); |
591 | 463 |
592 // SharedWorker sends WorkerHostMsg_WorkerScriptLoaded in | 464 // SharedWorker sends WorkerHostMsg_WorkerScriptLoaded in |
593 // EmbeddedSharedWorkerStub::workerScriptLoaded(). | 465 // EmbeddedSharedWorkerStub::workerScriptLoaded(). |
594 EXPECT_TRUE(renderer_host0->OnMessageReceived( | 466 EXPECT_TRUE(renderer_host0->OnMessageReceived( |
595 new WorkerHostMsg_WorkerScriptLoaded(worker_route_id))); | 467 new WorkerHostMsg_WorkerScriptLoaded(worker_route_id))); |
596 EXPECT_EQ(0U, renderer_host0->QueuedMessageCount()); | 468 EXPECT_EQ(0U, renderer_host0->QueuedMessageCount()); |
597 | 469 |
598 // SharedWorker sends WorkerHostMsg_WorkerConnected in | 470 // SharedWorker sends WorkerHostMsg_WorkerConnected in |
599 // EmbeddedSharedWorkerStub::workerScriptLoaded(). | 471 // EmbeddedSharedWorkerStub::workerScriptLoaded(). |
600 EXPECT_TRUE( | 472 EXPECT_TRUE( |
601 renderer_host0->OnMessageReceived(new WorkerHostMsg_WorkerConnected( | 473 renderer_host0->OnMessageReceived(new WorkerHostMsg_WorkerConnected( |
602 connector0->remote_port_id(), worker_route_id))); | 474 worker_msg_connection_request_id1, worker_route_id))); |
603 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | 475 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); |
604 // ViewMsg_WorkerConnected should be sent to SharedWorkerConnector side. | 476 // ViewMsg_WorkerConnected should be sent to SharedWorkerConnector side. |
605 CheckViewMsgWorkerConnected(renderer_host0.get(), connector0.get(), | 477 CheckViewMsgWorkerConnected(renderer_host0.get(), connector0.get(), |
606 std::set<uint32_t>()); | 478 std::set<uint32_t>()); |
607 | 479 |
608 // When SharedWorkerConnector side sends MessagePortHostMsg_PostMessage, | 480 // Verify that |worker_msg_port1| corresponds to |connector0->local_port()|. |
609 // SharedWorker side shuold receive MessagePortMsg_Message. | 481 base::string16 expected_message1(base::ASCIIToUTF16("test1")); |
610 connector0->SendPostMessage("test1"); | 482 connector0->local_port().PostMessage(expected_message1, |
611 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | 483 std::vector<MessagePort>()); |
612 CheckMessagePortMsgMessage( | 484 base::string16 received_message1; |
613 renderer_host0.get(), worker_msg_port_route_id1, "test1"); | 485 BlockingReadFromMessagePort(worker_msg_port1, &received_message1); |
614 | 486 EXPECT_EQ(expected_message1, received_message1); |
615 // When SharedWorker side sends MessagePortHostMsg_PostMessage, | |
616 // SharedWorkerConnector side shuold receive MessagePortMsg_Message. | |
617 const std::vector<int> empty_ports; | |
618 EXPECT_TRUE( | |
619 renderer_host0->OnMessageReceived(new MessagePortHostMsg_PostMessage( | |
620 connector0->remote_port_id(), | |
621 base::ASCIIToUTF16("test2"), empty_ports))); | |
622 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | |
623 CheckMessagePortMsgMessage( | |
624 renderer_host0.get(), connector0->local_port_route_id(), "test2"); | |
625 | 487 |
626 // SharedWorker sends WorkerHostMsg_CountFeature in | 488 // SharedWorker sends WorkerHostMsg_CountFeature in |
627 // EmbeddedSharedWorkerStub::CountFeature(). | 489 // EmbeddedSharedWorkerStub::CountFeature(). |
628 uint32_t feature1 = 124; | 490 uint32_t feature1 = 124; |
629 EXPECT_TRUE(renderer_host0->OnMessageReceived( | 491 EXPECT_TRUE(renderer_host0->OnMessageReceived( |
630 new WorkerHostMsg_CountFeature(worker_route_id, feature1))); | 492 new WorkerHostMsg_CountFeature(worker_route_id, feature1))); |
631 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | 493 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); |
632 // ViewMsg_CountFeature should be sent to SharedWorkerConnector side. | 494 // ViewMsg_CountFeature should be sent to SharedWorkerConnector side. |
633 CheckViewMsgCountFeature(renderer_host0.get(), connector0.get(), feature1); | 495 CheckViewMsgCountFeature(renderer_host0.get(), connector0.get(), feature1); |
634 uint32_t feature2 = 901; | 496 uint32_t feature2 = 901; |
635 EXPECT_TRUE(renderer_host0->OnMessageReceived( | 497 EXPECT_TRUE(renderer_host0->OnMessageReceived( |
636 new WorkerHostMsg_CountFeature(worker_route_id, feature2))); | 498 new WorkerHostMsg_CountFeature(worker_route_id, feature2))); |
637 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | 499 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); |
638 // ViewMsg_CountFeature should be sent to SharedWorkerConnector side. | 500 // ViewMsg_CountFeature should be sent to SharedWorkerConnector side. |
639 CheckViewMsgCountFeature(renderer_host0.get(), connector0.get(), feature2); | 501 CheckViewMsgCountFeature(renderer_host0.get(), connector0.get(), feature2); |
640 | 502 |
641 // The second renderer host. | 503 // The second renderer host. |
642 std::unique_ptr<MockRendererProcessHost> renderer_host1( | 504 std::unique_ptr<MockRendererProcessHost> renderer_host1( |
643 new MockRendererProcessHost(kProcessIDs[1], | 505 new MockRendererProcessHost(kProcessIDs[1], |
644 browser_context_->GetResourceContext(), | 506 browser_context_->GetResourceContext(), |
645 *partition_.get())); | 507 *partition_.get())); |
646 std::unique_ptr<MockSharedWorkerConnector> connector1( | 508 std::unique_ptr<MockSharedWorkerConnector> connector1( |
647 new MockSharedWorkerConnector(renderer_host1.get())); | 509 new MockSharedWorkerConnector(renderer_host1.get())); |
648 int worker_msg_port_route_id2; | |
649 | 510 |
650 // UpdateWorkerDependency should not be called yet. | 511 // UpdateWorkerDependency should not be called yet. |
651 EXPECT_EQ(0, s_update_worker_dependency_call_count_); | 512 EXPECT_EQ(0, s_update_worker_dependency_call_count_); |
652 | 513 |
653 // SharedWorkerConnector creates two message ports and sends | 514 // SharedWorkerConnector creates two message ports and sends |
654 // ViewHostMsg_CreateWorker. | 515 // ViewHostMsg_CreateWorker. |
655 connector1->Create("http://example.com/w.js", | 516 connector1->Create("http://example.com/w.js", |
656 "name", | 517 "name", |
657 kDocumentIDs[1], | 518 kDocumentIDs[1], |
658 kRenderFrameRouteIDs[1]); | 519 kRenderFrameRouteIDs[1]); |
659 // We need to go to UI thread to call ReserveRenderProcessOnUI(). | 520 // We need to go to UI thread to call ReserveRenderProcessOnUI(). |
660 RunAllPendingInMessageLoop(); | 521 RunAllPendingInMessageLoop(); |
661 EXPECT_EQ(1U, renderer_host1->QueuedMessageCount()); | 522 EXPECT_EQ(1U, renderer_host1->QueuedMessageCount()); |
662 // ViewMsg_WorkerCreated(3) should be sent back to SharedWorkerConnector side. | 523 // ViewMsg_WorkerCreated(3) should be sent back to SharedWorkerConnector side. |
663 CheckViewMsgWorkerCreated(renderer_host1.get(), connector1.get()); | 524 CheckViewMsgWorkerCreated(renderer_host1.get(), connector1.get()); |
664 | 525 |
665 // UpdateWorkerDependency should be called. | 526 // UpdateWorkerDependency should be called. |
666 EXPECT_EQ(1, s_update_worker_dependency_call_count_); | 527 EXPECT_EQ(1, s_update_worker_dependency_call_count_); |
667 EXPECT_EQ(1U, s_worker_dependency_added_ids_.size()); | 528 EXPECT_EQ(1U, s_worker_dependency_added_ids_.size()); |
668 EXPECT_EQ(kProcessIDs[0], s_worker_dependency_added_ids_[0]); | 529 EXPECT_EQ(kProcessIDs[0], s_worker_dependency_added_ids_[0]); |
669 EXPECT_EQ(0U, s_worker_dependency_removed_ids_.size()); | 530 EXPECT_EQ(0U, s_worker_dependency_removed_ids_.size()); |
670 | 531 |
671 // SharedWorkerConnector side sends MessagePortHostMsg_QueueMessages in | |
672 // WebSharedWorkerProxy::connect. | |
673 connector1->SendQueueMessages(); | |
674 EXPECT_EQ(1U, renderer_host1->QueuedMessageCount()); | |
675 // MessagePortMsg_MessagesQueued(4) should be sent back to | |
676 // SharedWorkerConnector side. | |
677 CheckMessagePortMsgMessagesQueued(renderer_host1.get(), connector1.get()); | |
678 | |
679 // When SharedWorkerConnector receives ViewMsg_WorkerCreated(3), it sends | 532 // When SharedWorkerConnector receives ViewMsg_WorkerCreated(3), it sends |
680 // WorkerMsg_Connect wrapped in ViewHostMsg_ForwardToWorker. | 533 // WorkerMsg_Connect wrapped in ViewHostMsg_ForwardToWorker. |
681 connector1->SendConnect(); | 534 connector1->SendConnect(); |
682 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | 535 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); |
683 // WorkerMsg_Connect should be sent to SharedWorker side. | 536 // WorkerMsg_Connect should be sent to SharedWorker side. |
684 CheckWorkerMsgConnect(renderer_host0.get(), | 537 int worker_msg_connection_request_id2; |
685 worker_route_id, | 538 MessagePort worker_msg_port2; |
686 connector1->remote_port_id(), | 539 CheckWorkerMsgConnect(renderer_host0.get(), worker_route_id, |
687 &worker_msg_port_route_id2); | 540 &worker_msg_connection_request_id2, &worker_msg_port2); |
688 | |
689 // When SharedWorkerConnector receives MessagePortMsg_MessagesQueued(4), it | |
690 // sends MessagePortHostMsg_SendQueuedMessages. | |
691 connector1->SendSendQueuedMessages(empty_messages); | |
692 EXPECT_EQ(0U, renderer_host1->QueuedMessageCount()); | |
693 | 541 |
694 // SharedWorker sends WorkerHostMsg_WorkerConnected in | 542 // SharedWorker sends WorkerHostMsg_WorkerConnected in |
695 // EmbeddedSharedWorkerStub::OnConnect(). | 543 // EmbeddedSharedWorkerStub::OnConnect(). |
696 EXPECT_TRUE( | 544 EXPECT_TRUE( |
697 renderer_host0->OnMessageReceived(new WorkerHostMsg_WorkerConnected( | 545 renderer_host0->OnMessageReceived(new WorkerHostMsg_WorkerConnected( |
698 connector1->remote_port_id(), worker_route_id))); | 546 worker_msg_connection_request_id2, worker_route_id))); |
699 EXPECT_EQ(1U, renderer_host1->QueuedMessageCount()); | 547 EXPECT_EQ(1U, renderer_host1->QueuedMessageCount()); |
700 // ViewMsg_WorkerConnected should be sent to SharedWorkerConnector side. | 548 // ViewMsg_WorkerConnected should be sent to SharedWorkerConnector side. |
701 CheckViewMsgWorkerConnected(renderer_host1.get(), connector1.get(), | 549 CheckViewMsgWorkerConnected(renderer_host1.get(), connector1.get(), |
702 {feature1, feature2}); | 550 {feature1, feature2}); |
703 | 551 |
704 // When SharedWorkerConnector side sends MessagePortHostMsg_PostMessage, | 552 // Verify that |worker_msg_port2| corresponds to |connector1->local_port()|. |
705 // SharedWorker side shuold receive MessagePortMsg_Message. | 553 base::string16 expected_message2(base::ASCIIToUTF16("test2")); |
706 connector1->SendPostMessage("test3"); | 554 connector1->local_port().PostMessage(expected_message2, |
707 EXPECT_EQ(1U, renderer_host0->QueuedMessageCount()); | 555 std::vector<MessagePort>()); |
708 CheckMessagePortMsgMessage( | 556 base::string16 received_message2; |
709 renderer_host0.get(), worker_msg_port_route_id2, "test3"); | 557 BlockingReadFromMessagePort(worker_msg_port2, &received_message2); |
710 | 558 EXPECT_EQ(expected_message2, received_message2); |
711 // When SharedWorker side sends MessagePortHostMsg_PostMessage, | |
712 // SharedWorkerConnector side shuold receive MessagePortMsg_Message. | |
713 EXPECT_TRUE( | |
714 renderer_host0->OnMessageReceived(new MessagePortHostMsg_PostMessage( | |
715 connector1->remote_port_id(), | |
716 base::ASCIIToUTF16("test4"), empty_ports))); | |
717 EXPECT_EQ(1U, renderer_host1->QueuedMessageCount()); | |
718 CheckMessagePortMsgMessage( | |
719 renderer_host1.get(), connector1->local_port_route_id(), "test4"); | |
720 | 559 |
721 // SharedWorker sends WorkerHostMsg_CountFeature in | 560 // SharedWorker sends WorkerHostMsg_CountFeature in |
722 // EmbeddedSharedWorkerStub::CountFeature(). These used_features are already | 561 // EmbeddedSharedWorkerStub::CountFeature(). These used_features are already |
723 // counted in the browser-side, so messages should not be sent to | 562 // counted in the browser-side, so messages should not be sent to |
724 // SharedWorkerConnectors. | 563 // SharedWorkerConnectors. |
725 EXPECT_TRUE(renderer_host0->OnMessageReceived( | 564 EXPECT_TRUE(renderer_host0->OnMessageReceived( |
726 new WorkerHostMsg_CountFeature(worker_route_id, feature1))); | 565 new WorkerHostMsg_CountFeature(worker_route_id, feature1))); |
727 EXPECT_EQ(0U, renderer_host0->QueuedMessageCount()); | 566 EXPECT_EQ(0U, renderer_host0->QueuedMessageCount()); |
728 EXPECT_EQ(0U, renderer_host1->QueuedMessageCount()); | 567 EXPECT_EQ(0U, renderer_host1->QueuedMessageCount()); |
729 | 568 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 kDocumentIDs[2], | 894 kDocumentIDs[2], |
1056 kRenderFrameRouteIDs[2]); | 895 kRenderFrameRouteIDs[2]); |
1057 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id()); | 896 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id()); |
1058 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount()); | 897 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount()); |
1059 RunAllPendingInMessageLoop(); | 898 RunAllPendingInMessageLoop(); |
1060 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount()); | 899 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount()); |
1061 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get()); | 900 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get()); |
1062 } | 901 } |
1063 | 902 |
1064 } // namespace content | 903 } // namespace content |
OLD | NEW |