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