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

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

Issue 355163003: Don't prematurely delete script resources when registration is deleted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: redesign Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/service_worker/service_worker_database.h" 5 #include "content/browser/service_worker/service_worker_database.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 origins.clear(); 246 origins.clear();
247 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 247 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
248 database->GetOriginsWithRegistrations(&origins)); 248 database->GetOriginsWithRegistrations(&origins));
249 EXPECT_EQ(3U, origins.size()); 249 EXPECT_EQ(3U, origins.size());
250 EXPECT_TRUE(ContainsKey(origins, origin1)); 250 EXPECT_TRUE(ContainsKey(origins, origin1));
251 EXPECT_TRUE(ContainsKey(origins, origin2)); 251 EXPECT_TRUE(ContainsKey(origins, origin2));
252 EXPECT_TRUE(ContainsKey(origins, origin3)); 252 EXPECT_TRUE(ContainsKey(origins, origin3));
253 253
254 // |origin3| has another registration, so should not remove it from the 254 // |origin3| has another registration, so should not remove it from the
255 // unique origin list. 255 // unique origin list.
256 int64 version_id;
256 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 257 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
257 database->DeleteRegistration(data4.registration_id, origin3, 258 database->DeleteRegistration(data4.registration_id,
259 origin3,
260 &version_id,
258 &newly_purgeable_resources)); 261 &newly_purgeable_resources));
259 262
260 origins.clear(); 263 origins.clear();
261 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 264 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
262 database->GetOriginsWithRegistrations(&origins)); 265 database->GetOriginsWithRegistrations(&origins));
263 EXPECT_EQ(3U, origins.size()); 266 EXPECT_EQ(3U, origins.size());
264 EXPECT_TRUE(ContainsKey(origins, origin1)); 267 EXPECT_TRUE(ContainsKey(origins, origin1));
265 EXPECT_TRUE(ContainsKey(origins, origin2)); 268 EXPECT_TRUE(ContainsKey(origins, origin2));
266 EXPECT_TRUE(ContainsKey(origins, origin3)); 269 EXPECT_TRUE(ContainsKey(origins, origin3));
267 270
268 // |origin3| should be removed from the unique origin list. 271 // |origin3| should be removed from the unique origin list.
269 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 272 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
270 database->DeleteRegistration(data3.registration_id, origin3, 273 database->DeleteRegistration(data3.registration_id,
274 origin3,
275 &version_id,
271 &newly_purgeable_resources)); 276 &newly_purgeable_resources));
272 277
273 origins.clear(); 278 origins.clear();
274 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 279 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
275 database->GetOriginsWithRegistrations(&origins)); 280 database->GetOriginsWithRegistrations(&origins));
276 EXPECT_EQ(2U, origins.size()); 281 EXPECT_EQ(2U, origins.size());
277 EXPECT_TRUE(ContainsKey(origins, origin1)); 282 EXPECT_TRUE(ContainsKey(origins, origin1));
278 EXPECT_TRUE(ContainsKey(origins, origin2)); 283 EXPECT_TRUE(ContainsKey(origins, origin2));
279 } 284 }
280 285
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 data.registration_id, origin, &data_out, &resources_out)); 443 data.registration_id, origin, &data_out, &resources_out));
439 VerifyRegistrationData(data, data_out); 444 VerifyRegistrationData(data, data_out);
440 VerifyResourceRecords(resources, resources_out); 445 VerifyResourceRecords(resources, resources_out);
441 446
442 // Make sure that the resource is removed from the uncommitted list. 447 // Make sure that the resource is removed from the uncommitted list.
443 uncommitted_ids_out.clear(); 448 uncommitted_ids_out.clear();
444 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 449 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
445 database->GetUncommittedResourceIds(&uncommitted_ids_out)); 450 database->GetUncommittedResourceIds(&uncommitted_ids_out));
446 EXPECT_TRUE(uncommitted_ids_out.empty()); 451 EXPECT_TRUE(uncommitted_ids_out.empty());
447 452
453 int64 version_id;
448 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 454 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
449 database->DeleteRegistration(data.registration_id, origin, 455 database->DeleteRegistration(data.registration_id,
456 origin,
457 &version_id,
450 &newly_purgeable_resources)); 458 &newly_purgeable_resources));
451 ASSERT_EQ(resources.size(), newly_purgeable_resources.size()); 459 ASSERT_EQ(resources.size(), newly_purgeable_resources.size());
452 for (size_t i = 0; i < resources.size(); ++i) 460 for (size_t i = 0; i < resources.size(); ++i)
453 EXPECT_EQ(newly_purgeable_resources[i], resources[i].resource_id); 461 EXPECT_EQ(newly_purgeable_resources[i], resources[i].resource_id);
454 462
455 // Make sure that the registration and resource records are gone. 463 // Make sure that the registration and resource records are gone.
456 resources_out.clear(); 464 resources_out.clear();
457 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 465 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
458 database->ReadRegistration( 466 database->ReadRegistration(
459 data.registration_id, origin, &data_out, &resources_out)); 467 data.registration_id, origin, &data_out, &resources_out));
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 data2.registration_id, origin, &data_out, &resources_out)); 582 data2.registration_id, origin, &data_out, &resources_out));
575 VerifyRegistrationData(data2, data_out); 583 VerifyRegistrationData(data2, data_out);
576 VerifyResourceRecords(resources2, resources_out); 584 VerifyResourceRecords(resources2, resources_out);
577 585
578 std::set<int64> purgeable_ids_out; 586 std::set<int64> purgeable_ids_out;
579 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 587 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
580 database->GetPurgeableResourceIds(&purgeable_ids_out)); 588 database->GetPurgeableResourceIds(&purgeable_ids_out));
581 EXPECT_TRUE(purgeable_ids_out.empty()); 589 EXPECT_TRUE(purgeable_ids_out.empty());
582 590
583 // Delete registration1. 591 // Delete registration1.
592 int64 version_id;
584 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 593 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
585 database->DeleteRegistration(data1.registration_id, origin, 594 database->DeleteRegistration(data1.registration_id,
595 origin,
596 &version_id,
586 &newly_purgeable_resources)); 597 &newly_purgeable_resources));
587 598
588 // Make sure that registration1 is gone. 599 // Make sure that registration1 is gone.
589 resources_out.clear(); 600 resources_out.clear();
590 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 601 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
591 database->ReadRegistration( 602 database->ReadRegistration(
592 data1.registration_id, origin, &data_out, &resources_out)); 603 data1.registration_id, origin, &data_out, &resources_out));
593 EXPECT_TRUE(resources_out.empty()); 604 EXPECT_TRUE(resources_out.empty());
594 605
595 purgeable_ids_out.clear(); 606 purgeable_ids_out.clear();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 resources_out.clear(); 656 resources_out.clear();
646 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 657 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
647 database->ReadRegistration( 658 database->ReadRegistration(
648 data.registration_id, origin, &data_out, &resources_out)); 659 data.registration_id, origin, &data_out, &resources_out));
649 RegistrationData expected_data = data; 660 RegistrationData expected_data = data;
650 expected_data.is_active = true; 661 expected_data.is_active = true;
651 VerifyRegistrationData(expected_data, data_out); 662 VerifyRegistrationData(expected_data, data_out);
652 EXPECT_TRUE(resources_out.empty()); 663 EXPECT_TRUE(resources_out.empty());
653 664
654 // Delete the registration. 665 // Delete the registration.
666 int64 version_id;
655 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 667 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
656 database->DeleteRegistration(data.registration_id, origin, 668 database->DeleteRegistration(data.registration_id,
669 origin,
670 &version_id,
657 &newly_purgeable_resources)); 671 &newly_purgeable_resources));
658 672
659 // Should be false because the registration is gone. 673 // Should be false because the registration is gone.
660 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 674 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
661 database->UpdateVersionToActive(data.registration_id, origin)); 675 database->UpdateVersionToActive(data.registration_id, origin));
662 } 676 }
663 677
664 TEST(ServiceWorkerDatabaseTest, UpdateLastCheckTime) { 678 TEST(ServiceWorkerDatabaseTest, UpdateLastCheckTime) {
665 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 679 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
666 GURL origin("http://example.com"); 680 GURL origin("http://example.com");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 resources_out.clear(); 714 resources_out.clear();
701 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 715 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
702 database->ReadRegistration( 716 database->ReadRegistration(
703 data.registration_id, origin, &data_out, &resources_out)); 717 data.registration_id, origin, &data_out, &resources_out));
704 RegistrationData expected_data = data; 718 RegistrationData expected_data = data;
705 expected_data.last_update_check = updated_time; 719 expected_data.last_update_check = updated_time;
706 VerifyRegistrationData(expected_data, data_out); 720 VerifyRegistrationData(expected_data, data_out);
707 EXPECT_TRUE(resources_out.empty()); 721 EXPECT_TRUE(resources_out.empty());
708 722
709 // Delete the registration. 723 // Delete the registration.
724 int64 version_id;
710 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 725 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
711 database->DeleteRegistration(data.registration_id, origin, 726 database->DeleteRegistration(data.registration_id,
727 origin,
728 &version_id,
712 &newly_purgeable_resources)); 729 &newly_purgeable_resources));
713 730
714 // Should be false because the registration is gone. 731 // Should be false because the registration is gone.
715 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 732 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
716 database->UpdateLastCheckTime( 733 database->UpdateLastCheckTime(
717 data.registration_id, origin, base::Time::Now())); 734 data.registration_id, origin, base::Time::Now()));
718 } 735 }
719 736
720 TEST(ServiceWorkerDatabaseTest, UncommittedResourceIds) { 737 TEST(ServiceWorkerDatabaseTest, UncommittedResourceIds) {
721 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 738 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 CreateDatabase(database_dir.path())); 912 CreateDatabase(database_dir.path()));
896 913
897 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true)); 914 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true));
898 ASSERT_TRUE(base::DirectoryExists(database_dir.path())); 915 ASSERT_TRUE(base::DirectoryExists(database_dir.path()));
899 916
900 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->DestroyDatabase()); 917 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->DestroyDatabase());
901 ASSERT_FALSE(base::DirectoryExists(database_dir.path())); 918 ASSERT_FALSE(base::DirectoryExists(database_dir.path()));
902 } 919 }
903 920
904 } // namespace content 921 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698