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

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: Rebase Created 8 years 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/file_util.h"
9 #include "base/json/json_reader.h"
8 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
9 #include "chrome/browser/chromeos/drive/drive_test_util.h" 11 #include "chrome/browser/chromeos/drive/drive_test_util.h"
10 #include "chrome/browser/chromeos/drive/file_system/drive_operations.h" 12 #include "chrome/browser/chromeos/drive/file_system/drive_operations.h"
11 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" 13 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h"
12 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" 14 #include "chrome/browser/chromeos/drive/file_system/move_operation.h"
13 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" 15 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
14 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 using ::testing::AnyNumber; 23 using ::testing::AnyNumber;
22 using ::testing::DoAll; 24 using ::testing::DoAll;
25 using ::testing::Eq;
23 using ::testing::Return; 26 using ::testing::Return;
24 using ::testing::StrictMock; 27 using ::testing::StrictMock;
25 using ::testing::_; 28 using ::testing::_;
26 29
30 namespace google_apis {
31
32 class FakeDriveService : public DriveServiceInterface {
33 virtual void Initialize(Profile* profile) {
34 }
35
36 virtual void AddObserver(DriveServiceObserver* observer) {
37 }
38
39 virtual void RemoveObserver(DriveServiceObserver* observer) {
40 }
41
42 virtual bool CanStartOperation() const {
43 return true;
44 }
45
46 virtual void CancelAll() {
47 }
48
49 virtual bool CancelForFilePath(const FilePath& file_path) {
50 return true;
51 }
52
53 virtual OperationProgressStatusList GetProgressStatusList() const {
54 return OperationProgressStatusList();
55 }
56
57 virtual bool HasAccessToken() const {
58 return true;
59 }
60
61 virtual bool HasRefreshToken() const {
62 return true;
63 }
64
65 virtual void GetDocuments(const GURL& feed_url,
66 int64 start_changestamp,
67 const std::string& search_query,
68 bool shared_with_me,
69 const std::string& directory_resource_id,
70 const GetDataCallback& callback) {
71 // TODO: Make this more flexible.
72 if (feed_url == GURL("http://example.com/gdata/root_feed.json")) {
73 // Make some sample data.
74 const FilePath feed_path =
75 test_util::GetTestFilePath("gdata/root_feed.json");
76 std::string feed_contents;
77 file_util::ReadFileToString(feed_path, &feed_contents);
78 scoped_ptr<base::Value> feed_data(
79 base::JSONReader::Read(feed_contents));
80
81 MessageLoop::current()->PostTask(FROM_HERE,
satorux1 2012/11/28 23:59:47 Please use MessageLoopProxy instead, to be consist
Zachary Kuznia 2012/11/30 05:42:30 Done.
82 base::Bind(callback,
83 HTTP_SUCCESS,
84 base::Passed(&feed_data)));
85 } else {
86 scoped_ptr<base::Value> feed_data;
87 MessageLoop::current()->PostTask(FROM_HERE,
88 base::Bind(callback,
89 GDATA_PARSE_ERROR,
90 base::Passed(&feed_data)));
91 }
92 }
93
94 virtual void GetDocumentEntry(const std::string& resource_id,
95 const GetDataCallback& callback) {
96 }
97
98 virtual void GetAccountMetadata(const GetDataCallback& callback) {
99 }
100
101 virtual void GetApplicationInfo(const GetDataCallback& callback) {
102 }
103
104 virtual void DeleteDocument(const GURL& document_url,
105 const EntryActionCallback& callback) {
106 }
107
108 virtual void DownloadDocument(const FilePath& virtual_path,
109 const FilePath& local_cache_path,
110 const GURL& content_url,
111 DocumentExportFormat format,
112 const DownloadActionCallback& callback) {
113 }
114
115 virtual void CopyDocument(const std::string& resource_id,
116 const FilePath::StringType& new_name,
117 const GetDataCallback& callback) {
118 }
119
120 virtual void RenameResource(const GURL& resource_url,
121 const FilePath::StringType& new_name,
122 const EntryActionCallback& callback) {
123 }
124
125 virtual void AddResourceToDirectory(const GURL& parent_content_url,
126 const GURL& resource_url,
127 const EntryActionCallback& callback) {
128 }
129
130 virtual void RemoveResourceFromDirectory(
131 const GURL& parent_content_url,
132 const GURL& resource_url,
133 const std::string& resource_id,
134 const EntryActionCallback& callback) {
135 }
136
137 virtual void AddNewDirectory(const GURL& parent_content_url,
138 const FilePath::StringType& directory_name,
139 const GetDataCallback& callback) {
140 }
141
142 virtual void DownloadFile(
143 const FilePath& virtual_path,
144 const FilePath& local_cache_path,
145 const GURL& content_url,
146 const DownloadActionCallback& download_action_callback,
147 const GetContentCallback& get_content_callback) {
148 }
149
150 virtual void InitiateUpload(const InitiateUploadParams& params,
151 const InitiateUploadCallback& callback) {
152 }
153
154 virtual void ResumeUpload(const ResumeUploadParams& params,
155 const ResumeUploadCallback& callback) {
156 }
157
158 virtual void AuthorizeApp(const GURL& resource_url,
159 const std::string& app_id,
160 const GetDataCallback& callback) {
161 }
162
163 };
164
165 } // namespace google_apis
166
27 namespace drive { 167 namespace drive {
28 168
29 namespace { 169 namespace {
30 170
31 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier { 171 class MockNetworkChangeNotifier : public net::NetworkChangeNotifier {
32 public: 172 public:
33 MOCK_CONST_METHOD0(GetCurrentConnectionType, 173 MOCK_CONST_METHOD0(GetCurrentConnectionType,
34 net::NetworkChangeNotifier::ConnectionType()); 174 net::NetworkChangeNotifier::ConnectionType());
35 }; 175 };
36 176
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 class DriveSchedulerTest : public testing::Test { 233 class DriveSchedulerTest : public testing::Test {
94 public: 234 public:
95 DriveSchedulerTest() 235 DriveSchedulerTest()
96 : ui_thread_(content::BrowserThread::UI, &message_loop_), 236 : ui_thread_(content::BrowserThread::UI, &message_loop_),
97 profile_(new TestingProfile) { 237 profile_(new TestingProfile) {
98 } 238 }
99 239
100 virtual void SetUp() OVERRIDE { 240 virtual void SetUp() OVERRIDE {
101 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier); 241 mock_network_change_notifier_.reset(new MockNetworkChangeNotifier);
102 242
243 fake_drive_service_.reset(new google_apis::FakeDriveService());
103 mock_copy_operation_ = new StrictMock<MockCopyOperation>(); 244 mock_copy_operation_ = new StrictMock<MockCopyOperation>();
104 mock_move_operation_ = new StrictMock<MockMoveOperation>(); 245 mock_move_operation_ = new StrictMock<MockMoveOperation>();
105 mock_remove_operation_ = new StrictMock<MockRemoveOperation>(); 246 mock_remove_operation_ = new StrictMock<MockRemoveOperation>();
106 drive_operations_.InitForTesting(mock_copy_operation_, 247 drive_operations_.InitForTesting(mock_copy_operation_,
107 mock_move_operation_, 248 mock_move_operation_,
108 mock_remove_operation_, 249 mock_remove_operation_,
109 NULL); 250 NULL);
110 scheduler_.reset(new DriveScheduler(profile_.get(), 251 scheduler_.reset(new DriveScheduler(profile_.get(),
252 fake_drive_service_.get(),
111 &drive_operations_)); 253 &drive_operations_));
112 254
113 scheduler_->Initialize(); 255 scheduler_->Initialize();
114 scheduler_->SetDisableThrottling(true); 256 scheduler_->SetDisableThrottling(true);
115 } 257 }
116 258
117 virtual void TearDown() OVERRIDE { 259 virtual void TearDown() OVERRIDE {
118 // The scheduler should be deleted before NetworkLibrary, as it 260 // The scheduler should be deleted before NetworkLibrary, as it
119 // registers itself as observer of NetworkLibrary. 261 // registers itself as observer of NetworkLibrary.
120 scheduler_.reset(); 262 scheduler_.reset();
121 google_apis::test_util::RunBlockingPoolTask(); 263 google_apis::test_util::RunBlockingPoolTask();
264 fake_drive_service_.reset();
122 mock_network_change_notifier_.reset(); 265 mock_network_change_notifier_.reset();
123 } 266 }
124 267
125 // Sets up MockNetworkChangeNotifier as if it's connected to a network with 268 // Sets up MockNetworkChangeNotifier as if it's connected to a network with
126 // the specified connection type. 269 // the specified connection type.
127 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) { 270 void ChangeConnectionType(net::NetworkChangeNotifier::ConnectionType type) {
128 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType()) 271 EXPECT_CALL(*mock_network_change_notifier_, GetCurrentConnectionType())
129 .WillRepeatedly(Return(type)); 272 .WillRepeatedly(Return(type));
130 // Notify the sync client that the network is changed. This is done via 273 // Notify the sync client that the network is changed. This is done via
131 // NetworkChangeNotifier in production, but here, we simulate the behavior 274 // NetworkChangeNotifier in production, but here, we simulate the behavior
(...skipping 20 matching lines...) Expand all
152 void ConnectToNone() { 295 void ConnectToNone() {
153 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE); 296 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE);
154 } 297 }
155 298
156 protected: 299 protected:
157 MessageLoopForUI message_loop_; 300 MessageLoopForUI message_loop_;
158 content::TestBrowserThread ui_thread_; 301 content::TestBrowserThread ui_thread_;
159 scoped_ptr<TestingProfile> profile_; 302 scoped_ptr<TestingProfile> profile_;
160 scoped_ptr<DriveScheduler> scheduler_; 303 scoped_ptr<DriveScheduler> scheduler_;
161 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; 304 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_;
305 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
162 306
163 file_system::DriveOperations drive_operations_; 307 file_system::DriveOperations drive_operations_;
164 StrictMock<MockCopyOperation>* mock_copy_operation_; 308 StrictMock<MockCopyOperation>* mock_copy_operation_;
165 StrictMock<MockMoveOperation>* mock_move_operation_; 309 StrictMock<MockMoveOperation>* mock_move_operation_;
166 StrictMock<MockRemoveOperation>* mock_remove_operation_; 310 StrictMock<MockRemoveOperation>* mock_remove_operation_;
167 }; 311 };
168 312
169 TEST_F(DriveSchedulerTest, CopyFile) { 313 TEST_F(DriveSchedulerTest, CopyFile) {
170 ConnectToWifi(); 314 ConnectToWifi();
171 315
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 374
231 DriveFileError error(DRIVE_FILE_ERROR_FAILED); 375 DriveFileError error(DRIVE_FILE_ERROR_FAILED);
232 scheduler_->TransferRegularFile( 376 scheduler_->TransferRegularFile(
233 file_in_root, dest_file, 377 file_in_root, dest_file,
234 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 378 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
235 google_apis::test_util::RunBlockingPoolTask(); 379 google_apis::test_util::RunBlockingPoolTask();
236 380
237 ASSERT_EQ(DRIVE_FILE_OK, error); 381 ASSERT_EQ(DRIVE_FILE_OK, error);
238 } 382 }
239 383
384 TEST_F(DriveSchedulerTest, GetDocuments) {
385 ConnectToWifi();
386
387 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
388 scoped_ptr<base::Value> value;
389
390 scheduler_->GetDocuments(
391 GURL("http://example.com/gdata/root_feed.json"),
392 0,
393 std::string(),
394 true,
395 std::string(),
396 base::Bind(&google_apis::test_util::CopyResultsFromGetDataCallback,
397 &error,
398 &value));
399 google_apis::test_util::RunBlockingPoolTask();
400
401 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
satorux1 2012/11/28 23:59:47 ASSERT_TRUE(value);
Zachary Kuznia 2012/11/30 05:42:30 Done.
402 }
403
240 TEST_F(DriveSchedulerTest, MoveFile) { 404 TEST_F(DriveSchedulerTest, MoveFile) {
241 ConnectToWifi(); 405 ConnectToWifi();
242 406
243 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 407 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
244 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt")); 408 FilePath dest_file(FILE_PATH_LITERAL("drive/File 1.txt"));
245 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _)) 409 EXPECT_CALL(*mock_move_operation_, Move(file_in_root, dest_file, _))
246 .WillOnce(MockOperation(DRIVE_FILE_OK)); 410 .WillOnce(MockOperation(DRIVE_FILE_OK));
247 411
248 DriveFileError error(DRIVE_FILE_ERROR_FAILED); 412 DriveFileError error(DRIVE_FILE_ERROR_FAILED);
249 scheduler_->Move( 413 scheduler_->Move(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 563
400 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 564 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
401 DriveFileError error; 565 DriveFileError error;
402 scheduler_->Remove( 566 scheduler_->Remove(
403 file_in_root, false, 567 file_in_root, false,
404 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 568 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
405 google_apis::test_util::RunBlockingPoolTask(); 569 google_apis::test_util::RunBlockingPoolTask();
406 } 570 }
407 571
408 } // namespace drive 572 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698