| 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> | 
|  | 6 | 
| 5 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 6 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" | 
| 7 #include "base/run_loop.h" | 9 #include "base/run_loop.h" | 
| 8 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" | 
| 9 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" | 
| 10 #include "content/browser/service_worker/service_worker_disk_cache.h" | 12 #include "content/browser/service_worker/service_worker_disk_cache.h" | 
| 11 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" | 
| 12 #include "content/browser/service_worker/service_worker_storage.h" | 14 #include "content/browser/service_worker/service_worker_storage.h" | 
| 13 #include "content/browser/service_worker/service_worker_version.h" | 15 #include "content/browser/service_worker/service_worker_version.h" | 
| 14 #include "content/common/service_worker/service_worker_status_code.h" | 16 #include "content/common/service_worker/service_worker_status_code.h" | 
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 603   EXPECT_EQ(2u, verify_ids.size()); | 605   EXPECT_EQ(2u, verify_ids.size()); | 
| 604   verify_ids.clear(); | 606   verify_ids.clear(); | 
| 605   EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 607   EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 
| 606             storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 608             storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 
| 607   EXPECT_TRUE(verify_ids.empty()); | 609   EXPECT_TRUE(verify_ids.empty()); | 
| 608 | 610 | 
| 609   EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId1, false)); | 611   EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId1, false)); | 
| 610   EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId2, false)); | 612   EXPECT_FALSE(VerifyBasicResponse(storage(), kResourceId2, false)); | 
| 611 } | 613 } | 
| 612 | 614 | 
|  | 615 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { | 
|  | 616   const GURL kDocumentUrl("http://www.example.com/scope/foo"); | 
|  | 617   bool was_called = false; | 
|  | 618   ServiceWorkerStatusCode result = SERVICE_WORKER_OK; | 
|  | 619   scoped_refptr<ServiceWorkerRegistration> found_registration; | 
|  | 620 | 
|  | 621   // Registration for "/scope/*". | 
|  | 622   const GURL kScope1("http://www.example.com/scope/*"); | 
|  | 623   const GURL kScript1("http://www.example.com/script1.js"); | 
|  | 624   const int64 kRegistrationId1 = 1; | 
|  | 625   const int64 kVersionId1 = 1; | 
|  | 626   scoped_refptr<ServiceWorkerRegistration> live_registration1 = | 
|  | 627       new ServiceWorkerRegistration( | 
|  | 628           kScope1, kScript1, kRegistrationId1, context_ptr_); | 
|  | 629   scoped_refptr<ServiceWorkerVersion> live_version1 = | 
|  | 630       new ServiceWorkerVersion( | 
|  | 631           live_registration1, kVersionId1, context_ptr_); | 
|  | 632   live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); | 
|  | 633   live_registration1->set_waiting_version(live_version1); | 
|  | 634 | 
|  | 635   // Registration for "/scope/foo*". | 
|  | 636   const GURL kScope2("http://www.example.com/scope/foo*"); | 
|  | 637   const GURL kScript2("http://www.example.com/script2.js"); | 
|  | 638   const int64 kRegistrationId2 = 2; | 
|  | 639   const int64 kVersionId2 = 2; | 
|  | 640   scoped_refptr<ServiceWorkerRegistration> live_registration2 = | 
|  | 641       new ServiceWorkerRegistration( | 
|  | 642           kScope2, kScript2, kRegistrationId2, context_ptr_); | 
|  | 643   scoped_refptr<ServiceWorkerVersion> live_version2 = | 
|  | 644       new ServiceWorkerVersion( | 
|  | 645           live_registration2, kVersionId2, context_ptr_); | 
|  | 646   live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); | 
|  | 647   live_registration2->set_waiting_version(live_version2); | 
|  | 648 | 
|  | 649   // Registration for "/scope/foo". | 
|  | 650   const GURL kScope3("http://www.example.com/scope/foo"); | 
|  | 651   const GURL kScript3("http://www.example.com/script3.js"); | 
|  | 652   const int64 kRegistrationId3 = 3; | 
|  | 653   const int64 kVersionId3 = 3; | 
|  | 654   scoped_refptr<ServiceWorkerRegistration> live_registration3 = | 
|  | 655       new ServiceWorkerRegistration( | 
|  | 656           kScope3, kScript3, kRegistrationId3, context_ptr_); | 
|  | 657   scoped_refptr<ServiceWorkerVersion> live_version3 = | 
|  | 658       new ServiceWorkerVersion( | 
|  | 659           live_registration3, kVersionId3, context_ptr_); | 
|  | 660   live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); | 
|  | 661   live_registration3->set_waiting_version(live_version3); | 
|  | 662 | 
|  | 663   // Notify storage of they being installed. | 
|  | 664   storage()->NotifyInstallingRegistration(live_registration1); | 
|  | 665   storage()->NotifyInstallingRegistration(live_registration2); | 
|  | 666   storage()->NotifyInstallingRegistration(live_registration3); | 
|  | 667 | 
|  | 668   // Find a registration among installing ones. | 
|  | 669   storage()->FindRegistrationForDocument( | 
|  | 670       kDocumentUrl, | 
|  | 671       MakeFindCallback(&was_called, &result, &found_registration)); | 
|  | 672   base::RunLoop().RunUntilIdle(); | 
|  | 673   ASSERT_TRUE(was_called); | 
|  | 674   EXPECT_EQ(SERVICE_WORKER_OK, result); | 
|  | 675   EXPECT_EQ(live_registration2, found_registration); | 
|  | 676   was_called = false; | 
|  | 677   found_registration = NULL; | 
|  | 678 | 
|  | 679   // Store registrations. | 
|  | 680   storage()->StoreRegistration(live_registration1, live_version1, | 
|  | 681                                MakeStatusCallback(&was_called, &result)); | 
|  | 682   EXPECT_FALSE(was_called); | 
|  | 683   base::RunLoop().RunUntilIdle(); | 
|  | 684   ASSERT_TRUE(was_called); | 
|  | 685   EXPECT_EQ(SERVICE_WORKER_OK, result); | 
|  | 686   was_called = false; | 
|  | 687   storage()->StoreRegistration(live_registration2, live_version2, | 
|  | 688                                MakeStatusCallback(&was_called, &result)); | 
|  | 689   EXPECT_FALSE(was_called); | 
|  | 690   base::RunLoop().RunUntilIdle(); | 
|  | 691   ASSERT_TRUE(was_called); | 
|  | 692   EXPECT_EQ(SERVICE_WORKER_OK, result); | 
|  | 693   was_called = false; | 
|  | 694   storage()->StoreRegistration(live_registration3, live_version3, | 
|  | 695                                MakeStatusCallback(&was_called, &result)); | 
|  | 696   EXPECT_FALSE(was_called); | 
|  | 697   base::RunLoop().RunUntilIdle(); | 
|  | 698   ASSERT_TRUE(was_called); | 
|  | 699   EXPECT_EQ(SERVICE_WORKER_OK, result); | 
|  | 700   was_called = false; | 
|  | 701 | 
|  | 702   // Notify storage of installations no longer happening. | 
|  | 703   storage()->NotifyDoneInstallingRegistration( | 
|  | 704       live_registration1, NULL, SERVICE_WORKER_OK); | 
|  | 705   storage()->NotifyDoneInstallingRegistration( | 
|  | 706       live_registration2, NULL, SERVICE_WORKER_OK); | 
|  | 707   storage()->NotifyDoneInstallingRegistration( | 
|  | 708       live_registration3, NULL, SERVICE_WORKER_OK); | 
|  | 709 | 
|  | 710   // Find a registration among installed ones. | 
|  | 711   storage()->FindRegistrationForDocument( | 
|  | 712       kDocumentUrl, | 
|  | 713       MakeFindCallback(&was_called, &result, &found_registration)); | 
|  | 714   base::RunLoop().RunUntilIdle(); | 
|  | 715   ASSERT_TRUE(was_called); | 
|  | 716   EXPECT_EQ(SERVICE_WORKER_OK, result); | 
|  | 717   EXPECT_EQ(live_registration2, found_registration); | 
|  | 718   was_called = false; | 
|  | 719   found_registration = NULL; | 
|  | 720 } | 
|  | 721 | 
| 613 }  // namespace content | 722 }  // namespace content | 
| OLD | NEW | 
|---|