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

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

Issue 11418127: Pass calls to GetDocuments through the scheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing comment Created 8 years, 1 month 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_scheduler.h" 5 #include "chrome/browser/chromeos/drive/drive_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/threading/sequenced_worker_pool.h" 8 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/chromeos/drive/drive_test_util.h" 9 #include "chrome/browser/chromeos/drive/drive_test_util.h"
10 #include "chrome/browser/chromeos/drive/file_system/drive_operations.h" 10 #include "chrome/browser/chromeos/drive/file_system/drive_operations.h"
11 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" 11 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h"
12 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" 12 #include "chrome/browser/chromeos/drive/file_system/move_operation.h"
13 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" 13 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
14 #include "chrome/browser/google_apis/mock_drive_service.h"
14 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 using ::testing::AnyNumber; 22 using ::testing::AnyNumber;
22 using ::testing::DoAll; 23 using ::testing::DoAll;
24 using ::testing::Eq;
23 using ::testing::Return; 25 using ::testing::Return;
24 using ::testing::StrictMock; 26 using ::testing::StrictMock;
25 using ::testing::_; 27 using ::testing::_;
26 28
27 namespace drive { 29 namespace drive {
28 30
29 namespace { 31 namespace {
30 32
31 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier { 33 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier {
32 public: 34 public:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 class DriveSchedulerTest : public testing::Test { 95 class DriveSchedulerTest : public testing::Test {
94 public: 96 public:
95 DriveSchedulerTest() 97 DriveSchedulerTest()
96 : ui_thread_(content::BrowserThread::UI, &message_loop_), 98 : ui_thread_(content::BrowserThread::UI, &message_loop_),
97 profile_(new TestingProfile) { 99 profile_(new TestingProfile) {
98 } 100 }
99 101
100 virtual void SetUp() OVERRIDE { 102 virtual void SetUp() OVERRIDE {
101 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier); 103 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier);
102 104
105 // Allocate and keep a pointer to the mock, and inject it into the
106 // DriveFileSystem object, which will own the mock object.
kinaba 2012/11/22 08:04:07 IIUC, DriveFileSystem does not own DriveService (t
Zachary Kuznia 2012/11/28 06:54:56 Removed the comment.
107 mock_drive_service_ = new StrictMock<google_apis::MockDriveService>;
kinaba 2012/11/22 08:04:07 Satorux is deprecating MockDriveService http://crb
108
103 mock_copy_operation_ = new StrictMock<MockCopyOperation>(); 109 mock_copy_operation_ = new StrictMock<MockCopyOperation>();
104 mock_move_operation_ = new StrictMock<MockMoveOperation>(); 110 mock_move_operation_ = new StrictMock<MockMoveOperation>();
105 mock_remove_operation_ = new StrictMock<MockRemoveOperation>(); 111 mock_remove_operation_ = new StrictMock<MockRemoveOperation>();
106 drive_operations_.InitForTesting(mock_copy_operation_, 112 drive_operations_.InitForTesting(mock_copy_operation_,
107 mock_move_operation_, 113 mock_move_operation_,
108 mock_remove_operation_, 114 mock_remove_operation_,
109 NULL); 115 NULL);
110 scheduler_.reset(new DriveScheduler(profile_.get(), 116 scheduler_.reset(new DriveScheduler(profile_.get(),
117 mock_drive_service_,
111 &drive_operations_)); 118 &drive_operations_));
112 119
113 scheduler_->Initialize(); 120 scheduler_->Initialize();
114 scheduler_->SetDisableThrottling(true); 121 scheduler_->SetDisableThrottling(true);
115 } 122 }
116 123
117 virtual void TearDown() OVERRIDE { 124 virtual void TearDown() OVERRIDE {
118 // The scheduler should be deleted before NetworkLibrary, as it 125 // The scheduler should be deleted before NetworkLibrary, as it
119 // registers itself as observer of NetworkLibrary. 126 // registers itself as observer of NetworkLibrary.
120 scheduler_.reset(); 127 scheduler_.reset();
121 google_apis::test_util::RunBlockingPoolTask(); 128 google_apis::test_util::RunBlockingPoolTask();
129 delete mock_drive_service_;
130 mock_drive_service_ = NULL;
122 mock_network_change_notifier_.reset(); 131 mock_network_change_notifier_.reset();
123 } 132 }
124 133
125 // Sets up MockNetworkChangeNotifier as if it's connected to a network with 134 // Sets up MockNetworkChangeNotifier as if it's connected to a network with
126 // the specified connection type. 135 // the specified connection type.
127 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) { 136 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) {
128 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType()) 137 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType())
129 .WillRepeatedly(Return(type)); 138 .WillRepeatedly(Return(type));
130 // Notify the sync client that the network is changed. This is done via 139 // Notify the sync client that the network is changed. This is done via
131 // NetworkChangeNotifier in production, but here, we simulate the behavior 140 // NetworkChangeNotifier in production, but here, we simulate the behavior
(...skipping 20 matching lines...) Expand all
152 void ConnectToNone() { 161 void ConnectToNone() {
153 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE); 162 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE);
154 } 163 }
155 164
156 protected: 165 protected:
157 MessageLoopForUI message_loop_; 166 MessageLoopForUI message_loop_;
158 content::TestBrowserThread ui_thread_; 167 content::TestBrowserThread ui_thread_;
159 scoped_ptr<TestingProfile> profile_; 168 scoped_ptr<TestingProfile> profile_;
160 scoped_ptr<DriveScheduler> scheduler_; 169 scoped_ptr<DriveScheduler> scheduler_;
161 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; 170 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_;
171 StrictMock<google_apis::MockDriveService>* mock_drive_service_;
162 172
163 file_system::DriveOperations drive_operations_; 173 file_system::DriveOperations drive_operations_;
164 StrictMock<MockCopyOperation>* mock_copy_operation_; 174 StrictMock<MockCopyOperation>* mock_copy_operation_;
165 StrictMock<MockMoveOperation>* mock_move_operation_; 175 StrictMock<MockMoveOperation>* mock_move_operation_;
166 StrictMock<MockRemoveOperation>* mock_remove_operation_; 176 StrictMock<MockRemoveOperation>* mock_remove_operation_;
167 }; 177 };
168 178
169 TEST_F(DriveSchedulerTest, CopyFile) { 179 TEST_F(DriveSchedulerTest, CopyFile) {
170 ConnectToWifi(); 180 ConnectToWifi();
171 181
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 240
231 DriveFileError error(DRIVE_FILE_ERROR_FAILED); 241 DriveFileError error(DRIVE_FILE_ERROR_FAILED);
232 scheduler_->TransferRegularFile( 242 scheduler_->TransferRegularFile(
233 file_in_root, dest_file, 243 file_in_root, dest_file,
234 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 244 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
235 google_apis::test_util::RunBlockingPoolTask(); 245 google_apis::test_util::RunBlockingPoolTask();
236 246
237 ASSERT_EQ(DRIVE_FILE_OK, error); 247 ASSERT_EQ(DRIVE_FILE_OK, error);
238 } 248 }
239 249
250 TEST_F(DriveSchedulerTest, GetDocuments) {
251 ConnectToWifi();
252
253 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
254 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt"));
255 EXPECT_CALL(*mock_drive_service_,
256 GetDocuments(Eq(GURL()), _, _, _, _, _)).Times(1);
257
258
259 scheduler_->GetDocuments(
260 GURL(),
261 0,
262 std::string(),
263 true,
264 std::string(),
265 google_apis::GetDataCallback());
266 google_apis::test_util::RunBlockingPoolTask();
satorux1 2012/11/22 08:12:45 I think we should check the results we get by GetD
Zachary Kuznia 2012/11/28 06:54:56 Done.
267 }
268
240 TEST_F(DriveSchedulerTest, MoveFile) { 269 TEST_F(DriveSchedulerTest, MoveFile) {
241 ConnectToWifi(); 270 ConnectToWifi();
242 271
243 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 272 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
244 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt")); 273 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt"));
245 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _)) 274 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _))
246 .WillOnce(MockOperation(DRIVE_FILE_OK)); 275 .WillOnce(MockOperation(DRIVE_FILE_OK));
247 276
248 DriveFileError error(DRIVE_FILE_ERROR_FAILED); 277 DriveFileError error(DRIVE_FILE_ERROR_FAILED);
249 scheduler_->Move( 278 scheduler_->Move(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 428
400 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 429 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
401 DriveFileError error; 430 DriveFileError error;
402 scheduler_->Remove( 431 scheduler_->Remove(
403 file_in_root, false, 432 file_in_root, false,
404 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 433 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
405 google_apis::test_util::RunBlockingPoolTask(); 434 google_apis::test_util::RunBlockingPoolTask();
406 } 435 }
407 436
408 } // namespace drive 437 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698