OLD | NEW |
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 ServiceWorkerDatabase::STATUS_OK, | 169 ServiceWorkerDatabase::STATUS_OK, |
170 database->WriteRegistration( | 170 database->WriteRegistration( |
171 data1, resources, &deleted_version_id, &newly_purgeable_resources)); | 171 data1, resources, &deleted_version_id, &newly_purgeable_resources)); |
172 | 172 |
173 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds( | 173 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds( |
174 &ids.reg_id, &ids.ver_id, &ids.res_id)); | 174 &ids.reg_id, &ids.ver_id, &ids.res_id)); |
175 EXPECT_EQ(101, ids.reg_id); | 175 EXPECT_EQ(101, ids.reg_id); |
176 EXPECT_EQ(201, ids.ver_id); | 176 EXPECT_EQ(201, ids.ver_id); |
177 EXPECT_EQ(0, ids.res_id); | 177 EXPECT_EQ(0, ids.res_id); |
178 | 178 |
| 179 // Writing uncommitted resources bumps the next available id. |
| 180 const int64 kUncommittedIds[] = {0, 1, 3, 5, 6, 10}; |
| 181 EXPECT_EQ( |
| 182 ServiceWorkerDatabase::STATUS_OK, |
| 183 database->WriteUncommittedResourceIds(std::set<int64>( |
| 184 kUncommittedIds, kUncommittedIds + arraysize(kUncommittedIds)))); |
| 185 EXPECT_EQ( |
| 186 ServiceWorkerDatabase::STATUS_OK, |
| 187 database->GetNextAvailableIds(&ids.reg_id, &ids.ver_id, &ids.res_id)); |
| 188 EXPECT_EQ(101, ids.reg_id); |
| 189 EXPECT_EQ(201, ids.ver_id); |
| 190 EXPECT_EQ(11, ids.res_id); |
| 191 |
| 192 // Writing purgeable resources bumps the next available id. |
| 193 const int64 kPurgeableIds[] = {4, 12, 16, 17, 20}; |
| 194 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
| 195 database->WriteUncommittedResourceIds(std::set<int64>( |
| 196 kPurgeableIds, kPurgeableIds + arraysize(kPurgeableIds)))); |
| 197 EXPECT_EQ( |
| 198 ServiceWorkerDatabase::STATUS_OK, |
| 199 database->GetNextAvailableIds(&ids.reg_id, &ids.ver_id, &ids.res_id)); |
| 200 EXPECT_EQ(101, ids.reg_id); |
| 201 EXPECT_EQ(201, ids.ver_id); |
| 202 EXPECT_EQ(21, ids.res_id); |
| 203 |
179 // Writing a registration whose ids are lower than the stored ones should not | 204 // Writing a registration whose ids are lower than the stored ones should not |
180 // bump the next available ids. | 205 // bump the next available ids. |
181 RegistrationData data2; | 206 RegistrationData data2; |
182 data2.registration_id = 10; | 207 data2.registration_id = 10; |
183 data2.scope = URL(origin, "/bar"); | 208 data2.scope = URL(origin, "/bar"); |
184 data2.script = URL(origin, "/script2.js"); | 209 data2.script = URL(origin, "/script2.js"); |
185 data2.version_id = 20; | 210 data2.version_id = 20; |
186 ASSERT_EQ( | 211 ASSERT_EQ( |
187 ServiceWorkerDatabase::STATUS_OK, | 212 ServiceWorkerDatabase::STATUS_OK, |
188 database->WriteRegistration( | 213 database->WriteRegistration( |
189 data2, resources, &deleted_version_id, &newly_purgeable_resources)); | 214 data2, resources, &deleted_version_id, &newly_purgeable_resources)); |
190 | 215 |
| 216 // Same with resources. |
| 217 int64 kLowResourceId = 15; |
| 218 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
| 219 database->WriteUncommittedResourceIds( |
| 220 std::set<int64>(&kLowResourceId, &kLowResourceId + 1))); |
| 221 |
191 // Close and reopen the database to verify the stored values. | 222 // Close and reopen the database to verify the stored values. |
192 database.reset(CreateDatabase(database_dir.path())); | 223 database.reset(CreateDatabase(database_dir.path())); |
193 | 224 |
194 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds( | 225 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds( |
195 &ids.reg_id, &ids.ver_id, &ids.res_id)); | 226 &ids.reg_id, &ids.ver_id, &ids.res_id)); |
196 EXPECT_EQ(101, ids.reg_id); | 227 EXPECT_EQ(101, ids.reg_id); |
197 EXPECT_EQ(201, ids.ver_id); | 228 EXPECT_EQ(201, ids.ver_id); |
198 EXPECT_EQ(0, ids.res_id); | 229 EXPECT_EQ(21, ids.res_id); |
199 } | 230 } |
200 | 231 |
201 TEST(ServiceWorkerDatabaseTest, GetOriginsWithRegistrations) { | 232 TEST(ServiceWorkerDatabaseTest, GetOriginsWithRegistrations) { |
202 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); | 233 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); |
203 | 234 |
204 std::set<GURL> origins; | 235 std::set<GURL> origins; |
205 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 236 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
206 database->GetOriginsWithRegistrations(&origins)); | 237 database->GetOriginsWithRegistrations(&origins)); |
207 EXPECT_TRUE(origins.empty()); | 238 EXPECT_TRUE(origins.empty()); |
208 | 239 |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 CreateDatabase(database_dir.path())); | 1038 CreateDatabase(database_dir.path())); |
1008 | 1039 |
1009 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true)); | 1040 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true)); |
1010 ASSERT_TRUE(base::DirectoryExists(database_dir.path())); | 1041 ASSERT_TRUE(base::DirectoryExists(database_dir.path())); |
1011 | 1042 |
1012 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->DestroyDatabase()); | 1043 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->DestroyDatabase()); |
1013 ASSERT_FALSE(base::DirectoryExists(database_dir.path())); | 1044 ASSERT_FALSE(base::DirectoryExists(database_dir.path())); |
1014 } | 1045 } |
1015 | 1046 |
1016 } // namespace content | 1047 } // namespace content |
OLD | NEW |