| OLD | NEW |
| 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 "chrome/browser/google_apis/drive_uploader.h" | 10 #include "chrome/browser/google_apis/drive_uploader.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 virtual void SetUp() OVERRIDE { | 134 virtual void SetUp() OVERRIDE { |
| 135 mock_drive_service_ = new StrictMock<MockDriveService>; | 135 mock_drive_service_ = new StrictMock<MockDriveService>; |
| 136 fake_drive_uploader_ = new FakeDriveUploader; | 136 fake_drive_uploader_ = new FakeDriveUploader; |
| 137 | 137 |
| 138 EXPECT_CALL(*mock_drive_service_, Initialize(&profile_)).Times(1); | 138 EXPECT_CALL(*mock_drive_service_, Initialize(&profile_)).Times(1); |
| 139 | 139 |
| 140 sync_client_ = DriveFileSyncClient::CreateForTesting( | 140 sync_client_ = DriveFileSyncClient::CreateForTesting( |
| 141 &profile_, | 141 &profile_, |
| 142 GURL(google_apis::GDataWapiUrlGenerator::kBaseUrlForProduction), |
| 142 scoped_ptr<DriveServiceInterface>(mock_drive_service_), | 143 scoped_ptr<DriveServiceInterface>(mock_drive_service_), |
| 143 scoped_ptr<DriveUploaderInterface>(fake_drive_uploader_)).Pass(); | 144 scoped_ptr<DriveUploaderInterface>(fake_drive_uploader_)).Pass(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 virtual void TearDown() OVERRIDE { | 147 virtual void TearDown() OVERRIDE { |
| 147 EXPECT_CALL(*mock_drive_service(), CancelAll()); | 148 EXPECT_CALL(*mock_drive_service(), CancelAll()); |
| 148 sync_client_.reset(); | 149 sync_client_.reset(); |
| 149 } | 150 } |
| 150 | 151 |
| 151 protected: | 152 protected: |
| 152 DriveFileSyncClient* sync_client() { return sync_client_.get(); } | 153 DriveFileSyncClient* sync_client() { return sync_client_.get(); } |
| 153 | 154 |
| 155 std::string FormatOriginQuery(const GURL& origin) { |
| 156 return FormatTitleQuery( |
| 157 DriveFileSyncClient::OriginToDirectoryTitle(origin)); |
| 158 } |
| 159 |
| 154 std::string FormatTitleQuery(const std::string& title) { | 160 std::string FormatTitleQuery(const std::string& title) { |
| 155 return DriveFileSyncClient::FormatTitleQuery(title); | 161 return DriveFileSyncClient::FormatTitleQuery(title); |
| 156 } | 162 } |
| 157 | 163 |
| 158 StrictMock<MockDriveService>* mock_drive_service() { | 164 StrictMock<MockDriveService>* mock_drive_service() { |
| 159 return mock_drive_service_; | 165 return mock_drive_service_; |
| 160 } | 166 } |
| 161 | 167 |
| 162 MessageLoop* message_loop() { return &message_loop_; } | 168 MessageLoop* message_loop() { return &message_loop_; } |
| 163 | 169 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 351 |
| 346 EXPECT_TRUE(done); | 352 EXPECT_TRUE(done); |
| 347 EXPECT_EQ(google_apis::HTTP_CREATED, error); | 353 EXPECT_EQ(google_apis::HTTP_CREATED, error); |
| 348 EXPECT_EQ("folder:sync_root_resource_id", resource_id); | 354 EXPECT_EQ("folder:sync_root_resource_id", resource_id); |
| 349 } | 355 } |
| 350 | 356 |
| 351 TEST_F(DriveFileSyncClientTest, GetOriginDirectory) { | 357 TEST_F(DriveFileSyncClientTest, GetOriginDirectory) { |
| 352 const std::string kParentResourceId("folder:sync_root_resource_id"); | 358 const std::string kParentResourceId("folder:sync_root_resource_id"); |
| 353 const std::string kOriginDirectoryResourceId( | 359 const std::string kOriginDirectoryResourceId( |
| 354 "folder:origin_directory_resource_id"); | 360 "folder:origin_directory_resource_id"); |
| 355 const GURL kOrigin("http://example.com"); | 361 const GURL kOrigin("chrome-extension://example"); |
| 356 | 362 |
| 357 scoped_ptr<base::Value> found_result(google_apis::test_util::LoadJSONFile( | 363 scoped_ptr<base::Value> found_result(google_apis::test_util::LoadJSONFile( |
| 358 "sync_file_system/origin_directory_found.json").Pass()); | 364 "sync_file_system/origin_directory_found.json").Pass()); |
| 359 | 365 |
| 360 // Expected to call GetDocuments from GetDriveDirectoryForOrigin. | 366 // Expected to call GetDocuments from GetDriveDirectoryForOrigin. |
| 361 EXPECT_CALL(*mock_drive_service(), | 367 EXPECT_CALL(*mock_drive_service(), |
| 362 GetDocuments(GURL(), // feed_url | 368 GetDocuments(GURL(), // feed_url |
| 363 0, // start_changestamp | 369 0, // start_changestamp |
| 364 FormatTitleQuery(kOrigin.spec()), | 370 FormatOriginQuery(kOrigin), |
| 365 false, // shared_with_me | 371 false, // shared_with_me |
| 366 kParentResourceId, | 372 kParentResourceId, |
| 367 _)) | 373 _)) |
| 368 .WillOnce(InvokeGetDataCallback5(google_apis::HTTP_SUCCESS, | 374 .WillOnce(InvokeGetDataCallback5(google_apis::HTTP_SUCCESS, |
| 369 base::Passed(&found_result))); | 375 base::Passed(&found_result))); |
| 370 | 376 |
| 371 bool done = false; | 377 bool done = false; |
| 372 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 378 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 373 std::string resource_id; | 379 std::string resource_id; |
| 374 sync_client()->GetDriveDirectoryForOrigin( | 380 sync_client()->GetDriveDirectoryForOrigin( |
| 375 kParentResourceId, kOrigin, | 381 kParentResourceId, kOrigin, |
| 376 base::Bind(&DidGetResourceID, &done, &error, &resource_id)); | 382 base::Bind(&DidGetResourceID, &done, &error, &resource_id)); |
| 377 message_loop()->RunUntilIdle(); | 383 message_loop()->RunUntilIdle(); |
| 378 | 384 |
| 379 EXPECT_TRUE(done); | 385 EXPECT_TRUE(done); |
| 380 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); | 386 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); |
| 381 EXPECT_EQ(kOriginDirectoryResourceId, resource_id); | 387 EXPECT_EQ(kOriginDirectoryResourceId, resource_id); |
| 382 } | 388 } |
| 383 | 389 |
| 384 TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) { | 390 TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) { |
| 385 const std::string kParentResourceId("folder:sync_root_resource_id"); | 391 const std::string kParentResourceId("folder:sync_root_resource_id"); |
| 386 const GURL kOrigin("http://example.com"); | 392 const GURL kOrigin("chrome-extension://example"); |
| 387 | 393 |
| 388 scoped_ptr<base::Value> not_found_result(google_apis::test_util::LoadJSONFile( | 394 scoped_ptr<base::Value> not_found_result(google_apis::test_util::LoadJSONFile( |
| 389 "sync_file_system/origin_directory_not_found.json").Pass()); | 395 "sync_file_system/origin_directory_not_found.json").Pass()); |
| 390 scoped_ptr<base::Value> got_parent_result( | 396 scoped_ptr<base::Value> got_parent_result( |
| 391 google_apis::test_util::LoadJSONFile( | 397 google_apis::test_util::LoadJSONFile( |
| 392 "sync_file_system/origin_directory_get_parent.json").Pass()); | 398 "sync_file_system/origin_directory_get_parent.json").Pass()); |
| 393 scoped_ptr<base::Value> created_result(google_apis::test_util::LoadJSONFile( | 399 scoped_ptr<base::Value> created_result(google_apis::test_util::LoadJSONFile( |
| 394 "sync_file_system/origin_directory_created.json").Pass()); | 400 "sync_file_system/origin_directory_created.json").Pass()); |
| 395 | 401 |
| 396 testing::InSequence sequence; | 402 testing::InSequence sequence; |
| 397 | 403 |
| 398 // Expected to call GetDocuments from GetDriveDirectoryForOrigin. | 404 // Expected to call GetDocuments from GetDriveDirectoryForOrigin. |
| 399 EXPECT_CALL(*mock_drive_service(), | 405 EXPECT_CALL(*mock_drive_service(), |
| 400 GetDocuments(GURL(), // feed_url | 406 GetDocuments(GURL(), // feed_url |
| 401 0, // start_changestamp | 407 0, // start_changestamp |
| 402 FormatTitleQuery(kOrigin.spec()), | 408 FormatOriginQuery(kOrigin), |
| 403 false, // shared_with_me | 409 false, // shared_with_me |
| 404 kParentResourceId, // directory_resource_id | 410 kParentResourceId, // directory_resource_id |
| 405 _)) | 411 _)) |
| 406 .WillOnce(InvokeGetDataCallback5(google_apis::HTTP_SUCCESS, | 412 .WillOnce(InvokeGetDataCallback5(google_apis::HTTP_SUCCESS, |
| 407 base::Passed(¬_found_result))); | 413 base::Passed(¬_found_result))); |
| 408 | 414 |
| 409 // Expected to call GetDocumentEntry from GetDriveDirectoryForOrigin. | 415 // Expected to call GetDocumentEntry from GetDriveDirectoryForOrigin. |
| 410 EXPECT_CALL(*mock_drive_service(), | 416 EXPECT_CALL(*mock_drive_service(), |
| 411 GetDocumentEntry(kParentResourceId, _)) | 417 GetDocumentEntry(kParentResourceId, _)) |
| 412 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, | 418 .WillOnce(InvokeGetDataCallback1(google_apis::HTTP_SUCCESS, |
| 413 base::Passed(&got_parent_result))); | 419 base::Passed(&got_parent_result))); |
| 414 | 420 |
| 421 std::string dir_title(DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); |
| 415 // Expected to call AddNewDirectory from GetDriveDirectoryForOrigin. | 422 // Expected to call AddNewDirectory from GetDriveDirectoryForOrigin. |
| 416 EXPECT_CALL(*mock_drive_service(), | 423 EXPECT_CALL(*mock_drive_service(), |
| 417 AddNewDirectory(GURL("https://sync_root_content_url"), | 424 AddNewDirectory(GURL("https://sync_root_content_url"), |
| 418 FilePath().AppendASCII(kOrigin.spec()).value(), | 425 FilePath().AppendASCII(dir_title).value(), |
| 419 _)) | 426 _)) |
| 420 .WillOnce(InvokeGetDataCallback2(google_apis::HTTP_CREATED, | 427 .WillOnce(InvokeGetDataCallback2(google_apis::HTTP_CREATED, |
| 421 base::Passed(&created_result))); | 428 base::Passed(&created_result))); |
| 422 | 429 |
| 423 bool done = false; | 430 bool done = false; |
| 424 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 431 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 425 std::string resource_id; | 432 std::string resource_id; |
| 426 sync_client()->GetDriveDirectoryForOrigin( | 433 sync_client()->GetDriveDirectoryForOrigin( |
| 427 kParentResourceId, kOrigin, | 434 kParentResourceId, kOrigin, |
| 428 base::Bind(&DidGetResourceID, &done, &error, &resource_id)); | 435 base::Bind(&DidGetResourceID, &done, &error, &resource_id)); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 base::Bind(&DidDeleteFile, &done, &error)); | 845 base::Bind(&DidDeleteFile, &done, &error)); |
| 839 message_loop()->RunUntilIdle(); | 846 message_loop()->RunUntilIdle(); |
| 840 | 847 |
| 841 EXPECT_TRUE(done); | 848 EXPECT_TRUE(done); |
| 842 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); | 849 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); |
| 843 } | 850 } |
| 844 | 851 |
| 845 #endif // !defined(OS_ANDROID) | 852 #endif // !defined(OS_ANDROID) |
| 846 | 853 |
| 847 } // namespace sync_file_system | 854 } // namespace sync_file_system |
| OLD | NEW |