OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync_file_system/local/local_file_sync_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/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" | 15 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" |
16 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 16 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
17 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 17 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
18 #include "chrome/browser/sync_file_system/sync_file_metadata.h" | 18 #include "chrome/browser/sync_file_system/sync_file_metadata.h" |
19 #include "chrome/browser/sync_file_system/sync_status_code.h" | 19 #include "chrome/browser/sync_file_system/sync_status_code.h" |
20 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 20 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/test/mock_blob_url_request_context.h" | 22 #include "content/public/test/mock_blob_url_request_context.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 "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 25 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
26 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 26 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
27 #include "webkit/browser/fileapi/file_system_context.h" | 27 #include "storage/browser/fileapi/file_system_context.h" |
28 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 28 #include "storage/browser/fileapi/file_system_operation_runner.h" |
29 #include "webkit/browser/fileapi/isolated_context.h" | 29 #include "storage/browser/fileapi/isolated_context.h" |
30 #include "webkit/common/blob/scoped_file.h" | 30 #include "storage/common/blob/scoped_file.h" |
31 | 31 |
32 #define FPL FILE_PATH_LITERAL | 32 #define FPL FILE_PATH_LITERAL |
33 | 33 |
34 using content::BrowserThread; | 34 using content::BrowserThread; |
35 using fileapi::FileSystemContext; | 35 using storage::FileSystemContext; |
36 using fileapi::FileSystemURL; | 36 using storage::FileSystemURL; |
37 using fileapi::FileSystemURLSet; | 37 using storage::FileSystemURLSet; |
38 | 38 |
39 // This tests LocalFileSyncContext behavior in multi-thread / | 39 // This tests LocalFileSyncContext behavior in multi-thread / |
40 // multi-file-system-context environment. | 40 // multi-file-system-context environment. |
41 // Basic combined tests (single-thread / single-file-system-context) | 41 // Basic combined tests (single-thread / single-file-system-context) |
42 // that involve LocalFileSyncContext are also in | 42 // that involve LocalFileSyncContext are also in |
43 // syncable_file_system_unittests.cc. | 43 // syncable_file_system_unittests.cc. |
44 | 44 |
45 namespace sync_file_system { | 45 namespace sync_file_system { |
46 | 46 |
47 namespace { | 47 namespace { |
(...skipping 26 matching lines...) Expand all Loading... |
74 | 74 |
75 virtual void TearDown() OVERRIDE { | 75 virtual void TearDown() OVERRIDE { |
76 RevokeSyncableFileSystem(); | 76 RevokeSyncableFileSystem(); |
77 } | 77 } |
78 | 78 |
79 void StartPrepareForSync(FileSystemContext* file_system_context, | 79 void StartPrepareForSync(FileSystemContext* file_system_context, |
80 const FileSystemURL& url, | 80 const FileSystemURL& url, |
81 LocalFileSyncContext::SyncMode sync_mode, | 81 LocalFileSyncContext::SyncMode sync_mode, |
82 SyncFileMetadata* metadata, | 82 SyncFileMetadata* metadata, |
83 FileChangeList* changes, | 83 FileChangeList* changes, |
84 webkit_blob::ScopedFile* snapshot) { | 84 storage::ScopedFile* snapshot) { |
85 ASSERT_TRUE(changes != NULL); | 85 ASSERT_TRUE(changes != NULL); |
86 ASSERT_FALSE(has_inflight_prepare_for_sync_); | 86 ASSERT_FALSE(has_inflight_prepare_for_sync_); |
87 status_ = SYNC_STATUS_UNKNOWN; | 87 status_ = SYNC_STATUS_UNKNOWN; |
88 has_inflight_prepare_for_sync_ = true; | 88 has_inflight_prepare_for_sync_ = true; |
89 sync_context_->PrepareForSync( | 89 sync_context_->PrepareForSync( |
90 file_system_context, | 90 file_system_context, |
91 url, | 91 url, |
92 sync_mode, | 92 sync_mode, |
93 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync, | 93 base::Bind(&LocalFileSyncContextTest::DidPrepareForSync, |
94 base::Unretained(this), metadata, changes, snapshot)); | 94 base::Unretained(this), metadata, changes, snapshot)); |
95 } | 95 } |
96 | 96 |
97 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context, | 97 SyncStatusCode PrepareForSync(FileSystemContext* file_system_context, |
98 const FileSystemURL& url, | 98 const FileSystemURL& url, |
99 LocalFileSyncContext::SyncMode sync_mode, | 99 LocalFileSyncContext::SyncMode sync_mode, |
100 SyncFileMetadata* metadata, | 100 SyncFileMetadata* metadata, |
101 FileChangeList* changes, | 101 FileChangeList* changes, |
102 webkit_blob::ScopedFile* snapshot) { | 102 storage::ScopedFile* snapshot) { |
103 StartPrepareForSync(file_system_context, url, sync_mode, | 103 StartPrepareForSync(file_system_context, url, sync_mode, |
104 metadata, changes, snapshot); | 104 metadata, changes, snapshot); |
105 base::MessageLoop::current()->Run(); | 105 base::MessageLoop::current()->Run(); |
106 return status_; | 106 return status_; |
107 } | 107 } |
108 | 108 |
109 base::Closure GetPrepareForSyncClosure( | 109 base::Closure GetPrepareForSyncClosure( |
110 FileSystemContext* file_system_context, | 110 FileSystemContext* file_system_context, |
111 const FileSystemURL& url, | 111 const FileSystemURL& url, |
112 LocalFileSyncContext::SyncMode sync_mode, | 112 LocalFileSyncContext::SyncMode sync_mode, |
113 SyncFileMetadata* metadata, | 113 SyncFileMetadata* metadata, |
114 FileChangeList* changes, | 114 FileChangeList* changes, |
115 webkit_blob::ScopedFile* snapshot) { | 115 storage::ScopedFile* snapshot) { |
116 return base::Bind(&LocalFileSyncContextTest::StartPrepareForSync, | 116 return base::Bind(&LocalFileSyncContextTest::StartPrepareForSync, |
117 base::Unretained(this), | 117 base::Unretained(this), |
118 base::Unretained(file_system_context), | 118 base::Unretained(file_system_context), |
119 url, sync_mode, metadata, changes, snapshot); | 119 url, sync_mode, metadata, changes, snapshot); |
120 } | 120 } |
121 | 121 |
122 void DidPrepareForSync(SyncFileMetadata* metadata_out, | 122 void DidPrepareForSync(SyncFileMetadata* metadata_out, |
123 FileChangeList* changes_out, | 123 FileChangeList* changes_out, |
124 webkit_blob::ScopedFile* snapshot_out, | 124 storage::ScopedFile* snapshot_out, |
125 SyncStatusCode status, | 125 SyncStatusCode status, |
126 const LocalFileSyncInfo& sync_file_info, | 126 const LocalFileSyncInfo& sync_file_info, |
127 webkit_blob::ScopedFile snapshot) { | 127 storage::ScopedFile snapshot) { |
128 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread()); | 128 ASSERT_TRUE(ui_task_runner_->RunsTasksOnCurrentThread()); |
129 has_inflight_prepare_for_sync_ = false; | 129 has_inflight_prepare_for_sync_ = false; |
130 status_ = status; | 130 status_ = status; |
131 *metadata_out = sync_file_info.metadata; | 131 *metadata_out = sync_file_info.metadata; |
132 *changes_out = sync_file_info.changes; | 132 *changes_out = sync_file_info.changes; |
133 if (snapshot_out) | 133 if (snapshot_out) |
134 *snapshot_out = snapshot.Pass(); | 134 *snapshot_out = snapshot.Pass(); |
135 base::MessageLoop::current()->Quit(); | 135 base::MessageLoop::current()->Quit(); |
136 } | 136 } |
137 | 137 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 ASSERT_EQ(SYNC_STATUS_OK, | 292 ASSERT_EQ(SYNC_STATUS_OK, |
293 file_system.MaybeInitializeFileSystemContext( | 293 file_system.MaybeInitializeFileSystemContext( |
294 sync_context_.get())); | 294 sync_context_.get())); |
295 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); | 295 ASSERT_EQ(base::File::FILE_OK, file_system.OpenFileSystem()); |
296 | 296 |
297 const FileSystemURL kFile(file_system.URL("file")); | 297 const FileSystemURL kFile(file_system.URL("file")); |
298 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); | 298 EXPECT_EQ(base::File::FILE_OK, file_system.CreateFile(kFile)); |
299 | 299 |
300 SyncFileMetadata metadata; | 300 SyncFileMetadata metadata; |
301 FileChangeList changes; | 301 FileChangeList changes; |
302 webkit_blob::ScopedFile snapshot; | 302 storage::ScopedFile snapshot; |
303 EXPECT_EQ(SYNC_STATUS_OK, | 303 EXPECT_EQ(SYNC_STATUS_OK, |
304 PrepareForSync(file_system.file_system_context(), kFile, | 304 PrepareForSync(file_system.file_system_context(), kFile, |
305 sync_mode, &metadata, &changes, &snapshot)); | 305 sync_mode, &metadata, &changes, &snapshot)); |
306 EXPECT_EQ(1U, changes.size()); | 306 EXPECT_EQ(1U, changes.size()); |
307 EXPECT_TRUE(changes.list().back().IsFile()); | 307 EXPECT_TRUE(changes.list().back().IsFile()); |
308 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); | 308 EXPECT_TRUE(changes.list().back().IsAddOrUpdate()); |
309 | 309 |
310 EXPECT_EQ(sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT, | 310 EXPECT_EQ(sync_mode == LocalFileSyncContext::SYNC_SNAPSHOT, |
311 !snapshot.path().empty()); | 311 !snapshot.path().empty()); |
312 | 312 |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 | 950 |
951 // Make sure kDir and kFile are created by ApplyRemoteChange. | 951 // Make sure kDir and kFile are created by ApplyRemoteChange. |
952 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile)); | 952 EXPECT_EQ(base::File::FILE_OK, file_system.FileExists(kFile)); |
953 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir)); | 953 EXPECT_EQ(base::File::FILE_OK, file_system.DirectoryExists(kDir)); |
954 | 954 |
955 sync_context_->ShutdownOnUIThread(); | 955 sync_context_->ShutdownOnUIThread(); |
956 file_system.TearDown(); | 956 file_system.TearDown(); |
957 } | 957 } |
958 | 958 |
959 } // namespace sync_file_system | 959 } // namespace sync_file_system |
OLD | NEW |