| OLD | NEW |
| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 } // namespace | 100 } // namespace |
| 101 | 101 |
| 102 class ServiceWorkerJobTest : public testing::Test { | 102 class ServiceWorkerJobTest : public testing::Test { |
| 103 public: | 103 public: |
| 104 ServiceWorkerJobTest() | 104 ServiceWorkerJobTest() |
| 105 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 105 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
| 106 render_process_id_(kMockRenderProcessId) {} | 106 render_process_id_(kMockRenderProcessId) {} |
| 107 | 107 |
| 108 void SetUp() override { | 108 void SetUp() override { |
| 109 helper_.reset(new EmbeddedWorkerTestHelper(render_process_id_)); | 109 helper_.reset( |
| 110 new EmbeddedWorkerTestHelper(base::FilePath(), render_process_id_)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void TearDown() override { helper_.reset(); } | 113 void TearDown() override { helper_.reset(); } |
| 113 | 114 |
| 114 ServiceWorkerContextCore* context() const { return helper_->context(); } | 115 ServiceWorkerContextCore* context() const { return helper_->context(); } |
| 115 | 116 |
| 116 ServiceWorkerJobCoordinator* job_coordinator() const { | 117 ServiceWorkerJobCoordinator* job_coordinator() const { |
| 117 return context()->job_coordinator(); | 118 return context()->job_coordinator(); |
| 118 } | 119 } |
| 119 ServiceWorkerStorage* storage() const { return context()->storage(); } | 120 ServiceWorkerStorage* storage() const { return context()->storage(); } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 353 |
| 353 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = | 354 scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern = |
| 354 FindRegistrationForPattern(pattern); | 355 FindRegistrationForPattern(pattern); |
| 355 | 356 |
| 356 ASSERT_EQ(new_registration, old_registration); | 357 ASSERT_EQ(new_registration, old_registration); |
| 357 } | 358 } |
| 358 | 359 |
| 359 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { | 360 class FailToStartWorkerTestHelper : public EmbeddedWorkerTestHelper { |
| 360 public: | 361 public: |
| 361 explicit FailToStartWorkerTestHelper(int mock_render_process_id) | 362 explicit FailToStartWorkerTestHelper(int mock_render_process_id) |
| 362 : EmbeddedWorkerTestHelper(mock_render_process_id) {} | 363 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id) {} |
| 363 | 364 |
| 364 void OnStartWorker(int embedded_worker_id, | 365 void OnStartWorker(int embedded_worker_id, |
| 365 int64 service_worker_version_id, | 366 int64 service_worker_version_id, |
| 366 const GURL& scope, | 367 const GURL& scope, |
| 367 const GURL& script_url, | 368 const GURL& script_url, |
| 368 bool pause_after_download) override { | 369 bool pause_after_download) override { |
| 369 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); | 370 EmbeddedWorkerInstance* worker = registry()->GetWorker(embedded_worker_id); |
| 370 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); | 371 registry()->OnWorkerStopped(worker->process_id(), embedded_worker_id); |
| 371 } | 372 } |
| 372 }; | 373 }; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 ChangedVersionAttributesMask mask; | 777 ChangedVersionAttributesMask mask; |
| 777 ServiceWorkerRegistrationInfo info; | 778 ServiceWorkerRegistrationInfo info; |
| 778 }; | 779 }; |
| 779 | 780 |
| 780 struct StateChangeLogEntry { | 781 struct StateChangeLogEntry { |
| 781 int64 version_id; | 782 int64 version_id; |
| 782 ServiceWorkerVersion::Status status; | 783 ServiceWorkerVersion::Status status; |
| 783 }; | 784 }; |
| 784 | 785 |
| 785 UpdateJobTestHelper(int mock_render_process_id) | 786 UpdateJobTestHelper(int mock_render_process_id) |
| 786 : EmbeddedWorkerTestHelper(mock_render_process_id), | 787 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id), |
| 787 update_found_(false) {} | 788 update_found_(false) {} |
| 788 ~UpdateJobTestHelper() override { | 789 ~UpdateJobTestHelper() override { |
| 789 if (registration_.get()) | 790 if (registration_.get()) |
| 790 registration_->RemoveListener(this); | 791 registration_->RemoveListener(this); |
| 791 } | 792 } |
| 792 | 793 |
| 793 ServiceWorkerStorage* storage() { return context()->storage(); } | 794 ServiceWorkerStorage* storage() { return context()->storage(); } |
| 794 ServiceWorkerJobCoordinator* job_coordinator() { | 795 ServiceWorkerJobCoordinator* job_coordinator() { |
| 795 return context()->job_coordinator(); | 796 return context()->job_coordinator(); |
| 796 } | 797 } |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 EXPECT_EQ(NULL, registration->installing_version()); | 1251 EXPECT_EQ(NULL, registration->installing_version()); |
| 1251 EXPECT_EQ(NULL, registration->waiting_version()); | 1252 EXPECT_EQ(NULL, registration->waiting_version()); |
| 1252 EXPECT_EQ(third_version, registration->active_version()); | 1253 EXPECT_EQ(third_version, registration->active_version()); |
| 1253 EXPECT_EQ(ServiceWorkerVersion::RUNNING, third_version->running_status()); | 1254 EXPECT_EQ(ServiceWorkerVersion::RUNNING, third_version->running_status()); |
| 1254 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); | 1255 EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, third_version->status()); |
| 1255 } | 1256 } |
| 1256 | 1257 |
| 1257 class EventCallbackHelper : public EmbeddedWorkerTestHelper { | 1258 class EventCallbackHelper : public EmbeddedWorkerTestHelper { |
| 1258 public: | 1259 public: |
| 1259 explicit EventCallbackHelper(int mock_render_process_id) | 1260 explicit EventCallbackHelper(int mock_render_process_id) |
| 1260 : EmbeddedWorkerTestHelper(mock_render_process_id), | 1261 : EmbeddedWorkerTestHelper(base::FilePath(), mock_render_process_id), |
| 1261 install_event_result_(blink::WebServiceWorkerEventResultCompleted), | 1262 install_event_result_(blink::WebServiceWorkerEventResultCompleted), |
| 1262 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} | 1263 activate_event_result_(blink::WebServiceWorkerEventResultCompleted) {} |
| 1263 | 1264 |
| 1264 void OnInstallEvent(int embedded_worker_id, | 1265 void OnInstallEvent(int embedded_worker_id, |
| 1265 int request_id) override { | 1266 int request_id) override { |
| 1266 if (!install_callback_.is_null()) | 1267 if (!install_callback_.is_null()) |
| 1267 install_callback_.Run(); | 1268 install_callback_.Run(); |
| 1268 SimulateSend( | 1269 SimulateSend( |
| 1269 new ServiceWorkerHostMsg_InstallEventFinished( | 1270 new ServiceWorkerHostMsg_InstallEventFinished( |
| 1270 embedded_worker_id, request_id, install_event_result_)); | 1271 embedded_worker_id, request_id, install_event_result_)); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 EXPECT_FALSE(registration->is_uninstalling()); | 1397 EXPECT_FALSE(registration->is_uninstalling()); |
| 1397 EXPECT_TRUE(registration->is_uninstalled()); | 1398 EXPECT_TRUE(registration->is_uninstalled()); |
| 1398 | 1399 |
| 1399 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); | 1400 EXPECT_EQ(ServiceWorkerVersion::STOPPED, old_version->running_status()); |
| 1400 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); | 1401 EXPECT_EQ(ServiceWorkerVersion::REDUNDANT, old_version->status()); |
| 1401 | 1402 |
| 1402 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); | 1403 FindRegistrationForPattern(pattern, SERVICE_WORKER_ERROR_NOT_FOUND); |
| 1403 } | 1404 } |
| 1404 | 1405 |
| 1405 } // namespace content | 1406 } // namespace content |
| OLD | NEW |