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