| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 scoped_ptr<ResourceList> resource_list; | 255 scoped_ptr<ResourceList> resource_list; |
| 256 fake_service_.Search( | 256 fake_service_.Search( |
| 257 "Directory 1", // search_query | 257 "Directory 1", // search_query |
| 258 test_util::CreateCopyResultCallback(&error, &resource_list)); | 258 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 259 message_loop_.RunUntilIdle(); | 259 message_loop_.RunUntilIdle(); |
| 260 | 260 |
| 261 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 261 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 262 EXPECT_FALSE(resource_list); | 262 EXPECT_FALSE(resource_list); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_F(FakeDriveServiceTest, SearchInDirectory) { | 265 TEST_F(FakeDriveServiceTest, SearchByTitle) { |
| 266 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 266 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 267 "chromeos/gdata/root_feed.json")); | 267 "chromeos/gdata/root_feed.json")); |
| 268 | 268 |
| 269 GDataErrorCode error = GDATA_OTHER_ERROR; | 269 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 270 scoped_ptr<ResourceList> resource_list; | 270 scoped_ptr<ResourceList> resource_list; |
| 271 fake_service_.SearchInDirectory( | 271 fake_service_.SearchByTitle( |
| 272 "File", // search_query | 272 "1.txt", // title |
| 273 fake_service_.GetRootResourceId(), // directory_resource_id | 273 fake_service_.GetRootResourceId(), // directory_resource_id |
| 274 test_util::CreateCopyResultCallback(&error, &resource_list)); | 274 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 275 message_loop_.RunUntilIdle(); | 275 message_loop_.RunUntilIdle(); |
| 276 | |
| 277 EXPECT_EQ(HTTP_SUCCESS, error); | |
| 278 ASSERT_TRUE(resource_list); | |
| 279 // Do some sanity check. There is entry that contain "File" in their | |
| 280 // titles directly under the root directory. | |
| 281 EXPECT_EQ(1U, resource_list->entries().size()); | |
| 282 EXPECT_EQ(1, fake_service_.resource_list_load_count()); | |
| 283 } | |
| 284 | |
| 285 TEST_F(FakeDriveServiceTest, SearchInDirectory_WithAttribute) { | |
| 286 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | |
| 287 "chromeos/gdata/root_feed.json")); | |
| 288 | |
| 289 GDataErrorCode error = GDATA_OTHER_ERROR; | |
| 290 scoped_ptr<ResourceList> resource_list; | |
| 291 fake_service_.SearchInDirectory( | |
| 292 "title:1.txt", // search_query | |
| 293 fake_service_.GetRootResourceId(), // directory_resource_id | |
| 294 test_util::CreateCopyResultCallback(&error, &resource_list)); | |
| 295 message_loop_.RunUntilIdle(); | |
| 296 | 276 |
| 297 EXPECT_EQ(HTTP_SUCCESS, error); | 277 EXPECT_EQ(HTTP_SUCCESS, error); |
| 298 ASSERT_TRUE(resource_list); | 278 ASSERT_TRUE(resource_list); |
| 299 // Do some sanity check. There are 2 entries that contain "1.txt" in their | 279 // Do some sanity check. There are 2 entries that contain "1.txt" in their |
| 300 // titles directly under the root directory. | 280 // titles directly under the root directory. |
| 301 EXPECT_EQ(2U, resource_list->entries().size()); | 281 EXPECT_EQ(2U, resource_list->entries().size()); |
| 302 EXPECT_EQ(1, fake_service_.resource_list_load_count()); | 282 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
| 303 } | 283 } |
| 304 | 284 |
| 305 TEST_F(FakeDriveServiceTest, SearchInDirectory_MultipleQueries) { | 285 TEST_F(FakeDriveServiceTest, SearchByTitle_EmptyDirectoryResourceId) { |
| 306 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 286 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 307 "chromeos/gdata/root_feed.json")); | 287 "chromeos/gdata/root_feed.json")); |
| 308 | 288 |
| 309 GDataErrorCode error = GDATA_OTHER_ERROR; | 289 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 310 scoped_ptr<ResourceList> resource_list; | 290 scoped_ptr<ResourceList> resource_list; |
| 311 fake_service_.SearchInDirectory( | 291 fake_service_.SearchByTitle( |
| 312 "Directory 1", // search_query | 292 "1.txt", // title |
| 313 fake_service_.GetRootResourceId(), // directory_resource_id | 293 "", // directory resource id |
| 314 test_util::CreateCopyResultCallback(&error, &resource_list)); | 294 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 315 message_loop_.RunUntilIdle(); | 295 message_loop_.RunUntilIdle(); |
| 316 | 296 |
| 317 EXPECT_EQ(HTTP_SUCCESS, error); | 297 EXPECT_EQ(HTTP_SUCCESS, error); |
| 318 ASSERT_TRUE(resource_list); | 298 ASSERT_TRUE(resource_list); |
| 319 // There is one entry that contains both "Directory" and "1" in its title | 299 // Do some sanity check. There are 4 entries that contain "1.txt" in their |
| 320 // directly under the root directory. | 300 // titles. |
| 321 EXPECT_EQ(1U, resource_list->entries().size()); | 301 EXPECT_EQ(4U, resource_list->entries().size()); |
| 322 | 302 EXPECT_EQ(1, fake_service_.resource_list_load_count()); |
| 323 fake_service_.SearchInDirectory( | |
| 324 "\"Directory 1\"", // search_query | |
| 325 fake_service_.GetRootResourceId(), // directory_resource_id | |
| 326 test_util::CreateCopyResultCallback(&error, &resource_list)); | |
| 327 message_loop_.RunUntilIdle(); | |
| 328 | |
| 329 EXPECT_EQ(HTTP_SUCCESS, error); | |
| 330 ASSERT_TRUE(resource_list); | |
| 331 // There is one entry that contains "Directory 1" in its title | |
| 332 // directly under the root directory. | |
| 333 EXPECT_EQ(1U, resource_list->entries().size()); | |
| 334 EXPECT_EQ(2, fake_service_.resource_list_load_count()); | |
| 335 } | 303 } |
| 336 | 304 |
| 337 TEST_F(FakeDriveServiceTest, SearchInDirectory_Offline) { | 305 TEST_F(FakeDriveServiceTest, SearchByTitle_Offline) { |
| 338 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 306 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 339 "chromeos/gdata/root_feed.json")); | 307 "chromeos/gdata/root_feed.json")); |
| 340 fake_service_.set_offline(true); | 308 fake_service_.set_offline(true); |
| 341 | 309 |
| 342 GDataErrorCode error = GDATA_OTHER_ERROR; | 310 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 343 scoped_ptr<ResourceList> resource_list; | 311 scoped_ptr<ResourceList> resource_list; |
| 344 fake_service_.SearchInDirectory( | 312 fake_service_.SearchByTitle( |
| 345 "Directory 1", // search_query | 313 "Directory 1", // title |
| 346 fake_service_.GetRootResourceId(), // directory_resource_id | 314 fake_service_.GetRootResourceId(), // directory_resource_id |
| 347 test_util::CreateCopyResultCallback(&error, &resource_list)); | 315 test_util::CreateCopyResultCallback(&error, &resource_list)); |
| 348 message_loop_.RunUntilIdle(); | 316 message_loop_.RunUntilIdle(); |
| 349 | 317 |
| 350 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 318 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 351 EXPECT_FALSE(resource_list); | 319 EXPECT_FALSE(resource_list); |
| 352 } | 320 } |
| 353 | 321 |
| 354 TEST_F(FakeDriveServiceTest, GetChangeList_NoNewEntries) { | 322 TEST_F(FakeDriveServiceTest, GetChangeList_NoNewEntries) { |
| 355 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 323 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| (...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1963 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1996 message_loop_.RunUntilIdle(); | 1964 message_loop_.RunUntilIdle(); |
| 1997 | 1965 |
| 1998 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1966 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 1999 EXPECT_FALSE(resource_entry); | 1967 EXPECT_FALSE(resource_entry); |
| 2000 } | 1968 } |
| 2001 | 1969 |
| 2002 } // namespace | 1970 } // namespace |
| 2003 | 1971 |
| 2004 } // namespace google_apis | 1972 } // namespace google_apis |
| OLD | NEW |