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

Unified Diff: content/browser/service_worker/service_worker_disk_cache_migrator_unittest.cc

Issue 1152543002: ServiceWorker: Migrate the script cache backend from BlockFile to Simple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update histograms.xml Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_disk_cache_migrator_unittest.cc
diff --git a/content/browser/service_worker/service_worker_disk_cache_migrator_unittest.cc b/content/browser/service_worker/service_worker_disk_cache_migrator_unittest.cc
index d987f095a0ab3bb824131bf4df3d02e8ac9a67a1..6cde678da9d1d498aa8f6d6d4dc75512a5e4e3b7 100644
--- a/content/browser/service_worker/service_worker_disk_cache_migrator_unittest.cc
+++ b/content/browser/service_worker/service_worker_disk_cache_migrator_unittest.cc
@@ -4,9 +4,12 @@
#include "content/browser/service_worker/service_worker_disk_cache_migrator.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
#include "base/thread_task_runner_handle.h"
+#include "content/browser/service_worker/service_worker_context_core.h"
+#include "content/browser/service_worker/service_worker_storage.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -51,16 +54,21 @@ class ServiceWorkerDiskCacheMigratorTest : public testing::Test {
void SetUp() override {
ASSERT_TRUE(user_data_directory_.CreateUniqueTempDir());
- const base::FilePath kSrcDiskCachePath =
- user_data_directory_.path().AppendASCII("SrcCache");
- const base::FilePath kDestDiskCachePath =
- user_data_directory_.path().AppendASCII("DestCache");
+ scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager(
+ new MockServiceWorkerDatabaseTaskManager(
+ base::ThreadTaskRunnerHandle::Get()));
+
+ context_.reset(new ServiceWorkerContextCore(
+ user_data_directory_.path(), database_task_manager.Pass(),
+ base::ThreadTaskRunnerHandle::Get(), nullptr, nullptr, nullptr,
+ nullptr));
+ ServiceWorkerStorage* storage = context_->storage();
// Initialize the src BlockFile diskcache.
src_ = ServiceWorkerDiskCache::CreateWithBlockFileBackend();
net::TestCompletionCallback cb1;
src_->InitWithDiskBackend(
- kSrcDiskCachePath, kMaxDiskCacheSize, false /* force */,
+ storage->GetOldDiskCachePath(), kMaxDiskCacheSize, false /* force */,
base::ThreadTaskRunnerHandle::Get(), cb1.callback());
ASSERT_EQ(net::OK, cb1.WaitForResult());
@@ -68,7 +76,7 @@ class ServiceWorkerDiskCacheMigratorTest : public testing::Test {
dest_ = ServiceWorkerDiskCache::CreateWithSimpleBackend();
net::TestCompletionCallback cb2;
dest_->InitWithDiskBackend(
- kDestDiskCachePath, kMaxDiskCacheSize, false /* force */,
+ storage->GetDiskCachePath(), kMaxDiskCacheSize, false /* force */,
base::ThreadTaskRunnerHandle::Get(), cb2.callback());
ASSERT_EQ(net::OK, cb2.WaitForResult());
@@ -173,9 +181,26 @@ class ServiceWorkerDiskCacheMigratorTest : public testing::Test {
migrator_->set_max_number_of_inflight_tasks(max_number);
}
+ void LazyInitialize() {
+ base::RunLoop run_loop;
+ context_->storage()->LazyInitialize(run_loop.QuitClosure());
+ run_loop.Run();
+ }
+
+ base::FilePath GetSrcDiskCachePath() {
+ return context_->storage()->GetOldDiskCachePath();
+ }
+
+ ServiceWorkerDiskCache* disk_cache() {
+ return context_->storage()->disk_cache();
+ }
+
protected:
TestBrowserThreadBundle browser_thread_bundle_;
base::ScopedTempDir user_data_directory_;
+
+ scoped_ptr<ServiceWorkerContextCore> context_;
+
scoped_ptr<ServiceWorkerDiskCache> src_;
scoped_ptr<ServiceWorkerDiskCache> dest_;
scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator_;
@@ -234,4 +259,31 @@ TEST_F(ServiceWorkerDiskCacheMigratorTest, ThrottleInflightTasks) {
EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(dest_.get()));
}
+TEST_F(ServiceWorkerDiskCacheMigratorTest, MigrateDuringLazyInitialize) {
+ std::vector<ResponseData> responses;
+ responses.push_back(ResponseData(1, "HTTP/1.1 200 OK\0\0", "Hello", ""));
+ responses.push_back(ResponseData(2, "HTTP/1.1 200 OK\0\0", "Service", ""));
+ responses.push_back(ResponseData(5, "HTTP/1.1 200 OK\0\0", "Worker", ""));
+ responses.push_back(ResponseData(3, "HTTP/1.1 200 OK\0\0", "World", "meta"));
+
+ // Populate initial data in the src diskcache.
+ for (const ResponseData& response : responses) {
+ ASSERT_TRUE(WriteResponse(src_.get(), response));
+ VerifyResponse(src_.get(), response);
+ }
+ ASSERT_EQ(static_cast<int>(responses.size()), GetEntryCount(src_.get()));
+ ASSERT_TRUE(base::DirectoryExists(GetSrcDiskCachePath()));
+
+ // LazyInitialize ignites the migrator.
+ LazyInitialize();
kinuko 2015/06/02 06:18:52 Is it possible to also test that concurrent reques
kinuko 2015/06/02 06:18:52 Did you check the local histogram to see how long
nhiroki 2015/06/02 09:18:32 Done.
nhiroki 2015/06/02 09:18:32 I tried the migration 3 times (Linux, SSD, Release
+
+ // Verify the migrated contents in the dest diskcache.
+ for (const ResponseData& response : responses)
+ VerifyResponse(disk_cache(), response);
+ EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(disk_cache()));
+
+ // The src DiskCache should be deleted after migration.
+ EXPECT_FALSE(base::DirectoryExists(GetSrcDiskCachePath()));
+}
+
falken 2015/06/01 04:31:49 Should we also do a test for if the migration fail
nhiroki 2015/06/02 09:18:32 I haven't found a handy way to fail the migration
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698