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

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

Issue 1656933003: Add origins argument to registerForeignFetchScopes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 10 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 EXPECT_EQ(expected.registration_id, actual.registration_id); 63 EXPECT_EQ(expected.registration_id, actual.registration_id);
64 EXPECT_EQ(expected.scope, actual.scope); 64 EXPECT_EQ(expected.scope, actual.scope);
65 EXPECT_EQ(expected.script, actual.script); 65 EXPECT_EQ(expected.script, actual.script);
66 EXPECT_EQ(expected.version_id, actual.version_id); 66 EXPECT_EQ(expected.version_id, actual.version_id);
67 EXPECT_EQ(expected.is_active, actual.is_active); 67 EXPECT_EQ(expected.is_active, actual.is_active);
68 EXPECT_EQ(expected.has_fetch_handler, actual.has_fetch_handler); 68 EXPECT_EQ(expected.has_fetch_handler, actual.has_fetch_handler);
69 EXPECT_EQ(expected.last_update_check, actual.last_update_check); 69 EXPECT_EQ(expected.last_update_check, actual.last_update_check);
70 EXPECT_EQ(expected.resources_total_size_bytes, 70 EXPECT_EQ(expected.resources_total_size_bytes,
71 actual.resources_total_size_bytes); 71 actual.resources_total_size_bytes);
72 EXPECT_EQ(expected.foreign_fetch_scopes, actual.foreign_fetch_scopes); 72 EXPECT_EQ(expected.foreign_fetch_scopes, actual.foreign_fetch_scopes);
73 EXPECT_EQ(expected.foreign_fetch_origins, actual.foreign_fetch_origins);
73 } 74 }
74 75
75 void VerifyResourceRecords(const std::vector<Resource>& expected, 76 void VerifyResourceRecords(const std::vector<Resource>& expected,
76 const std::vector<Resource>& actual) { 77 const std::vector<Resource>& actual) {
77 ASSERT_EQ(expected.size(), actual.size()); 78 ASSERT_EQ(expected.size(), actual.size());
78 for (size_t i = 0; i < expected.size(); ++i) { 79 for (size_t i = 0; i < expected.size(); ++i) {
79 EXPECT_EQ(expected[i].resource_id, actual[i].resource_id); 80 EXPECT_EQ(expected[i].resource_id, actual[i].resource_id);
80 EXPECT_EQ(expected[i].url, actual[i].url); 81 EXPECT_EQ(expected[i].url, actual[i].url);
81 EXPECT_EQ(expected[i].size_bytes, actual[i].size_bytes); 82 EXPECT_EQ(expected[i].size_bytes, actual[i].size_bytes);
82 } 83 }
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 752 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
752 753
753 GURL origin("http://example.com"); 754 GURL origin("http://example.com");
754 RegistrationData data; 755 RegistrationData data;
755 data.registration_id = 100; 756 data.registration_id = 100;
756 data.scope = URL(origin, "/foo"); 757 data.scope = URL(origin, "/foo");
757 data.script = URL(origin, "/script.js"); 758 data.script = URL(origin, "/script.js");
758 data.version_id = 200; 759 data.version_id = 200;
759 data.resources_total_size_bytes = 10 + 11; 760 data.resources_total_size_bytes = 10 + 11;
760 data.foreign_fetch_scopes.push_back(URL(origin, "/foo")); 761 data.foreign_fetch_scopes.push_back(URL(origin, "/foo"));
762 data.foreign_fetch_origins.push_back(GURL("https://chromium.org"));
761 763
762 std::vector<Resource> resources1; 764 std::vector<Resource> resources1;
763 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 10)); 765 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 10));
764 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 11)); 766 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 11));
765 767
766 ServiceWorkerDatabase::RegistrationData deleted_version; 768 ServiceWorkerDatabase::RegistrationData deleted_version;
767 deleted_version.version_id = 222; // Dummy inital value 769 deleted_version.version_id = 222; // Dummy inital value
768 std::vector<int64_t> newly_purgeable_resources; 770 std::vector<int64_t> newly_purgeable_resources;
769 771
770 EXPECT_EQ( 772 EXPECT_EQ(
771 ServiceWorkerDatabase::STATUS_OK, 773 ServiceWorkerDatabase::STATUS_OK,
772 database->WriteRegistration( 774 database->WriteRegistration(
773 data, resources1, &deleted_version, &newly_purgeable_resources)); 775 data, resources1, &deleted_version, &newly_purgeable_resources));
774 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version.version_id); 776 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version.version_id);
775 EXPECT_TRUE(newly_purgeable_resources.empty()); 777 EXPECT_TRUE(newly_purgeable_resources.empty());
776 778
777 // Make sure that the registration and resource records are stored. 779 // Make sure that the registration and resource records are stored.
778 RegistrationData data_out; 780 RegistrationData data_out;
779 std::vector<Resource> resources_out; 781 std::vector<Resource> resources_out;
780 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration( 782 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration(
781 data.registration_id, origin, &data_out, &resources_out)); 783 data.registration_id, origin, &data_out, &resources_out));
782 VerifyRegistrationData(data, data_out); 784 VerifyRegistrationData(data, data_out);
783 VerifyResourceRecords(resources1, resources_out); 785 VerifyResourceRecords(resources1, resources_out);
784 786
785 // Update the registration. 787 // Update the registration.
786 RegistrationData updated_data = data; 788 RegistrationData updated_data = data;
787 updated_data.version_id = data.version_id + 1; 789 updated_data.version_id = data.version_id + 1;
788 updated_data.resources_total_size_bytes = 12 + 13; 790 updated_data.resources_total_size_bytes = 12 + 13;
789 updated_data.foreign_fetch_scopes.clear(); 791 updated_data.foreign_fetch_scopes.clear();
792 updated_data.foreign_fetch_origins.push_back(GURL("https://example.com"));
790 std::vector<Resource> resources2; 793 std::vector<Resource> resources2;
791 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12)); 794 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12));
792 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13)); 795 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13));
793 796
794 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 797 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
795 database->WriteRegistration(updated_data, 798 database->WriteRegistration(updated_data,
796 resources2, 799 resources2,
797 &deleted_version, 800 &deleted_version,
798 &newly_purgeable_resources)); 801 &newly_purgeable_resources));
799 EXPECT_EQ(data.version_id, deleted_version.version_id); 802 EXPECT_EQ(data.version_id, deleted_version.version_id);
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 &deleted_version, 1720 &deleted_version,
1718 &newly_purgeable_resources)); 1721 &newly_purgeable_resources));
1719 1722
1720 origins.clear(); 1723 origins.clear();
1721 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1724 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1722 database->GetOriginsWithForeignFetchRegistrations(&origins)); 1725 database->GetOriginsWithForeignFetchRegistrations(&origins));
1723 EXPECT_EQ(0U, origins.size()); 1726 EXPECT_EQ(0U, origins.size());
1724 } 1727 }
1725 1728
1726 } // namespace content 1729 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698