OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/google_apis/fake_drive_service.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| 9 #include "chrome/browser/google_apis/test_util.h" |
| 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/test/test_browser_thread.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace google_apis { |
| 15 |
| 16 class FakeDriveServiceTest : public testing::Test { |
| 17 protected: |
| 18 FakeDriveServiceTest() |
| 19 : ui_thread_(content::BrowserThread::UI, &message_loop_) { |
| 20 } |
| 21 |
| 22 // Returns true if the resource identified by |resource_id| exists. |
| 23 bool Exists(const std::string& resource_id) { |
| 24 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 25 scoped_ptr<ResourceEntry> resource_entry; |
| 26 fake_service_.GetResourceEntry( |
| 27 resource_id, |
| 28 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, |
| 29 &error, |
| 30 &resource_entry)); |
| 31 message_loop_.RunUntilIdle(); |
| 32 return error == HTTP_SUCCESS; |
| 33 } |
| 34 |
| 35 MessageLoopForUI message_loop_; |
| 36 content::TestBrowserThread ui_thread_; |
| 37 FakeDriveService fake_service_; |
| 38 }; |
| 39 |
| 40 TEST_F(FakeDriveServiceTest, GetResourceList) { |
| 41 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 42 |
| 43 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 44 scoped_ptr<ResourceList> resource_list; |
| 45 fake_service_.GetResourceList( |
| 46 GURL(), |
| 47 0, // start_changestamp |
| 48 "", // search_query |
| 49 false, // shared_with_me |
| 50 "", // directory_resource_id |
| 51 base::Bind(&test_util::CopyResultsFromGetResourceListCallback, |
| 52 &error, |
| 53 &resource_list)); |
| 54 message_loop_.RunUntilIdle(); |
| 55 |
| 56 EXPECT_EQ(HTTP_SUCCESS, error); |
| 57 ASSERT_TRUE(resource_list); |
| 58 // Do some sanity check. |
| 59 EXPECT_EQ(12U, resource_list->entries().size()); |
| 60 } |
| 61 |
| 62 TEST_F(FakeDriveServiceTest, GetAccountMetadata) { |
| 63 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
| 64 "gdata/account_metadata.json")); |
| 65 |
| 66 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 67 scoped_ptr<AccountMetadataFeed> account_metadata; |
| 68 fake_service_.GetAccountMetadata( |
| 69 base::Bind(&test_util::CopyResultsFromGetAccountMetadataCallback, |
| 70 &error, |
| 71 &account_metadata)); |
| 72 message_loop_.RunUntilIdle(); |
| 73 |
| 74 EXPECT_EQ(HTTP_SUCCESS, error); |
| 75 |
| 76 ASSERT_TRUE(account_metadata); |
| 77 // Do some sanity check. |
| 78 EXPECT_EQ(2U, account_metadata->installed_apps().size()); |
| 79 } |
| 80 |
| 81 TEST_F(FakeDriveServiceTest, GetResourceEntry_ExistingFile) { |
| 82 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 83 |
| 84 const std::string kResourceId = "file:2_file_resource_id"; |
| 85 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 86 scoped_ptr<ResourceEntry> resource_entry; |
| 87 fake_service_.GetResourceEntry( |
| 88 kResourceId, |
| 89 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, |
| 90 &error, |
| 91 &resource_entry)); |
| 92 message_loop_.RunUntilIdle(); |
| 93 |
| 94 EXPECT_EQ(HTTP_SUCCESS, error); |
| 95 ASSERT_TRUE(resource_entry); |
| 96 // Do some sanity check. |
| 97 EXPECT_EQ(kResourceId, resource_entry->resource_id()); |
| 98 } |
| 99 |
| 100 TEST_F(FakeDriveServiceTest, GetResourceEntry_NonexistingFile) { |
| 101 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 102 |
| 103 const std::string kResourceId = "file:nonexisting_resource_id"; |
| 104 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 105 scoped_ptr<ResourceEntry> resource_entry; |
| 106 fake_service_.GetResourceEntry( |
| 107 kResourceId, |
| 108 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, |
| 109 &error, |
| 110 &resource_entry)); |
| 111 message_loop_.RunUntilIdle(); |
| 112 |
| 113 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 114 ASSERT_FALSE(resource_entry); |
| 115 } |
| 116 |
| 117 TEST_F(FakeDriveServiceTest, DeleteResource_ExistingFile) { |
| 118 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 119 |
| 120 // Resource "file:2_file_resource_id" should now exist. |
| 121 ASSERT_TRUE(Exists("file:2_file_resource_id")); |
| 122 |
| 123 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 124 fake_service_.DeleteResource( |
| 125 GURL("https://file1_link_self/file:2_file_resource_id"), |
| 126 base::Bind(&test_util::CopyResultsFromEntryActionCallback, |
| 127 &error)); |
| 128 message_loop_.RunUntilIdle(); |
| 129 |
| 130 EXPECT_EQ(HTTP_SUCCESS, error); |
| 131 // Resource "file:2_file_resource_id" should be gone now. |
| 132 EXPECT_FALSE(Exists("file:2_file_resource_id")); |
| 133 } |
| 134 |
| 135 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) { |
| 136 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); |
| 137 |
| 138 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 139 fake_service_.DeleteResource( |
| 140 GURL("https://file1_link_self/file:nonexisting_resource_id"), |
| 141 base::Bind(&test_util::CopyResultsFromEntryActionCallback, |
| 142 &error)); |
| 143 message_loop_.RunUntilIdle(); |
| 144 |
| 145 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 146 } |
| 147 |
| 148 } // namespace google_apis |
OLD | NEW |