| 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 "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 BrowserThreadImpl io_thread_; | 79 BrowserThreadImpl io_thread_; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { | 82 TEST_F(ServiceWorkerRegistrationTest, SetAndUnsetVersions) { |
| 83 const GURL kScope("http://www.example.not/"); | 83 const GURL kScope("http://www.example.not/"); |
| 84 const GURL kScript("http://www.example.not/service_worker.js"); | 84 const GURL kScript("http://www.example.not/service_worker.js"); |
| 85 int64 kRegistrationId = 1L; | 85 int64 kRegistrationId = 1L; |
| 86 scoped_refptr<ServiceWorkerRegistration> registration = | 86 scoped_refptr<ServiceWorkerRegistration> registration = |
| 87 new ServiceWorkerRegistration( | 87 new ServiceWorkerRegistration( |
| 88 kScope, | 88 kScope, |
| 89 kScript, | |
| 90 kRegistrationId, | 89 kRegistrationId, |
| 91 context_ptr_); | 90 context_ptr_); |
| 92 | 91 |
| 93 const int64 version_1_id = 1L; | 92 const int64 version_1_id = 1L; |
| 94 const int64 version_2_id = 2L; | 93 const int64 version_2_id = 2L; |
| 95 scoped_refptr<ServiceWorkerVersion> version_1 = | 94 scoped_refptr<ServiceWorkerVersion> version_1 = new ServiceWorkerVersion( |
| 96 new ServiceWorkerVersion(registration.get(), version_1_id, context_ptr_); | 95 registration.get(), kScript, version_1_id, context_ptr_); |
| 97 scoped_refptr<ServiceWorkerVersion> version_2 = | 96 scoped_refptr<ServiceWorkerVersion> version_2 = new ServiceWorkerVersion( |
| 98 new ServiceWorkerVersion(registration.get(), version_2_id, context_ptr_); | 97 registration.get(), kScript, version_2_id, context_ptr_); |
| 99 | 98 |
| 100 RegistrationListener listener; | 99 RegistrationListener listener; |
| 101 registration->AddListener(&listener); | 100 registration->AddListener(&listener); |
| 102 registration->SetActiveVersion(version_1.get()); | 101 registration->SetActiveVersion(version_1.get()); |
| 103 | 102 |
| 104 EXPECT_EQ(version_1.get(), registration->active_version()); | 103 EXPECT_EQ(version_1.get(), registration->active_version()); |
| 105 EXPECT_EQ(registration, listener.observed_registration_); | 104 EXPECT_EQ(registration, listener.observed_registration_); |
| 106 EXPECT_EQ(ChangedVersionAttributesMask::ACTIVE_VERSION, | 105 EXPECT_EQ(ChangedVersionAttributesMask::ACTIVE_VERSION, |
| 107 listener.observed_changed_mask_.changed()); | 106 listener.observed_changed_mask_.changed()); |
| 108 EXPECT_EQ(kScope, listener.observed_info_.pattern); | 107 EXPECT_EQ(kScope, listener.observed_info_.pattern); |
| 109 EXPECT_EQ(kScript, listener.observed_info_.script_url); | |
| 110 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); | 108 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); |
| 109 EXPECT_EQ(kScript, listener.observed_info_.active_version.script_url); |
| 111 EXPECT_TRUE(listener.observed_info_.installing_version.is_null); | 110 EXPECT_TRUE(listener.observed_info_.installing_version.is_null); |
| 112 EXPECT_TRUE(listener.observed_info_.waiting_version.is_null); | 111 EXPECT_TRUE(listener.observed_info_.waiting_version.is_null); |
| 113 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); | 112 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); |
| 114 listener.Reset(); | 113 listener.Reset(); |
| 115 | 114 |
| 116 registration->SetInstallingVersion(version_2.get()); | 115 registration->SetInstallingVersion(version_2.get()); |
| 117 | 116 |
| 118 EXPECT_EQ(version_2.get(), registration->installing_version()); | 117 EXPECT_EQ(version_2.get(), registration->installing_version()); |
| 119 EXPECT_EQ(ChangedVersionAttributesMask::INSTALLING_VERSION, | 118 EXPECT_EQ(ChangedVersionAttributesMask::INSTALLING_VERSION, |
| 120 listener.observed_changed_mask_.changed()); | 119 listener.observed_changed_mask_.changed()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 EXPECT_EQ(ChangedVersionAttributesMask::WAITING_VERSION, | 142 EXPECT_EQ(ChangedVersionAttributesMask::WAITING_VERSION, |
| 144 listener.observed_changed_mask_.changed()); | 143 listener.observed_changed_mask_.changed()); |
| 145 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); | 144 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); |
| 146 EXPECT_TRUE(listener.observed_info_.waiting_version.is_null); | 145 EXPECT_TRUE(listener.observed_info_.waiting_version.is_null); |
| 147 EXPECT_TRUE(listener.observed_info_.installing_version.is_null); | 146 EXPECT_TRUE(listener.observed_info_.installing_version.is_null); |
| 148 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); | 147 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); |
| 149 } | 148 } |
| 150 | 149 |
| 151 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { | 150 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { |
| 152 const GURL kScope("http://www.example.not/"); | 151 const GURL kScope("http://www.example.not/"); |
| 153 const GURL kScript("http://www.example.not/service_worker.js"); | |
| 154 int64 kRegistrationId = 1L; | 152 int64 kRegistrationId = 1L; |
| 155 int kProviderId = 1; | 153 int kProviderId = 1; |
| 156 scoped_refptr<ServiceWorkerRegistration> registration = | 154 scoped_refptr<ServiceWorkerRegistration> registration = |
| 157 new ServiceWorkerRegistration( | 155 new ServiceWorkerRegistration( |
| 158 kScope, | 156 kScope, |
| 159 kScript, | |
| 160 kRegistrationId, | 157 kRegistrationId, |
| 161 context_ptr_); | 158 context_ptr_); |
| 162 scoped_ptr<ServiceWorkerRegistrationHandle> handle( | 159 scoped_ptr<ServiceWorkerRegistrationHandle> handle( |
| 163 new ServiceWorkerRegistrationHandle(context_ptr_, | 160 new ServiceWorkerRegistrationHandle(context_ptr_, |
| 164 NULL, | 161 NULL, |
| 165 kProviderId, | 162 kProviderId, |
| 166 registration.get())); | 163 registration.get())); |
| 167 registration->NotifyRegistrationFailed(); | 164 registration->NotifyRegistrationFailed(); |
| 168 // Don't crash when handle gets destructed. | 165 // Don't crash when handle gets destructed. |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace content | 168 } // namespace content |
| OLD | NEW |