Chromium Code Reviews| 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/drive/fake_drive_service.h" | 5 #include "chrome/browser/drive/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/md5.h" | 12 #include "base/md5.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/drive/test_util.h" | 18 #include "chrome/browser/drive/test_util.h" |
| 19 #include "google_apis/drive/drive_api_parser.h" | 19 #include "google_apis/drive/drive_api_parser.h" |
| 20 #include "google_apis/drive/test_util.h" | 20 #include "google_apis/drive/test_util.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 using google_apis::AboutResource; | 23 using google_apis::AboutResource; |
| 24 using google_apis::AppList; | 24 using google_apis::AppList; |
| 25 using google_apis::ChangeList; | 25 using google_apis::ChangeList; |
| 26 using google_apis::ChangeResource; | 26 using google_apis::ChangeResource; |
| 27 using google_apis::FileList; | 27 using google_apis::FileList; |
| 28 using google_apis::FileResource; | 28 using google_apis::FileResource; |
| 29 using google_apis::GDATA_NO_CONNECTION; | 29 using google_apis::DRIVE_NO_CONNECTION; |
|
mtomasz
2015/01/29 06:18:02
nit: ditto
| |
| 30 using google_apis::GDATA_OTHER_ERROR; | 30 using google_apis::DRIVE_OTHER_ERROR; |
| 31 using google_apis::GDataErrorCode; | 31 using google_apis::DriveApiErrorCode; |
| 32 using google_apis::GetContentCallback; | 32 using google_apis::GetContentCallback; |
| 33 using google_apis::HTTP_CREATED; | 33 using google_apis::HTTP_CREATED; |
| 34 using google_apis::HTTP_FORBIDDEN; | 34 using google_apis::HTTP_FORBIDDEN; |
| 35 using google_apis::HTTP_NOT_FOUND; | 35 using google_apis::HTTP_NOT_FOUND; |
| 36 using google_apis::HTTP_NO_CONTENT; | 36 using google_apis::HTTP_NO_CONTENT; |
| 37 using google_apis::HTTP_PRECONDITION; | 37 using google_apis::HTTP_PRECONDITION; |
| 38 using google_apis::HTTP_RESUME_INCOMPLETE; | 38 using google_apis::HTTP_RESUME_INCOMPLETE; |
| 39 using google_apis::HTTP_SUCCESS; | 39 using google_apis::HTTP_SUCCESS; |
| 40 using google_apis::ProgressCallback; | 40 using google_apis::ProgressCallback; |
| 41 using google_apis::UploadRangeResponse; | 41 using google_apis::UploadRangeResponse; |
| 42 | 42 |
| 43 namespace drive { | 43 namespace drive { |
| 44 | 44 |
| 45 namespace test_util { | 45 namespace test_util { |
| 46 | 46 |
| 47 using google_apis::test_util::AppendProgressCallbackResult; | 47 using google_apis::test_util::AppendProgressCallbackResult; |
| 48 using google_apis::test_util::CreateCopyResultCallback; | 48 using google_apis::test_util::CreateCopyResultCallback; |
| 49 using google_apis::test_util::ProgressInfo; | 49 using google_apis::test_util::ProgressInfo; |
| 50 using google_apis::test_util::TestGetContentCallback; | 50 using google_apis::test_util::TestGetContentCallback; |
| 51 using google_apis::test_util::WriteStringToFile; | 51 using google_apis::test_util::WriteStringToFile; |
| 52 | 52 |
| 53 } // namespace test_util | 53 } // namespace test_util |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 class FakeDriveServiceTest : public testing::Test { | 57 class FakeDriveServiceTest : public testing::Test { |
| 58 protected: | 58 protected: |
| 59 // Returns the resource entry that matches |resource_id|. | 59 // Returns the resource entry that matches |resource_id|. |
| 60 scoped_ptr<FileResource> FindEntry(const std::string& resource_id) { | 60 scoped_ptr<FileResource> FindEntry(const std::string& resource_id) { |
| 61 GDataErrorCode error = GDATA_OTHER_ERROR; | 61 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 62 scoped_ptr<FileResource> entry; | 62 scoped_ptr<FileResource> entry; |
| 63 fake_service_.GetFileResource( | 63 fake_service_.GetFileResource( |
| 64 resource_id, test_util::CreateCopyResultCallback(&error, &entry)); | 64 resource_id, test_util::CreateCopyResultCallback(&error, &entry)); |
| 65 base::RunLoop().RunUntilIdle(); | 65 base::RunLoop().RunUntilIdle(); |
| 66 return entry.Pass(); | 66 return entry.Pass(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Returns true if the resource identified by |resource_id| exists. | 69 // Returns true if the resource identified by |resource_id| exists. |
| 70 bool Exists(const std::string& resource_id) { | 70 bool Exists(const std::string& resource_id) { |
| 71 scoped_ptr<FileResource> entry = FindEntry(resource_id); | 71 scoped_ptr<FileResource> entry = FindEntry(resource_id); |
| 72 return entry && !entry->labels().is_trashed(); | 72 return entry && !entry->labels().is_trashed(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Adds a new directory at |parent_resource_id| with the given name. | 75 // Adds a new directory at |parent_resource_id| with the given name. |
| 76 // Returns true on success. | 76 // Returns true on success. |
| 77 bool AddNewDirectory(const std::string& parent_resource_id, | 77 bool AddNewDirectory(const std::string& parent_resource_id, |
| 78 const std::string& directory_title) { | 78 const std::string& directory_title) { |
| 79 GDataErrorCode error = GDATA_OTHER_ERROR; | 79 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 80 scoped_ptr<FileResource> entry; | 80 scoped_ptr<FileResource> entry; |
| 81 fake_service_.AddNewDirectory( | 81 fake_service_.AddNewDirectory( |
| 82 parent_resource_id, | 82 parent_resource_id, |
| 83 directory_title, | 83 directory_title, |
| 84 DriveServiceInterface::AddNewDirectoryOptions(), | 84 DriveServiceInterface::AddNewDirectoryOptions(), |
| 85 test_util::CreateCopyResultCallback(&error, &entry)); | 85 test_util::CreateCopyResultCallback(&error, &entry)); |
| 86 base::RunLoop().RunUntilIdle(); | 86 base::RunLoop().RunUntilIdle(); |
| 87 return error == HTTP_CREATED; | 87 return error == HTTP_CREATED; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Returns true if the resource identified by |resource_id| has a parent | 90 // Returns true if the resource identified by |resource_id| has a parent |
| 91 // identified by |parent_id|. | 91 // identified by |parent_id|. |
| 92 bool HasParent(const std::string& resource_id, const std::string& parent_id) { | 92 bool HasParent(const std::string& resource_id, const std::string& parent_id) { |
| 93 scoped_ptr<FileResource> entry = FindEntry(resource_id); | 93 scoped_ptr<FileResource> entry = FindEntry(resource_id); |
| 94 if (entry) { | 94 if (entry) { |
| 95 for (size_t i = 0; i < entry->parents().size(); ++i) { | 95 for (size_t i = 0; i < entry->parents().size(); ++i) { |
| 96 if (entry->parents()[i].file_id() == parent_id) | 96 if (entry->parents()[i].file_id() == parent_id) |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 | 102 |
| 103 int64 GetLargestChangeByAboutResource() { | 103 int64 GetLargestChangeByAboutResource() { |
| 104 GDataErrorCode error; | 104 DriveApiErrorCode error; |
| 105 scoped_ptr<AboutResource> about_resource; | 105 scoped_ptr<AboutResource> about_resource; |
| 106 fake_service_.GetAboutResource( | 106 fake_service_.GetAboutResource( |
| 107 test_util::CreateCopyResultCallback(&error, &about_resource)); | 107 test_util::CreateCopyResultCallback(&error, &about_resource)); |
| 108 base::RunLoop().RunUntilIdle(); | 108 base::RunLoop().RunUntilIdle(); |
| 109 return about_resource->largest_change_id(); | 109 return about_resource->largest_change_id(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 base::MessageLoop message_loop_; | 112 base::MessageLoop message_loop_; |
| 113 FakeDriveService fake_service_; | 113 FakeDriveService fake_service_; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 TEST_F(FakeDriveServiceTest, GetAllFileList) { | 116 TEST_F(FakeDriveServiceTest, GetAllFileList) { |
| 117 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 117 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 118 | 118 |
| 119 GDataErrorCode error = GDATA_OTHER_ERROR; | 119 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 120 scoped_ptr<FileList> file_list; | 120 scoped_ptr<FileList> file_list; |
| 121 fake_service_.GetAllFileList( | 121 fake_service_.GetAllFileList( |
| 122 test_util::CreateCopyResultCallback(&error, &file_list)); | 122 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 123 base::RunLoop().RunUntilIdle(); | 123 base::RunLoop().RunUntilIdle(); |
| 124 | 124 |
| 125 EXPECT_EQ(HTTP_SUCCESS, error); | 125 EXPECT_EQ(HTTP_SUCCESS, error); |
| 126 ASSERT_TRUE(file_list); | 126 ASSERT_TRUE(file_list); |
| 127 // Do some sanity check. | 127 // Do some sanity check. |
| 128 EXPECT_EQ(15U, file_list->items().size()); | 128 EXPECT_EQ(15U, file_list->items().size()); |
| 129 EXPECT_EQ(1, fake_service_.file_list_load_count()); | 129 EXPECT_EQ(1, fake_service_.file_list_load_count()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TEST_F(FakeDriveServiceTest, GetAllFileList_Offline) { | 132 TEST_F(FakeDriveServiceTest, GetAllFileList_Offline) { |
| 133 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 133 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 134 fake_service_.set_offline(true); | 134 fake_service_.set_offline(true); |
| 135 | 135 |
| 136 GDataErrorCode error = GDATA_OTHER_ERROR; | 136 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 137 scoped_ptr<FileList> file_list; | 137 scoped_ptr<FileList> file_list; |
| 138 fake_service_.GetAllFileList( | 138 fake_service_.GetAllFileList( |
| 139 test_util::CreateCopyResultCallback(&error, &file_list)); | 139 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 140 base::RunLoop().RunUntilIdle(); | 140 base::RunLoop().RunUntilIdle(); |
| 141 | 141 |
| 142 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 142 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 143 EXPECT_FALSE(file_list); | 143 EXPECT_FALSE(file_list); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_InRootDirectory) { | 146 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_InRootDirectory) { |
| 147 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 147 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 148 | 148 |
| 149 GDataErrorCode error = GDATA_OTHER_ERROR; | 149 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 150 scoped_ptr<FileList> file_list; | 150 scoped_ptr<FileList> file_list; |
| 151 fake_service_.GetFileListInDirectory( | 151 fake_service_.GetFileListInDirectory( |
| 152 fake_service_.GetRootResourceId(), | 152 fake_service_.GetRootResourceId(), |
| 153 test_util::CreateCopyResultCallback(&error, &file_list)); | 153 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 154 base::RunLoop().RunUntilIdle(); | 154 base::RunLoop().RunUntilIdle(); |
| 155 | 155 |
| 156 EXPECT_EQ(HTTP_SUCCESS, error); | 156 EXPECT_EQ(HTTP_SUCCESS, error); |
| 157 ASSERT_TRUE(file_list); | 157 ASSERT_TRUE(file_list); |
| 158 // Do some sanity check. There are 8 entries in the root directory. | 158 // Do some sanity check. There are 8 entries in the root directory. |
| 159 EXPECT_EQ(8U, file_list->items().size()); | 159 EXPECT_EQ(8U, file_list->items().size()); |
| 160 EXPECT_EQ(1, fake_service_.directory_load_count()); | 160 EXPECT_EQ(1, fake_service_.directory_load_count()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_InNonRootDirectory) { | 163 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_InNonRootDirectory) { |
| 164 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 164 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 165 | 165 |
| 166 GDataErrorCode error = GDATA_OTHER_ERROR; | 166 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 167 scoped_ptr<FileList> file_list; | 167 scoped_ptr<FileList> file_list; |
| 168 fake_service_.GetFileListInDirectory( | 168 fake_service_.GetFileListInDirectory( |
| 169 "1_folder_resource_id", | 169 "1_folder_resource_id", |
| 170 test_util::CreateCopyResultCallback(&error, &file_list)); | 170 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 171 base::RunLoop().RunUntilIdle(); | 171 base::RunLoop().RunUntilIdle(); |
| 172 | 172 |
| 173 EXPECT_EQ(HTTP_SUCCESS, error); | 173 EXPECT_EQ(HTTP_SUCCESS, error); |
| 174 ASSERT_TRUE(file_list); | 174 ASSERT_TRUE(file_list); |
| 175 // Do some sanity check. There is three entries in 1_folder_resource_id | 175 // Do some sanity check. There is three entries in 1_folder_resource_id |
| 176 // directory. | 176 // directory. |
| 177 EXPECT_EQ(3U, file_list->items().size()); | 177 EXPECT_EQ(3U, file_list->items().size()); |
| 178 EXPECT_EQ(1, fake_service_.directory_load_count()); | 178 EXPECT_EQ(1, fake_service_.directory_load_count()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_Offline) { | 181 TEST_F(FakeDriveServiceTest, GetFileListInDirectory_Offline) { |
| 182 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 182 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 183 fake_service_.set_offline(true); | 183 fake_service_.set_offline(true); |
| 184 | 184 |
| 185 GDataErrorCode error = GDATA_OTHER_ERROR; | 185 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 186 scoped_ptr<FileList> file_list; | 186 scoped_ptr<FileList> file_list; |
| 187 fake_service_.GetFileListInDirectory( | 187 fake_service_.GetFileListInDirectory( |
| 188 fake_service_.GetRootResourceId(), | 188 fake_service_.GetRootResourceId(), |
| 189 test_util::CreateCopyResultCallback(&error, &file_list)); | 189 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 190 base::RunLoop().RunUntilIdle(); | 190 base::RunLoop().RunUntilIdle(); |
| 191 | 191 |
| 192 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 192 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 193 EXPECT_FALSE(file_list); | 193 EXPECT_FALSE(file_list); |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST_F(FakeDriveServiceTest, Search) { | 196 TEST_F(FakeDriveServiceTest, Search) { |
| 197 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 197 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 198 | 198 |
| 199 GDataErrorCode error = GDATA_OTHER_ERROR; | 199 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 200 scoped_ptr<FileList> file_list; | 200 scoped_ptr<FileList> file_list; |
| 201 fake_service_.Search( | 201 fake_service_.Search( |
| 202 "File", // search_query | 202 "File", // search_query |
| 203 test_util::CreateCopyResultCallback(&error, &file_list)); | 203 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 204 base::RunLoop().RunUntilIdle(); | 204 base::RunLoop().RunUntilIdle(); |
| 205 | 205 |
| 206 EXPECT_EQ(HTTP_SUCCESS, error); | 206 EXPECT_EQ(HTTP_SUCCESS, error); |
| 207 ASSERT_TRUE(file_list); | 207 ASSERT_TRUE(file_list); |
| 208 // Do some sanity check. There are 4 entries that contain "File" in their | 208 // Do some sanity check. There are 4 entries that contain "File" in their |
| 209 // titles. | 209 // titles. |
| 210 EXPECT_EQ(4U, file_list->items().size()); | 210 EXPECT_EQ(4U, file_list->items().size()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 TEST_F(FakeDriveServiceTest, Search_WithAttribute) { | 213 TEST_F(FakeDriveServiceTest, Search_WithAttribute) { |
| 214 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 214 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 215 | 215 |
| 216 GDataErrorCode error = GDATA_OTHER_ERROR; | 216 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 217 scoped_ptr<FileList> file_list; | 217 scoped_ptr<FileList> file_list; |
| 218 fake_service_.Search( | 218 fake_service_.Search( |
| 219 "title:1.txt", // search_query | 219 "title:1.txt", // search_query |
| 220 test_util::CreateCopyResultCallback(&error, &file_list)); | 220 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 221 base::RunLoop().RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
| 222 | 222 |
| 223 EXPECT_EQ(HTTP_SUCCESS, error); | 223 EXPECT_EQ(HTTP_SUCCESS, error); |
| 224 ASSERT_TRUE(file_list); | 224 ASSERT_TRUE(file_list); |
| 225 // Do some sanity check. There are 4 entries that contain "1.txt" in their | 225 // Do some sanity check. There are 4 entries that contain "1.txt" in their |
| 226 // titles. | 226 // titles. |
| 227 EXPECT_EQ(4U, file_list->items().size()); | 227 EXPECT_EQ(4U, file_list->items().size()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST_F(FakeDriveServiceTest, Search_MultipleQueries) { | 230 TEST_F(FakeDriveServiceTest, Search_MultipleQueries) { |
| 231 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 231 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 232 | 232 |
| 233 GDataErrorCode error = GDATA_OTHER_ERROR; | 233 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 234 scoped_ptr<FileList> file_list; | 234 scoped_ptr<FileList> file_list; |
| 235 fake_service_.Search( | 235 fake_service_.Search( |
| 236 "Directory 1", // search_query | 236 "Directory 1", // search_query |
| 237 test_util::CreateCopyResultCallback(&error, &file_list)); | 237 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 238 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
| 239 | 239 |
| 240 EXPECT_EQ(HTTP_SUCCESS, error); | 240 EXPECT_EQ(HTTP_SUCCESS, error); |
| 241 ASSERT_TRUE(file_list); | 241 ASSERT_TRUE(file_list); |
| 242 // There are 2 entries that contain both "Directory" and "1" in their titles. | 242 // There are 2 entries that contain both "Directory" and "1" in their titles. |
| 243 EXPECT_EQ(2U, file_list->items().size()); | 243 EXPECT_EQ(2U, file_list->items().size()); |
| 244 | 244 |
| 245 fake_service_.Search( | 245 fake_service_.Search( |
| 246 "\"Directory 1\"", // search_query | 246 "\"Directory 1\"", // search_query |
| 247 test_util::CreateCopyResultCallback(&error, &file_list)); | 247 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 248 base::RunLoop().RunUntilIdle(); | 248 base::RunLoop().RunUntilIdle(); |
| 249 | 249 |
| 250 EXPECT_EQ(HTTP_SUCCESS, error); | 250 EXPECT_EQ(HTTP_SUCCESS, error); |
| 251 ASSERT_TRUE(file_list); | 251 ASSERT_TRUE(file_list); |
| 252 // There is 1 entry that contain "Directory 1" in its title. | 252 // There is 1 entry that contain "Directory 1" in its title. |
| 253 EXPECT_EQ(1U, file_list->items().size()); | 253 EXPECT_EQ(1U, file_list->items().size()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 TEST_F(FakeDriveServiceTest, Search_Offline) { | 256 TEST_F(FakeDriveServiceTest, Search_Offline) { |
| 257 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 257 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 258 fake_service_.set_offline(true); | 258 fake_service_.set_offline(true); |
| 259 | 259 |
| 260 GDataErrorCode error = GDATA_OTHER_ERROR; | 260 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 261 scoped_ptr<FileList> file_list; | 261 scoped_ptr<FileList> file_list; |
| 262 fake_service_.Search( | 262 fake_service_.Search( |
| 263 "Directory 1", // search_query | 263 "Directory 1", // search_query |
| 264 test_util::CreateCopyResultCallback(&error, &file_list)); | 264 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 265 base::RunLoop().RunUntilIdle(); | 265 base::RunLoop().RunUntilIdle(); |
| 266 | 266 |
| 267 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 267 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 268 EXPECT_FALSE(file_list); | 268 EXPECT_FALSE(file_list); |
| 269 } | 269 } |
| 270 | 270 |
| 271 TEST_F(FakeDriveServiceTest, Search_Deleted) { | 271 TEST_F(FakeDriveServiceTest, Search_Deleted) { |
| 272 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 272 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 273 | 273 |
| 274 GDataErrorCode error = GDATA_OTHER_ERROR; | 274 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 275 fake_service_.DeleteResource("2_file_resource_id", | 275 fake_service_.DeleteResource("2_file_resource_id", |
| 276 std::string(), // etag | 276 std::string(), // etag |
| 277 test_util::CreateCopyResultCallback(&error)); | 277 test_util::CreateCopyResultCallback(&error)); |
| 278 base::RunLoop().RunUntilIdle(); | 278 base::RunLoop().RunUntilIdle(); |
| 279 EXPECT_EQ(HTTP_NO_CONTENT, error); | 279 EXPECT_EQ(HTTP_NO_CONTENT, error); |
| 280 | 280 |
| 281 error = GDATA_OTHER_ERROR; | 281 error = DRIVE_OTHER_ERROR; |
| 282 scoped_ptr<FileList> file_list; | 282 scoped_ptr<FileList> file_list; |
| 283 fake_service_.Search( | 283 fake_service_.Search( |
| 284 "File", // search_query | 284 "File", // search_query |
| 285 test_util::CreateCopyResultCallback(&error, &file_list)); | 285 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 286 base::RunLoop().RunUntilIdle(); | 286 base::RunLoop().RunUntilIdle(); |
| 287 | 287 |
| 288 EXPECT_EQ(HTTP_SUCCESS, error); | 288 EXPECT_EQ(HTTP_SUCCESS, error); |
| 289 ASSERT_TRUE(file_list); | 289 ASSERT_TRUE(file_list); |
| 290 // Do some sanity check. There are 4 entries that contain "File" in their | 290 // Do some sanity check. There are 4 entries that contain "File" in their |
| 291 // titles and one of them is deleted. | 291 // titles and one of them is deleted. |
| 292 EXPECT_EQ(3U, file_list->items().size()); | 292 EXPECT_EQ(3U, file_list->items().size()); |
| 293 } | 293 } |
| 294 | 294 |
| 295 TEST_F(FakeDriveServiceTest, Search_Trashed) { | 295 TEST_F(FakeDriveServiceTest, Search_Trashed) { |
| 296 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 296 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 297 | 297 |
| 298 GDataErrorCode error = GDATA_OTHER_ERROR; | 298 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 299 fake_service_.TrashResource("2_file_resource_id", | 299 fake_service_.TrashResource("2_file_resource_id", |
| 300 test_util::CreateCopyResultCallback(&error)); | 300 test_util::CreateCopyResultCallback(&error)); |
| 301 base::RunLoop().RunUntilIdle(); | 301 base::RunLoop().RunUntilIdle(); |
| 302 EXPECT_EQ(HTTP_SUCCESS, error); | 302 EXPECT_EQ(HTTP_SUCCESS, error); |
| 303 | 303 |
| 304 error = GDATA_OTHER_ERROR; | 304 error = DRIVE_OTHER_ERROR; |
| 305 scoped_ptr<FileList> file_list; | 305 scoped_ptr<FileList> file_list; |
| 306 fake_service_.Search( | 306 fake_service_.Search( |
| 307 "File", // search_query | 307 "File", // search_query |
| 308 test_util::CreateCopyResultCallback(&error, &file_list)); | 308 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 309 base::RunLoop().RunUntilIdle(); | 309 base::RunLoop().RunUntilIdle(); |
| 310 | 310 |
| 311 EXPECT_EQ(HTTP_SUCCESS, error); | 311 EXPECT_EQ(HTTP_SUCCESS, error); |
| 312 ASSERT_TRUE(file_list); | 312 ASSERT_TRUE(file_list); |
| 313 // Do some sanity check. There are 4 entries that contain "File" in their | 313 // Do some sanity check. There are 4 entries that contain "File" in their |
| 314 // titles and one of them is deleted. | 314 // titles and one of them is deleted. |
| 315 EXPECT_EQ(3U, file_list->items().size()); | 315 EXPECT_EQ(3U, file_list->items().size()); |
| 316 } | 316 } |
| 317 | 317 |
| 318 TEST_F(FakeDriveServiceTest, SearchByTitle) { | 318 TEST_F(FakeDriveServiceTest, SearchByTitle) { |
| 319 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 319 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 320 | 320 |
| 321 GDataErrorCode error = GDATA_OTHER_ERROR; | 321 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 322 scoped_ptr<FileList> file_list; | 322 scoped_ptr<FileList> file_list; |
| 323 fake_service_.SearchByTitle( | 323 fake_service_.SearchByTitle( |
| 324 "1.txt", // title | 324 "1.txt", // title |
| 325 fake_service_.GetRootResourceId(), // directory_resource_id | 325 fake_service_.GetRootResourceId(), // directory_resource_id |
| 326 test_util::CreateCopyResultCallback(&error, &file_list)); | 326 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 327 base::RunLoop().RunUntilIdle(); | 327 base::RunLoop().RunUntilIdle(); |
| 328 | 328 |
| 329 EXPECT_EQ(HTTP_SUCCESS, error); | 329 EXPECT_EQ(HTTP_SUCCESS, error); |
| 330 ASSERT_TRUE(file_list); | 330 ASSERT_TRUE(file_list); |
| 331 // Do some sanity check. There are 2 entries that contain "1.txt" in their | 331 // Do some sanity check. There are 2 entries that contain "1.txt" in their |
| 332 // titles directly under the root directory. | 332 // titles directly under the root directory. |
| 333 EXPECT_EQ(2U, file_list->items().size()); | 333 EXPECT_EQ(2U, file_list->items().size()); |
| 334 } | 334 } |
| 335 | 335 |
| 336 TEST_F(FakeDriveServiceTest, SearchByTitle_EmptyDirectoryResourceId) { | 336 TEST_F(FakeDriveServiceTest, SearchByTitle_EmptyDirectoryResourceId) { |
| 337 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 337 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 338 | 338 |
| 339 GDataErrorCode error = GDATA_OTHER_ERROR; | 339 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 340 scoped_ptr<FileList> file_list; | 340 scoped_ptr<FileList> file_list; |
| 341 fake_service_.SearchByTitle( | 341 fake_service_.SearchByTitle( |
| 342 "1.txt", // title | 342 "1.txt", // title |
| 343 "", // directory resource id | 343 "", // directory resource id |
| 344 test_util::CreateCopyResultCallback(&error, &file_list)); | 344 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 345 base::RunLoop().RunUntilIdle(); | 345 base::RunLoop().RunUntilIdle(); |
| 346 | 346 |
| 347 EXPECT_EQ(HTTP_SUCCESS, error); | 347 EXPECT_EQ(HTTP_SUCCESS, error); |
| 348 ASSERT_TRUE(file_list); | 348 ASSERT_TRUE(file_list); |
| 349 // Do some sanity check. There are 4 entries that contain "1.txt" in their | 349 // Do some sanity check. There are 4 entries that contain "1.txt" in their |
| 350 // titles. | 350 // titles. |
| 351 EXPECT_EQ(4U, file_list->items().size()); | 351 EXPECT_EQ(4U, file_list->items().size()); |
| 352 } | 352 } |
| 353 | 353 |
| 354 TEST_F(FakeDriveServiceTest, SearchByTitle_Offline) { | 354 TEST_F(FakeDriveServiceTest, SearchByTitle_Offline) { |
| 355 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 355 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 356 fake_service_.set_offline(true); | 356 fake_service_.set_offline(true); |
| 357 | 357 |
| 358 GDataErrorCode error = GDATA_OTHER_ERROR; | 358 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 359 scoped_ptr<FileList> file_list; | 359 scoped_ptr<FileList> file_list; |
| 360 fake_service_.SearchByTitle( | 360 fake_service_.SearchByTitle( |
| 361 "Directory 1", // title | 361 "Directory 1", // title |
| 362 fake_service_.GetRootResourceId(), // directory_resource_id | 362 fake_service_.GetRootResourceId(), // directory_resource_id |
| 363 test_util::CreateCopyResultCallback(&error, &file_list)); | 363 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 364 base::RunLoop().RunUntilIdle(); | 364 base::RunLoop().RunUntilIdle(); |
| 365 | 365 |
| 366 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 366 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 367 EXPECT_FALSE(file_list); | 367 EXPECT_FALSE(file_list); |
| 368 } | 368 } |
| 369 | 369 |
| 370 TEST_F(FakeDriveServiceTest, GetChangeList_NoNewEntries) { | 370 TEST_F(FakeDriveServiceTest, GetChangeList_NoNewEntries) { |
| 371 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 371 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 372 | 372 |
| 373 GDataErrorCode error = GDATA_OTHER_ERROR; | 373 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 374 scoped_ptr<ChangeList> change_list; | 374 scoped_ptr<ChangeList> change_list; |
| 375 fake_service_.GetChangeList( | 375 fake_service_.GetChangeList( |
| 376 fake_service_.about_resource().largest_change_id() + 1, | 376 fake_service_.about_resource().largest_change_id() + 1, |
| 377 test_util::CreateCopyResultCallback(&error, &change_list)); | 377 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 378 base::RunLoop().RunUntilIdle(); | 378 base::RunLoop().RunUntilIdle(); |
| 379 | 379 |
| 380 EXPECT_EQ(HTTP_SUCCESS, error); | 380 EXPECT_EQ(HTTP_SUCCESS, error); |
| 381 ASSERT_TRUE(change_list); | 381 ASSERT_TRUE(change_list); |
| 382 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), | 382 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), |
| 383 change_list->largest_change_id()); | 383 change_list->largest_change_id()); |
| 384 // This should be empty as the latest changestamp was passed to | 384 // This should be empty as the latest changestamp was passed to |
| 385 // GetChangeList(), hence there should be no new entries. | 385 // GetChangeList(), hence there should be no new entries. |
| 386 EXPECT_EQ(0U, change_list->items().size()); | 386 EXPECT_EQ(0U, change_list->items().size()); |
| 387 // It's considered loaded even if the result is empty. | 387 // It's considered loaded even if the result is empty. |
| 388 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 388 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 389 } | 389 } |
| 390 | 390 |
| 391 TEST_F(FakeDriveServiceTest, GetChangeList_WithNewEntry) { | 391 TEST_F(FakeDriveServiceTest, GetChangeList_WithNewEntry) { |
| 392 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 392 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 393 const int64 old_largest_change_id = | 393 const int64 old_largest_change_id = |
| 394 fake_service_.about_resource().largest_change_id(); | 394 fake_service_.about_resource().largest_change_id(); |
| 395 | 395 |
| 396 // Add a new directory in the root directory. | 396 // Add a new directory in the root directory. |
| 397 ASSERT_TRUE(AddNewDirectory( | 397 ASSERT_TRUE(AddNewDirectory( |
| 398 fake_service_.GetRootResourceId(), "new directory")); | 398 fake_service_.GetRootResourceId(), "new directory")); |
| 399 | 399 |
| 400 // Get the resource list newer than old_largest_change_id. | 400 // Get the resource list newer than old_largest_change_id. |
| 401 GDataErrorCode error = GDATA_OTHER_ERROR; | 401 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 402 scoped_ptr<ChangeList> change_list; | 402 scoped_ptr<ChangeList> change_list; |
| 403 fake_service_.GetChangeList( | 403 fake_service_.GetChangeList( |
| 404 old_largest_change_id + 1, | 404 old_largest_change_id + 1, |
| 405 test_util::CreateCopyResultCallback(&error, &change_list)); | 405 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 406 base::RunLoop().RunUntilIdle(); | 406 base::RunLoop().RunUntilIdle(); |
| 407 | 407 |
| 408 EXPECT_EQ(HTTP_SUCCESS, error); | 408 EXPECT_EQ(HTTP_SUCCESS, error); |
| 409 ASSERT_TRUE(change_list); | 409 ASSERT_TRUE(change_list); |
| 410 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), | 410 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), |
| 411 change_list->largest_change_id()); | 411 change_list->largest_change_id()); |
| 412 // The result should only contain the newly created directory. | 412 // The result should only contain the newly created directory. |
| 413 ASSERT_EQ(1U, change_list->items().size()); | 413 ASSERT_EQ(1U, change_list->items().size()); |
| 414 ASSERT_TRUE(change_list->items()[0]->file()); | 414 ASSERT_TRUE(change_list->items()[0]->file()); |
| 415 EXPECT_EQ("new directory", change_list->items()[0]->file()->title()); | 415 EXPECT_EQ("new directory", change_list->items()[0]->file()->title()); |
| 416 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 416 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 417 } | 417 } |
| 418 | 418 |
| 419 TEST_F(FakeDriveServiceTest, GetChangeList_Offline) { | 419 TEST_F(FakeDriveServiceTest, GetChangeList_Offline) { |
| 420 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 420 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 421 fake_service_.set_offline(true); | 421 fake_service_.set_offline(true); |
| 422 | 422 |
| 423 GDataErrorCode error = GDATA_OTHER_ERROR; | 423 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 424 scoped_ptr<ChangeList> change_list; | 424 scoped_ptr<ChangeList> change_list; |
| 425 fake_service_.GetChangeList( | 425 fake_service_.GetChangeList( |
| 426 654321, // start_changestamp | 426 654321, // start_changestamp |
| 427 test_util::CreateCopyResultCallback(&error, &change_list)); | 427 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 428 base::RunLoop().RunUntilIdle(); | 428 base::RunLoop().RunUntilIdle(); |
| 429 | 429 |
| 430 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 430 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 431 EXPECT_FALSE(change_list); | 431 EXPECT_FALSE(change_list); |
| 432 } | 432 } |
| 433 | 433 |
| 434 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) { | 434 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) { |
| 435 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 435 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 436 ASSERT_TRUE(Exists("2_file_resource_id")); | 436 ASSERT_TRUE(Exists("2_file_resource_id")); |
| 437 const int64 old_largest_change_id = | 437 const int64 old_largest_change_id = |
| 438 fake_service_.about_resource().largest_change_id(); | 438 fake_service_.about_resource().largest_change_id(); |
| 439 | 439 |
| 440 GDataErrorCode error = GDATA_OTHER_ERROR; | 440 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 441 fake_service_.DeleteResource("2_file_resource_id", | 441 fake_service_.DeleteResource("2_file_resource_id", |
| 442 std::string(), // etag | 442 std::string(), // etag |
| 443 test_util::CreateCopyResultCallback(&error)); | 443 test_util::CreateCopyResultCallback(&error)); |
| 444 base::RunLoop().RunUntilIdle(); | 444 base::RunLoop().RunUntilIdle(); |
| 445 ASSERT_EQ(HTTP_NO_CONTENT, error); | 445 ASSERT_EQ(HTTP_NO_CONTENT, error); |
| 446 ASSERT_FALSE(Exists("2_file_resource_id")); | 446 ASSERT_FALSE(Exists("2_file_resource_id")); |
| 447 | 447 |
| 448 // Get the resource list newer than old_largest_change_id. | 448 // Get the resource list newer than old_largest_change_id. |
| 449 error = GDATA_OTHER_ERROR; | 449 error = DRIVE_OTHER_ERROR; |
| 450 scoped_ptr<ChangeList> change_list; | 450 scoped_ptr<ChangeList> change_list; |
| 451 fake_service_.GetChangeList( | 451 fake_service_.GetChangeList( |
| 452 old_largest_change_id + 1, | 452 old_largest_change_id + 1, |
| 453 test_util::CreateCopyResultCallback(&error, &change_list)); | 453 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 454 base::RunLoop().RunUntilIdle(); | 454 base::RunLoop().RunUntilIdle(); |
| 455 | 455 |
| 456 EXPECT_EQ(HTTP_SUCCESS, error); | 456 EXPECT_EQ(HTTP_SUCCESS, error); |
| 457 ASSERT_TRUE(change_list); | 457 ASSERT_TRUE(change_list); |
| 458 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), | 458 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), |
| 459 change_list->largest_change_id()); | 459 change_list->largest_change_id()); |
| 460 // The result should only contain the deleted file. | 460 // The result should only contain the deleted file. |
| 461 ASSERT_EQ(1U, change_list->items().size()); | 461 ASSERT_EQ(1U, change_list->items().size()); |
| 462 const ChangeResource& item = *change_list->items()[0]; | 462 const ChangeResource& item = *change_list->items()[0]; |
| 463 EXPECT_EQ("2_file_resource_id", item.file_id()); | 463 EXPECT_EQ("2_file_resource_id", item.file_id()); |
| 464 EXPECT_FALSE(item.file()); | 464 EXPECT_FALSE(item.file()); |
| 465 EXPECT_TRUE(item.is_deleted()); | 465 EXPECT_TRUE(item.is_deleted()); |
| 466 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 466 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 467 } | 467 } |
| 468 | 468 |
| 469 TEST_F(FakeDriveServiceTest, GetChangeList_TrashedEntry) { | 469 TEST_F(FakeDriveServiceTest, GetChangeList_TrashedEntry) { |
| 470 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 470 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 471 ASSERT_TRUE(Exists("2_file_resource_id")); | 471 ASSERT_TRUE(Exists("2_file_resource_id")); |
| 472 const int64 old_largest_change_id = | 472 const int64 old_largest_change_id = |
| 473 fake_service_.about_resource().largest_change_id(); | 473 fake_service_.about_resource().largest_change_id(); |
| 474 | 474 |
| 475 GDataErrorCode error = GDATA_OTHER_ERROR; | 475 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 476 fake_service_.TrashResource("2_file_resource_id", | 476 fake_service_.TrashResource("2_file_resource_id", |
| 477 test_util::CreateCopyResultCallback(&error)); | 477 test_util::CreateCopyResultCallback(&error)); |
| 478 base::RunLoop().RunUntilIdle(); | 478 base::RunLoop().RunUntilIdle(); |
| 479 ASSERT_EQ(HTTP_SUCCESS, error); | 479 ASSERT_EQ(HTTP_SUCCESS, error); |
| 480 ASSERT_FALSE(Exists("2_file_resource_id")); | 480 ASSERT_FALSE(Exists("2_file_resource_id")); |
| 481 | 481 |
| 482 // Get the resource list newer than old_largest_change_id. | 482 // Get the resource list newer than old_largest_change_id. |
| 483 error = GDATA_OTHER_ERROR; | 483 error = DRIVE_OTHER_ERROR; |
| 484 scoped_ptr<ChangeList> change_list; | 484 scoped_ptr<ChangeList> change_list; |
| 485 fake_service_.GetChangeList( | 485 fake_service_.GetChangeList( |
| 486 old_largest_change_id + 1, | 486 old_largest_change_id + 1, |
| 487 test_util::CreateCopyResultCallback(&error, &change_list)); | 487 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 488 base::RunLoop().RunUntilIdle(); | 488 base::RunLoop().RunUntilIdle(); |
| 489 | 489 |
| 490 EXPECT_EQ(HTTP_SUCCESS, error); | 490 EXPECT_EQ(HTTP_SUCCESS, error); |
| 491 ASSERT_TRUE(change_list); | 491 ASSERT_TRUE(change_list); |
| 492 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), | 492 EXPECT_EQ(fake_service_.about_resource().largest_change_id(), |
| 493 change_list->largest_change_id()); | 493 change_list->largest_change_id()); |
| 494 // The result should only contain the trashed file. | 494 // The result should only contain the trashed file. |
| 495 ASSERT_EQ(1U, change_list->items().size()); | 495 ASSERT_EQ(1U, change_list->items().size()); |
| 496 const ChangeResource& item = *change_list->items()[0]; | 496 const ChangeResource& item = *change_list->items()[0]; |
| 497 EXPECT_EQ("2_file_resource_id", item.file_id()); | 497 EXPECT_EQ("2_file_resource_id", item.file_id()); |
| 498 ASSERT_TRUE(item.file()); | 498 ASSERT_TRUE(item.file()); |
| 499 EXPECT_TRUE(item.file()->labels().is_trashed()); | 499 EXPECT_TRUE(item.file()->labels().is_trashed()); |
| 500 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 500 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 501 } | 501 } |
| 502 | 502 |
| 503 TEST_F(FakeDriveServiceTest, GetRemainingFileList_GetAllFileList) { | 503 TEST_F(FakeDriveServiceTest, GetRemainingFileList_GetAllFileList) { |
| 504 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 504 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 505 fake_service_.set_default_max_results(6); | 505 fake_service_.set_default_max_results(6); |
| 506 | 506 |
| 507 GDataErrorCode error = GDATA_OTHER_ERROR; | 507 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 508 scoped_ptr<FileList> file_list; | 508 scoped_ptr<FileList> file_list; |
| 509 fake_service_.GetAllFileList( | 509 fake_service_.GetAllFileList( |
| 510 test_util::CreateCopyResultCallback(&error, &file_list)); | 510 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 511 base::RunLoop().RunUntilIdle(); | 511 base::RunLoop().RunUntilIdle(); |
| 512 EXPECT_EQ(HTTP_SUCCESS, error); | 512 EXPECT_EQ(HTTP_SUCCESS, error); |
| 513 ASSERT_TRUE(file_list); | 513 ASSERT_TRUE(file_list); |
| 514 | 514 |
| 515 // Do some sanity check. | 515 // Do some sanity check. |
| 516 // The number of results is 14 entries. Thus, it should split into three | 516 // The number of results is 14 entries. Thus, it should split into three |
| 517 // chunks: 6, 6, and then 2. | 517 // chunks: 6, 6, and then 2. |
| 518 EXPECT_EQ(6U, file_list->items().size()); | 518 EXPECT_EQ(6U, file_list->items().size()); |
| 519 EXPECT_EQ(1, fake_service_.file_list_load_count()); | 519 EXPECT_EQ(1, fake_service_.file_list_load_count()); |
| 520 | 520 |
| 521 // Second page loading. | 521 // Second page loading. |
| 522 // Keep the next url before releasing the |file_list|. | 522 // Keep the next url before releasing the |file_list|. |
| 523 GURL next_url(file_list->next_link()); | 523 GURL next_url(file_list->next_link()); |
| 524 | 524 |
| 525 error = GDATA_OTHER_ERROR; | 525 error = DRIVE_OTHER_ERROR; |
| 526 file_list.reset(); | 526 file_list.reset(); |
| 527 fake_service_.GetRemainingFileList( | 527 fake_service_.GetRemainingFileList( |
| 528 next_url, | 528 next_url, |
| 529 test_util::CreateCopyResultCallback(&error, &file_list)); | 529 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 530 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
| 531 | 531 |
| 532 EXPECT_EQ(HTTP_SUCCESS, error); | 532 EXPECT_EQ(HTTP_SUCCESS, error); |
| 533 ASSERT_TRUE(file_list); | 533 ASSERT_TRUE(file_list); |
| 534 | 534 |
| 535 EXPECT_EQ(6U, file_list->items().size()); | 535 EXPECT_EQ(6U, file_list->items().size()); |
| 536 EXPECT_EQ(1, fake_service_.file_list_load_count()); | 536 EXPECT_EQ(1, fake_service_.file_list_load_count()); |
| 537 | 537 |
| 538 // Third page loading. | 538 // Third page loading. |
| 539 next_url = file_list->next_link(); | 539 next_url = file_list->next_link(); |
| 540 | 540 |
| 541 error = GDATA_OTHER_ERROR; | 541 error = DRIVE_OTHER_ERROR; |
| 542 file_list.reset(); | 542 file_list.reset(); |
| 543 fake_service_.GetRemainingFileList( | 543 fake_service_.GetRemainingFileList( |
| 544 next_url, | 544 next_url, |
| 545 test_util::CreateCopyResultCallback(&error, &file_list)); | 545 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 546 base::RunLoop().RunUntilIdle(); | 546 base::RunLoop().RunUntilIdle(); |
| 547 | 547 |
| 548 EXPECT_EQ(HTTP_SUCCESS, error); | 548 EXPECT_EQ(HTTP_SUCCESS, error); |
| 549 ASSERT_TRUE(file_list); | 549 ASSERT_TRUE(file_list); |
| 550 | 550 |
| 551 EXPECT_EQ(3U, file_list->items().size()); | 551 EXPECT_EQ(3U, file_list->items().size()); |
| 552 EXPECT_EQ(1, fake_service_.file_list_load_count()); | 552 EXPECT_EQ(1, fake_service_.file_list_load_count()); |
| 553 } | 553 } |
| 554 | 554 |
| 555 TEST_F(FakeDriveServiceTest, GetRemainingFileList_GetFileListInDirectory) { | 555 TEST_F(FakeDriveServiceTest, GetRemainingFileList_GetFileListInDirectory) { |
| 556 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 556 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 557 fake_service_.set_default_max_results(3); | 557 fake_service_.set_default_max_results(3); |
| 558 | 558 |
| 559 GDataErrorCode error = GDATA_OTHER_ERROR; | 559 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 560 scoped_ptr<FileList> file_list; | 560 scoped_ptr<FileList> file_list; |
| 561 fake_service_.GetFileListInDirectory( | 561 fake_service_.GetFileListInDirectory( |
| 562 fake_service_.GetRootResourceId(), | 562 fake_service_.GetRootResourceId(), |
| 563 test_util::CreateCopyResultCallback(&error, &file_list)); | 563 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 564 base::RunLoop().RunUntilIdle(); | 564 base::RunLoop().RunUntilIdle(); |
| 565 EXPECT_EQ(HTTP_SUCCESS, error); | 565 EXPECT_EQ(HTTP_SUCCESS, error); |
| 566 ASSERT_TRUE(file_list); | 566 ASSERT_TRUE(file_list); |
| 567 | 567 |
| 568 // Do some sanity check. | 568 // Do some sanity check. |
| 569 // The number of results is 8 entries. Thus, it should split into three | 569 // The number of results is 8 entries. Thus, it should split into three |
| 570 // chunks: 3, 3, and then 2. | 570 // chunks: 3, 3, and then 2. |
| 571 EXPECT_EQ(3U, file_list->items().size()); | 571 EXPECT_EQ(3U, file_list->items().size()); |
| 572 EXPECT_EQ(1, fake_service_.directory_load_count()); | 572 EXPECT_EQ(1, fake_service_.directory_load_count()); |
| 573 | 573 |
| 574 // Second page loading. | 574 // Second page loading. |
| 575 // Keep the next url before releasing the |file_list|. | 575 // Keep the next url before releasing the |file_list|. |
| 576 GURL next_url = file_list->next_link(); | 576 GURL next_url = file_list->next_link(); |
| 577 | 577 |
| 578 error = GDATA_OTHER_ERROR; | 578 error = DRIVE_OTHER_ERROR; |
| 579 file_list.reset(); | 579 file_list.reset(); |
| 580 fake_service_.GetRemainingFileList( | 580 fake_service_.GetRemainingFileList( |
| 581 next_url, | 581 next_url, |
| 582 test_util::CreateCopyResultCallback(&error, &file_list)); | 582 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 583 base::RunLoop().RunUntilIdle(); | 583 base::RunLoop().RunUntilIdle(); |
| 584 | 584 |
| 585 EXPECT_EQ(HTTP_SUCCESS, error); | 585 EXPECT_EQ(HTTP_SUCCESS, error); |
| 586 ASSERT_TRUE(file_list); | 586 ASSERT_TRUE(file_list); |
| 587 | 587 |
| 588 EXPECT_EQ(3U, file_list->items().size()); | 588 EXPECT_EQ(3U, file_list->items().size()); |
| 589 EXPECT_EQ(1, fake_service_.directory_load_count()); | 589 EXPECT_EQ(1, fake_service_.directory_load_count()); |
| 590 | 590 |
| 591 // Third page loading. | 591 // Third page loading. |
| 592 next_url = file_list->next_link(); | 592 next_url = file_list->next_link(); |
| 593 | 593 |
| 594 error = GDATA_OTHER_ERROR; | 594 error = DRIVE_OTHER_ERROR; |
| 595 file_list.reset(); | 595 file_list.reset(); |
| 596 fake_service_.GetRemainingFileList( | 596 fake_service_.GetRemainingFileList( |
| 597 next_url, | 597 next_url, |
| 598 test_util::CreateCopyResultCallback(&error, &file_list)); | 598 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 599 base::RunLoop().RunUntilIdle(); | 599 base::RunLoop().RunUntilIdle(); |
| 600 | 600 |
| 601 EXPECT_EQ(HTTP_SUCCESS, error); | 601 EXPECT_EQ(HTTP_SUCCESS, error); |
| 602 ASSERT_TRUE(file_list); | 602 ASSERT_TRUE(file_list); |
| 603 | 603 |
| 604 EXPECT_EQ(2U, file_list->items().size()); | 604 EXPECT_EQ(2U, file_list->items().size()); |
| 605 EXPECT_EQ(1, fake_service_.directory_load_count()); | 605 EXPECT_EQ(1, fake_service_.directory_load_count()); |
| 606 } | 606 } |
| 607 | 607 |
| 608 TEST_F(FakeDriveServiceTest, GetRemainingFileList_Search) { | 608 TEST_F(FakeDriveServiceTest, GetRemainingFileList_Search) { |
| 609 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 609 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 610 fake_service_.set_default_max_results(2); | 610 fake_service_.set_default_max_results(2); |
| 611 | 611 |
| 612 GDataErrorCode error = GDATA_OTHER_ERROR; | 612 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 613 scoped_ptr<FileList> file_list; | 613 scoped_ptr<FileList> file_list; |
| 614 fake_service_.Search( | 614 fake_service_.Search( |
| 615 "File", // search_query | 615 "File", // search_query |
| 616 test_util::CreateCopyResultCallback(&error, &file_list)); | 616 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 617 base::RunLoop().RunUntilIdle(); | 617 base::RunLoop().RunUntilIdle(); |
| 618 EXPECT_EQ(HTTP_SUCCESS, error); | 618 EXPECT_EQ(HTTP_SUCCESS, error); |
| 619 ASSERT_TRUE(file_list); | 619 ASSERT_TRUE(file_list); |
| 620 | 620 |
| 621 // Do some sanity check. | 621 // Do some sanity check. |
| 622 // The number of results is 4 entries. Thus, it should split into two | 622 // The number of results is 4 entries. Thus, it should split into two |
| 623 // chunks: 2, and then 2 | 623 // chunks: 2, and then 2 |
| 624 EXPECT_EQ(2U, file_list->items().size()); | 624 EXPECT_EQ(2U, file_list->items().size()); |
| 625 | 625 |
| 626 // Second page loading. | 626 // Second page loading. |
| 627 // Keep the next url before releasing the |file_list|. | 627 // Keep the next url before releasing the |file_list|. |
| 628 GURL next_url = file_list->next_link(); | 628 GURL next_url = file_list->next_link(); |
| 629 | 629 |
| 630 error = GDATA_OTHER_ERROR; | 630 error = DRIVE_OTHER_ERROR; |
| 631 file_list.reset(); | 631 file_list.reset(); |
| 632 fake_service_.GetRemainingFileList( | 632 fake_service_.GetRemainingFileList( |
| 633 next_url, | 633 next_url, |
| 634 test_util::CreateCopyResultCallback(&error, &file_list)); | 634 test_util::CreateCopyResultCallback(&error, &file_list)); |
| 635 base::RunLoop().RunUntilIdle(); | 635 base::RunLoop().RunUntilIdle(); |
| 636 | 636 |
| 637 EXPECT_EQ(HTTP_SUCCESS, error); | 637 EXPECT_EQ(HTTP_SUCCESS, error); |
| 638 ASSERT_TRUE(file_list); | 638 ASSERT_TRUE(file_list); |
| 639 | 639 |
| 640 EXPECT_EQ(2U, file_list->items().size()); | 640 EXPECT_EQ(2U, file_list->items().size()); |
| 641 } | 641 } |
| 642 | 642 |
| 643 TEST_F(FakeDriveServiceTest, GetRemainingChangeList_GetChangeList) { | 643 TEST_F(FakeDriveServiceTest, GetRemainingChangeList_GetChangeList) { |
| 644 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 644 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 645 fake_service_.set_default_max_results(2); | 645 fake_service_.set_default_max_results(2); |
| 646 const int64 old_largest_change_id = | 646 const int64 old_largest_change_id = |
| 647 fake_service_.about_resource().largest_change_id(); | 647 fake_service_.about_resource().largest_change_id(); |
| 648 | 648 |
| 649 // Add 5 new directory in the root directory. | 649 // Add 5 new directory in the root directory. |
| 650 for (int i = 0; i < 5; ++i) { | 650 for (int i = 0; i < 5; ++i) { |
| 651 ASSERT_TRUE(AddNewDirectory( | 651 ASSERT_TRUE(AddNewDirectory( |
| 652 fake_service_.GetRootResourceId(), | 652 fake_service_.GetRootResourceId(), |
| 653 base::StringPrintf("new directory %d", i))); | 653 base::StringPrintf("new directory %d", i))); |
| 654 } | 654 } |
| 655 | 655 |
| 656 GDataErrorCode error = GDATA_OTHER_ERROR; | 656 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 657 scoped_ptr<ChangeList> change_list; | 657 scoped_ptr<ChangeList> change_list; |
| 658 fake_service_.GetChangeList( | 658 fake_service_.GetChangeList( |
| 659 old_largest_change_id + 1, // start_changestamp | 659 old_largest_change_id + 1, // start_changestamp |
| 660 test_util::CreateCopyResultCallback(&error, &change_list)); | 660 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 661 base::RunLoop().RunUntilIdle(); | 661 base::RunLoop().RunUntilIdle(); |
| 662 EXPECT_EQ(HTTP_SUCCESS, error); | 662 EXPECT_EQ(HTTP_SUCCESS, error); |
| 663 ASSERT_TRUE(change_list); | 663 ASSERT_TRUE(change_list); |
| 664 | 664 |
| 665 // Do some sanity check. | 665 // Do some sanity check. |
| 666 // The number of results is 5 entries. Thus, it should split into three | 666 // The number of results is 5 entries. Thus, it should split into three |
| 667 // chunks: 2, 2 and then 1. | 667 // chunks: 2, 2 and then 1. |
| 668 EXPECT_EQ(2U, change_list->items().size()); | 668 EXPECT_EQ(2U, change_list->items().size()); |
| 669 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 669 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 670 | 670 |
| 671 // Second page loading. | 671 // Second page loading. |
| 672 // Keep the next url before releasing the |change_list|. | 672 // Keep the next url before releasing the |change_list|. |
| 673 GURL next_url = change_list->next_link(); | 673 GURL next_url = change_list->next_link(); |
| 674 | 674 |
| 675 error = GDATA_OTHER_ERROR; | 675 error = DRIVE_OTHER_ERROR; |
| 676 change_list.reset(); | 676 change_list.reset(); |
| 677 fake_service_.GetRemainingChangeList( | 677 fake_service_.GetRemainingChangeList( |
| 678 next_url, | 678 next_url, |
| 679 test_util::CreateCopyResultCallback(&error, &change_list)); | 679 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 680 base::RunLoop().RunUntilIdle(); | 680 base::RunLoop().RunUntilIdle(); |
| 681 | 681 |
| 682 EXPECT_EQ(HTTP_SUCCESS, error); | 682 EXPECT_EQ(HTTP_SUCCESS, error); |
| 683 ASSERT_TRUE(change_list); | 683 ASSERT_TRUE(change_list); |
| 684 | 684 |
| 685 EXPECT_EQ(2U, change_list->items().size()); | 685 EXPECT_EQ(2U, change_list->items().size()); |
| 686 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 686 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 687 | 687 |
| 688 // Third page loading. | 688 // Third page loading. |
| 689 next_url = change_list->next_link(); | 689 next_url = change_list->next_link(); |
| 690 | 690 |
| 691 error = GDATA_OTHER_ERROR; | 691 error = DRIVE_OTHER_ERROR; |
| 692 change_list.reset(); | 692 change_list.reset(); |
| 693 fake_service_.GetRemainingChangeList( | 693 fake_service_.GetRemainingChangeList( |
| 694 next_url, | 694 next_url, |
| 695 test_util::CreateCopyResultCallback(&error, &change_list)); | 695 test_util::CreateCopyResultCallback(&error, &change_list)); |
| 696 base::RunLoop().RunUntilIdle(); | 696 base::RunLoop().RunUntilIdle(); |
| 697 | 697 |
| 698 EXPECT_EQ(HTTP_SUCCESS, error); | 698 EXPECT_EQ(HTTP_SUCCESS, error); |
| 699 ASSERT_TRUE(change_list); | 699 ASSERT_TRUE(change_list); |
| 700 | 700 |
| 701 EXPECT_EQ(1U, change_list->items().size()); | 701 EXPECT_EQ(1U, change_list->items().size()); |
| 702 EXPECT_EQ(1, fake_service_.change_list_load_count()); | 702 EXPECT_EQ(1, fake_service_.change_list_load_count()); |
| 703 } | 703 } |
| 704 | 704 |
| 705 TEST_F(FakeDriveServiceTest, GetAboutResource) { | 705 TEST_F(FakeDriveServiceTest, GetAboutResource) { |
| 706 GDataErrorCode error = GDATA_OTHER_ERROR; | 706 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 707 scoped_ptr<AboutResource> about_resource; | 707 scoped_ptr<AboutResource> about_resource; |
| 708 fake_service_.GetAboutResource( | 708 fake_service_.GetAboutResource( |
| 709 test_util::CreateCopyResultCallback(&error, &about_resource)); | 709 test_util::CreateCopyResultCallback(&error, &about_resource)); |
| 710 base::RunLoop().RunUntilIdle(); | 710 base::RunLoop().RunUntilIdle(); |
| 711 | 711 |
| 712 EXPECT_EQ(HTTP_SUCCESS, error); | 712 EXPECT_EQ(HTTP_SUCCESS, error); |
| 713 | 713 |
| 714 ASSERT_TRUE(about_resource); | 714 ASSERT_TRUE(about_resource); |
| 715 // Do some sanity check. | 715 // Do some sanity check. |
| 716 EXPECT_EQ(fake_service_.GetRootResourceId(), | 716 EXPECT_EQ(fake_service_.GetRootResourceId(), |
| 717 about_resource->root_folder_id()); | 717 about_resource->root_folder_id()); |
| 718 EXPECT_EQ(1, fake_service_.about_resource_load_count()); | 718 EXPECT_EQ(1, fake_service_.about_resource_load_count()); |
| 719 } | 719 } |
| 720 | 720 |
| 721 TEST_F(FakeDriveServiceTest, GetAboutResource_Offline) { | 721 TEST_F(FakeDriveServiceTest, GetAboutResource_Offline) { |
| 722 fake_service_.set_offline(true); | 722 fake_service_.set_offline(true); |
| 723 | 723 |
| 724 GDataErrorCode error = GDATA_OTHER_ERROR; | 724 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 725 scoped_ptr<AboutResource> about_resource; | 725 scoped_ptr<AboutResource> about_resource; |
| 726 fake_service_.GetAboutResource( | 726 fake_service_.GetAboutResource( |
| 727 test_util::CreateCopyResultCallback(&error, &about_resource)); | 727 test_util::CreateCopyResultCallback(&error, &about_resource)); |
| 728 base::RunLoop().RunUntilIdle(); | 728 base::RunLoop().RunUntilIdle(); |
| 729 | 729 |
| 730 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 730 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 731 EXPECT_FALSE(about_resource); | 731 EXPECT_FALSE(about_resource); |
| 732 } | 732 } |
| 733 | 733 |
| 734 TEST_F(FakeDriveServiceTest, GetAppList) { | 734 TEST_F(FakeDriveServiceTest, GetAppList) { |
| 735 ASSERT_TRUE(fake_service_.LoadAppListForDriveApi( | 735 ASSERT_TRUE(fake_service_.LoadAppListForDriveApi( |
| 736 "drive/applist.json")); | 736 "drive/applist.json")); |
| 737 | 737 |
| 738 GDataErrorCode error = GDATA_OTHER_ERROR; | 738 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 739 scoped_ptr<AppList> app_list; | 739 scoped_ptr<AppList> app_list; |
| 740 fake_service_.GetAppList( | 740 fake_service_.GetAppList( |
| 741 test_util::CreateCopyResultCallback(&error, &app_list)); | 741 test_util::CreateCopyResultCallback(&error, &app_list)); |
| 742 base::RunLoop().RunUntilIdle(); | 742 base::RunLoop().RunUntilIdle(); |
| 743 | 743 |
| 744 EXPECT_EQ(HTTP_SUCCESS, error); | 744 EXPECT_EQ(HTTP_SUCCESS, error); |
| 745 | 745 |
| 746 ASSERT_TRUE(app_list); | 746 ASSERT_TRUE(app_list); |
| 747 EXPECT_EQ(1, fake_service_.app_list_load_count()); | 747 EXPECT_EQ(1, fake_service_.app_list_load_count()); |
| 748 } | 748 } |
| 749 | 749 |
| 750 TEST_F(FakeDriveServiceTest, GetAppList_Offline) { | 750 TEST_F(FakeDriveServiceTest, GetAppList_Offline) { |
| 751 ASSERT_TRUE(fake_service_.LoadAppListForDriveApi( | 751 ASSERT_TRUE(fake_service_.LoadAppListForDriveApi( |
| 752 "drive/applist.json")); | 752 "drive/applist.json")); |
| 753 fake_service_.set_offline(true); | 753 fake_service_.set_offline(true); |
| 754 | 754 |
| 755 GDataErrorCode error = GDATA_OTHER_ERROR; | 755 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 756 scoped_ptr<AppList> app_list; | 756 scoped_ptr<AppList> app_list; |
| 757 fake_service_.GetAppList( | 757 fake_service_.GetAppList( |
| 758 test_util::CreateCopyResultCallback(&error, &app_list)); | 758 test_util::CreateCopyResultCallback(&error, &app_list)); |
| 759 base::RunLoop().RunUntilIdle(); | 759 base::RunLoop().RunUntilIdle(); |
| 760 | 760 |
| 761 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 761 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 762 EXPECT_FALSE(app_list); | 762 EXPECT_FALSE(app_list); |
| 763 } | 763 } |
| 764 | 764 |
| 765 TEST_F(FakeDriveServiceTest, GetFileResource_ExistingFile) { | 765 TEST_F(FakeDriveServiceTest, GetFileResource_ExistingFile) { |
| 766 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 766 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 767 | 767 |
| 768 const std::string kResourceId = "2_file_resource_id"; | 768 const std::string kResourceId = "2_file_resource_id"; |
| 769 GDataErrorCode error = GDATA_OTHER_ERROR; | 769 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 770 scoped_ptr<FileResource> entry; | 770 scoped_ptr<FileResource> entry; |
| 771 fake_service_.GetFileResource( | 771 fake_service_.GetFileResource( |
| 772 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); | 772 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); |
| 773 base::RunLoop().RunUntilIdle(); | 773 base::RunLoop().RunUntilIdle(); |
| 774 | 774 |
| 775 EXPECT_EQ(HTTP_SUCCESS, error); | 775 EXPECT_EQ(HTTP_SUCCESS, error); |
| 776 ASSERT_TRUE(entry); | 776 ASSERT_TRUE(entry); |
| 777 // Do some sanity check. | 777 // Do some sanity check. |
| 778 EXPECT_EQ(kResourceId, entry->file_id()); | 778 EXPECT_EQ(kResourceId, entry->file_id()); |
| 779 } | 779 } |
| 780 | 780 |
| 781 TEST_F(FakeDriveServiceTest, GetFileResource_NonexistingFile) { | 781 TEST_F(FakeDriveServiceTest, GetFileResource_NonexistingFile) { |
| 782 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 782 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 783 | 783 |
| 784 const std::string kResourceId = "nonexisting_resource_id"; | 784 const std::string kResourceId = "nonexisting_resource_id"; |
| 785 GDataErrorCode error = GDATA_OTHER_ERROR; | 785 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 786 scoped_ptr<FileResource> entry; | 786 scoped_ptr<FileResource> entry; |
| 787 fake_service_.GetFileResource( | 787 fake_service_.GetFileResource( |
| 788 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); | 788 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); |
| 789 base::RunLoop().RunUntilIdle(); | 789 base::RunLoop().RunUntilIdle(); |
| 790 | 790 |
| 791 EXPECT_EQ(HTTP_NOT_FOUND, error); | 791 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 792 ASSERT_FALSE(entry); | 792 ASSERT_FALSE(entry); |
| 793 } | 793 } |
| 794 | 794 |
| 795 TEST_F(FakeDriveServiceTest, GetFileResource_Offline) { | 795 TEST_F(FakeDriveServiceTest, GetFileResource_Offline) { |
| 796 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 796 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 797 fake_service_.set_offline(true); | 797 fake_service_.set_offline(true); |
| 798 | 798 |
| 799 const std::string kResourceId = "2_file_resource_id"; | 799 const std::string kResourceId = "2_file_resource_id"; |
| 800 GDataErrorCode error = GDATA_OTHER_ERROR; | 800 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 801 scoped_ptr<FileResource> entry; | 801 scoped_ptr<FileResource> entry; |
| 802 fake_service_.GetFileResource( | 802 fake_service_.GetFileResource( |
| 803 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); | 803 kResourceId, test_util::CreateCopyResultCallback(&error, &entry)); |
| 804 base::RunLoop().RunUntilIdle(); | 804 base::RunLoop().RunUntilIdle(); |
| 805 | 805 |
| 806 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 806 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 807 EXPECT_FALSE(entry); | 807 EXPECT_FALSE(entry); |
| 808 } | 808 } |
| 809 | 809 |
| 810 TEST_F(FakeDriveServiceTest, GetShareUrl) { | 810 TEST_F(FakeDriveServiceTest, GetShareUrl) { |
| 811 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 811 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 812 | 812 |
| 813 const std::string kResourceId = "2_file_resource_id"; | 813 const std::string kResourceId = "2_file_resource_id"; |
| 814 GDataErrorCode error = GDATA_OTHER_ERROR; | 814 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 815 GURL share_url; | 815 GURL share_url; |
| 816 fake_service_.GetShareUrl( | 816 fake_service_.GetShareUrl( |
| 817 kResourceId, | 817 kResourceId, |
| 818 GURL(), // embed origin | 818 GURL(), // embed origin |
| 819 test_util::CreateCopyResultCallback(&error, &share_url)); | 819 test_util::CreateCopyResultCallback(&error, &share_url)); |
| 820 base::RunLoop().RunUntilIdle(); | 820 base::RunLoop().RunUntilIdle(); |
| 821 | 821 |
| 822 EXPECT_EQ(HTTP_SUCCESS, error); | 822 EXPECT_EQ(HTTP_SUCCESS, error); |
| 823 EXPECT_FALSE(share_url.is_empty()); | 823 EXPECT_FALSE(share_url.is_empty()); |
| 824 } | 824 } |
| 825 | 825 |
| 826 TEST_F(FakeDriveServiceTest, DeleteResource_ExistingFile) { | 826 TEST_F(FakeDriveServiceTest, DeleteResource_ExistingFile) { |
| 827 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 827 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 828 | 828 |
| 829 // Resource "2_file_resource_id" should now exist. | 829 // Resource "2_file_resource_id" should now exist. |
| 830 ASSERT_TRUE(Exists("2_file_resource_id")); | 830 ASSERT_TRUE(Exists("2_file_resource_id")); |
| 831 | 831 |
| 832 GDataErrorCode error = GDATA_OTHER_ERROR; | 832 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 833 fake_service_.DeleteResource("2_file_resource_id", | 833 fake_service_.DeleteResource("2_file_resource_id", |
| 834 std::string(), // etag | 834 std::string(), // etag |
| 835 test_util::CreateCopyResultCallback(&error)); | 835 test_util::CreateCopyResultCallback(&error)); |
| 836 base::RunLoop().RunUntilIdle(); | 836 base::RunLoop().RunUntilIdle(); |
| 837 | 837 |
| 838 EXPECT_EQ(HTTP_NO_CONTENT, error); | 838 EXPECT_EQ(HTTP_NO_CONTENT, error); |
| 839 // Resource "2_file_resource_id" should be gone now. | 839 // Resource "2_file_resource_id" should be gone now. |
| 840 EXPECT_FALSE(Exists("2_file_resource_id")); | 840 EXPECT_FALSE(Exists("2_file_resource_id")); |
| 841 | 841 |
| 842 error = GDATA_OTHER_ERROR; | 842 error = DRIVE_OTHER_ERROR; |
| 843 fake_service_.DeleteResource("2_file_resource_id", | 843 fake_service_.DeleteResource("2_file_resource_id", |
| 844 std::string(), // etag | 844 std::string(), // etag |
| 845 test_util::CreateCopyResultCallback(&error)); | 845 test_util::CreateCopyResultCallback(&error)); |
| 846 base::RunLoop().RunUntilIdle(); | 846 base::RunLoop().RunUntilIdle(); |
| 847 EXPECT_EQ(HTTP_NOT_FOUND, error); | 847 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 848 EXPECT_FALSE(Exists("2_file_resource_id")); | 848 EXPECT_FALSE(Exists("2_file_resource_id")); |
| 849 } | 849 } |
| 850 | 850 |
| 851 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) { | 851 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) { |
| 852 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 852 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 853 | 853 |
| 854 GDataErrorCode error = GDATA_OTHER_ERROR; | 854 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 855 fake_service_.DeleteResource("nonexisting_resource_id", | 855 fake_service_.DeleteResource("nonexisting_resource_id", |
| 856 std::string(), // etag | 856 std::string(), // etag |
| 857 test_util::CreateCopyResultCallback(&error)); | 857 test_util::CreateCopyResultCallback(&error)); |
| 858 base::RunLoop().RunUntilIdle(); | 858 base::RunLoop().RunUntilIdle(); |
| 859 | 859 |
| 860 EXPECT_EQ(HTTP_NOT_FOUND, error); | 860 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 861 } | 861 } |
| 862 | 862 |
| 863 TEST_F(FakeDriveServiceTest, DeleteResource_ETagMatch) { | 863 TEST_F(FakeDriveServiceTest, DeleteResource_ETagMatch) { |
| 864 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 864 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 865 | 865 |
| 866 // Resource "2_file_resource_id" should now exist. | 866 // Resource "2_file_resource_id" should now exist. |
| 867 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); | 867 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
| 868 ASSERT_TRUE(entry); | 868 ASSERT_TRUE(entry); |
| 869 ASSERT_FALSE(entry->labels().is_trashed()); | 869 ASSERT_FALSE(entry->labels().is_trashed()); |
| 870 ASSERT_FALSE(entry->etag().empty()); | 870 ASSERT_FALSE(entry->etag().empty()); |
| 871 | 871 |
| 872 GDataErrorCode error = GDATA_OTHER_ERROR; | 872 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 873 fake_service_.DeleteResource("2_file_resource_id", | 873 fake_service_.DeleteResource("2_file_resource_id", |
| 874 entry->etag() + "_mismatch", | 874 entry->etag() + "_mismatch", |
| 875 test_util::CreateCopyResultCallback(&error)); | 875 test_util::CreateCopyResultCallback(&error)); |
| 876 base::RunLoop().RunUntilIdle(); | 876 base::RunLoop().RunUntilIdle(); |
| 877 | 877 |
| 878 EXPECT_EQ(HTTP_PRECONDITION, error); | 878 EXPECT_EQ(HTTP_PRECONDITION, error); |
| 879 // Resource "2_file_resource_id" should still exist. | 879 // Resource "2_file_resource_id" should still exist. |
| 880 EXPECT_TRUE(Exists("2_file_resource_id")); | 880 EXPECT_TRUE(Exists("2_file_resource_id")); |
| 881 | 881 |
| 882 error = GDATA_OTHER_ERROR; | 882 error = DRIVE_OTHER_ERROR; |
| 883 fake_service_.DeleteResource("2_file_resource_id", | 883 fake_service_.DeleteResource("2_file_resource_id", |
| 884 entry->etag(), | 884 entry->etag(), |
| 885 test_util::CreateCopyResultCallback(&error)); | 885 test_util::CreateCopyResultCallback(&error)); |
| 886 base::RunLoop().RunUntilIdle(); | 886 base::RunLoop().RunUntilIdle(); |
| 887 EXPECT_EQ(HTTP_NO_CONTENT, error); | 887 EXPECT_EQ(HTTP_NO_CONTENT, error); |
| 888 // Resource "2_file_resource_id" should be gone now. | 888 // Resource "2_file_resource_id" should be gone now. |
| 889 EXPECT_FALSE(Exists("2_file_resource_id")); | 889 EXPECT_FALSE(Exists("2_file_resource_id")); |
| 890 } | 890 } |
| 891 | 891 |
| 892 TEST_F(FakeDriveServiceTest, DeleteResource_Offline) { | 892 TEST_F(FakeDriveServiceTest, DeleteResource_Offline) { |
| 893 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 893 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 894 fake_service_.set_offline(true); | 894 fake_service_.set_offline(true); |
| 895 | 895 |
| 896 GDataErrorCode error = GDATA_OTHER_ERROR; | 896 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 897 fake_service_.DeleteResource("2_file_resource_id", | 897 fake_service_.DeleteResource("2_file_resource_id", |
| 898 std::string(), // etag | 898 std::string(), // etag |
| 899 test_util::CreateCopyResultCallback(&error)); | 899 test_util::CreateCopyResultCallback(&error)); |
| 900 base::RunLoop().RunUntilIdle(); | 900 base::RunLoop().RunUntilIdle(); |
| 901 | 901 |
| 902 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 902 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 903 } | 903 } |
| 904 | 904 |
| 905 TEST_F(FakeDriveServiceTest, DeleteResource_Forbidden) { | 905 TEST_F(FakeDriveServiceTest, DeleteResource_Forbidden) { |
| 906 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 906 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 907 | 907 |
| 908 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( | 908 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( |
| 909 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); | 909 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); |
| 910 | 910 |
| 911 GDataErrorCode error = GDATA_OTHER_ERROR; | 911 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 912 fake_service_.DeleteResource("2_file_resource_id", | 912 fake_service_.DeleteResource("2_file_resource_id", |
| 913 std::string(), // etag | 913 std::string(), // etag |
| 914 test_util::CreateCopyResultCallback(&error)); | 914 test_util::CreateCopyResultCallback(&error)); |
| 915 base::RunLoop().RunUntilIdle(); | 915 base::RunLoop().RunUntilIdle(); |
| 916 | 916 |
| 917 EXPECT_EQ(HTTP_FORBIDDEN, error); | 917 EXPECT_EQ(HTTP_FORBIDDEN, error); |
| 918 } | 918 } |
| 919 | 919 |
| 920 TEST_F(FakeDriveServiceTest, TrashResource_ExistingFile) { | 920 TEST_F(FakeDriveServiceTest, TrashResource_ExistingFile) { |
| 921 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 921 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 922 | 922 |
| 923 // Resource "2_file_resource_id" should now exist. | 923 // Resource "2_file_resource_id" should now exist. |
| 924 ASSERT_TRUE(Exists("2_file_resource_id")); | 924 ASSERT_TRUE(Exists("2_file_resource_id")); |
| 925 | 925 |
| 926 GDataErrorCode error = GDATA_OTHER_ERROR; | 926 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 927 fake_service_.TrashResource("2_file_resource_id", | 927 fake_service_.TrashResource("2_file_resource_id", |
| 928 test_util::CreateCopyResultCallback(&error)); | 928 test_util::CreateCopyResultCallback(&error)); |
| 929 base::RunLoop().RunUntilIdle(); | 929 base::RunLoop().RunUntilIdle(); |
| 930 | 930 |
| 931 EXPECT_EQ(HTTP_SUCCESS, error); | 931 EXPECT_EQ(HTTP_SUCCESS, error); |
| 932 // Resource "2_file_resource_id" should be gone now. | 932 // Resource "2_file_resource_id" should be gone now. |
| 933 EXPECT_FALSE(Exists("2_file_resource_id")); | 933 EXPECT_FALSE(Exists("2_file_resource_id")); |
| 934 | 934 |
| 935 error = GDATA_OTHER_ERROR; | 935 error = DRIVE_OTHER_ERROR; |
| 936 fake_service_.TrashResource("2_file_resource_id", | 936 fake_service_.TrashResource("2_file_resource_id", |
| 937 test_util::CreateCopyResultCallback(&error)); | 937 test_util::CreateCopyResultCallback(&error)); |
| 938 base::RunLoop().RunUntilIdle(); | 938 base::RunLoop().RunUntilIdle(); |
| 939 EXPECT_EQ(HTTP_NOT_FOUND, error); | 939 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 940 EXPECT_FALSE(Exists("2_file_resource_id")); | 940 EXPECT_FALSE(Exists("2_file_resource_id")); |
| 941 } | 941 } |
| 942 | 942 |
| 943 TEST_F(FakeDriveServiceTest, TrashResource_NonexistingFile) { | 943 TEST_F(FakeDriveServiceTest, TrashResource_NonexistingFile) { |
| 944 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 944 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 945 | 945 |
| 946 GDataErrorCode error = GDATA_OTHER_ERROR; | 946 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 947 fake_service_.TrashResource("nonexisting_resource_id", | 947 fake_service_.TrashResource("nonexisting_resource_id", |
| 948 test_util::CreateCopyResultCallback(&error)); | 948 test_util::CreateCopyResultCallback(&error)); |
| 949 base::RunLoop().RunUntilIdle(); | 949 base::RunLoop().RunUntilIdle(); |
| 950 | 950 |
| 951 EXPECT_EQ(HTTP_NOT_FOUND, error); | 951 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 952 } | 952 } |
| 953 | 953 |
| 954 TEST_F(FakeDriveServiceTest, TrashResource_Offline) { | 954 TEST_F(FakeDriveServiceTest, TrashResource_Offline) { |
| 955 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 955 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 956 fake_service_.set_offline(true); | 956 fake_service_.set_offline(true); |
| 957 | 957 |
| 958 GDataErrorCode error = GDATA_OTHER_ERROR; | 958 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 959 fake_service_.TrashResource("2_file_resource_id", | 959 fake_service_.TrashResource("2_file_resource_id", |
| 960 test_util::CreateCopyResultCallback(&error)); | 960 test_util::CreateCopyResultCallback(&error)); |
| 961 base::RunLoop().RunUntilIdle(); | 961 base::RunLoop().RunUntilIdle(); |
| 962 | 962 |
| 963 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 963 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 964 } | 964 } |
| 965 | 965 |
| 966 TEST_F(FakeDriveServiceTest, TrashResource_Forbidden) { | 966 TEST_F(FakeDriveServiceTest, TrashResource_Forbidden) { |
| 967 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 967 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 968 | 968 |
| 969 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( | 969 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( |
| 970 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); | 970 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); |
| 971 | 971 |
| 972 GDataErrorCode error = GDATA_OTHER_ERROR; | 972 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 973 fake_service_.TrashResource("2_file_resource_id", | 973 fake_service_.TrashResource("2_file_resource_id", |
| 974 test_util::CreateCopyResultCallback(&error)); | 974 test_util::CreateCopyResultCallback(&error)); |
| 975 base::RunLoop().RunUntilIdle(); | 975 base::RunLoop().RunUntilIdle(); |
| 976 | 976 |
| 977 EXPECT_EQ(HTTP_FORBIDDEN, error); | 977 EXPECT_EQ(HTTP_FORBIDDEN, error); |
| 978 } | 978 } |
| 979 | 979 |
| 980 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { | 980 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { |
| 981 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 981 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 982 | 982 |
| 983 base::ScopedTempDir temp_dir; | 983 base::ScopedTempDir temp_dir; |
| 984 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 984 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 985 | 985 |
| 986 std::vector<test_util::ProgressInfo> download_progress_values; | 986 std::vector<test_util::ProgressInfo> download_progress_values; |
| 987 | 987 |
| 988 const base::FilePath kOutputFilePath = | 988 const base::FilePath kOutputFilePath = |
| 989 temp_dir.path().AppendASCII("whatever.txt"); | 989 temp_dir.path().AppendASCII("whatever.txt"); |
| 990 GDataErrorCode error = GDATA_OTHER_ERROR; | 990 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 991 base::FilePath output_file_path; | 991 base::FilePath output_file_path; |
| 992 test_util::TestGetContentCallback get_content_callback; | 992 test_util::TestGetContentCallback get_content_callback; |
| 993 fake_service_.DownloadFile( | 993 fake_service_.DownloadFile( |
| 994 kOutputFilePath, | 994 kOutputFilePath, |
| 995 "2_file_resource_id", | 995 "2_file_resource_id", |
| 996 test_util::CreateCopyResultCallback(&error, &output_file_path), | 996 test_util::CreateCopyResultCallback(&error, &output_file_path), |
| 997 get_content_callback.callback(), | 997 get_content_callback.callback(), |
| 998 base::Bind(&test_util::AppendProgressCallbackResult, | 998 base::Bind(&test_util::AppendProgressCallbackResult, |
| 999 &download_progress_values)); | 999 &download_progress_values)); |
| 1000 base::RunLoop().RunUntilIdle(); | 1000 base::RunLoop().RunUntilIdle(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) { | 1014 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) { |
| 1015 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1015 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1016 | 1016 |
| 1017 base::ScopedTempDir temp_dir; | 1017 base::ScopedTempDir temp_dir; |
| 1018 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1018 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1019 | 1019 |
| 1020 const base::FilePath kOutputFilePath = | 1020 const base::FilePath kOutputFilePath = |
| 1021 temp_dir.path().AppendASCII("whatever.txt"); | 1021 temp_dir.path().AppendASCII("whatever.txt"); |
| 1022 GDataErrorCode error = GDATA_OTHER_ERROR; | 1022 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1023 base::FilePath output_file_path; | 1023 base::FilePath output_file_path; |
| 1024 fake_service_.DownloadFile( | 1024 fake_service_.DownloadFile( |
| 1025 kOutputFilePath, | 1025 kOutputFilePath, |
| 1026 "non_existent_file_resource_id", | 1026 "non_existent_file_resource_id", |
| 1027 test_util::CreateCopyResultCallback(&error, &output_file_path), | 1027 test_util::CreateCopyResultCallback(&error, &output_file_path), |
| 1028 GetContentCallback(), | 1028 GetContentCallback(), |
| 1029 ProgressCallback()); | 1029 ProgressCallback()); |
| 1030 base::RunLoop().RunUntilIdle(); | 1030 base::RunLoop().RunUntilIdle(); |
| 1031 | 1031 |
| 1032 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1032 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) { | 1035 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) { |
| 1036 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1036 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1037 fake_service_.set_offline(true); | 1037 fake_service_.set_offline(true); |
| 1038 | 1038 |
| 1039 base::ScopedTempDir temp_dir; | 1039 base::ScopedTempDir temp_dir; |
| 1040 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1040 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1041 | 1041 |
| 1042 const base::FilePath kOutputFilePath = | 1042 const base::FilePath kOutputFilePath = |
| 1043 temp_dir.path().AppendASCII("whatever.txt"); | 1043 temp_dir.path().AppendASCII("whatever.txt"); |
| 1044 GDataErrorCode error = GDATA_OTHER_ERROR; | 1044 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1045 base::FilePath output_file_path; | 1045 base::FilePath output_file_path; |
| 1046 fake_service_.DownloadFile( | 1046 fake_service_.DownloadFile( |
| 1047 kOutputFilePath, | 1047 kOutputFilePath, |
| 1048 "2_file_resource_id", | 1048 "2_file_resource_id", |
| 1049 test_util::CreateCopyResultCallback(&error, &output_file_path), | 1049 test_util::CreateCopyResultCallback(&error, &output_file_path), |
| 1050 GetContentCallback(), | 1050 GetContentCallback(), |
| 1051 ProgressCallback()); | 1051 ProgressCallback()); |
| 1052 base::RunLoop().RunUntilIdle(); | 1052 base::RunLoop().RunUntilIdle(); |
| 1053 | 1053 |
| 1054 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1054 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 TEST_F(FakeDriveServiceTest, CopyResource) { | 1057 TEST_F(FakeDriveServiceTest, CopyResource) { |
| 1058 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 1058 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 1059 | 1059 |
| 1060 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1060 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1061 | 1061 |
| 1062 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1062 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1063 | 1063 |
| 1064 const std::string kResourceId = "2_file_resource_id"; | 1064 const std::string kResourceId = "2_file_resource_id"; |
| 1065 const std::string kParentResourceId = "2_folder_resource_id"; | 1065 const std::string kParentResourceId = "2_folder_resource_id"; |
| 1066 GDataErrorCode error = GDATA_OTHER_ERROR; | 1066 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1067 scoped_ptr<FileResource> entry; | 1067 scoped_ptr<FileResource> entry; |
| 1068 fake_service_.CopyResource( | 1068 fake_service_.CopyResource( |
| 1069 kResourceId, | 1069 kResourceId, |
| 1070 kParentResourceId, | 1070 kParentResourceId, |
| 1071 "new title", | 1071 "new title", |
| 1072 base::Time::FromUTCExploded(kModifiedDate), | 1072 base::Time::FromUTCExploded(kModifiedDate), |
| 1073 test_util::CreateCopyResultCallback(&error, &entry)); | 1073 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1074 base::RunLoop().RunUntilIdle(); | 1074 base::RunLoop().RunUntilIdle(); |
| 1075 | 1075 |
| 1076 EXPECT_EQ(HTTP_SUCCESS, error); | 1076 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1077 ASSERT_TRUE(entry); | 1077 ASSERT_TRUE(entry); |
| 1078 // The copied entry should have the new resource ID and the title. | 1078 // The copied entry should have the new resource ID and the title. |
| 1079 EXPECT_NE(kResourceId, entry->file_id()); | 1079 EXPECT_NE(kResourceId, entry->file_id()); |
| 1080 EXPECT_EQ("new title", entry->title()); | 1080 EXPECT_EQ("new title", entry->title()); |
| 1081 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate), entry->modified_date()); | 1081 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate), entry->modified_date()); |
| 1082 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); | 1082 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); |
| 1083 // Should be incremented as a new hosted document was created. | 1083 // Should be incremented as a new hosted document was created. |
| 1084 EXPECT_EQ(old_largest_change_id + 1, | 1084 EXPECT_EQ(old_largest_change_id + 1, |
| 1085 fake_service_.about_resource().largest_change_id()); | 1085 fake_service_.about_resource().largest_change_id()); |
| 1086 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1086 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 TEST_F(FakeDriveServiceTest, CopyResource_NonExisting) { | 1089 TEST_F(FakeDriveServiceTest, CopyResource_NonExisting) { |
| 1090 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1090 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1091 | 1091 |
| 1092 const std::string kResourceId = "nonexisting_resource_id"; | 1092 const std::string kResourceId = "nonexisting_resource_id"; |
| 1093 GDataErrorCode error = GDATA_OTHER_ERROR; | 1093 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1094 scoped_ptr<FileResource> entry; | 1094 scoped_ptr<FileResource> entry; |
| 1095 fake_service_.CopyResource( | 1095 fake_service_.CopyResource( |
| 1096 kResourceId, | 1096 kResourceId, |
| 1097 "1_folder_resource_id", | 1097 "1_folder_resource_id", |
| 1098 "new title", | 1098 "new title", |
| 1099 base::Time(), | 1099 base::Time(), |
| 1100 test_util::CreateCopyResultCallback(&error, &entry)); | 1100 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1101 base::RunLoop().RunUntilIdle(); | 1101 base::RunLoop().RunUntilIdle(); |
| 1102 | 1102 |
| 1103 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1103 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) { | 1106 TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) { |
| 1107 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1107 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1108 | 1108 |
| 1109 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1109 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1110 | 1110 |
| 1111 const std::string kResourceId = "2_file_resource_id"; | 1111 const std::string kResourceId = "2_file_resource_id"; |
| 1112 GDataErrorCode error = GDATA_OTHER_ERROR; | 1112 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1113 scoped_ptr<FileResource> entry; | 1113 scoped_ptr<FileResource> entry; |
| 1114 fake_service_.CopyResource( | 1114 fake_service_.CopyResource( |
| 1115 kResourceId, | 1115 kResourceId, |
| 1116 std::string(), | 1116 std::string(), |
| 1117 "new title", | 1117 "new title", |
| 1118 base::Time(), | 1118 base::Time(), |
| 1119 test_util::CreateCopyResultCallback(&error, &entry)); | 1119 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1120 base::RunLoop().RunUntilIdle(); | 1120 base::RunLoop().RunUntilIdle(); |
| 1121 | 1121 |
| 1122 EXPECT_EQ(HTTP_SUCCESS, error); | 1122 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1123 ASSERT_TRUE(entry); | 1123 ASSERT_TRUE(entry); |
| 1124 // The copied entry should have the new resource ID and the title. | 1124 // The copied entry should have the new resource ID and the title. |
| 1125 EXPECT_NE(kResourceId, entry->file_id()); | 1125 EXPECT_NE(kResourceId, entry->file_id()); |
| 1126 EXPECT_EQ("new title", entry->title()); | 1126 EXPECT_EQ("new title", entry->title()); |
| 1127 EXPECT_TRUE(HasParent(kResourceId, fake_service_.GetRootResourceId())); | 1127 EXPECT_TRUE(HasParent(kResourceId, fake_service_.GetRootResourceId())); |
| 1128 // Should be incremented as a new hosted document was created. | 1128 // Should be incremented as a new hosted document was created. |
| 1129 EXPECT_EQ(old_largest_change_id + 1, | 1129 EXPECT_EQ(old_largest_change_id + 1, |
| 1130 fake_service_.about_resource().largest_change_id()); | 1130 fake_service_.about_resource().largest_change_id()); |
| 1131 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1131 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 TEST_F(FakeDriveServiceTest, CopyResource_Offline) { | 1134 TEST_F(FakeDriveServiceTest, CopyResource_Offline) { |
| 1135 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1135 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1136 fake_service_.set_offline(true); | 1136 fake_service_.set_offline(true); |
| 1137 | 1137 |
| 1138 const std::string kResourceId = "2_file_resource_id"; | 1138 const std::string kResourceId = "2_file_resource_id"; |
| 1139 GDataErrorCode error = GDATA_OTHER_ERROR; | 1139 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1140 scoped_ptr<FileResource> entry; | 1140 scoped_ptr<FileResource> entry; |
| 1141 fake_service_.CopyResource( | 1141 fake_service_.CopyResource( |
| 1142 kResourceId, | 1142 kResourceId, |
| 1143 "1_folder_resource_id", | 1143 "1_folder_resource_id", |
| 1144 "new title", | 1144 "new title", |
| 1145 base::Time(), | 1145 base::Time(), |
| 1146 test_util::CreateCopyResultCallback(&error, &entry)); | 1146 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1147 base::RunLoop().RunUntilIdle(); | 1147 base::RunLoop().RunUntilIdle(); |
| 1148 | 1148 |
| 1149 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1149 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1150 EXPECT_FALSE(entry); | 1150 EXPECT_FALSE(entry); |
| 1151 } | 1151 } |
| 1152 | 1152 |
| 1153 TEST_F(FakeDriveServiceTest, UpdateResource) { | 1153 TEST_F(FakeDriveServiceTest, UpdateResource) { |
| 1154 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 1154 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
| 1155 const base::Time::Exploded kViewedDate = {2013, 8, 1, 20, 16, 00, 14, 234}; | 1155 const base::Time::Exploded kViewedDate = {2013, 8, 1, 20, 16, 00, 14, 234}; |
| 1156 | 1156 |
| 1157 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1157 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1158 | 1158 |
| 1159 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1159 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1160 | 1160 |
| 1161 const std::string kResourceId = "2_file_resource_id"; | 1161 const std::string kResourceId = "2_file_resource_id"; |
| 1162 const std::string kParentResourceId = "2_folder_resource_id"; | 1162 const std::string kParentResourceId = "2_folder_resource_id"; |
| 1163 GDataErrorCode error = GDATA_OTHER_ERROR; | 1163 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1164 scoped_ptr<FileResource> entry; | 1164 scoped_ptr<FileResource> entry; |
| 1165 fake_service_.UpdateResource( | 1165 fake_service_.UpdateResource( |
| 1166 kResourceId, | 1166 kResourceId, |
| 1167 kParentResourceId, | 1167 kParentResourceId, |
| 1168 "new title", | 1168 "new title", |
| 1169 base::Time::FromUTCExploded(kModifiedDate), | 1169 base::Time::FromUTCExploded(kModifiedDate), |
| 1170 base::Time::FromUTCExploded(kViewedDate), | 1170 base::Time::FromUTCExploded(kViewedDate), |
| 1171 test_util::CreateCopyResultCallback(&error, &entry)); | 1171 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1172 base::RunLoop().RunUntilIdle(); | 1172 base::RunLoop().RunUntilIdle(); |
| 1173 | 1173 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1184 // Should be incremented as a new hosted document was created. | 1184 // Should be incremented as a new hosted document was created. |
| 1185 EXPECT_EQ(old_largest_change_id + 1, | 1185 EXPECT_EQ(old_largest_change_id + 1, |
| 1186 fake_service_.about_resource().largest_change_id()); | 1186 fake_service_.about_resource().largest_change_id()); |
| 1187 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1187 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 TEST_F(FakeDriveServiceTest, UpdateResource_NonExisting) { | 1190 TEST_F(FakeDriveServiceTest, UpdateResource_NonExisting) { |
| 1191 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1191 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1192 | 1192 |
| 1193 const std::string kResourceId = "nonexisting_resource_id"; | 1193 const std::string kResourceId = "nonexisting_resource_id"; |
| 1194 GDataErrorCode error = GDATA_OTHER_ERROR; | 1194 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1195 scoped_ptr<FileResource> entry; | 1195 scoped_ptr<FileResource> entry; |
| 1196 fake_service_.UpdateResource( | 1196 fake_service_.UpdateResource( |
| 1197 kResourceId, | 1197 kResourceId, |
| 1198 "1_folder_resource_id", | 1198 "1_folder_resource_id", |
| 1199 "new title", | 1199 "new title", |
| 1200 base::Time(), | 1200 base::Time(), |
| 1201 base::Time(), | 1201 base::Time(), |
| 1202 test_util::CreateCopyResultCallback(&error, &entry)); | 1202 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1203 base::RunLoop().RunUntilIdle(); | 1203 base::RunLoop().RunUntilIdle(); |
| 1204 | 1204 |
| 1205 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1205 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1206 } | 1206 } |
| 1207 | 1207 |
| 1208 TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) { | 1208 TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) { |
| 1209 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1209 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1210 | 1210 |
| 1211 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1211 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1212 | 1212 |
| 1213 const std::string kResourceId = "2_file_resource_id"; | 1213 const std::string kResourceId = "2_file_resource_id"; |
| 1214 | 1214 |
| 1215 // Just make sure that the resource is under root. | 1215 // Just make sure that the resource is under root. |
| 1216 ASSERT_TRUE(HasParent(kResourceId, "fake_root")); | 1216 ASSERT_TRUE(HasParent(kResourceId, "fake_root")); |
| 1217 | 1217 |
| 1218 GDataErrorCode error = GDATA_OTHER_ERROR; | 1218 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1219 scoped_ptr<FileResource> entry; | 1219 scoped_ptr<FileResource> entry; |
| 1220 fake_service_.UpdateResource( | 1220 fake_service_.UpdateResource( |
| 1221 kResourceId, | 1221 kResourceId, |
| 1222 std::string(), | 1222 std::string(), |
| 1223 "new title", | 1223 "new title", |
| 1224 base::Time(), | 1224 base::Time(), |
| 1225 base::Time(), | 1225 base::Time(), |
| 1226 test_util::CreateCopyResultCallback(&error, &entry)); | 1226 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1227 base::RunLoop().RunUntilIdle(); | 1227 base::RunLoop().RunUntilIdle(); |
| 1228 | 1228 |
| 1229 EXPECT_EQ(HTTP_SUCCESS, error); | 1229 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1230 ASSERT_TRUE(entry); | 1230 ASSERT_TRUE(entry); |
| 1231 // The updated entry should have the new title. | 1231 // The updated entry should have the new title. |
| 1232 EXPECT_EQ(kResourceId, entry->file_id()); | 1232 EXPECT_EQ(kResourceId, entry->file_id()); |
| 1233 EXPECT_EQ("new title", entry->title()); | 1233 EXPECT_EQ("new title", entry->title()); |
| 1234 EXPECT_TRUE(HasParent(kResourceId, "fake_root")); | 1234 EXPECT_TRUE(HasParent(kResourceId, "fake_root")); |
| 1235 // Should be incremented as a new hosted document was created. | 1235 // Should be incremented as a new hosted document was created. |
| 1236 EXPECT_EQ(old_largest_change_id + 1, | 1236 EXPECT_EQ(old_largest_change_id + 1, |
| 1237 fake_service_.about_resource().largest_change_id()); | 1237 fake_service_.about_resource().largest_change_id()); |
| 1238 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1238 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 TEST_F(FakeDriveServiceTest, UpdateResource_Offline) { | 1241 TEST_F(FakeDriveServiceTest, UpdateResource_Offline) { |
| 1242 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1242 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1243 fake_service_.set_offline(true); | 1243 fake_service_.set_offline(true); |
| 1244 | 1244 |
| 1245 const std::string kResourceId = "2_file_resource_id"; | 1245 const std::string kResourceId = "2_file_resource_id"; |
| 1246 GDataErrorCode error = GDATA_OTHER_ERROR; | 1246 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1247 scoped_ptr<FileResource> entry; | 1247 scoped_ptr<FileResource> entry; |
| 1248 fake_service_.UpdateResource( | 1248 fake_service_.UpdateResource( |
| 1249 kResourceId, | 1249 kResourceId, |
| 1250 std::string(), | 1250 std::string(), |
| 1251 "new title", | 1251 "new title", |
| 1252 base::Time(), | 1252 base::Time(), |
| 1253 base::Time(), | 1253 base::Time(), |
| 1254 test_util::CreateCopyResultCallback(&error, &entry)); | 1254 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1255 base::RunLoop().RunUntilIdle(); | 1255 base::RunLoop().RunUntilIdle(); |
| 1256 | 1256 |
| 1257 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1257 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1258 EXPECT_FALSE(entry); | 1258 EXPECT_FALSE(entry); |
| 1259 } | 1259 } |
| 1260 | 1260 |
| 1261 TEST_F(FakeDriveServiceTest, UpdateResource_Forbidden) { | 1261 TEST_F(FakeDriveServiceTest, UpdateResource_Forbidden) { |
| 1262 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1262 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1263 | 1263 |
| 1264 const std::string kResourceId = "2_file_resource_id"; | 1264 const std::string kResourceId = "2_file_resource_id"; |
| 1265 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( | 1265 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( |
| 1266 kResourceId, google_apis::drive::PERMISSION_ROLE_READER)); | 1266 kResourceId, google_apis::drive::PERMISSION_ROLE_READER)); |
| 1267 | 1267 |
| 1268 GDataErrorCode error = GDATA_OTHER_ERROR; | 1268 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1269 scoped_ptr<FileResource> entry; | 1269 scoped_ptr<FileResource> entry; |
| 1270 fake_service_.UpdateResource( | 1270 fake_service_.UpdateResource( |
| 1271 kResourceId, | 1271 kResourceId, |
| 1272 std::string(), | 1272 std::string(), |
| 1273 "new title", | 1273 "new title", |
| 1274 base::Time(), | 1274 base::Time(), |
| 1275 base::Time(), | 1275 base::Time(), |
| 1276 test_util::CreateCopyResultCallback(&error, &entry)); | 1276 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1277 base::RunLoop().RunUntilIdle(); | 1277 base::RunLoop().RunUntilIdle(); |
| 1278 | 1278 |
| 1279 EXPECT_EQ(HTTP_FORBIDDEN, error); | 1279 EXPECT_EQ(HTTP_FORBIDDEN, error); |
| 1280 EXPECT_FALSE(entry); | 1280 EXPECT_FALSE(entry); |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { | 1283 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { |
| 1284 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1284 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1285 | 1285 |
| 1286 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1286 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1287 | 1287 |
| 1288 const std::string kResourceId = "2_file_resource_id"; | 1288 const std::string kResourceId = "2_file_resource_id"; |
| 1289 const std::string kOldParentResourceId = fake_service_.GetRootResourceId(); | 1289 const std::string kOldParentResourceId = fake_service_.GetRootResourceId(); |
| 1290 const std::string kNewParentResourceId = "1_folder_resource_id"; | 1290 const std::string kNewParentResourceId = "1_folder_resource_id"; |
| 1291 | 1291 |
| 1292 // Here's the original parent link. | 1292 // Here's the original parent link. |
| 1293 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1293 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
| 1294 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); | 1294 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); |
| 1295 | 1295 |
| 1296 GDataErrorCode error = GDATA_OTHER_ERROR; | 1296 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1297 fake_service_.AddResourceToDirectory( | 1297 fake_service_.AddResourceToDirectory( |
| 1298 kNewParentResourceId, | 1298 kNewParentResourceId, |
| 1299 kResourceId, | 1299 kResourceId, |
| 1300 test_util::CreateCopyResultCallback(&error)); | 1300 test_util::CreateCopyResultCallback(&error)); |
| 1301 base::RunLoop().RunUntilIdle(); | 1301 base::RunLoop().RunUntilIdle(); |
| 1302 | 1302 |
| 1303 EXPECT_EQ(HTTP_SUCCESS, error); | 1303 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1304 | 1304 |
| 1305 // The parent link should now be changed. | 1305 // The parent link should now be changed. |
| 1306 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1306 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1317 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1317 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1318 | 1318 |
| 1319 const std::string kResourceId = "subdirectory_file_1_id"; | 1319 const std::string kResourceId = "subdirectory_file_1_id"; |
| 1320 const std::string kOldParentResourceId = "1_folder_resource_id"; | 1320 const std::string kOldParentResourceId = "1_folder_resource_id"; |
| 1321 const std::string kNewParentResourceId = "2_folder_resource_id"; | 1321 const std::string kNewParentResourceId = "2_folder_resource_id"; |
| 1322 | 1322 |
| 1323 // Here's the original parent link. | 1323 // Here's the original parent link. |
| 1324 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1324 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
| 1325 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); | 1325 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); |
| 1326 | 1326 |
| 1327 GDataErrorCode error = GDATA_OTHER_ERROR; | 1327 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1328 fake_service_.AddResourceToDirectory( | 1328 fake_service_.AddResourceToDirectory( |
| 1329 kNewParentResourceId, | 1329 kNewParentResourceId, |
| 1330 kResourceId, | 1330 kResourceId, |
| 1331 test_util::CreateCopyResultCallback(&error)); | 1331 test_util::CreateCopyResultCallback(&error)); |
| 1332 base::RunLoop().RunUntilIdle(); | 1332 base::RunLoop().RunUntilIdle(); |
| 1333 | 1333 |
| 1334 EXPECT_EQ(HTTP_SUCCESS, error); | 1334 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1335 | 1335 |
| 1336 // The parent link should now be changed. | 1336 // The parent link should now be changed. |
| 1337 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); | 1337 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId)); |
| 1338 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); | 1338 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); |
| 1339 // Should be incremented as a file was moved. | 1339 // Should be incremented as a file was moved. |
| 1340 EXPECT_EQ(old_largest_change_id + 1, | 1340 EXPECT_EQ(old_largest_change_id + 1, |
| 1341 fake_service_.about_resource().largest_change_id()); | 1341 fake_service_.about_resource().largest_change_id()); |
| 1342 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1342 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1343 } | 1343 } |
| 1344 | 1344 |
| 1345 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_NonexistingFile) { | 1345 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_NonexistingFile) { |
| 1346 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1346 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1347 | 1347 |
| 1348 const std::string kResourceId = "nonexisting_file"; | 1348 const std::string kResourceId = "nonexisting_file"; |
| 1349 const std::string kNewParentResourceId = "1_folder_resource_id"; | 1349 const std::string kNewParentResourceId = "1_folder_resource_id"; |
| 1350 | 1350 |
| 1351 GDataErrorCode error = GDATA_OTHER_ERROR; | 1351 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1352 fake_service_.AddResourceToDirectory( | 1352 fake_service_.AddResourceToDirectory( |
| 1353 kNewParentResourceId, | 1353 kNewParentResourceId, |
| 1354 kResourceId, | 1354 kResourceId, |
| 1355 test_util::CreateCopyResultCallback(&error)); | 1355 test_util::CreateCopyResultCallback(&error)); |
| 1356 base::RunLoop().RunUntilIdle(); | 1356 base::RunLoop().RunUntilIdle(); |
| 1357 | 1357 |
| 1358 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1358 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_OrphanFile) { | 1361 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_OrphanFile) { |
| 1362 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1362 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1363 | 1363 |
| 1364 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1364 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1365 | 1365 |
| 1366 const std::string kResourceId = "1_orphanfile_resource_id"; | 1366 const std::string kResourceId = "1_orphanfile_resource_id"; |
| 1367 const std::string kNewParentResourceId = "1_folder_resource_id"; | 1367 const std::string kNewParentResourceId = "1_folder_resource_id"; |
| 1368 | 1368 |
| 1369 // The file does not belong to any directory, even to the root. | 1369 // The file does not belong to any directory, even to the root. |
| 1370 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); | 1370 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId)); |
| 1371 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); | 1371 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); |
| 1372 | 1372 |
| 1373 GDataErrorCode error = GDATA_OTHER_ERROR; | 1373 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1374 fake_service_.AddResourceToDirectory( | 1374 fake_service_.AddResourceToDirectory( |
| 1375 kNewParentResourceId, | 1375 kNewParentResourceId, |
| 1376 kResourceId, | 1376 kResourceId, |
| 1377 test_util::CreateCopyResultCallback(&error)); | 1377 test_util::CreateCopyResultCallback(&error)); |
| 1378 base::RunLoop().RunUntilIdle(); | 1378 base::RunLoop().RunUntilIdle(); |
| 1379 | 1379 |
| 1380 EXPECT_EQ(HTTP_SUCCESS, error); | 1380 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1381 | 1381 |
| 1382 // The parent link should now be changed. | 1382 // The parent link should now be changed. |
| 1383 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); | 1383 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId)); |
| 1384 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); | 1384 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId())); |
| 1385 // Should be incremented as a file was moved. | 1385 // Should be incremented as a file was moved. |
| 1386 EXPECT_EQ(old_largest_change_id + 1, | 1386 EXPECT_EQ(old_largest_change_id + 1, |
| 1387 fake_service_.about_resource().largest_change_id()); | 1387 fake_service_.about_resource().largest_change_id()); |
| 1388 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1388 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_Offline) { | 1391 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_Offline) { |
| 1392 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1392 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1393 fake_service_.set_offline(true); | 1393 fake_service_.set_offline(true); |
| 1394 | 1394 |
| 1395 const std::string kResourceId = "2_file_resource_id"; | 1395 const std::string kResourceId = "2_file_resource_id"; |
| 1396 const std::string kNewParentResourceId = "1_folder_resource_id"; | 1396 const std::string kNewParentResourceId = "1_folder_resource_id"; |
| 1397 | 1397 |
| 1398 GDataErrorCode error = GDATA_OTHER_ERROR; | 1398 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1399 fake_service_.AddResourceToDirectory( | 1399 fake_service_.AddResourceToDirectory( |
| 1400 kNewParentResourceId, | 1400 kNewParentResourceId, |
| 1401 kResourceId, | 1401 kResourceId, |
| 1402 test_util::CreateCopyResultCallback(&error)); | 1402 test_util::CreateCopyResultCallback(&error)); |
| 1403 base::RunLoop().RunUntilIdle(); | 1403 base::RunLoop().RunUntilIdle(); |
| 1404 | 1404 |
| 1405 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1405 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1406 } | 1406 } |
| 1407 | 1407 |
| 1408 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { | 1408 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) { |
| 1409 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1409 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1410 | 1410 |
| 1411 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1411 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1412 | 1412 |
| 1413 const std::string kResourceId = "subdirectory_file_1_id"; | 1413 const std::string kResourceId = "subdirectory_file_1_id"; |
| 1414 const std::string kParentResourceId = "1_folder_resource_id"; | 1414 const std::string kParentResourceId = "1_folder_resource_id"; |
| 1415 | 1415 |
| 1416 scoped_ptr<FileResource> entry = FindEntry(kResourceId); | 1416 scoped_ptr<FileResource> entry = FindEntry(kResourceId); |
| 1417 ASSERT_TRUE(entry); | 1417 ASSERT_TRUE(entry); |
| 1418 // The entry should have a parent now. | 1418 // The entry should have a parent now. |
| 1419 ASSERT_FALSE(entry->parents().empty()); | 1419 ASSERT_FALSE(entry->parents().empty()); |
| 1420 | 1420 |
| 1421 GDataErrorCode error = GDATA_OTHER_ERROR; | 1421 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1422 fake_service_.RemoveResourceFromDirectory( | 1422 fake_service_.RemoveResourceFromDirectory( |
| 1423 kParentResourceId, | 1423 kParentResourceId, |
| 1424 kResourceId, | 1424 kResourceId, |
| 1425 test_util::CreateCopyResultCallback(&error)); | 1425 test_util::CreateCopyResultCallback(&error)); |
| 1426 base::RunLoop().RunUntilIdle(); | 1426 base::RunLoop().RunUntilIdle(); |
| 1427 | 1427 |
| 1428 EXPECT_EQ(HTTP_NO_CONTENT, error); | 1428 EXPECT_EQ(HTTP_NO_CONTENT, error); |
| 1429 | 1429 |
| 1430 entry = FindEntry(kResourceId); | 1430 entry = FindEntry(kResourceId); |
| 1431 ASSERT_TRUE(entry); | 1431 ASSERT_TRUE(entry); |
| 1432 // The entry should have no parent now. | 1432 // The entry should have no parent now. |
| 1433 ASSERT_TRUE(entry->parents().empty()); | 1433 ASSERT_TRUE(entry->parents().empty()); |
| 1434 // Should be incremented as a file was moved to the root directory. | 1434 // Should be incremented as a file was moved to the root directory. |
| 1435 EXPECT_EQ(old_largest_change_id + 1, | 1435 EXPECT_EQ(old_largest_change_id + 1, |
| 1436 fake_service_.about_resource().largest_change_id()); | 1436 fake_service_.about_resource().largest_change_id()); |
| 1437 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1437 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1438 } | 1438 } |
| 1439 | 1439 |
| 1440 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_NonexistingFile) { | 1440 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_NonexistingFile) { |
| 1441 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1441 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1442 | 1442 |
| 1443 const std::string kResourceId = "nonexisting_file"; | 1443 const std::string kResourceId = "nonexisting_file"; |
| 1444 const std::string kParentResourceId = "1_folder_resource_id"; | 1444 const std::string kParentResourceId = "1_folder_resource_id"; |
| 1445 | 1445 |
| 1446 GDataErrorCode error = GDATA_OTHER_ERROR; | 1446 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1447 fake_service_.RemoveResourceFromDirectory( | 1447 fake_service_.RemoveResourceFromDirectory( |
| 1448 kParentResourceId, | 1448 kParentResourceId, |
| 1449 kResourceId, | 1449 kResourceId, |
| 1450 test_util::CreateCopyResultCallback(&error)); | 1450 test_util::CreateCopyResultCallback(&error)); |
| 1451 base::RunLoop().RunUntilIdle(); | 1451 base::RunLoop().RunUntilIdle(); |
| 1452 | 1452 |
| 1453 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1453 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1454 } | 1454 } |
| 1455 | 1455 |
| 1456 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_OrphanFile) { | 1456 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_OrphanFile) { |
| 1457 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1457 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1458 | 1458 |
| 1459 const std::string kResourceId = "1_orphanfile_resource_id"; | 1459 const std::string kResourceId = "1_orphanfile_resource_id"; |
| 1460 const std::string kParentResourceId = fake_service_.GetRootResourceId(); | 1460 const std::string kParentResourceId = fake_service_.GetRootResourceId(); |
| 1461 | 1461 |
| 1462 GDataErrorCode error = GDATA_OTHER_ERROR; | 1462 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1463 fake_service_.RemoveResourceFromDirectory( | 1463 fake_service_.RemoveResourceFromDirectory( |
| 1464 kParentResourceId, | 1464 kParentResourceId, |
| 1465 kResourceId, | 1465 kResourceId, |
| 1466 test_util::CreateCopyResultCallback(&error)); | 1466 test_util::CreateCopyResultCallback(&error)); |
| 1467 base::RunLoop().RunUntilIdle(); | 1467 base::RunLoop().RunUntilIdle(); |
| 1468 | 1468 |
| 1469 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1469 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_Offline) { | 1472 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_Offline) { |
| 1473 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1473 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1474 fake_service_.set_offline(true); | 1474 fake_service_.set_offline(true); |
| 1475 | 1475 |
| 1476 const std::string kResourceId = "subdirectory_file_1_id"; | 1476 const std::string kResourceId = "subdirectory_file_1_id"; |
| 1477 const std::string kParentResourceId = "1_folder_resource_id"; | 1477 const std::string kParentResourceId = "1_folder_resource_id"; |
| 1478 | 1478 |
| 1479 GDataErrorCode error = GDATA_OTHER_ERROR; | 1479 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1480 fake_service_.RemoveResourceFromDirectory( | 1480 fake_service_.RemoveResourceFromDirectory( |
| 1481 kParentResourceId, | 1481 kParentResourceId, |
| 1482 kResourceId, | 1482 kResourceId, |
| 1483 test_util::CreateCopyResultCallback(&error)); | 1483 test_util::CreateCopyResultCallback(&error)); |
| 1484 base::RunLoop().RunUntilIdle(); | 1484 base::RunLoop().RunUntilIdle(); |
| 1485 | 1485 |
| 1486 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1486 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1487 } | 1487 } |
| 1488 | 1488 |
| 1489 TEST_F(FakeDriveServiceTest, AddNewDirectory_EmptyParent) { | 1489 TEST_F(FakeDriveServiceTest, AddNewDirectory_EmptyParent) { |
| 1490 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1490 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1491 | 1491 |
| 1492 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1492 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1493 | 1493 |
| 1494 GDataErrorCode error = GDATA_OTHER_ERROR; | 1494 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1495 scoped_ptr<FileResource> entry; | 1495 scoped_ptr<FileResource> entry; |
| 1496 fake_service_.AddNewDirectory( | 1496 fake_service_.AddNewDirectory( |
| 1497 std::string(), | 1497 std::string(), |
| 1498 "new directory", | 1498 "new directory", |
| 1499 DriveServiceInterface::AddNewDirectoryOptions(), | 1499 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1500 test_util::CreateCopyResultCallback(&error, &entry)); | 1500 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1501 base::RunLoop().RunUntilIdle(); | 1501 base::RunLoop().RunUntilIdle(); |
| 1502 | 1502 |
| 1503 EXPECT_EQ(HTTP_CREATED, error); | 1503 EXPECT_EQ(HTTP_CREATED, error); |
| 1504 ASSERT_TRUE(entry); | 1504 ASSERT_TRUE(entry); |
| 1505 EXPECT_TRUE(entry->IsDirectory()); | 1505 EXPECT_TRUE(entry->IsDirectory()); |
| 1506 EXPECT_EQ("resource_id_1", entry->file_id()); | 1506 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1507 EXPECT_EQ("new directory", entry->title()); | 1507 EXPECT_EQ("new directory", entry->title()); |
| 1508 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); | 1508 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); |
| 1509 // Should be incremented as a new directory was created. | 1509 // Should be incremented as a new directory was created. |
| 1510 EXPECT_EQ(old_largest_change_id + 1, | 1510 EXPECT_EQ(old_largest_change_id + 1, |
| 1511 fake_service_.about_resource().largest_change_id()); | 1511 fake_service_.about_resource().largest_change_id()); |
| 1512 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1512 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1513 } | 1513 } |
| 1514 | 1514 |
| 1515 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { | 1515 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { |
| 1516 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1516 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1517 | 1517 |
| 1518 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1518 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1519 | 1519 |
| 1520 GDataErrorCode error = GDATA_OTHER_ERROR; | 1520 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1521 scoped_ptr<FileResource> entry; | 1521 scoped_ptr<FileResource> entry; |
| 1522 fake_service_.AddNewDirectory( | 1522 fake_service_.AddNewDirectory( |
| 1523 fake_service_.GetRootResourceId(), | 1523 fake_service_.GetRootResourceId(), |
| 1524 "new directory", | 1524 "new directory", |
| 1525 DriveServiceInterface::AddNewDirectoryOptions(), | 1525 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1526 test_util::CreateCopyResultCallback(&error, &entry)); | 1526 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1527 base::RunLoop().RunUntilIdle(); | 1527 base::RunLoop().RunUntilIdle(); |
| 1528 | 1528 |
| 1529 EXPECT_EQ(HTTP_CREATED, error); | 1529 EXPECT_EQ(HTTP_CREATED, error); |
| 1530 ASSERT_TRUE(entry); | 1530 ASSERT_TRUE(entry); |
| 1531 EXPECT_TRUE(entry->IsDirectory()); | 1531 EXPECT_TRUE(entry->IsDirectory()); |
| 1532 EXPECT_EQ("resource_id_1", entry->file_id()); | 1532 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1533 EXPECT_EQ("new directory", entry->title()); | 1533 EXPECT_EQ("new directory", entry->title()); |
| 1534 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); | 1534 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); |
| 1535 // Should be incremented as a new directory was created. | 1535 // Should be incremented as a new directory was created. |
| 1536 EXPECT_EQ(old_largest_change_id + 1, | 1536 EXPECT_EQ(old_largest_change_id + 1, |
| 1537 fake_service_.about_resource().largest_change_id()); | 1537 fake_service_.about_resource().largest_change_id()); |
| 1538 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1538 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1539 } | 1539 } |
| 1540 | 1540 |
| 1541 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { | 1541 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { |
| 1542 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1542 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1543 | 1543 |
| 1544 GDataErrorCode error = GDATA_OTHER_ERROR; | 1544 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1545 scoped_ptr<FileResource> entry; | 1545 scoped_ptr<FileResource> entry; |
| 1546 fake_service_.AddNewDirectory( | 1546 fake_service_.AddNewDirectory( |
| 1547 fake_service_.GetRootResourceId(), | 1547 fake_service_.GetRootResourceId(), |
| 1548 "new directory", | 1548 "new directory", |
| 1549 DriveServiceInterface::AddNewDirectoryOptions(), | 1549 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1550 test_util::CreateCopyResultCallback(&error, &entry)); | 1550 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1551 base::RunLoop().RunUntilIdle(); | 1551 base::RunLoop().RunUntilIdle(); |
| 1552 | 1552 |
| 1553 EXPECT_EQ(HTTP_CREATED, error); | 1553 EXPECT_EQ(HTTP_CREATED, error); |
| 1554 ASSERT_TRUE(entry); | 1554 ASSERT_TRUE(entry); |
| 1555 EXPECT_TRUE(entry->IsDirectory()); | 1555 EXPECT_TRUE(entry->IsDirectory()); |
| 1556 EXPECT_EQ("resource_id_1", entry->file_id()); | 1556 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1557 EXPECT_EQ("new directory", entry->title()); | 1557 EXPECT_EQ("new directory", entry->title()); |
| 1558 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); | 1558 EXPECT_TRUE(HasParent(entry->file_id(), fake_service_.GetRootResourceId())); |
| 1559 // Should be incremented as a new directory was created. | 1559 // Should be incremented as a new directory was created. |
| 1560 EXPECT_EQ(old_largest_change_id + 1, | 1560 EXPECT_EQ(old_largest_change_id + 1, |
| 1561 fake_service_.about_resource().largest_change_id()); | 1561 fake_service_.about_resource().largest_change_id()); |
| 1562 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1562 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1563 } | 1563 } |
| 1564 | 1564 |
| 1565 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { | 1565 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) { |
| 1566 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1566 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1567 | 1567 |
| 1568 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1568 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1569 | 1569 |
| 1570 const std::string kParentResourceId = "1_folder_resource_id"; | 1570 const std::string kParentResourceId = "1_folder_resource_id"; |
| 1571 | 1571 |
| 1572 GDataErrorCode error = GDATA_OTHER_ERROR; | 1572 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1573 scoped_ptr<FileResource> entry; | 1573 scoped_ptr<FileResource> entry; |
| 1574 fake_service_.AddNewDirectory( | 1574 fake_service_.AddNewDirectory( |
| 1575 kParentResourceId, | 1575 kParentResourceId, |
| 1576 "new directory", | 1576 "new directory", |
| 1577 DriveServiceInterface::AddNewDirectoryOptions(), | 1577 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1578 test_util::CreateCopyResultCallback(&error, &entry)); | 1578 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1579 base::RunLoop().RunUntilIdle(); | 1579 base::RunLoop().RunUntilIdle(); |
| 1580 | 1580 |
| 1581 EXPECT_EQ(HTTP_CREATED, error); | 1581 EXPECT_EQ(HTTP_CREATED, error); |
| 1582 ASSERT_TRUE(entry); | 1582 ASSERT_TRUE(entry); |
| 1583 EXPECT_TRUE(entry->IsDirectory()); | 1583 EXPECT_TRUE(entry->IsDirectory()); |
| 1584 EXPECT_EQ("resource_id_1", entry->file_id()); | 1584 EXPECT_EQ("resource_id_1", entry->file_id()); |
| 1585 EXPECT_EQ("new directory", entry->title()); | 1585 EXPECT_EQ("new directory", entry->title()); |
| 1586 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); | 1586 EXPECT_TRUE(HasParent(entry->file_id(), kParentResourceId)); |
| 1587 // Should be incremented as a new directory was created. | 1587 // Should be incremented as a new directory was created. |
| 1588 EXPECT_EQ(old_largest_change_id + 1, | 1588 EXPECT_EQ(old_largest_change_id + 1, |
| 1589 fake_service_.about_resource().largest_change_id()); | 1589 fake_service_.about_resource().largest_change_id()); |
| 1590 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1590 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1591 } | 1591 } |
| 1592 | 1592 |
| 1593 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { | 1593 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { |
| 1594 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1594 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1595 | 1595 |
| 1596 const std::string kParentResourceId = "nonexisting_resource_id"; | 1596 const std::string kParentResourceId = "nonexisting_resource_id"; |
| 1597 | 1597 |
| 1598 GDataErrorCode error = GDATA_OTHER_ERROR; | 1598 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1599 scoped_ptr<FileResource> entry; | 1599 scoped_ptr<FileResource> entry; |
| 1600 fake_service_.AddNewDirectory( | 1600 fake_service_.AddNewDirectory( |
| 1601 kParentResourceId, | 1601 kParentResourceId, |
| 1602 "new directory", | 1602 "new directory", |
| 1603 DriveServiceInterface::AddNewDirectoryOptions(), | 1603 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1604 test_util::CreateCopyResultCallback(&error, &entry)); | 1604 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1605 base::RunLoop().RunUntilIdle(); | 1605 base::RunLoop().RunUntilIdle(); |
| 1606 | 1606 |
| 1607 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1607 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1608 EXPECT_FALSE(entry); | 1608 EXPECT_FALSE(entry); |
| 1609 } | 1609 } |
| 1610 | 1610 |
| 1611 TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) { | 1611 TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) { |
| 1612 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1612 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1613 fake_service_.set_offline(true); | 1613 fake_service_.set_offline(true); |
| 1614 | 1614 |
| 1615 GDataErrorCode error = GDATA_OTHER_ERROR; | 1615 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1616 scoped_ptr<FileResource> entry; | 1616 scoped_ptr<FileResource> entry; |
| 1617 fake_service_.AddNewDirectory( | 1617 fake_service_.AddNewDirectory( |
| 1618 fake_service_.GetRootResourceId(), | 1618 fake_service_.GetRootResourceId(), |
| 1619 "new directory", | 1619 "new directory", |
| 1620 DriveServiceInterface::AddNewDirectoryOptions(), | 1620 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1621 test_util::CreateCopyResultCallback(&error, &entry)); | 1621 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1622 base::RunLoop().RunUntilIdle(); | 1622 base::RunLoop().RunUntilIdle(); |
| 1623 | 1623 |
| 1624 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1624 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1625 EXPECT_FALSE(entry); | 1625 EXPECT_FALSE(entry); |
| 1626 } | 1626 } |
| 1627 | 1627 |
| 1628 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { | 1628 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { |
| 1629 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1629 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1630 fake_service_.set_offline(true); | 1630 fake_service_.set_offline(true); |
| 1631 | 1631 |
| 1632 GDataErrorCode error = GDATA_OTHER_ERROR; | 1632 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1633 GURL upload_location; | 1633 GURL upload_location; |
| 1634 fake_service_.InitiateUploadNewFile( | 1634 fake_service_.InitiateUploadNewFile( |
| 1635 "test/foo", 13, "1_folder_resource_id", "new file.foo", | 1635 "test/foo", 13, "1_folder_resource_id", "new file.foo", |
| 1636 FakeDriveService::UploadNewFileOptions(), | 1636 FakeDriveService::UploadNewFileOptions(), |
| 1637 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1637 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1638 base::RunLoop().RunUntilIdle(); | 1638 base::RunLoop().RunUntilIdle(); |
| 1639 | 1639 |
| 1640 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1640 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1641 EXPECT_TRUE(upload_location.is_empty()); | 1641 EXPECT_TRUE(upload_location.is_empty()); |
| 1642 } | 1642 } |
| 1643 | 1643 |
| 1644 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_NotFound) { | 1644 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_NotFound) { |
| 1645 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1645 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1646 | 1646 |
| 1647 GDataErrorCode error = GDATA_OTHER_ERROR; | 1647 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1648 GURL upload_location; | 1648 GURL upload_location; |
| 1649 fake_service_.InitiateUploadNewFile( | 1649 fake_service_.InitiateUploadNewFile( |
| 1650 "test/foo", 13, "non_existent", "new file.foo", | 1650 "test/foo", 13, "non_existent", "new file.foo", |
| 1651 FakeDriveService::UploadNewFileOptions(), | 1651 FakeDriveService::UploadNewFileOptions(), |
| 1652 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1652 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1653 base::RunLoop().RunUntilIdle(); | 1653 base::RunLoop().RunUntilIdle(); |
| 1654 | 1654 |
| 1655 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1655 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1656 EXPECT_TRUE(upload_location.is_empty()); | 1656 EXPECT_TRUE(upload_location.is_empty()); |
| 1657 } | 1657 } |
| 1658 | 1658 |
| 1659 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile) { | 1659 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile) { |
| 1660 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1660 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1661 | 1661 |
| 1662 GDataErrorCode error = GDATA_OTHER_ERROR; | 1662 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1663 GURL upload_location; | 1663 GURL upload_location; |
| 1664 fake_service_.InitiateUploadNewFile( | 1664 fake_service_.InitiateUploadNewFile( |
| 1665 "test/foo", 13, "1_folder_resource_id", "new file.foo", | 1665 "test/foo", 13, "1_folder_resource_id", "new file.foo", |
| 1666 FakeDriveService::UploadNewFileOptions(), | 1666 FakeDriveService::UploadNewFileOptions(), |
| 1667 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1667 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1668 base::RunLoop().RunUntilIdle(); | 1668 base::RunLoop().RunUntilIdle(); |
| 1669 | 1669 |
| 1670 EXPECT_EQ(HTTP_SUCCESS, error); | 1670 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1671 EXPECT_FALSE(upload_location.is_empty()); | 1671 EXPECT_FALSE(upload_location.is_empty()); |
| 1672 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"), | 1672 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"), |
| 1673 upload_location); | 1673 upload_location); |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Offline) { | 1676 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Offline) { |
| 1677 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1677 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1678 fake_service_.set_offline(true); | 1678 fake_service_.set_offline(true); |
| 1679 | 1679 |
| 1680 GDataErrorCode error = GDATA_OTHER_ERROR; | 1680 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1681 GURL upload_location; | 1681 GURL upload_location; |
| 1682 fake_service_.InitiateUploadExistingFile( | 1682 fake_service_.InitiateUploadExistingFile( |
| 1683 "test/foo", 13, "2_file_resource_id", | 1683 "test/foo", 13, "2_file_resource_id", |
| 1684 FakeDriveService::UploadExistingFileOptions(), | 1684 FakeDriveService::UploadExistingFileOptions(), |
| 1685 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1685 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1686 base::RunLoop().RunUntilIdle(); | 1686 base::RunLoop().RunUntilIdle(); |
| 1687 | 1687 |
| 1688 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1688 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 1689 EXPECT_TRUE(upload_location.is_empty()); | 1689 EXPECT_TRUE(upload_location.is_empty()); |
| 1690 } | 1690 } |
| 1691 | 1691 |
| 1692 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Forbidden) { | 1692 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Forbidden) { |
| 1693 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1693 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1694 | 1694 |
| 1695 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( | 1695 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission( |
| 1696 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); | 1696 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER)); |
| 1697 | 1697 |
| 1698 GDataErrorCode error = GDATA_OTHER_ERROR; | 1698 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1699 GURL upload_location; | 1699 GURL upload_location; |
| 1700 fake_service_.InitiateUploadExistingFile( | 1700 fake_service_.InitiateUploadExistingFile( |
| 1701 "test/foo", 13, "2_file_resource_id", | 1701 "test/foo", 13, "2_file_resource_id", |
| 1702 FakeDriveService::UploadExistingFileOptions(), | 1702 FakeDriveService::UploadExistingFileOptions(), |
| 1703 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1703 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1704 base::RunLoop().RunUntilIdle(); | 1704 base::RunLoop().RunUntilIdle(); |
| 1705 | 1705 |
| 1706 EXPECT_EQ(HTTP_FORBIDDEN, error); | 1706 EXPECT_EQ(HTTP_FORBIDDEN, error); |
| 1707 EXPECT_TRUE(upload_location.is_empty()); | 1707 EXPECT_TRUE(upload_location.is_empty()); |
| 1708 } | 1708 } |
| 1709 | 1709 |
| 1710 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) { | 1710 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) { |
| 1711 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1711 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1712 | 1712 |
| 1713 GDataErrorCode error = GDATA_OTHER_ERROR; | 1713 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1714 GURL upload_location; | 1714 GURL upload_location; |
| 1715 fake_service_.InitiateUploadExistingFile( | 1715 fake_service_.InitiateUploadExistingFile( |
| 1716 "test/foo", 13, "non_existent", | 1716 "test/foo", 13, "non_existent", |
| 1717 FakeDriveService::UploadExistingFileOptions(), | 1717 FakeDriveService::UploadExistingFileOptions(), |
| 1718 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1718 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1719 base::RunLoop().RunUntilIdle(); | 1719 base::RunLoop().RunUntilIdle(); |
| 1720 | 1720 |
| 1721 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1721 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1722 EXPECT_TRUE(upload_location.is_empty()); | 1722 EXPECT_TRUE(upload_location.is_empty()); |
| 1723 } | 1723 } |
| 1724 | 1724 |
| 1725 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_WrongETag) { | 1725 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_WrongETag) { |
| 1726 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1726 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1727 | 1727 |
| 1728 FakeDriveService::UploadExistingFileOptions options; | 1728 FakeDriveService::UploadExistingFileOptions options; |
| 1729 options.etag = "invalid_etag"; | 1729 options.etag = "invalid_etag"; |
| 1730 | 1730 |
| 1731 GDataErrorCode error = GDATA_OTHER_ERROR; | 1731 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1732 GURL upload_location; | 1732 GURL upload_location; |
| 1733 fake_service_.InitiateUploadExistingFile( | 1733 fake_service_.InitiateUploadExistingFile( |
| 1734 "text/plain", | 1734 "text/plain", |
| 1735 13, | 1735 13, |
| 1736 "2_file_resource_id", | 1736 "2_file_resource_id", |
| 1737 options, | 1737 options, |
| 1738 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1738 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1739 base::RunLoop().RunUntilIdle(); | 1739 base::RunLoop().RunUntilIdle(); |
| 1740 | 1740 |
| 1741 EXPECT_EQ(HTTP_PRECONDITION, error); | 1741 EXPECT_EQ(HTTP_PRECONDITION, error); |
| 1742 EXPECT_TRUE(upload_location.is_empty()); | 1742 EXPECT_TRUE(upload_location.is_empty()); |
| 1743 } | 1743 } |
| 1744 | 1744 |
| 1745 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) { | 1745 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) { |
| 1746 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1746 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1747 | 1747 |
| 1748 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); | 1748 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
| 1749 ASSERT_TRUE(entry); | 1749 ASSERT_TRUE(entry); |
| 1750 | 1750 |
| 1751 FakeDriveService::UploadExistingFileOptions options; | 1751 FakeDriveService::UploadExistingFileOptions options; |
| 1752 options.etag = entry->etag(); | 1752 options.etag = entry->etag(); |
| 1753 | 1753 |
| 1754 GDataErrorCode error = GDATA_OTHER_ERROR; | 1754 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1755 GURL upload_location; | 1755 GURL upload_location; |
| 1756 fake_service_.InitiateUploadExistingFile( | 1756 fake_service_.InitiateUploadExistingFile( |
| 1757 "text/plain", | 1757 "text/plain", |
| 1758 13, | 1758 13, |
| 1759 "2_file_resource_id", | 1759 "2_file_resource_id", |
| 1760 options, | 1760 options, |
| 1761 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1761 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1762 base::RunLoop().RunUntilIdle(); | 1762 base::RunLoop().RunUntilIdle(); |
| 1763 | 1763 |
| 1764 EXPECT_EQ(HTTP_SUCCESS, error); | 1764 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1765 EXPECT_TRUE(upload_location.is_valid()); | 1765 EXPECT_TRUE(upload_location.is_valid()); |
| 1766 } | 1766 } |
| 1767 | 1767 |
| 1768 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) { | 1768 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) { |
| 1769 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1769 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1770 | 1770 |
| 1771 GDataErrorCode error = GDATA_OTHER_ERROR; | 1771 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1772 GURL upload_location; | 1772 GURL upload_location; |
| 1773 fake_service_.InitiateUploadNewFile( | 1773 fake_service_.InitiateUploadNewFile( |
| 1774 "test/foo", 15, "1_folder_resource_id", "new file.foo", | 1774 "test/foo", 15, "1_folder_resource_id", "new file.foo", |
| 1775 FakeDriveService::UploadNewFileOptions(), | 1775 FakeDriveService::UploadNewFileOptions(), |
| 1776 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1776 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1777 base::RunLoop().RunUntilIdle(); | 1777 base::RunLoop().RunUntilIdle(); |
| 1778 | 1778 |
| 1779 EXPECT_EQ(HTTP_SUCCESS, error); | 1779 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1780 EXPECT_FALSE(upload_location.is_empty()); | 1780 EXPECT_FALSE(upload_location.is_empty()); |
| 1781 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), | 1781 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), |
| 1782 upload_location); | 1782 upload_location); |
| 1783 | 1783 |
| 1784 fake_service_.set_offline(true); | 1784 fake_service_.set_offline(true); |
| 1785 | 1785 |
| 1786 UploadRangeResponse response; | 1786 UploadRangeResponse response; |
| 1787 scoped_ptr<FileResource> entry; | 1787 scoped_ptr<FileResource> entry; |
| 1788 fake_service_.ResumeUpload( | 1788 fake_service_.ResumeUpload( |
| 1789 upload_location, | 1789 upload_location, |
| 1790 0, 13, 15, "test/foo", | 1790 0, 13, 15, "test/foo", |
| 1791 base::FilePath(), | 1791 base::FilePath(), |
| 1792 test_util::CreateCopyResultCallback(&response, &entry), | 1792 test_util::CreateCopyResultCallback(&response, &entry), |
| 1793 ProgressCallback()); | 1793 ProgressCallback()); |
| 1794 base::RunLoop().RunUntilIdle(); | 1794 base::RunLoop().RunUntilIdle(); |
| 1795 | 1795 |
| 1796 EXPECT_EQ(GDATA_NO_CONNECTION, response.code); | 1796 EXPECT_EQ(DRIVE_NO_CONNECTION, response.code); |
| 1797 EXPECT_FALSE(entry.get()); | 1797 EXPECT_FALSE(entry.get()); |
| 1798 } | 1798 } |
| 1799 | 1799 |
| 1800 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) { | 1800 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) { |
| 1801 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1801 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1802 | 1802 |
| 1803 GDataErrorCode error = GDATA_OTHER_ERROR; | 1803 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1804 GURL upload_location; | 1804 GURL upload_location; |
| 1805 fake_service_.InitiateUploadNewFile( | 1805 fake_service_.InitiateUploadNewFile( |
| 1806 "test/foo", 15, "1_folder_resource_id", "new file.foo", | 1806 "test/foo", 15, "1_folder_resource_id", "new file.foo", |
| 1807 FakeDriveService::UploadNewFileOptions(), | 1807 FakeDriveService::UploadNewFileOptions(), |
| 1808 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1808 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1809 base::RunLoop().RunUntilIdle(); | 1809 base::RunLoop().RunUntilIdle(); |
| 1810 | 1810 |
| 1811 ASSERT_EQ(HTTP_SUCCESS, error); | 1811 ASSERT_EQ(HTTP_SUCCESS, error); |
| 1812 | 1812 |
| 1813 UploadRangeResponse response; | 1813 UploadRangeResponse response; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1833 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1833 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
| 1834 | 1834 |
| 1835 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1835 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1836 | 1836 |
| 1837 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); | 1837 scoped_ptr<FileResource> entry = FindEntry("2_file_resource_id"); |
| 1838 ASSERT_TRUE(entry); | 1838 ASSERT_TRUE(entry); |
| 1839 | 1839 |
| 1840 FakeDriveService::UploadExistingFileOptions options; | 1840 FakeDriveService::UploadExistingFileOptions options; |
| 1841 options.etag = entry->etag(); | 1841 options.etag = entry->etag(); |
| 1842 | 1842 |
| 1843 GDataErrorCode error = GDATA_OTHER_ERROR; | 1843 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1844 GURL upload_location; | 1844 GURL upload_location; |
| 1845 fake_service_.InitiateUploadExistingFile( | 1845 fake_service_.InitiateUploadExistingFile( |
| 1846 "text/plain", | 1846 "text/plain", |
| 1847 contents.size(), | 1847 contents.size(), |
| 1848 "2_file_resource_id", | 1848 "2_file_resource_id", |
| 1849 options, | 1849 options, |
| 1850 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1850 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1851 base::RunLoop().RunUntilIdle(); | 1851 base::RunLoop().RunUntilIdle(); |
| 1852 | 1852 |
| 1853 ASSERT_EQ(HTTP_SUCCESS, error); | 1853 ASSERT_EQ(HTTP_SUCCESS, error); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1897 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { | 1897 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { |
| 1898 base::ScopedTempDir temp_dir; | 1898 base::ScopedTempDir temp_dir; |
| 1899 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1899 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1900 base::FilePath local_file_path = | 1900 base::FilePath local_file_path = |
| 1901 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo")); | 1901 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo")); |
| 1902 std::string contents("hogefugapiyo"); | 1902 std::string contents("hogefugapiyo"); |
| 1903 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); | 1903 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents)); |
| 1904 | 1904 |
| 1905 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1905 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1906 | 1906 |
| 1907 GDataErrorCode error = GDATA_OTHER_ERROR; | 1907 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1908 GURL upload_location; | 1908 GURL upload_location; |
| 1909 fake_service_.InitiateUploadNewFile( | 1909 fake_service_.InitiateUploadNewFile( |
| 1910 "test/foo", contents.size(), "1_folder_resource_id", "new file.foo", | 1910 "test/foo", contents.size(), "1_folder_resource_id", "new file.foo", |
| 1911 FakeDriveService::UploadNewFileOptions(), | 1911 FakeDriveService::UploadNewFileOptions(), |
| 1912 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1912 test_util::CreateCopyResultCallback(&error, &upload_location)); |
| 1913 base::RunLoop().RunUntilIdle(); | 1913 base::RunLoop().RunUntilIdle(); |
| 1914 | 1914 |
| 1915 EXPECT_EQ(HTTP_SUCCESS, error); | 1915 EXPECT_EQ(HTTP_SUCCESS, error); |
| 1916 EXPECT_FALSE(upload_location.is_empty()); | 1916 EXPECT_FALSE(upload_location.is_empty()); |
| 1917 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), | 1917 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1961 | 1961 |
| 1962 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) { | 1962 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) { |
| 1963 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 1963 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 1964 | 1964 |
| 1965 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1965 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1966 | 1966 |
| 1967 const std::string kContentType = "text/plain"; | 1967 const std::string kContentType = "text/plain"; |
| 1968 const std::string kContentData = "This is some test content."; | 1968 const std::string kContentData = "This is some test content."; |
| 1969 const std::string kTitle = "new file"; | 1969 const std::string kTitle = "new file"; |
| 1970 | 1970 |
| 1971 GDataErrorCode error = GDATA_OTHER_ERROR; | 1971 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 1972 scoped_ptr<FileResource> entry; | 1972 scoped_ptr<FileResource> entry; |
| 1973 fake_service_.AddNewFile( | 1973 fake_service_.AddNewFile( |
| 1974 kContentType, | 1974 kContentType, |
| 1975 kContentData, | 1975 kContentData, |
| 1976 fake_service_.GetRootResourceId(), | 1976 fake_service_.GetRootResourceId(), |
| 1977 kTitle, | 1977 kTitle, |
| 1978 false, // shared_with_me | 1978 false, // shared_with_me |
| 1979 test_util::CreateCopyResultCallback(&error, &entry)); | 1979 test_util::CreateCopyResultCallback(&error, &entry)); |
| 1980 base::RunLoop().RunUntilIdle(); | 1980 base::RunLoop().RunUntilIdle(); |
| 1981 | 1981 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1993 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); | 1993 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); |
| 1994 } | 1994 } |
| 1995 | 1995 |
| 1996 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) { | 1996 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) { |
| 1997 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1997 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1998 | 1998 |
| 1999 const std::string kContentType = "text/plain"; | 1999 const std::string kContentType = "text/plain"; |
| 2000 const std::string kContentData = "This is some test content."; | 2000 const std::string kContentData = "This is some test content."; |
| 2001 const std::string kTitle = "new file"; | 2001 const std::string kTitle = "new file"; |
| 2002 | 2002 |
| 2003 GDataErrorCode error = GDATA_OTHER_ERROR; | 2003 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2004 scoped_ptr<FileResource> entry; | 2004 scoped_ptr<FileResource> entry; |
| 2005 fake_service_.AddNewFile( | 2005 fake_service_.AddNewFile( |
| 2006 kContentType, | 2006 kContentType, |
| 2007 kContentData, | 2007 kContentData, |
| 2008 fake_service_.GetRootResourceId(), | 2008 fake_service_.GetRootResourceId(), |
| 2009 kTitle, | 2009 kTitle, |
| 2010 false, // shared_with_me | 2010 false, // shared_with_me |
| 2011 test_util::CreateCopyResultCallback(&error, &entry)); | 2011 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2012 base::RunLoop().RunUntilIdle(); | 2012 base::RunLoop().RunUntilIdle(); |
| 2013 | 2013 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2028 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) { | 2028 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) { |
| 2029 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2029 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 2030 | 2030 |
| 2031 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 2031 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 2032 | 2032 |
| 2033 const std::string kContentType = "text/plain"; | 2033 const std::string kContentType = "text/plain"; |
| 2034 const std::string kContentData = "This is some test content."; | 2034 const std::string kContentData = "This is some test content."; |
| 2035 const std::string kTitle = "new file"; | 2035 const std::string kTitle = "new file"; |
| 2036 const std::string kParentResourceId = "1_folder_resource_id"; | 2036 const std::string kParentResourceId = "1_folder_resource_id"; |
| 2037 | 2037 |
| 2038 GDataErrorCode error = GDATA_OTHER_ERROR; | 2038 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2039 scoped_ptr<FileResource> entry; | 2039 scoped_ptr<FileResource> entry; |
| 2040 fake_service_.AddNewFile( | 2040 fake_service_.AddNewFile( |
| 2041 kContentType, | 2041 kContentType, |
| 2042 kContentData, | 2042 kContentData, |
| 2043 kParentResourceId, | 2043 kParentResourceId, |
| 2044 kTitle, | 2044 kTitle, |
| 2045 false, // shared_with_me | 2045 false, // shared_with_me |
| 2046 test_util::CreateCopyResultCallback(&error, &entry)); | 2046 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2047 base::RunLoop().RunUntilIdle(); | 2047 base::RunLoop().RunUntilIdle(); |
| 2048 | 2048 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2061 } | 2061 } |
| 2062 | 2062 |
| 2063 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonexistingDirectory) { | 2063 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonexistingDirectory) { |
| 2064 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2064 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 2065 | 2065 |
| 2066 const std::string kContentType = "text/plain"; | 2066 const std::string kContentType = "text/plain"; |
| 2067 const std::string kContentData = "This is some test content."; | 2067 const std::string kContentData = "This is some test content."; |
| 2068 const std::string kTitle = "new file"; | 2068 const std::string kTitle = "new file"; |
| 2069 const std::string kParentResourceId = "nonexisting_resource_id"; | 2069 const std::string kParentResourceId = "nonexisting_resource_id"; |
| 2070 | 2070 |
| 2071 GDataErrorCode error = GDATA_OTHER_ERROR; | 2071 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2072 scoped_ptr<FileResource> entry; | 2072 scoped_ptr<FileResource> entry; |
| 2073 fake_service_.AddNewFile( | 2073 fake_service_.AddNewFile( |
| 2074 kContentType, | 2074 kContentType, |
| 2075 kContentData, | 2075 kContentData, |
| 2076 kParentResourceId, | 2076 kParentResourceId, |
| 2077 kTitle, | 2077 kTitle, |
| 2078 false, // shared_with_me | 2078 false, // shared_with_me |
| 2079 test_util::CreateCopyResultCallback(&error, &entry)); | 2079 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2080 base::RunLoop().RunUntilIdle(); | 2080 base::RunLoop().RunUntilIdle(); |
| 2081 | 2081 |
| 2082 EXPECT_EQ(HTTP_NOT_FOUND, error); | 2082 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 2083 EXPECT_FALSE(entry); | 2083 EXPECT_FALSE(entry); |
| 2084 } | 2084 } |
| 2085 | 2085 |
| 2086 TEST_F(FakeDriveServiceTest, AddNewFile_Offline) { | 2086 TEST_F(FakeDriveServiceTest, AddNewFile_Offline) { |
| 2087 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2087 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 2088 fake_service_.set_offline(true); | 2088 fake_service_.set_offline(true); |
| 2089 | 2089 |
| 2090 const std::string kContentType = "text/plain"; | 2090 const std::string kContentType = "text/plain"; |
| 2091 const std::string kContentData = "This is some test content."; | 2091 const std::string kContentData = "This is some test content."; |
| 2092 const std::string kTitle = "new file"; | 2092 const std::string kTitle = "new file"; |
| 2093 | 2093 |
| 2094 GDataErrorCode error = GDATA_OTHER_ERROR; | 2094 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2095 scoped_ptr<FileResource> entry; | 2095 scoped_ptr<FileResource> entry; |
| 2096 fake_service_.AddNewFile( | 2096 fake_service_.AddNewFile( |
| 2097 kContentType, | 2097 kContentType, |
| 2098 kContentData, | 2098 kContentData, |
| 2099 fake_service_.GetRootResourceId(), | 2099 fake_service_.GetRootResourceId(), |
| 2100 kTitle, | 2100 kTitle, |
| 2101 false, // shared_with_me | 2101 false, // shared_with_me |
| 2102 test_util::CreateCopyResultCallback(&error, &entry)); | 2102 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2103 base::RunLoop().RunUntilIdle(); | 2103 base::RunLoop().RunUntilIdle(); |
| 2104 | 2104 |
| 2105 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 2105 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 2106 EXPECT_FALSE(entry); | 2106 EXPECT_FALSE(entry); |
| 2107 } | 2107 } |
| 2108 | 2108 |
| 2109 TEST_F(FakeDriveServiceTest, AddNewFile_SharedWithMeLabel) { | 2109 TEST_F(FakeDriveServiceTest, AddNewFile_SharedWithMeLabel) { |
| 2110 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2110 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 2111 | 2111 |
| 2112 const std::string kContentType = "text/plain"; | 2112 const std::string kContentType = "text/plain"; |
| 2113 const std::string kContentData = "This is some test content."; | 2113 const std::string kContentData = "This is some test content."; |
| 2114 const std::string kTitle = "new file"; | 2114 const std::string kTitle = "new file"; |
| 2115 | 2115 |
| 2116 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 2116 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 2117 | 2117 |
| 2118 GDataErrorCode error = GDATA_OTHER_ERROR; | 2118 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2119 scoped_ptr<FileResource> entry; | 2119 scoped_ptr<FileResource> entry; |
| 2120 fake_service_.AddNewFile( | 2120 fake_service_.AddNewFile( |
| 2121 kContentType, | 2121 kContentType, |
| 2122 kContentData, | 2122 kContentData, |
| 2123 fake_service_.GetRootResourceId(), | 2123 fake_service_.GetRootResourceId(), |
| 2124 kTitle, | 2124 kTitle, |
| 2125 true, // shared_with_me | 2125 true, // shared_with_me |
| 2126 test_util::CreateCopyResultCallback(&error, &entry)); | 2126 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2127 base::RunLoop().RunUntilIdle(); | 2127 base::RunLoop().RunUntilIdle(); |
| 2128 | 2128 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2141 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); | 2141 EXPECT_EQ(base::MD5String(kContentData), entry->md5_checksum()); |
| 2142 } | 2142 } |
| 2143 | 2143 |
| 2144 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) { | 2144 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) { |
| 2145 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2145 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 2146 | 2146 |
| 2147 const std::string kResourceId = "2_file_resource_id"; | 2147 const std::string kResourceId = "2_file_resource_id"; |
| 2148 base::Time time; | 2148 base::Time time; |
| 2149 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | 2149 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); |
| 2150 | 2150 |
| 2151 GDataErrorCode error = GDATA_OTHER_ERROR; | 2151 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2152 scoped_ptr<FileResource> entry; | 2152 scoped_ptr<FileResource> entry; |
| 2153 fake_service_.SetLastModifiedTime( | 2153 fake_service_.SetLastModifiedTime( |
| 2154 kResourceId, | 2154 kResourceId, |
| 2155 time, | 2155 time, |
| 2156 test_util::CreateCopyResultCallback(&error, &entry)); | 2156 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2157 base::RunLoop().RunUntilIdle(); | 2157 base::RunLoop().RunUntilIdle(); |
| 2158 | 2158 |
| 2159 EXPECT_EQ(HTTP_SUCCESS, error); | 2159 EXPECT_EQ(HTTP_SUCCESS, error); |
| 2160 ASSERT_TRUE(entry); | 2160 ASSERT_TRUE(entry); |
| 2161 EXPECT_EQ(time, entry->modified_date()); | 2161 EXPECT_EQ(time, entry->modified_date()); |
| 2162 } | 2162 } |
| 2163 | 2163 |
| 2164 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_NonexistingFile) { | 2164 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_NonexistingFile) { |
| 2165 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2165 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 2166 | 2166 |
| 2167 const std::string kResourceId = "nonexisting_resource_id"; | 2167 const std::string kResourceId = "nonexisting_resource_id"; |
| 2168 base::Time time; | 2168 base::Time time; |
| 2169 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | 2169 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); |
| 2170 | 2170 |
| 2171 GDataErrorCode error = GDATA_OTHER_ERROR; | 2171 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2172 scoped_ptr<FileResource> entry; | 2172 scoped_ptr<FileResource> entry; |
| 2173 fake_service_.SetLastModifiedTime( | 2173 fake_service_.SetLastModifiedTime( |
| 2174 kResourceId, | 2174 kResourceId, |
| 2175 time, | 2175 time, |
| 2176 test_util::CreateCopyResultCallback(&error, &entry)); | 2176 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2177 base::RunLoop().RunUntilIdle(); | 2177 base::RunLoop().RunUntilIdle(); |
| 2178 | 2178 |
| 2179 EXPECT_EQ(HTTP_NOT_FOUND, error); | 2179 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 2180 EXPECT_FALSE(entry); | 2180 EXPECT_FALSE(entry); |
| 2181 } | 2181 } |
| 2182 | 2182 |
| 2183 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_Offline) { | 2183 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_Offline) { |
| 2184 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); | 2184 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); |
| 2185 fake_service_.set_offline(true); | 2185 fake_service_.set_offline(true); |
| 2186 | 2186 |
| 2187 const std::string kResourceId = "2_file_resource_id"; | 2187 const std::string kResourceId = "2_file_resource_id"; |
| 2188 base::Time time; | 2188 base::Time time; |
| 2189 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | 2189 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); |
| 2190 | 2190 |
| 2191 GDataErrorCode error = GDATA_OTHER_ERROR; | 2191 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
| 2192 scoped_ptr<FileResource> entry; | 2192 scoped_ptr<FileResource> entry; |
| 2193 fake_service_.SetLastModifiedTime( | 2193 fake_service_.SetLastModifiedTime( |
| 2194 kResourceId, | 2194 kResourceId, |
| 2195 time, | 2195 time, |
| 2196 test_util::CreateCopyResultCallback(&error, &entry)); | 2196 test_util::CreateCopyResultCallback(&error, &entry)); |
| 2197 base::RunLoop().RunUntilIdle(); | 2197 base::RunLoop().RunUntilIdle(); |
| 2198 | 2198 |
| 2199 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 2199 EXPECT_EQ(DRIVE_NO_CONNECTION, error); |
| 2200 EXPECT_FALSE(entry); | 2200 EXPECT_FALSE(entry); |
| 2201 } | 2201 } |
| 2202 | 2202 |
| 2203 } // namespace | 2203 } // namespace |
| 2204 | 2204 |
| 2205 } // namespace drive | 2205 } // namespace drive |
| OLD | NEW |