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

Side by Side Diff: content/browser/service_worker/embedded_worker_instance_unittest.cc

Issue 118103002: Add IPC stubs between browser and ServiceWorker's worker context in the child process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "content/browser/service_worker/embedded_worker_instance.h" 7 #include "content/browser/service_worker/embedded_worker_instance.h"
8 #include "content/browser/service_worker/embedded_worker_registry.h" 8 #include "content/browser/service_worker/embedded_worker_registry.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/common/service_worker_messages.h" 10 #include "content/common/service_worker_messages.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 EXPECT_TRUE(worker->Stop()); 98 EXPECT_TRUE(worker->Stop());
99 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status()); 99 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status());
100 100
101 // Simulate an upcall from embedded worker to notify that it's stopped. 101 // Simulate an upcall from embedded worker to notify that it's stopped.
102 worker->OnStopped(); 102 worker->OnStopped();
103 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); 103 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
104 104
105 // Verify that we've sent two messages to start and terminate the worker. 105 // Verify that we've sent two messages to start and terminate the worker.
106 const MessageList& messages = fake_sender.sent_messages(); 106 const MessageList& messages = fake_sender.sent_messages();
107 ASSERT_EQ(2U, messages.size()); 107 ASSERT_EQ(2U, messages.size());
108 ASSERT_EQ(ServiceWorkerMsg_StartWorker::ID, messages[0]->type()); 108 ASSERT_EQ(EmbeddedWorkerMsg_StartWorker::ID, messages[0]->type());
109 ASSERT_EQ(ServiceWorkerMsg_TerminateWorker::ID, messages[1]->type()); 109 ASSERT_EQ(EmbeddedWorkerMsg_StopWorker::ID, messages[1]->type());
110 } 110 }
111 111
112 TEST_F(EmbeddedWorkerInstanceTest, ChooseProcess) { 112 TEST_F(EmbeddedWorkerInstanceTest, ChooseProcess) {
113 scoped_ptr<EmbeddedWorkerInstance> worker = 113 scoped_ptr<EmbeddedWorkerInstance> worker =
114 embedded_worker_registry()->CreateWorker(); 114 embedded_worker_registry()->CreateWorker();
115 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); 115 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
116 116
117 FakeSender fake_sender; 117 FakeSender fake_sender;
118 118
119 // Simulate adding processes to the worker. 119 // Simulate adding processes to the worker.
120 // Process 1 has 1 ref, 2 has 2 refs and 3 has 3 refs. 120 // Process 1 has 1 ref, 2 has 2 refs and 3 has 3 refs.
121 worker->AddProcessReference(1); 121 worker->AddProcessReference(1);
122 worker->AddProcessReference(2); 122 worker->AddProcessReference(2);
123 worker->AddProcessReference(2); 123 worker->AddProcessReference(2);
124 worker->AddProcessReference(3); 124 worker->AddProcessReference(3);
125 worker->AddProcessReference(3); 125 worker->AddProcessReference(3);
126 worker->AddProcessReference(3); 126 worker->AddProcessReference(3);
127 embedded_worker_registry()->AddChildProcessSender(1, &fake_sender); 127 embedded_worker_registry()->AddChildProcessSender(1, &fake_sender);
128 embedded_worker_registry()->AddChildProcessSender(2, &fake_sender); 128 embedded_worker_registry()->AddChildProcessSender(2, &fake_sender);
129 embedded_worker_registry()->AddChildProcessSender(3, &fake_sender); 129 embedded_worker_registry()->AddChildProcessSender(3, &fake_sender);
130 130
131 // Process 3 has the biggest # of references and it should be chosen. 131 // Process 3 has the biggest # of references and it should be chosen.
132 EXPECT_TRUE(worker->Start(1L, GURL("http://example.com/worker.js"))); 132 EXPECT_TRUE(worker->Start(1L, GURL("http://example.com/worker.js")));
133 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status()); 133 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status());
134 EXPECT_EQ(3, worker->process_id()); 134 EXPECT_EQ(3, worker->process_id());
135 } 135 }
136 136
137 } // namespace content 137 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/embedded_worker_instance.cc ('k') | content/browser/service_worker/embedded_worker_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698