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/public/browser/service_worker_context.h" | 5 #include "content/public/browser/service_worker_context.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
15 #include "content/browser/service_worker/embedded_worker_registry.h" | 15 #include "content/browser/service_worker/embedded_worker_registry.h" |
16 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 16 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
17 #include "content/browser/service_worker/service_worker_context_core.h" | 17 #include "content/browser/service_worker/service_worker_context_core.h" |
18 #include "content/browser/service_worker/service_worker_context_observer.h" | 18 #include "content/browser/service_worker/service_worker_context_observer.h" |
19 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 19 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
20 #include "content/browser/service_worker/service_worker_provider_host.h" | 20 #include "content/browser/service_worker/service_worker_provider_host.h" |
21 #include "content/browser/service_worker/service_worker_registration.h" | 21 #include "content/browser/service_worker/service_worker_registration.h" |
22 #include "content/browser/service_worker/service_worker_storage.h" | 22 #include "content/browser/service_worker/service_worker_storage.h" |
| 23 #include "content/browser/service_worker/service_worker_test_utils.h" |
23 #include "content/common/service_worker/embedded_worker_messages.h" | 24 #include "content/common/service_worker/embedded_worker_messages.h" |
24 #include "content/common/service_worker/service_worker_messages.h" | 25 #include "content/common/service_worker/service_worker_messages.h" |
25 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
26 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 namespace content { | 30 namespace content { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 155 } |
155 | 156 |
156 ServiceWorkerContextCore* context() { return helper_->context(); } | 157 ServiceWorkerContextCore* context() { return helper_->context(); } |
157 | 158 |
158 protected: | 159 protected: |
159 TestBrowserThreadBundle browser_thread_bundle_; | 160 TestBrowserThreadBundle browser_thread_bundle_; |
160 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 161 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
161 std::vector<NotificationLog> notifications_; | 162 std::vector<NotificationLog> notifications_; |
162 }; | 163 }; |
163 | 164 |
| 165 class ServiceWorkerContextTestP |
| 166 : public MojoServiceWorkerTestP<ServiceWorkerContextTest> {}; |
| 167 |
| 168 class RecordableEmbeddedWorkerInstanceClient |
| 169 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { |
| 170 public: |
| 171 enum class Message { StartWorker, StopWorker }; |
| 172 |
| 173 explicit RecordableEmbeddedWorkerInstanceClient( |
| 174 base::WeakPtr<EmbeddedWorkerTestHelper> helper) |
| 175 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} |
| 176 |
| 177 const std::vector<Message>& events() const { return events_; } |
| 178 |
| 179 protected: |
| 180 void StartWorker( |
| 181 const EmbeddedWorkerStartParams& params, |
| 182 service_manager::mojom::InterfaceProviderPtr browser_interfaces, |
| 183 service_manager::mojom::InterfaceProviderRequest renderer_request) |
| 184 override { |
| 185 events_.push_back(Message::StartWorker); |
| 186 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StartWorker( |
| 187 params, std::move(browser_interfaces), std::move(renderer_request)); |
| 188 } |
| 189 |
| 190 void StopWorker(const StopWorkerCallback& callback) override { |
| 191 events_.push_back(Message::StopWorker); |
| 192 EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient::StopWorker( |
| 193 std::move(callback)); |
| 194 } |
| 195 |
| 196 std::vector<Message> events_; |
| 197 |
| 198 private: |
| 199 DISALLOW_COPY_AND_ASSIGN(RecordableEmbeddedWorkerInstanceClient); |
| 200 }; |
| 201 |
164 // Make sure basic registration is working. | 202 // Make sure basic registration is working. |
165 TEST_F(ServiceWorkerContextTest, Register) { | 203 TEST_P(ServiceWorkerContextTestP, Register) { |
166 GURL pattern("http://www.example.com/"); | 204 GURL pattern("http://www.example.com/"); |
167 GURL script_url("http://www.example.com/service_worker.js"); | 205 GURL script_url("http://www.example.com/service_worker.js"); |
168 | 206 |
| 207 RecordableEmbeddedWorkerInstanceClient* client = nullptr; |
| 208 if (is_mojo_enabled()) { |
| 209 client = helper_->CreateAndRegisterMockInstanceClient< |
| 210 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); |
| 211 } |
| 212 |
169 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 213 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
170 bool called = false; | 214 bool called = false; |
171 context()->RegisterServiceWorker( | 215 context()->RegisterServiceWorker( |
172 pattern, | 216 pattern, |
173 script_url, | 217 script_url, |
174 NULL, | 218 NULL, |
175 MakeRegisteredCallback(&called, ®istration_id)); | 219 MakeRegisteredCallback(&called, ®istration_id)); |
176 | 220 |
177 ASSERT_FALSE(called); | 221 ASSERT_FALSE(called); |
178 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
179 EXPECT_TRUE(called); | 223 EXPECT_TRUE(called); |
180 | 224 |
181 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); | 225 if (is_mojo_enabled()) { |
182 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 226 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
183 EmbeddedWorkerMsg_StartWorker::ID)); | 227 ASSERT_EQ(2UL, client->events().size()); |
184 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 228 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
185 ServiceWorkerMsg_InstallEvent::ID)); | 229 client->events()[0]); |
186 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 230 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
187 ServiceWorkerMsg_ActivateEvent::ID)); | 231 ServiceWorkerMsg_InstallEvent::ID)); |
188 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 232 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
189 EmbeddedWorkerMsg_StopWorker::ID)); | 233 ServiceWorkerMsg_ActivateEvent::ID)); |
| 234 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 235 client->events()[1]); |
| 236 } else { |
| 237 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); |
| 238 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 239 EmbeddedWorkerMsg_StartWorker::ID)); |
| 240 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 241 ServiceWorkerMsg_InstallEvent::ID)); |
| 242 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 243 ServiceWorkerMsg_ActivateEvent::ID)); |
| 244 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 245 EmbeddedWorkerMsg_StopWorker::ID)); |
| 246 } |
190 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 247 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
191 | 248 |
192 ASSERT_EQ(1u, notifications_.size()); | 249 ASSERT_EQ(1u, notifications_.size()); |
193 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 250 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
194 EXPECT_EQ(pattern, notifications_[0].pattern); | 251 EXPECT_EQ(pattern, notifications_[0].pattern); |
195 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 252 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
196 | 253 |
197 context()->storage()->FindRegistrationForId( | 254 context()->storage()->FindRegistrationForId( |
198 registration_id, | 255 registration_id, |
199 pattern.GetOrigin(), | 256 pattern.GetOrigin(), |
200 base::Bind(&ExpectRegisteredWorkers, | 257 base::Bind(&ExpectRegisteredWorkers, |
201 SERVICE_WORKER_OK, | 258 SERVICE_WORKER_OK, |
202 false /* expect_waiting */, | 259 false /* expect_waiting */, |
203 true /* expect_active */)); | 260 true /* expect_active */)); |
204 base::RunLoop().RunUntilIdle(); | 261 base::RunLoop().RunUntilIdle(); |
205 } | 262 } |
206 | 263 |
207 // Test registration when the service worker rejects the install event. The | 264 // Test registration when the service worker rejects the install event. The |
208 // registration callback should indicate success, but there should be no waiting | 265 // registration callback should indicate success, but there should be no waiting |
209 // or active worker in the registration. | 266 // or active worker in the registration. |
210 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { | 267 TEST_P(ServiceWorkerContextTestP, Register_RejectInstall) { |
211 GURL pattern("http://www.example.com/"); | 268 GURL pattern("http://www.example.com/"); |
212 GURL script_url("http://www.example.com/service_worker.js"); | 269 GURL script_url("http://www.example.com/service_worker.js"); |
213 | 270 |
214 helper_.reset(); // Make sure the process lookups stay overridden. | 271 helper_.reset(); // Make sure the process lookups stay overridden. |
215 helper_.reset(new RejectInstallTestHelper); | 272 helper_.reset(new RejectInstallTestHelper); |
216 helper_->context_wrapper()->AddObserver(this); | 273 helper_->context_wrapper()->AddObserver(this); |
| 274 |
| 275 RecordableEmbeddedWorkerInstanceClient* client = nullptr; |
| 276 if (is_mojo_enabled()) { |
| 277 client = helper_->CreateAndRegisterMockInstanceClient< |
| 278 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); |
| 279 } |
| 280 |
217 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 281 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
218 bool called = false; | 282 bool called = false; |
219 context()->RegisterServiceWorker( | 283 context()->RegisterServiceWorker( |
220 pattern, | 284 pattern, |
221 script_url, | 285 script_url, |
222 NULL, | 286 NULL, |
223 MakeRegisteredCallback(&called, ®istration_id)); | 287 MakeRegisteredCallback(&called, ®istration_id)); |
224 | 288 |
225 ASSERT_FALSE(called); | 289 ASSERT_FALSE(called); |
226 base::RunLoop().RunUntilIdle(); | 290 base::RunLoop().RunUntilIdle(); |
227 EXPECT_TRUE(called); | 291 EXPECT_TRUE(called); |
228 | 292 |
229 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); | 293 if (is_mojo_enabled()) { |
230 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 294 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
231 EmbeddedWorkerMsg_StartWorker::ID)); | 295 ASSERT_EQ(2UL, client->events().size()); |
232 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 296 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
233 ServiceWorkerMsg_InstallEvent::ID)); | 297 client->events()[0]); |
234 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 298 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
235 ServiceWorkerMsg_ActivateEvent::ID)); | 299 ServiceWorkerMsg_InstallEvent::ID)); |
236 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 300 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
237 EmbeddedWorkerMsg_StopWorker::ID)); | 301 ServiceWorkerMsg_ActivateEvent::ID)); |
| 302 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 303 client->events()[1]); |
| 304 } else { |
| 305 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); |
| 306 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 307 EmbeddedWorkerMsg_StartWorker::ID)); |
| 308 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 309 ServiceWorkerMsg_InstallEvent::ID)); |
| 310 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 311 ServiceWorkerMsg_ActivateEvent::ID)); |
| 312 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 313 EmbeddedWorkerMsg_StopWorker::ID)); |
| 314 } |
238 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 315 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
239 | 316 |
240 ASSERT_EQ(1u, notifications_.size()); | 317 ASSERT_EQ(1u, notifications_.size()); |
241 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 318 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
242 EXPECT_EQ(pattern, notifications_[0].pattern); | 319 EXPECT_EQ(pattern, notifications_[0].pattern); |
243 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 320 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
244 | 321 |
245 context()->storage()->FindRegistrationForId( | 322 context()->storage()->FindRegistrationForId( |
246 registration_id, | 323 registration_id, |
247 pattern.GetOrigin(), | 324 pattern.GetOrigin(), |
248 base::Bind(&ExpectRegisteredWorkers, | 325 base::Bind(&ExpectRegisteredWorkers, |
249 SERVICE_WORKER_ERROR_NOT_FOUND, | 326 SERVICE_WORKER_ERROR_NOT_FOUND, |
250 false /* expect_waiting */, | 327 false /* expect_waiting */, |
251 false /* expect_active */)); | 328 false /* expect_active */)); |
252 base::RunLoop().RunUntilIdle(); | 329 base::RunLoop().RunUntilIdle(); |
253 } | 330 } |
254 | 331 |
255 // Test registration when the service worker rejects the activate event. The | 332 // Test registration when the service worker rejects the activate event. The |
256 // worker should be activated anyway. | 333 // worker should be activated anyway. |
257 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { | 334 TEST_P(ServiceWorkerContextTestP, Register_RejectActivate) { |
258 GURL pattern("http://www.example.com/"); | 335 GURL pattern("http://www.example.com/"); |
259 GURL script_url("http://www.example.com/service_worker.js"); | 336 GURL script_url("http://www.example.com/service_worker.js"); |
260 | 337 |
261 helper_.reset(); | 338 helper_.reset(); |
262 helper_.reset(new RejectActivateTestHelper); | 339 helper_.reset(new RejectActivateTestHelper); |
263 helper_->context_wrapper()->AddObserver(this); | 340 helper_->context_wrapper()->AddObserver(this); |
| 341 |
| 342 RecordableEmbeddedWorkerInstanceClient* client = nullptr; |
| 343 if (is_mojo_enabled()) { |
| 344 client = helper_->CreateAndRegisterMockInstanceClient< |
| 345 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); |
| 346 } |
| 347 |
264 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 348 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
265 bool called = false; | 349 bool called = false; |
266 context()->RegisterServiceWorker( | 350 context()->RegisterServiceWorker( |
267 pattern, script_url, NULL, | 351 pattern, script_url, NULL, |
268 MakeRegisteredCallback(&called, ®istration_id)); | 352 MakeRegisteredCallback(&called, ®istration_id)); |
269 | 353 |
270 ASSERT_FALSE(called); | 354 ASSERT_FALSE(called); |
271 base::RunLoop().RunUntilIdle(); | 355 base::RunLoop().RunUntilIdle(); |
272 EXPECT_TRUE(called); | 356 EXPECT_TRUE(called); |
273 | 357 |
274 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); | 358 if (is_mojo_enabled()) { |
275 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 359 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
276 EmbeddedWorkerMsg_StartWorker::ID)); | 360 ASSERT_EQ(2UL, client->events().size()); |
277 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 361 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
278 ServiceWorkerMsg_InstallEvent::ID)); | 362 client->events()[0]); |
279 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 363 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
280 ServiceWorkerMsg_ActivateEvent::ID)); | 364 ServiceWorkerMsg_InstallEvent::ID)); |
281 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 365 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
282 EmbeddedWorkerMsg_StopWorker::ID)); | 366 ServiceWorkerMsg_ActivateEvent::ID)); |
| 367 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 368 client->events()[1]); |
| 369 } else { |
| 370 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); |
| 371 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 372 EmbeddedWorkerMsg_StartWorker::ID)); |
| 373 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 374 ServiceWorkerMsg_InstallEvent::ID)); |
| 375 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 376 ServiceWorkerMsg_ActivateEvent::ID)); |
| 377 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 378 EmbeddedWorkerMsg_StopWorker::ID)); |
| 379 } |
283 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 380 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
284 | 381 |
285 ASSERT_EQ(1u, notifications_.size()); | 382 ASSERT_EQ(1u, notifications_.size()); |
286 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 383 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
287 EXPECT_EQ(pattern, notifications_[0].pattern); | 384 EXPECT_EQ(pattern, notifications_[0].pattern); |
288 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 385 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
289 | 386 |
290 context()->storage()->FindRegistrationForId( | 387 context()->storage()->FindRegistrationForId( |
291 registration_id, pattern.GetOrigin(), | 388 registration_id, pattern.GetOrigin(), |
292 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK, | 389 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK, |
293 false /* expect_waiting */, true /* expect_active */)); | 390 false /* expect_waiting */, true /* expect_active */)); |
294 base::RunLoop().RunUntilIdle(); | 391 base::RunLoop().RunUntilIdle(); |
295 } | 392 } |
296 | 393 |
297 // Make sure registrations are cleaned up when they are unregistered. | 394 // Make sure registrations are cleaned up when they are unregistered. |
298 TEST_F(ServiceWorkerContextTest, Unregister) { | 395 TEST_P(ServiceWorkerContextTestP, Unregister) { |
299 GURL pattern("http://www.example.com/"); | 396 GURL pattern("http://www.example.com/"); |
300 | 397 |
301 bool called = false; | 398 bool called = false; |
302 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 399 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
303 context()->RegisterServiceWorker( | 400 context()->RegisterServiceWorker( |
304 pattern, | 401 pattern, |
305 GURL("http://www.example.com/service_worker.js"), | 402 GURL("http://www.example.com/service_worker.js"), |
306 NULL, | 403 NULL, |
307 MakeRegisteredCallback(&called, ®istration_id)); | 404 MakeRegisteredCallback(&called, ®istration_id)); |
308 | 405 |
(...skipping 22 matching lines...) Expand all Loading... |
331 ASSERT_EQ(2u, notifications_.size()); | 428 ASSERT_EQ(2u, notifications_.size()); |
332 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 429 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
333 EXPECT_EQ(pattern, notifications_[0].pattern); | 430 EXPECT_EQ(pattern, notifications_[0].pattern); |
334 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 431 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
335 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); | 432 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); |
336 EXPECT_EQ(pattern, notifications_[1].pattern); | 433 EXPECT_EQ(pattern, notifications_[1].pattern); |
337 EXPECT_EQ(registration_id, notifications_[1].registration_id); | 434 EXPECT_EQ(registration_id, notifications_[1].registration_id); |
338 } | 435 } |
339 | 436 |
340 // Make sure registrations are cleaned up when they are unregistered in bulk. | 437 // Make sure registrations are cleaned up when they are unregistered in bulk. |
341 TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { | 438 TEST_P(ServiceWorkerContextTestP, UnregisterMultiple) { |
342 GURL origin1_p1("http://www.example.com/test"); | 439 GURL origin1_p1("http://www.example.com/test"); |
343 GURL origin1_p2("http://www.example.com/hello"); | 440 GURL origin1_p2("http://www.example.com/hello"); |
344 GURL origin2_p1("http://www.example.com:8080/again"); | 441 GURL origin2_p1("http://www.example.com:8080/again"); |
345 GURL origin3_p1("http://www.other.com/"); | 442 GURL origin3_p1("http://www.other.com/"); |
346 | 443 |
347 bool called = false; | 444 bool called = false; |
348 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId; | 445 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId; |
349 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId; | 446 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId; |
350 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId; | 447 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId; |
351 int64_t registration_id4 = kInvalidServiceWorkerRegistrationId; | 448 int64_t registration_id4 = kInvalidServiceWorkerRegistrationId; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 EXPECT_EQ(registration_id4, notifications_[3].registration_id); | 531 EXPECT_EQ(registration_id4, notifications_[3].registration_id); |
435 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); | 532 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); |
436 EXPECT_EQ(origin1_p2, notifications_[4].pattern); | 533 EXPECT_EQ(origin1_p2, notifications_[4].pattern); |
437 EXPECT_EQ(registration_id2, notifications_[4].registration_id); | 534 EXPECT_EQ(registration_id2, notifications_[4].registration_id); |
438 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); | 535 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); |
439 EXPECT_EQ(origin1_p1, notifications_[5].pattern); | 536 EXPECT_EQ(origin1_p1, notifications_[5].pattern); |
440 EXPECT_EQ(registration_id1, notifications_[5].registration_id); | 537 EXPECT_EQ(registration_id1, notifications_[5].registration_id); |
441 } | 538 } |
442 | 539 |
443 // Make sure registering a new script shares an existing registration. | 540 // Make sure registering a new script shares an existing registration. |
444 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { | 541 TEST_P(ServiceWorkerContextTestP, RegisterNewScript) { |
445 GURL pattern("http://www.example.com/"); | 542 GURL pattern("http://www.example.com/"); |
446 | 543 |
447 bool called = false; | 544 bool called = false; |
448 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; | 545 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; |
449 context()->RegisterServiceWorker( | 546 context()->RegisterServiceWorker( |
450 pattern, | 547 pattern, |
451 GURL("http://www.example.com/service_worker.js"), | 548 GURL("http://www.example.com/service_worker.js"), |
452 NULL, | 549 NULL, |
453 MakeRegisteredCallback(&called, &old_registration_id)); | 550 MakeRegisteredCallback(&called, &old_registration_id)); |
454 | 551 |
(...skipping 21 matching lines...) Expand all Loading... |
476 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 573 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
477 EXPECT_EQ(pattern, notifications_[0].pattern); | 574 EXPECT_EQ(pattern, notifications_[0].pattern); |
478 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); | 575 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); |
479 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); | 576 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); |
480 EXPECT_EQ(pattern, notifications_[1].pattern); | 577 EXPECT_EQ(pattern, notifications_[1].pattern); |
481 EXPECT_EQ(new_registration_id, notifications_[1].registration_id); | 578 EXPECT_EQ(new_registration_id, notifications_[1].registration_id); |
482 } | 579 } |
483 | 580 |
484 // Make sure that when registering a duplicate pattern+script_url | 581 // Make sure that when registering a duplicate pattern+script_url |
485 // combination, that the same registration is used. | 582 // combination, that the same registration is used. |
486 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { | 583 TEST_P(ServiceWorkerContextTestP, RegisterDuplicateScript) { |
487 GURL pattern("http://www.example.com/"); | 584 GURL pattern("http://www.example.com/"); |
488 GURL script_url("http://www.example.com/service_worker.js"); | 585 GURL script_url("http://www.example.com/service_worker.js"); |
489 | 586 |
490 bool called = false; | 587 bool called = false; |
491 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; | 588 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; |
492 context()->RegisterServiceWorker( | 589 context()->RegisterServiceWorker( |
493 pattern, | 590 pattern, |
494 script_url, | 591 script_url, |
495 NULL, | 592 NULL, |
496 MakeRegisteredCallback(&called, &old_registration_id)); | 593 MakeRegisteredCallback(&called, &old_registration_id)); |
(...skipping 18 matching lines...) Expand all Loading... |
515 | 612 |
516 ASSERT_EQ(2u, notifications_.size()); | 613 ASSERT_EQ(2u, notifications_.size()); |
517 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 614 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
518 EXPECT_EQ(pattern, notifications_[0].pattern); | 615 EXPECT_EQ(pattern, notifications_[0].pattern); |
519 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); | 616 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); |
520 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); | 617 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); |
521 EXPECT_EQ(pattern, notifications_[1].pattern); | 618 EXPECT_EQ(pattern, notifications_[1].pattern); |
522 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); | 619 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); |
523 } | 620 } |
524 | 621 |
525 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { | 622 TEST_P(ServiceWorkerContextTestP, ProviderHostIterator) { |
526 const int kRenderProcessId1 = 1; | 623 const int kRenderProcessId1 = 1; |
527 const int kRenderProcessId2 = 2; | 624 const int kRenderProcessId2 = 2; |
528 const GURL kOrigin1 = GURL("http://www.example.com/"); | 625 const GURL kOrigin1 = GURL("http://www.example.com/"); |
529 const GURL kOrigin2 = GURL("https://www.example.com/"); | 626 const GURL kOrigin2 = GURL("https://www.example.com/"); |
530 int provider_id = 1; | 627 int provider_id = 1; |
531 | 628 |
532 // Host1 (provider_id=1): process_id=1, origin1. | 629 // Host1 (provider_id=1): process_id=1, origin1. |
533 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( | 630 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( |
534 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, | 631 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, |
535 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 632 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 EXPECT_TRUE(ContainsKey(results, host2)); | 696 EXPECT_TRUE(ContainsKey(results, host2)); |
600 | 697 |
601 context()->RemoveProviderHost(kRenderProcessId1, 1); | 698 context()->RemoveProviderHost(kRenderProcessId1, 1); |
602 context()->RemoveProviderHost(kRenderProcessId2, 2); | 699 context()->RemoveProviderHost(kRenderProcessId2, 2); |
603 context()->RemoveProviderHost(kRenderProcessId2, 3); | 700 context()->RemoveProviderHost(kRenderProcessId2, 3); |
604 context()->RemoveProviderHost(kRenderProcessId2, 4); | 701 context()->RemoveProviderHost(kRenderProcessId2, 4); |
605 } | 702 } |
606 | 703 |
607 class ServiceWorkerContextRecoveryTest | 704 class ServiceWorkerContextRecoveryTest |
608 : public ServiceWorkerContextTest, | 705 : public ServiceWorkerContextTest, |
609 public testing::WithParamInterface<bool> { | 706 public testing::WithParamInterface<testing::tuple<bool, bool>> { |
610 public: | 707 public: |
611 ServiceWorkerContextRecoveryTest() {} | 708 ServiceWorkerContextRecoveryTest() {} |
612 virtual ~ServiceWorkerContextRecoveryTest() {} | 709 virtual ~ServiceWorkerContextRecoveryTest() {} |
| 710 |
| 711 protected: |
| 712 void SetUp() override { |
| 713 if (is_mojo_enabled()) { |
| 714 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 715 switches::kMojoServiceWorker); |
| 716 } |
| 717 ServiceWorkerContextTest::SetUp(); |
| 718 } |
| 719 |
| 720 bool is_mojo_enabled() const { return testing::get<0>(GetParam()); } |
| 721 bool is_storage_on_disk() const { return testing::get<1>(GetParam()); } |
613 }; | 722 }; |
614 | 723 |
615 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | |
616 ServiceWorkerContextRecoveryTest, | |
617 testing::Values(true, false)); | |
618 | |
619 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { | 724 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { |
620 GURL pattern("http://www.example.com/"); | 725 GURL pattern("http://www.example.com/"); |
621 GURL script_url("http://www.example.com/service_worker.js"); | 726 GURL script_url("http://www.example.com/service_worker.js"); |
622 | 727 |
623 bool is_storage_on_disk = GetParam(); | 728 if (is_storage_on_disk()) { |
624 if (is_storage_on_disk) { | |
625 // Reinitialize the helper to test on-disk storage. | 729 // Reinitialize the helper to test on-disk storage. |
626 base::ScopedTempDir user_data_directory; | 730 base::ScopedTempDir user_data_directory; |
627 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir()); | 731 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir()); |
628 helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.GetPath())); | 732 helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.GetPath())); |
629 helper_->context_wrapper()->AddObserver(this); | 733 helper_->context_wrapper()->AddObserver(this); |
630 } | 734 } |
631 | 735 |
632 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 736 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
633 bool called = false; | 737 bool called = false; |
634 context()->RegisterServiceWorker( | 738 context()->RegisterServiceWorker( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 ASSERT_EQ(3u, notifications_.size()); | 806 ASSERT_EQ(3u, notifications_.size()); |
703 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 807 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
704 EXPECT_EQ(pattern, notifications_[0].pattern); | 808 EXPECT_EQ(pattern, notifications_[0].pattern); |
705 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 809 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
706 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); | 810 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); |
707 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 811 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
708 EXPECT_EQ(pattern, notifications_[2].pattern); | 812 EXPECT_EQ(pattern, notifications_[2].pattern); |
709 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 813 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
710 } | 814 } |
711 | 815 |
| 816 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextTest, |
| 817 ServiceWorkerContextTestP, |
| 818 testing::Bool()); |
| 819 |
| 820 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, |
| 821 ServiceWorkerContextRecoveryTest, |
| 822 testing::Combine(testing::Bool(), testing::Bool())); |
712 | 823 |
713 } // namespace content | 824 } // namespace content |
OLD | NEW |