OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using ::testing::_; | 31 using ::testing::_; |
32 using ::testing::AtLeast; | 32 using ::testing::AtLeast; |
33 using ::testing::InvokeWithoutArgs; | 33 using ::testing::InvokeWithoutArgs; |
34 using ::testing::StrictMock; | 34 using ::testing::StrictMock; |
35 | 35 |
36 namespace sync_file_system { | 36 namespace sync_file_system { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char kOrigin[] = "http://example.com"; | 40 const char kOrigin[] = "http://example.com"; |
41 const char kServiceName[] = "test"; | |
42 | 41 |
43 void DidPrepareForProcessRemoteChange(const tracked_objects::Location& where, | 42 void DidPrepareForProcessRemoteChange(const tracked_objects::Location& where, |
44 const base::Closure& oncompleted, | 43 const base::Closure& oncompleted, |
45 SyncStatusCode expected_status, | 44 SyncStatusCode expected_status, |
46 const SyncFileMetadata& expected_metadata, | 45 const SyncFileMetadata& expected_metadata, |
47 SyncStatusCode status, | 46 SyncStatusCode status, |
48 const SyncFileMetadata& metadata, | 47 const SyncFileMetadata& metadata, |
49 const FileChangeList& changes) { | 48 const FileChangeList& changes) { |
50 SCOPED_TRACE(testing::Message() << where.ToString()); | 49 SCOPED_TRACE(testing::Message() << where.ToString()); |
51 ASSERT_EQ(expected_status, status); | 50 ASSERT_EQ(expected_status, status); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 LocalFileSyncServiceTest() : num_changes_(0) {} | 98 LocalFileSyncServiceTest() : num_changes_(0) {} |
100 | 99 |
101 virtual ~LocalFileSyncServiceTest() {} | 100 virtual ~LocalFileSyncServiceTest() {} |
102 | 101 |
103 virtual void SetUp() OVERRIDE { | 102 virtual void SetUp() OVERRIDE { |
104 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 103 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
105 | 104 |
106 thread_helper_.SetUp(); | 105 thread_helper_.SetUp(); |
107 | 106 |
108 file_system_.reset(new CannedSyncableFileSystem( | 107 file_system_.reset(new CannedSyncableFileSystem( |
109 GURL(kOrigin), kServiceName, | 108 GURL(kOrigin), |
110 thread_helper_.io_task_runner(), | 109 thread_helper_.io_task_runner(), |
111 thread_helper_.file_task_runner())); | 110 thread_helper_.file_task_runner())); |
112 | 111 |
113 local_service_.reset(new LocalFileSyncService(&profile_)); | 112 local_service_.reset(new LocalFileSyncService(&profile_)); |
114 | 113 |
115 file_system_->SetUp(); | 114 file_system_->SetUp(); |
116 | 115 |
117 base::RunLoop run_loop; | 116 base::RunLoop run_loop; |
118 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 117 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
119 local_service_->MaybeInitializeFileSystemContext( | 118 local_service_->MaybeInitializeFileSystemContext( |
120 GURL(kOrigin), kServiceName, file_system_->file_system_context(), | 119 GURL(kOrigin), file_system_->file_system_context(), |
121 AssignAndQuitCallback(&run_loop, &status)); | 120 AssignAndQuitCallback(&run_loop, &status)); |
122 run_loop.Run(); | 121 run_loop.Run(); |
123 | 122 |
124 local_service_->AddChangeObserver(this); | 123 local_service_->AddChangeObserver(this); |
125 | 124 |
126 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem()); | 125 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->OpenFileSystem()); |
127 | 126 |
128 file_system_->file_system_context()->sync_context()-> | 127 file_system_->file_system_context()->sync_context()-> |
129 set_mock_notify_changes_duration_in_sec(0); | 128 set_mock_notify_changes_duration_in_sec(0); |
130 } | 129 } |
131 | 130 |
132 virtual void TearDown() OVERRIDE { | 131 virtual void TearDown() OVERRIDE { |
133 local_service_->Shutdown(); | 132 local_service_->Shutdown(); |
134 file_system_->TearDown(); | 133 file_system_->TearDown(); |
135 RevokeSyncableFileSystem(kServiceName); | 134 RevokeSyncableFileSystem(); |
136 | 135 |
137 thread_helper_.TearDown(); | 136 thread_helper_.TearDown(); |
138 } | 137 } |
139 | 138 |
140 // LocalChangeObserver overrides. | 139 // LocalChangeObserver overrides. |
141 virtual void OnLocalChangeAvailable(int64 num_changes) OVERRIDE { | 140 virtual void OnLocalChangeAvailable(int64 num_changes) OVERRIDE { |
142 num_changes_ = num_changes; | 141 num_changes_ = num_changes; |
143 } | 142 } |
144 | 143 |
145 void PrepareForProcessRemoteChange( | 144 void PrepareForProcessRemoteChange( |
146 const FileSystemURL& url, | 145 const FileSystemURL& url, |
147 const tracked_objects::Location& where, | 146 const tracked_objects::Location& where, |
148 SyncStatusCode expected_status, | 147 SyncStatusCode expected_status, |
149 const SyncFileMetadata& expected_metadata) { | 148 const SyncFileMetadata& expected_metadata) { |
150 base::RunLoop run_loop; | 149 base::RunLoop run_loop; |
151 local_service_->PrepareForProcessRemoteChange( | 150 local_service_->PrepareForProcessRemoteChange( |
152 url, | 151 url, |
153 kServiceName, | |
154 base::Bind(&DidPrepareForProcessRemoteChange, | 152 base::Bind(&DidPrepareForProcessRemoteChange, |
155 where, | 153 where, |
156 run_loop.QuitClosure(), | 154 run_loop.QuitClosure(), |
157 expected_status, | 155 expected_status, |
158 expected_metadata)); | 156 expected_metadata)); |
159 run_loop.Run(); | 157 run_loop.Run(); |
160 } | 158 } |
161 | 159 |
162 SyncStatusCode ApplyRemoteChange(const FileChange& change, | 160 SyncStatusCode ApplyRemoteChange(const FileChange& change, |
163 const base::FilePath& local_path, | 161 const base::FilePath& local_path, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 #define MAYBE_LocalChangeObserverMultipleContexts\ | 270 #define MAYBE_LocalChangeObserverMultipleContexts\ |
273 DISABLED_LocalChangeObserverMultipleContexts | 271 DISABLED_LocalChangeObserverMultipleContexts |
274 #else | 272 #else |
275 #define MAYBE_LocalChangeObserverMultipleContexts\ | 273 #define MAYBE_LocalChangeObserverMultipleContexts\ |
276 LocalChangeObserverMultipleContexts | 274 LocalChangeObserverMultipleContexts |
277 #endif | 275 #endif |
278 | 276 |
279 TEST_F(LocalFileSyncServiceTest, MAYBE_LocalChangeObserverMultipleContexts) { | 277 TEST_F(LocalFileSyncServiceTest, MAYBE_LocalChangeObserverMultipleContexts) { |
280 const char kOrigin2[] = "http://foo"; | 278 const char kOrigin2[] = "http://foo"; |
281 CannedSyncableFileSystem file_system2(GURL(kOrigin2), | 279 CannedSyncableFileSystem file_system2(GURL(kOrigin2), |
282 kServiceName, | |
283 thread_helper_.io_task_runner(), | 280 thread_helper_.io_task_runner(), |
284 thread_helper_.file_task_runner()); | 281 thread_helper_.file_task_runner()); |
285 file_system2.SetUp(); | 282 file_system2.SetUp(); |
286 | 283 |
287 base::RunLoop run_loop; | 284 base::RunLoop run_loop; |
288 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 285 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
289 local_service_->MaybeInitializeFileSystemContext( | 286 local_service_->MaybeInitializeFileSystemContext( |
290 GURL(kOrigin2), kServiceName, file_system2.file_system_context(), | 287 GURL(kOrigin2), file_system2.file_system_context(), |
291 AssignAndQuitCallback(&run_loop, &status)); | 288 AssignAndQuitCallback(&run_loop, &status)); |
292 run_loop.Run(); | 289 run_loop.Run(); |
293 | 290 |
294 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); | 291 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); |
295 file_system2.file_system_context()->sync_context()-> | 292 file_system2.file_system_context()->sync_context()-> |
296 set_mock_notify_changes_duration_in_sec(0); | 293 set_mock_notify_changes_duration_in_sec(0); |
297 | 294 |
298 const FileSystemURL kFile1(file_system_->URL("file1")); | 295 const FileSystemURL kFile1(file_system_->URL("file1")); |
299 const FileSystemURL kFile2(file_system_->URL("file2")); | 296 const FileSystemURL kFile2(file_system_->URL("file2")); |
300 const FileSystemURL kFile3(file_system2.URL("file3")); | 297 const FileSystemURL kFile3(file_system2.URL("file3")); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 all_origins.insert(kOrigin2); | 695 all_origins.insert(kOrigin2); |
699 all_origins.insert(kOrigin3); | 696 all_origins.insert(kOrigin3); |
700 while (!all_origins.empty()) { | 697 while (!all_origins.empty()) { |
701 ASSERT_TRUE(NextOriginToProcess(&origin)); | 698 ASSERT_TRUE(NextOriginToProcess(&origin)); |
702 ASSERT_TRUE(ContainsKey(all_origins, origin)); | 699 ASSERT_TRUE(ContainsKey(all_origins, origin)); |
703 all_origins.erase(origin); | 700 all_origins.erase(origin); |
704 } | 701 } |
705 } | 702 } |
706 | 703 |
707 } // namespace sync_file_system | 704 } // namespace sync_file_system |
OLD | NEW |