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

Side by Side Diff: content/browser/service_worker/service_worker_job_unittest.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 "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.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/embedded_worker_test_helper.h" 10 #include "content/browser/service_worker/embedded_worker_test_helper.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 } // namespace 88 } // namespace
89 89
90 class ServiceWorkerJobTest : public testing::Test { 90 class ServiceWorkerJobTest : public testing::Test {
91 public: 91 public:
92 ServiceWorkerJobTest() 92 ServiceWorkerJobTest()
93 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 93 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
94 render_process_id_(88) {} 94 render_process_id_(88) {}
95 95
96 virtual void SetUp() OVERRIDE { 96 virtual void SetUp() OVERRIDE {
97 context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL, NULL)); 97 helper_.reset(new EmbeddedWorkerTestHelper(render_process_id_));
98 helper_.reset(new EmbeddedWorkerTestHelper(context_.get(),
99 render_process_id_));
100 } 98 }
101 99
102 virtual void TearDown() OVERRIDE { 100 virtual void TearDown() OVERRIDE {
103 helper_.reset(); 101 helper_.reset();
104 context_.reset();
105 } 102 }
106 103
104 ServiceWorkerContextCore* context() const { return helper_->context(); }
105
107 ServiceWorkerJobCoordinator* job_coordinator() const { 106 ServiceWorkerJobCoordinator* job_coordinator() const {
108 return context_->job_coordinator(); 107 return context()->job_coordinator();
109 } 108 }
110 ServiceWorkerStorage* storage() const { return context_->storage(); } 109 ServiceWorkerStorage* storage() const { return context()->storage(); }
111 110
112 protected: 111 protected:
113 TestBrowserThreadBundle browser_thread_bundle_; 112 TestBrowserThreadBundle browser_thread_bundle_;
114 scoped_ptr<ServiceWorkerContextCore> context_;
115 scoped_ptr<EmbeddedWorkerTestHelper> helper_; 113 scoped_ptr<EmbeddedWorkerTestHelper> helper_;
116 114
117 int render_process_id_; 115 int render_process_id_;
118 }; 116 };
119 117
120 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { 118 TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
121 scoped_refptr<ServiceWorkerRegistration> original_registration; 119 scoped_refptr<ServiceWorkerRegistration> original_registration;
122 bool called; 120 bool called;
123 job_coordinator()->Register( 121 job_coordinator()->Register(
124 GURL("http://www.example.com/*"), 122 GURL("http://www.example.com/*"),
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 389
392 ASSERT_FALSE(called); 390 ASSERT_FALSE(called);
393 base::RunLoop().RunUntilIdle(); 391 base::RunLoop().RunUntilIdle();
394 ASSERT_TRUE(called); 392 ASSERT_TRUE(called);
395 393
396 ASSERT_EQ(new_registration, old_registration); 394 ASSERT_EQ(new_registration, old_registration);
397 } 395 }
398 396
399 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { 397 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper {
400 public: 398 public:
401 FailToStartWorkerTestHelper(ServiceWorkerContextCore* context, 399 FailToStartWorkerTestHelper(int mock_render_process_id)
402 int mock_render_process_id) 400 : EmbeddedWorkerTestHelper(mock_render_process_id) {}
403 : EmbeddedWorkerTestHelper(context, mock_render_process_id) {}
404 401
405 virtual void OnStartWorker(int embedded_worker_id, 402 virtual void OnStartWorker(int embedded_worker_id,
406 int64 service_worker_version_id, 403 int64 service_worker_version_id,
407 const GURL& scope, 404 const GURL& scope,
408 const GURL& script_url) OVERRIDE { 405 const GURL& script_url) OVERRIDE {
409 // Simulate failure by sending worker stopped instead of started. 406 // Simulate failure by sending worker stopped instead of started.
410 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); 407 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id);
411 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); 408 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id);
412 } 409 }
413 }; 410 };
414 411
415 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) { 412 TEST_F(ServiceWorkerJobTest, Register_FailToStartWorker) {
416 helper_.reset( 413 helper_.reset(new FailToStartWorkerTestHelper(render_process_id_));
417 new FailToStartWorkerTestHelper(context_.get(), render_process_id_));
418 414
419 bool called = false; 415 bool called = false;
420 scoped_refptr<ServiceWorkerRegistration> registration; 416 scoped_refptr<ServiceWorkerRegistration> registration;
421 job_coordinator()->Register( 417 job_coordinator()->Register(
422 GURL("http://www.example.com/*"), 418 GURL("http://www.example.com/*"),
423 GURL("http://www.example.com/service_worker.js"), 419 GURL("http://www.example.com/service_worker.js"),
424 render_process_id_, 420 render_process_id_,
425 SaveRegistration( 421 SaveRegistration(
426 SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, &registration)); 422 SERVICE_WORKER_ERROR_START_WORKER_FAILED, &called, &registration));
427 423
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 storage()->FindRegistrationForPattern( 584 storage()->FindRegistrationForPattern(
589 pattern, 585 pattern,
590 SaveFoundRegistration( 586 SaveFoundRegistration(
591 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, &registration)); 587 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, &registration));
592 588
593 base::RunLoop().RunUntilIdle(); 589 base::RunLoop().RunUntilIdle();
594 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); 590 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration);
595 } 591 }
596 592
597 } // namespace content 593 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698