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

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

Issue 23578026: Use SNAPSHOT sync mode for LocalSync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments 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/bind_helpers.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/platform_file.h" 14 #include "base/platform_file.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #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"
19 #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"
20 #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"
21 #include "chrome/browser/sync_file_system/sync_file_metadata.h" 21 #include "chrome/browser/sync_file_system/sync_file_metadata.h"
22 #include "chrome/browser/sync_file_system/sync_status_code.h" 22 #include "chrome/browser/sync_file_system/sync_status_code.h"
23 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 23 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "webkit/browser/blob/mock_blob_url_request_context.h" 25 #include "webkit/browser/blob/mock_blob_url_request_context.h"
26 #include "webkit/browser/fileapi/file_system_context.h" 26 #include "webkit/browser/fileapi/file_system_context.h"
27 #include "webkit/browser/fileapi/file_system_operation_runner.h" 27 #include "webkit/browser/fileapi/file_system_operation_runner.h"
28 #include "webkit/browser/fileapi/isolated_context.h" 28 #include "webkit/browser/fileapi/isolated_context.h"
29 #include "webkit/common/blob/scoped_file.h"
29 30
30 #define FPL FILE_PATH_LITERAL 31 #define FPL FILE_PATH_LITERAL
31 32
32 using fileapi::FileSystemContext; 33 using fileapi::FileSystemContext;
33 using fileapi::FileSystemURL; 34 using fileapi::FileSystemURL;
34 using fileapi::FileSystemURLSet; 35 using fileapi::FileSystemURLSet;
35 36
36 // This tests LocalFileSyncContext behavior in multi-thread / 37 // This tests LocalFileSyncContext behavior in multi-thread /
37 // multi-file-system-context environment. 38 // multi-file-system-context environment.
38 // Basic combined tests (single-thread / single-file-system-context) 39 // Basic combined tests (single-thread / single-file-system-context)
(...skipping 11 matching lines...) Expand all
50 protected: 51 protected:
51 LocalFileSyncContextTest() 52 LocalFileSyncContextTest()
52 : status_(SYNC_FILE_ERROR_FAILED), 53 : status_(SYNC_FILE_ERROR_FAILED),
53 file_error_(base::PLATFORM_FILE_ERROR_FAILED), 54 file_error_(base::PLATFORM_FILE_ERROR_FAILED),
54 async_modify_finished_(false), 55 async_modify_finished_(false),
55 has_inflight_prepare_for_sync_(false) {} 56 has_inflight_prepare_for_sync_(false) {}
56 57
57 virtual void SetUp() OVERRIDE { 58 virtual void SetUp() OVERRIDE {
58 RegisterSyncableFileSystem(); 59 RegisterSyncableFileSystem();
59 60
61 ASSERT_TRUE(dir_.CreateUniqueTempDir());
62
60 io_thread_.reset(new base::Thread("Thread_IO")); 63 io_thread_.reset(new base::Thread("Thread_IO"));
61 io_thread_->StartWithOptions( 64 io_thread_->StartWithOptions(
62 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); 65 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
63 66
64 file_thread_.reset(new base::Thread("Thread_File")); 67 file_thread_.reset(new base::Thread("Thread_File"));
65 file_thread_->Start(); 68 file_thread_->Start();
66 69
67 ui_task_runner_ = base::MessageLoop::current()->message_loop_proxy(); 70 ui_task_runner_ = base::MessageLoop::current()->message_loop_proxy();
68 io_task_runner_ = io_thread_->message_loop_proxy(); 71 io_task_runner_ = io_thread_->message_loop_proxy();
69 file_task_runner_ = file_thread_->message_loop_proxy(); 72 file_task_runner_ = file_thread_->message_loop_proxy();
70 } 73 }
71 74
72 virtual void TearDown() OVERRIDE { 75 virtual void TearDown() OVERRIDE {
73 RevokeSyncableFileSystem(); 76 RevokeSyncableFileSystem();
74 io_thread_->Stop(); 77 io_thread_->Stop();
75 file_thread_->Stop(); 78 file_thread_->Stop();
76 } 79 }
77 80
78 void StartPrepareForSync(FileSystemContext* file_system_context, 81 void StartPrepareForSync(FileSystemContext* file_system_context,
79 const FileSystemURL& url, 82 const FileSystemURL& url,
83 LocalFileSyncContext::SyncMode sync_mode,
80 SyncFileMetadata* metadata, 84 SyncFileMetadata* metadata,
81 FileChangeList* changes) { 85 FileChangeList* changes,
86 webkit_blob::ScopedFile* snapshot) {
82 ASSERT_TRUE(changes != NULL); 87 ASSERT_TRUE(changes != NULL);
83 ASSERT_FALSE(has_inflight_prepare_for_sync_); 88 ASSERT_FALSE(has_inflight_prepare_for_sync_);
84 status_ = SYNC_STATUS_UNKNOWN; 89 status_ = SYNC_STATUS_UNKNOWN;
85 has_inflight_prepare_for_sync_ = true; 90 has_inflight_prepare_for_sync_ = true;
86 sync_context_->PrepareForSync( 91 sync_context_->PrepareForSync(
87 file_system_context, 92 file_system_context,
88 url, 93 url,
89 LocalFileSyncContext::SYNC_EXCLUSIVE, 94 sync_mode,
90 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync, 95 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync,
91 base::Unretained(this), metadata, changes)); 96 base::Unretained(this), metadata, changes, snapshot));
92 } 97 }
93 98
94 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context, 99 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context,
95 const FileSystemURL& url, 100 const FileSystemURL& url,
101 LocalFileSyncContext::SyncMode sync_mode,
96 SyncFileMetadata* metadata, 102 SyncFileMetadata* metadata,
97 FileChangeList* changes) { 103 FileChangeList* changes,
98 StartPrepareForSync(file_system_context, url, metadata, changes); 104 webkit_blob::ScopedFile* snapshot) {
105 StartPrepareForSync(file_system_context, url, sync_mode,
106 metadata, changes, snapshot);
99 base::MessageLoop::current()->Run(); 107 base::MessageLoop::current()->Run();
100 return status_; 108 return status_;
101 } 109 }
102 110
103 base::Closure GetPrepareForSyncClosure(FileSystemContext* file_system_context, 111 base::Closure GetPrepareForSyncClosure(
104 const FileSystemURL& url, 112 FileSystemContext* file_system_context,
105 SyncFileMetadata* metadata, 113 const FileSystemURL& url,
106 FileChangeList* changes) { 114 LocalFileSyncContext::SyncMode sync_mode,
115 SyncFileMetadata* metadata,
116 FileChangeList* changes,
117 webkit_blob::ScopedFile* snapshot) {
107 return base::Bind(&LocalFileSyncContextTest::StartPrepareForSync, 118 return base::Bind(&LocalFileSyncContextTest::StartPrepareForSync,
108 base::Unretained(this), 119 base::Unretained(this),
109 base::Unretained(file_system_context), 120 base::Unretained(file_system_context),
110 url, metadata, changes); 121 url, sync_mode, metadata, changes, snapshot);
111 } 122 }
112 123
113 void DidPrepareForSync(SyncFileMetadata* metadata_out, 124 void DidPrepareForSync(SyncFileMetadata* metadata_out,
114 FileChangeList* changes_out, 125 FileChangeList* changes_out,
126 webkit_blob::ScopedFile* snapshot_out,
115 SyncStatusCode status, 127 SyncStatusCode status,
116 const LocalFileSyncInfo& sync_file_info) { 128 const LocalFileSyncInfo& sync_file_info,
129 scoped_ptr<webkit_blob::ScopedFile> snapshot) {
117 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread()); 130 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread());
118 has_inflight_prepare_for_sync_ = false; 131 has_inflight_prepare_for_sync_ = false;
119 status_ = status; 132 status_ = status;
120 *metadata_out = sync_file_info.metadata; 133 *metadata_out = sync_file_info.metadata;
121 *changes_out = sync_file_info.changes; 134 *changes_out = sync_file_info.changes;
135 if (snapshot_out && snapshot)
136 *snapshot_out = snapshot->Pass();
122 base::MessageLoop::current()->Quit(); 137 base::MessageLoop::current()->Quit();
123 } 138 }
124 139
125 SyncStatusCode ApplyRemoteChange(FileSystemContext* file_system_context, 140 SyncStatusCode ApplyRemoteChange(FileSystemContext* file_system_context,
126 const FileChange& change, 141 const FileChange& change,
127 const base::FilePath& local_path, 142 const base::FilePath& local_path,
128 const FileSystemURL& url, 143 const FileSystemURL& url,
129 SyncFileType expected_file_type) { 144 SyncFileType expected_file_type) {
130 SCOPED_TRACE(testing::Message() << "ApplyChange for " << 145 SCOPED_TRACE(testing::Message() << "ApplyChange for " <<
131 url.DebugString()); 146 url.DebugString());
132 147
133 // First we should call PrepareForSync to disable writing. 148 // First we should call PrepareForSync to disable writing.
134 SyncFileMetadata metadata; 149 SyncFileMetadata metadata;
135 FileChangeList changes; 150 FileChangeList changes;
136 EXPECT_EQ(SYNC_STATUS_OK, 151 EXPECT_EQ(SYNC_STATUS_OK,
137 PrepareForSync(file_system_context, url, &metadata, &changes)); 152 PrepareForSync(file_system_context, url,
153 LocalFileSyncContext::SYNC_EXCLUSIVE,
154 &metadata, &changes, NULL));
138 EXPECT_EQ(expected_file_type, metadata.file_type); 155 EXPECT_EQ(expected_file_type, metadata.file_type);
139 156
140 status_ = SYNC_STATUS_UNKNOWN; 157 status_ = SYNC_STATUS_UNKNOWN;
141 sync_context_->ApplyRemoteChange( 158 sync_context_->ApplyRemoteChange(
142 file_system_context, change, local_path, url, 159 file_system_context, change, local_path, url,
143 base::Bind(&LocalFileSyncContextTest::DidApplyRemoteChange, 160 base::Bind(&LocalFileSyncContextTest::DidApplyRemoteChange,
144 base::Unretained(this))); 161 base::Unretained(this)));
145 base::MessageLoop::current()->Run(); 162 base::MessageLoop::current()->Run();
146 return status_; 163 return status_;
147 } 164 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 base::MessageLoop::current()->RunUntilIdle(); 219 base::MessageLoop::current()->RunUntilIdle();
203 } 220 }
204 221
205 void PrepareForSync_Basic(LocalFileSyncContext::SyncMode sync_mode, 222 void PrepareForSync_Basic(LocalFileSyncContext::SyncMode sync_mode,
206 SyncStatusCode simulate_sync_finish_status) { 223 SyncStatusCode simulate_sync_finish_status) {
207 CannedSyncableFileSystem file_system(GURL(kOrigin1), 224 CannedSyncableFileSystem file_system(GURL(kOrigin1),
208 io_task_runner_.get(), 225 io_task_runner_.get(),
209 file_task_runner_.get()); 226 file_task_runner_.get());
210 file_system.SetUp(); 227 file_system.SetUp();
211 sync_context_ = new LocalFileSyncContext( 228 sync_context_ = new LocalFileSyncContext(
212 ui_task_runner_.get(), io_task_runner_.get()); 229 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
213 ASSERT_EQ(SYNC_STATUS_OK, 230 ASSERT_EQ(SYNC_STATUS_OK,
214 file_system.MaybeInitializeFileSystemContext( 231 file_system.MaybeInitializeFileSystemContext(
215 sync_context_.get())); 232 sync_context_.get()));
216 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 233 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem());
217 234
218 const FileSystemURL kFile(file_system.URL("file")); 235 const FileSystemURL kFile(file_system.URL("file"));
219 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile)); 236 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile));
220 237
221 SyncFileMetadata metadata; 238 SyncFileMetadata metadata;
222 FileChangeList changes; 239 FileChangeList changes;
223 EXPECT_EQ(SYNC_STATUS_OK, 240 EXPECT_EQ(SYNC_STATUS_OK,
224 PrepareForSync(file_system.file_system_context(), kFile, 241 PrepareForSync(file_system.file_system_context(), kFile,
225 &metadata, &changes)); 242 sync_mode, &metadata, &changes, NULL));
226 EXPECT_EQ(1U, changes.size()); 243 EXPECT_EQ(1U, changes.size());
227 EXPECT_TRUE(changes.list().back().IsFile()); 244 EXPECT_TRUE(changes.list().back().IsFile());
228 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 245 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
229 246
230 // We should see the same set of changes. 247 // We should see the same set of changes.
231 file_system.GetChangesForURLInTracker(kFile, &changes); 248 file_system.GetChangesForURLInTracker(kFile, &changes);
232 EXPECT_EQ(1U, changes.size()); 249 EXPECT_EQ(1U, changes.size());
233 EXPECT_TRUE(changes.list().back().IsFile()); 250 EXPECT_TRUE(changes.list().back().IsFile());
234 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 251 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
235 252
236 SimulateFinishSync(file_system.file_system_context(), kFile, 253 SimulateFinishSync(file_system.file_system_context(), kFile,
237 simulate_sync_finish_status); 254 simulate_sync_finish_status);
238 255
239 file_system.GetChangesForURLInTracker(kFile, &changes); 256 file_system.GetChangesForURLInTracker(kFile, &changes);
240 if (simulate_sync_finish_status == SYNC_STATUS_OK) { 257 if (simulate_sync_finish_status == SYNC_STATUS_OK) {
241 // The change's cleared. 258 // The change's cleared.
242 EXPECT_TRUE(changes.empty()); 259 EXPECT_TRUE(changes.empty());
243 } else { 260 } else {
244 EXPECT_EQ(1U, changes.size()); 261 EXPECT_EQ(1U, changes.size());
245 EXPECT_TRUE(changes.list().back().IsFile()); 262 EXPECT_TRUE(changes.list().back().IsFile());
246 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 263 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
247 } 264 }
248 265
249 sync_context_->ShutdownOnUIThread(); 266 sync_context_->ShutdownOnUIThread();
250 sync_context_ = NULL; 267 sync_context_ = NULL;
251 268
252 file_system.TearDown(); 269 file_system.TearDown();
253 } 270 }
254 271
272 void PrepareForSync_WriteDuringSync(
273 LocalFileSyncContext::SyncMode sync_mode) {
274 CannedSyncableFileSystem file_system(GURL(kOrigin1),
275 io_task_runner_.get(),
276 file_task_runner_.get());
277 file_system.SetUp();
278 sync_context_ = new LocalFileSyncContext(
279 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
280 ASSERT_EQ(SYNC_STATUS_OK,
281 file_system.MaybeInitializeFileSystemContext(
282 sync_context_.get()));
283 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem());
284
285 const FileSystemURL kFile(file_system.URL("file"));
286 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kFile));
287
288 SyncFileMetadata metadata;
289 FileChangeList changes;
290 webkit_blob::ScopedFile snapshot;
291 EXPECT_EQ(SYNC_STATUS_OK,
292 PrepareForSync(file_system.file_system_context(), kFile,
293 sync_mode, &metadata, &changes, &snapshot));
294 EXPECT_EQ(1U, changes.size());
295 EXPECT_TRUE(changes.list().back().IsFile());
296 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
297
298 EXPECT_EQ(sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT,
299 !snapshot.path().empty());
300
301 // Tracker keeps same set of changes.
302 file_system.GetChangesForURLInTracker(kFile, &changes);
303 EXPECT_EQ(1U, changes.size());
304 EXPECT_TRUE(changes.list().back().IsFile());
305 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
306
307 StartModifyFileOnIOThread(&file_system, kFile);
308
309 if (sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT) {
310 // Write should succeed.
311 EXPECT_EQ(base::PLATFORM_FILE_OK, WaitUntilModifyFileIsDone());
312 } else {
313 base::MessageLoop::current()->RunUntilIdle();
314 EXPECT_FALSE(async_modify_finished_);
315 }
316
317 SimulateFinishSync(file_system.file_system_context(), kFile,
318 SYNC_STATUS_OK);
319
320 EXPECT_EQ(base::PLATFORM_FILE_OK, WaitUntilModifyFileIsDone());
321
322 // Sync succeeded, but the other change that was made during or
323 // after sync is recorded.
324 file_system.GetChangesForURLInTracker(kFile, &changes);
325 EXPECT_EQ(1U, changes.size());
326 EXPECT_TRUE(changes.list().back().IsFile());
327 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
328
329 sync_context_->ShutdownOnUIThread();
330 sync_context_ = NULL;
331
332 file_system.TearDown();
333 }
334
255 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_; 335 ScopedEnableSyncFSDirectoryOperation enable_directory_operation_;
256 336
337 base::ScopedTempDir dir_;
338
257 // These need to remain until the very end. 339 // These need to remain until the very end.
258 scoped_ptr<base::Thread> io_thread_; 340 scoped_ptr<base::Thread> io_thread_;
259 scoped_ptr<base::Thread> file_thread_; 341 scoped_ptr<base::Thread> file_thread_;
earthdok 2013/09/17 12:39:26 It looks like there's a race condition between the
260 base::MessageLoop loop_; 342 base::MessageLoop loop_;
261 343
262 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 344 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
263 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 345 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
264 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 346 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
265 347
266 scoped_refptr<LocalFileSyncContext> sync_context_; 348 scoped_refptr<LocalFileSyncContext> sync_context_;
267 349
268 SyncStatusCode status_; 350 SyncStatusCode status_;
269 base::PlatformFileError file_error_; 351 base::PlatformFileError file_error_;
270 bool async_modify_finished_; 352 bool async_modify_finished_;
271 bool has_inflight_prepare_for_sync_; 353 bool has_inflight_prepare_for_sync_;
272 }; 354 };
273 355
274 TEST_F(LocalFileSyncContextTest, ConstructAndDestruct) { 356 TEST_F(LocalFileSyncContextTest, ConstructAndDestruct) {
275 sync_context_ = 357 sync_context_ =
276 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); 358 new LocalFileSyncContext(
359 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
277 sync_context_->ShutdownOnUIThread(); 360 sync_context_->ShutdownOnUIThread();
278 } 361 }
279 362
280 TEST_F(LocalFileSyncContextTest, InitializeFileSystemContext) { 363 TEST_F(LocalFileSyncContextTest, InitializeFileSystemContext) {
281 CannedSyncableFileSystem file_system(GURL(kOrigin1), 364 CannedSyncableFileSystem file_system(GURL(kOrigin1),
282 io_task_runner_.get(), 365 io_task_runner_.get(),
283 file_task_runner_.get()); 366 file_task_runner_.get());
284 file_system.SetUp(); 367 file_system.SetUp();
285 368
286 sync_context_ = 369 sync_context_ = new LocalFileSyncContext(
287 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); 370 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
288 371
289 // Initializes file_system using |sync_context_|. 372 // Initializes file_system using |sync_context_|.
290 EXPECT_EQ(SYNC_STATUS_OK, 373 EXPECT_EQ(SYNC_STATUS_OK,
291 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 374 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
292 375
293 // Make sure everything's set up for file_system to be able to handle 376 // Make sure everything's set up for file_system to be able to handle
294 // syncable file system operations. 377 // syncable file system operations.
295 EXPECT_TRUE(file_system.backend()->sync_context() != NULL); 378 EXPECT_TRUE(file_system.backend()->sync_context() != NULL);
296 EXPECT_TRUE(file_system.backend()->change_tracker() != NULL); 379 EXPECT_TRUE(file_system.backend()->change_tracker() != NULL);
297 EXPECT_EQ(sync_context_.get(), file_system.backend()->sync_context()); 380 EXPECT_EQ(sync_context_.get(), file_system.backend()->sync_context());
(...skipping 23 matching lines...) Expand all
321 TEST_F(LocalFileSyncContextTest, MultipleFileSystemContexts) { 404 TEST_F(LocalFileSyncContextTest, MultipleFileSystemContexts) {
322 CannedSyncableFileSystem file_system1(GURL(kOrigin1), 405 CannedSyncableFileSystem file_system1(GURL(kOrigin1),
323 io_task_runner_.get(), 406 io_task_runner_.get(),
324 file_task_runner_.get()); 407 file_task_runner_.get());
325 CannedSyncableFileSystem file_system2(GURL(kOrigin2), 408 CannedSyncableFileSystem file_system2(GURL(kOrigin2),
326 io_task_runner_.get(), 409 io_task_runner_.get(),
327 file_task_runner_.get()); 410 file_task_runner_.get());
328 file_system1.SetUp(); 411 file_system1.SetUp();
329 file_system2.SetUp(); 412 file_system2.SetUp();
330 413
331 sync_context_ = 414 sync_context_ = new LocalFileSyncContext(
332 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); 415 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
333 416
334 // Initializes file_system1 and file_system2. 417 // Initializes file_system1 and file_system2.
335 EXPECT_EQ(SYNC_STATUS_OK, 418 EXPECT_EQ(SYNC_STATUS_OK,
336 file_system1.MaybeInitializeFileSystemContext(sync_context_.get())); 419 file_system1.MaybeInitializeFileSystemContext(sync_context_.get()));
337 EXPECT_EQ(SYNC_STATUS_OK, 420 EXPECT_EQ(SYNC_STATUS_OK,
338 file_system2.MaybeInitializeFileSystemContext(sync_context_.get())); 421 file_system2.MaybeInitializeFileSystemContext(sync_context_.get()));
339 422
340 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.OpenFileSystem()); 423 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system1.OpenFileSystem());
341 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem()); 424 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system2.OpenFileSystem());
342 425
(...skipping 26 matching lines...) Expand all
369 // file_system2's tracker now must have the change for kURL2. 452 // file_system2's tracker now must have the change for kURL2.
370 urls.clear(); 453 urls.clear();
371 file_system2.GetChangedURLsInTracker(&urls); 454 file_system2.GetChangedURLsInTracker(&urls);
372 ASSERT_EQ(1U, urls.size()); 455 ASSERT_EQ(1U, urls.size());
373 EXPECT_TRUE(ContainsKey(urls, kURL2)); 456 EXPECT_TRUE(ContainsKey(urls, kURL2));
374 457
375 SyncFileMetadata metadata; 458 SyncFileMetadata metadata;
376 FileChangeList changes; 459 FileChangeList changes;
377 EXPECT_EQ(SYNC_STATUS_OK, 460 EXPECT_EQ(SYNC_STATUS_OK,
378 PrepareForSync(file_system1.file_system_context(), kURL1, 461 PrepareForSync(file_system1.file_system_context(), kURL1,
379 &metadata, &changes)); 462 LocalFileSyncContext::SYNC_EXCLUSIVE,
463 &metadata, &changes, NULL));
380 EXPECT_EQ(1U, changes.size()); 464 EXPECT_EQ(1U, changes.size());
381 EXPECT_TRUE(changes.list().back().IsFile()); 465 EXPECT_TRUE(changes.list().back().IsFile());
382 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 466 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
383 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type); 467 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type);
384 EXPECT_EQ(0, metadata.size); 468 EXPECT_EQ(0, metadata.size);
385 469
386 changes.clear(); 470 changes.clear();
387 EXPECT_EQ(SYNC_STATUS_OK, 471 EXPECT_EQ(SYNC_STATUS_OK,
388 PrepareForSync(file_system2.file_system_context(), kURL2, 472 PrepareForSync(file_system2.file_system_context(), kURL2,
389 &metadata, &changes)); 473 LocalFileSyncContext::SYNC_EXCLUSIVE,
474 &metadata, &changes, NULL));
390 EXPECT_EQ(1U, changes.size()); 475 EXPECT_EQ(1U, changes.size());
391 EXPECT_FALSE(changes.list().back().IsFile()); 476 EXPECT_FALSE(changes.list().back().IsFile());
392 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 477 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
393 EXPECT_EQ(SYNC_FILE_TYPE_DIRECTORY, metadata.file_type); 478 EXPECT_EQ(SYNC_FILE_TYPE_DIRECTORY, metadata.file_type);
394 EXPECT_EQ(0, metadata.size); 479 EXPECT_EQ(0, metadata.size);
395 480
396 sync_context_->ShutdownOnUIThread(); 481 sync_context_->ShutdownOnUIThread();
397 sync_context_ = NULL; 482 sync_context_ = NULL;
398 483
399 file_system1.TearDown(); 484 file_system1.TearDown();
(...skipping 13 matching lines...) Expand all
413 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncFailure_Exclusive) { 498 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncFailure_Exclusive) {
414 PrepareForSync_Basic(LocalFileSyncContext::SYNC_EXCLUSIVE, 499 PrepareForSync_Basic(LocalFileSyncContext::SYNC_EXCLUSIVE,
415 SYNC_STATUS_FAILED); 500 SYNC_STATUS_FAILED);
416 } 501 }
417 502
418 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncFailure_Snapshot) { 503 TEST_F(LocalFileSyncContextTest, PrepareSync_SyncFailure_Snapshot) {
419 PrepareForSync_Basic(LocalFileSyncContext::SYNC_SNAPSHOT, 504 PrepareForSync_Basic(LocalFileSyncContext::SYNC_SNAPSHOT,
420 SYNC_STATUS_FAILED); 505 SYNC_STATUS_FAILED);
421 } 506 }
422 507
508 TEST_F(LocalFileSyncContextTest, PrepareSync_WriteDuringSync_Exclusive) {
509 PrepareForSync_WriteDuringSync(LocalFileSyncContext::SYNC_EXCLUSIVE);
510 }
511
512 TEST_F(LocalFileSyncContextTest, PrepareSync_WriteDuringSync_Snapshot) {
513 PrepareForSync_WriteDuringSync(LocalFileSyncContext::SYNC_SNAPSHOT);
514 }
515
423 // LocalFileSyncContextTest.PrepareSyncWhileWriting is flaky on android. 516 // LocalFileSyncContextTest.PrepareSyncWhileWriting is flaky on android.
424 // http://crbug.com/239793 517 // http://crbug.com/239793
425 #if defined(OS_ANDROID) 518 #if defined(OS_ANDROID)
426 #define MAYBE_PrepareSyncWhileWriting DISABLED_PrepareSyncWhileWriting 519 #define MAYBE_PrepareSyncWhileWriting DISABLED_PrepareSyncWhileWriting
427 #else 520 #else
428 #define MAYBE_PrepareSyncWhileWriting PrepareSyncWhileWriting 521 #define MAYBE_PrepareSyncWhileWriting PrepareSyncWhileWriting
429 #endif 522 #endif
430 TEST_F(LocalFileSyncContextTest, MAYBE_PrepareSyncWhileWriting) { 523 TEST_F(LocalFileSyncContextTest, MAYBE_PrepareSyncWhileWriting) {
431 CannedSyncableFileSystem file_system(GURL(kOrigin1), 524 CannedSyncableFileSystem file_system(GURL(kOrigin1),
432 io_task_runner_.get(), 525 io_task_runner_.get(),
433 file_task_runner_.get()); 526 file_task_runner_.get());
434 file_system.SetUp(); 527 file_system.SetUp();
435 sync_context_ = 528 sync_context_ = new LocalFileSyncContext(
436 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); 529 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
437 EXPECT_EQ(SYNC_STATUS_OK, 530 EXPECT_EQ(SYNC_STATUS_OK,
438 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 531 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
439 532
440 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 533 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem());
441 534
442 const FileSystemURL kURL1(file_system.URL("foo")); 535 const FileSystemURL kURL1(file_system.URL("foo"));
443 536
444 // Creates a file in file_system. 537 // Creates a file in file_system.
445 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL1)); 538 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.CreateFile(kURL1));
446 539
447 // Kick file write on IO thread. 540 // Kick file write on IO thread.
448 StartModifyFileOnIOThread(&file_system, kURL1); 541 StartModifyFileOnIOThread(&file_system, kURL1);
449 542
450 // Until the operation finishes PrepareForSync should return BUSY error. 543 // Until the operation finishes PrepareForSync should return BUSY error.
451 SyncFileMetadata metadata; 544 SyncFileMetadata metadata;
452 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN; 545 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN;
453 FileChangeList changes; 546 FileChangeList changes;
454 EXPECT_EQ(SYNC_STATUS_FILE_BUSY, 547 EXPECT_EQ(SYNC_STATUS_FILE_BUSY,
455 PrepareForSync(file_system.file_system_context(), 548 PrepareForSync(file_system.file_system_context(), kURL1,
456 kURL1, &metadata, &changes)); 549 LocalFileSyncContext::SYNC_EXCLUSIVE,
550 &metadata, &changes, NULL));
457 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type); 551 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type);
458 552
459 // Register PrepareForSync method to be invoked when kURL1 becomes 553 // Register PrepareForSync method to be invoked when kURL1 becomes
460 // syncable. (Actually this may be done after all operations are done 554 // syncable. (Actually this may be done after all operations are done
461 // on IO thread in this test.) 555 // on IO thread in this test.)
462 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN; 556 metadata.file_type = SYNC_FILE_TYPE_UNKNOWN;
463 changes.clear(); 557 changes.clear();
464 sync_context_->RegisterURLForWaitingSync( 558 sync_context_->RegisterURLForWaitingSync(
465 kURL1, GetPrepareForSyncClosure(file_system.file_system_context(), 559 kURL1, GetPrepareForSyncClosure(file_system.file_system_context(), kURL1,
466 kURL1, &metadata, &changes)); 560 LocalFileSyncContext::SYNC_EXCLUSIVE,
561 &metadata, &changes, NULL));
467 562
468 // Wait for the completion. 563 // Wait for the completion.
469 EXPECT_EQ(base::PLATFORM_FILE_OK, WaitUntilModifyFileIsDone()); 564 EXPECT_EQ(base::PLATFORM_FILE_OK, WaitUntilModifyFileIsDone());
470 565
471 // The PrepareForSync must have been started; wait until DidPrepareForSync 566 // The PrepareForSync must have been started; wait until DidPrepareForSync
472 // is done. 567 // is done.
473 base::MessageLoop::current()->Run(); 568 base::MessageLoop::current()->Run();
474 ASSERT_FALSE(has_inflight_prepare_for_sync_); 569 ASSERT_FALSE(has_inflight_prepare_for_sync_);
475 570
476 // Now PrepareForSync should have run and returned OK. 571 // Now PrepareForSync should have run and returned OK.
477 EXPECT_EQ(SYNC_STATUS_OK, status_); 572 EXPECT_EQ(SYNC_STATUS_OK, status_);
478 EXPECT_EQ(1U, changes.size()); 573 EXPECT_EQ(1U, changes.size());
479 EXPECT_TRUE(changes.list().back().IsFile()); 574 EXPECT_TRUE(changes.list().back().IsFile());
480 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); 575 EXPECT_TRUE(changes.list().back().IsAddOrUpdate());
481 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type); 576 EXPECT_EQ(SYNC_FILE_TYPE_FILE, metadata.file_type);
482 EXPECT_EQ(1, metadata.size); 577 EXPECT_EQ(1, metadata.size);
483 578
484 sync_context_->ShutdownOnUIThread(); 579 sync_context_->ShutdownOnUIThread();
485 sync_context_ = NULL; 580 sync_context_ = NULL;
486 file_system.TearDown(); 581 file_system.TearDown();
487 } 582 }
488 583
489 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion) { 584 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForDeletion) {
490 CannedSyncableFileSystem file_system(GURL(kOrigin1), 585 CannedSyncableFileSystem file_system(GURL(kOrigin1),
491 io_task_runner_.get(), 586 io_task_runner_.get(),
492 file_task_runner_.get()); 587 file_task_runner_.get());
493 file_system.SetUp(); 588 file_system.SetUp();
494 589
495 sync_context_ = 590 sync_context_ = new LocalFileSyncContext(
496 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); 591 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
497 ASSERT_EQ(SYNC_STATUS_OK, 592 ASSERT_EQ(SYNC_STATUS_OK,
498 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 593 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
499 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 594 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem());
500 595
501 // Record the initial usage (likely 0). 596 // Record the initial usage (likely 0).
502 int64 initial_usage = -1; 597 int64 initial_usage = -1;
503 int64 quota = -1; 598 int64 quota = -1;
504 EXPECT_EQ(quota::kQuotaStatusOk, 599 EXPECT_EQ(quota::kQuotaStatusOk,
505 file_system.GetUsageAndQuota(&initial_usage, &quota)); 600 file_system.GetUsageAndQuota(&initial_usage, &quota));
506 601
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 669
575 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate) { 670 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate) {
576 base::ScopedTempDir temp_dir; 671 base::ScopedTempDir temp_dir;
577 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 672 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
578 673
579 CannedSyncableFileSystem file_system(GURL(kOrigin1), 674 CannedSyncableFileSystem file_system(GURL(kOrigin1),
580 io_task_runner_.get(), 675 io_task_runner_.get(),
581 file_task_runner_.get()); 676 file_task_runner_.get());
582 file_system.SetUp(); 677 file_system.SetUp();
583 678
584 sync_context_ = 679 sync_context_ = new LocalFileSyncContext(
585 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); 680 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
586 ASSERT_EQ(SYNC_STATUS_OK, 681 ASSERT_EQ(SYNC_STATUS_OK,
587 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 682 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
588 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 683 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem());
589 684
590 const FileSystemURL kFile1(file_system.URL("file1")); 685 const FileSystemURL kFile1(file_system.URL("file1"));
591 const FileSystemURL kFile2(file_system.URL("file2")); 686 const FileSystemURL kFile2(file_system.URL("file2"));
592 const FileSystemURL kDir(file_system.URL("dir")); 687 const FileSystemURL kDir(file_system.URL("dir"));
593 688
594 const char kTestFileData0[] = "0123456789"; 689 const char kTestFileData0[] = "0123456789";
595 const char kTestFileData1[] = "Lorem ipsum!"; 690 const char kTestFileData1[] = "Lorem ipsum!";
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 818
724 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate_NoParent) { 819 TEST_F(LocalFileSyncContextTest, ApplyRemoteChangeForAddOrUpdate_NoParent) {
725 base::ScopedTempDir temp_dir; 820 base::ScopedTempDir temp_dir;
726 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 821 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
727 822
728 CannedSyncableFileSystem file_system(GURL(kOrigin1), 823 CannedSyncableFileSystem file_system(GURL(kOrigin1),
729 io_task_runner_.get(), 824 io_task_runner_.get(),
730 file_task_runner_.get()); 825 file_task_runner_.get());
731 file_system.SetUp(); 826 file_system.SetUp();
732 827
733 sync_context_ = 828 sync_context_ = new LocalFileSyncContext(
734 new LocalFileSyncContext(ui_task_runner_.get(), io_task_runner_.get()); 829 dir_.path(), ui_task_runner_.get(), io_task_runner_.get());
735 ASSERT_EQ(SYNC_STATUS_OK, 830 ASSERT_EQ(SYNC_STATUS_OK,
736 file_system.MaybeInitializeFileSystemContext(sync_context_.get())); 831 file_system.MaybeInitializeFileSystemContext(sync_context_.get()));
737 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem()); 832 ASSERT_EQ(base::PLATFORM_FILE_OK, file_system.OpenFileSystem());
738 833
739 const char kTestFileData[] = "Lorem ipsum!"; 834 const char kTestFileData[] = "Lorem ipsum!";
740 const FileSystemURL kDir(file_system.URL("dir")); 835 const FileSystemURL kDir(file_system.URL("dir"));
741 const FileSystemURL kFile(file_system.URL("dir/file")); 836 const FileSystemURL kFile(file_system.URL("dir/file"));
742 837
743 // Either kDir or kFile not exist yet. 838 // Either kDir or kFile not exist yet.
744 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kDir)); 839 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, file_system.FileExists(kDir));
(...skipping 23 matching lines...) Expand all
768 863
769 // Make sure kDir and kFile are created by ApplyRemoteChange. 864 // Make sure kDir and kFile are created by ApplyRemoteChange.
770 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile)); 865 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.FileExists(kFile));
771 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir)); 866 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system.DirectoryExists(kDir));
772 867
773 sync_context_->ShutdownOnUIThread(); 868 sync_context_->ShutdownOnUIThread();
774 file_system.TearDown(); 869 file_system.TearDown();
775 } 870 }
776 871
777 } // namespace sync_file_system 872 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698