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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/drive_backend_sync_unittest.cc

Issue 296893002: [SyncFS] Make DriveBackendSyncTest run in multi-threaded env. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase2 Created 6 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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) {
47 *status_out = status;
48 closure.Run();
49 }
50
51 void SetSyncStatusAndUrl(const base::Closure& closure,
52 SyncStatusCode* status_out,
53 fileapi::FileSystemURL* url_out,
54 SyncStatusCode status,
55 const fileapi::FileSystemURL& url) {
56 *status_out = status;
57 *url_out = url;
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
56 io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( 77 io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
57 content::BrowserThread::IO); 78 content::BrowserThread::IO);
79 scoped_refptr<base::SequencedWorkerPool> worker_pool(
80 content::BrowserThread::GetBlockingPool());
81 worker_task_runner_ =
82 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
83 worker_pool->GetSequenceToken(),
84 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
58 file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( 85 file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
59 content::BrowserThread::FILE); 86 content::BrowserThread::FILE);
60 87
61 RegisterSyncableFileSystem(); 88 RegisterSyncableFileSystem();
62 local_sync_service_ = LocalFileSyncService::CreateForTesting( 89 local_sync_service_ = LocalFileSyncService::CreateForTesting(
63 &profile_, in_memory_env_.get()); 90 &profile_, in_memory_env_.get());
64 local_sync_service_->AddChangeObserver(this); 91 local_sync_service_->AddChangeObserver(this);
65 92
66 scoped_ptr<drive::FakeDriveService> 93 scoped_ptr<drive::FakeDriveService>
67 drive_service(new drive::FakeDriveService); 94 drive_service(new drive::FakeDriveService);
68 drive_service->Initialize("test@example.com"); 95 drive_service->Initialize("test@example.com");
69 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get())); 96 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get()));
70 97
71 scoped_ptr<drive::DriveUploaderInterface> uploader( 98 scoped_ptr<drive::DriveUploaderInterface> uploader(
72 new drive::DriveUploader(drive_service.get(), 99 new drive::DriveUploader(drive_service.get(),
73 file_task_runner_.get())); 100 file_task_runner_.get()));
74 101
75 fake_drive_service_helper_.reset(new FakeDriveServiceHelper( 102 fake_drive_service_helper_.reset(new FakeDriveServiceHelper(
76 drive_service.get(), uploader.get(), 103 drive_service.get(), uploader.get(),
77 kSyncRootFolderTitle)); 104 kSyncRootFolderTitle));
78 105
79 remote_sync_service_.reset(new SyncEngine( 106 remote_sync_service_.reset(new SyncEngine(
80 drive_service.PassAs<drive::DriveServiceInterface>(), 107 drive_service.PassAs<drive::DriveServiceInterface>(),
81 uploader.Pass(), 108 uploader.Pass(),
82 file_task_runner_.get(), 109 file_task_runner_.get(),
83 NULL, NULL, NULL)); 110 NULL, NULL, NULL));
84 remote_sync_service_->AddServiceObserver(this); 111 remote_sync_service_->AddServiceObserver(this);
85 remote_sync_service_->Initialize(base_dir_.path(), 112 remote_sync_service_->Initialize(base_dir_.path(),
86 NULL, 113 NULL,
87 base::MessageLoopProxy::current(), 114 worker_task_runner_.get(),
88 in_memory_env_.get()); 115 in_memory_env_.get());
89 remote_sync_service_->SetSyncEnabled(true); 116 remote_sync_service_->SetSyncEnabled(true);
90 117
91 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get()); 118 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get());
92 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get()); 119 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get());
93 } 120 }
94 121
95 virtual void TearDown() OVERRIDE { 122 virtual void TearDown() OVERRIDE {
96 typedef std::map<std::string, CannedSyncableFileSystem*>::iterator iterator; 123 typedef std::map<std::string, CannedSyncableFileSystem*>::iterator iterator;
97 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
155 182
156 SyncStatusCode RegisterApp(const std::string& app_id) { 183 SyncStatusCode RegisterApp(const std::string& app_id) {
157 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); 184 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id);
158 if (!ContainsKey(file_systems_, app_id)) { 185 if (!ContainsKey(file_systems_, app_id)) {
159 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( 186 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem(
160 origin, in_memory_env_.get(), 187 origin, in_memory_env_.get(),
161 io_task_runner_.get(), file_task_runner_.get()); 188 io_task_runner_.get(), file_task_runner_.get());
162 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED); 189 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED);
163 190
164 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 191 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
192 base::RunLoop run_loop;
165 local_sync_service_->MaybeInitializeFileSystemContext( 193 local_sync_service_->MaybeInitializeFileSystemContext(
166 origin, file_system->file_system_context(), 194 origin, file_system->file_system_context(),
167 CreateResultReceiver(&status)); 195 base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status));
168 base::RunLoop().RunUntilIdle(); 196 run_loop.Run();
169 EXPECT_EQ(SYNC_STATUS_OK, status); 197 EXPECT_EQ(SYNC_STATUS_OK, status);
170 198
171 file_system->backend()->sync_context()-> 199 file_system->backend()->sync_context()->
172 set_mock_notify_changes_duration_in_sec(0); 200 set_mock_notify_changes_duration_in_sec(0);
173 201
174 EXPECT_EQ(base::File::FILE_OK, file_system->OpenFileSystem()); 202 EXPECT_EQ(base::File::FILE_OK, file_system->OpenFileSystem());
175 file_systems_[app_id] = file_system; 203 file_systems_[app_id] = file_system;
176 } 204 }
177 205
178 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 206 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
179 remote_sync_service_->RegisterOrigin(origin, CreateResultReceiver(&status)); 207 base::RunLoop run_loop;
180 base::RunLoop().RunUntilIdle(); 208 remote_sync_service_->RegisterOrigin(
209 origin,
210 base::Bind(&SetSyncStatus, run_loop.QuitClosure(), &status));
211 run_loop.Run();
181 return status; 212 return status;
182 } 213 }
183 214
184 void AddLocalFolder(const std::string& app_id, 215 void AddLocalFolder(const std::string& app_id,
185 const base::FilePath::StringType& path) { 216 const base::FilePath::StringType& path) {
186 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 217 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
187 EXPECT_EQ(base::File::FILE_OK, 218 EXPECT_EQ(base::File::FILE_OK,
188 file_systems_[app_id]->CreateDirectory( 219 file_systems_[app_id]->CreateDirectory(
189 CreateURL(app_id, path))); 220 CreateURL(app_id, path)));
190 } 221 }
(...skipping 25 matching lines...) Expand all
216 EXPECT_EQ(base::File::FILE_OK, 247 EXPECT_EQ(base::File::FILE_OK,
217 file_systems_[app_id]->Remove( 248 file_systems_[app_id]->Remove(
218 CreateURL(app_id, path), 249 CreateURL(app_id, path),
219 true /* recursive */)); 250 true /* recursive */));
220 base::RunLoop().RunUntilIdle(); 251 base::RunLoop().RunUntilIdle();
221 } 252 }
222 253
223 SyncStatusCode ProcessLocalChange() { 254 SyncStatusCode ProcessLocalChange() {
224 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 255 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
225 fileapi::FileSystemURL url; 256 fileapi::FileSystemURL url;
226 local_sync_service_->ProcessLocalChange( 257 base::RunLoop run_loop;
227 CreateResultReceiver(&status, &url)); 258 local_sync_service_->ProcessLocalChange(base::Bind(
228 base::RunLoop().RunUntilIdle(); 259 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
260 run_loop.Run();
229 return status; 261 return status;
230 } 262 }
231 263
232 SyncStatusCode ProcessRemoteChange() { 264 SyncStatusCode ProcessRemoteChange() {
233 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 265 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
234 fileapi::FileSystemURL url; 266 fileapi::FileSystemURL url;
235 remote_sync_service_->ProcessRemoteChange( 267 base::RunLoop run_loop;
236 CreateResultReceiver(&status, &url)); 268 remote_sync_service_->ProcessRemoteChange(base::Bind(
237 base::RunLoop().RunUntilIdle(); 269 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
270 run_loop.Run();
238 return status; 271 return status;
239 } 272 }
240 273
241 int64 GetLargestChangeID() { 274 int64 GetLargestChangeID() {
242 scoped_ptr<google_apis::AboutResource> about_resource; 275 scoped_ptr<google_apis::AboutResource> about_resource;
243 EXPECT_EQ(google_apis::HTTP_SUCCESS, 276 EXPECT_EQ(google_apis::HTTP_SUCCESS,
244 fake_drive_service_helper()->GetAboutResource(&about_resource)); 277 fake_drive_service_helper()->GetAboutResource(&about_resource));
245 if (!about_resource) 278 if (!about_resource)
246 return 0; 279 return 0;
247 return about_resource->largest_change_id(); 280 return about_resource->largest_change_id();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 scoped_ptr<LocalFileSyncService> local_sync_service_; 518 scoped_ptr<LocalFileSyncService> local_sync_service_;
486 519
487 int64 pending_remote_changes_; 520 int64 pending_remote_changes_;
488 int64 pending_local_changes_; 521 int64 pending_local_changes_;
489 522
490 scoped_ptr<FakeDriveServiceHelper> fake_drive_service_helper_; 523 scoped_ptr<FakeDriveServiceHelper> fake_drive_service_helper_;
491 std::map<std::string, CannedSyncableFileSystem*> file_systems_; 524 std::map<std::string, CannedSyncableFileSystem*> file_systems_;
492 525
493 526
494 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 527 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
528 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
495 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 529 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
496 530
497 DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest); 531 DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest);
498 }; 532 };
499 533
500 TEST_F(DriveBackendSyncTest, LocalToRemoteBasicTest) { 534 TEST_F(DriveBackendSyncTest, LocalToRemoteBasicTest) {
501 std::string app_id = "example"; 535 std::string app_id = "example";
502 536
503 RegisterApp(app_id); 537 RegisterApp(app_id);
504 AddOrUpdateLocalFile(app_id, FPL("file"), "abcde"); 538 AddOrUpdateLocalFile(app_id, FPL("file"), "abcde");
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 1610
1577 EXPECT_EQ(1u, CountApp()); 1611 EXPECT_EQ(1u, CountApp());
1578 EXPECT_EQ(1u, CountLocalFile(app_id)); 1612 EXPECT_EQ(1u, CountLocalFile(app_id));
1579 1613
1580 EXPECT_EQ(2u, CountMetadata()); 1614 EXPECT_EQ(2u, CountMetadata());
1581 EXPECT_EQ(2u, CountTracker()); 1615 EXPECT_EQ(2u, CountTracker());
1582 } 1616 }
1583 1617
1584 } // namespace drive_backend 1618 } // namespace drive_backend
1585 } // namespace sync_file_system 1619 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698