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

Side by Side Diff: chrome/browser/chromeos/drive/sync_client_unittest.cc

Issue 1124813003: [chrome/browser/chromeos/drive] Avoid use of MessageLoopProxy by use of TTRH (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Review Comments 3 : Indent Created 5 years, 7 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
« no previous file with comments | « chrome/browser/chromeos/drive/sync_client.cc ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/drive/sync_client.h" 5 #include "chrome/browser/chromeos/drive/sync_client.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h"
13 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
15 #include "base/thread_task_runner_handle.h"
14 #include "chrome/browser/chromeos/drive/change_list_loader.h" 16 #include "chrome/browser/chromeos/drive/change_list_loader.h"
15 #include "chrome/browser/chromeos/drive/drive.pb.h" 17 #include "chrome/browser/chromeos/drive/drive.pb.h"
16 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 18 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
17 #include "chrome/browser/chromeos/drive/file_cache.h" 19 #include "chrome/browser/chromeos/drive/file_cache.h"
18 #include "chrome/browser/chromeos/drive/file_change.h" 20 #include "chrome/browser/chromeos/drive/file_change.h"
19 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" 21 #include "chrome/browser/chromeos/drive/file_system/move_operation.h"
20 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" 22 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h"
21 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" 23 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
22 #include "chrome/browser/chromeos/drive/file_system_util.h" 24 #include "chrome/browser/chromeos/drive/file_system_util.h"
23 #include "chrome/browser/chromeos/drive/job_scheduler.h" 25 #include "chrome/browser/chromeos/drive/job_scheduler.h"
(...skipping 26 matching lines...) Expand all
50 52
51 // FakeDriveService override: 53 // FakeDriveService override:
52 google_apis::CancelCallback DownloadFile( 54 google_apis::CancelCallback DownloadFile(
53 const base::FilePath& local_cache_path, 55 const base::FilePath& local_cache_path,
54 const std::string& resource_id, 56 const std::string& resource_id,
55 const google_apis::DownloadActionCallback& download_action_callback, 57 const google_apis::DownloadActionCallback& download_action_callback,
56 const google_apis::GetContentCallback& get_content_callback, 58 const google_apis::GetContentCallback& get_content_callback,
57 const google_apis::ProgressCallback& progress_callback) override { 59 const google_apis::ProgressCallback& progress_callback) override {
58 ++download_file_count_; 60 ++download_file_count_;
59 if (resource_id == resource_id_to_be_cancelled_) { 61 if (resource_id == resource_id_to_be_cancelled_) {
60 base::MessageLoopProxy::current()->PostTask( 62 base::ThreadTaskRunnerHandle::Get()->PostTask(
61 FROM_HERE, 63 FROM_HERE,
62 base::Bind(download_action_callback, 64 base::Bind(download_action_callback,
63 google_apis::DRIVE_CANCELLED, 65 google_apis::DRIVE_CANCELLED,
64 base::FilePath())); 66 base::FilePath()));
65 return google_apis::CancelCallback(); 67 return google_apis::CancelCallback();
66 } 68 }
67 if (resource_id == resource_id_to_be_paused_) { 69 if (resource_id == resource_id_to_be_paused_) {
68 paused_action_ = base::Bind(download_action_callback, 70 paused_action_ = base::Bind(download_action_callback,
69 google_apis::DRIVE_OTHER_ERROR, 71 google_apis::DRIVE_OTHER_ERROR,
70 base::FilePath()); 72 base::FilePath());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 pref_service_.reset(new TestingPrefServiceSimple); 108 pref_service_.reset(new TestingPrefServiceSimple);
107 test_util::RegisterDrivePrefs(pref_service_->registry()); 109 test_util::RegisterDrivePrefs(pref_service_->registry());
108 110
109 fake_network_change_notifier_.reset( 111 fake_network_change_notifier_.reset(
110 new test_util::FakeNetworkChangeNotifier); 112 new test_util::FakeNetworkChangeNotifier);
111 113
112 logger_.reset(new EventLogger); 114 logger_.reset(new EventLogger);
113 115
114 drive_service_.reset(new SyncClientTestDriveService); 116 drive_service_.reset(new SyncClientTestDriveService);
115 117
116 scheduler_.reset(new JobScheduler(pref_service_.get(), 118 scheduler_.reset(new JobScheduler(
117 logger_.get(), 119 pref_service_.get(),
118 drive_service_.get(), 120 logger_.get(),
119 base::MessageLoopProxy::current().get())); 121 drive_service_.get(),
122 base::ThreadTaskRunnerHandle::Get().get()));
120 123
121 metadata_storage_.reset(new ResourceMetadataStorage( 124 metadata_storage_.reset(new ResourceMetadataStorage(
122 temp_dir_.path(), base::MessageLoopProxy::current().get())); 125 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get().get()));
123 ASSERT_TRUE(metadata_storage_->Initialize()); 126 ASSERT_TRUE(metadata_storage_->Initialize());
124 127
125 cache_.reset(new FileCache(metadata_storage_.get(), 128 cache_.reset(new FileCache(metadata_storage_.get(),
126 temp_dir_.path(), 129 temp_dir_.path(),
127 base::MessageLoopProxy::current().get(), 130 base::ThreadTaskRunnerHandle::Get().get(),
128 NULL /* free_disk_space_getter */)); 131 NULL /* free_disk_space_getter */));
129 ASSERT_TRUE(cache_->Initialize()); 132 ASSERT_TRUE(cache_->Initialize());
130 133
131 metadata_.reset(new internal::ResourceMetadata( 134 metadata_.reset(new internal::ResourceMetadata(
132 metadata_storage_.get(), cache_.get(), 135 metadata_storage_.get(), cache_.get(),
133 base::MessageLoopProxy::current())); 136 base::ThreadTaskRunnerHandle::Get()));
134 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize()); 137 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize());
135 138
136 about_resource_loader_.reset(new AboutResourceLoader(scheduler_.get())); 139 about_resource_loader_.reset(new AboutResourceLoader(scheduler_.get()));
137 loader_controller_.reset(new LoaderController); 140 loader_controller_.reset(new LoaderController);
138 change_list_loader_.reset(new ChangeListLoader( 141 change_list_loader_.reset(new ChangeListLoader(
139 logger_.get(), 142 logger_.get(),
140 base::MessageLoopProxy::current().get(), 143 base::ThreadTaskRunnerHandle::Get().get(),
141 metadata_.get(), 144 metadata_.get(),
142 scheduler_.get(), 145 scheduler_.get(),
143 about_resource_loader_.get(), 146 about_resource_loader_.get(),
144 loader_controller_.get())); 147 loader_controller_.get()));
145 ASSERT_NO_FATAL_FAILURE(SetUpTestData()); 148 ASSERT_NO_FATAL_FAILURE(SetUpTestData());
146 149
147 sync_client_.reset(new SyncClient(base::MessageLoopProxy::current().get(), 150 sync_client_.reset(new SyncClient(base::ThreadTaskRunnerHandle::Get().get(),
148 &delegate_, 151 &delegate_,
149 scheduler_.get(), 152 scheduler_.get(),
150 metadata_.get(), 153 metadata_.get(),
151 cache_.get(), 154 cache_.get(),
152 loader_controller_.get(), 155 loader_controller_.get(),
153 temp_dir_.path())); 156 temp_dir_.path()));
154 157
155 // Disable delaying so that DoSyncLoop() starts immediately. 158 // Disable delaying so that DoSyncLoop() starts immediately.
156 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0)); 159 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0));
157 } 160 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("fetched"))); 213 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("fetched")));
211 214
212 // Prepare a pinned-and-fetched-and-dirty file. 215 // Prepare a pinned-and-fetched-and-dirty file.
213 EXPECT_EQ(FILE_ERROR_OK, 216 EXPECT_EQ(FILE_ERROR_OK,
214 cache_->Store(GetLocalId("dirty"), std::string(), 217 cache_->Store(GetLocalId("dirty"), std::string(),
215 temp_file, FileCache::FILE_OPERATION_COPY)); 218 temp_file, FileCache::FILE_OPERATION_COPY));
216 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("dirty"))); 219 EXPECT_EQ(FILE_ERROR_OK, cache_->Pin(GetLocalId("dirty")));
217 220
218 // Prepare a removed file. 221 // Prepare a removed file.
219 file_system::RemoveOperation remove_operation( 222 file_system::RemoveOperation remove_operation(
220 base::MessageLoopProxy::current().get(), &delegate_, metadata_.get(), 223 base::ThreadTaskRunnerHandle::Get().get(), &delegate_, metadata_.get(),
221 cache_.get()); 224 cache_.get());
222 remove_operation.Remove( 225 remove_operation.Remove(
223 util::GetDriveMyDriveRootPath().AppendASCII("removed"), 226 util::GetDriveMyDriveRootPath().AppendASCII("removed"),
224 false, // is_recursive 227 false, // is_recursive
225 google_apis::test_util::CreateCopyResultCallback(&error)); 228 google_apis::test_util::CreateCopyResultCallback(&error));
226 base::RunLoop().RunUntilIdle(); 229 base::RunLoop().RunUntilIdle();
227 EXPECT_EQ(FILE_ERROR_OK, error); 230 EXPECT_EQ(FILE_ERROR_OK, error);
228 231
229 // Prepare a moved file. 232 // Prepare a moved file.
230 file_system::MoveOperation move_operation( 233 file_system::MoveOperation move_operation(
231 base::MessageLoopProxy::current().get(), &delegate_, metadata_.get()); 234 base::ThreadTaskRunnerHandle::Get().get(), &delegate_, metadata_.get());
232 move_operation.Move( 235 move_operation.Move(
233 util::GetDriveMyDriveRootPath().AppendASCII("moved"), 236 util::GetDriveMyDriveRootPath().AppendASCII("moved"),
234 util::GetDriveMyDriveRootPath().AppendASCII("moved_new_title"), 237 util::GetDriveMyDriveRootPath().AppendASCII("moved_new_title"),
235 google_apis::test_util::CreateCopyResultCallback(&error)); 238 google_apis::test_util::CreateCopyResultCallback(&error));
236 base::RunLoop().RunUntilIdle(); 239 base::RunLoop().RunUntilIdle();
237 EXPECT_EQ(FILE_ERROR_OK, error); 240 EXPECT_EQ(FILE_ERROR_OK, error);
238 } 241 }
239 242
240 protected: 243 protected:
241 std::string GetLocalId(const std::string& title) { 244 std::string GetLocalId(const std::string& title) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 EXPECT_EQ(kLocalContent, content); 383 EXPECT_EQ(kLocalContent, content);
381 } 384 }
382 385
383 TEST_F(SyncClientTest, RetryOnDisconnection) { 386 TEST_F(SyncClientTest, RetryOnDisconnection) {
384 // Let the service go down. 387 // Let the service go down.
385 drive_service_->set_offline(true); 388 drive_service_->set_offline(true);
386 // Change the network connection state after some delay, to test that 389 // Change the network connection state after some delay, to test that
387 // FILE_ERROR_NO_CONNECTION is handled by SyncClient correctly. 390 // FILE_ERROR_NO_CONNECTION is handled by SyncClient correctly.
388 // Without this delay, JobScheduler will keep the jobs unrun and SyncClient 391 // Without this delay, JobScheduler will keep the jobs unrun and SyncClient
389 // will receive no error. 392 // will receive no error.
390 base::MessageLoopProxy::current()->PostDelayedTask( 393 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
391 FROM_HERE, 394 FROM_HERE,
392 base::Bind(&test_util::FakeNetworkChangeNotifier::SetConnectionType, 395 base::Bind(&test_util::FakeNetworkChangeNotifier::SetConnectionType,
393 base::Unretained(fake_network_change_notifier_.get()), 396 base::Unretained(fake_network_change_notifier_.get()),
394 net::NetworkChangeNotifier::CONNECTION_NONE), 397 net::NetworkChangeNotifier::CONNECTION_NONE),
395 TestTimeouts::tiny_timeout()); 398 TestTimeouts::tiny_timeout());
396 399
397 // Try fetch and upload. 400 // Try fetch and upload.
398 sync_client_->AddFetchTask(GetLocalId("foo")); 401 sync_client_->AddFetchTask(GetLocalId("foo"));
399 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED), 402 sync_client_->AddUpdateTask(ClientContext(USER_INITIATED),
400 GetLocalId("dirty")); 403 GetLocalId("dirty"));
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 local_id, google_apis::test_util::CreateCopyResultCallback(&error))); 514 local_id, google_apis::test_util::CreateCopyResultCallback(&error)));
512 515
513 base::RunLoop().RunUntilIdle(); 516 base::RunLoop().RunUntilIdle();
514 517
515 // The callback is called. 518 // The callback is called.
516 EXPECT_EQ(FILE_ERROR_OK, error); 519 EXPECT_EQ(FILE_ERROR_OK, error);
517 } 520 }
518 521
519 } // namespace internal 522 } // namespace internal
520 } // namespace drive 523 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/sync_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698