| 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/google_apis/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 scoped_ptr<ResourceList> resource_list; | 263 scoped_ptr<ResourceList> resource_list; |
| 264 fake_service_.Search( | 264 fake_service_.Search( |
| 265 "Directory 1", // search_query | 265 "Directory 1", // search_query |
| 266 test_util::CreateCopyResultCallback(&error, &resource_list)); | 266 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 267 message_loop_.RunUntilIdle(); | 267 message_loop_.RunUntilIdle(); |
| 268 | 268 |
| 269 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 269 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 270 EXPECT_FALSE(resource_list); | 270 EXPECT_FALSE(resource_list); |
| 271 } | 271 } |
| 272 | 272 |
| 273 TEST_F(FakeDriveServiceTest, SearchInDirectory) { | 273 TEST_F(FakeDriveServiceTest, SearchByTitle) { |
| 274 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 274 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 275 "chromeos/gdata/root_feed.json")); | 275 "chromeos/gdata/root_feed.json")); |
| 276 | 276 |
| 277 GDataErrorCode error = GDATA_OTHER_ERROR; | 277 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 278 scoped_ptr<ResourceList> resource_list; | 278 scoped_ptr<ResourceList> resource_list; |
| 279 fake_service_.SearchInDirectory( | 279 fake_service_.SearchByTitle( |
| 280 "File", // search_query | 280 "1.txt", // title |
| 281 fake_service_.GetRootResourceId(), // directory_resource_id | 281 fake_service_.GetRootResourceId(), // directory_resource_id |
| 282 test_util::CreateCopyResultCallback(&error, &resource_list)); | 282 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 283 message_loop_.RunUntilIdle(); | 283 message_loop_.RunUntilIdle(); |
| 284 | |
| 285 EXPECT_EQ(HTTP_SUCCESS, error); | |
| 286 ASSERT_TRUE(resource_list); | |
| 287 // Do some sanity check. There is entry that contain "File" in their | |
| 288 // titles directly under the root directory. | |
| 289 EXPECT_EQ(1U, resource_list->entries().size()); | |
| 290 EXPECT_EQ(1, fake_service_.resource_list_load_count()); | |
| 291 } | |
| 292 | |
| 293 TEST_F(FakeDriveServiceTest, SearchInDirectory_WithAttribute) { | |
| 294 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
| 295 "chromeos/gdata/root_feed.json")); | |
| 296 | |
| 297 GDataErrorCode error = GDATA_OTHER_ERROR; | |
| 298 scoped_ptr<ResourceList> resource_list; | |
| 299 fake_service_.SearchInDirectory( | |
| 300 "title:1.txt", // search_query | |
| 301 fake_service_.GetRootResourceId(), // directory_resource_id | |
| 302 test_util::CreateCopyResultCallback(&error, &resource_list)); | |
| 303 message_loop_.RunUntilIdle(); | |
| 304 | 284 |
| 305 EXPECT_EQ(HTTP_SUCCESS, error); | 285 EXPECT_EQ(HTTP_SUCCESS, error); |
| 306 ASSERT_TRUE(resource_list); | 286 ASSERT_TRUE(resource_list); |
| 307 // Do some sanity check. There are 2 entries that contain "1.txt" in their | 287 // Do some sanity check. There are 2 entries that contain "1.txt" in their |
| 308 // titles directly under the root directory. | 288 // titles directly under the root directory. |
| 309 EXPECT_EQ(2U, resource_list->entries().size()); | 289 EXPECT_EQ(2U, resource_list->entries().size()); |
| 310 EXPECT_EQ(1, fake_service_.resource_list_load_count()); | 290 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
| 311 } | 291 } |
| 312 | 292 |
| 313 TEST_F(FakeDriveServiceTest, SearchInDirectory_MultipleQueries) { | 293 TEST_F(FakeDriveServiceTest, SearchByTitle_EmptyDirectoryResourceId) { |
| 314 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 294 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 315 "chromeos/gdata/root_feed.json")); | 295 "chromeos/gdata/root_feed.json")); |
| 316 | 296 |
| 317 GDataErrorCode error = GDATA_OTHER_ERROR; | 297 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 318 scoped_ptr<ResourceList> resource_list; | 298 scoped_ptr<ResourceList> resource_list; |
| 319 fake_service_.SearchInDirectory( | 299 fake_service_.SearchByTitle( |
| 320 "Directory 1", // search_query | 300 "1.txt", // title |
| 321 fake_service_.GetRootResourceId(), // directory_resource_id | 301 "", // directory resource id |
| 322 test_util::CreateCopyResultCallback(&error, &resource_list)); | 302 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 323 message_loop_.RunUntilIdle(); | 303 message_loop_.RunUntilIdle(); |
| 324 | 304 |
| 325 EXPECT_EQ(HTTP_SUCCESS, error); | 305 EXPECT_EQ(HTTP_SUCCESS, error); |
| 326 ASSERT_TRUE(resource_list); | 306 ASSERT_TRUE(resource_list); |
| 327 // There is one entry that contains both "Directory" and "1" in its title | 307 // Do some sanity check. There are 4 entries that contain "1.txt" in their |
| 328 // directly under the root directory. | 308 // titles. |
| 329 EXPECT_EQ(1U, resource_list->entries().size()); | 309 EXPECT_EQ(4U, resource_list->entries().size()); |
| 330 | 310 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
| 331 fake_service_.SearchInDirectory( | |
| 332 "\"Directory 1\"", // search_query | |
| 333 fake_service_.GetRootResourceId(), // directory_resource_id | |
| 334 test_util::CreateCopyResultCallback(&error, &resource_list)); | |
| 335 message_loop_.RunUntilIdle(); | |
| 336 | |
| 337 EXPECT_EQ(HTTP_SUCCESS, error); | |
| 338 ASSERT_TRUE(resource_list); | |
| 339 // There is one entry that contains "Directory 1" in its title | |
| 340 // directly under the root directory. | |
| 341 EXPECT_EQ(1U, resource_list->entries().size()); | |
| 342 EXPECT_EQ(2, fake_service_.resource_list_load_count()); | |
| 343 } | 311 } |
| 344 | 312 |
| 345 TEST_F(FakeDriveServiceTest, SearchInDirectory_Offline) { | 313 TEST_F(FakeDriveServiceTest, SearchByTitle_Offline) { |
| 346 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 314 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 347 "chromeos/gdata/root_feed.json")); | 315 "chromeos/gdata/root_feed.json")); |
| 348 fake_service_.set_offline(true); | 316 fake_service_.set_offline(true); |
| 349 | 317 |
| 350 GDataErrorCode error = GDATA_OTHER_ERROR; | 318 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 351 scoped_ptr<ResourceList> resource_list; | 319 scoped_ptr<ResourceList> resource_list; |
| 352 fake_service_.SearchInDirectory( | 320 fake_service_.SearchByTitle( |
| 353 "Directory 1", // search_query | 321 "Directory 1", // title |
| 354 fake_service_.GetRootResourceId(), // directory_resource_id | 322 fake_service_.GetRootResourceId(), // directory_resource_id |
| 355 test_util::CreateCopyResultCallback(&error, &resource_list)); | 323 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 356 message_loop_.RunUntilIdle(); | 324 message_loop_.RunUntilIdle(); |
| 357 | 325 |
| 358 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 326 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 359 EXPECT_FALSE(resource_list); | 327 EXPECT_FALSE(resource_list); |
| 360 } | 328 } |
| 361 | 329 |
| 362 TEST_F(FakeDriveServiceTest, GetChangeList_NoNewEntries) { | 330 TEST_F(FakeDriveServiceTest, GetChangeList_NoNewEntries) { |
| 363 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 331 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| (...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1932 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1965 message_loop_.RunUntilIdle(); | 1933 message_loop_.RunUntilIdle(); |
| 1966 | 1934 |
| 1967 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1935 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 1968 EXPECT_FALSE(resource_entry); | 1936 EXPECT_FALSE(resource_entry); |
| 1969 } | 1937 } |
| 1970 | 1938 |
| 1971 } // namespace | 1939 } // namespace |
| 1972 | 1940 |
| 1973 } // namespace google_apis | 1941 } // namespace google_apis |
| OLD | NEW |