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

Side by Side Diff: content/browser/service_worker/service_worker_version_unittest.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, 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "content/browser/service_worker/embedded_worker_registry.h" 7 #include "content/browser/service_worker/embedded_worker_registry.h"
8 #include "content/browser/service_worker/embedded_worker_test_helper.h" 8 #include "content/browser/service_worker/embedded_worker_test_helper.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_registration.h" 10 #include "content/browser/service_worker/service_worker_registration.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } // namespace 112 } // namespace
113 113
114 class ServiceWorkerVersionTest : public testing::Test { 114 class ServiceWorkerVersionTest : public testing::Test {
115 protected: 115 protected:
116 ServiceWorkerVersionTest() 116 ServiceWorkerVersionTest()
117 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} 117 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
118 118
119 virtual void SetUp() OVERRIDE { 119 virtual void SetUp() OVERRIDE {
120 helper_.reset(new MessageReceiver()); 120 helper_.reset(new MessageReceiver());
121 121
122 scope_ = GURL("http://www.example.com/*");
dominicc (has gone to gerrit) 2014/08/06 06:48:18 Here too.
xiang 2014/08/11 04:50:55 Done.
122 registration_ = new ServiceWorkerRegistration( 123 registration_ = new ServiceWorkerRegistration(
123 GURL("http://www.example.com/*"), 124 scope_,
124 GURL("http://www.example.com/service_worker.js"), 125 GURL("http://www.example.com/service_worker.js"),
125 1L, 126 1L,
126 helper_->context()->AsWeakPtr()); 127 helper_->context()->AsWeakPtr());
127 version_ = new ServiceWorkerVersion( 128 version_ = new ServiceWorkerVersion(
128 registration_, 1L, helper_->context()->AsWeakPtr()); 129 registration_, 1L, helper_->context()->AsWeakPtr());
129 130
130 // Simulate adding one process to the worker. 131 // Simulate adding one process to the scope.
131 int embedded_worker_id = version_->embedded_worker()->embedded_worker_id(); 132 helper_->SimulateAddProcessToScope(scope_, kRenderProcessId);
132 helper_->SimulateAddProcessToWorker(embedded_worker_id, kRenderProcessId); 133 ASSERT_TRUE(HasProcessToRun());
133 ASSERT_TRUE(version_->HasProcessToRun());
134 } 134 }
135 135
136 virtual void TearDown() OVERRIDE { 136 virtual void TearDown() OVERRIDE {
137 version_ = 0; 137 version_ = 0;
138 registration_ = 0; 138 registration_ = 0;
139 helper_.reset(); 139 helper_.reset();
140 } 140 }
141 141
142 bool HasProcessToRun() const {
143 return helper_->context()->process_manager()->ScopeHasProcessToRun(scope_);
144 }
145
142 TestBrowserThreadBundle thread_bundle_; 146 TestBrowserThreadBundle thread_bundle_;
143 scoped_ptr<MessageReceiver> helper_; 147 scoped_ptr<MessageReceiver> helper_;
144 scoped_refptr<ServiceWorkerRegistration> registration_; 148 scoped_refptr<ServiceWorkerRegistration> registration_;
145 scoped_refptr<ServiceWorkerVersion> version_; 149 scoped_refptr<ServiceWorkerVersion> version_;
150 GURL scope_;
146 151
147 private: 152 private:
148 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest); 153 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersionTest);
149 }; 154 };
150 155
151 TEST_F(ServiceWorkerVersionTest, ConcurrentStartAndStop) { 156 TEST_F(ServiceWorkerVersionTest, ConcurrentStartAndStop) {
152 // Call StartWorker() multiple times. 157 // Call StartWorker() multiple times.
153 ServiceWorkerStatusCode status1 = SERVICE_WORKER_ERROR_FAILED; 158 ServiceWorkerStatusCode status1 = SERVICE_WORKER_ERROR_FAILED;
154 ServiceWorkerStatusCode status2 = SERVICE_WORKER_ERROR_FAILED; 159 ServiceWorkerStatusCode status2 = SERVICE_WORKER_ERROR_FAILED;
155 ServiceWorkerStatusCode status3 = SERVICE_WORKER_ERROR_FAILED; 160 ServiceWorkerStatusCode status3 = SERVICE_WORKER_ERROR_FAILED;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 ASSERT_EQ(5U, statuses.size()); 325 ASSERT_EQ(5U, statuses.size());
321 ASSERT_EQ(ServiceWorkerVersion::INSTALLING, statuses[0]); 326 ASSERT_EQ(ServiceWorkerVersion::INSTALLING, statuses[0]);
322 ASSERT_EQ(ServiceWorkerVersion::INSTALLED, statuses[1]); 327 ASSERT_EQ(ServiceWorkerVersion::INSTALLED, statuses[1]);
323 ASSERT_EQ(ServiceWorkerVersion::ACTIVATING, statuses[2]); 328 ASSERT_EQ(ServiceWorkerVersion::ACTIVATING, statuses[2]);
324 ASSERT_EQ(ServiceWorkerVersion::ACTIVATED, statuses[3]); 329 ASSERT_EQ(ServiceWorkerVersion::ACTIVATED, statuses[3]);
325 ASSERT_EQ(ServiceWorkerVersion::REDUNDANT, statuses[4]); 330 ASSERT_EQ(ServiceWorkerVersion::REDUNDANT, statuses[4]);
326 } 331 }
327 332
328 TEST_F(ServiceWorkerVersionTest, AddAndRemoveProcesses) { 333 TEST_F(ServiceWorkerVersionTest, AddAndRemoveProcesses) {
329 // Preparation (to reset the process count to 0). 334 // Preparation (to reset the process count to 0).
330 ASSERT_TRUE(version_->HasProcessToRun()); 335 ASSERT_TRUE(HasProcessToRun());
331 version_->RemoveProcessFromWorker(kRenderProcessId); 336 version_->RemoveProcessFromWorker(kRenderProcessId);
332 ASSERT_FALSE(version_->HasProcessToRun()); 337 ASSERT_FALSE(HasProcessToRun());
333 338
334 // Add another process to the worker twice, and then remove process once. 339 // Add another process to the worker twice, and then remove process once.
335 const int another_process_id = kRenderProcessId + 1; 340 const int another_process_id = kRenderProcessId + 1;
336 version_->AddProcessToWorker(another_process_id); 341 version_->AddProcessToWorker(another_process_id);
337 version_->AddProcessToWorker(another_process_id); 342 version_->AddProcessToWorker(another_process_id);
338 version_->RemoveProcessFromWorker(another_process_id); 343 version_->RemoveProcessFromWorker(another_process_id);
339 344
340 // We're ref-counting the process internally, so adding the same process 345 // We're ref-counting the process internally, so adding the same process
341 // multiple times should be handled correctly. 346 // multiple times should be handled correctly.
342 ASSERT_TRUE(version_->HasProcessToRun()); 347 ASSERT_TRUE(HasProcessToRun());
343 348
344 // Removing the process again (so that # of AddProcess == # of RemoveProcess 349 // Removing the process again (so that # of AddProcess == # of RemoveProcess
345 // for the process) should remove all process references. 350 // for the process) should remove all process references.
346 version_->RemoveProcessFromWorker(another_process_id); 351 version_->RemoveProcessFromWorker(another_process_id);
347 ASSERT_FALSE(version_->HasProcessToRun()); 352 ASSERT_FALSE(HasProcessToRun());
348 } 353 }
349 354
350 TEST_F(ServiceWorkerVersionTest, ScheduleStopWorker) { 355 TEST_F(ServiceWorkerVersionTest, ScheduleStopWorker) {
351 // Verify the timer is not running when version initializes its status. 356 // Verify the timer is not running when version initializes its status.
352 version_->SetStatus(ServiceWorkerVersion::ACTIVATED); 357 version_->SetStatus(ServiceWorkerVersion::ACTIVATED);
353 EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); 358 EXPECT_FALSE(version_->stop_worker_timer_.IsRunning());
354 359
355 // Verify the timer is running when version status changes frome ACTIVATING 360 // Verify the timer is running when version status changes frome ACTIVATING
356 // to ACTIVATED. 361 // to ACTIVATED.
357 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED; 362 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_FAILED;
(...skipping 23 matching lines...) Expand all
381 NULL)); 386 NULL));
382 version_->AddControllee(host.get()); 387 version_->AddControllee(host.get());
383 EXPECT_FALSE(version_->stop_worker_timer_.IsRunning()); 388 EXPECT_FALSE(version_->stop_worker_timer_.IsRunning());
384 389
385 // The timer should be running if the controllee is removed. 390 // The timer should be running if the controllee is removed.
386 version_->RemoveControllee(host.get()); 391 version_->RemoveControllee(host.get());
387 EXPECT_TRUE(version_->stop_worker_timer_.IsRunning()); 392 EXPECT_TRUE(version_->stop_worker_timer_.IsRunning());
388 } 393 }
389 394
390 } // namespace content 395 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698