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_api_parser.h" |
10 #include "chrome/browser/google_apis/drive_uploader.h" | 11 #include "chrome/browser/google_apis/drive_uploader.h" |
11 #include "chrome/browser/google_apis/gdata_errorcode.h" | 12 #include "chrome/browser/google_apis/gdata_errorcode.h" |
12 #include "chrome/browser/google_apis/mock_drive_service.h" | 13 #include "chrome/browser/google_apis/mock_drive_service.h" |
13 #include "chrome/browser/google_apis/test_util.h" | 14 #include "chrome/browser/google_apis/test_util.h" |
14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 #define FPL(x) FILE_PATH_LITERAL(x) | 20 #define FPL(x) FILE_PATH_LITERAL(x) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 MessageLoop message_loop_; | 149 MessageLoop message_loop_; |
149 | 150 |
150 TestingProfile profile_; | 151 TestingProfile profile_; |
151 scoped_ptr<DriveFileSyncClient> sync_client_; | 152 scoped_ptr<DriveFileSyncClient> sync_client_; |
152 StrictMock<MockDriveService>* mock_drive_service_; | 153 StrictMock<MockDriveService>* mock_drive_service_; |
153 FakeDriveUploader* fake_drive_uploader_; | 154 FakeDriveUploader* fake_drive_uploader_; |
154 | 155 |
155 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClientTest); | 156 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClientTest); |
156 }; | 157 }; |
157 | 158 |
158 // Invokes |arg0| as a GetAccountMetadataCallback. | 159 // Invokes |arg0| as a GetAboutResourceCallback. |
159 ACTION_P2(InvokeGetAccountMetadataCallback0, error, result) { | 160 ACTION_P2(InvokeGetAboutResourceCallback0, error, result) { |
160 scoped_ptr<google_apis::AccountMetadata> account_metadata(result.Pass()); | 161 scoped_ptr<google_apis::AboutResource> about_resource(result.Pass()); |
161 base::MessageLoopProxy::current()->PostTask( | 162 base::MessageLoopProxy::current()->PostTask( |
162 FROM_HERE, | 163 FROM_HERE, |
163 base::Bind(arg0, error, base::Passed(&account_metadata))); | 164 base::Bind(arg0, error, base::Passed(&about_resource))); |
164 } | 165 } |
165 | 166 |
166 // Invokes |arg1| as a GetResourceEntryCallback. | 167 // Invokes |arg1| as a GetResourceEntryCallback. |
167 ACTION_P2(InvokeGetResourceEntryCallback1, error, result) { | 168 ACTION_P2(InvokeGetResourceEntryCallback1, error, result) { |
168 scoped_ptr<google_apis::ResourceEntry> entry(result.Pass()); | 169 scoped_ptr<google_apis::ResourceEntry> entry(result.Pass()); |
169 base::MessageLoopProxy::current()->PostTask( | 170 base::MessageLoopProxy::current()->PostTask( |
170 FROM_HERE, | 171 FROM_HERE, |
171 base::Bind(arg1, error, base::Passed(&entry))); | 172 base::Bind(arg1, error, base::Passed(&entry))); |
172 } | 173 } |
173 | 174 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 message_loop()->RunUntilIdle(); | 565 message_loop()->RunUntilIdle(); |
565 | 566 |
566 EXPECT_TRUE(done); | 567 EXPECT_TRUE(done); |
567 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); | 568 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); |
568 EXPECT_EQ("folder:origin_directory_resource_id", resource_id); | 569 EXPECT_EQ("folder:origin_directory_resource_id", resource_id); |
569 } | 570 } |
570 | 571 |
571 TEST_F(DriveFileSyncClientTest, GetLargestChangeStamp) { | 572 TEST_F(DriveFileSyncClientTest, GetLargestChangeStamp) { |
572 scoped_ptr<base::Value> result( | 573 scoped_ptr<base::Value> result( |
573 LoadJSONFile("sync_file_system/account_metadata.json").Pass()); | 574 LoadJSONFile("sync_file_system/account_metadata.json").Pass()); |
574 scoped_ptr<google_apis::AccountMetadata> account_metadata( | 575 scoped_ptr<google_apis::AboutResource> about_resource( |
575 google_apis::AccountMetadata::CreateFrom(*result)); | 576 google_apis::AboutResource::CreateFromAccountMetadata( |
| 577 *google_apis::AccountMetadata::CreateFrom(*result), |
| 578 "folder:root")); |
576 | 579 |
577 // Expect to call GetAccountMetadata from GetLargestChangeStamp. | 580 // Expect to call GetAboutResource from GetLargestChangeStamp. |
578 EXPECT_CALL(*mock_drive_service(), GetAccountMetadata(_)) | 581 EXPECT_CALL(*mock_drive_service(), GetAboutResource(_)) |
579 .WillOnce(InvokeGetAccountMetadataCallback0( | 582 .WillOnce(InvokeGetAboutResourceCallback0( |
580 google_apis::HTTP_SUCCESS, | 583 google_apis::HTTP_SUCCESS, |
581 base::Passed(&account_metadata))) | 584 base::Passed(&about_resource))) |
582 .RetiresOnSaturation(); | 585 .RetiresOnSaturation(); |
583 | 586 |
584 bool done = false; | 587 bool done = false; |
585 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 588 GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
586 int64 largest_changestamp = -1; | 589 int64 largest_changestamp = -1; |
587 sync_client()->GetLargestChangeStamp( | 590 sync_client()->GetLargestChangeStamp( |
588 base::Bind(&DidGetLargestChangeStamp, | 591 base::Bind(&DidGetLargestChangeStamp, |
589 &done, &error, &largest_changestamp)); | 592 &done, &error, &largest_changestamp)); |
590 message_loop()->RunUntilIdle(); | 593 message_loop()->RunUntilIdle(); |
591 | 594 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 base::Bind(&DidDeleteFile, &done, &error)); | 1002 base::Bind(&DidDeleteFile, &done, &error)); |
1000 message_loop()->RunUntilIdle(); | 1003 message_loop()->RunUntilIdle(); |
1001 | 1004 |
1002 EXPECT_TRUE(done); | 1005 EXPECT_TRUE(done); |
1003 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); | 1006 EXPECT_EQ(google_apis::HTTP_CONFLICT, error); |
1004 } | 1007 } |
1005 | 1008 |
1006 #endif // !defined(OS_ANDROID) | 1009 #endif // !defined(OS_ANDROID) |
1007 | 1010 |
1008 } // namespace sync_file_system | 1011 } // namespace sync_file_system |
OLD | NEW |