Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync_file_system / local / local_file_sync_status_unittest.cc
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.
4
5 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h"
6
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h"
10
11 using storage::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 const char kHasPeriod[]   = "filesystem:http://foo.com/test/dir a.dir b";
21
22 const char kOther1[] = "filesystem:http://foo.com/test/dir b";
23 const char kOther2[] = "filesystem:http://foo.com/temporary/dir a";
24
25 FileSystemURL URL(const char* spec) {
26   return FileSystemURL::CreateForTest((GURL(spec)));
27 }
28
29 }  // namespace
30
31 TEST(LocalFileSyncStatusTest, WritingSimple) {
32   LocalFileSyncStatus status;
33
34   status.StartWriting(URL(kFile));
35   status.StartWriting(URL(kFile));
36   status.EndWriting(URL(kFile));
37
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)));
43
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)));
50
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)));
57
58   status.EndWriting(URL(kFile));
59
60   EXPECT_FALSE(status.IsWriting(URL(kFile)));
61   EXPECT_FALSE(status.IsWriting(URL(kParent)));
62   EXPECT_FALSE(status.IsWriting(URL(kChild)));
63 }
64
65 TEST(LocalFileSyncStatusTest, SyncingSimple) {
66   LocalFileSyncStatus status;
67
68   status.StartSyncing(URL(kFile));
69
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)));
75
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)));
82
83   status.EndSyncing(URL(kFile));
84
85   EXPECT_TRUE(status.IsWritable(URL(kFile)));
86   EXPECT_TRUE(status.IsWritable(URL(kParent)));
87   EXPECT_TRUE(status.IsWritable(URL(kChild)));
88 }
89
90 TEST(LocalFileSyncStatusTest, WritingOnPathsWithPeriod) {
91   LocalFileSyncStatus status;
92
93   status.StartWriting(URL(kParent));
94   status.StartWriting(URL(kHasPeriod));
95
96   EXPECT_TRUE(status.IsChildOrParentWriting(URL(kFile)));
97
98   status.EndWriting(URL(kParent));
99   status.StartWriting(URL(kFile));
100
101   EXPECT_TRUE(status.IsChildOrParentWriting(URL(kParent)));
102 }
103
104 TEST(LocalFileSyncStatusTest, SyncingOnPathsWithPeriod) {
105   LocalFileSyncStatus status;
106
107   status.StartSyncing(URL(kParent));
108   status.StartSyncing(URL(kHasPeriod));
109
110   EXPECT_TRUE(status.IsChildOrParentSyncing(URL(kFile)));
111
112   status.EndSyncing(URL(kParent));
113   status.StartSyncing(URL(kFile));
114
115   EXPECT_TRUE(status.IsChildOrParentSyncing(URL(kParent)));
116 }
117
118 }  // namespace sync_file_system