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

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

Issue 501453002: Decouple script_url from ServiceWorkerRegistration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 EXPECT_FALSE(found_registration); 343 EXPECT_FALSE(found_registration);
344 344
345 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 345 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
346 FindRegistrationForId( 346 FindRegistrationForId(
347 kRegistrationId, kScope.GetOrigin(), &found_registration)); 347 kRegistrationId, kScope.GetOrigin(), &found_registration));
348 EXPECT_FALSE(found_registration); 348 EXPECT_FALSE(found_registration);
349 349
350 // Store something. 350 // Store something.
351 scoped_refptr<ServiceWorkerRegistration> live_registration = 351 scoped_refptr<ServiceWorkerRegistration> live_registration =
352 new ServiceWorkerRegistration( 352 new ServiceWorkerRegistration(
353 kScope, kScript, kRegistrationId, context_ptr_); 353 kScope, kRegistrationId, context_ptr_);
354 scoped_refptr<ServiceWorkerVersion> live_version = 354 scoped_refptr<ServiceWorkerVersion> live_version =
355 new ServiceWorkerVersion( 355 new ServiceWorkerVersion(
356 live_registration, kVersionId, context_ptr_); 356 live_registration, kScript, kVersionId, context_ptr_);
357 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); 357 live_version->SetStatus(ServiceWorkerVersion::INSTALLED);
358 live_registration->SetWaitingVersion(live_version); 358 live_registration->SetWaitingVersion(live_version);
359 live_registration->set_last_update_check(kYesterday); 359 live_registration->set_last_update_check(kYesterday);
360 EXPECT_EQ(SERVICE_WORKER_OK, 360 EXPECT_EQ(SERVICE_WORKER_OK,
361 StoreRegistration(live_registration, live_version)); 361 StoreRegistration(live_registration, live_version));
362 362
363 // Now we should find it and get the live ptr back immediately. 363 // Now we should find it and get the live ptr back immediately.
364 EXPECT_EQ(SERVICE_WORKER_OK, 364 EXPECT_EQ(SERVICE_WORKER_OK,
365 FindRegistrationForDocument(kDocumentUrl, &found_registration)); 365 FindRegistrationForDocument(kDocumentUrl, &found_registration));
366 EXPECT_EQ(live_registration, found_registration); 366 EXPECT_EQ(live_registration, found_registration);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 temp_version = NULL; 416 temp_version = NULL;
417 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); 417 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration));
418 found_registration->set_last_update_check(kToday); 418 found_registration->set_last_update_check(kToday);
419 UpdateLastUpdateCheckTime(found_registration); 419 UpdateLastUpdateCheckTime(found_registration);
420 420
421 found_registration = NULL; 421 found_registration = NULL;
422 422
423 // Trying to update a unstored registration to active should fail. 423 // Trying to update a unstored registration to active should fail.
424 scoped_refptr<ServiceWorkerRegistration> unstored_registration = 424 scoped_refptr<ServiceWorkerRegistration> unstored_registration =
425 new ServiceWorkerRegistration( 425 new ServiceWorkerRegistration(
426 kScope, kScript, kRegistrationId + 1, context_ptr_); 426 kScope, kRegistrationId + 1, context_ptr_);
427 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 427 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
428 UpdateToActiveState(unstored_registration)); 428 UpdateToActiveState(unstored_registration));
429 unstored_registration = NULL; 429 unstored_registration = NULL;
430 430
431 // The Find methods should return a registration with an active version 431 // The Find methods should return a registration with an active version
432 // and the expected update time. 432 // and the expected update time.
433 EXPECT_EQ(SERVICE_WORKER_OK, 433 EXPECT_EQ(SERVICE_WORKER_OK,
434 FindRegistrationForDocument(kDocumentUrl, &found_registration)); 434 FindRegistrationForDocument(kDocumentUrl, &found_registration));
435 ASSERT_TRUE(found_registration); 435 ASSERT_TRUE(found_registration);
436 EXPECT_EQ(kRegistrationId, found_registration->id()); 436 EXPECT_EQ(kRegistrationId, found_registration->id());
(...skipping 26 matching lines...) Expand all
463 const GURL kScript("http://www.test.not/script.js"); 463 const GURL kScript("http://www.test.not/script.js");
464 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 464 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
465 const int64 kRegistrationId = 0; 465 const int64 kRegistrationId = 0;
466 const int64 kVersionId = 0; 466 const int64 kVersionId = 0;
467 467
468 scoped_refptr<ServiceWorkerRegistration> found_registration; 468 scoped_refptr<ServiceWorkerRegistration> found_registration;
469 469
470 // Create an unstored registration. 470 // Create an unstored registration.
471 scoped_refptr<ServiceWorkerRegistration> live_registration = 471 scoped_refptr<ServiceWorkerRegistration> live_registration =
472 new ServiceWorkerRegistration( 472 new ServiceWorkerRegistration(
473 kScope, kScript, kRegistrationId, context_ptr_); 473 kScope, kRegistrationId, context_ptr_);
474 scoped_refptr<ServiceWorkerVersion> live_version = 474 scoped_refptr<ServiceWorkerVersion> live_version =
475 new ServiceWorkerVersion( 475 new ServiceWorkerVersion(
476 live_registration, kVersionId, context_ptr_); 476 live_registration, kScript, kVersionId, context_ptr_);
477 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); 477 live_version->SetStatus(ServiceWorkerVersion::INSTALLING);
478 live_registration->SetWaitingVersion(live_version); 478 live_registration->SetWaitingVersion(live_version);
479 479
480 // Should not be findable, including by GetAllRegistrations. 480 // Should not be findable, including by GetAllRegistrations.
481 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 481 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
482 FindRegistrationForId( 482 FindRegistrationForId(
483 kRegistrationId, kScope.GetOrigin(), &found_registration)); 483 kRegistrationId, kScope.GetOrigin(), &found_registration));
484 EXPECT_FALSE(found_registration); 484 EXPECT_FALSE(found_registration);
485 485
486 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 486 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 context_->AsWeakPtr(), 855 context_->AsWeakPtr(),
856 NULL)); 856 NULL));
857 registration_->active_version()->AddControllee(host.get()); 857 registration_->active_version()->AddControllee(host.get());
858 858
859 bool was_called = false; 859 bool was_called = false;
860 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; 860 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED;
861 std::set<int64> verify_ids; 861 std::set<int64> verify_ids;
862 862
863 // Make an updated registration. 863 // Make an updated registration.
864 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 864 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
865 registration_, storage()->NewVersionId(), context_ptr_); 865 registration_, script_, storage()->NewVersionId(), context_ptr_);
866 live_version->SetStatus(ServiceWorkerVersion::NEW); 866 live_version->SetStatus(ServiceWorkerVersion::NEW);
867 registration_->SetWaitingVersion(live_version); 867 registration_->SetWaitingVersion(live_version);
868 868
869 // Writing the registration should move the old version's resources to the 869 // Writing the registration should move the old version's resources to the
870 // purgeable list but keep them available. 870 // purgeable list but keep them available.
871 storage()->StoreRegistration( 871 storage()->StoreRegistration(
872 registration_, 872 registration_,
873 registration_->waiting_version(), 873 registration_->waiting_version(),
874 base::Bind(&VerifyPurgeableListStatusCallback, 874 base::Bind(&VerifyPurgeableListStatusCallback,
875 base::Unretained(storage()->database_.get()), 875 base::Unretained(storage()->database_.get()),
(...skipping 30 matching lines...) Expand all
906 const GURL kDocumentUrl("http://www.example.com/scope/foo"); 906 const GURL kDocumentUrl("http://www.example.com/scope/foo");
907 scoped_refptr<ServiceWorkerRegistration> found_registration; 907 scoped_refptr<ServiceWorkerRegistration> found_registration;
908 908
909 // Registration for "/scope/". 909 // Registration for "/scope/".
910 const GURL kScope1("http://www.example.com/scope/"); 910 const GURL kScope1("http://www.example.com/scope/");
911 const GURL kScript1("http://www.example.com/script1.js"); 911 const GURL kScript1("http://www.example.com/script1.js");
912 const int64 kRegistrationId1 = 1; 912 const int64 kRegistrationId1 = 1;
913 const int64 kVersionId1 = 1; 913 const int64 kVersionId1 = 1;
914 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 914 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
915 new ServiceWorkerRegistration( 915 new ServiceWorkerRegistration(
916 kScope1, kScript1, kRegistrationId1, context_ptr_); 916 kScope1, kRegistrationId1, context_ptr_);
917 scoped_refptr<ServiceWorkerVersion> live_version1 = 917 scoped_refptr<ServiceWorkerVersion> live_version1 =
918 new ServiceWorkerVersion( 918 new ServiceWorkerVersion(
919 live_registration1, kVersionId1, context_ptr_); 919 live_registration1, kScript1, kVersionId1, context_ptr_);
920 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); 920 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED);
921 live_registration1->SetWaitingVersion(live_version1); 921 live_registration1->SetWaitingVersion(live_version1);
922 922
923 // Registration for "/scope/foo". 923 // Registration for "/scope/foo".
924 const GURL kScope2("http://www.example.com/scope/foo"); 924 const GURL kScope2("http://www.example.com/scope/foo");
925 const GURL kScript2("http://www.example.com/script2.js"); 925 const GURL kScript2("http://www.example.com/script2.js");
926 const int64 kRegistrationId2 = 2; 926 const int64 kRegistrationId2 = 2;
927 const int64 kVersionId2 = 2; 927 const int64 kVersionId2 = 2;
928 scoped_refptr<ServiceWorkerRegistration> live_registration2 = 928 scoped_refptr<ServiceWorkerRegistration> live_registration2 =
929 new ServiceWorkerRegistration( 929 new ServiceWorkerRegistration(
930 kScope2, kScript2, kRegistrationId2, context_ptr_); 930 kScope2, kRegistrationId2, context_ptr_);
931 scoped_refptr<ServiceWorkerVersion> live_version2 = 931 scoped_refptr<ServiceWorkerVersion> live_version2 =
932 new ServiceWorkerVersion( 932 new ServiceWorkerVersion(
933 live_registration2, kVersionId2, context_ptr_); 933 live_registration2, kScript2, kVersionId2, context_ptr_);
934 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); 934 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED);
935 live_registration2->SetWaitingVersion(live_version2); 935 live_registration2->SetWaitingVersion(live_version2);
936 936
937 // Registration for "/scope/foobar". 937 // Registration for "/scope/foobar".
938 const GURL kScope3("http://www.example.com/scope/foobar"); 938 const GURL kScope3("http://www.example.com/scope/foobar");
939 const GURL kScript3("http://www.example.com/script3.js"); 939 const GURL kScript3("http://www.example.com/script3.js");
940 const int64 kRegistrationId3 = 3; 940 const int64 kRegistrationId3 = 3;
941 const int64 kVersionId3 = 3; 941 const int64 kVersionId3 = 3;
942 scoped_refptr<ServiceWorkerRegistration> live_registration3 = 942 scoped_refptr<ServiceWorkerRegistration> live_registration3 =
943 new ServiceWorkerRegistration( 943 new ServiceWorkerRegistration(
944 kScope3, kScript3, kRegistrationId3, context_ptr_); 944 kScope3, kRegistrationId3, context_ptr_);
945 scoped_refptr<ServiceWorkerVersion> live_version3 = 945 scoped_refptr<ServiceWorkerVersion> live_version3 =
946 new ServiceWorkerVersion( 946 new ServiceWorkerVersion(
947 live_registration3, kVersionId3, context_ptr_); 947 live_registration3, kScript3, kVersionId3, context_ptr_);
948 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); 948 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED);
949 live_registration3->SetWaitingVersion(live_version3); 949 live_registration3->SetWaitingVersion(live_version3);
950 950
951 // Notify storage of they being installed. 951 // Notify storage of they being installed.
952 storage()->NotifyInstallingRegistration(live_registration1); 952 storage()->NotifyInstallingRegistration(live_registration1);
953 storage()->NotifyInstallingRegistration(live_registration2); 953 storage()->NotifyInstallingRegistration(live_registration2);
954 storage()->NotifyInstallingRegistration(live_registration3); 954 storage()->NotifyInstallingRegistration(live_registration3);
955 955
956 // Find a registration among installing ones. 956 // Find a registration among installing ones.
957 EXPECT_EQ(SERVICE_WORKER_OK, 957 EXPECT_EQ(SERVICE_WORKER_OK,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 are_equal = true; 1037 are_equal = true;
1038 storage()->CompareScriptResources( 1038 storage()->CompareScriptResources(
1039 5, 6, 1039 5, 6,
1040 base::Bind(&OnCompareComplete, &status, &are_equal)); 1040 base::Bind(&OnCompareComplete, &status, &are_equal));
1041 base::RunLoop().RunUntilIdle(); 1041 base::RunLoop().RunUntilIdle();
1042 EXPECT_EQ(SERVICE_WORKER_OK, status); 1042 EXPECT_EQ(SERVICE_WORKER_OK, status);
1043 EXPECT_FALSE(are_equal); 1043 EXPECT_FALSE(are_equal);
1044 } 1044 }
1045 1045
1046 } // namespace content 1046 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698