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

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

Issue 443593002: ServiceWorker: Move worker candidate process knowledge to ServiceWorkerProcessManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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 "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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 }; 137 };
138 138
139 // Make sure basic registration is working. 139 // Make sure basic registration is working.
140 TEST_F(ServiceWorkerContextTest, Register) { 140 TEST_F(ServiceWorkerContextTest, Register) {
141 int64 registration_id = kInvalidServiceWorkerRegistrationId; 141 int64 registration_id = kInvalidServiceWorkerRegistrationId;
142 int64 version_id = kInvalidServiceWorkerVersionId; 142 int64 version_id = kInvalidServiceWorkerVersionId;
143 bool called = false; 143 bool called = false;
144 context()->RegisterServiceWorker( 144 context()->RegisterServiceWorker(
145 GURL("http://www.example.com/"), 145 GURL("http://www.example.com/"),
146 GURL("http://www.example.com/service_worker.js"), 146 GURL("http://www.example.com/service_worker.js"),
147 render_process_id_,
148 NULL, 147 NULL,
149 MakeRegisteredCallback(&called, &registration_id, &version_id)); 148 MakeRegisteredCallback(&called, &registration_id, &version_id));
150 149
151 ASSERT_FALSE(called); 150 ASSERT_FALSE(called);
152 base::RunLoop().RunUntilIdle(); 151 base::RunLoop().RunUntilIdle();
153 EXPECT_TRUE(called); 152 EXPECT_TRUE(called);
154 153
155 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); 154 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
156 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 155 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
157 EmbeddedWorkerMsg_StartWorker::ID)); 156 EmbeddedWorkerMsg_StartWorker::ID));
(...skipping 22 matching lines...) Expand all
180 // or active worker in the registration. 179 // or active worker in the registration.
181 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) { 180 TEST_F(ServiceWorkerContextTest, Register_RejectInstall) {
182 helper_.reset(); // Make sure the process lookups stay overridden. 181 helper_.reset(); // Make sure the process lookups stay overridden.
183 helper_.reset(new RejectInstallTestHelper(render_process_id_)); 182 helper_.reset(new RejectInstallTestHelper(render_process_id_));
184 int64 registration_id = kInvalidServiceWorkerRegistrationId; 183 int64 registration_id = kInvalidServiceWorkerRegistrationId;
185 int64 version_id = kInvalidServiceWorkerVersionId; 184 int64 version_id = kInvalidServiceWorkerVersionId;
186 bool called = false; 185 bool called = false;
187 context()->RegisterServiceWorker( 186 context()->RegisterServiceWorker(
188 GURL("http://www.example.com/"), 187 GURL("http://www.example.com/"),
189 GURL("http://www.example.com/service_worker.js"), 188 GURL("http://www.example.com/service_worker.js"),
190 render_process_id_,
191 NULL, 189 NULL,
192 MakeRegisteredCallback(&called, &registration_id, &version_id)); 190 MakeRegisteredCallback(&called, &registration_id, &version_id));
193 191
194 ASSERT_FALSE(called); 192 ASSERT_FALSE(called);
195 base::RunLoop().RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
196 EXPECT_TRUE(called); 194 EXPECT_TRUE(called);
197 195
198 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count()); 196 EXPECT_EQ(3UL, helper_->ipc_sink()->message_count());
199 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 197 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
200 EmbeddedWorkerMsg_StartWorker::ID)); 198 EmbeddedWorkerMsg_StartWorker::ID));
(...skipping 22 matching lines...) Expand all
223 // or active worker in the registration. 221 // or active worker in the registration.
224 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) { 222 TEST_F(ServiceWorkerContextTest, Register_RejectActivate) {
225 helper_.reset(); // Make sure the process lookups stay overridden. 223 helper_.reset(); // Make sure the process lookups stay overridden.
226 helper_.reset(new RejectActivateTestHelper(render_process_id_)); 224 helper_.reset(new RejectActivateTestHelper(render_process_id_));
227 int64 registration_id = kInvalidServiceWorkerRegistrationId; 225 int64 registration_id = kInvalidServiceWorkerRegistrationId;
228 int64 version_id = kInvalidServiceWorkerVersionId; 226 int64 version_id = kInvalidServiceWorkerVersionId;
229 bool called = false; 227 bool called = false;
230 context()->RegisterServiceWorker( 228 context()->RegisterServiceWorker(
231 GURL("http://www.example.com/"), 229 GURL("http://www.example.com/"),
232 GURL("http://www.example.com/service_worker.js"), 230 GURL("http://www.example.com/service_worker.js"),
233 render_process_id_,
234 NULL, 231 NULL,
235 MakeRegisteredCallback(&called, &registration_id, &version_id)); 232 MakeRegisteredCallback(&called, &registration_id, &version_id));
236 233
237 ASSERT_FALSE(called); 234 ASSERT_FALSE(called);
238 base::RunLoop().RunUntilIdle(); 235 base::RunLoop().RunUntilIdle();
239 EXPECT_TRUE(called); 236 EXPECT_TRUE(called);
240 237
241 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count()); 238 EXPECT_EQ(4UL, helper_->ipc_sink()->message_count());
242 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching( 239 EXPECT_TRUE(helper_->ipc_sink()->GetUniqueMessageMatching(
243 EmbeddedWorkerMsg_StartWorker::ID)); 240 EmbeddedWorkerMsg_StartWorker::ID));
(...skipping 20 matching lines...) Expand all
264 // Make sure registrations are cleaned up when they are unregistered. 261 // Make sure registrations are cleaned up when they are unregistered.
265 TEST_F(ServiceWorkerContextTest, Unregister) { 262 TEST_F(ServiceWorkerContextTest, Unregister) {
266 GURL pattern("http://www.example.com/"); 263 GURL pattern("http://www.example.com/");
267 264
268 bool called = false; 265 bool called = false;
269 int64 registration_id = kInvalidServiceWorkerRegistrationId; 266 int64 registration_id = kInvalidServiceWorkerRegistrationId;
270 int64 version_id = kInvalidServiceWorkerVersionId; 267 int64 version_id = kInvalidServiceWorkerVersionId;
271 context()->RegisterServiceWorker( 268 context()->RegisterServiceWorker(
272 pattern, 269 pattern,
273 GURL("http://www.example.com/service_worker.js"), 270 GURL("http://www.example.com/service_worker.js"),
274 render_process_id_,
275 NULL, 271 NULL,
276 MakeRegisteredCallback(&called, &registration_id, &version_id)); 272 MakeRegisteredCallback(&called, &registration_id, &version_id));
277 273
278 ASSERT_FALSE(called); 274 ASSERT_FALSE(called);
279 base::RunLoop().RunUntilIdle(); 275 base::RunLoop().RunUntilIdle();
280 ASSERT_TRUE(called); 276 ASSERT_TRUE(called);
281 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id); 277 EXPECT_NE(kInvalidServiceWorkerRegistrationId, registration_id);
282 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id); 278 EXPECT_NE(kInvalidServiceWorkerVersionId, version_id);
283 279
284 called = false; 280 called = false;
(...skipping 19 matching lines...) Expand all
304 // existing registration. 300 // existing registration.
305 TEST_F(ServiceWorkerContextTest, RegisterNewScript) { 301 TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
306 GURL pattern("http://www.example.com/"); 302 GURL pattern("http://www.example.com/");
307 303
308 bool called = false; 304 bool called = false;
309 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; 305 int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
310 int64 old_version_id = kInvalidServiceWorkerVersionId; 306 int64 old_version_id = kInvalidServiceWorkerVersionId;
311 context()->RegisterServiceWorker( 307 context()->RegisterServiceWorker(
312 pattern, 308 pattern,
313 GURL("http://www.example.com/service_worker.js"), 309 GURL("http://www.example.com/service_worker.js"),
314 render_process_id_,
315 NULL, 310 NULL,
316 MakeRegisteredCallback(&called, &old_registration_id, &old_version_id)); 311 MakeRegisteredCallback(&called, &old_registration_id, &old_version_id));
317 312
318 ASSERT_FALSE(called); 313 ASSERT_FALSE(called);
319 base::RunLoop().RunUntilIdle(); 314 base::RunLoop().RunUntilIdle();
320 ASSERT_TRUE(called); 315 ASSERT_TRUE(called);
321 EXPECT_NE(kInvalidServiceWorkerRegistrationId, old_registration_id); 316 EXPECT_NE(kInvalidServiceWorkerRegistrationId, old_registration_id);
322 EXPECT_NE(kInvalidServiceWorkerVersionId, old_version_id); 317 EXPECT_NE(kInvalidServiceWorkerVersionId, old_version_id);
323 318
324 called = false; 319 called = false;
325 int64 new_registration_id = kInvalidServiceWorkerRegistrationId; 320 int64 new_registration_id = kInvalidServiceWorkerRegistrationId;
326 int64 new_version_id = kInvalidServiceWorkerVersionId; 321 int64 new_version_id = kInvalidServiceWorkerVersionId;
327 context()->RegisterServiceWorker( 322 context()->RegisterServiceWorker(
328 pattern, 323 pattern,
329 GURL("http://www.example.com/service_worker_new.js"), 324 GURL("http://www.example.com/service_worker_new.js"),
330 render_process_id_,
331 NULL, 325 NULL,
332 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id)); 326 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id));
333 327
334 ASSERT_FALSE(called); 328 ASSERT_FALSE(called);
335 base::RunLoop().RunUntilIdle(); 329 base::RunLoop().RunUntilIdle();
336 ASSERT_TRUE(called); 330 ASSERT_TRUE(called);
337 331
338 EXPECT_NE(kInvalidServiceWorkerRegistrationId, new_registration_id); 332 EXPECT_NE(kInvalidServiceWorkerRegistrationId, new_registration_id);
339 EXPECT_NE(kInvalidServiceWorkerVersionId, new_version_id); 333 EXPECT_NE(kInvalidServiceWorkerVersionId, new_version_id);
340 EXPECT_EQ(old_registration_id, new_registration_id); 334 EXPECT_EQ(old_registration_id, new_registration_id);
341 EXPECT_NE(old_version_id, new_version_id); 335 EXPECT_NE(old_version_id, new_version_id);
342 } 336 }
343 337
344 // Make sure that when registering a duplicate pattern+script_url 338 // Make sure that when registering a duplicate pattern+script_url
345 // combination, that the same registration is used. 339 // combination, that the same registration is used.
346 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { 340 TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
347 GURL pattern("http://www.example.com/"); 341 GURL pattern("http://www.example.com/");
348 GURL script_url("http://www.example.com/service_worker.js"); 342 GURL script_url("http://www.example.com/service_worker.js");
349 343
350 bool called = false; 344 bool called = false;
351 int64 old_registration_id = kInvalidServiceWorkerRegistrationId; 345 int64 old_registration_id = kInvalidServiceWorkerRegistrationId;
352 int64 old_version_id = kInvalidServiceWorkerVersionId; 346 int64 old_version_id = kInvalidServiceWorkerVersionId;
353 context()->RegisterServiceWorker( 347 context()->RegisterServiceWorker(
354 pattern, 348 pattern,
355 script_url, 349 script_url,
356 render_process_id_,
357 NULL, 350 NULL,
358 MakeRegisteredCallback(&called, &old_registration_id, &old_version_id)); 351 MakeRegisteredCallback(&called, &old_registration_id, &old_version_id));
359 352
360 ASSERT_FALSE(called); 353 ASSERT_FALSE(called);
361 base::RunLoop().RunUntilIdle(); 354 base::RunLoop().RunUntilIdle();
362 ASSERT_TRUE(called); 355 ASSERT_TRUE(called);
363 EXPECT_NE(kInvalidServiceWorkerRegistrationId, old_registration_id); 356 EXPECT_NE(kInvalidServiceWorkerRegistrationId, old_registration_id);
364 EXPECT_NE(kInvalidServiceWorkerVersionId, old_version_id); 357 EXPECT_NE(kInvalidServiceWorkerVersionId, old_version_id);
365 358
366 called = false; 359 called = false;
367 int64 new_registration_id = kInvalidServiceWorkerRegistrationId; 360 int64 new_registration_id = kInvalidServiceWorkerRegistrationId;
368 int64 new_version_id = kInvalidServiceWorkerVersionId; 361 int64 new_version_id = kInvalidServiceWorkerVersionId;
369 context()->RegisterServiceWorker( 362 context()->RegisterServiceWorker(
370 pattern, 363 pattern,
371 script_url, 364 script_url,
372 render_process_id_,
373 NULL, 365 NULL,
374 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id)); 366 MakeRegisteredCallback(&called, &new_registration_id, &new_version_id));
375 367
376 ASSERT_FALSE(called); 368 ASSERT_FALSE(called);
377 base::RunLoop().RunUntilIdle(); 369 base::RunLoop().RunUntilIdle();
378 ASSERT_TRUE(called); 370 ASSERT_TRUE(called);
379 EXPECT_EQ(old_registration_id, new_registration_id); 371 EXPECT_EQ(old_registration_id, new_registration_id);
380 EXPECT_EQ(old_version_id, new_version_id); 372 EXPECT_EQ(old_version_id, new_version_id);
381 } 373 }
382 374
383 // TODO(nhiroki): Test this for on-disk storage. 375 // TODO(nhiroki): Test this for on-disk storage.
384 TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) { 376 TEST_F(ServiceWorkerContextTest, DeleteAndStartOver) {
385 int64 registration_id = kInvalidServiceWorkerRegistrationId; 377 int64 registration_id = kInvalidServiceWorkerRegistrationId;
386 int64 version_id = kInvalidServiceWorkerVersionId; 378 int64 version_id = kInvalidServiceWorkerVersionId;
387 bool called = false; 379 bool called = false;
388 context()->RegisterServiceWorker( 380 context()->RegisterServiceWorker(
389 GURL("http://www.example.com/"), 381 GURL("http://www.example.com/"),
390 GURL("http://www.example.com/service_worker.js"), 382 GURL("http://www.example.com/service_worker.js"),
391 render_process_id_,
392 NULL, 383 NULL,
393 MakeRegisteredCallback(&called, &registration_id, &version_id)); 384 MakeRegisteredCallback(&called, &registration_id, &version_id));
394 385
395 ASSERT_FALSE(called); 386 ASSERT_FALSE(called);
396 base::RunLoop().RunUntilIdle(); 387 base::RunLoop().RunUntilIdle();
397 EXPECT_TRUE(called); 388 EXPECT_TRUE(called);
398 389
399 context()->storage()->FindRegistrationForId( 390 context()->storage()->FindRegistrationForId(
400 registration_id, 391 registration_id,
401 GURL("http://www.example.com"), 392 GURL("http://www.example.com"),
(...skipping 27 matching lines...) Expand all
429 SERVICE_WORKER_ERROR_NOT_FOUND, 420 SERVICE_WORKER_ERROR_NOT_FOUND,
430 version_id, 421 version_id,
431 false /* expect_waiting */, 422 false /* expect_waiting */,
432 true /* expect_active */)); 423 true /* expect_active */));
433 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
434 425
435 called = false; 426 called = false;
436 context()->RegisterServiceWorker( 427 context()->RegisterServiceWorker(
437 GURL("http://www.example.com/"), 428 GURL("http://www.example.com/"),
438 GURL("http://www.example.com/service_worker.js"), 429 GURL("http://www.example.com/service_worker.js"),
439 render_process_id_,
440 NULL, 430 NULL,
441 MakeRegisteredCallback(&called, &registration_id, &version_id)); 431 MakeRegisteredCallback(&called, &registration_id, &version_id));
442 432
443 ASSERT_FALSE(called); 433 ASSERT_FALSE(called);
444 base::RunLoop().RunUntilIdle(); 434 base::RunLoop().RunUntilIdle();
445 EXPECT_TRUE(called); 435 EXPECT_TRUE(called);
446 436
447 context()->storage()->FindRegistrationForId( 437 context()->storage()->FindRegistrationForId(
448 registration_id, 438 registration_id,
449 GURL("http://www.example.com"), 439 GURL("http://www.example.com"),
450 base::Bind(&ExpectRegisteredWorkers, 440 base::Bind(&ExpectRegisteredWorkers,
451 SERVICE_WORKER_OK, 441 SERVICE_WORKER_OK,
452 version_id, 442 version_id,
453 false /* expect_waiting */, 443 false /* expect_waiting */,
454 true /* expect_active */)); 444 true /* expect_active */));
455 base::RunLoop().RunUntilIdle(); 445 base::RunLoop().RunUntilIdle();
456 } 446 }
457 447
458 } // namespace content 448 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698