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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 EXPECT_FALSE(found_registration); | 298 EXPECT_FALSE(found_registration); |
299 | 299 |
300 // Store something. | 300 // Store something. |
301 scoped_refptr<ServiceWorkerRegistration> live_registration = | 301 scoped_refptr<ServiceWorkerRegistration> live_registration = |
302 new ServiceWorkerRegistration( | 302 new ServiceWorkerRegistration( |
303 kScope, kScript, kRegistrationId, context_ptr_); | 303 kScope, kScript, kRegistrationId, context_ptr_); |
304 scoped_refptr<ServiceWorkerVersion> live_version = | 304 scoped_refptr<ServiceWorkerVersion> live_version = |
305 new ServiceWorkerVersion( | 305 new ServiceWorkerVersion( |
306 live_registration, kVersionId, context_ptr_); | 306 live_registration, kVersionId, context_ptr_); |
307 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); | 307 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); |
308 live_registration->set_waiting_version(live_version); | 308 live_registration->SetWaitingVersion(live_version); |
309 EXPECT_EQ(SERVICE_WORKER_OK, | 309 EXPECT_EQ(SERVICE_WORKER_OK, |
310 StoreRegistration(live_registration, live_version)); | 310 StoreRegistration(live_registration, live_version)); |
311 | 311 |
312 // Now we should find it and get the live ptr back immediately. | 312 // Now we should find it and get the live ptr back immediately. |
313 EXPECT_EQ(SERVICE_WORKER_OK, | 313 EXPECT_EQ(SERVICE_WORKER_OK, |
314 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 314 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
315 EXPECT_EQ(live_registration, found_registration); | 315 EXPECT_EQ(live_registration, found_registration); |
316 found_registration = NULL; | 316 found_registration = NULL; |
317 | 317 |
318 // But FindRegistrationForPattern is always async. | 318 // But FindRegistrationForPattern is always async. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 EXPECT_EQ(kRegistrationId, found_registration->id()); | 352 EXPECT_EQ(kRegistrationId, found_registration->id()); |
353 EXPECT_TRUE(found_registration->HasOneRef()); | 353 EXPECT_TRUE(found_registration->HasOneRef()); |
354 EXPECT_FALSE(found_registration->active_version()); | 354 EXPECT_FALSE(found_registration->active_version()); |
355 ASSERT_TRUE(found_registration->waiting_version()); | 355 ASSERT_TRUE(found_registration->waiting_version()); |
356 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, | 356 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, |
357 found_registration->waiting_version()->status()); | 357 found_registration->waiting_version()->status()); |
358 | 358 |
359 // Update to active. | 359 // Update to active. |
360 scoped_refptr<ServiceWorkerVersion> temp_version = | 360 scoped_refptr<ServiceWorkerVersion> temp_version = |
361 found_registration->waiting_version(); | 361 found_registration->waiting_version(); |
362 found_registration->set_waiting_version(NULL); | |
363 temp_version->SetStatus(ServiceWorkerVersion::ACTIVE); | 362 temp_version->SetStatus(ServiceWorkerVersion::ACTIVE); |
364 found_registration->set_active_version(temp_version); | 363 found_registration->SetActiveVersion(temp_version); |
365 temp_version = NULL; | 364 temp_version = NULL; |
366 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); | 365 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); |
367 found_registration = NULL; | 366 found_registration = NULL; |
368 | 367 |
369 // Trying to update a unstored registration to active should fail. | 368 // Trying to update a unstored registration to active should fail. |
370 scoped_refptr<ServiceWorkerRegistration> unstored_registration = | 369 scoped_refptr<ServiceWorkerRegistration> unstored_registration = |
371 new ServiceWorkerRegistration( | 370 new ServiceWorkerRegistration( |
372 kScope, kScript, kRegistrationId + 1, context_ptr_); | 371 kScope, kScript, kRegistrationId + 1, context_ptr_); |
373 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 372 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
374 UpdateToActiveState(unstored_registration)); | 373 UpdateToActiveState(unstored_registration)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 scoped_refptr<ServiceWorkerRegistration> found_registration; | 411 scoped_refptr<ServiceWorkerRegistration> found_registration; |
413 | 412 |
414 // Create an unstored registration. | 413 // Create an unstored registration. |
415 scoped_refptr<ServiceWorkerRegistration> live_registration = | 414 scoped_refptr<ServiceWorkerRegistration> live_registration = |
416 new ServiceWorkerRegistration( | 415 new ServiceWorkerRegistration( |
417 kScope, kScript, kRegistrationId, context_ptr_); | 416 kScope, kScript, kRegistrationId, context_ptr_); |
418 scoped_refptr<ServiceWorkerVersion> live_version = | 417 scoped_refptr<ServiceWorkerVersion> live_version = |
419 new ServiceWorkerVersion( | 418 new ServiceWorkerVersion( |
420 live_registration, kVersionId, context_ptr_); | 419 live_registration, kVersionId, context_ptr_); |
421 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); | 420 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); |
422 live_registration->set_waiting_version(live_version); | 421 live_registration->SetWaitingVersion(live_version); |
423 | 422 |
424 // Should not be findable, including by GetAllRegistrations. | 423 // Should not be findable, including by GetAllRegistrations. |
425 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 424 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
426 FindRegistrationForId( | 425 FindRegistrationForId( |
427 kRegistrationId, kScope.GetOrigin(), &found_registration)); | 426 kRegistrationId, kScope.GetOrigin(), &found_registration)); |
428 EXPECT_FALSE(found_registration); | 427 EXPECT_FALSE(found_registration); |
429 | 428 |
430 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 429 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
431 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 430 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
432 EXPECT_FALSE(found_registration); | 431 EXPECT_FALSE(found_registration); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 const GURL kScript1("http://www.example.com/script1.js"); | 565 const GURL kScript1("http://www.example.com/script1.js"); |
567 const int64 kRegistrationId1 = 1; | 566 const int64 kRegistrationId1 = 1; |
568 const int64 kVersionId1 = 1; | 567 const int64 kVersionId1 = 1; |
569 scoped_refptr<ServiceWorkerRegistration> live_registration1 = | 568 scoped_refptr<ServiceWorkerRegistration> live_registration1 = |
570 new ServiceWorkerRegistration( | 569 new ServiceWorkerRegistration( |
571 kScope1, kScript1, kRegistrationId1, context_ptr_); | 570 kScope1, kScript1, kRegistrationId1, context_ptr_); |
572 scoped_refptr<ServiceWorkerVersion> live_version1 = | 571 scoped_refptr<ServiceWorkerVersion> live_version1 = |
573 new ServiceWorkerVersion( | 572 new ServiceWorkerVersion( |
574 live_registration1, kVersionId1, context_ptr_); | 573 live_registration1, kVersionId1, context_ptr_); |
575 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); | 574 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); |
576 live_registration1->set_waiting_version(live_version1); | 575 live_registration1->SetWaitingVersion(live_version1); |
577 | 576 |
578 // Registration for "/scope/foo*". | 577 // Registration for "/scope/foo*". |
579 const GURL kScope2("http://www.example.com/scope/foo*"); | 578 const GURL kScope2("http://www.example.com/scope/foo*"); |
580 const GURL kScript2("http://www.example.com/script2.js"); | 579 const GURL kScript2("http://www.example.com/script2.js"); |
581 const int64 kRegistrationId2 = 2; | 580 const int64 kRegistrationId2 = 2; |
582 const int64 kVersionId2 = 2; | 581 const int64 kVersionId2 = 2; |
583 scoped_refptr<ServiceWorkerRegistration> live_registration2 = | 582 scoped_refptr<ServiceWorkerRegistration> live_registration2 = |
584 new ServiceWorkerRegistration( | 583 new ServiceWorkerRegistration( |
585 kScope2, kScript2, kRegistrationId2, context_ptr_); | 584 kScope2, kScript2, kRegistrationId2, context_ptr_); |
586 scoped_refptr<ServiceWorkerVersion> live_version2 = | 585 scoped_refptr<ServiceWorkerVersion> live_version2 = |
587 new ServiceWorkerVersion( | 586 new ServiceWorkerVersion( |
588 live_registration2, kVersionId2, context_ptr_); | 587 live_registration2, kVersionId2, context_ptr_); |
589 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); | 588 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); |
590 live_registration2->set_waiting_version(live_version2); | 589 live_registration2->SetWaitingVersion(live_version2); |
591 | 590 |
592 // Registration for "/scope/foo". | 591 // Registration for "/scope/foo". |
593 const GURL kScope3("http://www.example.com/scope/foo"); | 592 const GURL kScope3("http://www.example.com/scope/foo"); |
594 const GURL kScript3("http://www.example.com/script3.js"); | 593 const GURL kScript3("http://www.example.com/script3.js"); |
595 const int64 kRegistrationId3 = 3; | 594 const int64 kRegistrationId3 = 3; |
596 const int64 kVersionId3 = 3; | 595 const int64 kVersionId3 = 3; |
597 scoped_refptr<ServiceWorkerRegistration> live_registration3 = | 596 scoped_refptr<ServiceWorkerRegistration> live_registration3 = |
598 new ServiceWorkerRegistration( | 597 new ServiceWorkerRegistration( |
599 kScope3, kScript3, kRegistrationId3, context_ptr_); | 598 kScope3, kScript3, kRegistrationId3, context_ptr_); |
600 scoped_refptr<ServiceWorkerVersion> live_version3 = | 599 scoped_refptr<ServiceWorkerVersion> live_version3 = |
601 new ServiceWorkerVersion( | 600 new ServiceWorkerVersion( |
602 live_registration3, kVersionId3, context_ptr_); | 601 live_registration3, kVersionId3, context_ptr_); |
603 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); | 602 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); |
604 live_registration3->set_waiting_version(live_version3); | 603 live_registration3->SetWaitingVersion(live_version3); |
605 | 604 |
606 // Notify storage of they being installed. | 605 // Notify storage of they being installed. |
607 storage()->NotifyInstallingRegistration(live_registration1); | 606 storage()->NotifyInstallingRegistration(live_registration1); |
608 storage()->NotifyInstallingRegistration(live_registration2); | 607 storage()->NotifyInstallingRegistration(live_registration2); |
609 storage()->NotifyInstallingRegistration(live_registration3); | 608 storage()->NotifyInstallingRegistration(live_registration3); |
610 | 609 |
611 // Find a registration among installing ones. | 610 // Find a registration among installing ones. |
612 EXPECT_EQ(SERVICE_WORKER_OK, | 611 EXPECT_EQ(SERVICE_WORKER_OK, |
613 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 612 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
614 EXPECT_EQ(live_registration2, found_registration); | 613 EXPECT_EQ(live_registration2, found_registration); |
(...skipping 15 matching lines...) Expand all Loading... |
630 storage()->NotifyDoneInstallingRegistration( | 629 storage()->NotifyDoneInstallingRegistration( |
631 live_registration3, NULL, SERVICE_WORKER_OK); | 630 live_registration3, NULL, SERVICE_WORKER_OK); |
632 | 631 |
633 // Find a registration among installed ones. | 632 // Find a registration among installed ones. |
634 EXPECT_EQ(SERVICE_WORKER_OK, | 633 EXPECT_EQ(SERVICE_WORKER_OK, |
635 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 634 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
636 EXPECT_EQ(live_registration2, found_registration); | 635 EXPECT_EQ(live_registration2, found_registration); |
637 } | 636 } |
638 | 637 |
639 } // namespace content | 638 } // namespace content |
OLD | NEW |