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

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: Null out browser_context_ in Shutdown Created 6 years, 8 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()),
21 next_thread_id_(0), 24 next_thread_id_(0),
22 weak_factory_(this) { 25 weak_factory_(this) {
26 wrapper_->Init(base::FilePath(), NULL);
23 registry()->AddChildProcessSender(mock_render_process_id, this); 27 registry()->AddChildProcessSender(mock_render_process_id, this);
28 ServiceWorkerContextWrapper::ResetWorkerRefCountOperationsForTest(
29 base::Bind(AlwaysTrue), base::Bind(AlwaysTrue));
24 } 30 }
25 31
26 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() { 32 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() {
33 ServiceWorkerContextWrapper::ResetWorkerRefCountOperationsForTest();
34 if (wrapper_)
35 wrapper_->Shutdown();
27 } 36 }
28 37
29 void EmbeddedWorkerTestHelper::SimulateAddProcessToWorker( 38 void EmbeddedWorkerTestHelper::SimulateAddProcessToWorker(
30 int embedded_worker_id, 39 int embedded_worker_id,
31 int process_id) { 40 int process_id) {
32 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 41 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
33 ASSERT_TRUE(worker); 42 ASSERT_TRUE(worker);
34 registry()->AddChildProcessSender(process_id, this); 43 registry()->AddChildProcessSender(process_id, this);
35 worker->AddProcessReference(process_id); 44 worker->AddProcessReference(process_id);
36 } 45 }
(...skipping 14 matching lines...) Expand all
51 IPC_MESSAGE_UNHANDLED(handled = false) 60 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP() 61 IPC_END_MESSAGE_MAP()
53 62
54 // IPC::TestSink only records messages that are not handled by filters, 63 // IPC::TestSink only records messages that are not handled by filters,
55 // so we just forward all messages to the separate sink. 64 // so we just forward all messages to the separate sink.
56 sink_.OnMessageReceived(message); 65 sink_.OnMessageReceived(message);
57 66
58 return handled; 67 return handled;
59 } 68 }
60 69
70 ServiceWorkerContextCore* EmbeddedWorkerTestHelper::context() {
71 return wrapper_->context();
72 }
73
74 void EmbeddedWorkerTestHelper::ShutdownContext() {
75 wrapper_->Shutdown();
76 wrapper_ = NULL;
77 }
78
61 void EmbeddedWorkerTestHelper::OnStartWorker( 79 void EmbeddedWorkerTestHelper::OnStartWorker(
62 int embedded_worker_id, 80 int embedded_worker_id,
63 int64 service_worker_version_id, 81 int64 service_worker_version_id,
64 const GURL& scope, 82 const GURL& scope,
65 const GURL& script_url) { 83 const GURL& script_url) {
66 // By default just notify the sender that the worker is started. 84 // By default just notify the sender that the worker is started.
67 SimulateWorkerStarted(next_thread_id_++, embedded_worker_id); 85 SimulateWorkerStarted(next_thread_id_++, embedded_worker_id);
68 } 86 }
69 87
70 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) { 88 void EmbeddedWorkerTestHelper::OnStopWorker(int embedded_worker_id) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 base::MessageLoopProxy::current()->PostTask( 230 base::MessageLoopProxy::current()->PostTask(
213 FROM_HERE, 231 FROM_HERE,
214 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent, 232 base::Bind(&EmbeddedWorkerTestHelper::OnFetchEvent,
215 weak_factory_.GetWeakPtr(), 233 weak_factory_.GetWeakPtr(),
216 current_embedded_worker_id_, 234 current_embedded_worker_id_,
217 request_id, 235 request_id,
218 request)); 236 request));
219 } 237 }
220 238
221 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { 239 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() {
222 DCHECK(context_); 240 DCHECK(context());
223 return context_->embedded_worker_registry(); 241 return context()->embedded_worker_registry();
224 } 242 }
225 243
226 } // namespace content 244 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698