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

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

Issue 435873002: ServiceWorker: Remove wildcard from scope matching (Chromium) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 6 years, 4 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 | Annotate | Revision Log
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 <string> 5 #include <string>
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 "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 EXPECT_TRUE(was_called); 311 EXPECT_TRUE(was_called);
312 return result; 312 return result;
313 } 313 }
314 314
315 scoped_ptr<ServiceWorkerContextCore> context_; 315 scoped_ptr<ServiceWorkerContextCore> context_;
316 base::WeakPtr<ServiceWorkerContextCore> context_ptr_; 316 base::WeakPtr<ServiceWorkerContextCore> context_ptr_;
317 TestBrowserThreadBundle browser_thread_bundle_; 317 TestBrowserThreadBundle browser_thread_bundle_;
318 }; 318 };
319 319
320 TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) { 320 TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) {
321 const GURL kScope("http://www.test.not/scope/*"); 321 const GURL kScope("http://www.test.not/scope/");
322 const GURL kScript("http://www.test.not/script.js"); 322 const GURL kScript("http://www.test.not/script.js");
323 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 323 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
324 const int64 kRegistrationId = 0; 324 const int64 kRegistrationId = 0;
325 const int64 kVersionId = 0; 325 const int64 kVersionId = 0;
326 326
327 scoped_refptr<ServiceWorkerRegistration> found_registration; 327 scoped_refptr<ServiceWorkerRegistration> found_registration;
328 328
329 // We shouldn't find anything without having stored anything. 329 // We shouldn't find anything without having stored anything.
330 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 330 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
331 FindRegistrationForDocument(kDocumentUrl, &found_registration)); 331 FindRegistrationForDocument(kDocumentUrl, &found_registration));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 FindRegistrationForId( 438 FindRegistrationForId(
439 kRegistrationId, kScope.GetOrigin(), &found_registration)); 439 kRegistrationId, kScope.GetOrigin(), &found_registration));
440 EXPECT_FALSE(found_registration); 440 EXPECT_FALSE(found_registration);
441 441
442 // Deleting an unstored registration should succeed. 442 // Deleting an unstored registration should succeed.
443 EXPECT_EQ(SERVICE_WORKER_OK, 443 EXPECT_EQ(SERVICE_WORKER_OK,
444 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin())); 444 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin()));
445 } 445 }
446 446
447 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { 447 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) {
448 const GURL kScope("http://www.test.not/scope/*"); 448 const GURL kScope("http://www.test.not/scope/");
449 const GURL kScript("http://www.test.not/script.js"); 449 const GURL kScript("http://www.test.not/script.js");
450 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 450 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
451 const int64 kRegistrationId = 0; 451 const int64 kRegistrationId = 0;
452 const int64 kVersionId = 0; 452 const int64 kVersionId = 0;
453 453
454 scoped_refptr<ServiceWorkerRegistration> found_registration; 454 scoped_refptr<ServiceWorkerRegistration> found_registration;
455 455
456 // Create an unstored registration. 456 // Create an unstored registration.
457 scoped_refptr<ServiceWorkerRegistration> live_registration = 457 scoped_refptr<ServiceWorkerRegistration> live_registration =
458 new ServiceWorkerRegistration( 458 new ServiceWorkerRegistration(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 EXPECT_TRUE(all_registrations.empty()); 527 EXPECT_TRUE(all_registrations.empty());
528 } 528 }
529 529
530 class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest { 530 class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest {
531 public: 531 public:
532 virtual void SetUp() OVERRIDE { 532 virtual void SetUp() OVERRIDE {
533 ServiceWorkerStorageTest::SetUp(); 533 ServiceWorkerStorageTest::SetUp();
534 534
535 storage()->LazyInitialize(base::Bind(&base::DoNothing)); 535 storage()->LazyInitialize(base::Bind(&base::DoNothing));
536 base::RunLoop().RunUntilIdle(); 536 base::RunLoop().RunUntilIdle();
537 scope_ = GURL("http://www.test.not/scope/*"); 537 scope_ = GURL("http://www.test.not/scope/");
538 script_ = GURL("http://www.test.not/script.js"); 538 script_ = GURL("http://www.test.not/script.js");
539 import_ = GURL("http://www.test.not/import.js"); 539 import_ = GURL("http://www.test.not/import.js");
540 document_url_ = GURL("http://www.test.not/scope/document.html"); 540 document_url_ = GURL("http://www.test.not/scope/document.html");
541 registration_id_ = storage()->NewRegistrationId(); 541 registration_id_ = storage()->NewRegistrationId();
542 version_id_ = storage()->NewVersionId(); 542 version_id_ = storage()->NewVersionId();
543 resource_id1_ = storage()->NewResourceId(); 543 resource_id1_ = storage()->NewResourceId();
544 resource_id2_ = storage()->NewResourceId(); 544 resource_id2_ = storage()->NewResourceId();
545 545
546 // Cons up a new registration+version with two script resources. 546 // Cons up a new registration+version with two script resources.
547 RegistrationData data; 547 RegistrationData data;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 EXPECT_TRUE(verify_ids.empty()); 884 EXPECT_TRUE(verify_ids.empty());
885 885
886 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 886 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
887 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 887 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
888 } 888 }
889 889
890 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { 890 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) {
891 const GURL kDocumentUrl("http://www.example.com/scope/foo"); 891 const GURL kDocumentUrl("http://www.example.com/scope/foo");
892 scoped_refptr<ServiceWorkerRegistration> found_registration; 892 scoped_refptr<ServiceWorkerRegistration> found_registration;
893 893
894 // Registration for "/scope/*". 894 // Registration for "/scope/".
895 const GURL kScope1("http://www.example.com/scope/*"); 895 const GURL kScope1("http://www.example.com/scope/");
896 const GURL kScript1("http://www.example.com/script1.js"); 896 const GURL kScript1("http://www.example.com/script1.js");
897 const int64 kRegistrationId1 = 1; 897 const int64 kRegistrationId1 = 1;
898 const int64 kVersionId1 = 1; 898 const int64 kVersionId1 = 1;
899 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 899 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
900 new ServiceWorkerRegistration( 900 new ServiceWorkerRegistration(
901 kScope1, kScript1, kRegistrationId1, context_ptr_); 901 kScope1, kScript1, kRegistrationId1, context_ptr_);
902 scoped_refptr<ServiceWorkerVersion> live_version1 = 902 scoped_refptr<ServiceWorkerVersion> live_version1 =
903 new ServiceWorkerVersion( 903 new ServiceWorkerVersion(
904 live_registration1, kVersionId1, context_ptr_); 904 live_registration1, kVersionId1, context_ptr_);
905 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 905 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
906 live_registration1->SetWaitingVersion(live_version1); 906 live_registration1->SetWaitingVersion(live_version1);
907 907
908 // Registration for "/scope/foo*". 908 // Registration for "/scope/foo".
909 const GURL kScope2("http://www.example.com/scope/foo*"); 909 const GURL kScope2("http://www.example.com/scope/foo");
910 const GURL kScript2("http://www.example.com/script2.js"); 910 const GURL kScript2("http://www.example.com/script2.js");
911 const int64 kRegistrationId2 = 2; 911 const int64 kRegistrationId2 = 2;
912 const int64 kVersionId2 = 2; 912 const int64 kVersionId2 = 2;
913 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 913 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
914 new ServiceWorkerRegistration( 914 new ServiceWorkerRegistration(
915 kScope2, kScript2, kRegistrationId2, context_ptr_); 915 kScope2, kScript2, kRegistrationId2, context_ptr_);
916 scoped_refptr<ServiceWorkerVersion> live_version2 = 916 scoped_refptr<ServiceWorkerVersion> live_version2 =
917 new ServiceWorkerVersion( 917 new ServiceWorkerVersion(
918 live_registration2, kVersionId2, context_ptr_); 918 live_registration2, kVersionId2, context_ptr_);
919 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 919 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
920 live_registration2->SetWaitingVersion(live_version2); 920 live_registration2->SetWaitingVersion(live_version2);
921 921
922 // Registration for "/scope/foo". 922 // Registration for "/scope/foobar".
923 const GURL kScope3("http://www.example.com/scope/foo"); 923 const GURL kScope3("http://www.example.com/scope/foobar");
924 const GURL kScript3("http://www.example.com/script3.js"); 924 const GURL kScript3("http://www.example.com/script3.js");
925 const int64 kRegistrationId3 = 3; 925 const int64 kRegistrationId3 = 3;
926 const int64 kVersionId3 = 3; 926 const int64 kVersionId3 = 3;
927 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 927 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
928 new ServiceWorkerRegistration( 928 new ServiceWorkerRegistration(
929 kScope3, kScript3, kRegistrationId3, context_ptr_); 929 kScope3, kScript3, kRegistrationId3, context_ptr_);
930 scoped_refptr<ServiceWorkerVersion> live_version3 = 930 scoped_refptr<ServiceWorkerVersion> live_version3 =
931 new ServiceWorkerVersion( 931 new ServiceWorkerVersion(
932 live_registration3, kVersionId3, context_ptr_); 932 live_registration3, kVersionId3, context_ptr_);
933 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 933 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 are_equal = true; 1022 are_equal = true;
1023 storage()->CompareScriptResources( 1023 storage()->CompareScriptResources(
1024 5, 6, 1024 5, 6,
1025 base::Bind(&OnCompareComplete, &status, &are_equal)); 1025 base::Bind(&OnCompareComplete, &status, &are_equal));
1026 base::RunLoop().RunUntilIdle(); 1026 base::RunLoop().RunUntilIdle();
1027 EXPECT_EQ(SERVICE_WORKER_OK, status); 1027 EXPECT_EQ(SERVICE_WORKER_OK, status);
1028 EXPECT_FALSE(are_equal); 1028 EXPECT_FALSE(are_equal);
1029 } 1029 }
1030 1030
1031 } // namespace content 1031 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698