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

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

Issue 443593002: ServiceWorker: Move worker candidate process knowledge to ServiceWorkerProcessManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: RPH observer DCHECK and browser tests build fix Created 6 years, 4 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/fileapi/chrome_blob_storage_context.h" 10 #include "content/browser/fileapi/chrome_blob_storage_context.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 RunOnIOThread(base::Bind(&self::TearDownOnIOThread, this)); 203 RunOnIOThread(base::Bind(&self::TearDownOnIOThread, this));
204 wrapper_ = NULL; 204 wrapper_ = NULL;
205 } 205 }
206 206
207 virtual void SetUpOnIOThread() {} 207 virtual void SetUpOnIOThread() {}
208 virtual void TearDownOnIOThread() {} 208 virtual void TearDownOnIOThread() {}
209 209
210 ServiceWorkerContextWrapper* wrapper() { return wrapper_.get(); } 210 ServiceWorkerContextWrapper* wrapper() { return wrapper_.get(); }
211 ServiceWorkerContext* public_context() { return wrapper(); } 211 ServiceWorkerContext* public_context() { return wrapper(); }
212 212
213 void AssociateRendererProcessToWorker(EmbeddedWorkerInstance* worker) { 213 void AssociateRendererProcessToScope(const GURL& scope) {
214 worker->AddProcessReference( 214 wrapper_->process_manager()->AddScopeProcessReference(
215 shell()->web_contents()->GetRenderProcessHost()->GetID()); 215 scope, shell()->web_contents()->GetRenderProcessHost()->GetID());
216 } 216 }
217 217
218 private: 218 private:
219 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 219 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
220 }; 220 };
221 221
222 class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest, 222 class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest,
223 public EmbeddedWorkerInstance::Listener { 223 public EmbeddedWorkerInstance::Listener {
224 public: 224 public:
225 typedef EmbeddedWorkerBrowserTest self; 225 typedef EmbeddedWorkerBrowserTest self;
226 226
227 EmbeddedWorkerBrowserTest() 227 EmbeddedWorkerBrowserTest()
228 : last_worker_status_(EmbeddedWorkerInstance::STOPPED), 228 : last_worker_status_(EmbeddedWorkerInstance::STOPPED),
229 pause_mode_(DONT_PAUSE) {} 229 pause_mode_(DONT_PAUSE) {}
230 virtual ~EmbeddedWorkerBrowserTest() {} 230 virtual ~EmbeddedWorkerBrowserTest() {}
231 231
232 virtual void TearDownOnIOThread() OVERRIDE { 232 virtual void TearDownOnIOThread() OVERRIDE {
233 if (worker_) { 233 if (worker_) {
234 worker_->RemoveListener(this); 234 worker_->RemoveListener(this);
235 worker_.reset(); 235 worker_.reset();
236 } 236 }
237 } 237 }
238 238
239 void StartOnIOThread() { 239 void StartOnIOThread() {
240 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 240 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
241 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); 241 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker();
242 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); 242 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status());
243 worker_->AddListener(this); 243 worker_->AddListener(this);
244 244
245 AssociateRendererProcessToWorker(worker_.get());
246 245
247 const int64 service_worker_version_id = 33L; 246 const int64 service_worker_version_id = 33L;
248 const GURL scope = embedded_test_server()->GetURL("/"); 247 const GURL scope = embedded_test_server()->GetURL("/");
249 const GURL script_url = embedded_test_server()->GetURL( 248 const GURL script_url = embedded_test_server()->GetURL(
250 "/service_worker/worker.js"); 249 "/service_worker/worker.js");
250 AssociateRendererProcessToScope(scope);
251 std::vector<int> processes; 251 std::vector<int> processes;
252 processes.push_back( 252 processes.push_back(
253 shell()->web_contents()->GetRenderProcessHost()->GetID()); 253 shell()->web_contents()->GetRenderProcessHost()->GetID());
254 wrapper()->process_manager()->AddScopePendingProcesses(scope, processes);
254 worker_->Start( 255 worker_->Start(
255 service_worker_version_id, 256 service_worker_version_id,
256 scope, 257 scope,
257 script_url, 258 script_url,
258 pause_mode_ != DONT_PAUSE, 259 pause_mode_ != DONT_PAUSE,
259 processes,
260 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this)); 260 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this));
261 } 261 }
262 void StartOnIOThread2(ServiceWorkerStatusCode status) { 262 void StartOnIOThread2(ServiceWorkerStatusCode status) {
263 last_worker_status_ = worker_->status(); 263 last_worker_status_ = worker_->status();
264 EXPECT_EQ(SERVICE_WORKER_OK, status); 264 EXPECT_EQ(SERVICE_WORKER_OK, status);
265 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_); 265 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_);
266 266
267 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) 267 if (status != SERVICE_WORKER_OK && !done_closure_.is_null())
268 done_closure_.Run(); 268 done_closure_.Run();
269 } 269 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 const std::string& worker_url, 410 const std::string& worker_url,
411 ServiceWorkerFetchEventResult* result, 411 ServiceWorkerFetchEventResult* result,
412 ServiceWorkerResponse* response, 412 ServiceWorkerResponse* response,
413 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) { 413 scoped_ptr<webkit_blob::BlobDataHandle>* blob_data_handle) {
414 RunOnIOThread( 414 RunOnIOThread(
415 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); 415 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
416 FetchOnRegisteredWorker(result, response, blob_data_handle); 416 FetchOnRegisteredWorker(result, response, blob_data_handle);
417 } 417 }
418 418
419 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 419 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
420 const GURL scope = embedded_test_server()->GetURL("/");
420 registration_ = new ServiceWorkerRegistration( 421 registration_ = new ServiceWorkerRegistration(
421 embedded_test_server()->GetURL("/"), 422 scope,
422 embedded_test_server()->GetURL(worker_url), 423 embedded_test_server()->GetURL(worker_url),
423 wrapper()->context()->storage()->NewRegistrationId(), 424 wrapper()->context()->storage()->NewRegistrationId(),
424 wrapper()->context()->AsWeakPtr()); 425 wrapper()->context()->AsWeakPtr());
425 version_ = new ServiceWorkerVersion( 426 version_ = new ServiceWorkerVersion(
426 registration_, 427 registration_,
427 wrapper()->context()->storage()->NewVersionId(), 428 wrapper()->context()->storage()->NewVersionId(),
428 wrapper()->context()->AsWeakPtr()); 429 wrapper()->context()->AsWeakPtr());
429 AssociateRendererProcessToWorker(version_->embedded_worker()); 430 AssociateRendererProcessToScope(scope);
430 } 431 }
431 432
432 void StartOnIOThread(const base::Closure& done, 433 void StartOnIOThread(const base::Closure& done,
433 ServiceWorkerStatusCode* result) { 434 ServiceWorkerStatusCode* result) {
434 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 435 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
435 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); 436 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result));
436 } 437 }
437 438
438 void InstallOnIOThread(const base::Closure& done, 439 void InstallOnIOThread(const base::Closure& done,
439 ServiceWorkerStatusCode* result) { 440 ServiceWorkerStatusCode* result) {
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 829 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
829 this, 830 this,
830 embedded_test_server()->GetURL("/service_worker/empty.html"), 831 embedded_test_server()->GetURL("/service_worker/empty.html"),
831 &status, 832 &status,
832 &script_url)); 833 &script_url));
833 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 834 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
834 } 835 }
835 } 836 }
836 837
837 } // namespace content 838 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698