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 "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 enum NotificationType { | 105 enum NotificationType { |
106 REGISTRATION_STORED, | 106 REGISTRATION_STORED, |
107 REGISTRATION_DELETED, | 107 REGISTRATION_DELETED, |
108 STORAGE_RECOVERED, | 108 STORAGE_RECOVERED, |
109 }; | 109 }; |
110 | 110 |
111 struct NotificationLog { | 111 struct NotificationLog { |
112 NotificationType type; | 112 NotificationType type; |
113 GURL pattern; | 113 GURL pattern; |
| 114 int64 registration_id; |
114 }; | 115 }; |
115 | 116 |
116 } // namespace | 117 } // namespace |
117 | 118 |
118 class ServiceWorkerContextTest : public ServiceWorkerContextObserver, | 119 class ServiceWorkerContextTest : public ServiceWorkerContextObserver, |
119 public testing::Test { | 120 public testing::Test { |
120 public: | 121 public: |
121 ServiceWorkerContextTest() | 122 ServiceWorkerContextTest() |
122 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), | 123 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), |
123 render_process_id_(99) {} | 124 render_process_id_(99) {} |
124 | 125 |
125 void SetUp() override { | 126 void SetUp() override { |
126 helper_.reset(new EmbeddedWorkerTestHelper(render_process_id_)); | 127 helper_.reset(new EmbeddedWorkerTestHelper(render_process_id_)); |
127 helper_->context_wrapper()->AddObserver(this); | 128 helper_->context_wrapper()->AddObserver(this); |
128 } | 129 } |
129 | 130 |
130 void TearDown() override { helper_.reset(); } | 131 void TearDown() override { helper_.reset(); } |
131 | 132 |
132 // ServiceWorkerContextObserver overrides. | 133 // ServiceWorkerContextObserver overrides. |
133 void OnRegistrationStored(const GURL& pattern) override { | 134 void OnRegistrationStored(const GURL& pattern) override { |
134 NotificationLog log; | 135 NotificationLog log; |
135 log.type = REGISTRATION_STORED; | 136 log.type = REGISTRATION_STORED; |
136 log.pattern = pattern; | 137 log.pattern = pattern; |
137 notifications_.push_back(log); | 138 notifications_.push_back(log); |
138 } | 139 } |
139 void OnRegistrationDeleted(const GURL& pattern) override { | 140 void OnRegistrationDeleted(int64 registration_id, |
| 141 const GURL& pattern) override { |
140 NotificationLog log; | 142 NotificationLog log; |
141 log.type = REGISTRATION_DELETED; | 143 log.type = REGISTRATION_DELETED; |
142 log.pattern = pattern; | 144 log.pattern = pattern; |
| 145 log.registration_id = registration_id; |
143 notifications_.push_back(log); | 146 notifications_.push_back(log); |
144 } | 147 } |
145 void OnStorageWiped() override { | 148 void OnStorageWiped() override { |
146 NotificationLog log; | 149 NotificationLog log; |
147 log.type = STORAGE_RECOVERED; | 150 log.type = STORAGE_RECOVERED; |
148 notifications_.push_back(log); | 151 notifications_.push_back(log); |
149 } | 152 } |
150 | 153 |
151 ServiceWorkerContextCore* context() { return helper_->context(); } | 154 ServiceWorkerContextCore* context() { return helper_->context(); } |
152 | 155 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 SERVICE_WORKER_ERROR_NOT_FOUND, | 319 SERVICE_WORKER_ERROR_NOT_FOUND, |
317 false /* expect_waiting */, | 320 false /* expect_waiting */, |
318 false /* expect_active */)); | 321 false /* expect_active */)); |
319 base::RunLoop().RunUntilIdle(); | 322 base::RunLoop().RunUntilIdle(); |
320 | 323 |
321 ASSERT_EQ(2u, notifications_.size()); | 324 ASSERT_EQ(2u, notifications_.size()); |
322 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 325 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
323 EXPECT_EQ(pattern, notifications_[0].pattern); | 326 EXPECT_EQ(pattern, notifications_[0].pattern); |
324 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); | 327 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); |
325 EXPECT_EQ(pattern, notifications_[1].pattern); | 328 EXPECT_EQ(pattern, notifications_[1].pattern); |
| 329 EXPECT_EQ(registration_id, notifications_[1].registration_id); |
326 } | 330 } |
327 | 331 |
328 // Make sure registrations are cleaned up when they are unregistered in bulk. | 332 // Make sure registrations are cleaned up when they are unregistered in bulk. |
329 TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { | 333 TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { |
330 GURL origin1_p1("http://www.example.com/test"); | 334 GURL origin1_p1("http://www.example.com/test"); |
331 GURL origin1_p2("http://www.example.com/hello"); | 335 GURL origin1_p2("http://www.example.com/hello"); |
332 GURL origin2_p1("http://www.example.com:8080/again"); | 336 GURL origin2_p1("http://www.example.com:8080/again"); |
333 GURL origin3_p1("http://www.other.com/"); | 337 GURL origin3_p1("http://www.other.com/"); |
334 | 338 |
335 bool called = false; | 339 bool called = false; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 415 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
412 EXPECT_EQ(origin1_p1, notifications_[0].pattern); | 416 EXPECT_EQ(origin1_p1, notifications_[0].pattern); |
413 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); | 417 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); |
414 EXPECT_EQ(origin1_p2, notifications_[1].pattern); | 418 EXPECT_EQ(origin1_p2, notifications_[1].pattern); |
415 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 419 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
416 EXPECT_EQ(origin2_p1, notifications_[2].pattern); | 420 EXPECT_EQ(origin2_p1, notifications_[2].pattern); |
417 EXPECT_EQ(REGISTRATION_STORED, notifications_[3].type); | 421 EXPECT_EQ(REGISTRATION_STORED, notifications_[3].type); |
418 EXPECT_EQ(origin3_p1, notifications_[3].pattern); | 422 EXPECT_EQ(origin3_p1, notifications_[3].pattern); |
419 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); | 423 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); |
420 EXPECT_EQ(origin1_p2, notifications_[4].pattern); | 424 EXPECT_EQ(origin1_p2, notifications_[4].pattern); |
| 425 EXPECT_EQ(registration_id2, notifications_[4].registration_id); |
421 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); | 426 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); |
422 EXPECT_EQ(origin1_p1, notifications_[5].pattern); | 427 EXPECT_EQ(origin1_p1, notifications_[5].pattern); |
| 428 EXPECT_EQ(registration_id1, notifications_[5].registration_id); |
423 } | 429 } |
424 | 430 |
425 // Make sure registering a new script shares an existing registration. | 431 // Make sure registering a new script shares an existing registration. |
426 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { | 432 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { |
427 GURL pattern("http://www.example.com/"); | 433 GURL pattern("http://www.example.com/"); |
428 | 434 |
429 bool called = false; | 435 bool called = false; |
430 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; | 436 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; |
431 context()->RegisterServiceWorker( | 437 context()->RegisterServiceWorker( |
432 pattern, | 438 pattern, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 586 |
581 ASSERT_EQ(3u, notifications_.size()); | 587 ASSERT_EQ(3u, notifications_.size()); |
582 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); | 588 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); |
583 EXPECT_EQ(pattern, notifications_[0].pattern); | 589 EXPECT_EQ(pattern, notifications_[0].pattern); |
584 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); | 590 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); |
585 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); | 591 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); |
586 EXPECT_EQ(pattern, notifications_[2].pattern); | 592 EXPECT_EQ(pattern, notifications_[2].pattern); |
587 } | 593 } |
588 | 594 |
589 } // namespace content | 595 } // namespace content |
OLD | NEW |