| 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" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 155 } |
| 156 | 156 |
| 157 ServiceWorkerContextCore* context() { return helper_->context(); } | 157 ServiceWorkerContextCore* context() { return helper_->context(); } |
| 158 | 158 |
| 159 protected: | 159 protected: |
| 160 TestBrowserThreadBundle browser_thread_bundle_; | 160 TestBrowserThreadBundle browser_thread_bundle_; |
| 161 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; | 161 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
| 162 std::vector<NotificationLog> notifications_; | 162 std::vector<NotificationLog> notifications_; |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 class ServiceWorkerContextTestP | |
| 166 : public MojoServiceWorkerTestP<ServiceWorkerContextTest> {}; | |
| 167 | |
| 168 class RecordableEmbeddedWorkerInstanceClient | 165 class RecordableEmbeddedWorkerInstanceClient |
| 169 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { | 166 : public EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient { |
| 170 public: | 167 public: |
| 171 enum class Message { StartWorker, StopWorker }; | 168 enum class Message { StartWorker, StopWorker }; |
| 172 | 169 |
| 173 explicit RecordableEmbeddedWorkerInstanceClient( | 170 explicit RecordableEmbeddedWorkerInstanceClient( |
| 174 base::WeakPtr<EmbeddedWorkerTestHelper> helper) | 171 base::WeakPtr<EmbeddedWorkerTestHelper> helper) |
| 175 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} | 172 : EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {} |
| 176 | 173 |
| 177 const std::vector<Message>& events() const { return events_; } | 174 const std::vector<Message>& events() const { return events_; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 191 std::move(callback)); | 188 std::move(callback)); |
| 192 } | 189 } |
| 193 | 190 |
| 194 std::vector<Message> events_; | 191 std::vector<Message> events_; |
| 195 | 192 |
| 196 private: | 193 private: |
| 197 DISALLOW_COPY_AND_ASSIGN(RecordableEmbeddedWorkerInstanceClient); | 194 DISALLOW_COPY_AND_ASSIGN(RecordableEmbeddedWorkerInstanceClient); |
| 198 }; | 195 }; |
| 199 | 196 |
| 200 // Make sure basic registration is working. | 197 // Make sure basic registration is working. |
| 201 TEST_P(ServiceWorkerContextTestP, Register) { | 198 TEST_F(ServiceWorkerContextTest, Register) { |
| 202 GURL pattern("http://www.example.com/"); | 199 GURL pattern("http://www.example.com/"); |
| 203 GURL script_url("http://www.example.com/service_worker.js"); | 200 GURL script_url("http://www.example.com/service_worker.js"); |
| 204 | 201 |
| 205 RecordableEmbeddedWorkerInstanceClient* client = nullptr; | 202 RecordableEmbeddedWorkerInstanceClient* client = nullptr; |
| 206 if (is_mojo_enabled()) { | 203 client = helper_->CreateAndRegisterMockInstanceClient< |
| 207 client = helper_->CreateAndRegisterMockInstanceClient< | 204 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); |
| 208 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); | |
| 209 } | |
| 210 | 205 |
| 211 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 206 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 212 bool called = false; | 207 bool called = false; |
| 213 context()->RegisterServiceWorker( | 208 context()->RegisterServiceWorker( |
| 214 pattern, | 209 pattern, |
| 215 script_url, | 210 script_url, |
| 216 NULL, | 211 NULL, |
| 217 MakeRegisteredCallback(&called, ®istration_id)); | 212 MakeRegisteredCallback(&called, ®istration_id)); |
| 218 | 213 |
| 219 ASSERT_FALSE(called); | 214 ASSERT_FALSE(called); |
| 220 base::RunLoop().RunUntilIdle(); | 215 base::RunLoop().RunUntilIdle(); |
| 221 EXPECT_TRUE(called); | 216 EXPECT_TRUE(called); |
| 222 | 217 |
| 223 if (is_mojo_enabled()) { | 218 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
| 224 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); | 219 ASSERT_EQ(2UL, client->events().size()); |
| 225 ASSERT_EQ(2UL, client->events().size()); | 220 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
| 226 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 221 client->events()[0]); |
| 227 client->events()[0]); | 222 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 228 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 223 ServiceWorkerMsg_InstallEvent::ID)); |
| 229 ServiceWorkerMsg_InstallEvent::ID)); | 224 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 230 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 225 ServiceWorkerMsg_ActivateEvent::ID)); |
| 231 ServiceWorkerMsg_ActivateEvent::ID)); | 226 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 232 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 227 client->events()[1]); |
| 233 client->events()[1]); | 228 |
| 234 } else { | |
| 235 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); | |
| 236 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 237 EmbeddedWorkerMsg_StartWorker::ID)); | |
| 238 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 239 ServiceWorkerMsg_InstallEvent::ID)); | |
| 240 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 241 ServiceWorkerMsg_ActivateEvent::ID)); | |
| 242 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 243 EmbeddedWorkerMsg_StopWorker::ID)); | |
| 244 } | |
| 245 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 229 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 246 | 230 |
| 247 ASSERT_EQ(1u, notifications_.size()); | 231 ASSERT_EQ(1u, notifications_.size()); |
| 248 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 232 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 249 EXPECT_EQ(pattern, notifications_[0].pattern); | 233 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 250 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 234 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 251 | 235 |
| 252 context()->storage()->FindRegistrationForId( | 236 context()->storage()->FindRegistrationForId( |
| 253 registration_id, | 237 registration_id, |
| 254 pattern.GetOrigin(), | 238 pattern.GetOrigin(), |
| 255 base::Bind(&ExpectRegisteredWorkers, | 239 base::Bind(&ExpectRegisteredWorkers, |
| 256 SERVICE_WORKER_OK, | 240 SERVICE_WORKER_OK, |
| 257 false /* expect_waiting */, | 241 false /* expect_waiting */, |
| 258 true /* expect_active */)); | 242 true /* expect_active */)); |
| 259 base::RunLoop().RunUntilIdle(); | 243 base::RunLoop().RunUntilIdle(); |
| 260 } | 244 } |
| 261 | 245 |
| 262 // Test registration when the service worker rejects the install event. The | 246 // Test registration when the service worker rejects the install event. The |
| 263 // registration callback should indicate success, but there should be no waiting | 247 // registration callback should indicate success, but there should be no waiting |
| 264 // or active worker in the registration. | 248 // or active worker in the registration. |
| 265 TEST_P(ServiceWorkerContextTestP, Register_RejectInstall) { | 249 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { |
| 266 GURL pattern("http://www.example.com/"); | 250 GURL pattern("http://www.example.com/"); |
| 267 GURL script_url("http://www.example.com/service_worker.js"); | 251 GURL script_url("http://www.example.com/service_worker.js"); |
| 268 | 252 |
| 269 helper_.reset(); // Make sure the process lookups stay overridden. | 253 helper_.reset(); // Make sure the process lookups stay overridden. |
| 270 helper_.reset(new RejectInstallTestHelper); | 254 helper_.reset(new RejectInstallTestHelper); |
| 271 helper_->context_wrapper()->AddObserver(this); | 255 helper_->context_wrapper()->AddObserver(this); |
| 272 | 256 |
| 273 RecordableEmbeddedWorkerInstanceClient* client = nullptr; | 257 RecordableEmbeddedWorkerInstanceClient* client = nullptr; |
| 274 if (is_mojo_enabled()) { | 258 client = helper_->CreateAndRegisterMockInstanceClient< |
| 275 client = helper_->CreateAndRegisterMockInstanceClient< | 259 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); |
| 276 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); | |
| 277 } | |
| 278 | 260 |
| 279 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 261 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 280 bool called = false; | 262 bool called = false; |
| 281 context()->RegisterServiceWorker( | 263 context()->RegisterServiceWorker( |
| 282 pattern, | 264 pattern, |
| 283 script_url, | 265 script_url, |
| 284 NULL, | 266 NULL, |
| 285 MakeRegisteredCallback(&called, ®istration_id)); | 267 MakeRegisteredCallback(&called, ®istration_id)); |
| 286 | 268 |
| 287 ASSERT_FALSE(called); | 269 ASSERT_FALSE(called); |
| 288 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
| 289 EXPECT_TRUE(called); | 271 EXPECT_TRUE(called); |
| 290 | 272 |
| 291 if (is_mojo_enabled()) { | 273 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
| 292 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); | 274 ASSERT_EQ(2UL, client->events().size()); |
| 293 ASSERT_EQ(2UL, client->events().size()); | 275 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
| 294 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 276 client->events()[0]); |
| 295 client->events()[0]); | 277 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 296 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 278 ServiceWorkerMsg_InstallEvent::ID)); |
| 297 ServiceWorkerMsg_InstallEvent::ID)); | 279 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 298 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 280 ServiceWorkerMsg_ActivateEvent::ID)); |
| 299 ServiceWorkerMsg_ActivateEvent::ID)); | 281 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 300 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 282 client->events()[1]); |
| 301 client->events()[1]); | 283 |
| 302 } else { | |
| 303 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); | |
| 304 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 305 EmbeddedWorkerMsg_StartWorker::ID)); | |
| 306 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 307 ServiceWorkerMsg_InstallEvent::ID)); | |
| 308 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 309 ServiceWorkerMsg_ActivateEvent::ID)); | |
| 310 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 311 EmbeddedWorkerMsg_StopWorker::ID)); | |
| 312 } | |
| 313 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 284 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 314 | 285 |
| 315 ASSERT_EQ(1u, notifications_.size()); | 286 ASSERT_EQ(1u, notifications_.size()); |
| 316 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 287 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 317 EXPECT_EQ(pattern, notifications_[0].pattern); | 288 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 318 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 289 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 319 | 290 |
| 320 context()->storage()->FindRegistrationForId( | 291 context()->storage()->FindRegistrationForId( |
| 321 registration_id, | 292 registration_id, |
| 322 pattern.GetOrigin(), | 293 pattern.GetOrigin(), |
| 323 base::Bind(&ExpectRegisteredWorkers, | 294 base::Bind(&ExpectRegisteredWorkers, |
| 324 SERVICE_WORKER_ERROR_NOT_FOUND, | 295 SERVICE_WORKER_ERROR_NOT_FOUND, |
| 325 false /* expect_waiting */, | 296 false /* expect_waiting */, |
| 326 false /* expect_active */)); | 297 false /* expect_active */)); |
| 327 base::RunLoop().RunUntilIdle(); | 298 base::RunLoop().RunUntilIdle(); |
| 328 } | 299 } |
| 329 | 300 |
| 330 // Test registration when the service worker rejects the activate event. The | 301 // Test registration when the service worker rejects the activate event. The |
| 331 // worker should be activated anyway. | 302 // worker should be activated anyway. |
| 332 TEST_P(ServiceWorkerContextTestP, Register_RejectActivate) { | 303 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { |
| 333 GURL pattern("http://www.example.com/"); | 304 GURL pattern("http://www.example.com/"); |
| 334 GURL script_url("http://www.example.com/service_worker.js"); | 305 GURL script_url("http://www.example.com/service_worker.js"); |
| 335 | 306 |
| 336 helper_.reset(); | 307 helper_.reset(); |
| 337 helper_.reset(new RejectActivateTestHelper); | 308 helper_.reset(new RejectActivateTestHelper); |
| 338 helper_->context_wrapper()->AddObserver(this); | 309 helper_->context_wrapper()->AddObserver(this); |
| 339 | 310 |
| 340 RecordableEmbeddedWorkerInstanceClient* client = nullptr; | 311 RecordableEmbeddedWorkerInstanceClient* client = nullptr; |
| 341 if (is_mojo_enabled()) { | 312 client = helper_->CreateAndRegisterMockInstanceClient< |
| 342 client = helper_->CreateAndRegisterMockInstanceClient< | 313 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); |
| 343 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr()); | |
| 344 } | |
| 345 | 314 |
| 346 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 315 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 347 bool called = false; | 316 bool called = false; |
| 348 context()->RegisterServiceWorker( | 317 context()->RegisterServiceWorker( |
| 349 pattern, script_url, NULL, | 318 pattern, script_url, NULL, |
| 350 MakeRegisteredCallback(&called, ®istration_id)); | 319 MakeRegisteredCallback(&called, ®istration_id)); |
| 351 | 320 |
| 352 ASSERT_FALSE(called); | 321 ASSERT_FALSE(called); |
| 353 base::RunLoop().RunUntilIdle(); | 322 base::RunLoop().RunUntilIdle(); |
| 354 EXPECT_TRUE(called); | 323 EXPECT_TRUE(called); |
| 355 | 324 |
| 356 if (is_mojo_enabled()) { | 325 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
| 357 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); | 326 ASSERT_EQ(2UL, client->events().size()); |
| 358 ASSERT_EQ(2UL, client->events().size()); | 327 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, |
| 359 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker, | 328 client->events()[0]); |
| 360 client->events()[0]); | 329 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 361 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 330 ServiceWorkerMsg_InstallEvent::ID)); |
| 362 ServiceWorkerMsg_InstallEvent::ID)); | 331 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 363 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 332 ServiceWorkerMsg_ActivateEvent::ID)); |
| 364 ServiceWorkerMsg_ActivateEvent::ID)); | 333 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, |
| 365 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker, | 334 client->events()[1]); |
| 366 client->events()[1]); | 335 |
| 367 } else { | |
| 368 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); | |
| 369 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 370 EmbeddedWorkerMsg_StartWorker::ID)); | |
| 371 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 372 ServiceWorkerMsg_InstallEvent::ID)); | |
| 373 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 374 ServiceWorkerMsg_ActivateEvent::ID)); | |
| 375 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 376 EmbeddedWorkerMsg_StopWorker::ID)); | |
| 377 } | |
| 378 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 336 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 379 | 337 |
| 380 ASSERT_EQ(1u, notifications_.size()); | 338 ASSERT_EQ(1u, notifications_.size()); |
| 381 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 339 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 382 EXPECT_EQ(pattern, notifications_[0].pattern); | 340 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 383 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 341 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 384 | 342 |
| 385 context()->storage()->FindRegistrationForId( | 343 context()->storage()->FindRegistrationForId( |
| 386 registration_id, pattern.GetOrigin(), | 344 registration_id, pattern.GetOrigin(), |
| 387 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK, | 345 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK, |
| 388 false /* expect_waiting */, true /* expect_active */)); | 346 false /* expect_waiting */, true /* expect_active */)); |
| 389 base::RunLoop().RunUntilIdle(); | 347 base::RunLoop().RunUntilIdle(); |
| 390 } | 348 } |
| 391 | 349 |
| 392 // Make sure registrations are cleaned up when they are unregistered. | 350 // Make sure registrations are cleaned up when they are unregistered. |
| 393 TEST_P(ServiceWorkerContextTestP, Unregister) { | 351 TEST_F(ServiceWorkerContextTest, Unregister) { |
| 394 GURL pattern("http://www.example.com/"); | 352 GURL pattern("http://www.example.com/"); |
| 395 | 353 |
| 396 bool called = false; | 354 bool called = false; |
| 397 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 355 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 398 context()->RegisterServiceWorker( | 356 context()->RegisterServiceWorker( |
| 399 pattern, | 357 pattern, |
| 400 GURL("http://www.example.com/service_worker.js"), | 358 GURL("http://www.example.com/service_worker.js"), |
| 401 NULL, | 359 NULL, |
| 402 MakeRegisteredCallback(&called, ®istration_id)); | 360 MakeRegisteredCallback(&called, ®istration_id)); |
| 403 | 361 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 426 ASSERT_EQ(2u, notifications_.size()); | 384 ASSERT_EQ(2u, notifications_.size()); |
| 427 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 385 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 428 EXPECT_EQ(pattern, notifications_[0].pattern); | 386 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 429 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 387 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 430 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); | 388 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); |
| 431 EXPECT_EQ(pattern, notifications_[1].pattern); | 389 EXPECT_EQ(pattern, notifications_[1].pattern); |
| 432 EXPECT_EQ(registration_id, notifications_[1].registration_id); | 390 EXPECT_EQ(registration_id, notifications_[1].registration_id); |
| 433 } | 391 } |
| 434 | 392 |
| 435 // Make sure registrations are cleaned up when they are unregistered in bulk. | 393 // Make sure registrations are cleaned up when they are unregistered in bulk. |
| 436 TEST_P(ServiceWorkerContextTestP, UnregisterMultiple) { | 394 TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { |
| 437 GURL origin1_p1("http://www.example.com/test"); | 395 GURL origin1_p1("http://www.example.com/test"); |
| 438 GURL origin1_p2("http://www.example.com/hello"); | 396 GURL origin1_p2("http://www.example.com/hello"); |
| 439 GURL origin2_p1("http://www.example.com:8080/again"); | 397 GURL origin2_p1("http://www.example.com:8080/again"); |
| 440 GURL origin3_p1("http://www.other.com/"); | 398 GURL origin3_p1("http://www.other.com/"); |
| 441 | 399 |
| 442 bool called = false; | 400 bool called = false; |
| 443 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId; | 401 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId; |
| 444 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId; | 402 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId; |
| 445 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId; | 403 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId; |
| 446 int64_t registration_id4 = kInvalidServiceWorkerRegistrationId; | 404 int64_t registration_id4 = kInvalidServiceWorkerRegistrationId; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 EXPECT_EQ(registration_id4, notifications_[3].registration_id); | 487 EXPECT_EQ(registration_id4, notifications_[3].registration_id); |
| 530 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); | 488 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); |
| 531 EXPECT_EQ(origin1_p2, notifications_[4].pattern); | 489 EXPECT_EQ(origin1_p2, notifications_[4].pattern); |
| 532 EXPECT_EQ(registration_id2, notifications_[4].registration_id); | 490 EXPECT_EQ(registration_id2, notifications_[4].registration_id); |
| 533 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); | 491 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); |
| 534 EXPECT_EQ(origin1_p1, notifications_[5].pattern); | 492 EXPECT_EQ(origin1_p1, notifications_[5].pattern); |
| 535 EXPECT_EQ(registration_id1, notifications_[5].registration_id); | 493 EXPECT_EQ(registration_id1, notifications_[5].registration_id); |
| 536 } | 494 } |
| 537 | 495 |
| 538 // Make sure registering a new script shares an existing registration. | 496 // Make sure registering a new script shares an existing registration. |
| 539 TEST_P(ServiceWorkerContextTestP, RegisterNewScript) { | 497 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { |
| 540 GURL pattern("http://www.example.com/"); | 498 GURL pattern("http://www.example.com/"); |
| 541 | 499 |
| 542 bool called = false; | 500 bool called = false; |
| 543 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; | 501 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; |
| 544 context()->RegisterServiceWorker( | 502 context()->RegisterServiceWorker( |
| 545 pattern, | 503 pattern, |
| 546 GURL("http://www.example.com/service_worker.js"), | 504 GURL("http://www.example.com/service_worker.js"), |
| 547 NULL, | 505 NULL, |
| 548 MakeRegisteredCallback(&called, &old_registration_id)); | 506 MakeRegisteredCallback(&called, &old_registration_id)); |
| 549 | 507 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 571 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 529 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 572 EXPECT_EQ(pattern, notifications_[0].pattern); | 530 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 573 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); | 531 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); |
| 574 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); | 532 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); |
| 575 EXPECT_EQ(pattern, notifications_[1].pattern); | 533 EXPECT_EQ(pattern, notifications_[1].pattern); |
| 576 EXPECT_EQ(new_registration_id, notifications_[1].registration_id); | 534 EXPECT_EQ(new_registration_id, notifications_[1].registration_id); |
| 577 } | 535 } |
| 578 | 536 |
| 579 // Make sure that when registering a duplicate pattern+script_url | 537 // Make sure that when registering a duplicate pattern+script_url |
| 580 // combination, that the same registration is used. | 538 // combination, that the same registration is used. |
| 581 TEST_P(ServiceWorkerContextTestP, RegisterDuplicateScript) { | 539 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { |
| 582 GURL pattern("http://www.example.com/"); | 540 GURL pattern("http://www.example.com/"); |
| 583 GURL script_url("http://www.example.com/service_worker.js"); | 541 GURL script_url("http://www.example.com/service_worker.js"); |
| 584 | 542 |
| 585 bool called = false; | 543 bool called = false; |
| 586 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; | 544 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; |
| 587 context()->RegisterServiceWorker( | 545 context()->RegisterServiceWorker( |
| 588 pattern, | 546 pattern, |
| 589 script_url, | 547 script_url, |
| 590 NULL, | 548 NULL, |
| 591 MakeRegisteredCallback(&called, &old_registration_id)); | 549 MakeRegisteredCallback(&called, &old_registration_id)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 610 | 568 |
| 611 ASSERT_EQ(2u, notifications_.size()); | 569 ASSERT_EQ(2u, notifications_.size()); |
| 612 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 570 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 613 EXPECT_EQ(pattern, notifications_[0].pattern); | 571 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 614 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); | 572 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); |
| 615 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); | 573 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); |
| 616 EXPECT_EQ(pattern, notifications_[1].pattern); | 574 EXPECT_EQ(pattern, notifications_[1].pattern); |
| 617 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); | 575 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); |
| 618 } | 576 } |
| 619 | 577 |
| 620 TEST_P(ServiceWorkerContextTestP, ProviderHostIterator) { | 578 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { |
| 621 const int kRenderProcessId1 = 1; | 579 const int kRenderProcessId1 = 1; |
| 622 const int kRenderProcessId2 = 2; | 580 const int kRenderProcessId2 = 2; |
| 623 const GURL kOrigin1 = GURL("http://www.example.com/"); | 581 const GURL kOrigin1 = GURL("http://www.example.com/"); |
| 624 const GURL kOrigin2 = GURL("https://www.example.com/"); | 582 const GURL kOrigin2 = GURL("https://www.example.com/"); |
| 625 int provider_id = 1; | 583 int provider_id = 1; |
| 626 | 584 |
| 627 // Host1 (provider_id=1): process_id=1, origin1. | 585 // Host1 (provider_id=1): process_id=1, origin1. |
| 628 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( | 586 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( |
| 629 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, | 587 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, |
| 630 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 588 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 EXPECT_TRUE(ContainsKey(results, host2)); | 652 EXPECT_TRUE(ContainsKey(results, host2)); |
| 695 | 653 |
| 696 context()->RemoveProviderHost(kRenderProcessId1, 1); | 654 context()->RemoveProviderHost(kRenderProcessId1, 1); |
| 697 context()->RemoveProviderHost(kRenderProcessId2, 2); | 655 context()->RemoveProviderHost(kRenderProcessId2, 2); |
| 698 context()->RemoveProviderHost(kRenderProcessId2, 3); | 656 context()->RemoveProviderHost(kRenderProcessId2, 3); |
| 699 context()->RemoveProviderHost(kRenderProcessId2, 4); | 657 context()->RemoveProviderHost(kRenderProcessId2, 4); |
| 700 } | 658 } |
| 701 | 659 |
| 702 class ServiceWorkerContextRecoveryTest | 660 class ServiceWorkerContextRecoveryTest |
| 703 : public ServiceWorkerContextTest, | 661 : public ServiceWorkerContextTest, |
| 704 public testing::WithParamInterface<testing::tuple<bool, bool>> { | 662 public testing::WithParamInterface<bool> { |
| 705 public: | 663 public: |
| 706 ServiceWorkerContextRecoveryTest() {} | 664 ServiceWorkerContextRecoveryTest() {} |
| 707 virtual ~ServiceWorkerContextRecoveryTest() {} | 665 virtual ~ServiceWorkerContextRecoveryTest() {} |
| 708 | 666 |
| 709 protected: | 667 protected: |
| 710 void SetUp() override { | 668 bool is_storage_on_disk() const { return GetParam(); } |
| 711 if (!is_mojo_enabled()) { | |
| 712 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 713 switches::kDisableMojoServiceWorker); | |
| 714 } | |
| 715 ServiceWorkerContextTest::SetUp(); | |
| 716 } | |
| 717 | |
| 718 bool is_mojo_enabled() const { return testing::get<0>(GetParam()); } | |
| 719 bool is_storage_on_disk() const { return testing::get<1>(GetParam()); } | |
| 720 }; | 669 }; |
| 721 | 670 |
| 722 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { | 671 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { |
| 723 GURL pattern("http://www.example.com/"); | 672 GURL pattern("http://www.example.com/"); |
| 724 GURL script_url("http://www.example.com/service_worker.js"); | 673 GURL script_url("http://www.example.com/service_worker.js"); |
| 725 | 674 |
| 726 if (is_storage_on_disk()) { | 675 if (is_storage_on_disk()) { |
| 727 // Reinitialize the helper to test on-disk storage. | 676 // Reinitialize the helper to test on-disk storage. |
| 728 base::ScopedTempDir user_data_directory; | 677 base::ScopedTempDir user_data_directory; |
| 729 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir()); | 678 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 ASSERT_EQ(3u, notifications_.size()); | 753 ASSERT_EQ(3u, notifications_.size()); |
| 805 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 754 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 806 EXPECT_EQ(pattern, notifications_[0].pattern); | 755 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 807 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 756 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 808 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); | 757 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); |
| 809 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 758 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
| 810 EXPECT_EQ(pattern, notifications_[2].pattern); | 759 EXPECT_EQ(pattern, notifications_[2].pattern); |
| 811 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 760 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
| 812 } | 761 } |
| 813 | 762 |
| 814 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextTest, | 763 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, |
| 815 ServiceWorkerContextTestP, | 764 ServiceWorkerContextRecoveryTest, |
| 816 testing::Bool()); | 765 testing::Bool()); |
| 817 | 766 |
| 818 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | |
| 819 ServiceWorkerContextRecoveryTest, | |
| 820 testing::Combine(testing::Bool(), testing::Bool())); | |
| 821 | |
| 822 } // namespace content | 767 } // namespace content |
| OLD | NEW |