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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 registration->AddListener(&listener); | 113 registration->AddListener(&listener); |
114 registration->SetActiveVersion(version_1.get()); | 114 registration->SetActiveVersion(version_1.get()); |
115 | 115 |
116 EXPECT_EQ(version_1.get(), registration->active_version()); | 116 EXPECT_EQ(version_1.get(), registration->active_version()); |
117 EXPECT_EQ(registration, listener.observed_registration_); | 117 EXPECT_EQ(registration, listener.observed_registration_); |
118 EXPECT_EQ(ChangedVersionAttributesMask::ACTIVE_VERSION, | 118 EXPECT_EQ(ChangedVersionAttributesMask::ACTIVE_VERSION, |
119 listener.observed_changed_mask_.changed()); | 119 listener.observed_changed_mask_.changed()); |
120 EXPECT_EQ(kScope, listener.observed_info_.pattern); | 120 EXPECT_EQ(kScope, listener.observed_info_.pattern); |
121 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); | 121 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); |
122 EXPECT_EQ(kScript, listener.observed_info_.active_version.script_url); | 122 EXPECT_EQ(kScript, listener.observed_info_.active_version.script_url); |
123 EXPECT_TRUE(listener.observed_info_.installing_version.is_null); | 123 EXPECT_EQ(listener.observed_info_.installing_version.version_id, |
124 EXPECT_TRUE(listener.observed_info_.waiting_version.is_null); | 124 kInvalidServiceWorkerVersionId); |
125 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); | 125 EXPECT_EQ(listener.observed_info_.waiting_version.version_id, |
| 126 kInvalidServiceWorkerVersionId); |
| 127 EXPECT_EQ(listener.observed_info_.controlling_version.version_id, |
| 128 kInvalidServiceWorkerVersionId); |
126 listener.Reset(); | 129 listener.Reset(); |
127 | 130 |
128 registration->SetInstallingVersion(version_2.get()); | 131 registration->SetInstallingVersion(version_2.get()); |
129 | 132 |
130 EXPECT_EQ(version_2.get(), registration->installing_version()); | 133 EXPECT_EQ(version_2.get(), registration->installing_version()); |
131 EXPECT_EQ(ChangedVersionAttributesMask::INSTALLING_VERSION, | 134 EXPECT_EQ(ChangedVersionAttributesMask::INSTALLING_VERSION, |
132 listener.observed_changed_mask_.changed()); | 135 listener.observed_changed_mask_.changed()); |
133 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); | 136 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); |
134 EXPECT_EQ(version_2_id, | 137 EXPECT_EQ(version_2_id, |
135 listener.observed_info_.installing_version.version_id); | 138 listener.observed_info_.installing_version.version_id); |
136 EXPECT_TRUE(listener.observed_info_.waiting_version.is_null); | 139 EXPECT_EQ(listener.observed_info_.waiting_version.version_id, |
137 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); | 140 kInvalidServiceWorkerVersionId); |
| 141 EXPECT_EQ(listener.observed_info_.controlling_version.version_id, |
| 142 kInvalidServiceWorkerVersionId); |
138 listener.Reset(); | 143 listener.Reset(); |
139 | 144 |
140 registration->SetWaitingVersion(version_2.get()); | 145 registration->SetWaitingVersion(version_2.get()); |
141 | 146 |
142 EXPECT_EQ(version_2.get(), registration->waiting_version()); | 147 EXPECT_EQ(version_2.get(), registration->waiting_version()); |
143 EXPECT_FALSE(registration->installing_version()); | 148 EXPECT_FALSE(registration->installing_version()); |
144 EXPECT_TRUE(listener.observed_changed_mask_.waiting_changed()); | 149 EXPECT_TRUE(listener.observed_changed_mask_.waiting_changed()); |
145 EXPECT_TRUE(listener.observed_changed_mask_.installing_changed()); | 150 EXPECT_TRUE(listener.observed_changed_mask_.installing_changed()); |
146 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); | 151 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); |
147 EXPECT_EQ(version_2_id, listener.observed_info_.waiting_version.version_id); | 152 EXPECT_EQ(version_2_id, listener.observed_info_.waiting_version.version_id); |
148 EXPECT_TRUE(listener.observed_info_.installing_version.is_null); | 153 EXPECT_EQ(listener.observed_info_.installing_version.version_id, |
149 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); | 154 kInvalidServiceWorkerVersionId); |
| 155 EXPECT_EQ(listener.observed_info_.controlling_version.version_id, |
| 156 kInvalidServiceWorkerVersionId); |
150 listener.Reset(); | 157 listener.Reset(); |
151 | 158 |
152 registration->UnsetVersion(version_2.get()); | 159 registration->UnsetVersion(version_2.get()); |
153 | 160 |
154 EXPECT_FALSE(registration->waiting_version()); | 161 EXPECT_FALSE(registration->waiting_version()); |
155 EXPECT_EQ(ChangedVersionAttributesMask::WAITING_VERSION, | 162 EXPECT_EQ(ChangedVersionAttributesMask::WAITING_VERSION, |
156 listener.observed_changed_mask_.changed()); | 163 listener.observed_changed_mask_.changed()); |
157 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); | 164 EXPECT_EQ(version_1_id, listener.observed_info_.active_version.version_id); |
158 EXPECT_TRUE(listener.observed_info_.waiting_version.is_null); | 165 EXPECT_EQ(listener.observed_info_.waiting_version.version_id, |
159 EXPECT_TRUE(listener.observed_info_.installing_version.is_null); | 166 kInvalidServiceWorkerVersionId); |
160 EXPECT_TRUE(listener.observed_info_.controlling_version.is_null); | 167 EXPECT_EQ(listener.observed_info_.installing_version.version_id, |
| 168 kInvalidServiceWorkerVersionId); |
| 169 EXPECT_EQ(listener.observed_info_.controlling_version.version_id, |
| 170 kInvalidServiceWorkerVersionId); |
161 } | 171 } |
162 | 172 |
163 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { | 173 TEST_F(ServiceWorkerRegistrationTest, FailedRegistrationNoCrash) { |
164 const GURL kScope("http://www.example.not/"); | 174 const GURL kScope("http://www.example.not/"); |
165 int64 kRegistrationId = 1L; | 175 int64 kRegistrationId = 1L; |
166 int kProviderId = 1; | 176 int kProviderId = 1; |
167 scoped_refptr<ServiceWorkerRegistration> registration = | 177 scoped_refptr<ServiceWorkerRegistration> registration = |
168 new ServiceWorkerRegistration( | 178 new ServiceWorkerRegistration( |
169 kScope, | 179 kScope, |
170 kRegistrationId, | 180 kRegistrationId, |
171 context_ptr_); | 181 context_ptr_); |
172 scoped_ptr<ServiceWorkerRegistrationHandle> handle( | 182 scoped_ptr<ServiceWorkerRegistrationHandle> handle( |
173 new ServiceWorkerRegistrationHandle(context_ptr_, | 183 new ServiceWorkerRegistrationHandle(context_ptr_, |
174 NULL, | 184 NULL, |
175 kProviderId, | 185 kProviderId, |
176 registration.get())); | 186 registration.get())); |
177 registration->NotifyRegistrationFailed(); | 187 registration->NotifyRegistrationFailed(); |
178 // Don't crash when handle gets destructed. | 188 // Don't crash when handle gets destructed. |
179 } | 189 } |
180 | 190 |
181 } // namespace content | 191 } // namespace content |
OLD | NEW |