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/chromeos/gdata/gdata_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
| 10 #include "base/message_loop.h" |
10 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 11 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace gdata { | 15 namespace gdata { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // See gdata.proto for the difference between the two URLs. | 19 // See gdata.proto for the difference between the two URLs. |
18 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; | 20 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; |
19 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; | 21 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; |
20 | 22 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ASSERT_TRUE(directory_service.ParseFromString(serialized_proto)); | 205 ASSERT_TRUE(directory_service.ParseFromString(serialized_proto)); |
204 // No file should be added to the root directory. | 206 // No file should be added to the root directory. |
205 ASSERT_TRUE(root->child_files().empty()); | 207 ASSERT_TRUE(root->child_files().empty()); |
206 // Two directories ("empty", "dir") should be added to the root directory. | 208 // Two directories ("empty", "dir") should be added to the root directory. |
207 ASSERT_EQ(2U, root->child_directories().size()); | 209 ASSERT_EQ(2U, root->child_directories().size()); |
208 // The origin should change to FROM_CACHE because we loaded from the cache. | 210 // The origin should change to FROM_CACHE because we loaded from the cache. |
209 ASSERT_EQ(FROM_CACHE, directory_service.origin()); | 211 ASSERT_EQ(FROM_CACHE, directory_service.origin()); |
210 } | 212 } |
211 | 213 |
212 TEST(GDataRootDirectoryTest, RefreshFile) { | 214 TEST(GDataRootDirectoryTest, RefreshFile) { |
| 215 MessageLoopForUI message_loop; |
213 GDataDirectoryService directory_service; | 216 GDataDirectoryService directory_service; |
214 GDataDirectory* root(directory_service.root()); | 217 GDataDirectory* root(directory_service.root()); |
215 // Add a directory to the file system. | 218 // Add a directory to the file system. |
216 GDataDirectory* directory_entry = new GDataDirectory(root, | 219 GDataDirectory* directory_entry = new GDataDirectory(root, |
217 &directory_service); | 220 &directory_service); |
218 directory_entry->set_resource_id("folder:directory_resource_id"); | 221 directory_entry->set_resource_id("folder:directory_resource_id"); |
219 root->AddEntry(directory_entry); | 222 directory_entry->set_title("directory"); |
| 223 directory_entry->SetBaseNameFromTitle(); |
| 224 GDataFileError error = GDATA_FILE_ERROR_FAILED; |
| 225 directory_service.AddEntryToDirectory( |
| 226 FilePath(kGDataRootDirectory), |
| 227 directory_entry, |
| 228 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
| 229 test_util::RunBlockingPoolTask(); |
| 230 ASSERT_EQ(GDATA_FILE_OK, error); |
220 | 231 |
221 // Add a new file to the directory. | 232 // Add a new file to the directory. |
222 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service); | 233 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service); |
223 initial_file_entry->set_resource_id("file:file_resource_id"); | 234 initial_file_entry->set_resource_id("file:file_resource_id"); |
224 directory_entry->AddEntry(initial_file_entry); | 235 initial_file_entry->set_title("file"); |
| 236 initial_file_entry->SetBaseNameFromTitle(); |
| 237 directory_service.AddEntryToDirectory( |
| 238 directory_entry->GetFilePath(), |
| 239 initial_file_entry, |
| 240 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); |
| 241 test_util::RunBlockingPoolTask(); |
| 242 ASSERT_EQ(GDATA_FILE_OK, error); |
| 243 |
225 ASSERT_EQ(directory_entry, initial_file_entry->parent()); | 244 ASSERT_EQ(directory_entry, initial_file_entry->parent()); |
226 | 245 |
227 // Initial file system state set, let's try refreshing entries. | 246 // Initial file system state set, let's try refreshing entries. |
228 | 247 |
229 // New value for the entry with resource id "file:file_resource_id". | 248 // New value for the entry with resource id "file:file_resource_id". |
230 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service); | 249 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service); |
231 new_file_entry->set_resource_id("file:file_resource_id"); | 250 new_file_entry->set_resource_id("file:file_resource_id"); |
232 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass()); | 251 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass()); |
233 // Root should have |new_file_entry|, not |initial_file_entry|. | 252 // Root should have |new_file_entry|, not |initial_file_entry|. |
234 // If this is not true, |new_file_entry| has probably been destroyed, hence | 253 // If this is not true, |new_file_entry| has probably been destroyed, hence |
(...skipping 16 matching lines...) Expand all Loading... |
251 TEST(GDataRootDirectoryTest, GetEntryByResourceId_RootDirectory) { | 270 TEST(GDataRootDirectoryTest, GetEntryByResourceId_RootDirectory) { |
252 GDataDirectoryService directory_service; | 271 GDataDirectoryService directory_service; |
253 // Look up the root directory by its resource ID. | 272 // Look up the root directory by its resource ID. |
254 GDataEntry* entry = directory_service.GetEntryByResourceId( | 273 GDataEntry* entry = directory_service.GetEntryByResourceId( |
255 kGDataRootDirectoryResourceId); | 274 kGDataRootDirectoryResourceId); |
256 ASSERT_TRUE(entry); | 275 ASSERT_TRUE(entry); |
257 EXPECT_EQ(kGDataRootDirectoryResourceId, entry->resource_id()); | 276 EXPECT_EQ(kGDataRootDirectoryResourceId, entry->resource_id()); |
258 } | 277 } |
259 | 278 |
260 } // namespace gdata | 279 } // namespace gdata |
OLD | NEW |