Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: content/browser/service_worker/service_worker_context_unittest.cc

Issue 2432083002: Mojofy unittests: ServiceWorkerContextTest (Closed)
Patch Set: Check if StopWorker/StartWorker is called Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 RecordableEmbeddedWorkerInstanceClient(
horo 2016/10/20 07:33:00 nit: explicit
shimazu 2016/10/20 08:45:55 Done.
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 private:
197 std::vector<Message> events_;
horo 2016/10/20 07:33:00 nit: DISALLOW_COPY_AND_ASSIGN(RecordableEmbedded
shimazu 2016/10/20 08:45:55 Done.
198 };
199
164 // Make sure basic registration is working. 200 // Make sure basic registration is working.
165 TEST_F(ServiceWorkerContextTest, Register) { 201 TEST_P(ServiceWorkerContextTestP, Register) {
166 GURL pattern("http://www.example.com/"); 202 GURL pattern("http://www.example.com/");
167 GURL script_url("http://www.example.com/service_worker.js"); 203 GURL script_url("http://www.example.com/service_worker.js");
168 204
205 RecordableEmbeddedWorkerInstanceClient* client = nullptr;
206 if (is_mojo_enabled()) {
207 client = helper_->CreateAndRegisterMockInstanceClient<
208 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr());
209 }
210
169 int64_t registration_id = kInvalidServiceWorkerRegistrationId; 211 int64_t registration_id = kInvalidServiceWorkerRegistrationId;
170 bool called = false; 212 bool called = false;
171 context()->RegisterServiceWorker( 213 context()->RegisterServiceWorker(
172 pattern, 214 pattern,
173 script_url, 215 script_url,
174 NULL, 216 NULL,
175 MakeRegisteredCallback(&called, &registration_id)); 217 MakeRegisteredCallback(&called, &registration_id));
176 218
177 ASSERT_FALSE(called); 219 ASSERT_FALSE(called);
178 base::RunLoop().RunUntilIdle(); 220 base::RunLoop().RunUntilIdle();
179 EXPECT_TRUE(called); 221 EXPECT_TRUE(called);
180 222
181 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); 223 if (is_mojo_enabled()) {
182 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 224 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count());
183 EmbeddedWorkerMsg_StartWorker::ID)); 225 ASSERT_EQ(2UL, client->events().size());
184 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 226 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker,
185 ServiceWorkerMsg_InstallEvent::ID)); 227 client->events()[0]);
186 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 228 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
187 ServiceWorkerMsg_ActivateEvent::ID)); 229 ServiceWorkerMsg_InstallEvent::ID));
188 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 230 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
189 EmbeddedWorkerMsg_StopWorker::ID)); 231 ServiceWorkerMsg_ActivateEvent::ID));
232 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker,
233 client->events()[1]);
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 }
190 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 245 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
191 246
192 ASSERT_EQ(1u, notifications_.size()); 247 ASSERT_EQ(1u, notifications_.size());
193 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 248 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
194 EXPECT_EQ(pattern, notifications_[0].pattern); 249 EXPECT_EQ(pattern, notifications_[0].pattern);
195 EXPECT_EQ(registration_id, notifications_[0].registration_id); 250 EXPECT_EQ(registration_id, notifications_[0].registration_id);
196 251
197 context()->storage()->FindRegistrationForId( 252 context()->storage()->FindRegistrationForId(
198 registration_id, 253 registration_id,
199 pattern.GetOrigin(), 254 pattern.GetOrigin(),
200 base::Bind(&ExpectRegisteredWorkers, 255 base::Bind(&ExpectRegisteredWorkers,
201 SERVICE_WORKER_OK, 256 SERVICE_WORKER_OK,
202 false /* expect_waiting */, 257 false /* expect_waiting */,
203 true /* expect_active */)); 258 true /* expect_active */));
204 base::RunLoop().RunUntilIdle(); 259 base::RunLoop().RunUntilIdle();
205 } 260 }
206 261
207 // Test registration when the service worker rejects the install event. The 262 // Test registration when the service worker rejects the install event. The
208 // registration callback should indicate success, but there should be no waiting 263 // registration callback should indicate success, but there should be no waiting
209 // or active worker in the registration. 264 // or active worker in the registration.
210 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { 265 TEST_P(ServiceWorkerContextTestP, Register_RejectInstall) {
211 GURL pattern("http://www.example.com/"); 266 GURL pattern("http://www.example.com/");
212 GURL script_url("http://www.example.com/service_worker.js"); 267 GURL script_url("http://www.example.com/service_worker.js");
213 268
214 helper_.reset(); // Make sure the process lookups stay overridden. 269 helper_.reset(); // Make sure the process lookups stay overridden.
215 helper_.reset(new RejectInstallTestHelper); 270 helper_.reset(new RejectInstallTestHelper);
216 helper_->context_wrapper()->AddObserver(this); 271 helper_->context_wrapper()->AddObserver(this);
272
273 RecordableEmbeddedWorkerInstanceClient* client = nullptr;
274 if (is_mojo_enabled()) {
275 client = helper_->CreateAndRegisterMockInstanceClient<
276 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr());
277 }
278
217 int64_t registration_id = kInvalidServiceWorkerRegistrationId; 279 int64_t registration_id = kInvalidServiceWorkerRegistrationId;
218 bool called = false; 280 bool called = false;
219 context()->RegisterServiceWorker( 281 context()->RegisterServiceWorker(
220 pattern, 282 pattern,
221 script_url, 283 script_url,
222 NULL, 284 NULL,
223 MakeRegisteredCallback(&called, &registration_id)); 285 MakeRegisteredCallback(&called, &registration_id));
224 286
225 ASSERT_FALSE(called); 287 ASSERT_FALSE(called);
226 base::RunLoop().RunUntilIdle(); 288 base::RunLoop().RunUntilIdle();
227 EXPECT_TRUE(called); 289 EXPECT_TRUE(called);
228 290
229 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); 291 if (is_mojo_enabled()) {
230 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 292 EXPECT_EQ(1UL, helper_->ipc_sink()->message_count());
231 EmbeddedWorkerMsg_StartWorker::ID)); 293 ASSERT_EQ(2UL, client->events().size());
232 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 294 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker,
233 ServiceWorkerMsg_InstallEvent::ID)); 295 client->events()[0]);
234 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 296 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
235 ServiceWorkerMsg_ActivateEvent::ID)); 297 ServiceWorkerMsg_InstallEvent::ID));
236 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 298 EXPECT_FALSE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
237 EmbeddedWorkerMsg_StopWorker::ID)); 299 ServiceWorkerMsg_ActivateEvent::ID));
300 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker,
301 client->events()[1]);
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 }
238 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 313 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
239 314
240 ASSERT_EQ(1u, notifications_.size()); 315 ASSERT_EQ(1u, notifications_.size());
241 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 316 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
242 EXPECT_EQ(pattern, notifications_[0].pattern); 317 EXPECT_EQ(pattern, notifications_[0].pattern);
243 EXPECT_EQ(registration_id, notifications_[0].registration_id); 318 EXPECT_EQ(registration_id, notifications_[0].registration_id);
244 319
245 context()->storage()->FindRegistrationForId( 320 context()->storage()->FindRegistrationForId(
246 registration_id, 321 registration_id,
247 pattern.GetOrigin(), 322 pattern.GetOrigin(),
248 base::Bind(&ExpectRegisteredWorkers, 323 base::Bind(&ExpectRegisteredWorkers,
249 SERVICE_WORKER_ERROR_NOT_FOUND, 324 SERVICE_WORKER_ERROR_NOT_FOUND,
250 false /* expect_waiting */, 325 false /* expect_waiting */,
251 false /* expect_active */)); 326 false /* expect_active */));
252 base::RunLoop().RunUntilIdle(); 327 base::RunLoop().RunUntilIdle();
253 } 328 }
254 329
255 // Test registration when the service worker rejects the activate event. The 330 // Test registration when the service worker rejects the activate event. The
256 // worker should be activated anyway. 331 // worker should be activated anyway.
257 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { 332 TEST_P(ServiceWorkerContextTestP, Register_RejectActivate) {
258 GURL pattern("http://www.example.com/"); 333 GURL pattern("http://www.example.com/");
259 GURL script_url("http://www.example.com/service_worker.js"); 334 GURL script_url("http://www.example.com/service_worker.js");
260 335
261 helper_.reset(); 336 helper_.reset();
262 helper_.reset(new RejectActivateTestHelper); 337 helper_.reset(new RejectActivateTestHelper);
263 helper_->context_wrapper()->AddObserver(this); 338 helper_->context_wrapper()->AddObserver(this);
339
340 RecordableEmbeddedWorkerInstanceClient* client = nullptr;
341 if (is_mojo_enabled()) {
342 client = helper_->CreateAndRegisterMockInstanceClient<
343 RecordableEmbeddedWorkerInstanceClient>(helper_->AsWeakPtr());
344 }
345
264 int64_t registration_id = kInvalidServiceWorkerRegistrationId; 346 int64_t registration_id = kInvalidServiceWorkerRegistrationId;
265 bool called = false; 347 bool called = false;
266 context()->RegisterServiceWorker( 348 context()->RegisterServiceWorker(
267 pattern, script_url, NULL, 349 pattern, script_url, NULL,
268 MakeRegisteredCallback(&called, &registration_id)); 350 MakeRegisteredCallback(&called, &registration_id));
269 351
270 ASSERT_FALSE(called); 352 ASSERT_FALSE(called);
271 base::RunLoop().RunUntilIdle(); 353 base::RunLoop().RunUntilIdle();
272 EXPECT_TRUE(called); 354 EXPECT_TRUE(called);
273 355
274 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); 356 if (is_mojo_enabled()) {
275 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 357 EXPECT_EQ(2UL, helper_->ipc_sink()->message_count());
276 EmbeddedWorkerMsg_StartWorker::ID)); 358 ASSERT_EQ(2UL, client->events().size());
277 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 359 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StartWorker,
278 ServiceWorkerMsg_InstallEvent::ID)); 360 client->events()[0]);
279 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching( 361 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
280 ServiceWorkerMsg_ActivateEvent::ID)); 362 ServiceWorkerMsg_InstallEvent::ID));
281 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 363 EXPECT_TRUE(helper_->inner_ipc_sink()->GetUniqueMessageMatching(
282 EmbeddedWorkerMsg_StopWorker::ID)); 364 ServiceWorkerMsg_ActivateEvent::ID));
365 EXPECT_EQ(RecordableEmbeddedWorkerInstanceClient::Message::StopWorker,
366 client->events()[1]);
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 }
283 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 378 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
284 379
285 ASSERT_EQ(1u, notifications_.size()); 380 ASSERT_EQ(1u, notifications_.size());
286 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 381 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
287 EXPECT_EQ(pattern, notifications_[0].pattern); 382 EXPECT_EQ(pattern, notifications_[0].pattern);
288 EXPECT_EQ(registration_id, notifications_[0].registration_id); 383 EXPECT_EQ(registration_id, notifications_[0].registration_id);
289 384
290 context()->storage()->FindRegistrationForId( 385 context()->storage()->FindRegistrationForId(
291 registration_id, pattern.GetOrigin(), 386 registration_id, pattern.GetOrigin(),
292 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK, 387 base::Bind(&ExpectRegisteredWorkers, SERVICE_WORKER_OK,
293 false /* expect_waiting */, true /* expect_active */)); 388 false /* expect_waiting */, true /* expect_active */));
294 base::RunLoop().RunUntilIdle(); 389 base::RunLoop().RunUntilIdle();
295 } 390 }
296 391
297 // Make sure registrations are cleaned up when they are unregistered. 392 // Make sure registrations are cleaned up when they are unregistered.
298 TEST_F(ServiceWorkerContextTest, Unregister) { 393 TEST_P(ServiceWorkerContextTestP, Unregister) {
299 GURL pattern("http://www.example.com/"); 394 GURL pattern("http://www.example.com/");
300 395
301 bool called = false; 396 bool called = false;
302 int64_t registration_id = kInvalidServiceWorkerRegistrationId; 397 int64_t registration_id = kInvalidServiceWorkerRegistrationId;
303 context()->RegisterServiceWorker( 398 context()->RegisterServiceWorker(
304 pattern, 399 pattern,
305 GURL("http://www.example.com/service_worker.js"), 400 GURL("http://www.example.com/service_worker.js"),
306 NULL, 401 NULL,
307 MakeRegisteredCallback(&called, &registration_id)); 402 MakeRegisteredCallback(&called, &registration_id));
308 403
(...skipping 22 matching lines...) Expand all
331 ASSERT_EQ(2u, notifications_.size()); 426 ASSERT_EQ(2u, notifications_.size());
332 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 427 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
333 EXPECT_EQ(pattern, notifications_[0].pattern); 428 EXPECT_EQ(pattern, notifications_[0].pattern);
334 EXPECT_EQ(registration_id, notifications_[0].registration_id); 429 EXPECT_EQ(registration_id, notifications_[0].registration_id);
335 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type); 430 EXPECT_EQ(REGISTRATION_DELETED, notifications_[1].type);
336 EXPECT_EQ(pattern, notifications_[1].pattern); 431 EXPECT_EQ(pattern, notifications_[1].pattern);
337 EXPECT_EQ(registration_id, notifications_[1].registration_id); 432 EXPECT_EQ(registration_id, notifications_[1].registration_id);
338 } 433 }
339 434
340 // Make sure registrations are cleaned up when they are unregistered in bulk. 435 // Make sure registrations are cleaned up when they are unregistered in bulk.
341 TEST_F(ServiceWorkerContextTest, UnregisterMultiple) { 436 TEST_P(ServiceWorkerContextTestP, UnregisterMultiple) {
342 GURL origin1_p1("http://www.example.com/test"); 437 GURL origin1_p1("http://www.example.com/test");
343 GURL origin1_p2("http://www.example.com/hello"); 438 GURL origin1_p2("http://www.example.com/hello");
344 GURL origin2_p1("http://www.example.com:8080/again"); 439 GURL origin2_p1("http://www.example.com:8080/again");
345 GURL origin3_p1("http://www.other.com/"); 440 GURL origin3_p1("http://www.other.com/");
346 441
347 bool called = false; 442 bool called = false;
348 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId; 443 int64_t registration_id1 = kInvalidServiceWorkerRegistrationId;
349 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId; 444 int64_t registration_id2 = kInvalidServiceWorkerRegistrationId;
350 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId; 445 int64_t registration_id3 = kInvalidServiceWorkerRegistrationId;
351 int64_t registration_id4 = kInvalidServiceWorkerRegistrationId; 446 int64_t registration_id4 = kInvalidServiceWorkerRegistrationId;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 EXPECT_EQ(registration_id4, notifications_[3].registration_id); 529 EXPECT_EQ(registration_id4, notifications_[3].registration_id);
435 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type); 530 EXPECT_EQ(REGISTRATION_DELETED, notifications_[4].type);
436 EXPECT_EQ(origin1_p2, notifications_[4].pattern); 531 EXPECT_EQ(origin1_p2, notifications_[4].pattern);
437 EXPECT_EQ(registration_id2, notifications_[4].registration_id); 532 EXPECT_EQ(registration_id2, notifications_[4].registration_id);
438 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type); 533 EXPECT_EQ(REGISTRATION_DELETED, notifications_[5].type);
439 EXPECT_EQ(origin1_p1, notifications_[5].pattern); 534 EXPECT_EQ(origin1_p1, notifications_[5].pattern);
440 EXPECT_EQ(registration_id1, notifications_[5].registration_id); 535 EXPECT_EQ(registration_id1, notifications_[5].registration_id);
441 } 536 }
442 537
443 // Make sure registering a new script shares an existing registration. 538 // Make sure registering a new script shares an existing registration.
444 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { 539 TEST_P(ServiceWorkerContextTestP, RegisterNewScript) {
445 GURL pattern("http://www.example.com/"); 540 GURL pattern("http://www.example.com/");
446 541
447 bool called = false; 542 bool called = false;
448 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; 543 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId;
449 context()->RegisterServiceWorker( 544 context()->RegisterServiceWorker(
450 pattern, 545 pattern,
451 GURL("http://www.example.com/service_worker.js"), 546 GURL("http://www.example.com/service_worker.js"),
452 NULL, 547 NULL,
453 MakeRegisteredCallback(&called, &old_registration_id)); 548 MakeRegisteredCallback(&called, &old_registration_id));
454 549
(...skipping 21 matching lines...) Expand all
476 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 571 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
477 EXPECT_EQ(pattern, notifications_[0].pattern); 572 EXPECT_EQ(pattern, notifications_[0].pattern);
478 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); 573 EXPECT_EQ(old_registration_id, notifications_[0].registration_id);
479 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); 574 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type);
480 EXPECT_EQ(pattern, notifications_[1].pattern); 575 EXPECT_EQ(pattern, notifications_[1].pattern);
481 EXPECT_EQ(new_registration_id, notifications_[1].registration_id); 576 EXPECT_EQ(new_registration_id, notifications_[1].registration_id);
482 } 577 }
483 578
484 // Make sure that when registering a duplicate pattern+script_url 579 // Make sure that when registering a duplicate pattern+script_url
485 // combination, that the same registration is used. 580 // combination, that the same registration is used.
486 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { 581 TEST_P(ServiceWorkerContextTestP, RegisterDuplicateScript) {
487 GURL pattern("http://www.example.com/"); 582 GURL pattern("http://www.example.com/");
488 GURL script_url("http://www.example.com/service_worker.js"); 583 GURL script_url("http://www.example.com/service_worker.js");
489 584
490 bool called = false; 585 bool called = false;
491 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId; 586 int64_t old_registration_id = kInvalidServiceWorkerRegistrationId;
492 context()->RegisterServiceWorker( 587 context()->RegisterServiceWorker(
493 pattern, 588 pattern,
494 script_url, 589 script_url,
495 NULL, 590 NULL,
496 MakeRegisteredCallback(&called, &old_registration_id)); 591 MakeRegisteredCallback(&called, &old_registration_id));
(...skipping 18 matching lines...) Expand all
515 610
516 ASSERT_EQ(2u, notifications_.size()); 611 ASSERT_EQ(2u, notifications_.size());
517 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 612 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
518 EXPECT_EQ(pattern, notifications_[0].pattern); 613 EXPECT_EQ(pattern, notifications_[0].pattern);
519 EXPECT_EQ(old_registration_id, notifications_[0].registration_id); 614 EXPECT_EQ(old_registration_id, notifications_[0].registration_id);
520 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type); 615 EXPECT_EQ(REGISTRATION_STORED, notifications_[1].type);
521 EXPECT_EQ(pattern, notifications_[1].pattern); 616 EXPECT_EQ(pattern, notifications_[1].pattern);
522 EXPECT_EQ(old_registration_id, notifications_[1].registration_id); 617 EXPECT_EQ(old_registration_id, notifications_[1].registration_id);
523 } 618 }
524 619
525 TEST_F(ServiceWorkerContextTest, ProviderHostIterator) { 620 TEST_P(ServiceWorkerContextTestP, ProviderHostIterator) {
526 const int kRenderProcessId1 = 1; 621 const int kRenderProcessId1 = 1;
527 const int kRenderProcessId2 = 2; 622 const int kRenderProcessId2 = 2;
528 const GURL kOrigin1 = GURL("http://www.example.com/"); 623 const GURL kOrigin1 = GURL("http://www.example.com/");
529 const GURL kOrigin2 = GURL("https://www.example.com/"); 624 const GURL kOrigin2 = GURL("https://www.example.com/");
530 int provider_id = 1; 625 int provider_id = 1;
531 626
532 // Host1 (provider_id=1): process_id=1, origin1. 627 // Host1 (provider_id=1): process_id=1, origin1.
533 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost( 628 ServiceWorkerProviderHost* host1(new ServiceWorkerProviderHost(
534 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++, 629 kRenderProcessId1, MSG_ROUTING_NONE, provider_id++,
535 SERVICE_WORKER_PROVIDER_FOR_WINDOW, 630 SERVICE_WORKER_PROVIDER_FOR_WINDOW,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 EXPECT_TRUE(ContainsKey(results, host2)); 694 EXPECT_TRUE(ContainsKey(results, host2));
600 695
601 context()->RemoveProviderHost(kRenderProcessId1, 1); 696 context()->RemoveProviderHost(kRenderProcessId1, 1);
602 context()->RemoveProviderHost(kRenderProcessId2, 2); 697 context()->RemoveProviderHost(kRenderProcessId2, 2);
603 context()->RemoveProviderHost(kRenderProcessId2, 3); 698 context()->RemoveProviderHost(kRenderProcessId2, 3);
604 context()->RemoveProviderHost(kRenderProcessId2, 4); 699 context()->RemoveProviderHost(kRenderProcessId2, 4);
605 } 700 }
606 701
607 class ServiceWorkerContextRecoveryTest 702 class ServiceWorkerContextRecoveryTest
608 : public ServiceWorkerContextTest, 703 : public ServiceWorkerContextTest,
609 public testing::WithParamInterface<bool> { 704 public testing::WithParamInterface<testing::tuple<bool, bool>> {
610 public: 705 public:
611 ServiceWorkerContextRecoveryTest() {} 706 ServiceWorkerContextRecoveryTest() {}
612 virtual ~ServiceWorkerContextRecoveryTest() {} 707 virtual ~ServiceWorkerContextRecoveryTest() {}
708
709 protected:
710 void SetUp() override {
711 if (is_mojo_enabled()) {
712 base::CommandLine::ForCurrentProcess()->AppendSwitch(
713 switches::kMojoServiceWorker);
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()); }
613 }; 720 };
614 721
615 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest,
616 ServiceWorkerContextRecoveryTest,
617 testing::Values(true, false));
618
619 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) { 722 TEST_P(ServiceWorkerContextRecoveryTest, DeleteAndStartOver) {
620 GURL pattern("http://www.example.com/"); 723 GURL pattern("http://www.example.com/");
621 GURL script_url("http://www.example.com/service_worker.js"); 724 GURL script_url("http://www.example.com/service_worker.js");
622 725
623 bool is_storage_on_disk = GetParam(); 726 if (is_storage_on_disk()) {
624 if (is_storage_on_disk) {
625 // Reinitialize the helper to test on-disk storage. 727 // Reinitialize the helper to test on-disk storage.
626 base::ScopedTempDir user_data_directory; 728 base::ScopedTempDir user_data_directory;
627 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir()); 729 ASSERT_TRUE(user_data_directory.CreateUniqueTempDir());
628 helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.GetPath())); 730 helper_.reset(new EmbeddedWorkerTestHelper(user_data_directory.GetPath()));
629 helper_->context_wrapper()->AddObserver(this); 731 helper_->context_wrapper()->AddObserver(this);
630 } 732 }
631 733
632 int64_t registration_id = kInvalidServiceWorkerRegistrationId; 734 int64_t registration_id = kInvalidServiceWorkerRegistrationId;
633 bool called = false; 735 bool called = false;
634 context()->RegisterServiceWorker( 736 context()->RegisterServiceWorker(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 ASSERT_EQ(3u, notifications_.size()); 804 ASSERT_EQ(3u, notifications_.size());
703 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type); 805 EXPECT_EQ(REGISTRATION_STORED, notifications_[0].type);
704 EXPECT_EQ(pattern, notifications_[0].pattern); 806 EXPECT_EQ(pattern, notifications_[0].pattern);
705 EXPECT_EQ(registration_id, notifications_[0].registration_id); 807 EXPECT_EQ(registration_id, notifications_[0].registration_id);
706 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type); 808 EXPECT_EQ(STORAGE_RECOVERED, notifications_[1].type);
707 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type); 809 EXPECT_EQ(REGISTRATION_STORED, notifications_[2].type);
708 EXPECT_EQ(pattern, notifications_[2].pattern); 810 EXPECT_EQ(pattern, notifications_[2].pattern);
709 EXPECT_EQ(registration_id, notifications_[2].registration_id); 811 EXPECT_EQ(registration_id, notifications_[2].registration_id);
710 } 812 }
711 813
814 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextTest,
815 ServiceWorkerContextTestP,
816 testing::Bool());
817
818 INSTANTIATE_TEST_CASE_P(ServiceWorkerContextRecoveryTest,
819 ServiceWorkerContextRecoveryTest,
820 testing::Combine(testing::Bool(), testing::Bool()));
712 821
713 } // namespace content 822 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698