Index: content/browser/service_worker/service_worker_database_unittest.cc |
diff --git a/content/browser/service_worker/service_worker_database_unittest.cc b/content/browser/service_worker/service_worker_database_unittest.cc |
index e654e88684cea133e535eb5212c1a546e2546e5b..413d9091b4fe0ee31eeaf4ca81a508338128ed1b 100644 |
--- a/content/browser/service_worker/service_worker_database_unittest.cc |
+++ b/content/browser/service_worker/service_worker_database_unittest.cc |
@@ -1094,6 +1094,84 @@ TEST(ServiceWorkerDatabaseTest, UserData_Basic) { |
EXPECT_EQ("data4", user_data_out[0]); |
} |
+TEST(ServiceWorkerDatabaseTest, |
+ UserData_ReadUserDataForAllRegistrationsByKeyPrefix) { |
+ std::unique_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); |
+ const GURL kOrigin("http://example.com"); |
+ |
+ // Add registration 1. |
+ RegistrationData data1; |
+ data1.registration_id = 100; |
+ data1.scope = URL(kOrigin, "/foo"); |
+ data1.script = URL(kOrigin, "/script1.js"); |
+ data1.version_id = 200; |
+ data1.resources_total_size_bytes = 100; |
+ std::vector<Resource> resources1; |
+ resources1.push_back(CreateResource(1, data1.script, 100)); |
+ |
+ // Add registration 2. |
+ RegistrationData data2; |
+ data2.registration_id = 101; |
+ data2.scope = URL(kOrigin, "/bar"); |
+ data2.script = URL(kOrigin, "/script2.js"); |
+ data2.version_id = 201; |
+ data2.resources_total_size_bytes = 200; |
+ std::vector<Resource> resources2; |
+ resources2.push_back(CreateResource(2, data2.script, 200)); |
+ |
+ ServiceWorkerDatabase::RegistrationData deleted_version; |
+ std::vector<int64_t> newly_purgeable_resources; |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteRegistration(data1, resources1, &deleted_version, |
+ &newly_purgeable_resources)); |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteRegistration(data2, resources2, &deleted_version, |
+ &newly_purgeable_resources)); |
+ |
+ // Write user data associated with the registration1. |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteUserData(data1.registration_id, kOrigin, |
+ {{"key_prefix:key1", "value1"}})); |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteUserData(data1.registration_id, kOrigin, |
+ {{"key_prefix:key2", "value2"}})); |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteUserData(data1.registration_id, kOrigin, |
+ {{"key_prefix:key3", "value3"}})); |
+ |
+ // Write user data associated with the registration2. |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteUserData(data2.registration_id, kOrigin, |
+ {{"key_prefix:key1", "value1"}})); |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteUserData(data2.registration_id, kOrigin, |
+ {{"key_prefix:key2", "value2"}})); |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteUserData(data2.registration_id, kOrigin, |
+ {{"another_key_prefix:key1", "value1"}})); |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->WriteUserData(data2.registration_id, kOrigin, |
+ {{"another_key_prefix:key2", "value2"}})); |
+ |
+ // Get all registrations with user data by key prefix. |
+ std::vector<std::pair<int64_t, std::string>> user_data_list; |
+ ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
+ database->ReadUserDataForAllRegistrationsByKeyPrefix( |
+ "key_prefix:", &user_data_list)); |
+ ASSERT_EQ(5u, user_data_list.size()); |
+ |
+ EXPECT_EQ(data1.registration_id, user_data_list[0].first); |
+ EXPECT_EQ("value1", user_data_list[0].second); |
+ EXPECT_EQ(data2.registration_id, user_data_list[1].first); |
+ EXPECT_EQ("value1", user_data_list[1].second); |
+ EXPECT_EQ(data1.registration_id, user_data_list[2].first); |
+ EXPECT_EQ("value2", user_data_list[2].second); |
+ EXPECT_EQ(data2.registration_id, user_data_list[3].first); |
+ EXPECT_EQ("value2", user_data_list[3].second); |
+ EXPECT_EQ(data1.registration_id, user_data_list[4].first); |
+ EXPECT_EQ("value3", user_data_list[4].second); |
+} |
+ |
TEST(ServiceWorkerDatabaseTest, UserData_DataIsolation) { |
std::unique_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); |
const GURL kOrigin("http://example.com"); |