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

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: Created 6 years, 3 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 RunOnIOThread(base::Bind(&self::TearDownOnIOThread, this)); 287 RunOnIOThread(base::Bind(&self::TearDownOnIOThread, this));
288 wrapper_ = NULL; 288 wrapper_ = NULL;
289 } 289 }
290 290
291 virtual void SetUpOnIOThread() {} 291 virtual void SetUpOnIOThread() {}
292 virtual void TearDownOnIOThread() {} 292 virtual void TearDownOnIOThread() {}
293 293
294 ServiceWorkerContextWrapper* wrapper() { return wrapper_.get(); } 294 ServiceWorkerContextWrapper* wrapper() { return wrapper_.get(); }
295 ServiceWorkerContext* public_context() { return wrapper(); } 295 ServiceWorkerContext* public_context() { return wrapper(); }
296 296
297 void AssociateRendererProcessToWorker(EmbeddedWorkerInstance* worker) { 297 void AssociateRendererProcessToPattern(const GURL& pattern) {
298 worker->AddProcessReference( 298 wrapper_->process_manager()->AddProcessReferenceToPattern(
299 shell()->web_contents()->GetRenderProcessHost()->GetID()); 299 pattern, shell()->web_contents()->GetRenderProcessHost()->GetID());
300 } 300 }
301 301
302 private: 302 private:
303 scoped_refptr<ServiceWorkerContextWrapper> wrapper_; 303 scoped_refptr<ServiceWorkerContextWrapper> wrapper_;
304 }; 304 };
305 305
306 class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest, 306 class EmbeddedWorkerBrowserTest : public ServiceWorkerBrowserTest,
307 public EmbeddedWorkerInstance::Listener { 307 public EmbeddedWorkerInstance::Listener {
308 public: 308 public:
309 typedef EmbeddedWorkerBrowserTest self; 309 typedef EmbeddedWorkerBrowserTest self;
310 310
311 EmbeddedWorkerBrowserTest() 311 EmbeddedWorkerBrowserTest()
312 : last_worker_status_(EmbeddedWorkerInstance::STOPPED), 312 : last_worker_status_(EmbeddedWorkerInstance::STOPPED),
313 pause_mode_(DONT_PAUSE) {} 313 pause_mode_(DONT_PAUSE) {}
314 virtual ~EmbeddedWorkerBrowserTest() {} 314 virtual ~EmbeddedWorkerBrowserTest() {}
315 315
316 virtual void TearDownOnIOThread() OVERRIDE { 316 virtual void TearDownOnIOThread() OVERRIDE {
317 if (worker_) { 317 if (worker_) {
318 worker_->RemoveListener(this); 318 worker_->RemoveListener(this);
319 worker_.reset(); 319 worker_.reset();
320 } 320 }
321 } 321 }
322 322
323 void StartOnIOThread() { 323 void StartOnIOThread() {
324 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 324 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
325 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker(); 325 worker_ = wrapper()->context()->embedded_worker_registry()->CreateWorker();
326 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status()); 326 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker_->status());
327 worker_->AddListener(this); 327 worker_->AddListener(this);
328 328
329 AssociateRendererProcessToWorker(worker_.get());
330 329
331 const int64 service_worker_version_id = 33L; 330 const int64 service_worker_version_id = 33L;
332 const GURL scope = embedded_test_server()->GetURL("/"); 331 const GURL pattern = embedded_test_server()->GetURL("/");
333 const GURL script_url = embedded_test_server()->GetURL( 332 const GURL script_url = embedded_test_server()->GetURL(
334 "/service_worker/worker.js"); 333 "/service_worker/worker.js");
335 std::vector<int> processes; 334 AssociateRendererProcessToPattern(pattern);
336 processes.push_back( 335 int process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
337 shell()->web_contents()->GetRenderProcessHost()->GetID()); 336 wrapper()->process_manager()->AddProcessReferenceToPattern(
337 pattern, process_id);
338 worker_->Start( 338 worker_->Start(
339 service_worker_version_id, 339 service_worker_version_id,
340 scope, 340 pattern,
341 script_url, 341 script_url,
342 pause_mode_ != DONT_PAUSE, 342 pause_mode_ != DONT_PAUSE,
343 processes,
344 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this)); 343 base::Bind(&EmbeddedWorkerBrowserTest::StartOnIOThread2, this));
345 } 344 }
346 void StartOnIOThread2(ServiceWorkerStatusCode status) { 345 void StartOnIOThread2(ServiceWorkerStatusCode status) {
347 last_worker_status_ = worker_->status(); 346 last_worker_status_ = worker_->status();
348 EXPECT_EQ(SERVICE_WORKER_OK, status); 347 EXPECT_EQ(SERVICE_WORKER_OK, status);
349 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_); 348 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, last_worker_status_);
350 349
351 if (status != SERVICE_WORKER_OK && !done_closure_.is_null()) 350 if (status != SERVICE_WORKER_OK && !done_closure_.is_null())
352 done_closure_.Run(); 351 done_closure_.Run();
353 } 352 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 void FetchTestHelper(const std::string& worker_url, 495 void FetchTestHelper(const std::string& worker_url,
497 ServiceWorkerFetchEventResult* result, 496 ServiceWorkerFetchEventResult* result,
498 ServiceWorkerResponse* response, 497 ServiceWorkerResponse* response,
499 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) { 498 scoped_ptr<storage::BlobDataHandle>* blob_data_handle) {
500 RunOnIOThread( 499 RunOnIOThread(
501 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url)); 500 base::Bind(&self::SetUpRegistrationOnIOThread, this, worker_url));
502 FetchOnRegisteredWorker(result, response, blob_data_handle); 501 FetchOnRegisteredWorker(result, response, blob_data_handle);
503 } 502 }
504 503
505 void SetUpRegistrationOnIOThread(const std::string& worker_url) { 504 void SetUpRegistrationOnIOThread(const std::string& worker_url) {
505 const GURL pattern = embedded_test_server()->GetURL("/");
506 registration_ = new ServiceWorkerRegistration( 506 registration_ = new ServiceWorkerRegistration(
507 embedded_test_server()->GetURL("/"), 507 pattern,
508 wrapper()->context()->storage()->NewRegistrationId(), 508 wrapper()->context()->storage()->NewRegistrationId(),
509 wrapper()->context()->AsWeakPtr()); 509 wrapper()->context()->AsWeakPtr());
510 version_ = new ServiceWorkerVersion( 510 version_ = new ServiceWorkerVersion(
511 registration_.get(), 511 registration_.get(),
512 embedded_test_server()->GetURL(worker_url), 512 embedded_test_server()->GetURL(worker_url),
513 wrapper()->context()->storage()->NewVersionId(), 513 wrapper()->context()->storage()->NewVersionId(),
514 wrapper()->context()->AsWeakPtr()); 514 wrapper()->context()->AsWeakPtr());
515 AssociateRendererProcessToWorker(version_->embedded_worker()); 515 AssociateRendererProcessToPattern(pattern);
516 } 516 }
517 517
518 void StartOnIOThread(const base::Closure& done, 518 void StartOnIOThread(const base::Closure& done,
519 ServiceWorkerStatusCode* result) { 519 ServiceWorkerStatusCode* result) {
520 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 520 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
521 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result)); 521 version_->StartWorker(CreateReceiver(BrowserThread::UI, done, result));
522 } 522 }
523 523
524 void InstallOnIOThread(const base::Closure& done, 524 void InstallOnIOThread(const base::Closure& done,
525 ServiceWorkerStatusCode* result) { 525 ServiceWorkerStatusCode* result) {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 RunOnIOThread( 946 RunOnIOThread(
947 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO, 947 base::Bind(&ServiceWorkerBlackBoxBrowserTest::FindRegistrationOnIO,
948 this, 948 this,
949 embedded_test_server()->GetURL("/service_worker/empty.html"), 949 embedded_test_server()->GetURL("/service_worker/empty.html"),
950 &status)); 950 &status));
951 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status); 951 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, status);
952 } 952 }
953 } 953 }
954 954
955 } // namespace content 955 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698