Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: content/browser/shared_worker/shared_worker_service_impl_unittest.cc

Issue 2600113003: (SUSPENDED) SharedWorker: Mojofy Renderer(Document)->Browser communication for SharedWorker
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 15 matching lines...) Expand all
26 #include "content/common/worker_messages.h" 26 #include "content/common/worker_messages.h"
27 #include "content/public/browser/storage_partition.h" 27 #include "content/public/browser/storage_partition.h"
28 #include "content/public/test/test_browser_context.h" 28 #include "content/public/test/test_browser_context.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "content/public/test/test_utils.h" 30 #include "content/public/test/test_utils.h"
31 #include "ipc/ipc_sync_message.h" 31 #include "ipc/ipc_sync_message.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 namespace content { 34 namespace content {
35 35
36 namespace {
37
38 void CreateWorkerCallback(mojom::SharedWorker_CreateWorker_ReplyPtr* out,
39 mojom::SharedWorker_CreateWorker_ReplyPtr reply) {
40 *out = std::move(reply);
41 }
42
43 } // namespace
44
36 class SharedWorkerServiceImplTest : public testing::Test { 45 class SharedWorkerServiceImplTest : public testing::Test {
37 public: 46 public:
38 static void RegisterRunningProcessID(int process_id) { 47 static void RegisterRunningProcessID(int process_id) {
39 base::AutoLock lock(s_lock_); 48 base::AutoLock lock(s_lock_);
40 s_running_process_id_set_.insert(process_id); 49 s_running_process_id_set_.insert(process_id);
41 } 50 }
42 static void UnregisterRunningProcessID(int process_id) { 51 static void UnregisterRunningProcessID(int process_id) {
43 base::AutoLock lock(s_lock_); 52 base::AutoLock lock(s_lock_);
44 s_running_process_id_set_.erase(process_id); 53 s_running_process_id_set_.erase(process_id);
45 } 54 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 queued_messages_.pop_back(); 213 queued_messages_.pop_back();
205 IPC::SyncMessage* sync_msg = static_cast<IPC::SyncMessage*>(message); 214 IPC::SyncMessage* sync_msg = static_cast<IPC::SyncMessage*>(message);
206 std::unique_ptr<IPC::MessageReplyDeserializer> reply_serializer( 215 std::unique_ptr<IPC::MessageReplyDeserializer> reply_serializer(
207 sync_msg->GetReplyDeserializer()); 216 sync_msg->GetReplyDeserializer());
208 bool result = reply_serializer->SerializeOutputParameters(*response_msg); 217 bool result = reply_serializer->SerializeOutputParameters(*response_msg);
209 CHECK(result); 218 CHECK(result);
210 } 219 }
211 return ret; 220 return ret;
212 } 221 }
213 222
223 // Emulates mojo RPC calls (Renderer(Document)->Browser).
224 void OnCreateWorker(mojom::SharedWorker_CreateWorker_ParamsPtr params,
225 mojom::SharedWorker_CreateWorker_ReplyPtr* reply) {
226 worker_filter_->OnCreateWorker(std::move(params),
227 base::Bind(&CreateWorkerCallback, reply));
228 }
229
230 void OnConnectToWorker(int route_id, int message_port_id) {
231 worker_filter_->OnConnectToWorker(route_id, message_port_id);
232 }
233
214 size_t QueuedMessageCount() const { return queued_messages_.size(); } 234 size_t QueuedMessageCount() const { return queued_messages_.size(); }
215 235
216 std::unique_ptr<IPC::Message> PopMessage() { 236 std::unique_ptr<IPC::Message> PopMessage() {
217 CHECK(queued_messages_.size()); 237 CHECK(queued_messages_.size());
218 std::unique_ptr<IPC::Message> msg(queued_messages_.begin()->release()); 238 std::unique_ptr<IPC::Message> msg(queued_messages_.begin()->release());
219 queued_messages_.erase(queued_messages_.begin()); 239 queued_messages_.erase(queued_messages_.begin());
220 return msg; 240 return msg;
221 } 241 }
222 242
223 void FastShutdownIfPossible() { 243 void FastShutdownIfPossible() {
(...skipping 21 matching lines...) Expand all
245 new MessagePortHostMsg_Entangle(*port_1, *port_2))); 265 new MessagePortHostMsg_Entangle(*port_1, *port_2)));
246 EXPECT_TRUE(renderer->OnMessageReceived( 266 EXPECT_TRUE(renderer->OnMessageReceived(
247 new MessagePortHostMsg_Entangle(*port_2, *port_1))); 267 new MessagePortHostMsg_Entangle(*port_2, *port_1)));
248 } 268 }
249 269
250 void PostCreateWorker(MockRendererProcessHost* renderer, 270 void PostCreateWorker(MockRendererProcessHost* renderer,
251 const std::string& url, 271 const std::string& url,
252 const std::string& name, 272 const std::string& name,
253 unsigned long long document_id, 273 unsigned long long document_id,
254 int render_frame_route_id, 274 int render_frame_route_id,
255 ViewHostMsg_CreateWorker_Reply* reply) { 275 mojom::SharedWorker_CreateWorker_ReplyPtr* reply) {
256 ViewHostMsg_CreateWorker_Params params; 276 mojom::SharedWorker_CreateWorker_ParamsPtr params =
257 params.url = GURL(url); 277 mojom::SharedWorker_CreateWorker_Params::New();
258 params.name = base::ASCIIToUTF16(name); 278 params->url = GURL(url);
259 params.content_security_policy = base::string16(); 279 params->name = base::ASCIIToUTF16(name);
260 params.security_policy_type = blink::WebContentSecurityPolicyTypeReport; 280 params->content_security_policy = base::string16();
261 params.document_id = document_id; 281 params->security_policy_type =
262 params.render_frame_route_id = render_frame_route_id; 282 static_cast<mojom::WebContentSecurityPolicyType>(
263 params.creation_context_type = 283 blink::WebContentSecurityPolicyTypeReport);
264 blink::WebSharedWorkerCreationContextTypeSecure; 284 params->document_id = document_id;
265 EXPECT_TRUE( 285 params->render_frame_route_id = render_frame_route_id;
266 renderer->OnMessageReceived(new ViewHostMsg_CreateWorker(params, reply))); 286 params->creation_context_type =
287 static_cast<mojom::WebSharedWorkerCreationContextType>(
288 blink::WebSharedWorkerCreationContextTypeSecure);
289 renderer->OnCreateWorker(std::move(params), reply);
267 } 290 }
268 291
269 class MockSharedWorkerConnector { 292 class MockSharedWorkerConnector {
270 public: 293 public:
271 MockSharedWorkerConnector(MockRendererProcessHost* renderer_host) 294 MockSharedWorkerConnector(MockRendererProcessHost* renderer_host)
272 : renderer_host_(renderer_host), 295 : renderer_host_(renderer_host),
273 temporary_remote_port_route_id_(0), 296 temporary_remote_port_route_id_(0),
274 remote_port_id_(0), 297 remote_port_id_(0),
275 local_port_route_id_(0), 298 local_port_route_id_(0),
276 local_port_id_(0) {} 299 local_port_id_(0) {}
(...skipping 13 matching lines...) Expand all
290 EXPECT_TRUE(renderer_host_->OnMessageReceived( 313 EXPECT_TRUE(renderer_host_->OnMessageReceived(
291 new MessagePortHostMsg_QueueMessages(remote_port_id_))); 314 new MessagePortHostMsg_QueueMessages(remote_port_id_)));
292 } 315 }
293 void SendPostMessage(const std::string& data) { 316 void SendPostMessage(const std::string& data) {
294 const std::vector<int> empty_ports; 317 const std::vector<int> empty_ports;
295 EXPECT_TRUE( 318 EXPECT_TRUE(
296 renderer_host_->OnMessageReceived(new MessagePortHostMsg_PostMessage( 319 renderer_host_->OnMessageReceived(new MessagePortHostMsg_PostMessage(
297 local_port_id_, base::ASCIIToUTF16(data), empty_ports))); 320 local_port_id_, base::ASCIIToUTF16(data), empty_ports)));
298 } 321 }
299 void SendConnect() { 322 void SendConnect() {
300 EXPECT_TRUE( 323 renderer_host_->OnConnectToWorker(create_worker_reply_->route_id,
301 renderer_host_->OnMessageReceived(new ViewHostMsg_ConnectToWorker( 324 remote_port_id_);
302 create_worker_reply_.route_id, remote_port_id_)));
303 } 325 }
304 void SendSendQueuedMessages( 326 void SendSendQueuedMessages(
305 const std::vector<QueuedMessage>& queued_messages) { 327 const std::vector<QueuedMessage>& queued_messages) {
306 EXPECT_TRUE(renderer_host_->OnMessageReceived( 328 EXPECT_TRUE(renderer_host_->OnMessageReceived(
307 new MessagePortHostMsg_SendQueuedMessages(remote_port_id_, 329 new MessagePortHostMsg_SendQueuedMessages(remote_port_id_,
308 queued_messages))); 330 queued_messages)));
309 } 331 }
310 int temporary_remote_port_route_id() { 332 int temporary_remote_port_route_id() {
311 return temporary_remote_port_route_id_; 333 return temporary_remote_port_route_id_;
312 } 334 }
313 int remote_port_id() { return remote_port_id_; } 335 int remote_port_id() { return remote_port_id_; }
314 int local_port_route_id() { return local_port_route_id_; } 336 int local_port_route_id() { return local_port_route_id_; }
315 int local_port_id() { return local_port_id_; } 337 int local_port_id() { return local_port_id_; }
316 int route_id() { return create_worker_reply_.route_id; } 338 int route_id() { return create_worker_reply_->route_id; }
317 blink::WebWorkerCreationError creation_error() { 339 blink::WebWorkerCreationError creation_error() {
318 return create_worker_reply_.error; 340 return static_cast<blink::WebWorkerCreationError>(
341 create_worker_reply_->error);
319 } 342 }
320 343
321 private: 344 private:
322 MockRendererProcessHost* renderer_host_; 345 MockRendererProcessHost* renderer_host_;
323 int temporary_remote_port_route_id_; 346 int temporary_remote_port_route_id_;
324 int remote_port_id_; 347 int remote_port_id_;
325 int local_port_route_id_; 348 int local_port_route_id_;
326 int local_port_id_; 349 int local_port_id_;
327 ViewHostMsg_CreateWorker_Reply create_worker_reply_; 350 mojom::SharedWorker_CreateWorker_ReplyPtr create_worker_reply_;
328 }; 351 };
329 352
330 void CheckWorkerProcessMsgCreateWorker( 353 void CheckWorkerProcessMsgCreateWorker(
331 MockRendererProcessHost* renderer_host, 354 MockRendererProcessHost* renderer_host,
332 const std::string& expected_url, 355 const std::string& expected_url,
333 const std::string& expected_name, 356 const std::string& expected_name,
334 blink::WebContentSecurityPolicyType expected_security_policy_type, 357 blink::WebContentSecurityPolicyType expected_security_policy_type,
335 int* route_id) { 358 int* route_id) {
336 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage()); 359 std::unique_ptr<IPC::Message> msg(renderer_host->PopMessage());
337 EXPECT_EQ(WorkerProcessMsg_CreateWorker::ID, msg->type()); 360 EXPECT_EQ(WorkerProcessMsg_CreateWorker::ID, msg->type());
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 kDocumentIDs[2], 1000 kDocumentIDs[2],
978 kRenderFrameRouteIDs[2]); 1001 kRenderFrameRouteIDs[2]);
979 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id()); 1002 EXPECT_NE(MSG_ROUTING_NONE, connector2->route_id());
980 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount()); 1003 EXPECT_EQ(0U, renderer_host2->QueuedMessageCount());
981 RunAllPendingInMessageLoop(); 1004 RunAllPendingInMessageLoop();
982 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount()); 1005 EXPECT_EQ(1U, renderer_host2->QueuedMessageCount());
983 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get()); 1006 CheckViewMsgWorkerCreated(renderer_host2.get(), connector2.get());
984 } 1007 }
985 1008
986 } // namespace content 1009 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698