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

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

Issue 672813002: [ServiceWorker] Added size deltas and total size computation for QuotaM. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Opening a new database does not write anything, so its schema version 113 // Opening a new database does not write anything, so its schema version
114 // should be 0. 114 // should be 0.
115 int64 db_version = -1; 115 int64 db_version = -1;
116 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 116 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
117 database->ReadDatabaseVersion(&db_version)); 117 database->ReadDatabaseVersion(&db_version));
118 EXPECT_EQ(0u, db_version); 118 EXPECT_EQ(0u, db_version);
119 119
120 // First writing triggers database initialization and bumps the schema 120 // First writing triggers database initialization and bumps the schema
121 // version. 121 // version.
122 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 122 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
123 int64 deleted_version_id; 123 ServiceWorkerDatabase::RegistrationData deleted_version;
124 std::vector<int64> newly_purgeable_resources; 124 std::vector<int64> newly_purgeable_resources;
125 ServiceWorkerDatabase::RegistrationData data; 125 ServiceWorkerDatabase::RegistrationData data;
126 ASSERT_EQ( 126 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
127 ServiceWorkerDatabase::STATUS_OK, 127 database->WriteRegistration(
128 database->WriteRegistration( 128 data, resources, &deleted_version, &newly_purgeable_resources));
129 data, resources, &deleted_version_id, &newly_purgeable_resources));
130 129
131 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 130 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
132 database->ReadDatabaseVersion(&db_version)); 131 database->ReadDatabaseVersion(&db_version));
133 EXPECT_LT(0, db_version); 132 EXPECT_LT(0, db_version);
134 } 133 }
135 134
136 TEST(ServiceWorkerDatabaseTest, GetNextAvailableIds) { 135 TEST(ServiceWorkerDatabaseTest, GetNextAvailableIds) {
137 base::ScopedTempDir database_dir; 136 base::ScopedTempDir database_dir;
138 ASSERT_TRUE(database_dir.CreateUniqueTempDir()); 137 ASSERT_TRUE(database_dir.CreateUniqueTempDir());
139 scoped_ptr<ServiceWorkerDatabase> database( 138 scoped_ptr<ServiceWorkerDatabase> database(
(...skipping 12 matching lines...) Expand all
152 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true)); 151 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true));
153 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds( 152 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds(
154 &ids.reg_id, &ids.ver_id, &ids.res_id)); 153 &ids.reg_id, &ids.ver_id, &ids.res_id));
155 EXPECT_EQ(0, ids.reg_id); 154 EXPECT_EQ(0, ids.reg_id);
156 EXPECT_EQ(0, ids.ver_id); 155 EXPECT_EQ(0, ids.ver_id);
157 EXPECT_EQ(0, ids.res_id); 156 EXPECT_EQ(0, ids.res_id);
158 157
159 // Writing a registration bumps the next available ids. 158 // Writing a registration bumps the next available ids.
160 std::vector<Resource> resources; 159 std::vector<Resource> resources;
161 RegistrationData data1; 160 RegistrationData data1;
162 int64 deleted_version_id; 161 ServiceWorkerDatabase::RegistrationData deleted_version;
163 std::vector<int64> newly_purgeable_resources; 162 std::vector<int64> newly_purgeable_resources;
164 data1.registration_id = 100; 163 data1.registration_id = 100;
165 data1.scope = URL(origin, "/foo"); 164 data1.scope = URL(origin, "/foo");
166 data1.script = URL(origin, "/script1.js"); 165 data1.script = URL(origin, "/script1.js");
167 data1.version_id = 200; 166 data1.version_id = 200;
168 ASSERT_EQ( 167 ASSERT_EQ(
169 ServiceWorkerDatabase::STATUS_OK, 168 ServiceWorkerDatabase::STATUS_OK,
170 database->WriteRegistration( 169 database->WriteRegistration(
171 data1, resources, &deleted_version_id, &newly_purgeable_resources)); 170 data1, resources, &deleted_version, &newly_purgeable_resources));
172 171
173 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds( 172 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds(
174 &ids.reg_id, &ids.ver_id, &ids.res_id)); 173 &ids.reg_id, &ids.ver_id, &ids.res_id));
175 EXPECT_EQ(101, ids.reg_id); 174 EXPECT_EQ(101, ids.reg_id);
176 EXPECT_EQ(201, ids.ver_id); 175 EXPECT_EQ(201, ids.ver_id);
177 EXPECT_EQ(0, ids.res_id); 176 EXPECT_EQ(0, ids.res_id);
178 177
179 // Writing uncommitted resources bumps the next available id. 178 // Writing uncommitted resources bumps the next available id.
180 const int64 kUncommittedIds[] = {0, 1, 3, 5, 6, 10}; 179 const int64 kUncommittedIds[] = {0, 1, 3, 5, 6, 10};
181 EXPECT_EQ( 180 EXPECT_EQ(
(...skipping 22 matching lines...) Expand all
204 // Writing a registration whose ids are lower than the stored ones should not 203 // Writing a registration whose ids are lower than the stored ones should not
205 // bump the next available ids. 204 // bump the next available ids.
206 RegistrationData data2; 205 RegistrationData data2;
207 data2.registration_id = 10; 206 data2.registration_id = 10;
208 data2.scope = URL(origin, "/bar"); 207 data2.scope = URL(origin, "/bar");
209 data2.script = URL(origin, "/script2.js"); 208 data2.script = URL(origin, "/script2.js");
210 data2.version_id = 20; 209 data2.version_id = 20;
211 ASSERT_EQ( 210 ASSERT_EQ(
212 ServiceWorkerDatabase::STATUS_OK, 211 ServiceWorkerDatabase::STATUS_OK,
213 database->WriteRegistration( 212 database->WriteRegistration(
214 data2, resources, &deleted_version_id, &newly_purgeable_resources)); 213 data2, resources, &deleted_version, &newly_purgeable_resources));
215 214
216 // Same with resources. 215 // Same with resources.
217 int64 kLowResourceId = 15; 216 int64 kLowResourceId = 15;
218 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 217 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
219 database->WriteUncommittedResourceIds( 218 database->WriteUncommittedResourceIds(
220 std::set<int64>(&kLowResourceId, &kLowResourceId + 1))); 219 std::set<int64>(&kLowResourceId, &kLowResourceId + 1)));
221 220
222 // Close and reopen the database to verify the stored values. 221 // Close and reopen the database to verify the stored values.
223 database.reset(CreateDatabase(database_dir.path())); 222 database.reset(CreateDatabase(database_dir.path()));
224 223
225 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds( 224 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->GetNextAvailableIds(
226 &ids.reg_id, &ids.ver_id, &ids.res_id)); 225 &ids.reg_id, &ids.ver_id, &ids.res_id));
227 EXPECT_EQ(101, ids.reg_id); 226 EXPECT_EQ(101, ids.reg_id);
228 EXPECT_EQ(201, ids.ver_id); 227 EXPECT_EQ(201, ids.ver_id);
229 EXPECT_EQ(21, ids.res_id); 228 EXPECT_EQ(21, ids.res_id);
230 } 229 }
231 230
232 TEST(ServiceWorkerDatabaseTest, GetOriginsWithRegistrations) { 231 TEST(ServiceWorkerDatabaseTest, GetOriginsWithRegistrations) {
233 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 232 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
234 233
235 std::set<GURL> origins; 234 std::set<GURL> origins;
236 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 235 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
237 database->GetOriginsWithRegistrations(&origins)); 236 database->GetOriginsWithRegistrations(&origins));
238 EXPECT_TRUE(origins.empty()); 237 EXPECT_TRUE(origins.empty());
239 238
240 std::vector<Resource> resources; 239 std::vector<Resource> resources;
241 int64 deleted_version_id; 240 ServiceWorkerDatabase::RegistrationData deleted_version;
242 std::vector<int64> newly_purgeable_resources; 241 std::vector<int64> newly_purgeable_resources;
243 242
244 GURL origin1("http://example.com"); 243 GURL origin1("http://example.com");
245 RegistrationData data1; 244 RegistrationData data1;
246 data1.registration_id = 123; 245 data1.registration_id = 123;
247 data1.scope = URL(origin1, "/foo"); 246 data1.scope = URL(origin1, "/foo");
248 data1.script = URL(origin1, "/script1.js"); 247 data1.script = URL(origin1, "/script1.js");
249 data1.version_id = 456; 248 data1.version_id = 456;
250 ASSERT_EQ( 249 ASSERT_EQ(
251 ServiceWorkerDatabase::STATUS_OK, 250 ServiceWorkerDatabase::STATUS_OK,
252 database->WriteRegistration( 251 database->WriteRegistration(
253 data1, resources, &deleted_version_id, &newly_purgeable_resources)); 252 data1, resources, &deleted_version, &newly_purgeable_resources));
254 253
255 GURL origin2("https://www.example.com"); 254 GURL origin2("https://www.example.com");
256 RegistrationData data2; 255 RegistrationData data2;
257 data2.registration_id = 234; 256 data2.registration_id = 234;
258 data2.scope = URL(origin2, "/bar"); 257 data2.scope = URL(origin2, "/bar");
259 data2.script = URL(origin2, "/script2.js"); 258 data2.script = URL(origin2, "/script2.js");
260 data2.version_id = 567; 259 data2.version_id = 567;
261 ASSERT_EQ( 260 ASSERT_EQ(
262 ServiceWorkerDatabase::STATUS_OK, 261 ServiceWorkerDatabase::STATUS_OK,
263 database->WriteRegistration( 262 database->WriteRegistration(
264 data2, resources, &deleted_version_id, &newly_purgeable_resources)); 263 data2, resources, &deleted_version, &newly_purgeable_resources));
265 264
266 GURL origin3("https://example.org"); 265 GURL origin3("https://example.org");
267 RegistrationData data3; 266 RegistrationData data3;
268 data3.registration_id = 345; 267 data3.registration_id = 345;
269 data3.scope = URL(origin3, "/hoge"); 268 data3.scope = URL(origin3, "/hoge");
270 data3.script = URL(origin3, "/script3.js"); 269 data3.script = URL(origin3, "/script3.js");
271 data3.version_id = 678; 270 data3.version_id = 678;
272 ASSERT_EQ( 271 ASSERT_EQ(
273 ServiceWorkerDatabase::STATUS_OK, 272 ServiceWorkerDatabase::STATUS_OK,
274 database->WriteRegistration( 273 database->WriteRegistration(
275 data3, resources, &deleted_version_id, &newly_purgeable_resources)); 274 data3, resources, &deleted_version, &newly_purgeable_resources));
276 275
277 // |origin3| has two registrations. 276 // |origin3| has two registrations.
278 RegistrationData data4; 277 RegistrationData data4;
279 data4.registration_id = 456; 278 data4.registration_id = 456;
280 data4.scope = URL(origin3, "/fuga"); 279 data4.scope = URL(origin3, "/fuga");
281 data4.script = URL(origin3, "/script4.js"); 280 data4.script = URL(origin3, "/script4.js");
282 data4.version_id = 789; 281 data4.version_id = 789;
283 ASSERT_EQ( 282 ASSERT_EQ(
284 ServiceWorkerDatabase::STATUS_OK, 283 ServiceWorkerDatabase::STATUS_OK,
285 database->WriteRegistration( 284 database->WriteRegistration(
286 data4, resources, &deleted_version_id, &newly_purgeable_resources)); 285 data4, resources, &deleted_version, &newly_purgeable_resources));
287 286
288 origins.clear(); 287 origins.clear();
289 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 288 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
290 database->GetOriginsWithRegistrations(&origins)); 289 database->GetOriginsWithRegistrations(&origins));
291 EXPECT_EQ(3U, origins.size()); 290 EXPECT_EQ(3U, origins.size());
292 EXPECT_TRUE(ContainsKey(origins, origin1)); 291 EXPECT_TRUE(ContainsKey(origins, origin1));
293 EXPECT_TRUE(ContainsKey(origins, origin2)); 292 EXPECT_TRUE(ContainsKey(origins, origin2));
294 EXPECT_TRUE(ContainsKey(origins, origin3)); 293 EXPECT_TRUE(ContainsKey(origins, origin3));
295 294
296 // |origin3| has another registration, so should not remove it from the 295 // |origin3| has another registration, so should not remove it from the
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 GURL origin1("http://example.com"); 330 GURL origin1("http://example.com");
332 GURL origin2("https://www.example.com"); 331 GURL origin2("https://www.example.com");
333 GURL origin3("https://example.org"); 332 GURL origin3("https://example.org");
334 333
335 std::vector<RegistrationData> registrations; 334 std::vector<RegistrationData> registrations;
336 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 335 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
337 database->GetRegistrationsForOrigin(origin1, &registrations)); 336 database->GetRegistrationsForOrigin(origin1, &registrations));
338 EXPECT_TRUE(registrations.empty()); 337 EXPECT_TRUE(registrations.empty());
339 338
340 std::vector<Resource> resources; 339 std::vector<Resource> resources;
341 int64 deleted_version_id; 340 ServiceWorkerDatabase::RegistrationData deleted_version;
342 std::vector<int64> newly_purgeable_resources; 341 std::vector<int64> newly_purgeable_resources;
343 342
344 RegistrationData data1; 343 RegistrationData data1;
345 data1.registration_id = 100; 344 data1.registration_id = 100;
346 data1.scope = URL(origin1, "/foo"); 345 data1.scope = URL(origin1, "/foo");
347 data1.script = URL(origin1, "/script1.js"); 346 data1.script = URL(origin1, "/script1.js");
348 data1.version_id = 1000; 347 data1.version_id = 1000;
349 ASSERT_EQ( 348 ASSERT_EQ(
350 ServiceWorkerDatabase::STATUS_OK, 349 ServiceWorkerDatabase::STATUS_OK,
351 database->WriteRegistration( 350 database->WriteRegistration(
352 data1, resources, &deleted_version_id, &newly_purgeable_resources)); 351 data1, resources, &deleted_version, &newly_purgeable_resources));
353 352
354 RegistrationData data2; 353 RegistrationData data2;
355 data2.registration_id = 200; 354 data2.registration_id = 200;
356 data2.scope = URL(origin2, "/bar"); 355 data2.scope = URL(origin2, "/bar");
357 data2.script = URL(origin2, "/script2.js"); 356 data2.script = URL(origin2, "/script2.js");
358 data2.version_id = 2000; 357 data2.version_id = 2000;
359 ASSERT_EQ( 358 ASSERT_EQ(
360 ServiceWorkerDatabase::STATUS_OK, 359 ServiceWorkerDatabase::STATUS_OK,
361 database->WriteRegistration( 360 database->WriteRegistration(
362 data2, resources, &deleted_version_id, &newly_purgeable_resources)); 361 data2, resources, &deleted_version, &newly_purgeable_resources));
363 362
364 RegistrationData data3; 363 RegistrationData data3;
365 data3.registration_id = 300; 364 data3.registration_id = 300;
366 data3.scope = URL(origin3, "/hoge"); 365 data3.scope = URL(origin3, "/hoge");
367 data3.script = URL(origin3, "/script3.js"); 366 data3.script = URL(origin3, "/script3.js");
368 data3.version_id = 3000; 367 data3.version_id = 3000;
369 ASSERT_EQ( 368 ASSERT_EQ(
370 ServiceWorkerDatabase::STATUS_OK, 369 ServiceWorkerDatabase::STATUS_OK,
371 database->WriteRegistration( 370 database->WriteRegistration(
372 data3, resources, &deleted_version_id, &newly_purgeable_resources)); 371 data3, resources, &deleted_version, &newly_purgeable_resources));
373 372
374 // |origin3| has two registrations. 373 // |origin3| has two registrations.
375 RegistrationData data4; 374 RegistrationData data4;
376 data4.registration_id = 400; 375 data4.registration_id = 400;
377 data4.scope = URL(origin3, "/fuga"); 376 data4.scope = URL(origin3, "/fuga");
378 data4.script = URL(origin3, "/script4.js"); 377 data4.script = URL(origin3, "/script4.js");
379 data4.version_id = 4000; 378 data4.version_id = 4000;
380 ASSERT_EQ( 379 ASSERT_EQ(
381 ServiceWorkerDatabase::STATUS_OK, 380 ServiceWorkerDatabase::STATUS_OK,
382 database->WriteRegistration( 381 database->WriteRegistration(
383 data4, resources, &deleted_version_id, &newly_purgeable_resources)); 382 data4, resources, &deleted_version, &newly_purgeable_resources));
384 383
385 registrations.clear(); 384 registrations.clear();
386 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 385 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
387 database->GetRegistrationsForOrigin(origin3, &registrations)); 386 database->GetRegistrationsForOrigin(origin3, &registrations));
388 EXPECT_EQ(2U, registrations.size()); 387 EXPECT_EQ(2U, registrations.size());
389 VerifyRegistrationData(data3, registrations[0]); 388 VerifyRegistrationData(data3, registrations[0]);
390 VerifyRegistrationData(data4, registrations[1]); 389 VerifyRegistrationData(data4, registrations[1]);
391 } 390 }
392 391
393 TEST(ServiceWorkerDatabaseTest, GetAllRegistrations) { 392 TEST(ServiceWorkerDatabaseTest, GetAllRegistrations) {
394 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 393 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
395 394
396 std::vector<RegistrationData> registrations; 395 std::vector<RegistrationData> registrations;
397 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 396 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
398 database->GetAllRegistrations(&registrations)); 397 database->GetAllRegistrations(&registrations));
399 EXPECT_TRUE(registrations.empty()); 398 EXPECT_TRUE(registrations.empty());
400 399
401 std::vector<Resource> resources; 400 std::vector<Resource> resources;
402 int64 deleted_version_id; 401 ServiceWorkerDatabase::RegistrationData deleted_version;
403 std::vector<int64> newly_purgeable_resources; 402 std::vector<int64> newly_purgeable_resources;
404 403
405 GURL origin1("http://www1.example.com"); 404 GURL origin1("http://www1.example.com");
406 RegistrationData data1; 405 RegistrationData data1;
407 data1.registration_id = 100; 406 data1.registration_id = 100;
408 data1.scope = URL(origin1, "/foo"); 407 data1.scope = URL(origin1, "/foo");
409 data1.script = URL(origin1, "/script1.js"); 408 data1.script = URL(origin1, "/script1.js");
410 data1.version_id = 1000; 409 data1.version_id = 1000;
411 ASSERT_EQ( 410 ASSERT_EQ(
412 ServiceWorkerDatabase::STATUS_OK, 411 ServiceWorkerDatabase::STATUS_OK,
413 database->WriteRegistration( 412 database->WriteRegistration(
414 data1, resources, &deleted_version_id, &newly_purgeable_resources)); 413 data1, resources, &deleted_version, &newly_purgeable_resources));
415 414
416 GURL origin2("http://www2.example.com"); 415 GURL origin2("http://www2.example.com");
417 RegistrationData data2; 416 RegistrationData data2;
418 data2.registration_id = 200; 417 data2.registration_id = 200;
419 data2.scope = URL(origin2, "/bar"); 418 data2.scope = URL(origin2, "/bar");
420 data2.script = URL(origin2, "/script2.js"); 419 data2.script = URL(origin2, "/script2.js");
421 data2.version_id = 2000; 420 data2.version_id = 2000;
422 ASSERT_EQ( 421 ASSERT_EQ(
423 ServiceWorkerDatabase::STATUS_OK, 422 ServiceWorkerDatabase::STATUS_OK,
424 database->WriteRegistration( 423 database->WriteRegistration(
425 data2, resources, &deleted_version_id, &newly_purgeable_resources)); 424 data2, resources, &deleted_version, &newly_purgeable_resources));
426 425
427 GURL origin3("http://www3.example.com"); 426 GURL origin3("http://www3.example.com");
428 RegistrationData data3; 427 RegistrationData data3;
429 data3.registration_id = 300; 428 data3.registration_id = 300;
430 data3.scope = URL(origin3, "/hoge"); 429 data3.scope = URL(origin3, "/hoge");
431 data3.script = URL(origin3, "/script3.js"); 430 data3.script = URL(origin3, "/script3.js");
432 data3.version_id = 3000; 431 data3.version_id = 3000;
433 ASSERT_EQ( 432 ASSERT_EQ(
434 ServiceWorkerDatabase::STATUS_OK, 433 ServiceWorkerDatabase::STATUS_OK,
435 database->WriteRegistration( 434 database->WriteRegistration(
436 data3, resources, &deleted_version_id, &newly_purgeable_resources)); 435 data3, resources, &deleted_version, &newly_purgeable_resources));
437 436
438 // |origin3| has two registrations. 437 // |origin3| has two registrations.
439 RegistrationData data4; 438 RegistrationData data4;
440 data4.registration_id = 400; 439 data4.registration_id = 400;
441 data4.scope = URL(origin3, "/fuga"); 440 data4.scope = URL(origin3, "/fuga");
442 data4.script = URL(origin3, "/script4.js"); 441 data4.script = URL(origin3, "/script4.js");
443 data4.version_id = 4000; 442 data4.version_id = 4000;
444 ASSERT_EQ( 443 ASSERT_EQ(
445 ServiceWorkerDatabase::STATUS_OK, 444 ServiceWorkerDatabase::STATUS_OK,
446 database->WriteRegistration( 445 database->WriteRegistration(
447 data4, resources, &deleted_version_id, &newly_purgeable_resources)); 446 data4, resources, &deleted_version, &newly_purgeable_resources));
448 447
449 registrations.clear(); 448 registrations.clear();
450 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 449 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
451 database->GetAllRegistrations(&registrations)); 450 database->GetAllRegistrations(&registrations));
452 EXPECT_EQ(4U, registrations.size()); 451 EXPECT_EQ(4U, registrations.size());
453 VerifyRegistrationData(data1, registrations[0]); 452 VerifyRegistrationData(data1, registrations[0]);
454 VerifyRegistrationData(data2, registrations[1]); 453 VerifyRegistrationData(data2, registrations[1]);
455 VerifyRegistrationData(data3, registrations[2]); 454 VerifyRegistrationData(data3, registrations[2]);
456 VerifyRegistrationData(data4, registrations[3]); 455 VerifyRegistrationData(data4, registrations[3]);
457 } 456 }
(...skipping 18 matching lines...) Expand all
476 // the uncommitted list. 475 // the uncommitted list.
477 std::set<int64> uncommitted_ids; 476 std::set<int64> uncommitted_ids;
478 uncommitted_ids.insert(resources[0].resource_id); 477 uncommitted_ids.insert(resources[0].resource_id);
479 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 478 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
480 database->WriteUncommittedResourceIds(uncommitted_ids)); 479 database->WriteUncommittedResourceIds(uncommitted_ids));
481 std::set<int64> uncommitted_ids_out; 480 std::set<int64> uncommitted_ids_out;
482 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 481 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
483 database->GetUncommittedResourceIds(&uncommitted_ids_out)); 482 database->GetUncommittedResourceIds(&uncommitted_ids_out));
484 EXPECT_EQ(uncommitted_ids, uncommitted_ids_out); 483 EXPECT_EQ(uncommitted_ids, uncommitted_ids_out);
485 484
486 int64 deleted_version_id = 222; // Dummy initial value 485 ServiceWorkerDatabase::RegistrationData deleted_version;
486 deleted_version.version_id = 222; // Dummy initial value
487 std::vector<int64> newly_purgeable_resources; 487 std::vector<int64> newly_purgeable_resources;
488 488
489 EXPECT_EQ( 489 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
490 ServiceWorkerDatabase::STATUS_OK, 490 database->WriteRegistration(
491 database->WriteRegistration( 491 data, resources, &deleted_version, &newly_purgeable_resources));
492 data, resources, &deleted_version_id, &newly_purgeable_resources)); 492 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version.version_id);
493 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id);
494 EXPECT_TRUE(newly_purgeable_resources.empty()); 493 EXPECT_TRUE(newly_purgeable_resources.empty());
495 494
496 // Make sure that the registration and resource records are stored. 495 // Make sure that the registration and resource records are stored.
497 RegistrationData data_out; 496 RegistrationData data_out;
498 std::vector<Resource> resources_out; 497 std::vector<Resource> resources_out;
499 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 498 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
500 database->ReadRegistration( 499 database->ReadRegistration(
501 data.registration_id, origin, &data_out, &resources_out)); 500 data.registration_id, origin, &data_out, &resources_out));
502 VerifyRegistrationData(data, data_out); 501 VerifyRegistrationData(data, data_out);
503 VerifyResourceRecords(resources, resources_out); 502 VerifyResourceRecords(resources, resources_out);
504 503
505 // Make sure that the resource is removed from the uncommitted list. 504 // Make sure that the resource is removed from the uncommitted list.
506 uncommitted_ids_out.clear(); 505 uncommitted_ids_out.clear();
507 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 506 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
508 database->GetUncommittedResourceIds(&uncommitted_ids_out)); 507 database->GetUncommittedResourceIds(&uncommitted_ids_out));
509 EXPECT_TRUE(uncommitted_ids_out.empty()); 508 EXPECT_TRUE(uncommitted_ids_out.empty());
510 509
511 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 510 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
512 database->DeleteRegistration(data.registration_id, 511 database->DeleteRegistration(data.registration_id,
513 origin, 512 origin,
514 &deleted_version_id, 513 &deleted_version.version_id,
515 &newly_purgeable_resources)); 514 &newly_purgeable_resources));
516 EXPECT_EQ(data.version_id, deleted_version_id); 515 EXPECT_EQ(data.version_id, deleted_version.version_id);
517 ASSERT_EQ(resources.size(), newly_purgeable_resources.size()); 516 ASSERT_EQ(resources.size(), newly_purgeable_resources.size());
518 for (size_t i = 0; i < resources.size(); ++i) 517 for (size_t i = 0; i < resources.size(); ++i)
519 EXPECT_EQ(newly_purgeable_resources[i], resources[i].resource_id); 518 EXPECT_EQ(newly_purgeable_resources[i], resources[i].resource_id);
520 519
521 // Make sure that the registration and resource records are gone. 520 // Make sure that the registration and resource records are gone.
522 resources_out.clear(); 521 resources_out.clear();
523 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 522 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
524 database->ReadRegistration( 523 database->ReadRegistration(
525 data.registration_id, origin, &data_out, &resources_out)); 524 data.registration_id, origin, &data_out, &resources_out));
526 EXPECT_TRUE(resources_out.empty()); 525 EXPECT_TRUE(resources_out.empty());
(...skipping 18 matching lines...) Expand all
545 data.version_id = 200; 544 data.version_id = 200;
546 data.resources_total_size_bytes = 19 + 29129; 545 data.resources_total_size_bytes = 19 + 29129;
547 546
548 std::vector<Resource> resources; 547 std::vector<Resource> resources;
549 resources.push_back(CreateResource(1, URL(origin, "/resource1"), 19)); 548 resources.push_back(CreateResource(1, URL(origin, "/resource1"), 19));
550 resources.push_back(CreateResource(2, URL(origin, "/resource2"), 29129)); 549 resources.push_back(CreateResource(2, URL(origin, "/resource2"), 29129));
551 550
552 const int64 kNonExistentRegistrationId = 999; 551 const int64 kNonExistentRegistrationId = 999;
553 const int64 kArbitraryVersionId = 222; // Used as a dummy initial value 552 const int64 kArbitraryVersionId = 222; // Used as a dummy initial value
554 553
555 int64 deleted_version_id = kArbitraryVersionId; 554 ServiceWorkerDatabase::RegistrationData deleted_version;
555 deleted_version.version_id = kArbitraryVersionId;
556 std::vector<int64> newly_purgeable_resources; 556 std::vector<int64> newly_purgeable_resources;
557 EXPECT_EQ( 557 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
558 ServiceWorkerDatabase::STATUS_OK, 558 database->WriteRegistration(
559 database->WriteRegistration( 559 data, resources, &deleted_version, &newly_purgeable_resources));
560 data, resources, &deleted_version_id, &newly_purgeable_resources)); 560 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version.version_id);
561 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id);
562 EXPECT_TRUE(newly_purgeable_resources.empty()); 561 EXPECT_TRUE(newly_purgeable_resources.empty());
563 562
564 // Delete from an origin that has a registration. 563 // Delete from an origin that has a registration.
565 deleted_version_id = kArbitraryVersionId; 564 deleted_version.version_id = kArbitraryVersionId;
566 newly_purgeable_resources.clear(); 565 newly_purgeable_resources.clear();
567 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 566 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
568 database->DeleteRegistration(kNonExistentRegistrationId, 567 database->DeleteRegistration(kNonExistentRegistrationId,
569 origin, 568 origin,
570 &deleted_version_id, 569 &deleted_version.version_id,
571 &newly_purgeable_resources)); 570 &newly_purgeable_resources));
572 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id); 571 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version.version_id);
573 EXPECT_TRUE(newly_purgeable_resources.empty()); 572 EXPECT_TRUE(newly_purgeable_resources.empty());
574 573
575 // Delete from an origin that has no registration. 574 // Delete from an origin that has no registration.
576 deleted_version_id = kArbitraryVersionId; 575 deleted_version.version_id = kArbitraryVersionId;
577 newly_purgeable_resources.clear(); 576 newly_purgeable_resources.clear();
578 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 577 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
579 database->DeleteRegistration(kNonExistentRegistrationId, 578 database->DeleteRegistration(kNonExistentRegistrationId,
580 GURL("http://example.net"), 579 GURL("http://example.net"),
581 &deleted_version_id, 580 &deleted_version.version_id,
582 &newly_purgeable_resources)); 581 &newly_purgeable_resources));
583 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id); 582 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version.version_id);
584 EXPECT_TRUE(newly_purgeable_resources.empty()); 583 EXPECT_TRUE(newly_purgeable_resources.empty());
585 } 584 }
586 585
587 TEST(ServiceWorkerDatabaseTest, Registration_Overwrite) { 586 TEST(ServiceWorkerDatabaseTest, Registration_Overwrite) {
588 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 587 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
589 588
590 GURL origin("http://example.com"); 589 GURL origin("http://example.com");
591 RegistrationData data; 590 RegistrationData data;
592 data.registration_id = 100; 591 data.registration_id = 100;
593 data.scope = URL(origin, "/foo"); 592 data.scope = URL(origin, "/foo");
594 data.script = URL(origin, "/script.js"); 593 data.script = URL(origin, "/script.js");
595 data.version_id = 200; 594 data.version_id = 200;
596 data.resources_total_size_bytes = 10 + 11; 595 data.resources_total_size_bytes = 10 + 11;
597 596
598 std::vector<Resource> resources1; 597 std::vector<Resource> resources1;
599 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 10)); 598 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 10));
600 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 11)); 599 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 11));
601 600
602 int64 deleted_version_id = 222; // Dummy inital value 601 ServiceWorkerDatabase::RegistrationData deleted_version;
602 deleted_version.version_id = 222; // Dummy inital value
603 std::vector<int64> newly_purgeable_resources; 603 std::vector<int64> newly_purgeable_resources;
604 604
605 EXPECT_EQ( 605 EXPECT_EQ(
606 ServiceWorkerDatabase::STATUS_OK, 606 ServiceWorkerDatabase::STATUS_OK,
607 database->WriteRegistration( 607 database->WriteRegistration(
608 data, resources1, &deleted_version_id, &newly_purgeable_resources)); 608 data, resources1, &deleted_version, &newly_purgeable_resources));
609 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id); 609 EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version.version_id);
610 EXPECT_TRUE(newly_purgeable_resources.empty()); 610 EXPECT_TRUE(newly_purgeable_resources.empty());
611 611
612 // Make sure that the registration and resource records are stored. 612 // Make sure that the registration and resource records are stored.
613 RegistrationData data_out; 613 RegistrationData data_out;
614 std::vector<Resource> resources_out; 614 std::vector<Resource> resources_out;
615 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration( 615 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration(
616 data.registration_id, origin, &data_out, &resources_out)); 616 data.registration_id, origin, &data_out, &resources_out));
617 VerifyRegistrationData(data, data_out); 617 VerifyRegistrationData(data, data_out);
618 VerifyResourceRecords(resources1, resources_out); 618 VerifyResourceRecords(resources1, resources_out);
619 619
620 // Update the registration. 620 // Update the registration.
621 RegistrationData updated_data = data; 621 RegistrationData updated_data = data;
622 updated_data.version_id = data.version_id + 1; 622 updated_data.version_id = data.version_id + 1;
623 updated_data.resources_total_size_bytes = 12 + 13; 623 updated_data.resources_total_size_bytes = 12 + 13;
624 std::vector<Resource> resources2; 624 std::vector<Resource> resources2;
625 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12)); 625 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12));
626 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13)); 626 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13));
627 627
628 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 628 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
629 database->WriteRegistration(updated_data, 629 database->WriteRegistration(updated_data,
630 resources2, 630 resources2,
631 &deleted_version_id, 631 &deleted_version,
632 &newly_purgeable_resources)); 632 &newly_purgeable_resources));
633 EXPECT_EQ(data.version_id, deleted_version_id); 633 EXPECT_EQ(data.version_id, deleted_version.version_id);
634 ASSERT_EQ(resources1.size(), newly_purgeable_resources.size()); 634 ASSERT_EQ(resources1.size(), newly_purgeable_resources.size());
635 for (size_t i = 0; i < resources1.size(); ++i) 635 for (size_t i = 0; i < resources1.size(); ++i)
636 EXPECT_EQ(newly_purgeable_resources[i], resources1[i].resource_id); 636 EXPECT_EQ(newly_purgeable_resources[i], resources1[i].resource_id);
637 637
638 // Make sure that |updated_data| is stored and resources referred from |data| 638 // Make sure that |updated_data| is stored and resources referred from |data|
639 // is moved to the purgeable list. 639 // is moved to the purgeable list.
640 resources_out.clear(); 640 resources_out.clear();
641 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration( 641 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration(
642 updated_data.registration_id, origin, &data_out, &resources_out)); 642 updated_data.registration_id, origin, &data_out, &resources_out));
643 VerifyRegistrationData(updated_data, data_out); 643 VerifyRegistrationData(updated_data, data_out);
644 VerifyResourceRecords(resources2, resources_out); 644 VerifyResourceRecords(resources2, resources_out);
645 645
646 std::set<int64> purgeable_ids_out; 646 std::set<int64> purgeable_ids_out;
647 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 647 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
648 database->GetPurgeableResourceIds(&purgeable_ids_out)); 648 database->GetPurgeableResourceIds(&purgeable_ids_out));
649 EXPECT_EQ(2u, purgeable_ids_out.size()); 649 EXPECT_EQ(2u, purgeable_ids_out.size());
650 EXPECT_TRUE(ContainsKey(purgeable_ids_out, resources1[0].resource_id)); 650 EXPECT_TRUE(ContainsKey(purgeable_ids_out, resources1[0].resource_id));
651 EXPECT_TRUE(ContainsKey(purgeable_ids_out, resources1[1].resource_id)); 651 EXPECT_TRUE(ContainsKey(purgeable_ids_out, resources1[1].resource_id));
652 } 652 }
653 653
654 TEST(ServiceWorkerDatabaseTest, Registration_Multiple) { 654 TEST(ServiceWorkerDatabaseTest, Registration_Multiple) {
655 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 655 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
656 GURL origin("http://example.com"); 656 GURL origin("http://example.com");
657 657
658 int64 deleted_version_id; 658 ServiceWorkerDatabase::RegistrationData deleted_version;
659 std::vector<int64> newly_purgeable_resources; 659 std::vector<int64> newly_purgeable_resources;
660 660
661 // Add registration1. 661 // Add registration1.
662 RegistrationData data1; 662 RegistrationData data1;
663 data1.registration_id = 100; 663 data1.registration_id = 100;
664 data1.scope = URL(origin, "/foo"); 664 data1.scope = URL(origin, "/foo");
665 data1.script = URL(origin, "/script1.js"); 665 data1.script = URL(origin, "/script1.js");
666 data1.version_id = 200; 666 data1.version_id = 200;
667 data1.resources_total_size_bytes = 1451 + 15234; 667 data1.resources_total_size_bytes = 1451 + 15234;
668 668
669 std::vector<Resource> resources1; 669 std::vector<Resource> resources1;
670 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 1451)); 670 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 1451));
671 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 15234)); 671 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 15234));
672 EXPECT_EQ( 672 EXPECT_EQ(
673 ServiceWorkerDatabase::STATUS_OK, 673 ServiceWorkerDatabase::STATUS_OK,
674 database->WriteRegistration( 674 database->WriteRegistration(
675 data1, resources1, &deleted_version_id, &newly_purgeable_resources)); 675 data1, resources1, &deleted_version, &newly_purgeable_resources));
676 676
677 // Add registration2. 677 // Add registration2.
678 RegistrationData data2; 678 RegistrationData data2;
679 data2.registration_id = 101; 679 data2.registration_id = 101;
680 data2.scope = URL(origin, "/bar"); 680 data2.scope = URL(origin, "/bar");
681 data2.script = URL(origin, "/script2.js"); 681 data2.script = URL(origin, "/script2.js");
682 data2.version_id = 201; 682 data2.version_id = 201;
683 data2.resources_total_size_bytes = 5 + 6; 683 data2.resources_total_size_bytes = 5 + 6;
684 684
685 std::vector<Resource> resources2; 685 std::vector<Resource> resources2;
686 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 5)); 686 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 5));
687 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 6)); 687 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 6));
688 EXPECT_EQ( 688 EXPECT_EQ(
689 ServiceWorkerDatabase::STATUS_OK, 689 ServiceWorkerDatabase::STATUS_OK,
690 database->WriteRegistration( 690 database->WriteRegistration(
691 data2, resources2, &deleted_version_id, &newly_purgeable_resources)); 691 data2, resources2, &deleted_version, &newly_purgeable_resources));
692 692
693 // Make sure that registration1 is stored. 693 // Make sure that registration1 is stored.
694 RegistrationData data_out; 694 RegistrationData data_out;
695 std::vector<Resource> resources_out; 695 std::vector<Resource> resources_out;
696 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration( 696 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration(
697 data1.registration_id, origin, &data_out, &resources_out)); 697 data1.registration_id, origin, &data_out, &resources_out));
698 VerifyRegistrationData(data1, data_out); 698 VerifyRegistrationData(data1, data_out);
699 VerifyResourceRecords(resources1, resources_out); 699 VerifyResourceRecords(resources1, resources_out);
700 700
701 // Make sure that registration2 is also stored. 701 // Make sure that registration2 is also stored.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration( 737 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->ReadRegistration(
738 data2.registration_id, origin, &data_out, &resources_out)); 738 data2.registration_id, origin, &data_out, &resources_out));
739 VerifyRegistrationData(data2, data_out); 739 VerifyRegistrationData(data2, data_out);
740 VerifyResourceRecords(resources2, resources_out); 740 VerifyResourceRecords(resources2, resources_out);
741 } 741 }
742 742
743 TEST(ServiceWorkerDatabaseTest, UpdateVersionToActive) { 743 TEST(ServiceWorkerDatabaseTest, UpdateVersionToActive) {
744 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 744 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
745 GURL origin("http://example.com"); 745 GURL origin("http://example.com");
746 746
747 int64 deleted_version_id; 747 ServiceWorkerDatabase::RegistrationData deleted_version;
748 std::vector<int64> newly_purgeable_resources; 748 std::vector<int64> newly_purgeable_resources;
749 749
750 // Should be false because a registration does not exist. 750 // Should be false because a registration does not exist.
751 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 751 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
752 database->UpdateVersionToActive(0, origin)); 752 database->UpdateVersionToActive(0, origin));
753 753
754 // Add a registration. 754 // Add a registration.
755 RegistrationData data; 755 RegistrationData data;
756 data.registration_id = 100; 756 data.registration_id = 100;
757 data.scope = URL(origin, "/foo"); 757 data.scope = URL(origin, "/foo");
758 data.script = URL(origin, "/script.js"); 758 data.script = URL(origin, "/script.js");
759 data.version_id = 200; 759 data.version_id = 200;
760 data.is_active = false; 760 data.is_active = false;
761 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 761 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
762 database->WriteRegistration(data, 762 database->WriteRegistration(data,
763 std::vector<Resource>(), 763 std::vector<Resource>(),
764 &deleted_version_id, 764 &deleted_version,
765 &newly_purgeable_resources)); 765 &newly_purgeable_resources));
766 766
767 // Make sure that the registration is stored. 767 // Make sure that the registration is stored.
768 RegistrationData data_out; 768 RegistrationData data_out;
769 std::vector<Resource> resources_out; 769 std::vector<Resource> resources_out;
770 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 770 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
771 database->ReadRegistration( 771 database->ReadRegistration(
772 data.registration_id, origin, &data_out, &resources_out)); 772 data.registration_id, origin, &data_out, &resources_out));
773 VerifyRegistrationData(data, data_out); 773 VerifyRegistrationData(data, data_out);
774 EXPECT_TRUE(resources_out.empty()); 774 EXPECT_TRUE(resources_out.empty());
(...skipping 21 matching lines...) Expand all
796 &newly_purgeable_resources)); 796 &newly_purgeable_resources));
797 797
798 // Should be false because the registration is gone. 798 // Should be false because the registration is gone.
799 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 799 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
800 database->UpdateVersionToActive(data.registration_id, origin)); 800 database->UpdateVersionToActive(data.registration_id, origin));
801 } 801 }
802 802
803 TEST(ServiceWorkerDatabaseTest, UpdateLastCheckTime) { 803 TEST(ServiceWorkerDatabaseTest, UpdateLastCheckTime) {
804 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 804 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
805 GURL origin("http://example.com"); 805 GURL origin("http://example.com");
806 int64 deleted_version_id; 806 ServiceWorkerDatabase::RegistrationData deleted_version;
807 std::vector<int64> newly_purgeable_resources; 807 std::vector<int64> newly_purgeable_resources;
808 808
809 // Should be false because a registration does not exist. 809 // Should be false because a registration does not exist.
810 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND, 810 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND,
811 database->UpdateLastCheckTime(0, origin, base::Time::Now())); 811 database->UpdateLastCheckTime(0, origin, base::Time::Now()));
812 812
813 // Add a registration. 813 // Add a registration.
814 RegistrationData data; 814 RegistrationData data;
815 data.registration_id = 100; 815 data.registration_id = 100;
816 data.scope = URL(origin, "/foo"); 816 data.scope = URL(origin, "/foo");
817 data.script = URL(origin, "/script.js"); 817 data.script = URL(origin, "/script.js");
818 data.version_id = 200; 818 data.version_id = 200;
819 data.last_update_check = base::Time::Now(); 819 data.last_update_check = base::Time::Now();
820 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 820 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
821 database->WriteRegistration(data, 821 database->WriteRegistration(data,
822 std::vector<Resource>(), 822 std::vector<Resource>(),
823 &deleted_version_id, 823 &deleted_version,
824 &newly_purgeable_resources)); 824 &newly_purgeable_resources));
825 825
826 // Make sure that the registration is stored. 826 // Make sure that the registration is stored.
827 RegistrationData data_out; 827 RegistrationData data_out;
828 std::vector<Resource> resources_out; 828 std::vector<Resource> resources_out;
829 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 829 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
830 database->ReadRegistration( 830 database->ReadRegistration(
831 data.registration_id, origin, &data_out, &resources_out)); 831 data.registration_id, origin, &data_out, &resources_out));
832 VerifyRegistrationData(data, data_out); 832 VerifyRegistrationData(data, data_out);
833 EXPECT_TRUE(resources_out.empty()); 833 EXPECT_TRUE(resources_out.empty());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 943
944 ids_out.clear(); 944 ids_out.clear();
945 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 945 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
946 database->GetPurgeableResourceIds(&ids_out)); 946 database->GetPurgeableResourceIds(&ids_out));
947 expected = base::STLSetDifference<std::set<int64> >(expected, ids3); 947 expected = base::STLSetDifference<std::set<int64> >(expected, ids3);
948 EXPECT_EQ(expected, ids_out); 948 EXPECT_EQ(expected, ids_out);
949 } 949 }
950 950
951 TEST(ServiceWorkerDatabaseTest, DeleteAllDataForOrigin) { 951 TEST(ServiceWorkerDatabaseTest, DeleteAllDataForOrigin) {
952 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 952 scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
953 int64 deleted_version_id; 953 ServiceWorkerDatabase::RegistrationData deleted_version;
954 std::vector<int64> newly_purgeable_resources; 954 std::vector<int64> newly_purgeable_resources;
955 955
956 // Data associated with |origin1| will be removed. 956 // Data associated with |origin1| will be removed.
957 GURL origin1("http://example.com"); 957 GURL origin1("http://example.com");
958 GURL origin2("http://example.org"); 958 GURL origin2("http://example.org");
959 959
960 // |origin1| has two registrations. 960 // |origin1| has two registrations.
961 RegistrationData data1; 961 RegistrationData data1;
962 data1.registration_id = 10; 962 data1.registration_id = 10;
963 data1.scope = URL(origin1, "/foo"); 963 data1.scope = URL(origin1, "/foo");
964 data1.script = URL(origin1, "/script1.js"); 964 data1.script = URL(origin1, "/script1.js");
965 data1.version_id = 100; 965 data1.version_id = 100;
966 data1.resources_total_size_bytes = 2013 + 512; 966 data1.resources_total_size_bytes = 2013 + 512;
967 967
968 std::vector<Resource> resources1; 968 std::vector<Resource> resources1;
969 resources1.push_back(CreateResource(1, URL(origin1, "/resource1"), 2013)); 969 resources1.push_back(CreateResource(1, URL(origin1, "/resource1"), 2013));
970 resources1.push_back(CreateResource(2, URL(origin1, "/resource2"), 512)); 970 resources1.push_back(CreateResource(2, URL(origin1, "/resource2"), 512));
971 ASSERT_EQ( 971 ASSERT_EQ(
972 ServiceWorkerDatabase::STATUS_OK, 972 ServiceWorkerDatabase::STATUS_OK,
973 database->WriteRegistration( 973 database->WriteRegistration(
974 data1, resources1, &deleted_version_id, &newly_purgeable_resources)); 974 data1, resources1, &deleted_version, &newly_purgeable_resources));
975 975
976 RegistrationData data2; 976 RegistrationData data2;
977 data2.registration_id = 11; 977 data2.registration_id = 11;
978 data2.scope = URL(origin1, "/bar"); 978 data2.scope = URL(origin1, "/bar");
979 data2.script = URL(origin1, "/script2.js"); 979 data2.script = URL(origin1, "/script2.js");
980 data2.version_id = 101; 980 data2.version_id = 101;
981 data2.resources_total_size_bytes = 4 + 5; 981 data2.resources_total_size_bytes = 4 + 5;
982 982
983 std::vector<Resource> resources2; 983 std::vector<Resource> resources2;
984 resources2.push_back(CreateResource(3, URL(origin1, "/resource3"), 4)); 984 resources2.push_back(CreateResource(3, URL(origin1, "/resource3"), 4));
985 resources2.push_back(CreateResource(4, URL(origin1, "/resource4"), 5)); 985 resources2.push_back(CreateResource(4, URL(origin1, "/resource4"), 5));
986 ASSERT_EQ( 986 ASSERT_EQ(
987 ServiceWorkerDatabase::STATUS_OK, 987 ServiceWorkerDatabase::STATUS_OK,
988 database->WriteRegistration( 988 database->WriteRegistration(
989 data2, resources2, &deleted_version_id, &newly_purgeable_resources)); 989 data2, resources2, &deleted_version, &newly_purgeable_resources));
990 990
991 // |origin2| has one registration. 991 // |origin2| has one registration.
992 RegistrationData data3; 992 RegistrationData data3;
993 data3.registration_id = 12; 993 data3.registration_id = 12;
994 data3.scope = URL(origin2, "/hoge"); 994 data3.scope = URL(origin2, "/hoge");
995 data3.script = URL(origin2, "/script3.js"); 995 data3.script = URL(origin2, "/script3.js");
996 data3.version_id = 102; 996 data3.version_id = 102;
997 data3.resources_total_size_bytes = 6 + 7; 997 data3.resources_total_size_bytes = 6 + 7;
998 998
999 std::vector<Resource> resources3; 999 std::vector<Resource> resources3;
1000 resources3.push_back(CreateResource(5, URL(origin2, "/resource5"), 6)); 1000 resources3.push_back(CreateResource(5, URL(origin2, "/resource5"), 6));
1001 resources3.push_back(CreateResource(6, URL(origin2, "/resource6"), 7)); 1001 resources3.push_back(CreateResource(6, URL(origin2, "/resource6"), 7));
1002 ASSERT_EQ( 1002 ASSERT_EQ(
1003 ServiceWorkerDatabase::STATUS_OK, 1003 ServiceWorkerDatabase::STATUS_OK,
1004 database->WriteRegistration( 1004 database->WriteRegistration(
1005 data3, resources3, &deleted_version_id, &newly_purgeable_resources)); 1005 data3, resources3, &deleted_version, &newly_purgeable_resources));
1006 1006
1007 std::set<GURL> origins_to_delete; 1007 std::set<GURL> origins_to_delete;
1008 origins_to_delete.insert(origin1); 1008 origins_to_delete.insert(origin1);
1009 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1009 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1010 database->DeleteAllDataForOrigins(origins_to_delete, 1010 database->DeleteAllDataForOrigins(origins_to_delete,
1011 &newly_purgeable_resources)); 1011 &newly_purgeable_resources));
1012 1012
1013 // |origin1| should be removed from the unique origin list. 1013 // |origin1| should be removed from the unique origin list.
1014 std::set<GURL> unique_origins; 1014 std::set<GURL> unique_origins;
1015 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1015 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 CreateDatabase(database_dir.path())); 1049 CreateDatabase(database_dir.path()));
1050 1050
1051 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true)); 1051 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->LazyOpen(true));
1052 ASSERT_TRUE(base::DirectoryExists(database_dir.path())); 1052 ASSERT_TRUE(base::DirectoryExists(database_dir.path()));
1053 1053
1054 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->DestroyDatabase()); 1054 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, database->DestroyDatabase());
1055 ASSERT_FALSE(base::DirectoryExists(database_dir.path())); 1055 ASSERT_FALSE(base::DirectoryExists(database_dir.path()));
1056 } 1056 }
1057 1057
1058 } // namespace content 1058 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698