Chromium Code Reviews| 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 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class ServiceWorkerRegistrationTest : public testing::Test { | 16 class ServiceWorkerRegistrationTest : public testing::Test { |
| 17 public: | 17 public: |
| 18 ServiceWorkerRegistrationTest() | 18 ServiceWorkerRegistrationTest() |
| 19 : io_thread_(BrowserThread::IO, &message_loop_) {} | 19 : io_thread_(BrowserThread::IO, &message_loop_) {} |
| 20 | 20 |
| 21 virtual void SetUp() OVERRIDE {} | 21 virtual void SetUp() OVERRIDE {} |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 base::MessageLoopForIO message_loop_; | 24 base::MessageLoopForIO message_loop_; |
| 25 BrowserThreadImpl io_thread_; | 25 BrowserThreadImpl io_thread_; |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 TEST_F(ServiceWorkerRegistrationTest, Shutdown) { | 28 TEST_F(ServiceWorkerRegistrationTest, Shutdown) { |
| 29 int64 registration_id = -1L; | 29 const int64 registration_id = -1L; |
| 30 const int64 version_id = -1L; | |
| 30 scoped_refptr<ServiceWorkerRegistration> registration = | 31 scoped_refptr<ServiceWorkerRegistration> registration = |
| 31 new ServiceWorkerRegistration( | 32 new ServiceWorkerRegistration( |
| 32 GURL("http://www.example.com/*"), | 33 GURL("http://www.example.com/*"), |
| 33 GURL("http://www.example.com/service_worker.js"), | 34 GURL("http://www.example.com/service_worker.js"), |
| 34 registration_id); | 35 registration_id); |
| 35 | 36 |
| 36 scoped_refptr<ServiceWorkerVersion> active_version = | 37 scoped_refptr<ServiceWorkerVersion> active_version = |
| 37 new ServiceWorkerVersion(registration); | 38 new ServiceWorkerVersion(registration, NULL, version_id); |
| 38 registration->set_active_version(active_version); | 39 registration->set_active_version(active_version); |
| 39 | 40 |
| 40 registration->Shutdown(); | 41 registration->Shutdown(); |
| 41 | 42 |
| 42 DCHECK(registration->is_shutdown()); | 43 DCHECK(registration->is_shutdown()); |
| 43 DCHECK(active_version->is_shutdown()); | 44 DCHECK(active_version->is_shutdown()); |
| 44 DCHECK(registration->HasOneRef()); | 45 DCHECK(registration->HasOneRef()); |
| 45 DCHECK(active_version->HasOneRef()); | 46 DCHECK(active_version->HasOneRef()); |
| 46 } | 47 } |
| 47 | 48 |
| 48 // Make sure that activation does not leak | 49 // Make sure that activation does not leak |
| 49 TEST_F(ServiceWorkerRegistrationTest, ActivatePending) { | 50 TEST_F(ServiceWorkerRegistrationTest, ActivatePending) { |
| 50 int64 registration_id = -1L; | 51 int64 registration_id = -1L; |
| 51 scoped_refptr<ServiceWorkerRegistration> registration = | 52 scoped_refptr<ServiceWorkerRegistration> registration = |
| 52 new ServiceWorkerRegistration( | 53 new ServiceWorkerRegistration( |
| 53 GURL("http://www.example.com/*"), | 54 GURL("http://www.example.com/*"), |
| 54 GURL("http://www.example.com/service_worker.js"), | 55 GURL("http://www.example.com/service_worker.js"), |
| 55 registration_id); | 56 registration_id); |
| 56 | 57 |
| 58 const int version_1_id = 1L; | |
|
alecflett
2013/12/05 05:18:42
(I suspect these will need to be long long / int64
kinuko
2013/12/09 14:07:42
Done.
| |
| 59 const int version_2_id = 2L; | |
| 57 scoped_refptr<ServiceWorkerVersion> version_1 = | 60 scoped_refptr<ServiceWorkerVersion> version_1 = |
| 58 new ServiceWorkerVersion(registration); | 61 new ServiceWorkerVersion(registration, NULL, version_1_id); |
| 59 registration->set_active_version(version_1); | 62 registration->set_active_version(version_1); |
| 60 | 63 |
| 61 scoped_refptr<ServiceWorkerVersion> version_2 = | 64 scoped_refptr<ServiceWorkerVersion> version_2 = |
| 62 new ServiceWorkerVersion(registration); | 65 new ServiceWorkerVersion(registration, NULL, version_2_id); |
| 63 registration->set_pending_version(version_2); | 66 registration->set_pending_version(version_2); |
| 64 | 67 |
| 65 registration->ActivatePendingVersion(); | 68 registration->ActivatePendingVersion(); |
| 66 DCHECK_EQ(version_2, registration->active_version()); | 69 DCHECK_EQ(version_2, registration->active_version()); |
| 67 DCHECK(version_1->is_shutdown()); | 70 DCHECK(version_1->is_shutdown()); |
| 68 DCHECK(version_1->HasOneRef()); | 71 DCHECK(version_1->HasOneRef()); |
| 69 version_1 = NULL; | 72 version_1 = NULL; |
| 70 | 73 |
| 71 DCHECK(!version_2->is_shutdown()); | 74 DCHECK(!version_2->is_shutdown()); |
| 72 DCHECK(!version_2->HasOneRef()); | 75 DCHECK(!version_2->HasOneRef()); |
| 73 | 76 |
| 74 registration->Shutdown(); | 77 registration->Shutdown(); |
| 75 | 78 |
| 76 DCHECK(registration->is_shutdown()); | 79 DCHECK(registration->is_shutdown()); |
| 77 DCHECK(version_2->is_shutdown()); | 80 DCHECK(version_2->is_shutdown()); |
| 78 DCHECK(registration->HasOneRef()); | 81 DCHECK(registration->HasOneRef()); |
| 79 DCHECK(version_2->HasOneRef()); | 82 DCHECK(version_2->HasOneRef()); |
| 80 } | 83 } |
| 81 | 84 |
| 82 } // namespace content | 85 } // namespace content |
| OLD | NEW |