OLD | NEW |
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 "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
9 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "content/browser/service_worker/service_worker_context_core.h" |
| 12 #include "content/browser/service_worker/service_worker_storage.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
11 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
13 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
14 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
16 | 19 |
17 namespace content { | 20 namespace content { |
18 | 21 |
19 namespace { | 22 namespace { |
(...skipping 15 matching lines...) Expand all Loading... |
35 body(body), | 38 body(body), |
36 metadata(metadata) {} | 39 metadata(metadata) {} |
37 }; | 40 }; |
38 | 41 |
39 void OnDiskCacheMigrated(const base::Closure& callback, | 42 void OnDiskCacheMigrated(const base::Closure& callback, |
40 ServiceWorkerStatusCode status) { | 43 ServiceWorkerStatusCode status) { |
41 EXPECT_EQ(SERVICE_WORKER_OK, status); | 44 EXPECT_EQ(SERVICE_WORKER_OK, status); |
42 callback.Run(); | 45 callback.Run(); |
43 } | 46 } |
44 | 47 |
| 48 void OnRegistrationFound( |
| 49 const base::Closure& callback, |
| 50 ServiceWorkerStatusCode status, |
| 51 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 52 callback.Run(); |
| 53 } |
| 54 |
45 } // namespace | 55 } // namespace |
46 | 56 |
47 class ServiceWorkerDiskCacheMigratorTest : public testing::Test { | 57 class ServiceWorkerDiskCacheMigratorTest : public testing::Test { |
48 public: | 58 public: |
49 ServiceWorkerDiskCacheMigratorTest() | 59 ServiceWorkerDiskCacheMigratorTest() |
50 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 60 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
51 | 61 |
52 void SetUp() override { | 62 void SetUp() override { |
53 ASSERT_TRUE(user_data_directory_.CreateUniqueTempDir()); | 63 ASSERT_TRUE(user_data_directory_.CreateUniqueTempDir()); |
54 const base::FilePath kSrcDiskCachePath = | 64 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( |
55 user_data_directory_.path().AppendASCII("SrcCache"); | 65 new MockServiceWorkerDatabaseTaskManager( |
56 const base::FilePath kDestDiskCachePath = | 66 base::ThreadTaskRunnerHandle::Get())); |
57 user_data_directory_.path().AppendASCII("DestCache"); | |
58 | 67 |
59 // Initialize the src BlockFile diskcache. | 68 context_.reset(new ServiceWorkerContextCore( |
60 src_ = ServiceWorkerDiskCache::CreateWithBlockFileBackend(); | 69 user_data_directory_.path(), database_task_manager.Pass(), |
61 net::TestCompletionCallback cb1; | 70 base::ThreadTaskRunnerHandle::Get(), nullptr, nullptr, nullptr, |
62 src_->InitWithDiskBackend( | 71 nullptr)); |
63 kSrcDiskCachePath, kMaxDiskCacheSize, false /* force */, | 72 } |
64 base::ThreadTaskRunnerHandle::Get(), cb1.callback()); | |
65 ASSERT_EQ(net::OK, cb1.WaitForResult()); | |
66 | 73 |
67 // Initialize the dest Simple diskcache. | 74 void TearDown() override { |
68 dest_ = ServiceWorkerDiskCache::CreateWithSimpleBackend(); | 75 context_.reset(); |
69 net::TestCompletionCallback cb2; | 76 base::RunLoop().RunUntilIdle(); |
70 dest_->InitWithDiskBackend( | 77 } |
71 kDestDiskCachePath, kMaxDiskCacheSize, false /* force */, | |
72 base::ThreadTaskRunnerHandle::Get(), cb2.callback()); | |
73 ASSERT_EQ(net::OK, cb2.WaitForResult()); | |
74 | 78 |
75 migrator_.reset( | 79 scoped_ptr<ServiceWorkerDiskCache> CreateSrcDiskCache() { |
76 new ServiceWorkerDiskCacheMigrator(src_.get(), dest_.get())); | 80 scoped_ptr<ServiceWorkerDiskCache> src( |
| 81 ServiceWorkerDiskCache::CreateWithBlockFileBackend()); |
| 82 net::TestCompletionCallback cb; |
| 83 src->InitWithDiskBackend( |
| 84 storage()->GetOldDiskCachePath(), kMaxDiskCacheSize, false /* force */, |
| 85 base::ThreadTaskRunnerHandle::Get(), cb.callback()); |
| 86 EXPECT_EQ(net::OK, cb.WaitForResult()); |
| 87 return src.Pass(); |
| 88 } |
| 89 |
| 90 scoped_ptr<ServiceWorkerDiskCache> CreateDestDiskCache() { |
| 91 scoped_ptr<ServiceWorkerDiskCache> dest( |
| 92 ServiceWorkerDiskCache::CreateWithSimpleBackend()); |
| 93 net::TestCompletionCallback cb; |
| 94 dest->InitWithDiskBackend( |
| 95 storage()->GetDiskCachePath(), kMaxDiskCacheSize, false /* force */, |
| 96 base::ThreadTaskRunnerHandle::Get(), cb.callback()); |
| 97 EXPECT_EQ(net::OK, cb.WaitForResult()); |
| 98 return dest.Pass(); |
| 99 } |
| 100 |
| 101 scoped_ptr<ServiceWorkerDiskCacheMigrator> CreateMigrator() { |
| 102 return make_scoped_ptr(new ServiceWorkerDiskCacheMigrator( |
| 103 storage()->GetOldDiskCachePath(), storage()->GetDiskCachePath(), |
| 104 kMaxDiskCacheSize, base::ThreadTaskRunnerHandle::Get())); |
77 } | 105 } |
78 | 106 |
79 bool WriteResponse(ServiceWorkerDiskCache* disk_cache, | 107 bool WriteResponse(ServiceWorkerDiskCache* disk_cache, |
80 const ResponseData& response) { | 108 const ResponseData& response) { |
81 scoped_ptr<ServiceWorkerResponseWriter> writer( | 109 scoped_ptr<ServiceWorkerResponseWriter> writer( |
82 new ServiceWorkerResponseWriter(response.resource_id, disk_cache)); | 110 new ServiceWorkerResponseWriter(response.resource_id, disk_cache)); |
83 | 111 |
84 // Write the response info. | 112 // Write the response info. |
85 scoped_ptr<net::HttpResponseInfo> info(new net::HttpResponseInfo); | 113 scoped_ptr<net::HttpResponseInfo> info(new net::HttpResponseInfo); |
86 info->request_time = base::Time() + base::TimeDelta::FromSeconds(10); | 114 info->request_time = base::Time() + base::TimeDelta::FromSeconds(10); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // Verify the response body. | 180 // Verify the response body. |
153 const int kBigEnough = 512; | 181 const int kBigEnough = 512; |
154 scoped_refptr<net::IOBuffer> body_buffer = new net::IOBuffer(kBigEnough); | 182 scoped_refptr<net::IOBuffer> body_buffer = new net::IOBuffer(kBigEnough); |
155 net::TestCompletionCallback cb2; | 183 net::TestCompletionCallback cb2; |
156 reader->ReadData(body_buffer.get(), kBigEnough, cb2.callback()); | 184 reader->ReadData(body_buffer.get(), kBigEnough, cb2.callback()); |
157 rv = cb2.WaitForResult(); | 185 rv = cb2.WaitForResult(); |
158 ASSERT_EQ(static_cast<int>(expected.body.length()), rv); | 186 ASSERT_EQ(static_cast<int>(expected.body.length()), rv); |
159 EXPECT_EQ(0, memcmp(expected.body.data(), body_buffer->data(), rv)); | 187 EXPECT_EQ(0, memcmp(expected.body.data(), body_buffer->data(), rv)); |
160 } | 188 } |
161 | 189 |
162 void Migrate() { | |
163 base::RunLoop run_loop; | |
164 migrator_->Start(base::Bind(&OnDiskCacheMigrated, run_loop.QuitClosure())); | |
165 run_loop.Run(); | |
166 } | |
167 | |
168 int32 GetEntryCount(ServiceWorkerDiskCache* disk_cache) { | 190 int32 GetEntryCount(ServiceWorkerDiskCache* disk_cache) { |
169 return disk_cache->disk_cache()->GetEntryCount(); | 191 return disk_cache->disk_cache()->GetEntryCount(); |
170 } | 192 } |
171 | 193 |
172 void SetMaxNumberOfInflightTasks(size_t max_number) { | 194 ServiceWorkerStorage* storage() { return context_->storage(); } |
173 migrator_->set_max_number_of_inflight_tasks(max_number); | |
174 } | |
175 | 195 |
176 protected: | 196 private: |
177 TestBrowserThreadBundle browser_thread_bundle_; | 197 TestBrowserThreadBundle browser_thread_bundle_; |
178 base::ScopedTempDir user_data_directory_; | 198 base::ScopedTempDir user_data_directory_; |
179 scoped_ptr<ServiceWorkerDiskCache> src_; | 199 |
180 scoped_ptr<ServiceWorkerDiskCache> dest_; | 200 scoped_ptr<ServiceWorkerContextCore> context_; |
181 scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator_; | |
182 }; | 201 }; |
183 | 202 |
184 TEST_F(ServiceWorkerDiskCacheMigratorTest, Basic) { | 203 TEST_F(ServiceWorkerDiskCacheMigratorTest, MigrateDiskCache) { |
185 std::vector<ResponseData> responses; | 204 std::vector<ResponseData> responses; |
186 responses.push_back(ResponseData(1, "HTTP/1.1 200 OK\0\0", "Hello", "")); | 205 responses.push_back(ResponseData(1, "HTTP/1.1 200 OK\0\0", "Hello", "")); |
187 responses.push_back(ResponseData(2, "HTTP/1.1 200 OK\0\0", "Service", "")); | 206 responses.push_back(ResponseData(2, "HTTP/1.1 200 OK\0\0", "Service", "")); |
188 responses.push_back(ResponseData(5, "HTTP/1.1 200 OK\0\0", "Worker", "")); | 207 responses.push_back(ResponseData(5, "HTTP/1.1 200 OK\0\0", "Worker", "")); |
189 responses.push_back(ResponseData(3, "HTTP/1.1 200 OK\0\0", "World", "meta")); | 208 responses.push_back(ResponseData(3, "HTTP/1.1 200 OK\0\0", "World", "meta")); |
190 responses.push_back(ResponseData(10, "HTTP/1.1 200 OK\0\0", "", "meta")); | 209 responses.push_back(ResponseData(10, "HTTP/1.1 200 OK\0\0", "", "meta")); |
191 responses.push_back(ResponseData(11, "HTTP/1.1 200 OK\0\0", "body", "")); | 210 responses.push_back(ResponseData(11, "HTTP/1.1 200 OK\0\0", "body", "")); |
192 responses.push_back(ResponseData(12, "HTTP/1.1 200 OK\0\0", "", "")); | 211 responses.push_back(ResponseData(12, "HTTP/1.1 200 OK\0\0", "", "")); |
193 responses.push_back(ResponseData( | 212 responses.push_back(ResponseData( |
194 20, "HTTP/1.1 200 OK\0\0", std::string(256, 'a'), std::string(128, 'b'))); | 213 20, "HTTP/1.1 200 OK\0\0", std::string(256, 'a'), std::string(128, 'b'))); |
195 | 214 |
196 // Populate initial data in the src diskcache. | 215 // Populate initial data in the src diskcache. |
| 216 scoped_ptr<ServiceWorkerDiskCache> src(CreateSrcDiskCache()); |
197 for (const ResponseData& response : responses) { | 217 for (const ResponseData& response : responses) { |
198 ASSERT_TRUE(WriteResponse(src_.get(), response)); | 218 ASSERT_TRUE(WriteResponse(src.get(), response)); |
199 VerifyResponse(src_.get(), response); | 219 VerifyResponse(src.get(), response); |
200 } | 220 } |
201 ASSERT_EQ(static_cast<int>(responses.size()), GetEntryCount(src_.get())); | 221 ASSERT_EQ(static_cast<int>(responses.size()), GetEntryCount(src.get())); |
| 222 src.reset(); |
202 | 223 |
203 Migrate(); | 224 // Start the migrator. |
| 225 base::RunLoop run_loop; |
| 226 scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator(CreateMigrator()); |
| 227 migrator->Start(base::Bind(&OnDiskCacheMigrated, run_loop.QuitClosure())); |
| 228 run_loop.Run(); |
204 | 229 |
205 // Verify the migrated contents in the dest diskcache. | 230 // Verify the migrated contents in the dest diskcache. |
| 231 scoped_ptr<ServiceWorkerDiskCache> dest(CreateDestDiskCache()); |
206 for (const ResponseData& response : responses) | 232 for (const ResponseData& response : responses) |
207 VerifyResponse(dest_.get(), response); | 233 VerifyResponse(dest.get(), response); |
208 EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(dest_.get())); | 234 EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(dest.get())); |
209 } | 235 } |
210 | 236 |
211 TEST_F(ServiceWorkerDiskCacheMigratorTest, MigrateEmptyDiskCache) { | 237 TEST_F(ServiceWorkerDiskCacheMigratorTest, MigrateEmptyDiskCache) { |
212 ASSERT_EQ(0, GetEntryCount(src_.get())); | 238 scoped_ptr<ServiceWorkerDiskCache> src(CreateSrcDiskCache()); |
213 Migrate(); | 239 ASSERT_EQ(0, GetEntryCount(src.get())); |
214 EXPECT_EQ(0, GetEntryCount(dest_.get())); | 240 src.reset(); |
| 241 |
| 242 // Start the migrator. |
| 243 base::RunLoop run_loop; |
| 244 scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator(CreateMigrator()); |
| 245 migrator->Start(base::Bind(&OnDiskCacheMigrated, run_loop.QuitClosure())); |
| 246 run_loop.Run(); |
| 247 |
| 248 scoped_ptr<ServiceWorkerDiskCache> dest(CreateDestDiskCache()); |
| 249 ASSERT_EQ(0, GetEntryCount(dest.get())); |
| 250 } |
| 251 |
| 252 // Tests that the migrator properly removes existing resources in the dest |
| 253 // diskcache before starting the migration. |
| 254 TEST_F(ServiceWorkerDiskCacheMigratorTest, RemoveExistingResourcesFromDest) { |
| 255 std::vector<ResponseData> responses1; |
| 256 responses1.push_back(ResponseData(1, "HTTP/1.1 200 OK\0\0", "Hello", "")); |
| 257 responses1.push_back(ResponseData(3, "HTTP/1.1 200 OK\0\0", "World", "")); |
| 258 |
| 259 std::vector<ResponseData> responses2; |
| 260 responses2.push_back(ResponseData(10, "HTTP/1.1 200 OK\0\0", "Hello", "")); |
| 261 responses2.push_back(ResponseData(11, "HTTP/1.1 200 OK\0\0", "Service", "")); |
| 262 responses2.push_back(ResponseData(12, "HTTP/1.1 200 OK\0\0", "", "Worker")); |
| 263 |
| 264 // Populate initial resources in the src diskcache. |
| 265 scoped_ptr<ServiceWorkerDiskCache> src(CreateSrcDiskCache()); |
| 266 for (const ResponseData& response : responses1) { |
| 267 ASSERT_TRUE(WriteResponse(src.get(), response)); |
| 268 VerifyResponse(src.get(), response); |
| 269 } |
| 270 ASSERT_EQ(static_cast<int>(responses1.size()), GetEntryCount(src.get())); |
| 271 src.reset(); |
| 272 |
| 273 // Populate different resources in the dest diskcache in order to simulate |
| 274 // a previous partial migration. |
| 275 scoped_ptr<ServiceWorkerDiskCache> dest(CreateDestDiskCache()); |
| 276 for (const ResponseData& response : responses2) { |
| 277 ASSERT_TRUE(WriteResponse(dest.get(), response)); |
| 278 VerifyResponse(dest.get(), response); |
| 279 } |
| 280 ASSERT_EQ(static_cast<int>(responses2.size()), GetEntryCount(dest.get())); |
| 281 dest.reset(); |
| 282 |
| 283 // Start the migrator. |
| 284 base::RunLoop run_loop; |
| 285 scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator(CreateMigrator()); |
| 286 migrator->Start(base::Bind(&OnDiskCacheMigrated, run_loop.QuitClosure())); |
| 287 run_loop.Run(); |
| 288 |
| 289 // Verify that only newly migrated resources exist in the dest diskcache. |
| 290 dest = CreateDestDiskCache(); |
| 291 for (const ResponseData& response : responses1) |
| 292 VerifyResponse(dest.get(), response); |
| 293 EXPECT_EQ(static_cast<int>(responses1.size()), GetEntryCount(dest.get())); |
215 } | 294 } |
216 | 295 |
217 TEST_F(ServiceWorkerDiskCacheMigratorTest, ThrottleInflightTasks) { | 296 TEST_F(ServiceWorkerDiskCacheMigratorTest, ThrottleInflightTasks) { |
218 std::vector<ResponseData> responses; | 297 std::vector<ResponseData> responses; |
219 for (int i = 0; i < 10; ++i) | 298 for (int i = 0; i < 10; ++i) |
220 responses.push_back(ResponseData(i, "HTTP/1.1 200 OK\0\0", "foo", "bar")); | 299 responses.push_back(ResponseData(i, "HTTP/1.1 200 OK\0\0", "foo", "bar")); |
221 | 300 |
222 // Populate initial data in the src diskcache. | 301 // Populate initial data in the src diskcache. |
| 302 scoped_ptr<ServiceWorkerDiskCache> src(CreateSrcDiskCache()); |
223 for (const ResponseData& response : responses) { | 303 for (const ResponseData& response : responses) { |
224 ASSERT_TRUE(WriteResponse(src_.get(), response)); | 304 ASSERT_TRUE(WriteResponse(src.get(), response)); |
225 VerifyResponse(src_.get(), response); | 305 VerifyResponse(src.get(), response); |
226 } | 306 } |
227 ASSERT_EQ(static_cast<int>(responses.size()), GetEntryCount(src_.get())); | 307 ASSERT_EQ(static_cast<int>(responses.size()), GetEntryCount(src.get())); |
| 308 src.reset(); |
| 309 |
| 310 scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator(CreateMigrator()); |
228 | 311 |
229 // Tighten the max number of inflight tasks. | 312 // Tighten the max number of inflight tasks. |
230 SetMaxNumberOfInflightTasks(2); | 313 migrator->set_max_number_of_inflight_tasks(2); |
231 | 314 |
232 // Migration should hit the limit, but should successfully complete. | 315 // Migration should hit the limit, but should successfully complete. |
233 Migrate(); | 316 base::RunLoop run_loop; |
| 317 migrator->Start(base::Bind(&OnDiskCacheMigrated, run_loop.QuitClosure())); |
| 318 run_loop.Run(); |
| 319 |
| 320 // Verify the migrated contents in the dest diskcache. |
| 321 scoped_ptr<ServiceWorkerDiskCache> dest(CreateDestDiskCache()); |
| 322 for (const ResponseData& response : responses) |
| 323 VerifyResponse(dest.get(), response); |
| 324 EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(dest.get())); |
| 325 } |
| 326 |
| 327 TEST_F(ServiceWorkerDiskCacheMigratorTest, MigrateOnDiskCacheAccess) { |
| 328 std::vector<ResponseData> responses; |
| 329 responses.push_back(ResponseData(1, "HTTP/1.1 200 OK\0\0", "Hello", "")); |
| 330 responses.push_back(ResponseData(2, "HTTP/1.1 200 OK\0\0", "Service", "")); |
| 331 responses.push_back(ResponseData(5, "HTTP/1.1 200 OK\0\0", "Worker", "")); |
| 332 responses.push_back(ResponseData(3, "HTTP/1.1 200 OK\0\0", "World", "meta")); |
| 333 |
| 334 // Populate initial resources in the src diskcache. |
| 335 scoped_ptr<ServiceWorkerDiskCache> src(CreateSrcDiskCache()); |
| 336 for (const ResponseData& response : responses) { |
| 337 ASSERT_TRUE(WriteResponse(src.get(), response)); |
| 338 VerifyResponse(src.get(), response); |
| 339 } |
| 340 ASSERT_EQ(static_cast<int>(responses.size()), GetEntryCount(src.get())); |
| 341 ASSERT_TRUE(base::DirectoryExists(storage()->GetOldDiskCachePath())); |
| 342 src.reset(); |
| 343 |
| 344 base::RunLoop run_loop; |
| 345 storage()->LazyInitialize(run_loop.QuitClosure()); |
| 346 run_loop.Run(); |
| 347 |
| 348 // Before the migration, the diskcache version should be 0. |
| 349 EXPECT_EQ(0u, storage()->current_disk_cache_version_); |
| 350 |
| 351 // DiskCache access should start the migration. |
| 352 ServiceWorkerDiskCache* dest = storage()->disk_cache(); |
234 | 353 |
235 // Verify the migrated contents in the dest diskcache. | 354 // Verify the migrated contents in the dest diskcache. |
236 for (const ResponseData& response : responses) | 355 for (const ResponseData& response : responses) |
237 VerifyResponse(dest_.get(), response); | 356 VerifyResponse(dest, response); |
238 EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(dest_.get())); | 357 EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(dest)); |
| 358 |
| 359 // The src diskcache should be deleted after the migration. |
| 360 EXPECT_FALSE(base::DirectoryExists(storage()->GetOldDiskCachePath())); |
| 361 |
| 362 // After the migration, the diskcache version should be updated. |
| 363 int64 disk_cache_version = -1; |
| 364 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
| 365 storage()->database_->ReadDiskCacheVersion(&disk_cache_version)); |
| 366 EXPECT_LT(0u, disk_cache_version); |
| 367 EXPECT_EQ(storage()->current_disk_cache_version_, disk_cache_version); |
| 368 |
| 369 // After the migration, purgeable files should be empty. |
| 370 std::vector<std::string> purgeable_files; |
| 371 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
| 372 storage()->database_->GetPurgeableFiles(&purgeable_files)); |
| 373 EXPECT_TRUE(purgeable_files.empty()); |
| 374 } |
| 375 |
| 376 TEST_F(ServiceWorkerDiskCacheMigratorTest, NotMigrateOnDatabaseAccess) { |
| 377 std::vector<ResponseData> responses; |
| 378 responses.push_back(ResponseData(1, "HTTP/1.1 200 OK\0\0", "Hello", "")); |
| 379 responses.push_back(ResponseData(2, "HTTP/1.1 200 OK\0\0", "Service", "")); |
| 380 responses.push_back(ResponseData(5, "HTTP/1.1 200 OK\0\0", "Worker", "")); |
| 381 responses.push_back(ResponseData(3, "HTTP/1.1 200 OK\0\0", "World", "meta")); |
| 382 |
| 383 // Populate initial resources in the src diskcache. |
| 384 scoped_ptr<ServiceWorkerDiskCache> src(CreateSrcDiskCache()); |
| 385 for (const ResponseData& response : responses) { |
| 386 ASSERT_TRUE(WriteResponse(src.get(), response)); |
| 387 VerifyResponse(src.get(), response); |
| 388 } |
| 389 ASSERT_EQ(static_cast<int>(responses.size()), GetEntryCount(src.get())); |
| 390 ASSERT_TRUE(base::DirectoryExists(storage()->GetOldDiskCachePath())); |
| 391 |
| 392 // Database access should not start the migration. |
| 393 base::RunLoop run_loop; |
| 394 storage()->FindRegistrationForDocument( |
| 395 GURL("http://example.com/"), |
| 396 base::Bind(&OnRegistrationFound, run_loop.QuitClosure())); |
| 397 run_loop.Run(); |
| 398 |
| 399 // Verify that the migration didn't happen. |
| 400 scoped_ptr<ServiceWorkerDiskCache> dest(CreateDestDiskCache()); |
| 401 EXPECT_EQ(static_cast<int>(responses.size()), GetEntryCount(src.get())); |
| 402 EXPECT_EQ(0, GetEntryCount(dest.get())); |
| 403 EXPECT_TRUE(base::DirectoryExists(storage()->GetOldDiskCachePath())); |
239 } | 404 } |
240 | 405 |
241 } // namespace content | 406 } // namespace content |
OLD | NEW |