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

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

Issue 238043002: Teach EmbeddedWorkerInstance to create a process when it needs one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle 2 places where context_ could be NULL. Created 6 years, 7 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 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/service_worker/embedded_worker_test_helper.h" 5 #include "content/browser/service_worker/embedded_worker_test_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/service_worker/embedded_worker_instance.h" 8 #include "content/browser/service_worker/embedded_worker_instance.h"
9 #include "content/browser/service_worker/embedded_worker_registry.h" 9 #include "content/browser/service_worker/embedded_worker_registry.h"
10 #include "content/browser/service_worker/service_worker_context_core.h" 10 #include "content/browser/service_worker/service_worker_context_core.h"
11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
11 #include "content/common/service_worker/embedded_worker_messages.h" 12 #include "content/common/service_worker/embedded_worker_messages.h"
12 #include "content/common/service_worker/service_worker_messages.h" 13 #include "content/common/service_worker/service_worker_messages.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper( 18 static bool AlwaysTrue(int process_id) {
18 ServiceWorkerContextCore* context, 19 return true;
19 int mock_render_process_id) 20 }
20 : context_(context->AsWeakPtr()), 21
22 EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper(int mock_render_process_id)
23 : wrapper_(new ServiceWorkerContextWrapper(NULL)),
21 next_thread_id_(0), 24 next_thread_id_(0),
22 weak_factory_(this) { 25 weak_factory_(this) {
26 wrapper_->Init(base::FilePath(), NULL);
27 scoped_ptr<ServiceWorkerProcessManager> process_manager(
28 new ServiceWorkerProcessManager(wrapper_));
29 process_manager->SetProcessRefcountOpsForTest(base::Bind(AlwaysTrue),
30 base::Bind(AlwaysTrue));
31 wrapper_->context()->SetProcessManagerForTest(process_manager.Pass());
23 registry()->AddChildProcessSender(mock_render_process_id, this); 32 registry()->AddChildProcessSender(mock_render_process_id, this);
24 } 33 }
25 34
26 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() { 35 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() {
36 if (wrapper_)
37 wrapper_->Shutdown();
27 } 38 }
28 39
29 void EmbeddedWorkerTestHelper::SimulateAddProcessToWorker( 40 void EmbeddedWorkerTestHelper::SimulateAddProcessToWorker(
30 int embedded_worker_id, 41 int embedded_worker_id,
31 int process_id) { 42 int process_id) {
32 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 43 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
33 ASSERT_TRUE(worker); 44 ASSERT_TRUE(worker);
34 registry()->AddChildProcessSender(process_id, this); 45 registry()->AddChildProcessSender(process_id, this);
35 worker->AddProcessReference(process_id); 46 worker->AddProcessReference(process_id);
36 } 47 }
(...skipping 14 matching lines...) Expand all
51 IPC_MESSAGE_UNHANDLED(handled = false) 62 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP() 63 IPC_END_MESSAGE_MAP()
53 64
54 // IPC::TestSink only records messages that are not handled by filters, 65 // IPC::TestSink only records messages that are not handled by filters,
55 // so we just forward all messages to the separate sink. 66 // so we just forward all messages to the separate sink.
56 sink_.OnMessageReceived(message); 67 sink_.OnMessageReceived(message);
57 68
58 return handled; 69 return handled;
59 } 70 }
60 71
72 ServiceWorkerContextCore* EmbeddedWorkerTestHelper::context() {
73 return wrapper_->context();
74 }
75
76 void EmbeddedWorkerTestHelper::ShutdownContext() {
77 wrapper_->Shutdown();
78 wrapper_ = NULL;
79 }
80
61 void EmbeddedWorkerTestHelper::OnStartWorker( 81 void EmbeddedWorkerTestHelper::OnStartWorker(
62 int embedded_worker_id, 82 int embedded_worker_id,
63 int64 service_worker_version_id, 83 int64 service_worker_version_id,
64 const GURL& scope, 84 const GURL& scope,
65 const GURL& script_url) { 85 const GURL& script_url) {
66 // By default just notify the sender that the worker is started. 86 // By default just notify the sender that the worker is started.
67 SimulateWorkerStarted(next_thread_id_++, embedded_worker_id); 87 SimulateWorkerStarted(next_thread_id_++, embedded_worker_id);
68 } 88 }
69 89
70 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) { 90 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 base::MessageLoopProxy::current()->PostTask( 232 base::MessageLoopProxy::current()->PostTask(
213 FROM_HERE, 233 FROM_HERE,
214 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent, 234 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent,
215 weak_factory_.GetWeakPtr(), 235 weak_factory_.GetWeakPtr(),
216 current_embedded_worker_id_, 236 current_embedded_worker_id_,
217 request_id, 237 request_id,
218 request)); 238 request));
219 } 239 }
220 240
221 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { 241 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() {
222 DCHECK(context_); 242 DCHECK(context());
223 return context_->embedded_worker_registry(); 243 return context()->embedded_worker_registry();
224 } 244 }
225 245
226 } // namespace content 246 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698