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

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

Powered by Google App Engine
This is Rietveld 408576698