Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_sync_context_unittest.cc

Issue 24106002: Add SNAPSHOT sync mode to LocalFileSyncContext::PrepareForSync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change handling fix Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_context.h" 5 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/platform_file.h" 14 #include "base/platform_file.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
17 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" 18 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
18 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" 19 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
19 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 20 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 const FileSystemURL& url, 79 const FileSystemURL& url,
79 SyncFileMetadata* metadata, 80 SyncFileMetadata* metadata,
80 FileChangeList* changes) { 81 FileChangeList* changes) {
81 ASSERT_TRUE(changes != NULL); 82 ASSERT_TRUE(changes != NULL);
82 ASSERT_FALSE(has_inflight_prepare_for_sync_); 83 ASSERT_FALSE(has_inflight_prepare_for_sync_);
83 status_ = SYNC_STATUS_UNKNOWN; 84 status_ = SYNC_STATUS_UNKNOWN;
84 has_inflight_prepare_for_sync_ = true; 85 has_inflight_prepare_for_sync_ = true;
85 sync_context_->PrepareForSync( 86 sync_context_->PrepareForSync(
86 file_system_context, 87 file_system_context,
87 url, 88 url,
89 LocalFileSyncContext::SYNC_EXCLUSIVE,
88 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync, 90 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync,
89 base::Unretained(this), metadata, changes)); 91 base::Unretained(this), metadata, changes));
90 } 92 }
91 93
92 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context, 94 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context,
93 const FileSystemURL& url, 95 const FileSystemURL& url,
94 SyncFileMetadata* metadata, 96 SyncFileMetadata* metadata,
95 FileChangeList* changes) { 97 FileChangeList* changes) {
96 StartPrepareForSync(file_system_context, url, metadata, changes); 98 StartPrepareForSync(file_system_context, url, metadata, changes);
97 base::MessageLoop::current()->Run(); 99 base::MessageLoop::current()->Run();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 FROM_HERE, 183 FROM_HERE,
182 base::Bind(&LocalFileSyncContextTest::DidModifyFile, 184 base::Bind(&LocalFileSyncContextTest::DidModifyFile,
183 base::Unretained(this), error)); 185 base::Unretained(this), error));
184 return; 186 return;
185 } 187 }
186 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread()); 188 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread());
187 file_error_ = error; 189 file_error_ = error;
188 async_modify_finished_ = true; 190 async_modify_finished_ = true;
189 } 191 }
190 192
193 void SimulateFinishSync(FileSystemContext* file_system_context,
194 const FileSystemURL& url,
195 SyncStatusCode status) {
196 sync_context_->CommitChangeStatusForURL(
197 file_system_context,
198 url,
199 status,
200 base::Bind(&LocalFileSyncContext::ClearSyncFlagForURL,
201 sync_context_, url));
202 base::MessageLoop::current()->RunUntilIdle();
203 }
204
205 void PrepareForSync_Basic(LocalFileSyncContext::SyncMode sync_mode,
206 SyncStatusCode simulate_sync_finish_status) {
207 CannedSyncableFileSystem file_system(GURL(kOrigin1),
208 io_task_runner_.get(),
209 file_task_runner_.get());
210 file_system.SetUp();
211 sync_context_ = new LocalFileSyncContext(
212 ui_task_runner_.get(), io_task_runner_.get());
213 ASSERT_EQ(SYNC_STATUS_OK,
214 file_system.MaybeInitializeFileSystemContext(
215 sync_context_.get()));
216 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem());
217
218 const FileSystemURL kFile(file_system.URL("file"));
219 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile));
220
221 SyncFileMetadata metadata;
222 FileChangeList changes;
223 EXPECT_EQ(SYNC_STATUS_OK,
224 PrepareForSync(file_system.file_system_context(), kFile,
225 &metadata, &changes));
226 EXPECT_EQ(1U, changes.size());
227 EXPECT_TRUE(changes.list().back().IsFile());
228 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
229
230 // We should see the same set of changes.
231 file_system.GetChangesForURLInTracker(kFile, &changes);
232 EXPECT_EQ(1U, changes.size());
233 EXPECT_TRUE(changes.list().back().IsFile());
234 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
235
236 SimulateFinishSync(file_system.file_system_context(), kFile,
237 simulate_sync_finish_status);
238
239 file_system.GetChangesForURLInTracker(kFile, &changes);
240 if (simulate_sync_finish_status == SYNC_STATUS_OK) {
241 // The change's cleared.
242 EXPECT_TRUE(changes.empty());
243 } else {
244 EXPECT_EQ(1U, changes.size());
245 EXPECT_TRUE(changes.list().back().IsFile());
246 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
247 }
248
249 sync_context_->ShutdownOnUIThread();
250 sync_context_ = NULL;
251
252 file_system.TearDown();
253 }
254
191 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; 255 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
192 256
193 // These need to remain until the very end. 257 // These need to remain until the very end.
194 scoped_ptr<base::Thread> io_thread_; 258 scoped_ptr<base::Thread> io_thread_;
195 scoped_ptr<base::Thread> file_thread_; 259 scoped_ptr<base::Thread> file_thread_;
196 base::MessageLoop loop_; 260 base::MessageLoop loop_;
197 261
198 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 262 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
199 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 263 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
200 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 264 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 EXPECT_EQ(SYNC_FILE_TYPE_DIRECTORY, metadata.file_type); 393 EXPECT_EQ(SYNC_FILE_TYPE_DIRECTORY, metadata.file_type);
330 EXPECT_EQ(0, metadata.size); 394 EXPECT_EQ(0, metadata.size);
331 395
332 sync_context_->ShutdownOnUIThread(); 396 sync_context_->ShutdownOnUIThread();
333 sync_context_ = NULL; 397 sync_context_ = NULL;
334 398
335 file_system1.TearDown(); 399 file_system1.TearDown();
336 file_system2.TearDown(); 400 file_system2.TearDown();
337 } 401 }
338 402
403 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncSuccess_Exclusive) {
404 PrepareForSync_Basic(LocalFileSyncContext::SYNC_EXCLUSIVE,
405 SYNC_STATUS_OK);
406 }
407
408 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncSuccess_Snapshot) {
409 PrepareForSync_Basic(LocalFileSyncContext::SYNC_SNAPSHOT,
410 SYNC_STATUS_OK);
411 }
412
413 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncFailure_Exclusive) {
414 PrepareForSync_Basic(LocalFileSyncContext::SYNC_EXCLUSIVE,
415 SYNC_STATUS_FAILED);
416 }
417
418 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncFailure_Snapshot) {
419 PrepareForSync_Basic(LocalFileSyncContext::SYNC_SNAPSHOT,
420 SYNC_STATUS_FAILED);
421 }
422
339 // LocalFileSyncContextTest.PrepareSyncWhileWriting is flaky on android. 423 // LocalFileSyncContextTest.PrepareSyncWhileWriting is flaky on android.
340 // http://crbug.com/239793 424 // http://crbug.com/239793
341 #if defined(OS_ANDROID) 425 #if defined(OS_ANDROID)
342 #define MAYBE_PrepareSyncWhileWriting DISABLED_PrepareSyncWhileWriting 426 #define MAYBE_PrepareSyncWhileWriting DISABLED_PrepareSyncWhileWriting
343 #else 427 #else
344 #define MAYBE_PrepareSyncWhileWriting PrepareSyncWhileWriting 428 #define MAYBE_PrepareSyncWhileWriting PrepareSyncWhileWriting
345 #endif 429 #endif
346 TEST_F(LocalFileSyncContextTest, MAYBE_PrepareSyncWhileWriting) { 430 TEST_F(LocalFileSyncContextTest, MAYBE_PrepareSyncWhileWriting) {
347 CannedSyncableFileSystem file_system(GURL(kOrigin1), 431 CannedSyncableFileSystem file_system(GURL(kOrigin1),
348 io_task_runner_.get(), 432 io_task_runner_.get(),
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 768
685 // Make sure kDir and kFile are created by ApplyRemoteChange. 769 // Make sure kDir and kFile are created by ApplyRemoteChange.
686 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile)); 770 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile));
687 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); 771 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir));
688 772
689 sync_context_->ShutdownOnUIThread(); 773 sync_context_->ShutdownOnUIThread();
690 file_system.TearDown(); 774 file_system.TearDown();
691 } 775 }
692 776
693 } // namespace sync_file_system 777 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698