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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc

Issue 14146006: Refactoring: replace SearchInDirectory by SearchByTitle. (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/sync_file_system/drive_file_sync_client.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_client.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 virtual void TearDown() OVERRIDE { 127 virtual void TearDown() OVERRIDE {
128 EXPECT_CALL(*mock_drive_service_, RemoveObserver(_)); 128 EXPECT_CALL(*mock_drive_service_, RemoveObserver(_));
129 EXPECT_CALL(*mock_drive_service(), CancelAll()); 129 EXPECT_CALL(*mock_drive_service(), CancelAll());
130 sync_client_.reset(); 130 sync_client_.reset();
131 } 131 }
132 132
133 protected: 133 protected:
134 DriveFileSyncClient* sync_client() { return sync_client_.get(); } 134 DriveFileSyncClient* sync_client() { return sync_client_.get(); }
135 135
136 std::string FormatOriginQuery(const GURL& origin) {
137 return FormatTitleQuery(
138 DriveFileSyncClient::OriginToDirectoryTitle(origin));
139 }
140
141 std::string FormatTitleQuery(const std::string& title) {
142 return DriveFileSyncClient::FormatTitleQuery(title);
143 }
144
145 StrictMock<MockDriveService>* mock_drive_service() { 136 StrictMock<MockDriveService>* mock_drive_service() {
146 return mock_drive_service_; 137 return mock_drive_service_;
147 } 138 }
148 139
149 MessageLoop* message_loop() { return &message_loop_; } 140 MessageLoop* message_loop() { return &message_loop_; }
150 141
151 private: 142 private:
152 MessageLoop message_loop_; 143 MessageLoop message_loop_;
153 144
154 TestingProfile profile_; 145 TestingProfile profile_;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 TEST_F(DriveFileSyncClientTest, GetSyncRoot) { 272 TEST_F(DriveFileSyncClientTest, GetSyncRoot) {
282 const std::string kRootResourceId = "folder:root"; 273 const std::string kRootResourceId = "folder:root";
283 const std::string kSyncRootResourceId = "folder:sync_root_resource_id"; 274 const std::string kSyncRootResourceId = "folder:sync_root_resource_id";
284 scoped_ptr<base::Value> found_result_value( 275 scoped_ptr<base::Value> found_result_value(
285 LoadJSONFile("chromeos/sync_file_system/sync_root_found.json").Pass()); 276 LoadJSONFile("chromeos/sync_file_system/sync_root_found.json").Pass());
286 scoped_ptr<google_apis::ResourceList> found_result = 277 scoped_ptr<google_apis::ResourceList> found_result =
287 google_apis::ResourceList::ExtractAndParse(*found_result_value); 278 google_apis::ResourceList::ExtractAndParse(*found_result_value);
288 279
289 // Expect to call Search from GetDriveDirectoryForSyncRoot. 280 // Expect to call Search from GetDriveDirectoryForSyncRoot.
290 EXPECT_CALL(*mock_drive_service(), 281 EXPECT_CALL(*mock_drive_service(),
291 Search(FormatTitleQuery(kSyncRootDirectoryName), _)) 282 SearchByTitle(kSyncRootDirectoryName, "", _))
tzik 2013/04/18 14:26:23 s/""/std::string()/ ?
hidehiko 2013/04/22 04:24:45 Done.
292 .WillOnce(InvokeGetResourceListCallback1( 283 .WillOnce(InvokeGetResourceListCallback2(
293 google_apis::HTTP_SUCCESS, 284 google_apis::HTTP_SUCCESS,
294 base::Passed(&found_result))); 285 base::Passed(&found_result)));
295 286
296 // Expect to call GetRootResourceId and RemoveResourceFromDirectory from 287 // Expect to call GetRootResourceId and RemoveResourceFromDirectory from
297 // EnsureSyncRootIsNotInMyDrive. 288 // EnsureSyncRootIsNotInMyDrive.
298 EXPECT_CALL(*mock_drive_service(), GetRootResourceId()) 289 EXPECT_CALL(*mock_drive_service(), GetRootResourceId())
299 .WillRepeatedly(Return(kRootResourceId)); 290 .WillRepeatedly(Return(kRootResourceId));
300 EXPECT_CALL(*mock_drive_service(), 291 EXPECT_CALL(*mock_drive_service(),
301 RemoveResourceFromDirectory(kRootResourceId, 292 RemoveResourceFromDirectory(kRootResourceId,
302 kSyncRootResourceId, 293 kSyncRootResourceId,
(...skipping 24 matching lines...) Expand all
327 google_apis::ResourceList::ExtractAndParse(*found_result_value); 318 google_apis::ResourceList::ExtractAndParse(*found_result_value);
328 319
329 scoped_ptr<base::Value> created_result_value = 320 scoped_ptr<base::Value> created_result_value =
330 LoadJSONFile("chromeos/sync_file_system/sync_root_created.json").Pass(); 321 LoadJSONFile("chromeos/sync_file_system/sync_root_created.json").Pass();
331 scoped_ptr<google_apis::ResourceEntry> created_result = 322 scoped_ptr<google_apis::ResourceEntry> created_result =
332 google_apis::ResourceEntry::ExtractAndParse(*created_result_value); 323 google_apis::ResourceEntry::ExtractAndParse(*created_result_value);
333 324
334 // Expect to call Search from GetDriveDirectoryForSyncRoot and 325 // Expect to call Search from GetDriveDirectoryForSyncRoot and
335 // EnsureTitleUniqueness 326 // EnsureTitleUniqueness
336 EXPECT_CALL(*mock_drive_service(), 327 EXPECT_CALL(*mock_drive_service(),
337 Search(FormatTitleQuery(kSyncRootDirectoryName), _)) 328 SearchByTitle(kSyncRootDirectoryName, "", _))
tzik 2013/04/18 14:26:23 ditto
hidehiko 2013/04/22 04:24:45 Done.
338 .WillOnce(InvokeGetResourceListCallback1( 329 .WillOnce(InvokeGetResourceListCallback2(
339 google_apis::HTTP_SUCCESS, 330 google_apis::HTTP_SUCCESS,
340 base::Passed(&not_found_result))) 331 base::Passed(&not_found_result)))
341 .WillOnce(InvokeGetResourceListCallback1( 332 .WillOnce(InvokeGetResourceListCallback2(
342 google_apis::HTTP_SUCCESS, 333 google_apis::HTTP_SUCCESS,
343 base::Passed(&found_result))); 334 base::Passed(&found_result)));
344 335
345 // Expect to call GetRootResourceId from GetDriveDirectoryForSyncRoot for the 336 // Expect to call GetRootResourceId from GetDriveDirectoryForSyncRoot for the
346 // first, and from EnsureSyncRootIsNotInMyDrive for the second. 337 // first, and from EnsureSyncRootIsNotInMyDrive for the second.
347 EXPECT_CALL(*mock_drive_service(), GetRootResourceId()) 338 EXPECT_CALL(*mock_drive_service(), GetRootResourceId())
348 .WillRepeatedly(Return(kRootResourceId)); 339 .WillRepeatedly(Return(kRootResourceId));
349 340
350 // Expect to call AddNewDirectory from GetDriveDirectoryForSyncRoot. 341 // Expect to call AddNewDirectory from GetDriveDirectoryForSyncRoot.
351 EXPECT_CALL(*mock_drive_service(), 342 EXPECT_CALL(*mock_drive_service(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 google_apis::ResourceList::ExtractAndParse(*duplicated_result_value); 377 google_apis::ResourceList::ExtractAndParse(*duplicated_result_value);
387 378
388 scoped_ptr<base::Value> created_result_value = 379 scoped_ptr<base::Value> created_result_value =
389 LoadJSONFile("chromeos/sync_file_system/sync_root_created.json").Pass(); 380 LoadJSONFile("chromeos/sync_file_system/sync_root_created.json").Pass();
390 scoped_ptr<google_apis::ResourceEntry> created_result = 381 scoped_ptr<google_apis::ResourceEntry> created_result =
391 google_apis::ResourceEntry::ExtractAndParse(*created_result_value); 382 google_apis::ResourceEntry::ExtractAndParse(*created_result_value);
392 383
393 // Expect to call Search from GetDriveDirectoryForSyncRoot and 384 // Expect to call Search from GetDriveDirectoryForSyncRoot and
394 // EnsureTitleUniqueness. 385 // EnsureTitleUniqueness.
395 EXPECT_CALL(*mock_drive_service(), 386 EXPECT_CALL(*mock_drive_service(),
396 Search(FormatTitleQuery(kSyncRootDirectoryName), _)) 387 SearchByTitle(kSyncRootDirectoryName, "", _))
tzik 2013/04/18 14:26:23 ditto
hidehiko 2013/04/22 04:24:45 Done.
397 .WillOnce(InvokeGetResourceListCallback1( 388 .WillOnce(InvokeGetResourceListCallback2(
398 google_apis::HTTP_SUCCESS, 389 google_apis::HTTP_SUCCESS,
399 base::Passed(&not_found_result))) 390 base::Passed(&not_found_result)))
400 .WillOnce(InvokeGetResourceListCallback1( 391 .WillOnce(InvokeGetResourceListCallback2(
401 google_apis::HTTP_SUCCESS, 392 google_apis::HTTP_SUCCESS,
402 base::Passed(&duplicated_result))); 393 base::Passed(&duplicated_result)));
403 394
404 // Expect to call GetRootResourceId from GetDriveDirectoryForSyncRoot for the 395 // Expect to call GetRootResourceId from GetDriveDirectoryForSyncRoot for the
405 // first, and from EnsureSyncRootIsNotInMyDrive for the second. 396 // first, and from EnsureSyncRootIsNotInMyDrive for the second.
406 EXPECT_CALL(*mock_drive_service(), GetRootResourceId()) 397 EXPECT_CALL(*mock_drive_service(), GetRootResourceId())
407 .WillRepeatedly(Return(kRootResourceId)); 398 .WillRepeatedly(Return(kRootResourceId));
408 399
409 // Expect to call AddNewDirectory from GetDriveDirectoryForSyncRoot. 400 // Expect to call AddNewDirectory from GetDriveDirectoryForSyncRoot.
410 EXPECT_CALL(*mock_drive_service(), 401 EXPECT_CALL(*mock_drive_service(),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 const GURL kOrigin("chrome-extension://example"); 435 const GURL kOrigin("chrome-extension://example");
445 436
446 scoped_ptr<base::Value> found_result_value( 437 scoped_ptr<base::Value> found_result_value(
447 LoadJSONFile( 438 LoadJSONFile(
448 "chromeos/sync_file_system/origin_directory_found.json").Pass()); 439 "chromeos/sync_file_system/origin_directory_found.json").Pass());
449 scoped_ptr<google_apis::ResourceList> found_result = 440 scoped_ptr<google_apis::ResourceList> found_result =
450 google_apis::ResourceList::ExtractAndParse(*found_result_value); 441 google_apis::ResourceList::ExtractAndParse(*found_result_value);
451 442
452 // Expect to call SearchInDirectory from GetDriveDirectoryForOrigin. 443 // Expect to call SearchInDirectory from GetDriveDirectoryForOrigin.
453 EXPECT_CALL(*mock_drive_service(), 444 EXPECT_CALL(*mock_drive_service(),
454 SearchInDirectory(FormatOriginQuery(kOrigin), 445 SearchByTitle(
455 kParentResourceId, 446 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin),
456 _)) 447 kParentResourceId, _))
457 .WillOnce(InvokeGetResourceListCallback2( 448 .WillOnce(InvokeGetResourceListCallback2(
458 google_apis::HTTP_SUCCESS, 449 google_apis::HTTP_SUCCESS,
459 base::Passed(&found_result))); 450 base::Passed(&found_result)));
460 451
461 bool done = false; 452 bool done = false;
462 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 453 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
463 std::string resource_id; 454 std::string resource_id;
464 sync_client()->GetDriveDirectoryForOrigin( 455 sync_client()->GetDriveDirectoryForOrigin(
465 kParentResourceId, kOrigin, 456 kParentResourceId, kOrigin,
466 base::Bind(&DidGetResourceID, &done, &error, &resource_id)); 457 base::Bind(&DidGetResourceID, &done, &error, &resource_id));
(...skipping 25 matching lines...) Expand all
492 scoped_ptr<google_apis::ResourceEntry> got_parent_result 483 scoped_ptr<google_apis::ResourceEntry> got_parent_result
493 = google_apis::ResourceEntry::ExtractAndParse(*got_parent_result_value); 484 = google_apis::ResourceEntry::ExtractAndParse(*got_parent_result_value);
494 scoped_ptr<base::Value> created_result_value( 485 scoped_ptr<base::Value> created_result_value(
495 LoadJSONFile( 486 LoadJSONFile(
496 "chromeos/sync_file_system/origin_directory_created.json").Pass()); 487 "chromeos/sync_file_system/origin_directory_created.json").Pass());
497 scoped_ptr<google_apis::ResourceEntry> created_result = 488 scoped_ptr<google_apis::ResourceEntry> created_result =
498 google_apis::ResourceEntry::ExtractAndParse(*created_result_value); 489 google_apis::ResourceEntry::ExtractAndParse(*created_result_value);
499 490
500 // Expect to call SearchInDirectory from GetDriveDirectoryForOrigin. 491 // Expect to call SearchInDirectory from GetDriveDirectoryForOrigin.
501 EXPECT_CALL(*mock_drive_service(), 492 EXPECT_CALL(*mock_drive_service(),
502 SearchInDirectory(FormatOriginQuery(kOrigin), 493 SearchByTitle(
503 kParentResourceId, // directory_resource_id 494 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin),
504 _)) 495 kParentResourceId, // directory_resource_id
496 _))
505 .WillOnce(InvokeGetResourceListCallback2( 497 .WillOnce(InvokeGetResourceListCallback2(
506 google_apis::HTTP_SUCCESS, 498 google_apis::HTTP_SUCCESS,
507 base::Passed(&not_found_result))) 499 base::Passed(&not_found_result)))
508 .WillOnce(InvokeGetResourceListCallback2( 500 .WillOnce(InvokeGetResourceListCallback2(
509 google_apis::HTTP_SUCCESS, 501 google_apis::HTTP_SUCCESS,
510 base::Passed(&found_result))); 502 base::Passed(&found_result)));
511 503
512 std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); 504 std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
513 // Expect to call AddNewDirectory from GetDriveDirectoryForOrigin. 505 // Expect to call AddNewDirectory from GetDriveDirectoryForOrigin.
514 EXPECT_CALL(*mock_drive_service(), 506 EXPECT_CALL(*mock_drive_service(),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 = google_apis::ResourceEntry::ExtractAndParse(*got_parent_result_value); 543 = google_apis::ResourceEntry::ExtractAndParse(*got_parent_result_value);
552 scoped_ptr<base::Value> created_result_value( 544 scoped_ptr<base::Value> created_result_value(
553 LoadJSONFile( 545 LoadJSONFile(
554 "chromeos/sync_file_system/origin_directory_created.json").Pass()); 546 "chromeos/sync_file_system/origin_directory_created.json").Pass());
555 scoped_ptr<google_apis::ResourceEntry> created_result = 547 scoped_ptr<google_apis::ResourceEntry> created_result =
556 google_apis::ResourceEntry::ExtractAndParse(*created_result_value); 548 google_apis::ResourceEntry::ExtractAndParse(*created_result_value);
557 549
558 // Expect to call SearchInDirectory from GetDriveDirectoryForOrigin for the 550 // Expect to call SearchInDirectory from GetDriveDirectoryForOrigin for the
559 // first, and from EnsureTitleUniqueness for the second. 551 // first, and from EnsureTitleUniqueness for the second.
560 EXPECT_CALL(*mock_drive_service(), 552 EXPECT_CALL(*mock_drive_service(),
561 SearchInDirectory(FormatOriginQuery(kOrigin), 553 SearchByTitle(
562 kParentResourceId, // directory_resource_id 554 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin),
563 _)) 555 kParentResourceId, // directory_resource_id
556 _))
564 .WillOnce(InvokeGetResourceListCallback2( 557 .WillOnce(InvokeGetResourceListCallback2(
565 google_apis::HTTP_SUCCESS, 558 google_apis::HTTP_SUCCESS,
566 base::Passed(&not_found_result))) 559 base::Passed(&not_found_result)))
567 .WillOnce(InvokeGetResourceListCallback2( 560 .WillOnce(InvokeGetResourceListCallback2(
568 google_apis::HTTP_SUCCESS, 561 google_apis::HTTP_SUCCESS,
569 base::Passed(&duplicated_result))); 562 base::Passed(&duplicated_result)));
570 563
571 std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); 564 std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
572 // Expect to call AddNewDirectory from GetDriveDirectoryForOrigin. 565 // Expect to call AddNewDirectory from GetDriveDirectoryForOrigin.
573 EXPECT_CALL(*mock_drive_service(), 566 EXPECT_CALL(*mock_drive_service(),
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 832
840 scoped_ptr<base::Value> verifying_file_found_data( 833 scoped_ptr<base::Value> verifying_file_found_data(
841 LoadJSONFile( 834 LoadJSONFile(
842 "chromeos/sync_file_system/verifing_file_found.json").Pass()); 835 "chromeos/sync_file_system/verifing_file_found.json").Pass());
843 scoped_ptr<ResourceList> verifying_file_found( 836 scoped_ptr<ResourceList> verifying_file_found(
844 ResourceList::ExtractAndParse(*verifying_file_found_data)); 837 ResourceList::ExtractAndParse(*verifying_file_found_data));
845 838
846 // Expect to call SearchInDirectory from 839 // Expect to call SearchInDirectory from
847 // DriveFileSyncClient::EnsureTitleUniqueness. 840 // DriveFileSyncClient::EnsureTitleUniqueness.
848 EXPECT_CALL(*mock_drive_service(), 841 EXPECT_CALL(*mock_drive_service(),
849 SearchInDirectory(FormatTitleQuery(kTitle), 842 SearchByTitle(kTitle, kDirectoryResourceId, _))
850 kDirectoryResourceId,
851 _))
852 .WillOnce(InvokeGetResourceListCallback2( 843 .WillOnce(InvokeGetResourceListCallback2(
853 google_apis::HTTP_SUCCESS, 844 google_apis::HTTP_SUCCESS,
854 base::Passed(&verifying_file_found))); 845 base::Passed(&verifying_file_found)));
855 846
856 bool done = false; 847 bool done = false;
857 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 848 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
858 std::string resource_id; 849 std::string resource_id;
859 sync_client()->UploadNewFile(kDirectoryResourceId, 850 sync_client()->UploadNewFile(kDirectoryResourceId,
860 kLocalFilePath, 851 kLocalFilePath,
861 kTitle, 852 kTitle,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 base::Bind(&DidDeleteFile, &done, &error)); 1001 base::Bind(&DidDeleteFile, &done, &error));
1011 message_loop()->RunUntilIdle(); 1002 message_loop()->RunUntilIdle();
1012 1003
1013 EXPECT_TRUE(done); 1004 EXPECT_TRUE(done);
1014 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); 1005 EXPECT_EQ(google_apis::HTTP_CONFLICT, error);
1015 } 1006 }
1016 1007
1017 #endif // !defined(OS_ANDROID) 1008 #endif // !defined(OS_ANDROID)
1018 1009
1019 } // namespace sync_file_system 1010 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698