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

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

Powered by Google App Engine
This is Rietveld 408576698