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

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

Issue 14493009: drive: Rename DriveScheduler to JobScheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indent 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_scheduler.h" 5 #include "chrome/browser/chromeos/drive/job_scheduler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/chromeos/drive/test_util.h" 14 #include "chrome/browser/chromeos/drive/test_util.h"
15 #include "chrome/browser/google_apis/drive_api_parser.h" 15 #include "chrome/browser/google_apis/drive_api_parser.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 virtual void OnJobDone(const JobInfo& info, FileError error) OVERRIDE { 91 virtual void OnJobDone(const JobInfo& info, FileError error) OVERRIDE {
92 events.push_back(EventLog(DONE, info)); 92 events.push_back(EventLog(DONE, info));
93 } 93 }
94 94
95 private: 95 private:
96 std::vector<EventLog> events; 96 std::vector<EventLog> events;
97 }; 97 };
98 98
99 } // namespace 99 } // namespace
100 100
101 class DriveSchedulerTest : public testing::Test { 101 class JobSchedulerTest : public testing::Test {
102 public: 102 public:
103 DriveSchedulerTest() 103 JobSchedulerTest()
104 : ui_thread_(content::BrowserThread::UI, &message_loop_), 104 : ui_thread_(content::BrowserThread::UI, &message_loop_),
105 profile_(new TestingProfile) { 105 profile_(new TestingProfile) {
106 } 106 }
107 107
108 virtual void SetUp() OVERRIDE { 108 virtual void SetUp() OVERRIDE {
109 fake_network_change_notifier_.reset(new FakeNetworkChangeNotifier); 109 fake_network_change_notifier_.reset(new FakeNetworkChangeNotifier);
110 110
111 fake_drive_service_.reset(new google_apis::FakeDriveService()); 111 fake_drive_service_.reset(new google_apis::FakeDriveService());
112 fake_drive_service_->LoadResourceListForWapi( 112 fake_drive_service_->LoadResourceListForWapi(
113 "chromeos/gdata/root_feed.json"); 113 "chromeos/gdata/root_feed.json");
114 fake_drive_service_->LoadAccountMetadataForWapi( 114 fake_drive_service_->LoadAccountMetadataForWapi(
115 "chromeos/gdata/account_metadata.json"); 115 "chromeos/gdata/account_metadata.json");
116 fake_drive_service_->LoadAppListForDriveApi( 116 fake_drive_service_->LoadAppListForDriveApi(
117 "chromeos/drive/applist.json"); 117 "chromeos/drive/applist.json");
118 118
119 scheduler_.reset(new DriveScheduler(profile_.get(), 119 scheduler_.reset(new JobScheduler(profile_.get(),
120 fake_drive_service_.get())); 120 fake_drive_service_.get()));
121 scheduler_->SetDisableThrottling(true); 121 scheduler_->SetDisableThrottling(true);
122 } 122 }
123 123
124 virtual void TearDown() OVERRIDE { 124 virtual void TearDown() OVERRIDE {
125 // The scheduler should be deleted before NetworkLibrary, as it 125 // The scheduler should be deleted before NetworkLibrary, as it
126 // registers itself as observer of NetworkLibrary. 126 // registers itself as observer of NetworkLibrary.
127 scheduler_.reset(); 127 scheduler_.reset();
128 google_apis::test_util::RunBlockingPoolTask(); 128 google_apis::test_util::RunBlockingPoolTask();
129 fake_drive_service_.reset(); 129 fake_drive_service_.reset();
130 fake_network_change_notifier_.reset(); 130 fake_network_change_notifier_.reset();
(...skipping 26 matching lines...) Expand all
157 } 157 }
158 158
159 // Sets up FakeNetworkChangeNotifier as if it's disconnected. 159 // Sets up FakeNetworkChangeNotifier as if it's disconnected.
160 void ConnectToNone() { 160 void ConnectToNone() {
161 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE); 161 ChangeConnectionType(net::NetworkChangeNotifier::CONNECTION_NONE);
162 } 162 }
163 163
164 MessageLoopForUI message_loop_; 164 MessageLoopForUI message_loop_;
165 content::TestBrowserThread ui_thread_; 165 content::TestBrowserThread ui_thread_;
166 scoped_ptr<TestingProfile> profile_; 166 scoped_ptr<TestingProfile> profile_;
167 scoped_ptr<DriveScheduler> scheduler_; 167 scoped_ptr<JobScheduler> scheduler_;
168 scoped_ptr<FakeNetworkChangeNotifier> fake_network_change_notifier_; 168 scoped_ptr<FakeNetworkChangeNotifier> fake_network_change_notifier_;
169 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; 169 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
170 }; 170 };
171 171
172 TEST_F(DriveSchedulerTest, GetAboutResource) { 172 TEST_F(JobSchedulerTest, GetAboutResource) {
173 ConnectToWifi(); 173 ConnectToWifi();
174 174
175 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 175 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
176 scoped_ptr<google_apis::AboutResource> about_resource; 176 scoped_ptr<google_apis::AboutResource> about_resource;
177 scheduler_->GetAboutResource( 177 scheduler_->GetAboutResource(
178 google_apis::test_util::CreateCopyResultCallback( 178 google_apis::test_util::CreateCopyResultCallback(
179 &error, &about_resource)); 179 &error, &about_resource));
180 google_apis::test_util::RunBlockingPoolTask(); 180 google_apis::test_util::RunBlockingPoolTask();
181 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 181 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
182 ASSERT_TRUE(about_resource); 182 ASSERT_TRUE(about_resource);
183 } 183 }
184 184
185 TEST_F(DriveSchedulerTest, GetAppList) { 185 TEST_F(JobSchedulerTest, GetAppList) {
186 ConnectToWifi(); 186 ConnectToWifi();
187 187
188 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 188 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
189 scoped_ptr<google_apis::AppList> app_list; 189 scoped_ptr<google_apis::AppList> app_list;
190 190
191 scheduler_->GetAppList( 191 scheduler_->GetAppList(
192 google_apis::test_util::CreateCopyResultCallback(&error, &app_list)); 192 google_apis::test_util::CreateCopyResultCallback(&error, &app_list));
193 google_apis::test_util::RunBlockingPoolTask(); 193 google_apis::test_util::RunBlockingPoolTask();
194 194
195 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 195 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
196 ASSERT_TRUE(app_list); 196 ASSERT_TRUE(app_list);
197 } 197 }
198 198
199 TEST_F(DriveSchedulerTest, GetAccountMetadata) { 199 TEST_F(JobSchedulerTest, GetAccountMetadata) {
200 ConnectToWifi(); 200 ConnectToWifi();
201 201
202 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 202 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
203 scoped_ptr<google_apis::AccountMetadata> account_metadata; 203 scoped_ptr<google_apis::AccountMetadata> account_metadata;
204 204
205 scheduler_->GetAccountMetadata( 205 scheduler_->GetAccountMetadata(
206 google_apis::test_util::CreateCopyResultCallback( 206 google_apis::test_util::CreateCopyResultCallback(
207 &error, &account_metadata)); 207 &error, &account_metadata));
208 google_apis::test_util::RunBlockingPoolTask(); 208 google_apis::test_util::RunBlockingPoolTask();
209 209
210 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 210 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
211 ASSERT_TRUE(account_metadata); 211 ASSERT_TRUE(account_metadata);
212 } 212 }
213 213
214 TEST_F(DriveSchedulerTest, GetAllResourceList) { 214 TEST_F(JobSchedulerTest, GetAllResourceList) {
215 ConnectToWifi(); 215 ConnectToWifi();
216 216
217 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 217 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
218 scoped_ptr<google_apis::ResourceList> resource_list; 218 scoped_ptr<google_apis::ResourceList> resource_list;
219 219
220 scheduler_->GetAllResourceList( 220 scheduler_->GetAllResourceList(
221 google_apis::test_util::CreateCopyResultCallback( 221 google_apis::test_util::CreateCopyResultCallback(
222 &error, &resource_list)); 222 &error, &resource_list));
223 google_apis::test_util::RunBlockingPoolTask(); 223 google_apis::test_util::RunBlockingPoolTask();
224 224
225 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 225 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
226 ASSERT_TRUE(resource_list); 226 ASSERT_TRUE(resource_list);
227 } 227 }
228 228
229 TEST_F(DriveSchedulerTest, GetResourceListInDirectory) { 229 TEST_F(JobSchedulerTest, GetResourceListInDirectory) {
230 ConnectToWifi(); 230 ConnectToWifi();
231 231
232 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 232 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
233 scoped_ptr<google_apis::ResourceList> resource_list; 233 scoped_ptr<google_apis::ResourceList> resource_list;
234 234
235 scheduler_->GetResourceListInDirectory( 235 scheduler_->GetResourceListInDirectory(
236 fake_drive_service_->GetRootResourceId(), 236 fake_drive_service_->GetRootResourceId(),
237 google_apis::test_util::CreateCopyResultCallback( 237 google_apis::test_util::CreateCopyResultCallback(
238 &error, &resource_list)); 238 &error, &resource_list));
239 google_apis::test_util::RunBlockingPoolTask(); 239 google_apis::test_util::RunBlockingPoolTask();
240 240
241 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 241 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
242 ASSERT_TRUE(resource_list); 242 ASSERT_TRUE(resource_list);
243 } 243 }
244 244
245 TEST_F(DriveSchedulerTest, Search) { 245 TEST_F(JobSchedulerTest, Search) {
246 ConnectToWifi(); 246 ConnectToWifi();
247 247
248 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 248 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
249 scoped_ptr<google_apis::ResourceList> resource_list; 249 scoped_ptr<google_apis::ResourceList> resource_list;
250 250
251 scheduler_->Search( 251 scheduler_->Search(
252 "File", // search query 252 "File", // search query
253 google_apis::test_util::CreateCopyResultCallback( 253 google_apis::test_util::CreateCopyResultCallback(
254 &error, &resource_list)); 254 &error, &resource_list));
255 google_apis::test_util::RunBlockingPoolTask(); 255 google_apis::test_util::RunBlockingPoolTask();
256 256
257 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 257 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
258 ASSERT_TRUE(resource_list); 258 ASSERT_TRUE(resource_list);
259 } 259 }
260 260
261 TEST_F(DriveSchedulerTest, GetChangeList) { 261 TEST_F(JobSchedulerTest, GetChangeList) {
262 ConnectToWifi(); 262 ConnectToWifi();
263 263
264 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 264 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
265 265
266 // Create a new directory. 266 // Create a new directory.
267 // The loaded (initial) changestamp is 654321. Thus, by this operation, 267 // The loaded (initial) changestamp is 654321. Thus, by this operation,
268 // it should become 654322. 268 // it should become 654322.
269 { 269 {
270 scoped_ptr<google_apis::ResourceEntry> resource_entry; 270 scoped_ptr<google_apis::ResourceEntry> resource_entry;
271 fake_drive_service_->AddNewDirectory( 271 fake_drive_service_->AddNewDirectory(
(...skipping 10 matching lines...) Expand all
282 scheduler_->GetChangeList( 282 scheduler_->GetChangeList(
283 654321 + 1, // start_changestamp 283 654321 + 1, // start_changestamp
284 google_apis::test_util::CreateCopyResultCallback( 284 google_apis::test_util::CreateCopyResultCallback(
285 &error, &resource_list)); 285 &error, &resource_list));
286 google_apis::test_util::RunBlockingPoolTask(); 286 google_apis::test_util::RunBlockingPoolTask();
287 287
288 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 288 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
289 ASSERT_TRUE(resource_list); 289 ASSERT_TRUE(resource_list);
290 } 290 }
291 291
292 TEST_F(DriveSchedulerTest, ContinueGetResourceList) { 292 TEST_F(JobSchedulerTest, ContinueGetResourceList) {
293 ConnectToWifi(); 293 ConnectToWifi();
294 fake_drive_service_->set_default_max_results(2); 294 fake_drive_service_->set_default_max_results(2);
295 295
296 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 296 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
297 scoped_ptr<google_apis::ResourceList> resource_list; 297 scoped_ptr<google_apis::ResourceList> resource_list;
298 298
299 scheduler_->GetAllResourceList( 299 scheduler_->GetAllResourceList(
300 google_apis::test_util::CreateCopyResultCallback( 300 google_apis::test_util::CreateCopyResultCallback(
301 &error, &resource_list)); 301 &error, &resource_list));
302 google_apis::test_util::RunBlockingPoolTask(); 302 google_apis::test_util::RunBlockingPoolTask();
(...skipping 13 matching lines...) Expand all
316 scheduler_->ContinueGetResourceList( 316 scheduler_->ContinueGetResourceList(
317 next_url, 317 next_url,
318 google_apis::test_util::CreateCopyResultCallback( 318 google_apis::test_util::CreateCopyResultCallback(
319 &error, &resource_list)); 319 &error, &resource_list));
320 google_apis::test_util::RunBlockingPoolTask(); 320 google_apis::test_util::RunBlockingPoolTask();
321 321
322 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 322 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
323 ASSERT_TRUE(resource_list); 323 ASSERT_TRUE(resource_list);
324 } 324 }
325 325
326 TEST_F(DriveSchedulerTest, GetResourceEntry) { 326 TEST_F(JobSchedulerTest, GetResourceEntry) {
327 ConnectToWifi(); 327 ConnectToWifi();
328 328
329 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 329 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
330 scoped_ptr<google_apis::ResourceEntry> entry; 330 scoped_ptr<google_apis::ResourceEntry> entry;
331 331
332 scheduler_->GetResourceEntry( 332 scheduler_->GetResourceEntry(
333 "file:2_file_resource_id", // resource ID 333 "file:2_file_resource_id", // resource ID
334 DriveClientContext(USER_INITIATED), 334 DriveClientContext(USER_INITIATED),
335 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 335 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
336 google_apis::test_util::RunBlockingPoolTask(); 336 google_apis::test_util::RunBlockingPoolTask();
337 337
338 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 338 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
339 ASSERT_TRUE(entry); 339 ASSERT_TRUE(entry);
340 } 340 }
341 341
342 TEST_F(DriveSchedulerTest, DeleteResource) { 342 TEST_F(JobSchedulerTest, DeleteResource) {
343 ConnectToWifi(); 343 ConnectToWifi();
344 344
345 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 345 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
346 346
347 scheduler_->DeleteResource( 347 scheduler_->DeleteResource(
348 "file:2_file_resource_id", 348 "file:2_file_resource_id",
349 google_apis::test_util::CreateCopyResultCallback(&error)); 349 google_apis::test_util::CreateCopyResultCallback(&error));
350 google_apis::test_util::RunBlockingPoolTask(); 350 google_apis::test_util::RunBlockingPoolTask();
351 351
352 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 352 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
353 } 353 }
354 354
355 TEST_F(DriveSchedulerTest, CopyHostedDocument) { 355 TEST_F(JobSchedulerTest, CopyHostedDocument) {
356 ConnectToWifi(); 356 ConnectToWifi();
357 357
358 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 358 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
359 scoped_ptr<google_apis::ResourceEntry> entry; 359 scoped_ptr<google_apis::ResourceEntry> entry;
360 360
361 scheduler_->CopyHostedDocument( 361 scheduler_->CopyHostedDocument(
362 "document:5_document_resource_id", // resource ID 362 "document:5_document_resource_id", // resource ID
363 "New Document", // new name 363 "New Document", // new name
364 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 364 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
365 google_apis::test_util::RunBlockingPoolTask(); 365 google_apis::test_util::RunBlockingPoolTask();
366 366
367 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 367 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
368 ASSERT_TRUE(entry); 368 ASSERT_TRUE(entry);
369 } 369 }
370 370
371 TEST_F(DriveSchedulerTest, RenameResource) { 371 TEST_F(JobSchedulerTest, RenameResource) {
372 ConnectToWifi(); 372 ConnectToWifi();
373 373
374 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 374 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
375 375
376 scheduler_->RenameResource( 376 scheduler_->RenameResource(
377 "file:2_file_resource_id", 377 "file:2_file_resource_id",
378 "New Name", 378 "New Name",
379 google_apis::test_util::CreateCopyResultCallback(&error)); 379 google_apis::test_util::CreateCopyResultCallback(&error));
380 google_apis::test_util::RunBlockingPoolTask(); 380 google_apis::test_util::RunBlockingPoolTask();
381 381
382 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 382 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
383 } 383 }
384 384
385 TEST_F(DriveSchedulerTest, AddResourceToDirectory) { 385 TEST_F(JobSchedulerTest, AddResourceToDirectory) {
386 ConnectToWifi(); 386 ConnectToWifi();
387 387
388 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 388 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
389 389
390 scheduler_->AddResourceToDirectory( 390 scheduler_->AddResourceToDirectory(
391 "folder:1_folder_resource_id", 391 "folder:1_folder_resource_id",
392 "file:2_file_resource_id", 392 "file:2_file_resource_id",
393 google_apis::test_util::CreateCopyResultCallback(&error)); 393 google_apis::test_util::CreateCopyResultCallback(&error));
394 google_apis::test_util::RunBlockingPoolTask(); 394 google_apis::test_util::RunBlockingPoolTask();
395 395
396 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 396 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
397 } 397 }
398 398
399 TEST_F(DriveSchedulerTest, RemoveResourceFromDirectory) { 399 TEST_F(JobSchedulerTest, RemoveResourceFromDirectory) {
400 ConnectToWifi(); 400 ConnectToWifi();
401 401
402 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 402 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
403 403
404 scheduler_->RemoveResourceFromDirectory( 404 scheduler_->RemoveResourceFromDirectory(
405 "folder:1_folder_resource_id", 405 "folder:1_folder_resource_id",
406 "file:subdirectory_file_1_id", // resource ID 406 "file:subdirectory_file_1_id", // resource ID
407 google_apis::test_util::CreateCopyResultCallback(&error)); 407 google_apis::test_util::CreateCopyResultCallback(&error));
408 google_apis::test_util::RunBlockingPoolTask(); 408 google_apis::test_util::RunBlockingPoolTask();
409 409
410 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); 410 ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
411 } 411 }
412 412
413 TEST_F(DriveSchedulerTest, AddNewDirectory) { 413 TEST_F(JobSchedulerTest, AddNewDirectory) {
414 ConnectToWifi(); 414 ConnectToWifi();
415 415
416 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 416 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
417 scoped_ptr<google_apis::ResourceEntry> entry; 417 scoped_ptr<google_apis::ResourceEntry> entry;
418 418
419 scheduler_->AddNewDirectory( 419 scheduler_->AddNewDirectory(
420 fake_drive_service_->GetRootResourceId(), // Root directory. 420 fake_drive_service_->GetRootResourceId(), // Root directory.
421 "New Directory", 421 "New Directory",
422 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 422 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
423 google_apis::test_util::RunBlockingPoolTask(); 423 google_apis::test_util::RunBlockingPoolTask();
424 424
425 ASSERT_EQ(google_apis::HTTP_CREATED, error); 425 ASSERT_EQ(google_apis::HTTP_CREATED, error);
426 ASSERT_TRUE(entry); 426 ASSERT_TRUE(entry);
427 } 427 }
428 428
429 TEST_F(DriveSchedulerTest, GetResourceEntryPriority) { 429 TEST_F(JobSchedulerTest, GetResourceEntryPriority) {
430 // Disconnect from the network to prevent jobs from starting. 430 // Disconnect from the network to prevent jobs from starting.
431 ConnectToNone(); 431 ConnectToNone();
432 432
433 std::string resource_1("file:1_file_resource_id"); 433 std::string resource_1("file:1_file_resource_id");
434 std::string resource_2("file:2_file_resource_id"); 434 std::string resource_2("file:2_file_resource_id");
435 std::string resource_3("file:3_file_resource_id"); 435 std::string resource_3("file:3_file_resource_id");
436 std::string resource_4("file:4_file_resource_id"); 436 std::string resource_4("file:4_file_resource_id");
437 std::vector<std::string> resource_ids; 437 std::vector<std::string> resource_ids;
438 438
439 scheduler_->GetResourceEntry( 439 scheduler_->GetResourceEntry(
(...skipping 25 matching lines...) Expand all
465 ConnectToWifi(); 465 ConnectToWifi();
466 google_apis::test_util::RunBlockingPoolTask(); 466 google_apis::test_util::RunBlockingPoolTask();
467 467
468 ASSERT_EQ(resource_ids.size(), 4ul); 468 ASSERT_EQ(resource_ids.size(), 4ul);
469 ASSERT_EQ(resource_ids[0], resource_1); 469 ASSERT_EQ(resource_ids[0], resource_1);
470 ASSERT_EQ(resource_ids[1], resource_4); 470 ASSERT_EQ(resource_ids[1], resource_4);
471 ASSERT_EQ(resource_ids[2], resource_3); 471 ASSERT_EQ(resource_ids[2], resource_3);
472 ASSERT_EQ(resource_ids[3], resource_2); 472 ASSERT_EQ(resource_ids[3], resource_2);
473 } 473 }
474 474
475 TEST_F(DriveSchedulerTest, GetResourceEntryNoConnection) { 475 TEST_F(JobSchedulerTest, GetResourceEntryNoConnection) {
476 ConnectToNone(); 476 ConnectToNone();
477 477
478 std::string resource("file:1_file_resource_id"); 478 std::string resource("file:1_file_resource_id");
479 std::vector<std::string> resource_ids; 479 std::vector<std::string> resource_ids;
480 480
481 scheduler_->GetResourceEntry( 481 scheduler_->GetResourceEntry(
482 resource, // resource ID 482 resource, // resource ID
483 DriveClientContext(BACKGROUND), 483 DriveClientContext(BACKGROUND),
484 base::Bind(&CopyResourceIdFromGetResourceEntryCallback, 484 base::Bind(&CopyResourceIdFromGetResourceEntryCallback,
485 &resource_ids, 485 &resource_ids,
486 resource)); 486 resource));
487 google_apis::test_util::RunBlockingPoolTask(); 487 google_apis::test_util::RunBlockingPoolTask();
488 488
489 ASSERT_EQ(resource_ids.size(), 0ul); 489 ASSERT_EQ(resource_ids.size(), 0ul);
490 490
491 // Reconnect to the net. 491 // Reconnect to the net.
492 ConnectToWifi(); 492 ConnectToWifi();
493 493
494 google_apis::test_util::RunBlockingPoolTask(); 494 google_apis::test_util::RunBlockingPoolTask();
495 495
496 ASSERT_EQ(resource_ids.size(), 1ul); 496 ASSERT_EQ(resource_ids.size(), 1ul);
497 ASSERT_EQ(resource_ids[0], resource); 497 ASSERT_EQ(resource_ids[0], resource);
498 } 498 }
499 499
500 TEST_F(DriveSchedulerTest, DownloadFileCellularDisabled) { 500 TEST_F(JobSchedulerTest, DownloadFileCellularDisabled) {
501 ConnectToCellular(); 501 ConnectToCellular();
502 502
503 // Disable fetching over cellular network. 503 // Disable fetching over cellular network.
504 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); 504 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true);
505 505
506 // Try to get a file in the background 506 // Try to get a file in the background
507 base::ScopedTempDir temp_dir; 507 base::ScopedTempDir temp_dir;
508 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 508 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
509 509
510 const GURL kContentUrl("https://file_content_url/"); 510 const GURL kContentUrl("https://file_content_url/");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 544
545 // Check the download again 545 // Check the download again
546 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); 546 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error);
547 std::string content; 547 std::string content;
548 EXPECT_EQ(output_file_path, kOutputFilePath); 548 EXPECT_EQ(output_file_path, kOutputFilePath);
549 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); 549 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
550 // The content is "x"s of the file size specified in root_feed.json. 550 // The content is "x"s of the file size specified in root_feed.json.
551 EXPECT_EQ("xxxxxxxxxx", content); 551 EXPECT_EQ("xxxxxxxxxx", content);
552 } 552 }
553 553
554 TEST_F(DriveSchedulerTest, DownloadFileWimaxDisabled) { 554 TEST_F(JobSchedulerTest, DownloadFileWimaxDisabled) {
555 ConnectToWimax(); 555 ConnectToWimax();
556 556
557 // Disable fetching over cellular network. 557 // Disable fetching over cellular network.
558 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); 558 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true);
559 559
560 // Try to get a file in the background 560 // Try to get a file in the background
561 base::ScopedTempDir temp_dir; 561 base::ScopedTempDir temp_dir;
562 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 562 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
563 563
564 const GURL kContentUrl("https://file_content_url/"); 564 const GURL kContentUrl("https://file_content_url/");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 598
599 // Check the download again 599 // Check the download again
600 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); 600 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error);
601 std::string content; 601 std::string content;
602 EXPECT_EQ(output_file_path, kOutputFilePath); 602 EXPECT_EQ(output_file_path, kOutputFilePath);
603 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); 603 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
604 // The content is "x"s of the file size specified in root_feed.json. 604 // The content is "x"s of the file size specified in root_feed.json.
605 EXPECT_EQ("xxxxxxxxxx", content); 605 EXPECT_EQ("xxxxxxxxxx", content);
606 } 606 }
607 607
608 TEST_F(DriveSchedulerTest, DownloadFileCellularEnabled) { 608 TEST_F(JobSchedulerTest, DownloadFileCellularEnabled) {
609 ConnectToCellular(); 609 ConnectToCellular();
610 610
611 // Enable fetching over cellular network. 611 // Enable fetching over cellular network.
612 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); 612 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false);
613 613
614 // Try to get a file in the background 614 // Try to get a file in the background
615 base::ScopedTempDir temp_dir; 615 base::ScopedTempDir temp_dir;
616 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 616 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
617 617
618 const GURL kContentUrl("https://file_content_url/"); 618 const GURL kContentUrl("https://file_content_url/");
(...skipping 25 matching lines...) Expand all
644 644
645 // Check the download 645 // Check the download
646 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); 646 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error);
647 std::string content; 647 std::string content;
648 EXPECT_EQ(output_file_path, kOutputFilePath); 648 EXPECT_EQ(output_file_path, kOutputFilePath);
649 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); 649 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
650 // The content is "x"s of the file size specified in root_feed.json. 650 // The content is "x"s of the file size specified in root_feed.json.
651 EXPECT_EQ("xxxxxxxxxx", content); 651 EXPECT_EQ("xxxxxxxxxx", content);
652 } 652 }
653 653
654 TEST_F(DriveSchedulerTest, DownloadFileWimaxEnabled) { 654 TEST_F(JobSchedulerTest, DownloadFileWimaxEnabled) {
655 ConnectToWimax(); 655 ConnectToWimax();
656 656
657 // Enable fetching over cellular network. 657 // Enable fetching over cellular network.
658 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false); 658 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, false);
659 659
660 // Try to get a file in the background 660 // Try to get a file in the background
661 base::ScopedTempDir temp_dir; 661 base::ScopedTempDir temp_dir;
662 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 662 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
663 663
664 const GURL kContentUrl("https://file_content_url/"); 664 const GURL kContentUrl("https://file_content_url/");
(...skipping 25 matching lines...) Expand all
690 690
691 // Check the download 691 // Check the download
692 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); 692 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error);
693 std::string content; 693 std::string content;
694 EXPECT_EQ(output_file_path, kOutputFilePath); 694 EXPECT_EQ(output_file_path, kOutputFilePath);
695 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); 695 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
696 // The content is "x"s of the file size specified in root_feed.json. 696 // The content is "x"s of the file size specified in root_feed.json.
697 EXPECT_EQ("xxxxxxxxxx", content); 697 EXPECT_EQ("xxxxxxxxxx", content);
698 } 698 }
699 699
700 TEST_F(DriveSchedulerTest, JobInfo) { 700 TEST_F(JobSchedulerTest, JobInfo) {
701 JobListLogger logger; 701 JobListLogger logger;
702 scheduler_->AddObserver(&logger); 702 scheduler_->AddObserver(&logger);
703 703
704 // Disable background upload/download. 704 // Disable background upload/download.
705 ConnectToWimax(); 705 ConnectToWimax();
706 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true); 706 profile_->GetPrefs()->SetBoolean(prefs::kDisableDriveOverCellular, true);
707 707
708 base::ScopedTempDir temp_dir; 708 base::ScopedTempDir temp_dir;
709 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 709 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
710 710
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 ConnectToWifi(); 806 ConnectToWifi();
807 google_apis::test_util::RunBlockingPoolTask(); 807 google_apis::test_util::RunBlockingPoolTask();
808 808
809 // All jobs should have finished. 809 // All jobs should have finished.
810 EXPECT_EQ(0U, scheduler_->GetJobInfoList().size()); 810 EXPECT_EQ(0U, scheduler_->GetJobInfoList().size());
811 EXPECT_TRUE(logger.Has(JobListLogger::UPDATED, TYPE_DOWNLOAD_FILE)); 811 EXPECT_TRUE(logger.Has(JobListLogger::UPDATED, TYPE_DOWNLOAD_FILE));
812 EXPECT_TRUE(logger.Has(JobListLogger::DONE, TYPE_DOWNLOAD_FILE)); 812 EXPECT_TRUE(logger.Has(JobListLogger::DONE, TYPE_DOWNLOAD_FILE));
813 } 813 }
814 814
815 815
816 TEST_F(DriveSchedulerTest, JobInfoProgress) { 816 TEST_F(JobSchedulerTest, JobInfoProgress) {
817 JobListLogger logger; 817 JobListLogger logger;
818 scheduler_->AddObserver(&logger); 818 scheduler_->AddObserver(&logger);
819 819
820 ConnectToWifi(); 820 ConnectToWifi();
821 821
822 base::ScopedTempDir temp_dir; 822 base::ScopedTempDir temp_dir;
823 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 823 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
824 824
825 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 825 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
826 base::FilePath path; 826 base::FilePath path;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 862
863 std::vector<int64> upload_progress; 863 std::vector<int64> upload_progress;
864 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress); 864 logger.GetProgressInfo(TYPE_UPLOAD_NEW_FILE, &upload_progress);
865 ASSERT_TRUE(!upload_progress.empty()); 865 ASSERT_TRUE(!upload_progress.empty());
866 EXPECT_TRUE(base::STLIsSorted(upload_progress)); 866 EXPECT_TRUE(base::STLIsSorted(upload_progress));
867 EXPECT_GE(upload_progress.front(), 0); 867 EXPECT_GE(upload_progress.front(), 0);
868 EXPECT_LE(upload_progress.back(), 5); 868 EXPECT_LE(upload_progress.back(), 5);
869 } 869 }
870 870
871 } // namespace drive 871 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/job_scheduler.cc ('k') | chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698