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 "chrome/browser/sync_file_system/local/local_file_sync_status.h" | 5 #include "chrome/browser/sync_file_system/local/local_file_sync_status.h" |
6 | 6 |
| 7 #include "content/public/test/test_browser_thread_bundle.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "url/gurl.h" | 9 #include "url/gurl.h" |
9 | 10 |
10 using storage::FileSystemURL; | 11 using storage::FileSystemURL; |
11 | 12 |
12 namespace sync_file_system { | 13 namespace sync_file_system { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const char kParent[] = "filesystem:http://foo.com/test/dir a"; | 17 const char kParent[] = "filesystem:http://foo.com/test/dir a"; |
17 const char kFile[] = "filesystem:http://foo.com/test/dir a/dir b"; | 18 const char kFile[] = "filesystem:http://foo.com/test/dir a/dir b"; |
18 const char kChild[] = "filesystem:http://foo.com/test/dir a/dir b/file"; | 19 const char kChild[] = "filesystem:http://foo.com/test/dir a/dir b/file"; |
19 const char kHasPeriod[] = "filesystem:http://foo.com/test/dir a.dir b"; | 20 const char kHasPeriod[] = "filesystem:http://foo.com/test/dir a.dir b"; |
20 | 21 |
21 const char kOther1[] = "filesystem:http://foo.com/test/dir b"; | 22 const char kOther1[] = "filesystem:http://foo.com/test/dir b"; |
22 const char kOther2[] = "filesystem:http://foo.com/temporary/dir a"; | 23 const char kOther2[] = "filesystem:http://foo.com/temporary/dir a"; |
23 | 24 |
24 FileSystemURL URL(const char* spec) { | 25 FileSystemURL URL(const char* spec) { |
25 return FileSystemURL::CreateForTest((GURL(spec))); | 26 return FileSystemURL::CreateForTest((GURL(spec))); |
26 } | 27 } |
27 | 28 |
28 } // namespace | 29 } // namespace |
29 | 30 |
30 TEST(LocalFileSyncStatusTest, WritingSimple) { | 31 class LocalFileSyncStatusTest : public testing::Test { |
| 32 public: |
| 33 LocalFileSyncStatusTest() |
| 34 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 35 |
| 36 private: |
| 37 content::TestBrowserThreadBundle thread_bundle_; |
| 38 }; |
| 39 |
| 40 TEST_F(LocalFileSyncStatusTest, WritingSimple) { |
31 LocalFileSyncStatus status; | 41 LocalFileSyncStatus status; |
32 | 42 |
33 status.StartWriting(URL(kFile)); | 43 status.StartWriting(URL(kFile)); |
34 status.StartWriting(URL(kFile)); | 44 status.StartWriting(URL(kFile)); |
35 status.EndWriting(URL(kFile)); | 45 status.EndWriting(URL(kFile)); |
36 | 46 |
37 EXPECT_TRUE(status.IsWriting(URL(kFile))); | 47 EXPECT_TRUE(status.IsWriting(URL(kFile))); |
38 EXPECT_TRUE(status.IsWriting(URL(kParent))); | 48 EXPECT_TRUE(status.IsWriting(URL(kParent))); |
39 EXPECT_TRUE(status.IsWriting(URL(kChild))); | 49 EXPECT_TRUE(status.IsWriting(URL(kChild))); |
40 EXPECT_FALSE(status.IsWriting(URL(kOther1))); | 50 EXPECT_FALSE(status.IsWriting(URL(kOther1))); |
(...skipping 13 matching lines...) Expand all Loading... |
54 EXPECT_TRUE(status.IsSyncable(URL(kOther1))); | 64 EXPECT_TRUE(status.IsSyncable(URL(kOther1))); |
55 EXPECT_TRUE(status.IsSyncable(URL(kOther2))); | 65 EXPECT_TRUE(status.IsSyncable(URL(kOther2))); |
56 | 66 |
57 status.EndWriting(URL(kFile)); | 67 status.EndWriting(URL(kFile)); |
58 | 68 |
59 EXPECT_FALSE(status.IsWriting(URL(kFile))); | 69 EXPECT_FALSE(status.IsWriting(URL(kFile))); |
60 EXPECT_FALSE(status.IsWriting(URL(kParent))); | 70 EXPECT_FALSE(status.IsWriting(URL(kParent))); |
61 EXPECT_FALSE(status.IsWriting(URL(kChild))); | 71 EXPECT_FALSE(status.IsWriting(URL(kChild))); |
62 } | 72 } |
63 | 73 |
64 TEST(LocalFileSyncStatusTest, SyncingSimple) { | 74 TEST_F(LocalFileSyncStatusTest, SyncingSimple) { |
65 LocalFileSyncStatus status; | 75 LocalFileSyncStatus status; |
66 | 76 |
67 status.StartSyncing(URL(kFile)); | 77 status.StartSyncing(URL(kFile)); |
68 | 78 |
69 EXPECT_FALSE(status.IsWritable(URL(kFile))); | 79 EXPECT_FALSE(status.IsWritable(URL(kFile))); |
70 EXPECT_FALSE(status.IsWritable(URL(kParent))); | 80 EXPECT_FALSE(status.IsWritable(URL(kParent))); |
71 EXPECT_FALSE(status.IsWritable(URL(kChild))); | 81 EXPECT_FALSE(status.IsWritable(URL(kChild))); |
72 EXPECT_TRUE(status.IsWritable(URL(kOther1))); | 82 EXPECT_TRUE(status.IsWritable(URL(kOther1))); |
73 EXPECT_TRUE(status.IsWritable(URL(kOther2))); | 83 EXPECT_TRUE(status.IsWritable(URL(kOther2))); |
74 | 84 |
75 // New sync cannot be started for entries that are already in syncing. | 85 // New sync cannot be started for entries that are already in syncing. |
76 EXPECT_FALSE(status.IsSyncable(URL(kFile))); | 86 EXPECT_FALSE(status.IsSyncable(URL(kFile))); |
77 EXPECT_FALSE(status.IsSyncable(URL(kParent))); | 87 EXPECT_FALSE(status.IsSyncable(URL(kParent))); |
78 EXPECT_FALSE(status.IsSyncable(URL(kChild))); | 88 EXPECT_FALSE(status.IsSyncable(URL(kChild))); |
79 EXPECT_TRUE(status.IsSyncable(URL(kOther1))); | 89 EXPECT_TRUE(status.IsSyncable(URL(kOther1))); |
80 EXPECT_TRUE(status.IsSyncable(URL(kOther2))); | 90 EXPECT_TRUE(status.IsSyncable(URL(kOther2))); |
81 | 91 |
82 status.EndSyncing(URL(kFile)); | 92 status.EndSyncing(URL(kFile)); |
83 | 93 |
84 EXPECT_TRUE(status.IsWritable(URL(kFile))); | 94 EXPECT_TRUE(status.IsWritable(URL(kFile))); |
85 EXPECT_TRUE(status.IsWritable(URL(kParent))); | 95 EXPECT_TRUE(status.IsWritable(URL(kParent))); |
86 EXPECT_TRUE(status.IsWritable(URL(kChild))); | 96 EXPECT_TRUE(status.IsWritable(URL(kChild))); |
87 } | 97 } |
88 | 98 |
89 TEST(LocalFileSyncStatusTest, WritingOnPathsWithPeriod) { | 99 TEST_F(LocalFileSyncStatusTest, WritingOnPathsWithPeriod) { |
90 LocalFileSyncStatus status; | 100 LocalFileSyncStatus status; |
91 | 101 |
92 status.StartWriting(URL(kParent)); | 102 status.StartWriting(URL(kParent)); |
93 status.StartWriting(URL(kHasPeriod)); | 103 status.StartWriting(URL(kHasPeriod)); |
94 | 104 |
95 EXPECT_TRUE(status.IsChildOrParentWriting(URL(kFile))); | 105 EXPECT_TRUE(status.IsChildOrParentWriting(URL(kFile))); |
96 | 106 |
97 status.EndWriting(URL(kParent)); | 107 status.EndWriting(URL(kParent)); |
98 status.StartWriting(URL(kFile)); | 108 status.StartWriting(URL(kFile)); |
99 | 109 |
100 EXPECT_TRUE(status.IsChildOrParentWriting(URL(kParent))); | 110 EXPECT_TRUE(status.IsChildOrParentWriting(URL(kParent))); |
101 } | 111 } |
102 | 112 |
103 TEST(LocalFileSyncStatusTest, SyncingOnPathsWithPeriod) { | 113 TEST_F(LocalFileSyncStatusTest, SyncingOnPathsWithPeriod) { |
104 LocalFileSyncStatus status; | 114 LocalFileSyncStatus status; |
105 | 115 |
106 status.StartSyncing(URL(kParent)); | 116 status.StartSyncing(URL(kParent)); |
107 status.StartSyncing(URL(kHasPeriod)); | 117 status.StartSyncing(URL(kHasPeriod)); |
108 | 118 |
109 EXPECT_TRUE(status.IsChildOrParentSyncing(URL(kFile))); | 119 EXPECT_TRUE(status.IsChildOrParentSyncing(URL(kFile))); |
110 | 120 |
111 status.EndSyncing(URL(kParent)); | 121 status.EndSyncing(URL(kParent)); |
112 status.StartSyncing(URL(kFile)); | 122 status.StartSyncing(URL(kFile)); |
113 | 123 |
114 EXPECT_TRUE(status.IsChildOrParentSyncing(URL(kParent))); | 124 EXPECT_TRUE(status.IsChildOrParentSyncing(URL(kParent))); |
115 } | 125 } |
116 | 126 |
117 } // namespace sync_file_system | 127 } // namespace sync_file_system |
OLD | NEW |