OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "webkit/browser/fileapi/syncable/local_file_sync_context.h" | 5 #include "webkit/browser/fileapi/syncable/local_file_sync_context.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 scoped_refptr<LocalFileSyncContext> sync_context_; | 201 scoped_refptr<LocalFileSyncContext> sync_context_; |
202 | 202 |
203 SyncStatusCode status_; | 203 SyncStatusCode status_; |
204 base::PlatformFileError file_error_; | 204 base::PlatformFileError file_error_; |
205 bool async_modify_finished_; | 205 bool async_modify_finished_; |
206 bool has_inflight_prepare_for_sync_; | 206 bool has_inflight_prepare_for_sync_; |
207 }; | 207 }; |
208 | 208 |
209 TEST_F(LocalFileSyncContextTest, ConstructAndDestruct) { | 209 TEST_F(LocalFileSyncContextTest, ConstructAndDestruct) { |
210 sync_context_ = new LocalFileSyncContext( | 210 sync_context_ = |
211 ui_task_runner_, io_task_runner_); | 211 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); |
212 sync_context_->ShutdownOnUIThread(); | 212 sync_context_->ShutdownOnUIThread(); |
213 } | 213 } |
214 | 214 |
215 TEST_F(LocalFileSyncContextTest, InitializeFileSystemContext) { | 215 TEST_F(LocalFileSyncContextTest, InitializeFileSystemContext) { |
216 CannedSyncableFileSystem file_system(GURL(kOrigin1), kServiceName, | 216 CannedSyncableFileSystem file_system(GURL(kOrigin1), |
217 io_task_runner_, file_task_runner_); | 217 kServiceName, |
| 218 io_task_runner_.get(), |
| 219 file_task_runner_.get()); |
218 file_system.SetUp(); | 220 file_system.SetUp(); |
219 | 221 |
220 sync_context_ = new LocalFileSyncContext(ui_task_runner_, io_task_runner_); | 222 sync_context_ = |
| 223 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); |
221 | 224 |
222 // Initializes file_system using |sync_context_|. | 225 // Initializes file_system using |sync_context_|. |
223 EXPECT_EQ(SYNC_STATUS_OK, | 226 EXPECT_EQ(SYNC_STATUS_OK, |
224 file_system.MaybeInitializeFileSystemContext(sync_context_)); | 227 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
225 | 228 |
226 // Make sure everything's set up for file_system to be able to handle | 229 // Make sure everything's set up for file_system to be able to handle |
227 // syncable file system operations. | 230 // syncable file system operations. |
228 EXPECT_TRUE(file_system.file_system_context()->sync_context() != NULL); | 231 EXPECT_TRUE(file_system.file_system_context()->sync_context() != NULL); |
229 EXPECT_TRUE(file_system.file_system_context()->change_tracker() != NULL); | 232 EXPECT_TRUE(file_system.file_system_context()->change_tracker() != NULL); |
230 EXPECT_EQ(sync_context_.get(), | 233 EXPECT_EQ(sync_context_.get(), |
231 file_system.file_system_context()->sync_context()); | 234 file_system.file_system_context()->sync_context()); |
232 | 235 |
233 // Calling MaybeInitialize for the same context multiple times must be ok. | 236 // Calling MaybeInitialize for the same context multiple times must be ok. |
234 EXPECT_EQ(SYNC_STATUS_OK, | 237 EXPECT_EQ(SYNC_STATUS_OK, |
235 file_system.MaybeInitializeFileSystemContext(sync_context_)); | 238 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
236 EXPECT_EQ(sync_context_.get(), | 239 EXPECT_EQ(sync_context_.get(), |
237 file_system.file_system_context()->sync_context()); | 240 file_system.file_system_context()->sync_context()); |
238 | 241 |
239 // Opens the file_system, perform some operation and see if the change tracker | 242 // Opens the file_system, perform some operation and see if the change tracker |
240 // correctly captures the change. | 243 // correctly captures the change. |
241 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); | 244 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); |
242 | 245 |
243 const FileSystemURL kURL(file_system.URL("foo")); | 246 const FileSystemURL kURL(file_system.URL("foo")); |
244 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL)); | 247 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL)); |
245 | 248 |
246 FileSystemURLSet urls; | 249 FileSystemURLSet urls; |
247 file_system.GetChangedURLsInTracker(&urls); | 250 file_system.GetChangedURLsInTracker(&urls); |
248 ASSERT_EQ(1U, urls.size()); | 251 ASSERT_EQ(1U, urls.size()); |
249 EXPECT_TRUE(ContainsKey(urls, kURL)); | 252 EXPECT_TRUE(ContainsKey(urls, kURL)); |
250 | 253 |
251 // Finishing the test. | 254 // Finishing the test. |
252 sync_context_->ShutdownOnUIThread(); | 255 sync_context_->ShutdownOnUIThread(); |
253 file_system.TearDown(); | 256 file_system.TearDown(); |
254 } | 257 } |
255 | 258 |
256 TEST_F(LocalFileSyncContextTest, MultipleFileSystemContexts) { | 259 TEST_F(LocalFileSyncContextTest, MultipleFileSystemContexts) { |
257 CannedSyncableFileSystem file_system1(GURL(kOrigin1), kServiceName, | 260 CannedSyncableFileSystem file_system1(GURL(kOrigin1), |
258 io_task_runner_, file_task_runner_); | 261 kServiceName, |
259 CannedSyncableFileSystem file_system2(GURL(kOrigin2), kServiceName, | 262 io_task_runner_.get(), |
260 io_task_runner_, file_task_runner_); | 263 file_task_runner_.get()); |
| 264 CannedSyncableFileSystem file_system2(GURL(kOrigin2), |
| 265 kServiceName, |
| 266 io_task_runner_.get(), |
| 267 file_task_runner_.get()); |
261 file_system1.SetUp(); | 268 file_system1.SetUp(); |
262 file_system2.SetUp(); | 269 file_system2.SetUp(); |
263 | 270 |
264 sync_context_ = new LocalFileSyncContext(ui_task_runner_, io_task_runner_); | 271 sync_context_ = |
| 272 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); |
265 | 273 |
266 // Initializes file_system1 and file_system2. | 274 // Initializes file_system1 and file_system2. |
267 EXPECT_EQ(SYNC_STATUS_OK, | 275 EXPECT_EQ(SYNC_STATUS_OK, |
268 file_system1.MaybeInitializeFileSystemContext(sync_context_)); | 276 file_system1.MaybeInitializeFileSystemContext(sync_context_.get())); |
269 EXPECT_EQ(SYNC_STATUS_OK, | 277 EXPECT_EQ(SYNC_STATUS_OK, |
270 file_system2.MaybeInitializeFileSystemContext(sync_context_)); | 278 file_system2.MaybeInitializeFileSystemContext(sync_context_.get())); |
271 | 279 |
272 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.OpenFileSystem()); | 280 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.OpenFileSystem()); |
273 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); | 281 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); |
274 | 282 |
275 const FileSystemURL kURL1(file_system1.URL("foo")); | 283 const FileSystemURL kURL1(file_system1.URL("foo")); |
276 const FileSystemURL kURL2(file_system2.URL("bar")); | 284 const FileSystemURL kURL2(file_system2.URL("bar")); |
277 | 285 |
278 // Creates a file in file_system1. | 286 // Creates a file in file_system1. |
279 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.CreateFile(kURL1)); | 287 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.CreateFile(kURL1)); |
280 | 288 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 341 } |
334 | 342 |
335 // LocalFileSyncContextTest.PrepareSyncWhileWriting is flaky on android. | 343 // LocalFileSyncContextTest.PrepareSyncWhileWriting is flaky on android. |
336 // http://crbug.com/239793 | 344 // http://crbug.com/239793 |
337 #if defined(OS_ANDROID) | 345 #if defined(OS_ANDROID) |
338 #define MAYBE_PrepareSyncWhileWriting DISABLED_PrepareSyncWhileWriting | 346 #define MAYBE_PrepareSyncWhileWriting DISABLED_PrepareSyncWhileWriting |
339 #else | 347 #else |
340 #define MAYBE_PrepareSyncWhileWriting PrepareSyncWhileWriting | 348 #define MAYBE_PrepareSyncWhileWriting PrepareSyncWhileWriting |
341 #endif | 349 #endif |
342 TEST_F(LocalFileSyncContextTest, MAYBE_PrepareSyncWhileWriting) { | 350 TEST_F(LocalFileSyncContextTest, MAYBE_PrepareSyncWhileWriting) { |
343 CannedSyncableFileSystem file_system(GURL(kOrigin1), kServiceName, | 351 CannedSyncableFileSystem file_system(GURL(kOrigin1), |
344 io_task_runner_, file_task_runner_); | 352 kServiceName, |
| 353 io_task_runner_.get(), |
| 354 file_task_runner_.get()); |
345 file_system.SetUp(); | 355 file_system.SetUp(); |
346 sync_context_ = new LocalFileSyncContext(ui_task_runner_, io_task_runner_); | 356 sync_context_ = |
| 357 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); |
347 EXPECT_EQ(SYNC_STATUS_OK, | 358 EXPECT_EQ(SYNC_STATUS_OK, |
348 file_system.MaybeInitializeFileSystemContext(sync_context_)); | 359 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
349 | 360 |
350 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); | 361 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); |
351 | 362 |
352 const FileSystemURL kURL1(file_system.URL("foo")); | 363 const FileSystemURL kURL1(file_system.URL("foo")); |
353 | 364 |
354 // Creates a file in file_system. | 365 // Creates a file in file_system. |
355 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL1)); | 366 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL1)); |
356 | 367 |
357 // Kick file write on IO thread. | 368 // Kick file write on IO thread. |
358 StartModifyFileOnIOThread(&file_system, kURL1); | 369 StartModifyFileOnIOThread(&file_system, kURL1); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); | 401 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); |
391 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type); | 402 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type); |
392 EXPECT_EQ(1, metadata.size); | 403 EXPECT_EQ(1, metadata.size); |
393 | 404 |
394 sync_context_->ShutdownOnUIThread(); | 405 sync_context_->ShutdownOnUIThread(); |
395 sync_context_ = NULL; | 406 sync_context_ = NULL; |
396 file_system.TearDown(); | 407 file_system.TearDown(); |
397 } | 408 } |
398 | 409 |
399 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion) { | 410 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion) { |
400 CannedSyncableFileSystem file_system(GURL(kOrigin1), kServiceName, | 411 CannedSyncableFileSystem file_system(GURL(kOrigin1), |
401 io_task_runner_, file_task_runner_); | 412 kServiceName, |
| 413 io_task_runner_.get(), |
| 414 file_task_runner_.get()); |
402 file_system.SetUp(); | 415 file_system.SetUp(); |
403 | 416 |
404 sync_context_ = new LocalFileSyncContext(ui_task_runner_, io_task_runner_); | 417 sync_context_ = |
| 418 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); |
405 ASSERT_EQ(SYNC_STATUS_OK, | 419 ASSERT_EQ(SYNC_STATUS_OK, |
406 file_system.MaybeInitializeFileSystemContext(sync_context_)); | 420 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
407 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); | 421 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); |
408 | 422 |
409 // Record the initial usage (likely 0). | 423 // Record the initial usage (likely 0). |
410 int64 initial_usage = -1; | 424 int64 initial_usage = -1; |
411 int64 quota = -1; | 425 int64 quota = -1; |
412 EXPECT_EQ(quota::kQuotaStatusOk, | 426 EXPECT_EQ(quota::kQuotaStatusOk, |
413 file_system.GetUsageAndQuota(&initial_usage, "a)); | 427 file_system.GetUsageAndQuota(&initial_usage, "a)); |
414 | 428 |
415 // Create a file and directory in the file_system. | 429 // Create a file and directory in the file_system. |
416 const FileSystemURL kFile(file_system.URL("file")); | 430 const FileSystemURL kFile(file_system.URL("file")); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 491 |
478 sync_context_->ShutdownOnUIThread(); | 492 sync_context_->ShutdownOnUIThread(); |
479 sync_context_ = NULL; | 493 sync_context_ = NULL; |
480 file_system.TearDown(); | 494 file_system.TearDown(); |
481 } | 495 } |
482 | 496 |
483 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate) { | 497 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate) { |
484 base::ScopedTempDir temp_dir; | 498 base::ScopedTempDir temp_dir; |
485 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 499 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
486 | 500 |
487 CannedSyncableFileSystem file_system(GURL(kOrigin1), kServiceName, | 501 CannedSyncableFileSystem file_system(GURL(kOrigin1), |
488 io_task_runner_, file_task_runner_); | 502 kServiceName, |
| 503 io_task_runner_.get(), |
| 504 file_task_runner_.get()); |
489 file_system.SetUp(); | 505 file_system.SetUp(); |
490 | 506 |
491 sync_context_ = new LocalFileSyncContext(ui_task_runner_, io_task_runner_); | 507 sync_context_ = |
| 508 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); |
492 ASSERT_EQ(SYNC_STATUS_OK, | 509 ASSERT_EQ(SYNC_STATUS_OK, |
493 file_system.MaybeInitializeFileSystemContext(sync_context_)); | 510 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
494 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); | 511 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); |
495 | 512 |
496 const FileSystemURL kFile1(file_system.URL("file1")); | 513 const FileSystemURL kFile1(file_system.URL("file1")); |
497 const FileSystemURL kFile2(file_system.URL("file2")); | 514 const FileSystemURL kFile2(file_system.URL("file2")); |
498 const FileSystemURL kDir(file_system.URL("dir")); | 515 const FileSystemURL kDir(file_system.URL("dir")); |
499 | 516 |
500 const char kTestFileData0[] = "0123456789"; | 517 const char kTestFileData0[] = "0123456789"; |
501 const char kTestFileData1[] = "Lorem ipsum!"; | 518 const char kTestFileData1[] = "Lorem ipsum!"; |
502 const char kTestFileData2[] = "This is sample test data."; | 519 const char kTestFileData2[] = "This is sample test data."; |
503 | 520 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); | 641 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); |
625 | 642 |
626 sync_context_->ShutdownOnUIThread(); | 643 sync_context_->ShutdownOnUIThread(); |
627 file_system.TearDown(); | 644 file_system.TearDown(); |
628 } | 645 } |
629 | 646 |
630 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate_NoParent) { | 647 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate_NoParent) { |
631 base::ScopedTempDir temp_dir; | 648 base::ScopedTempDir temp_dir; |
632 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 649 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
633 | 650 |
634 CannedSyncableFileSystem file_system(GURL(kOrigin1), kServiceName, | 651 CannedSyncableFileSystem file_system(GURL(kOrigin1), |
635 io_task_runner_, file_task_runner_); | 652 kServiceName, |
| 653 io_task_runner_.get(), |
| 654 file_task_runner_.get()); |
636 file_system.SetUp(); | 655 file_system.SetUp(); |
637 | 656 |
638 sync_context_ = new LocalFileSyncContext(ui_task_runner_, io_task_runner_); | 657 sync_context_ = |
| 658 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); |
639 ASSERT_EQ(SYNC_STATUS_OK, | 659 ASSERT_EQ(SYNC_STATUS_OK, |
640 file_system.MaybeInitializeFileSystemContext(sync_context_)); | 660 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); |
641 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); | 661 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); |
642 | 662 |
643 const char kTestFileData[] = "Lorem ipsum!"; | 663 const char kTestFileData[] = "Lorem ipsum!"; |
644 const FileSystemURL kDir(file_system.URL("dir")); | 664 const FileSystemURL kDir(file_system.URL("dir")); |
645 const FileSystemURL kFile(file_system.URL("dir/file")); | 665 const FileSystemURL kFile(file_system.URL("dir/file")); |
646 | 666 |
647 // Either kDir or kFile not exist yet. | 667 // Either kDir or kFile not exist yet. |
648 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kDir)); | 668 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kDir)); |
649 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kFile)); | 669 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kFile)); |
650 | 670 |
(...skipping 21 matching lines...) Expand all Loading... |
672 | 692 |
673 // Make sure kDir and kFile are created by ApplyRemoteChange. | 693 // Make sure kDir and kFile are created by ApplyRemoteChange. |
674 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile)); | 694 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile)); |
675 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); | 695 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); |
676 | 696 |
677 sync_context_->ShutdownOnUIThread(); | 697 sync_context_->ShutdownOnUIThread(); |
678 file_system.TearDown(); | 698 file_system.TearDown(); |
679 } | 699 } |
680 | 700 |
681 } // namespace sync_file_system | 701 } // namespace sync_file_system |
OLD | NEW |