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

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

Issue 14348013: Remove legacy in DriveSyncClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix + alpha Created 7 years, 8 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 (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/drive_sync_client.h" 5 #include "chrome/browser/chromeos/drive/drive_sync_client.h"
6 6
7 #include <algorithm>
8 #include <vector> 7 #include <vector>
9 8
10 #include "base/bind.h"
11 #include "base/file_util.h" 9 #include "base/file_util.h"
12 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 13 #include "base/message_loop.h"
16 #include "base/path_service.h"
17 #include "base/prefs/pref_service.h"
18 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
19 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
20 #include "chrome/browser/chromeos/drive/drive.pb.h" 16 #include "chrome/browser/chromeos/drive/drive.pb.h"
17 #include "chrome/browser/chromeos/drive/drive_cache.h"
21 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 18 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
22 #include "chrome/browser/chromeos/drive/drive_test_util.h" 19 #include "chrome/browser/chromeos/drive/drive_test_util.h"
23 #include "chrome/browser/chromeos/drive/mock_drive_file_system.h" 20 #include "chrome/browser/chromeos/drive/mock_drive_file_system.h"
24 #include "chrome/browser/google_apis/test_util.h" 21 #include "chrome/browser/google_apis/test_util.h"
25 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/testing_profile.h"
28 #include "content/public/test/test_browser_thread.h" 22 #include "content/public/test/test_browser_thread.h"
29 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
31 25
32 using ::testing::AnyNumber;
33 using ::testing::DoAll;
34 using ::testing::Return;
35 using ::testing::StrictMock; 26 using ::testing::StrictMock;
36 using ::testing::_; 27 using ::testing::_;
37 28
38 namespace drive { 29 namespace drive {
39 30
40 namespace { 31 namespace {
41 32
42 // Action used to set mock expectations for GetFileByResourceId(). 33 // Action used to set mock expectations for GetFileByResourceId().
43 ACTION_P4(MockGetFileByResourceId, error, local_path, mime_type, file_type) { 34 ACTION_P4(MockGetFileByResourceId, error, local_path, mime_type, file_type) {
44 arg2.Run(error, local_path, mime_type, file_type); 35 arg2.Run(error, local_path, mime_type, file_type);
45 } 36 }
46 37
47 // Action used to set mock expectations for UpdateFileByResourceId(). 38 // Action used to set mock expectations for UpdateFileByResourceId().
48 ACTION_P(MockUpdateFileByResourceId, error) { 39 ACTION_P(MockUpdateFileByResourceId, error) {
49 arg2.Run(error); 40 arg2.Run(error);
50 } 41 }
51 42
52 // Action used to set mock expectations for GetFileInfoByResourceId(). 43 // Action used to set mock expectations for GetFileInfoByResourceId().
53 ACTION_P2(MockUpdateFileByResourceId, error, md5) { 44 ACTION_P2(MockUpdateFileByResourceId, error, md5) {
54 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto); 45 scoped_ptr<DriveEntryProto> entry_proto(new DriveEntryProto);
55 entry_proto->mutable_file_specific_info()->set_file_md5(md5); 46 entry_proto->mutable_file_specific_info()->set_file_md5(md5);
56 arg1.Run(error, base::FilePath(), entry_proto.Pass()); 47 arg1.Run(error, base::FilePath(), entry_proto.Pass());
57 } 48 }
58 49
59 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier {
60 public:
61 MOCK_CONST_METHOD0(GetCurrentConnectionType,
62 net::NetworkChangeNotifier::ConnectionType());
63 };
64
65 } // namespace 50 } // namespace
66 51
67 class DriveSyncClientTest : public testing::Test { 52 class DriveSyncClientTest : public testing::Test {
68 public: 53 public:
69 DriveSyncClientTest() 54 DriveSyncClientTest()
70 : ui_thread_(content::BrowserThread::UI, &message_loop_), 55 : ui_thread_(content::BrowserThread::UI, &message_loop_),
71 profile_(new TestingProfile),
72 mock_file_system_(new StrictMock<MockDriveFileSystem>) { 56 mock_file_system_(new StrictMock<MockDriveFileSystem>) {
73 } 57 }
74 58
75 virtual void SetUp() OVERRIDE { 59 virtual void SetUp() OVERRIDE {
76 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier);
77
78 // Create a temporary directory. 60 // Create a temporary directory.
79 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 61 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
80 62
81 // Initialize the cache. 63 // Initialize the cache.
82 scoped_refptr<base::SequencedWorkerPool> pool = 64 scoped_refptr<base::SequencedWorkerPool> pool =
83 content::BrowserThread::GetBlockingPool(); 65 content::BrowserThread::GetBlockingPool();
84 cache_.reset(new DriveCache( 66 cache_.reset(new DriveCache(
85 temp_dir_.path(), 67 temp_dir_.path(),
86 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), 68 pool->GetSequencedTaskRunner(pool->GetSequenceToken()),
87 NULL /* free_disk_space_getter */)); 69 NULL /* free_disk_space_getter */));
88 bool success = false; 70 bool success = false;
89 cache_->RequestInitialize( 71 cache_->RequestInitialize(
90 google_apis::test_util::CreateCopyResultCallback(&success)); 72 google_apis::test_util::CreateCopyResultCallback(&success));
91 google_apis::test_util::RunBlockingPoolTask(); 73 google_apis::test_util::RunBlockingPoolTask();
92 ASSERT_TRUE(success); 74 ASSERT_TRUE(success);
93 SetUpCache(); 75 SetUpCache();
94 76
95 // Initialize the sync client. 77 // Initialize the sync client.
96 sync_client_.reset(new DriveSyncClient(profile_.get(), 78 EXPECT_CALL(*mock_file_system_, AddObserver(_)).Times(1);
97 mock_file_system_.get(), 79 EXPECT_CALL(*mock_file_system_, RemoveObserver(_)).Times(1);
80 sync_client_.reset(new DriveSyncClient(mock_file_system_.get(),
98 cache_.get())); 81 cache_.get()));
99 82
100 EXPECT_CALL(*mock_file_system_, AddObserver(sync_client_.get())).Times(1);
101 EXPECT_CALL(*mock_file_system_,
102 RemoveObserver(sync_client_.get())).Times(1);
103
104 // Disable delaying so that DoSyncLoop() starts immediately. 83 // Disable delaying so that DoSyncLoop() starts immediately.
105 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0)); 84 sync_client_->set_delay_for_testing(base::TimeDelta::FromSeconds(0));
106 sync_client_->Initialize();
107 } 85 }
108 86
109 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
110 // The sync client should be deleted before NetworkLibrary, as the sync
111 // client registers itself as observer of NetworkLibrary.
112 sync_client_.reset(); 88 sync_client_.reset();
113 cache_.reset(); 89 cache_.reset();
114 mock_network_change_notifier_.reset();
115 } 90 }
116 91
117 // Sets up cache for tests. 92 // Sets up cache for tests.
118 void SetUpCache() { 93 void SetUpCache() {
119 // Prepare a temp file. 94 // Prepare a temp file.
120 base::FilePath temp_file; 95 base::FilePath temp_file;
121 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), 96 EXPECT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(),
122 &temp_file)); 97 &temp_file));
123 const std::string content = "hello"; 98 const std::string content = "hello";
124 EXPECT_EQ(static_cast<int>(content.size()), 99 EXPECT_EQ(static_cast<int>(content.size()),
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Adds a resource ID of a file to upload. 212 // Adds a resource ID of a file to upload.
238 void AddResourceIdToUpload(const std::string& resource_id) { 213 void AddResourceIdToUpload(const std::string& resource_id) {
239 sync_client_->AddResourceIdForTesting(DriveSyncClient::UPLOAD, 214 sync_client_->AddResourceIdForTesting(DriveSyncClient::UPLOAD,
240 resource_id); 215 resource_id);
241 } 216 }
242 217
243 protected: 218 protected:
244 MessageLoopForUI message_loop_; 219 MessageLoopForUI message_loop_;
245 content::TestBrowserThread ui_thread_; 220 content::TestBrowserThread ui_thread_;
246 base::ScopedTempDir temp_dir_; 221 base::ScopedTempDir temp_dir_;
247 scoped_ptr<TestingProfile> profile_;
248 scoped_ptr<StrictMock<MockDriveFileSystem> > mock_file_system_; 222 scoped_ptr<StrictMock<MockDriveFileSystem> > mock_file_system_;
249 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_; 223 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_;
250 scoped_ptr<DriveSyncClient> sync_client_; 224 scoped_ptr<DriveSyncClient> sync_client_;
251 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_;
252 }; 225 };
253 226
254 TEST_F(DriveSyncClientTest, StartInitialScan) { 227 TEST_F(DriveSyncClientTest, StartInitialScan) {
255 // Start processing the files in the backlog. This will collect the 228 // Start processing the files in the backlog. This will collect the
256 // resource IDs of these files. 229 // resource IDs of these files.
257 sync_client_->StartProcessingBacklog(); 230 sync_client_->StartProcessingBacklog();
258 231
259 // Check the contents of the queue for fetching. 232 // Check the contents of the queue for fetching.
260 SetExpectationForGetFileByResourceId("resource_id_not_fetched_bar"); 233 SetExpectationForGetFileByResourceId("resource_id_not_fetched_bar");
261 SetExpectationForGetFileByResourceId("resource_id_not_fetched_baz"); 234 SetExpectationForGetFileByResourceId("resource_id_not_fetched_baz");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // Start checking the existing pinned files. This will collect the resource 294 // Start checking the existing pinned files. This will collect the resource
322 // IDs of pinned files, with stale local cache files. 295 // IDs of pinned files, with stale local cache files.
323 sync_client_->StartCheckingExistingPinnedFiles(); 296 sync_client_->StartCheckingExistingPinnedFiles();
324 297
325 SetExpectationForGetFileByResourceId("resource_id_fetched"); 298 SetExpectationForGetFileByResourceId("resource_id_fetched");
326 299
327 google_apis::test_util::RunBlockingPoolTask(); 300 google_apis::test_util::RunBlockingPoolTask();
328 } 301 }
329 302
330 } // namespace drive 303 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_sync_client.cc ('k') | chrome/browser/chromeos/drive/drive_system_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698