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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h"
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
11 using storage::FileSystemURL
;
13 namespace sync_file_system
{
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 const char kHasPeriod
[] = "filesystem:http://foo.com/test/dir a.dir b";
22 const char kOther1
[] = "filesystem:http://foo.com/test/dir b";
23 const char kOther2
[] = "filesystem:http://foo.com/temporary/dir a";
25 FileSystemURL
URL(const char* spec
) {
26 return FileSystemURL::CreateForTest((GURL(spec
)));
31 TEST(LocalFileSyncStatusTest
, WritingSimple
) {
32 LocalFileSyncStatus status
;
34 status
.StartWriting(URL(kFile
));
35 status
.StartWriting(URL(kFile
));
36 status
.EndWriting(URL(kFile
));
38 EXPECT_TRUE(status
.IsWriting(URL(kFile
)));
39 EXPECT_TRUE(status
.IsWriting(URL(kParent
)));
40 EXPECT_TRUE(status
.IsWriting(URL(kChild
)));
41 EXPECT_FALSE(status
.IsWriting(URL(kOther1
)));
42 EXPECT_FALSE(status
.IsWriting(URL(kOther2
)));
44 // Adding writers doesn't change the entry's writability.
45 EXPECT_TRUE(status
.IsWritable(URL(kFile
)));
46 EXPECT_TRUE(status
.IsWritable(URL(kParent
)));
47 EXPECT_TRUE(status
.IsWritable(URL(kChild
)));
48 EXPECT_TRUE(status
.IsWritable(URL(kOther1
)));
49 EXPECT_TRUE(status
.IsWritable(URL(kOther2
)));
51 // Adding writers makes the entry non-syncable.
52 EXPECT_FALSE(status
.IsSyncable(URL(kFile
)));
53 EXPECT_FALSE(status
.IsSyncable(URL(kParent
)));
54 EXPECT_FALSE(status
.IsSyncable(URL(kChild
)));
55 EXPECT_TRUE(status
.IsSyncable(URL(kOther1
)));
56 EXPECT_TRUE(status
.IsSyncable(URL(kOther2
)));
58 status
.EndWriting(URL(kFile
));
60 EXPECT_FALSE(status
.IsWriting(URL(kFile
)));
61 EXPECT_FALSE(status
.IsWriting(URL(kParent
)));
62 EXPECT_FALSE(status
.IsWriting(URL(kChild
)));
65 TEST(LocalFileSyncStatusTest
, SyncingSimple
) {
66 LocalFileSyncStatus status
;
68 status
.StartSyncing(URL(kFile
));
70 EXPECT_FALSE(status
.IsWritable(URL(kFile
)));
71 EXPECT_FALSE(status
.IsWritable(URL(kParent
)));
72 EXPECT_FALSE(status
.IsWritable(URL(kChild
)));
73 EXPECT_TRUE(status
.IsWritable(URL(kOther1
)));
74 EXPECT_TRUE(status
.IsWritable(URL(kOther2
)));
76 // New sync cannot be started for entries that are already in syncing.
77 EXPECT_FALSE(status
.IsSyncable(URL(kFile
)));
78 EXPECT_FALSE(status
.IsSyncable(URL(kParent
)));
79 EXPECT_FALSE(status
.IsSyncable(URL(kChild
)));
80 EXPECT_TRUE(status
.IsSyncable(URL(kOther1
)));
81 EXPECT_TRUE(status
.IsSyncable(URL(kOther2
)));
83 status
.EndSyncing(URL(kFile
));
85 EXPECT_TRUE(status
.IsWritable(URL(kFile
)));
86 EXPECT_TRUE(status
.IsWritable(URL(kParent
)));
87 EXPECT_TRUE(status
.IsWritable(URL(kChild
)));
90 TEST(LocalFileSyncStatusTest
, WritingOnPathsWithPeriod
) {
91 LocalFileSyncStatus status
;
93 status
.StartWriting(URL(kParent
));
94 status
.StartWriting(URL(kHasPeriod
));
96 EXPECT_TRUE(status
.IsChildOrParentWriting(URL(kFile
)));
98 status
.EndWriting(URL(kParent
));
99 status
.StartWriting(URL(kFile
));
101 EXPECT_TRUE(status
.IsChildOrParentWriting(URL(kParent
)));
104 TEST(LocalFileSyncStatusTest
, SyncingOnPathsWithPeriod
) {
105 LocalFileSyncStatus status
;
107 status
.StartSyncing(URL(kParent
));
108 status
.StartSyncing(URL(kHasPeriod
));
110 EXPECT_TRUE(status
.IsChildOrParentSyncing(URL(kFile
)));
112 status
.EndSyncing(URL(kParent
));
113 status
.StartSyncing(URL(kFile
));
115 EXPECT_TRUE(status
.IsChildOrParentSyncing(URL(kParent
)));
118 } // namespace sync_file_system