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/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 | |
| 164 // Make sure basic registration is working. | 168 // Make sure basic registration is working. |
| 165 TEST_F(ServiceWorkerContextTest, Register) { | 169 TEST_P(ServiceWorkerContextTestP, Register) { |
| 166 GURL pattern("http://www.example.com/"); | 170 GURL pattern("http://www.example.com/"); |
| 167 GURL script_url("http://www.example.com/service_worker.js"); | 171 GURL script_url("http://www.example.com/service_worker.js"); |
| 168 | 172 |
| 169 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 173 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 170 bool called = false; | 174 bool called = false; |
| 171 context()->RegisterServiceWorker( | 175 context()->RegisterServiceWorker( |
| 172 pattern, | 176 pattern, |
| 173 script_url, | 177 script_url, |
| 174 NULL, | 178 NULL, |
| 175 MakeRegisteredCallback(&called, ®istration_id)); | 179 MakeRegisteredCallback(&called, ®istration_id)); |
| 176 | 180 |
| 177 ASSERT_FALSE(called); | 181 ASSERT_FALSE(called); |
| 178 base::RunLoop().RunUntilIdle(); | 182 base::RunLoop().RunUntilIdle(); |
| 179 EXPECT_TRUE(called); | 183 EXPECT_TRUE(called); |
| 180 | 184 |
| 181 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); | 185 if (is_mojo_enabled()) { |
| 182 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 186 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
|
horo
2016/10/19 04:50:09
Please check this using CreateAndRegisterMockInsta
shimazu
2016/10/20 05:08:45
Done.
| |
| 183 EmbeddedWorkerMsg_StartWorker::ID)); | 187 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 184 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 188 ServiceWorkerMsg_InstallEvent::ID)); |
| 185 ServiceWorkerMsg_InstallEvent::ID)); | 189 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 186 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 190 ServiceWorkerMsg_ActivateEvent::ID)); |
| 187 ServiceWorkerMsg_ActivateEvent::ID)); | 191 } else { |
| 188 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 192 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); |
| 189 EmbeddedWorkerMsg_StopWorker::ID)); | 193 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 194 EmbeddedWorkerMsg_StartWorker::ID)); | |
| 195 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 196 ServiceWorkerMsg_InstallEvent::ID)); | |
| 197 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 198 ServiceWorkerMsg_ActivateEvent::ID)); | |
| 199 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 200 EmbeddedWorkerMsg_StopWorker::ID)); | |
| 201 } | |
| 190 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 202 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 191 | 203 |
| 192 ASSERT_EQ(1u, notifications_.size()); | 204 ASSERT_EQ(1u, notifications_.size()); |
| 193 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 205 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 194 EXPECT_EQ(pattern, notifications_[0].pattern); | 206 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 195 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 207 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 196 | 208 |
| 197 context()->storage()->FindRegistrationForId( | 209 context()->storage()->FindRegistrationForId( |
| 198 registration_id, | 210 registration_id, |
| 199 pattern.GetOrigin(), | 211 pattern.GetOrigin(), |
| 200 base::Bind(&ExpectRegisteredWorkers, | 212 base::Bind(&ExpectRegisteredWorkers, |
| 201 SERVICE_WORKER_OK, | 213 SERVICE_WORKER_OK, |
| 202 false /* expect_waiting */, | 214 false /* expect_waiting */, |
| 203 true /* expect_active */)); | 215 true /* expect_active */)); |
| 204 base::RunLoop().RunUntilIdle(); | 216 base::RunLoop().RunUntilIdle(); |
| 205 } | 217 } |
| 206 | 218 |
| 207 // Test registration when the service worker rejects the install event. The | 219 // Test registration when the service worker rejects the install event. The |
| 208 // registration callback should indicate success, but there should be no waiting | 220 // registration callback should indicate success, but there should be no waiting |
| 209 // or active worker in the registration. | 221 // or active worker in the registration. |
| 210 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { | 222 TEST_P(ServiceWorkerContextTestP, Register_RejectInstall) { |
| 211 GURL pattern("http://www.example.com/"); | 223 GURL pattern("http://www.example.com/"); |
| 212 GURL script_url("http://www.example.com/service_worker.js"); | 224 GURL script_url("http://www.example.com/service_worker.js"); |
| 213 | 225 |
| 214 helper_.reset(); // Make sure the process lookups stay overridden. | 226 helper_.reset(); // Make sure the process lookups stay overridden. |
| 215 helper_.reset(new RejectInstallTestHelper); | 227 helper_.reset(new RejectInstallTestHelper); |
| 216 helper_->context_wrapper()->AddObserver(this); | 228 helper_->context_wrapper()->AddObserver(this); |
| 217 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 229 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 218 bool called = false; | 230 bool called = false; |
| 219 context()->RegisterServiceWorker( | 231 context()->RegisterServiceWorker( |
| 220 pattern, | 232 pattern, |
| 221 script_url, | 233 script_url, |
| 222 NULL, | 234 NULL, |
| 223 MakeRegisteredCallback(&called, ®istration_id)); | 235 MakeRegisteredCallback(&called, ®istration_id)); |
| 224 | 236 |
| 225 ASSERT_FALSE(called); | 237 ASSERT_FALSE(called); |
| 226 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
| 227 EXPECT_TRUE(called); | 239 EXPECT_TRUE(called); |
| 228 | 240 |
| 229 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); | 241 if (is_mojo_enabled()) { |
| 230 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 242 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
|
horo
2016/10/19 04:50:09
ditto
shimazu
2016/10/20 05:08:45
Done.
| |
| 231 EmbeddedWorkerMsg_StartWorker::ID)); | 243 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 232 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 244 ServiceWorkerMsg_InstallEvent::ID)); |
| 233 ServiceWorkerMsg_InstallEvent::ID)); | 245 // ActivateEvent shouldn't be recorded. |
| 234 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 246 } else { |
| 235 ServiceWorkerMsg_ActivateEvent::ID)); | 247 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); |
| 236 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 248 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 237 EmbeddedWorkerMsg_StopWorker::ID)); | 249 EmbeddedWorkerMsg_StartWorker::ID)); |
| 250 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 251 ServiceWorkerMsg_InstallEvent::ID)); | |
| 252 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 253 ServiceWorkerMsg_ActivateEvent::ID)); | |
| 254 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 255 EmbeddedWorkerMsg_StopWorker::ID)); | |
| 256 } | |
| 238 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 257 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 239 | 258 |
| 240 ASSERT_EQ(1u, notifications_.size()); | 259 ASSERT_EQ(1u, notifications_.size()); |
| 241 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 260 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 242 EXPECT_EQ(pattern, notifications_[0].pattern); | 261 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 243 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 262 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 244 | 263 |
| 245 context()->storage()->FindRegistrationForId( | 264 context()->storage()->FindRegistrationForId( |
| 246 registration_id, | 265 registration_id, |
| 247 pattern.GetOrigin(), | 266 pattern.GetOrigin(), |
| 248 base::Bind(&ExpectRegisteredWorkers, | 267 base::Bind(&ExpectRegisteredWorkers, |
| 249 SERVICE_WORKER_ERROR_NOT_FOUND, | 268 SERVICE_WORKER_ERROR_NOT_FOUND, |
| 250 false /* expect_waiting */, | 269 false /* expect_waiting */, |
| 251 false /* expect_active */)); | 270 false /* expect_active */)); |
| 252 base::RunLoop().RunUntilIdle(); | 271 base::RunLoop().RunUntilIdle(); |
| 253 } | 272 } |
| 254 | 273 |
| 255 // Test registration when the service worker rejects the activate event. The | 274 // Test registration when the service worker rejects the activate event. The |
| 256 // worker should be activated anyway. | 275 // worker should be activated anyway. |
| 257 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { | 276 TEST_P(ServiceWorkerContextTestP, Register_RejectActivate) { |
| 258 GURL pattern("http://www.example.com/"); | 277 GURL pattern("http://www.example.com/"); |
| 259 GURL script_url("http://www.example.com/service_worker.js"); | 278 GURL script_url("http://www.example.com/service_worker.js"); |
| 260 | 279 |
| 261 helper_.reset(); | 280 helper_.reset(); |
| 262 helper_.reset(new RejectActivateTestHelper); | 281 helper_.reset(new RejectActivateTestHelper); |
| 263 helper_->context_wrapper()->AddObserver(this); | 282 helper_->context_wrapper()->AddObserver(this); |
| 264 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 283 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 265 bool called = false; | 284 bool called = false; |
| 266 context()->RegisterServiceWorker( | 285 context()->RegisterServiceWorker( |
| 267 pattern, script_url, NULL, | 286 pattern, script_url, NULL, |
| 268 MakeRegisteredCallback(&called, ®istration_id)); | 287 MakeRegisteredCallback(&called, ®istration_id)); |
| 269 | 288 |
| 270 ASSERT_FALSE(called); | 289 ASSERT_FALSE(called); |
| 271 base::RunLoop().RunUntilIdle(); | 290 base::RunLoop().RunUntilIdle(); |
| 272 EXPECT_TRUE(called); | 291 EXPECT_TRUE(called); |
| 273 | 292 |
| 274 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); | 293 if (is_mojo_enabled()) { |
| 275 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 294 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count()); |
|
horo
2016/10/19 04:50:09
ditto
shimazu
2016/10/20 05:08:45
Done.
| |
| 276 EmbeddedWorkerMsg_StartWorker::ID)); | 295 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 277 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 296 ServiceWorkerMsg_InstallEvent::ID)); |
| 278 ServiceWorkerMsg_InstallEvent::ID)); | 297 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( |
| 279 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | 298 ServiceWorkerMsg_ActivateEvent::ID)); |
| 280 ServiceWorkerMsg_ActivateEvent::ID)); | 299 } else { |
| 281 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | 300 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); |
| 282 EmbeddedWorkerMsg_StopWorker::ID)); | 301 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( |
| 302 EmbeddedWorkerMsg_StartWorker::ID)); | |
| 303 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 304 ServiceWorkerMsg_InstallEvent::ID)); | |
| 305 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( | |
| 306 ServiceWorkerMsg_ActivateEvent::ID)); | |
| 307 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( | |
| 308 EmbeddedWorkerMsg_StopWorker::ID)); | |
| 309 } | |
| 283 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); | 310 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); |
| 284 | 311 |
| 285 ASSERT_EQ(1u, notifications_.size()); | 312 ASSERT_EQ(1u, notifications_.size()); |
| 286 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 313 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 287 EXPECT_EQ(pattern, notifications_[0].pattern); | 314 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 288 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 315 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 289 | 316 |
| 290 context()->storage()->FindRegistrationForId( | 317 context()->storage()->FindRegistrationForId( |
| 291 registration_id, pattern.GetOrigin(), | 318 registration_id, pattern.GetOrigin(), |
| 292 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK, | 319 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK, |
| 293 false /* expect_waiting */, true /* expect_active */)); | 320 false /* expect_waiting */, true /* expect_active */)); |
| 294 base::RunLoop().RunUntilIdle(); | 321 base::RunLoop().RunUntilIdle(); |
| 295 } | 322 } |
| 296 | 323 |
| 297 // Make sure registrations are cleaned up when they are unregistered. | 324 // Make sure registrations are cleaned up when they are unregistered. |
| 298 TEST_F(ServiceWorkerContextTest, Unregister) { | 325 TEST_P(ServiceWorkerContextTestP, Unregister) { |
| 299 GURL pattern("http://www.example.com/"); | 326 GURL pattern("http://www.example.com/"); |
| 300 | 327 |
| 301 bool called = false; | 328 bool called = false; |
| 302 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 329 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 303 context()->RegisterServiceWorker( | 330 context()->RegisterServiceWorker( |
| 304 pattern, | 331 pattern, |
| 305 GURL("http://www.example.com/service_worker.js"), | 332 GURL("http://www.example.com/service_worker.js"), |
| 306 NULL, | 333 NULL, |
| 307 MakeRegisteredCallback(&called, ®istration_id)); | 334 MakeRegisteredCallback(&called, ®istration_id)); |
| 308 | 335 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 331 ASSERT_EQ(2u, notifications_.size()); | 358 ASSERT_EQ(2u, notifications_.size()); |
| 332 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 359 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 333 EXPECT_EQ(pattern, notifications_[0].pattern); | 360 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 334 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 361 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 335 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); | 362 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); |
| 336 EXPECT_EQ(pattern, notifications_[1].pattern); | 363 EXPECT_EQ(pattern, notifications_[1].pattern); |
| 337 EXPECT_EQ(registration_id, notifications_[1].registration_id); | 364 EXPECT_EQ(registration_id, notifications_[1].registration_id); |
| 338 } | 365 } |
| 339 | 366 |
| 340 // Make sure registrations are cleaned up when they are unregistered in bulk. | 367 // Make sure registrations are cleaned up when they are unregistered in bulk. |
| 341 TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { | 368 TEST_P(ServiceWorkerContextTestP, UnregisterMultiple) { |
| 342 GURL origin1_p1("http://www.example.com/test"); | 369 GURL origin1_p1("http://www.example.com/test"); |
| 343 GURL origin1_p2("http://www.example.com/hello"); | 370 GURL origin1_p2("http://www.example.com/hello"); |
| 344 GURL origin2_p1("http://www.example.com:8080/again"); | 371 GURL origin2_p1("http://www.example.com:8080/again"); |
| 345 GURL origin3_p1("http://www.other.com/"); | 372 GURL origin3_p1("http://www.other.com/"); |
| 346 | 373 |
| 347 bool called = false; | 374 bool called = false; |
| 348 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId; | 375 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId; |
| 349 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId; | 376 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId; |
| 350 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId; | 377 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId; |
| 351 int64_t registration_id4 = kInvalidServiceWorkerRegistrationId; | 378 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); | 461 EXPECT_EQ(registration_id4, notifications_[3].registration_id); |
| 435 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); | 462 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); |
| 436 EXPECT_EQ(origin1_p2, notifications_[4].pattern); | 463 EXPECT_EQ(origin1_p2, notifications_[4].pattern); |
| 437 EXPECT_EQ(registration_id2, notifications_[4].registration_id); | 464 EXPECT_EQ(registration_id2, notifications_[4].registration_id); |
| 438 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); | 465 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); |
| 439 EXPECT_EQ(origin1_p1, notifications_[5].pattern); | 466 EXPECT_EQ(origin1_p1, notifications_[5].pattern); |
| 440 EXPECT_EQ(registration_id1, notifications_[5].registration_id); | 467 EXPECT_EQ(registration_id1, notifications_[5].registration_id); |
| 441 } | 468 } |
| 442 | 469 |
| 443 // Make sure registering a new script shares an existing registration. | 470 // Make sure registering a new script shares an existing registration. |
| 444 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { | 471 TEST_P(ServiceWorkerContextTestP, RegisterNewScript) { |
| 445 GURL pattern("http://www.example.com/"); | 472 GURL pattern("http://www.example.com/"); |
| 446 | 473 |
| 447 bool called = false; | 474 bool called = false; |
| 448 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; | 475 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; |
| 449 context()->RegisterServiceWorker( | 476 context()->RegisterServiceWorker( |
| 450 pattern, | 477 pattern, |
| 451 GURL("http://www.example.com/service_worker.js"), | 478 GURL("http://www.example.com/service_worker.js"), |
| 452 NULL, | 479 NULL, |
| 453 MakeRegisteredCallback(&called, &old_registration_id)); | 480 MakeRegisteredCallback(&called, &old_registration_id)); |
| 454 | 481 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 476 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 503 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 477 EXPECT_EQ(pattern, notifications_[0].pattern); | 504 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 478 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); | 505 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); |
| 479 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); | 506 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); |
| 480 EXPECT_EQ(pattern, notifications_[1].pattern); | 507 EXPECT_EQ(pattern, notifications_[1].pattern); |
| 481 EXPECT_EQ(new_registration_id, notifications_[1].registration_id); | 508 EXPECT_EQ(new_registration_id, notifications_[1].registration_id); |
| 482 } | 509 } |
| 483 | 510 |
| 484 // Make sure that when registering a duplicate pattern+script_url | 511 // Make sure that when registering a duplicate pattern+script_url |
| 485 // combination, that the same registration is used. | 512 // combination, that the same registration is used. |
| 486 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { | 513 TEST_P(ServiceWorkerContextTestP, RegisterDuplicateScript) { |
| 487 GURL pattern("http://www.example.com/"); | 514 GURL pattern("http://www.example.com/"); |
| 488 GURL script_url("http://www.example.com/service_worker.js"); | 515 GURL script_url("http://www.example.com/service_worker.js"); |
| 489 | 516 |
| 490 bool called = false; | 517 bool called = false; |
| 491 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; | 518 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; |
| 492 context()->RegisterServiceWorker( | 519 context()->RegisterServiceWorker( |
| 493 pattern, | 520 pattern, |
| 494 script_url, | 521 script_url, |
| 495 NULL, | 522 NULL, |
| 496 MakeRegisteredCallback(&called, &old_registration_id)); | 523 MakeRegisteredCallback(&called, &old_registration_id)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 515 | 542 |
| 516 ASSERT_EQ(2u, notifications_.size()); | 543 ASSERT_EQ(2u, notifications_.size()); |
| 517 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 544 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 518 EXPECT_EQ(pattern, notifications_[0].pattern); | 545 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 519 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); | 546 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); |
| 520 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); | 547 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); |
| 521 EXPECT_EQ(pattern, notifications_[1].pattern); | 548 EXPECT_EQ(pattern, notifications_[1].pattern); |
| 522 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); | 549 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); |
| 523 } | 550 } |
| 524 | 551 |
| 525 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { | 552 TEST_P(ServiceWorkerContextTestP, ProviderHostIterator) { |
| 526 const int kRenderProcessId1 = 1; | 553 const int kRenderProcessId1 = 1; |
| 527 const int kRenderProcessId2 = 2; | 554 const int kRenderProcessId2 = 2; |
| 528 const GURL kOrigin1 = GURL("http://www.example.com/"); | 555 const GURL kOrigin1 = GURL("http://www.example.com/"); |
| 529 const GURL kOrigin2 = GURL("https://www.example.com/"); | 556 const GURL kOrigin2 = GURL("https://www.example.com/"); |
| 530 int provider_id = 1; | 557 int provider_id = 1; |
| 531 | 558 |
| 532 // Host1 (provider_id=1): process_id=1, origin1. | 559 // Host1 (provider_id=1): process_id=1, origin1. |
| 533 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( | 560 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( |
| 534 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, | 561 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, |
| 535 SERVICE_WORKER_PROVIDER_FOR_WINDOW, | 562 SERVICE_WORKER_PROVIDER_FOR_WINDOW, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 EXPECT_TRUE(ContainsKey(results, host2)); | 626 EXPECT_TRUE(ContainsKey(results, host2)); |
| 600 | 627 |
| 601 context()->RemoveProviderHost(kRenderProcessId1, 1); | 628 context()->RemoveProviderHost(kRenderProcessId1, 1); |
| 602 context()->RemoveProviderHost(kRenderProcessId2, 2); | 629 context()->RemoveProviderHost(kRenderProcessId2, 2); |
| 603 context()->RemoveProviderHost(kRenderProcessId2, 3); | 630 context()->RemoveProviderHost(kRenderProcessId2, 3); |
| 604 context()->RemoveProviderHost(kRenderProcessId2, 4); | 631 context()->RemoveProviderHost(kRenderProcessId2, 4); |
| 605 } | 632 } |
| 606 | 633 |
| 607 class ServiceWorkerContextRecoveryTest | 634 class ServiceWorkerContextRecoveryTest |
| 608 : public ServiceWorkerContextTest, | 635 : public ServiceWorkerContextTest, |
| 609 public testing::WithParamInterface<bool> { | 636 public testing::WithParamInterface<testing::tuple<bool, bool>> { |
| 610 public: | 637 public: |
| 611 ServiceWorkerContextRecoveryTest() {} | 638 ServiceWorkerContextRecoveryTest() {} |
| 612 virtual ~ServiceWorkerContextRecoveryTest() {} | 639 virtual ~ServiceWorkerContextRecoveryTest() {} |
| 640 | |
| 641 protected: | |
| 642 void SetUp() override { | |
| 643 if (is_mojo_enabled()) { | |
| 644 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 645 switches::kMojoServiceWorker); | |
| 646 } | |
| 647 ServiceWorkerContextTest::SetUp(); | |
| 648 } | |
| 649 | |
| 650 bool is_mojo_enabled() const { return testing::get<0>(GetParam()); } | |
| 651 bool is_storage_on_disk() const { return testing::get<1>(GetParam()); } | |
| 613 }; | 652 }; |
| 614 | 653 |
| 615 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | |
| 616 ServiceWorkerContextRecoveryTest, | |
| 617 testing::Values(true, false)); | |
| 618 | |
| 619 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { | 654 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { |
| 620 GURL pattern("http://www.example.com/"); | 655 GURL pattern("http://www.example.com/"); |
| 621 GURL script_url("http://www.example.com/service_worker.js"); | 656 GURL script_url("http://www.example.com/service_worker.js"); |
| 622 | 657 |
| 623 bool is_storage_on_disk = GetParam(); | 658 if (is_storage_on_disk()) { |
| 624 if (is_storage_on_disk) { | |
| 625 // Reinitialize the helper to test on-disk storage. | 659 // Reinitialize the helper to test on-disk storage. |
| 626 base::ScopedTempDir user_data_directory; | 660 base::ScopedTempDir user_data_directory; |
| 627 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir()); | 661 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir()); |
| 628 helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.GetPath())); | 662 helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.GetPath())); |
| 629 helper_->context_wrapper()->AddObserver(this); | 663 helper_->context_wrapper()->AddObserver(this); |
| 630 } | 664 } |
| 631 | 665 |
| 632 int64_t registration_id = kInvalidServiceWorkerRegistrationId; | 666 int64_t registration_id = kInvalidServiceWorkerRegistrationId; |
| 633 bool called = false; | 667 bool called = false; |
| 634 context()->RegisterServiceWorker( | 668 context()->RegisterServiceWorker( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 ASSERT_EQ(3u, notifications_.size()); | 736 ASSERT_EQ(3u, notifications_.size()); |
| 703 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 737 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
| 704 EXPECT_EQ(pattern, notifications_[0].pattern); | 738 EXPECT_EQ(pattern, notifications_[0].pattern); |
| 705 EXPECT_EQ(registration_id, notifications_[0].registration_id); | 739 EXPECT_EQ(registration_id, notifications_[0].registration_id); |
| 706 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); | 740 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); |
| 707 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 741 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
| 708 EXPECT_EQ(pattern, notifications_[2].pattern); | 742 EXPECT_EQ(pattern, notifications_[2].pattern); |
| 709 EXPECT_EQ(registration_id, notifications_[2].registration_id); | 743 EXPECT_EQ(registration_id, notifications_[2].registration_id); |
| 710 } | 744 } |
| 711 | 745 |
| 746 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextTest, | |
| 747 ServiceWorkerContextTestP, | |
| 748 testing::Bool()); | |
| 749 | |
| 750 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest, | |
| 751 ServiceWorkerContextRecoveryTest, | |
| 752 testing::Combine(testing::Bool(), testing::Bool())); | |
| 712 | 753 |
| 713 } // namespace content | 754 } // namespace content |
| OLD | NEW |