| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/fileapi/syncable/local_file_sync_status.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "googleurl/src/gurl.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 using fileapi::FileSystemURL; | |
| 12 | |
| 13 namespace sync_file_system { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const char kParent[] = "filesystem:http://foo.com/test/dir a"; | |
| 18 const char kFile[] = "filesystem:http://foo.com/test/dir a/dir b"; | |
| 19 const char kChild[] = "filesystem:http://foo.com/test/dir a/dir b/file"; | |
| 20 | |
| 21 const char kOther1[] = "filesystem:http://foo.com/test/dir b"; | |
| 22 const char kOther2[] = "filesystem:http://foo.com/temporary/dir a"; | |
| 23 | |
| 24 FileSystemURL URL(const char* spec) { | |
| 25 return FileSystemURL::CreateForTest((GURL(spec))); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 TEST(LocalFileSyncStatusTest, WritingSimple) { | |
| 31 LocalFileSyncStatus status; | |
| 32 | |
| 33 status.StartWriting(URL(kFile)); | |
| 34 status.StartWriting(URL(kFile)); | |
| 35 status.EndWriting(URL(kFile)); | |
| 36 | |
| 37 EXPECT_TRUE(status.IsWriting(URL(kFile))); | |
| 38 EXPECT_TRUE(status.IsWriting(URL(kParent))); | |
| 39 EXPECT_TRUE(status.IsWriting(URL(kChild))); | |
| 40 EXPECT_FALSE(status.IsWriting(URL(kOther1))); | |
| 41 EXPECT_FALSE(status.IsWriting(URL(kOther2))); | |
| 42 | |
| 43 // Adding writers doesn't change the entry's writability. | |
| 44 EXPECT_TRUE(status.IsWritable(URL(kFile))); | |
| 45 EXPECT_TRUE(status.IsWritable(URL(kParent))); | |
| 46 EXPECT_TRUE(status.IsWritable(URL(kChild))); | |
| 47 EXPECT_TRUE(status.IsWritable(URL(kOther1))); | |
| 48 EXPECT_TRUE(status.IsWritable(URL(kOther2))); | |
| 49 | |
| 50 // Adding writers makes the entry non-syncable. | |
| 51 EXPECT_FALSE(status.IsSyncable(URL(kFile))); | |
| 52 EXPECT_FALSE(status.IsSyncable(URL(kParent))); | |
| 53 EXPECT_FALSE(status.IsSyncable(URL(kChild))); | |
| 54 EXPECT_TRUE(status.IsSyncable(URL(kOther1))); | |
| 55 EXPECT_TRUE(status.IsSyncable(URL(kOther2))); | |
| 56 | |
| 57 status.EndWriting(URL(kFile)); | |
| 58 | |
| 59 EXPECT_FALSE(status.IsWriting(URL(kFile))); | |
| 60 EXPECT_FALSE(status.IsWriting(URL(kParent))); | |
| 61 EXPECT_FALSE(status.IsWriting(URL(kChild))); | |
| 62 } | |
| 63 | |
| 64 TEST(LocalFileSyncStatusTest, SyncingSimple) { | |
| 65 LocalFileSyncStatus status; | |
| 66 | |
| 67 status.StartSyncing(URL(kFile)); | |
| 68 | |
| 69 EXPECT_FALSE(status.IsWritable(URL(kFile))); | |
| 70 EXPECT_FALSE(status.IsWritable(URL(kParent))); | |
| 71 EXPECT_FALSE(status.IsWritable(URL(kChild))); | |
| 72 EXPECT_TRUE(status.IsWritable(URL(kOther1))); | |
| 73 EXPECT_TRUE(status.IsWritable(URL(kOther2))); | |
| 74 | |
| 75 // New sync cannot be started for entries that are already in syncing. | |
| 76 EXPECT_FALSE(status.IsSyncable(URL(kFile))); | |
| 77 EXPECT_FALSE(status.IsSyncable(URL(kParent))); | |
| 78 EXPECT_FALSE(status.IsSyncable(URL(kChild))); | |
| 79 EXPECT_TRUE(status.IsSyncable(URL(kOther1))); | |
| 80 EXPECT_TRUE(status.IsSyncable(URL(kOther2))); | |
| 81 | |
| 82 status.EndSyncing(URL(kFile)); | |
| 83 | |
| 84 EXPECT_TRUE(status.IsWritable(URL(kFile))); | |
| 85 EXPECT_TRUE(status.IsWritable(URL(kParent))); | |
| 86 EXPECT_TRUE(status.IsWritable(URL(kChild))); | |
| 87 } | |
| 88 | |
| 89 } // namespace sync_file_system | |
| OLD | NEW |