| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_registration.h" | 5 #include "content/browser/service_worker/service_worker_registration.h" |
| 6 | 6 |
| 7 | 7 |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 context_ptr_ = context_->AsWeakPtr(); | 25 context_ptr_ = context_->AsWeakPtr(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 scoped_ptr<ServiceWorkerContextCore> context_; | 29 scoped_ptr<ServiceWorkerContextCore> context_; |
| 30 base::WeakPtr<ServiceWorkerContextCore> context_ptr_; | 30 base::WeakPtr<ServiceWorkerContextCore> context_ptr_; |
| 31 base::MessageLoopForIO message_loop_; | 31 base::MessageLoopForIO message_loop_; |
| 32 BrowserThreadImpl io_thread_; | 32 BrowserThreadImpl io_thread_; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 TEST_F(ServiceWorkerRegistrationTest, Shutdown) { | |
| 36 const int64 registration_id = -1L; | |
| 37 const int64 version_id = -1L; | |
| 38 scoped_refptr<ServiceWorkerRegistration> registration = | |
| 39 new ServiceWorkerRegistration( | |
| 40 GURL("http://www.example.com/*"), | |
| 41 GURL("http://www.example.com/service_worker.js"), | |
| 42 registration_id, | |
| 43 context_ptr_); | |
| 44 | |
| 45 scoped_refptr<ServiceWorkerVersion> active_version = | |
| 46 new ServiceWorkerVersion(registration, version_id, context_ptr_); | |
| 47 registration->set_active_version(active_version); | |
| 48 | |
| 49 registration->Shutdown(); | |
| 50 | |
| 51 DCHECK(registration->is_shutdown()); | |
| 52 DCHECK(active_version->is_shutdown()); | |
| 53 DCHECK(registration->HasOneRef()); | |
| 54 DCHECK(active_version->HasOneRef()); | |
| 55 } | |
| 56 | |
| 57 // Make sure that activation does not leak | 35 // Make sure that activation does not leak |
| 58 TEST_F(ServiceWorkerRegistrationTest, ActivatePending) { | 36 TEST_F(ServiceWorkerRegistrationTest, ActivatePending) { |
| 59 int64 registration_id = -1L; | 37 int64 registration_id = -1L; |
| 60 scoped_refptr<ServiceWorkerRegistration> registration = | 38 scoped_refptr<ServiceWorkerRegistration> registration = |
| 61 new ServiceWorkerRegistration( | 39 new ServiceWorkerRegistration( |
| 62 GURL("http://www.example.com/*"), | 40 GURL("http://www.example.com/*"), |
| 63 GURL("http://www.example.com/service_worker.js"), | 41 GURL("http://www.example.com/service_worker.js"), |
| 64 registration_id, | 42 registration_id, |
| 65 context_ptr_); | 43 context_ptr_); |
| 66 | 44 |
| 67 const int64 version_1_id = 1L; | 45 const int64 version_1_id = 1L; |
| 68 const int64 version_2_id = 2L; | 46 const int64 version_2_id = 2L; |
| 69 scoped_refptr<ServiceWorkerVersion> version_1 = | 47 scoped_refptr<ServiceWorkerVersion> version_1 = |
| 70 new ServiceWorkerVersion(registration, version_1_id, context_ptr_); | 48 new ServiceWorkerVersion(registration, version_1_id, context_ptr_); |
| 71 version_1->SetStatus(ServiceWorkerVersion::ACTIVE); | 49 version_1->SetStatus(ServiceWorkerVersion::ACTIVE); |
| 72 registration->set_active_version(version_1); | 50 registration->set_active_version(version_1); |
| 73 | 51 |
| 74 scoped_refptr<ServiceWorkerVersion> version_2 = | 52 scoped_refptr<ServiceWorkerVersion> version_2 = |
| 75 new ServiceWorkerVersion(registration, version_2_id, context_ptr_); | 53 new ServiceWorkerVersion(registration, version_2_id, context_ptr_); |
| 76 registration->set_pending_version(version_2); | 54 registration->set_pending_version(version_2); |
| 77 | 55 |
| 78 registration->ActivatePendingVersion(); | 56 registration->ActivatePendingVersion(); |
| 79 DCHECK_EQ(version_2, registration->active_version()); | 57 DCHECK_EQ(version_2, registration->active_version()); |
| 80 DCHECK(version_1->is_shutdown()); | |
| 81 DCHECK(version_1->HasOneRef()); | 58 DCHECK(version_1->HasOneRef()); |
| 82 version_1 = NULL; | 59 version_1 = NULL; |
| 83 | 60 |
| 84 DCHECK(!version_2->is_shutdown()); | |
| 85 DCHECK(!version_2->HasOneRef()); | 61 DCHECK(!version_2->HasOneRef()); |
| 86 | |
| 87 registration->Shutdown(); | |
| 88 | |
| 89 DCHECK(registration->is_shutdown()); | |
| 90 DCHECK(version_2->is_shutdown()); | |
| 91 DCHECK(registration->HasOneRef()); | |
| 92 DCHECK(version_2->HasOneRef()); | |
| 93 } | 62 } |
| 94 | 63 |
| 95 } // namespace content | 64 } // namespace content |
| OLD | NEW |