Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <stack> | 6 #include <stack> |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 32 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 33 #include "webkit/browser/fileapi/file_system_context.h" | 33 #include "webkit/browser/fileapi/file_system_context.h" |
| 34 | 34 |
| 35 #define FPL(a) FILE_PATH_LITERAL(a) | 35 #define FPL(a) FILE_PATH_LITERAL(a) |
| 36 | 36 |
| 37 namespace sync_file_system { | 37 namespace sync_file_system { |
| 38 namespace drive_backend { | 38 namespace drive_backend { |
| 39 | 39 |
| 40 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; | 40 typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; |
| 41 | 41 |
| 42 namespace { | |
| 43 | |
| 44 void SetSyncStatus(const base::Closure& closure, | |
| 45 SyncStatusCode* status_out, | |
| 46 SyncStatusCode status_in) { | |
|
nhiroki
2014/05/26 09:56:00
In syncfs, we haven't used "_in" suffix for input
peria
2014/05/27 02:40:12
Done.
Going along with current code is better, I t
| |
| 47 *status_out = status_in; | |
| 48 closure.Run(); | |
| 49 } | |
| 50 | |
| 51 void SetSyncStatusAndUrl(const base::Closure& closure, | |
| 52 SyncStatusCode* status_out, | |
| 53 fileapi::FileSystemURL* url_out, | |
| 54 SyncStatusCode status_in, | |
| 55 const fileapi::FileSystemURL& url_in) { | |
| 56 *status_out = status_in; | |
| 57 *url_out = url_in; | |
| 58 closure.Run(); | |
| 59 } | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 42 class DriveBackendSyncTest : public testing::Test, | 63 class DriveBackendSyncTest : public testing::Test, |
| 43 public LocalFileSyncService::Observer, | 64 public LocalFileSyncService::Observer, |
| 44 public RemoteFileSyncService::Observer { | 65 public RemoteFileSyncService::Observer { |
| 45 public: | 66 public: |
| 46 DriveBackendSyncTest() | 67 DriveBackendSyncTest() |
| 47 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 68 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 48 pending_remote_changes_(0), | 69 pending_remote_changes_(0), |
| 49 pending_local_changes_(0) {} | 70 pending_local_changes_(0) {} |
| 50 virtual ~DriveBackendSyncTest() {} | 71 virtual ~DriveBackendSyncTest() {} |
| 51 | 72 |
| 52 virtual void SetUp() OVERRIDE { | 73 virtual void SetUp() OVERRIDE { |
| 53 ASSERT_TRUE(base_dir_.CreateUniqueTempDir()); | 74 ASSERT_TRUE(base_dir_.CreateUniqueTempDir()); |
| 54 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); | 75 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); |
| 55 | 76 |
| 77 scoped_refptr<base::SequencedWorkerPool> worker_pool( | |
| 78 content::BrowserThread::GetBlockingPool()); | |
| 79 | |
|
nhiroki
2014/05/26 09:56:00
Can you move this to line 83 or just call content:
peria
2014/05/27 02:40:12
Done.
| |
| 56 io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( | 80 io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( |
| 57 content::BrowserThread::IO); | 81 content::BrowserThread::IO); |
| 58 file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( | 82 file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( |
| 59 content::BrowserThread::FILE); | 83 content::BrowserThread::FILE); |
| 84 worker_task_runner_ = | |
| 85 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
| 86 worker_pool->GetSequenceToken(), | |
| 87 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
| 60 | 88 |
| 61 RegisterSyncableFileSystem(); | 89 RegisterSyncableFileSystem(); |
| 62 local_sync_service_ = LocalFileSyncService::CreateForTesting( | 90 local_sync_service_ = LocalFileSyncService::CreateForTesting( |
| 63 &profile_, in_memory_env_.get()); | 91 &profile_, in_memory_env_.get()); |
| 64 local_sync_service_->AddChangeObserver(this); | 92 local_sync_service_->AddChangeObserver(this); |
| 65 | 93 |
| 66 scoped_ptr<drive::FakeDriveService> | 94 scoped_ptr<drive::FakeDriveService> |
| 67 drive_service(new drive::FakeDriveService); | 95 drive_service(new drive::FakeDriveService); |
| 68 drive_service->Initialize("test@example.com"); | 96 drive_service->Initialize("test@example.com"); |
| 69 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get())); | 97 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get())); |
| 70 | 98 |
| 71 scoped_ptr<drive::DriveUploaderInterface> uploader( | 99 scoped_ptr<drive::DriveUploaderInterface> uploader( |
| 72 new drive::DriveUploader(drive_service.get(), | 100 new drive::DriveUploader(drive_service.get(), |
| 73 file_task_runner_.get())); | 101 file_task_runner_.get())); |
| 74 | 102 |
| 75 fake_drive_service_helper_.reset(new FakeDriveServiceHelper( | 103 fake_drive_service_helper_.reset(new FakeDriveServiceHelper( |
| 76 drive_service.get(), uploader.get(), | 104 drive_service.get(), uploader.get(), |
| 77 kSyncRootFolderTitle)); | 105 kSyncRootFolderTitle)); |
| 78 | 106 |
| 79 remote_sync_service_.reset(new SyncEngine( | 107 remote_sync_service_.reset(new SyncEngine( |
| 80 drive_service.PassAs<drive::DriveServiceInterface>(), | 108 drive_service.PassAs<drive::DriveServiceInterface>(), |
| 81 uploader.Pass(), | 109 uploader.Pass(), |
| 82 file_task_runner_.get(), | 110 file_task_runner_.get(), |
| 83 NULL, NULL, NULL)); | 111 NULL, NULL, NULL)); |
| 84 remote_sync_service_->AddServiceObserver(this); | 112 remote_sync_service_->AddServiceObserver(this); |
| 85 remote_sync_service_->Initialize(base_dir_.path(), | 113 remote_sync_service_->Initialize(base_dir_.path(), |
| 86 base::MessageLoopProxy::current(), | 114 worker_task_runner_.get(), |
| 87 in_memory_env_.get()); | 115 in_memory_env_.get()); |
| 88 remote_sync_service_->SetSyncEnabled(true); | 116 remote_sync_service_->SetSyncEnabled(true); |
| 89 | 117 |
| 90 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get()); | 118 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get()); |
| 91 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get()); | 119 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get()); |
| 92 } | 120 } |
| 93 | 121 |
| 94 virtual void TearDown() OVERRIDE { | 122 virtual void TearDown() OVERRIDE { |
| 95 typedef std::map<std::string, CannedSyncableFileSystem*>::iterator iterator; | 123 typedef std::map<std::string, CannedSyncableFileSystem*>::iterator iterator; |
| 96 for (iterator itr = file_systems_.begin(); | 124 for (iterator itr = file_systems_.begin(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 182 |
| 155 SyncStatusCode RegisterApp(const std::string& app_id) { | 183 SyncStatusCode RegisterApp(const std::string& app_id) { |
| 156 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); | 184 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); |
| 157 if (!ContainsKey(file_systems_, app_id)) { | 185 if (!ContainsKey(file_systems_, app_id)) { |
| 158 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( | 186 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( |
| 159 origin, in_memory_env_.get(), | 187 origin, in_memory_env_.get(), |
| 160 io_task_runner_.get(), file_task_runner_.get()); | 188 io_task_runner_.get(), file_task_runner_.get()); |
| 161 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED); | 189 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED); |
| 162 | 190 |
| 163 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 191 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 164 local_sync_service_->MaybeInitializeFileSystemContext( | 192 { |
| 165 origin, file_system->file_system_context(), | 193 base::RunLoop run_loop; |
| 166 CreateResultReceiver(&status)); | 194 local_sync_service_->MaybeInitializeFileSystemContext( |
| 167 base::RunLoop().RunUntilIdle(); | 195 origin, file_system->file_system_context(), |
| 196 base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status)); | |
| 197 run_loop.Run(); | |
| 198 } | |
|
nhiroki
2014/05/26 09:56:00
You are already surrounded with if-block.
peria
2014/05/27 02:40:12
Done.
| |
| 168 EXPECT_EQ(SYNC_STATUS_OK, status); | 199 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 169 | 200 |
| 170 file_system->backend()->sync_context()-> | 201 file_system->backend()->sync_context()-> |
| 171 set_mock_notify_changes_duration_in_sec(0); | 202 set_mock_notify_changes_duration_in_sec(0); |
| 172 | 203 |
| 173 EXPECT_EQ(base::File::FILE_OK, file_system->OpenFileSystem()); | 204 EXPECT_EQ(base::File::FILE_OK, file_system->OpenFileSystem()); |
| 174 file_systems_[app_id] = file_system; | 205 file_systems_[app_id] = file_system; |
| 175 } | 206 } |
| 176 | 207 |
| 177 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 208 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 178 remote_sync_service_->RegisterOrigin(origin, CreateResultReceiver(&status)); | 209 { |
| 179 base::RunLoop().RunUntilIdle(); | 210 base::RunLoop run_loop; |
| 211 remote_sync_service_->RegisterOrigin( | |
| 212 origin, | |
| 213 base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status)); | |
| 214 run_loop.Run(); | |
| 215 } | |
| 180 return status; | 216 return status; |
| 181 } | 217 } |
| 182 | 218 |
| 183 void AddLocalFolder(const std::string& app_id, | 219 void AddLocalFolder(const std::string& app_id, |
| 184 const base::FilePath::StringType& path) { | 220 const base::FilePath::StringType& path) { |
| 185 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); | 221 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); |
| 186 EXPECT_EQ(base::File::FILE_OK, | 222 EXPECT_EQ(base::File::FILE_OK, |
| 187 file_systems_[app_id]->CreateDirectory( | 223 file_systems_[app_id]->CreateDirectory( |
| 188 CreateURL(app_id, path))); | 224 CreateURL(app_id, path))); |
| 189 } | 225 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 215 EXPECT_EQ(base::File::FILE_OK, | 251 EXPECT_EQ(base::File::FILE_OK, |
| 216 file_systems_[app_id]->Remove( | 252 file_systems_[app_id]->Remove( |
| 217 CreateURL(app_id, path), | 253 CreateURL(app_id, path), |
| 218 true /* recursive */)); | 254 true /* recursive */)); |
| 219 base::RunLoop().RunUntilIdle(); | 255 base::RunLoop().RunUntilIdle(); |
| 220 } | 256 } |
| 221 | 257 |
| 222 SyncStatusCode ProcessLocalChange() { | 258 SyncStatusCode ProcessLocalChange() { |
| 223 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 259 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 224 fileapi::FileSystemURL url; | 260 fileapi::FileSystemURL url; |
| 225 local_sync_service_->ProcessLocalChange( | 261 base::RunLoop run_loop; |
| 226 CreateResultReceiver(&status, &url)); | 262 local_sync_service_->ProcessLocalChange(base::Bind( |
| 227 base::RunLoop().RunUntilIdle(); | 263 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url)); |
| 264 run_loop.Run(); | |
| 228 return status; | 265 return status; |
| 229 } | 266 } |
| 230 | 267 |
| 231 SyncStatusCode ProcessRemoteChange() { | 268 SyncStatusCode ProcessRemoteChange() { |
| 232 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 269 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 233 fileapi::FileSystemURL url; | 270 fileapi::FileSystemURL url; |
| 234 remote_sync_service_->ProcessRemoteChange( | 271 base::RunLoop run_loop; |
| 235 CreateResultReceiver(&status, &url)); | 272 remote_sync_service_->ProcessRemoteChange(base::Bind( |
| 236 base::RunLoop().RunUntilIdle(); | 273 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url)); |
| 274 run_loop.Run(); | |
| 237 return status; | 275 return status; |
| 238 } | 276 } |
| 239 | 277 |
| 240 int64 GetLargestChangeID() { | 278 int64 GetLargestChangeID() { |
| 241 scoped_ptr<google_apis::AboutResource> about_resource; | 279 scoped_ptr<google_apis::AboutResource> about_resource; |
| 242 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 280 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 243 fake_drive_service_helper()->GetAboutResource(&about_resource)); | 281 fake_drive_service_helper()->GetAboutResource(&about_resource)); |
| 244 if (!about_resource) | 282 if (!about_resource) |
| 245 return 0; | 283 return 0; |
| 246 return about_resource->largest_change_id(); | 284 return about_resource->largest_change_id(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 scoped_ptr<LocalFileSyncService> local_sync_service_; | 522 scoped_ptr<LocalFileSyncService> local_sync_service_; |
| 485 | 523 |
| 486 int64 pending_remote_changes_; | 524 int64 pending_remote_changes_; |
| 487 int64 pending_local_changes_; | 525 int64 pending_local_changes_; |
| 488 | 526 |
| 489 scoped_ptr<FakeDriveServiceHelper> fake_drive_service_helper_; | 527 scoped_ptr<FakeDriveServiceHelper> fake_drive_service_helper_; |
| 490 std::map<std::string, CannedSyncableFileSystem*> file_systems_; | 528 std::map<std::string, CannedSyncableFileSystem*> file_systems_; |
| 491 | 529 |
| 492 | 530 |
| 493 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 531 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 532 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_; | |
|
nhiroki
2014/05/26 09:56:00
Can you move this after |file_task_runner_| to sor
peria
2014/05/27 02:40:12
Done.
I changed the order of setting them up.
I an
| |
| 494 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 533 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 495 | 534 |
| 496 DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest); | 535 DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest); |
| 497 }; | 536 }; |
| 498 | 537 |
| 499 TEST_F(DriveBackendSyncTest, LocalToRemoteBasicTest) { | 538 TEST_F(DriveBackendSyncTest, LocalToRemoteBasicTest) { |
| 500 std::string app_id = "example"; | 539 std::string app_id = "example"; |
| 501 | 540 |
| 502 RegisterApp(app_id); | 541 RegisterApp(app_id); |
| 503 AddOrUpdateLocalFile(app_id, FPL("file"), "abcde"); | 542 AddOrUpdateLocalFile(app_id, FPL("file"), "abcde"); |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1575 | 1614 |
| 1576 EXPECT_EQ(1u, CountApp()); | 1615 EXPECT_EQ(1u, CountApp()); |
| 1577 EXPECT_EQ(1u, CountLocalFile(app_id)); | 1616 EXPECT_EQ(1u, CountLocalFile(app_id)); |
| 1578 | 1617 |
| 1579 EXPECT_EQ(2u, CountMetadata()); | 1618 EXPECT_EQ(2u, CountMetadata()); |
| 1580 EXPECT_EQ(2u, CountTracker()); | 1619 EXPECT_EQ(2u, CountTracker()); |
| 1581 } | 1620 } |
| 1582 | 1621 |
| 1583 } // namespace drive_backend | 1622 } // namespace drive_backend |
| 1584 } // namespace sync_file_system | 1623 } // namespace sync_file_system |
| OLD | NEW |