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

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

Issue 1221643014: Service Worker: Migrate to version_uuid and surface ServiceWorker.id. (Chromium 2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_disk_cache_migrator.h" 5 #include "content/browser/service_worker/service_worker_disk_cache_migrator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // Simulate an existing database. 360 // Simulate an existing database.
361 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 361 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
362 resources.push_back(ServiceWorkerDatabase::ResourceRecord( 362 resources.push_back(ServiceWorkerDatabase::ResourceRecord(
363 1, GURL("https://example.com/foo"), 10)); 363 1, GURL("https://example.com/foo"), 10));
364 ServiceWorkerDatabase::RegistrationData deleted_version; 364 ServiceWorkerDatabase::RegistrationData deleted_version;
365 std::vector<int64> newly_purgeable_resources; 365 std::vector<int64> newly_purgeable_resources;
366 ServiceWorkerDatabase::RegistrationData data; 366 ServiceWorkerDatabase::RegistrationData data;
367 data.registration_id = 100; 367 data.registration_id = 100;
368 data.scope = GURL("https://example.com/"); 368 data.scope = GURL("https://example.com/");
369 data.script = GURL("https://example.com/script.js"); 369 data.script = GURL("https://example.com/script.js");
370 data.version_id = 200; 370 data.version_uuid = "84a19bb1-148b-484d-a3ff-1ab43ac3fe53";
371 data.resources_total_size_bytes = 10; 371 data.resources_total_size_bytes = 10;
372 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 372 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
373 database->WriteRegistration(data, resources, &deleted_version, 373 database->WriteRegistration(data, resources, &deleted_version,
374 &newly_purgeable_resources)); 374 &newly_purgeable_resources));
375 database.reset(); 375 database.reset();
376 376
377 // LazyInitialize() reads initial data and should schedule to migrate. 377 // LazyInitialize() reads initial data and should schedule to migrate.
378 ASSERT_FALSE(storage()->disk_cache_migration_needed_); 378 ASSERT_FALSE(storage()->disk_cache_migration_needed_);
379 base::RunLoop run_loop; 379 base::RunLoop run_loop;
380 storage()->LazyInitialize(run_loop.QuitClosure()); 380 storage()->LazyInitialize(run_loop.QuitClosure());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // Simulate an existing database. 430 // Simulate an existing database.
431 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 431 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
432 resources.push_back(ServiceWorkerDatabase::ResourceRecord( 432 resources.push_back(ServiceWorkerDatabase::ResourceRecord(
433 1, GURL("https://example.com/foo"), 10)); 433 1, GURL("https://example.com/foo"), 10));
434 ServiceWorkerDatabase::RegistrationData deleted_version; 434 ServiceWorkerDatabase::RegistrationData deleted_version;
435 std::vector<int64> newly_purgeable_resources; 435 std::vector<int64> newly_purgeable_resources;
436 ServiceWorkerDatabase::RegistrationData data; 436 ServiceWorkerDatabase::RegistrationData data;
437 data.registration_id = 100; 437 data.registration_id = 100;
438 data.scope = GURL("https://example.com/"); 438 data.scope = GURL("https://example.com/");
439 data.script = GURL("https://example.com/script.js"); 439 data.script = GURL("https://example.com/script.js");
440 data.version_id = 200; 440 data.version_uuid = "84a19bb1-148b-484d-a3ff-1ab43ac3fe53";
441 data.resources_total_size_bytes = 10; 441 data.resources_total_size_bytes = 10;
442 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 442 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
443 database->WriteRegistration(data, resources, &deleted_version, 443 database->WriteRegistration(data, resources, &deleted_version,
444 &newly_purgeable_resources)); 444 &newly_purgeable_resources));
445 database.reset(); 445 database.reset();
446 446
447 // LazyInitialize() reads initial data and should schedule to migrate. 447 // LazyInitialize() reads initial data and should schedule to migrate.
448 ASSERT_FALSE(storage()->disk_cache_migration_needed_); 448 ASSERT_FALSE(storage()->disk_cache_migration_needed_);
449 base::RunLoop run_loop1; 449 base::RunLoop run_loop1;
450 storage()->LazyInitialize(run_loop1.QuitClosure()); 450 storage()->LazyInitialize(run_loop1.QuitClosure());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 // Write a registration into the database to start database initialization. 504 // Write a registration into the database to start database initialization.
505 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 505 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
506 resources.push_back(ServiceWorkerDatabase::ResourceRecord( 506 resources.push_back(ServiceWorkerDatabase::ResourceRecord(
507 1, GURL("https://example.com/foo"), 10)); 507 1, GURL("https://example.com/foo"), 10));
508 ServiceWorkerDatabase::RegistrationData deleted_version; 508 ServiceWorkerDatabase::RegistrationData deleted_version;
509 std::vector<int64> newly_purgeable_resources; 509 std::vector<int64> newly_purgeable_resources;
510 ServiceWorkerDatabase::RegistrationData data; 510 ServiceWorkerDatabase::RegistrationData data;
511 data.registration_id = 100; 511 data.registration_id = 100;
512 data.scope = GURL("https://example.com/"); 512 data.scope = GURL("https://example.com/");
513 data.script = GURL("https://example.com/script.js"); 513 data.script = GURL("https://example.com/script.js");
514 data.version_id = 200; 514 data.version_uuid = "84a19bb1-148b-484d-a3ff-1ab43ac3fe53";
515 data.resources_total_size_bytes = 10; 515 data.resources_total_size_bytes = 10;
516 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 516 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
517 storage()->database_->WriteRegistration( 517 storage()->database_->WriteRegistration(
518 data, resources, &deleted_version, &newly_purgeable_resources)); 518 data, resources, &deleted_version, &newly_purgeable_resources));
519 519
520 // After the database initialization, the migration state should be 520 // After the database initialization, the migration state should be
521 // initialized. 521 // initialized.
522 bool migration_needed = false; 522 bool migration_needed = false;
523 EXPECT_EQ( 523 EXPECT_EQ(
524 ServiceWorkerDatabase::STATUS_OK, 524 ServiceWorkerDatabase::STATUS_OK,
525 storage()->database_->IsDiskCacheMigrationNeeded(&migration_needed)); 525 storage()->database_->IsDiskCacheMigrationNeeded(&migration_needed));
526 EXPECT_FALSE(migration_needed); 526 EXPECT_FALSE(migration_needed);
527 bool deletion_needed = false; 527 bool deletion_needed = false;
528 EXPECT_EQ( 528 EXPECT_EQ(
529 ServiceWorkerDatabase::STATUS_OK, 529 ServiceWorkerDatabase::STATUS_OK,
530 storage()->database_->IsOldDiskCacheDeletionNeeded(&deletion_needed)); 530 storage()->database_->IsOldDiskCacheDeletionNeeded(&deletion_needed));
531 531
532 // The deletion flag should be set for the case that the database is empty but 532 // The deletion flag should be set for the case that the database is empty but
533 // the old diskcache exists. 533 // the old diskcache exists.
534 EXPECT_TRUE(deletion_needed); 534 EXPECT_TRUE(deletion_needed);
535 } 535 }
536 536
537 } // namespace content 537 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698