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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 13 #include "base/string16.h" | 15 #include "base/string16.h" |
| 14 #include "base/time.h" | 16 #include "base/time.h" |
| 15 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_mock.h" | |
| 18 #include "chrome/browser/chromeos/gdata/gdata_parser.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_parser.h" |
| 19 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 21 #include "content/test/test_browser_thread.h" | 24 #include "content/test/test_browser_thread.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 27 |
| 25 using ::testing::AnyNumber; | 28 using ::testing::AnyNumber; |
| 26 using ::testing::Return; | 29 using ::testing::Return; |
| 27 using ::testing::ReturnNull; | 30 using ::testing::ReturnNull; |
| 28 using ::testing::_; | 31 using ::testing::_; |
| 29 | 32 |
| 30 using base::Value; | 33 using base::Value; |
| 31 using base::DictionaryValue; | 34 using base::DictionaryValue; |
| 32 using base::ListValue; | 35 using base::ListValue; |
| 33 | 36 |
| 37 #define FPL(x) FILE_PATH_LITERAL(x) | |
| 38 | |
| 34 namespace gdata { | 39 namespace gdata { |
| 35 | 40 |
| 36 class GDataFileSystemTest : public testing::Test { | 41 class GDataFileSystemTest : public testing::Test { |
| 37 protected: | 42 protected: |
| 38 GDataFileSystemTest() | 43 GDataFileSystemTest() |
| 39 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | 44 : ui_thread_(content::BrowserThread::UI, &message_loop_) { |
| 40 } | 45 } |
| 41 | 46 |
| 42 virtual void SetUp() { | 47 virtual void SetUp() OVERRIDE { |
| 48 callback_helper_ = new CallbackHelper; | |
| 43 profile_.reset(new TestingProfile); | 49 profile_.reset(new TestingProfile); |
| 44 file_system_ = GDataFileSystemFactory::GetForProfile(profile_.get()); | 50 file_system_ = GDataFileSystemFactory::GetForProfile(profile_.get()); |
|
satorux1
2012/03/08 01:48:37
For testing, let's do new GDataFileSystem. You can
Greg Spencer (Chromium)
2012/03/08 19:06:35
Yeah, but are we bypassing anything important in G
satorux1
2012/03/08 19:28:37
I think it's not important to use GetForProfile().
Greg Spencer (Chromium)
2012/03/09 00:33:30
As long as we never make GDataFileSystem dependent
| |
| 51 | |
| 52 // Allocate and keep a weak pointer to the mock. | |
| 53 mock_doc_service_ = new MockDocumentsService; | |
| 54 EXPECT_CALL(*mock_doc_service_, Initialize(profile_.get())).Times(1); | |
| 55 | |
| 56 // Pass the service for the filesystem to own. | |
| 57 scoped_ptr<DocumentsServiceInterface> service(mock_doc_service_); | |
| 58 file_system_->ReplaceDocumentsService(service.Pass()); | |
|
satorux1
2012/03/08 01:48:37
Cannot you just pass mock_doc_service_? I thought
Greg Spencer (Chromium)
2012/03/08 19:06:35
Nope, that doesn't work, since the constructor for
| |
| 59 } | |
| 60 | |
| 61 virtual void TearDown() OVERRIDE { | |
| 62 EXPECT_CALL(*mock_doc_service_, CancelAll()).Times(1); | |
| 45 } | 63 } |
| 46 | 64 |
| 47 // Loads test json file as root ("/gdata") element. | 65 // Loads test json file as root ("/gdata") element. |
| 48 void LoadRootFeedDocument(const std::string& filename) { | 66 void LoadRootFeedDocument(const std::string& filename) { |
| 49 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata")), filename); | 67 LoadSubdirFeedDocument(FilePath(FPL("gdata")), filename); |
| 50 } | 68 } |
| 51 | 69 |
| 52 // Loads test json file as subdirectory content of |directory_path|. | 70 // Loads test json file as subdirectory content of |directory_path|. |
| 53 void LoadSubdirFeedDocument(const FilePath& directory_path, | 71 void LoadSubdirFeedDocument(const FilePath& directory_path, |
| 54 const std::string& filename) { | 72 const std::string& filename) { |
| 55 std::string error; | 73 std::string error; |
| 56 scoped_ptr<Value> document(LoadJSONFile(filename)); | 74 scoped_ptr<Value> document(LoadJSONFile(filename)); |
| 57 ASSERT_TRUE(document.get()); | 75 ASSERT_TRUE(document.get()); |
| 58 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); | 76 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); |
| 59 GURL unused; | 77 GURL unused; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 EXPECT_TRUE(file_util::PathExists(path)) << | 150 EXPECT_TRUE(file_util::PathExists(path)) << |
| 133 "Couldn't find " << path.value(); | 151 "Couldn't find " << path.value(); |
| 134 | 152 |
| 135 JSONFileValueSerializer serializer(path); | 153 JSONFileValueSerializer serializer(path); |
| 136 Value* value = serializer.Deserialize(NULL, &error); | 154 Value* value = serializer.Deserialize(NULL, &error); |
| 137 EXPECT_TRUE(value) << | 155 EXPECT_TRUE(value) << |
| 138 "Parse error " << path.value() << ": " << error; | 156 "Parse error " << path.value() << ": " << error; |
| 139 return value; | 157 return value; |
| 140 } | 158 } |
| 141 | 159 |
| 160 class CallbackHelper | |
|
satorux1
2012/03/08 01:48:37
nit: class comment missing. what's this used for?
Greg Spencer (Chromium)
2012/03/08 19:06:35
Done.
| |
| 161 : public base::RefCountedThreadSafe<CallbackHelper> { | |
| 162 public: | |
| 163 CallbackHelper() : last_error_(base::PLATFORM_FILE_OK) {} | |
| 164 virtual ~CallbackHelper() {} | |
| 165 virtual void GetFileCallback(base::PlatformFileError error, | |
| 166 const FilePath& file_path) { | |
| 167 last_error_ = error; | |
| 168 download_path_ = file_path; | |
| 169 } | |
| 170 virtual void FileOperationCallback(base::PlatformFileError error) { | |
| 171 last_error_ = error; | |
| 172 } | |
| 173 | |
| 174 base::PlatformFileError last_error_; | |
| 175 FilePath download_path_; | |
| 176 }; | |
| 177 | |
| 142 MessageLoopForUI message_loop_; | 178 MessageLoopForUI message_loop_; |
| 143 content::TestBrowserThread ui_thread_; | 179 content::TestBrowserThread ui_thread_; |
| 144 scoped_ptr<TestingProfile> profile_; | 180 scoped_ptr<TestingProfile> profile_; |
| 181 scoped_refptr<CallbackHelper> callback_helper_; | |
| 145 GDataFileSystem* file_system_; | 182 GDataFileSystem* file_system_; |
| 183 MockDocumentsService* mock_doc_service_; | |
| 146 }; | 184 }; |
| 147 | 185 |
| 148 | 186 |
| 149 // Delegate used to find a directory element for file system updates. | 187 // Delegate used to find a directory element for file system updates. |
| 150 class MockFindFileDelegate : public gdata::FindFileDelegate { | 188 class MockFindFileDelegate : public gdata::FindFileDelegate { |
| 151 public: | 189 public: |
| 152 MockFindFileDelegate() { | 190 MockFindFileDelegate() { |
| 153 } | 191 } |
| 154 | 192 |
| 155 virtual ~MockFindFileDelegate() { | 193 virtual ~MockFindFileDelegate() { |
| 156 } | 194 } |
| 157 | 195 |
| 158 // gdata::FindFileDelegate overrides. | 196 // gdata::FindFileDelegate overrides. |
| 159 MOCK_METHOD1(OnFileFound, void(GDataFile*)); | 197 MOCK_METHOD1(OnFileFound, void(GDataFile*)); |
| 160 MOCK_METHOD2(OnDirectoryFound, void(const FilePath&, GDataDirectory* dir)); | 198 MOCK_METHOD2(OnDirectoryFound, void(const FilePath&, GDataDirectory* dir)); |
| 161 MOCK_METHOD2(OnEnterDirectory, FindFileTraversalCommand( | 199 MOCK_METHOD2(OnEnterDirectory, FindFileTraversalCommand( |
| 162 const FilePath&, GDataDirectory* dir)); | 200 const FilePath&, GDataDirectory* dir)); |
| 163 MOCK_METHOD1(OnError, void(base::PlatformFileError)); | 201 MOCK_METHOD1(OnError, void(base::PlatformFileError)); |
| 164 }; | 202 }; |
| 165 | 203 |
| 166 TEST_F(GDataFileSystemTest, SearchRootDirectory) { | 204 TEST_F(GDataFileSystemTest, SearchRootDirectory) { |
| 167 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 205 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 168 new MockFindFileDelegate(); | 206 new MockFindFileDelegate(); |
| 169 | 207 |
| 170 EXPECT_CALL(*mock_find_file_delegate.get(), | 208 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 171 OnDirectoryFound(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 209 OnDirectoryFound(FilePath(FPL("gdata")), _)) |
| 172 .Times(1); | 210 .Times(1); |
| 173 | 211 |
| 174 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata")), | 212 file_system_->FindFileByPath(FilePath(FPL("gdata")), |
| 175 mock_find_file_delegate); | 213 mock_find_file_delegate); |
| 176 } | 214 } |
| 177 | 215 |
| 178 TEST_F(GDataFileSystemTest, SearchExistingFile) { | 216 TEST_F(GDataFileSystemTest, SearchExistingFile) { |
| 179 LoadRootFeedDocument("root_feed.json"); | 217 LoadRootFeedDocument("root_feed.json"); |
| 180 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 218 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 181 new MockFindFileDelegate(); | 219 new MockFindFileDelegate(); |
| 182 | 220 |
| 183 EXPECT_CALL(*mock_find_file_delegate.get(), | 221 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 184 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 222 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 185 .Times(1) | 223 .Times(1) |
| 186 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 224 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 187 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 225 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 188 .Times(1); | 226 .Times(1); |
| 189 | 227 |
| 190 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata/File 1.txt")), | 228 file_system_->FindFileByPath(FilePath(FPL("gdata/File 1.txt")), |
| 191 mock_find_file_delegate); | 229 mock_find_file_delegate); |
| 192 } | 230 } |
| 193 | 231 |
| 194 TEST_F(GDataFileSystemTest, SearchExistingDocument) { | 232 TEST_F(GDataFileSystemTest, SearchExistingDocument) { |
| 195 LoadRootFeedDocument("root_feed.json"); | 233 LoadRootFeedDocument("root_feed.json"); |
| 196 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 234 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 197 new MockFindFileDelegate(); | 235 new MockFindFileDelegate(); |
| 198 | 236 |
| 199 EXPECT_CALL(*mock_find_file_delegate.get(), | 237 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 200 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 238 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 201 .Times(1) | 239 .Times(1) |
| 202 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 240 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 203 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 241 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 204 .Times(1); | 242 .Times(1); |
| 205 | 243 |
| 206 file_system_->FindFileByPath( | 244 file_system_->FindFileByPath( |
| 207 FilePath(FILE_PATH_LITERAL("gdata/Document 1.gdoc")), | 245 FilePath(FPL("gdata/Document 1.gdoc")), |
| 208 mock_find_file_delegate); | 246 mock_find_file_delegate); |
| 209 } | 247 } |
| 210 | 248 |
| 211 TEST_F(GDataFileSystemTest, SearchDuplicateNames) { | 249 TEST_F(GDataFileSystemTest, SearchDuplicateNames) { |
| 212 LoadRootFeedDocument("root_feed.json"); | 250 LoadRootFeedDocument("root_feed.json"); |
| 213 | 251 |
| 214 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 252 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 215 new MockFindFileDelegate(); | 253 new MockFindFileDelegate(); |
| 216 EXPECT_CALL(*mock_find_file_delegate.get(), | 254 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 217 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 255 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 218 .Times(1) | 256 .Times(1) |
| 219 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 257 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 220 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 258 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 221 .Times(1); | 259 .Times(1); |
| 222 file_system_->FindFileByPath( | 260 file_system_->FindFileByPath( |
| 223 FilePath(FILE_PATH_LITERAL("gdata/Duplicate Name.txt")), | 261 FilePath(FPL("gdata/Duplicate Name.txt")), |
| 224 mock_find_file_delegate); | 262 mock_find_file_delegate); |
| 225 | 263 |
| 226 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate2 = | 264 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate2 = |
| 227 new MockFindFileDelegate(); | 265 new MockFindFileDelegate(); |
| 228 EXPECT_CALL(*mock_find_file_delegate2.get(), | 266 EXPECT_CALL(*mock_find_file_delegate2.get(), |
| 229 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 267 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 230 .Times(1) | 268 .Times(1) |
| 231 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 269 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 232 EXPECT_CALL(*mock_find_file_delegate2.get(), OnFileFound(_)) | 270 EXPECT_CALL(*mock_find_file_delegate2.get(), OnFileFound(_)) |
| 233 .Times(1); | 271 .Times(1); |
| 234 file_system_->FindFileByPath( | 272 file_system_->FindFileByPath( |
| 235 FilePath(FILE_PATH_LITERAL("gdata/Duplicate Name (2).txt")), | 273 FilePath(FPL("gdata/Duplicate Name (2).txt")), |
| 236 mock_find_file_delegate2); | 274 mock_find_file_delegate2); |
| 237 } | 275 } |
| 238 | 276 |
| 239 TEST_F(GDataFileSystemTest, SearchExistingDirectory) { | 277 TEST_F(GDataFileSystemTest, SearchExistingDirectory) { |
| 240 LoadRootFeedDocument("root_feed.json"); | 278 LoadRootFeedDocument("root_feed.json"); |
| 241 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 279 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 242 new MockFindFileDelegate(); | 280 new MockFindFileDelegate(); |
| 243 | 281 |
| 244 EXPECT_CALL(*mock_find_file_delegate.get(), | 282 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 245 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 283 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 246 .Times(1) | 284 .Times(1) |
| 247 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 285 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 248 EXPECT_CALL(*mock_find_file_delegate.get(), OnDirectoryFound(_, _)) | 286 EXPECT_CALL(*mock_find_file_delegate.get(), OnDirectoryFound(_, _)) |
| 249 .Times(1); | 287 .Times(1); |
| 250 | 288 |
| 251 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 289 file_system_->FindFileByPath(FilePath(FPL("gdata/Directory 1")), |
| 252 mock_find_file_delegate); | 290 mock_find_file_delegate); |
| 253 } | 291 } |
| 254 | 292 |
| 255 | 293 |
| 256 TEST_F(GDataFileSystemTest, SearchNonExistingFile) { | 294 TEST_F(GDataFileSystemTest, SearchNonExistingFile) { |
| 257 LoadRootFeedDocument("root_feed.json"); | 295 LoadRootFeedDocument("root_feed.json"); |
| 258 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 296 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 259 new MockFindFileDelegate(); | 297 new MockFindFileDelegate(); |
| 260 | 298 |
| 261 EXPECT_CALL(*mock_find_file_delegate.get(), | 299 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 262 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 300 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 263 .Times(1) | 301 .Times(1) |
| 264 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 302 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 265 EXPECT_CALL(*mock_find_file_delegate.get(), | 303 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 266 OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND)) | 304 OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND)) |
| 267 .Times(1); | 305 .Times(1); |
| 268 | 306 |
| 269 file_system_->FindFileByPath( | 307 file_system_->FindFileByPath( |
| 270 FilePath(FILE_PATH_LITERAL("gdata/nonexisting.file")), | 308 FilePath(FPL("gdata/nonexisting.file")), |
| 271 mock_find_file_delegate); | 309 mock_find_file_delegate); |
| 272 } | 310 } |
| 273 | 311 |
| 274 TEST_F(GDataFileSystemTest, StopFileSearch) { | 312 TEST_F(GDataFileSystemTest, StopFileSearch) { |
| 275 LoadRootFeedDocument("root_feed.json"); | 313 LoadRootFeedDocument("root_feed.json"); |
| 276 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 314 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 277 new MockFindFileDelegate(); | 315 new MockFindFileDelegate(); |
| 278 | 316 |
| 279 // Stop on first directory entry. | 317 // Stop on first directory entry. |
| 280 EXPECT_CALL(*mock_find_file_delegate.get(), | 318 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 281 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 319 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 282 .Times(1) | 320 .Times(1) |
| 283 .WillOnce(Return(FindFileDelegate::FIND_FILE_TERMINATES)); | 321 .WillOnce(Return(FindFileDelegate::FIND_FILE_TERMINATES)); |
| 284 | 322 |
| 285 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 323 file_system_->FindFileByPath(FilePath(FPL("gdata/Directory 1")), |
| 286 mock_find_file_delegate); | 324 mock_find_file_delegate); |
| 287 } | 325 } |
| 288 | 326 |
| 289 TEST_F(GDataFileSystemTest, SearchInSubdir) { | 327 TEST_F(GDataFileSystemTest, SearchInSubdir) { |
| 290 LoadRootFeedDocument("root_feed.json"); | 328 LoadRootFeedDocument("root_feed.json"); |
| 291 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 329 LoadSubdirFeedDocument(FilePath(FPL("gdata/Directory 1")), |
| 292 "subdir_feed.json"); | 330 "subdir_feed.json"); |
| 293 | 331 |
| 294 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 332 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 295 new MockFindFileDelegate(); | 333 new MockFindFileDelegate(); |
| 296 | 334 |
| 297 EXPECT_CALL(*mock_find_file_delegate.get(), | 335 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 298 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) | 336 OnEnterDirectory(FilePath(FPL("gdata")), _)) |
| 299 .Times(1) | 337 .Times(1) |
| 300 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 338 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 301 | 339 |
| 302 EXPECT_CALL(*mock_find_file_delegate.get(), | 340 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 303 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 341 OnEnterDirectory(FilePath(FPL("gdata/Directory 1")), |
| 304 _)) | 342 _)) |
| 305 .Times(1) | 343 .Times(1) |
| 306 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 344 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 307 | 345 |
| 308 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 346 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 309 .Times(1); | 347 .Times(1); |
| 310 | 348 |
| 311 file_system_->FindFileByPath( | 349 file_system_->FindFileByPath( |
| 312 FilePath(FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt")), | 350 FilePath(FPL("gdata/Directory 1/SubDirectory File 1.txt")), |
| 313 mock_find_file_delegate); | 351 mock_find_file_delegate); |
| 314 } | 352 } |
| 315 | 353 |
| 316 TEST_F(GDataFileSystemTest, FilePathTests) { | 354 TEST_F(GDataFileSystemTest, FilePathTests) { |
| 317 LoadRootFeedDocument("root_feed.json"); | 355 LoadRootFeedDocument("root_feed.json"); |
| 318 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 356 LoadSubdirFeedDocument(FilePath(FPL("gdata/Directory 1")), |
| 319 "subdir_feed.json"); | 357 "subdir_feed.json"); |
| 320 | 358 |
| 321 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/File 1.txt"))); | 359 FindAndTestFilePath(FilePath(FPL("gdata/File 1.txt"))); |
| 322 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))); | 360 FindAndTestFilePath(FilePath(FPL("gdata/Directory 1"))); |
| 323 FindAndTestFilePath( | 361 FindAndTestFilePath( |
| 324 FilePath(FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt"))); | 362 FilePath(FPL("gdata/Directory 1/SubDirectory File 1.txt"))); |
| 325 } | 363 } |
| 326 | 364 |
| 327 TEST_F(GDataFileSystemTest, RemoveFiles) { | 365 TEST_F(GDataFileSystemTest, RemoveFiles) { |
| 328 LoadRootFeedDocument("root_feed.json"); | 366 LoadRootFeedDocument("root_feed.json"); |
| 329 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 367 LoadSubdirFeedDocument(FilePath(FPL("gdata/Directory 1")), |
| 330 "subdir_feed.json"); | 368 "subdir_feed.json"); |
| 331 | 369 |
| 332 FilePath nonexisting_file(FILE_PATH_LITERAL("gdata/Dummy file.txt")); | 370 FilePath nonexisting_file(FPL("gdata/Dummy file.txt")); |
| 333 FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt")); | 371 FilePath file_in_root(FPL("gdata/File 1.txt")); |
| 334 FilePath dir_in_root(FILE_PATH_LITERAL("gdata/Directory 1")); | 372 FilePath dir_in_root(FPL("gdata/Directory 1")); |
| 335 FilePath file_in_subdir( | 373 FilePath file_in_subdir( |
| 336 FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt")); | 374 FPL("gdata/Directory 1/SubDirectory File 1.txt")); |
| 337 | 375 |
| 338 EXPECT_TRUE(FindFile(file_in_root) != NULL); | 376 EXPECT_TRUE(FindFile(file_in_root) != NULL); |
| 339 EXPECT_TRUE(FindFile(dir_in_root) != NULL); | 377 EXPECT_TRUE(FindFile(dir_in_root) != NULL); |
| 340 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); | 378 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); |
| 341 | 379 |
| 342 // Remove first file in root. | 380 // Remove first file in root. |
| 343 EXPECT_TRUE(RemoveFile(file_in_root)); | 381 EXPECT_TRUE(RemoveFile(file_in_root)); |
| 344 EXPECT_TRUE(FindFile(file_in_root) == NULL); | 382 EXPECT_TRUE(FindFile(file_in_root) == NULL); |
| 345 EXPECT_TRUE(FindFile(dir_in_root) != NULL); | 383 EXPECT_TRUE(FindFile(dir_in_root) != NULL); |
| 346 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); | 384 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); |
| 347 | 385 |
| 348 // Remove directory. | 386 // Remove directory. |
| 349 EXPECT_TRUE(RemoveFile(dir_in_root)); | 387 EXPECT_TRUE(RemoveFile(dir_in_root)); |
| 350 EXPECT_TRUE(FindFile(file_in_root) == NULL); | 388 EXPECT_TRUE(FindFile(file_in_root) == NULL); |
| 351 EXPECT_TRUE(FindFile(dir_in_root) == NULL); | 389 EXPECT_TRUE(FindFile(dir_in_root) == NULL); |
| 352 EXPECT_TRUE(FindFile(file_in_subdir) == NULL); | 390 EXPECT_TRUE(FindFile(file_in_subdir) == NULL); |
| 353 | 391 |
| 354 // Try removing file in already removed subdirectory. | 392 // Try removing file in already removed subdirectory. |
| 355 EXPECT_FALSE(RemoveFile(file_in_subdir)); | 393 EXPECT_FALSE(RemoveFile(file_in_subdir)); |
| 356 | 394 |
| 357 // Try removing non-existing file. | 395 // Try removing non-existing file. |
| 358 EXPECT_FALSE(RemoveFile(nonexisting_file)); | 396 EXPECT_FALSE(RemoveFile(nonexisting_file)); |
| 359 | 397 |
| 360 // Try removing root file element. | 398 // Try removing root file element. |
| 361 EXPECT_FALSE(RemoveFile(FilePath(FILE_PATH_LITERAL("gdata")))); | 399 EXPECT_FALSE(RemoveFile(FilePath(FPL("gdata")))); |
| 362 } | 400 } |
| 363 | 401 |
| 364 TEST_F(GDataFileSystemTest, CreateDirectory) { | 402 TEST_F(GDataFileSystemTest, CreateDirectory) { |
| 365 LoadRootFeedDocument("root_feed.json"); | 403 LoadRootFeedDocument("root_feed.json"); |
| 366 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 404 LoadSubdirFeedDocument(FilePath(FPL("gdata/Directory 1")), |
| 367 "subdir_feed.json"); | 405 "subdir_feed.json"); |
| 368 | 406 |
| 369 // Create directory in root. | 407 // Create directory in root. |
| 370 FilePath dir_path(FILE_PATH_LITERAL("gdata/New Folder 1")); | 408 FilePath dir_path(FPL("gdata/New Folder 1")); |
| 371 EXPECT_TRUE(FindFile(dir_path) == NULL); | 409 EXPECT_TRUE(FindFile(dir_path) == NULL); |
| 372 AddDirectoryFromFile(dir_path, "directory_entry_atom.json"); | 410 AddDirectoryFromFile(dir_path, "directory_entry_atom.json"); |
| 373 EXPECT_TRUE(FindFile(dir_path) != NULL); | 411 EXPECT_TRUE(FindFile(dir_path) != NULL); |
| 374 | 412 |
| 375 // Create directory in a sub dirrectory. | 413 // Create directory in a sub dirrectory. |
| 376 FilePath subdir_path(FILE_PATH_LITERAL("gdata/New Folder 1/New Folder 2")); | 414 FilePath subdir_path(FPL("gdata/New Folder 1/New Folder 2")); |
| 377 EXPECT_TRUE(FindFile(subdir_path) == NULL); | 415 EXPECT_TRUE(FindFile(subdir_path) == NULL); |
| 378 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json"); | 416 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json"); |
| 379 EXPECT_TRUE(FindFile(subdir_path) != NULL); | 417 EXPECT_TRUE(FindFile(subdir_path) != NULL); |
| 380 } | 418 } |
| 381 | 419 |
| 382 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) { | 420 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) { |
| 383 LoadRootFeedDocument("root_feed.json"); | 421 LoadRootFeedDocument("root_feed.json"); |
| 384 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 422 LoadSubdirFeedDocument(FilePath(FPL("gdata/Directory 1")), |
| 385 "subdir_feed.json"); | 423 "subdir_feed.json"); |
| 386 | 424 |
| 387 GURL last_dir_content_url; | 425 GURL last_dir_content_url; |
| 388 FilePath first_missing_parent_path; | 426 FilePath first_missing_parent_path; |
| 389 | 427 |
| 390 // Create directory in root. | 428 // Create directory in root. |
| 391 FilePath dir_path(FILE_PATH_LITERAL("gdata/New Folder 1")); | 429 FilePath dir_path(FPL("gdata/New Folder 1")); |
| 392 EXPECT_EQ( | 430 EXPECT_EQ( |
| 393 GDataFileSystem::FOUND_MISSING, | 431 GDataFileSystem::FOUND_MISSING, |
| 394 file_system_->FindFirstMissingParentDirectory(dir_path, | 432 file_system_->FindFirstMissingParentDirectory(dir_path, |
| 395 &last_dir_content_url, | 433 &last_dir_content_url, |
| 396 &first_missing_parent_path)); | 434 &first_missing_parent_path)); |
| 397 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("gdata/New Folder 1")), | 435 EXPECT_EQ(FilePath(FPL("gdata/New Folder 1")), |
| 398 first_missing_parent_path); | 436 first_missing_parent_path); |
| 399 EXPECT_TRUE(last_dir_content_url.is_empty()); // root directory. | 437 EXPECT_TRUE(last_dir_content_url.is_empty()); // root directory. |
| 400 | 438 |
| 401 // Missing folders in subdir of an existing folder. | 439 // Missing folders in subdir of an existing folder. |
| 402 FilePath dir_path2(FILE_PATH_LITERAL("gdata/Directory 1/New Folder 2")); | 440 FilePath dir_path2(FPL("gdata/Directory 1/New Folder 2")); |
| 403 EXPECT_EQ( | 441 EXPECT_EQ( |
| 404 GDataFileSystem::FOUND_MISSING, | 442 GDataFileSystem::FOUND_MISSING, |
| 405 file_system_->FindFirstMissingParentDirectory(dir_path2, | 443 file_system_->FindFirstMissingParentDirectory(dir_path2, |
| 406 &last_dir_content_url, | 444 &last_dir_content_url, |
| 407 &first_missing_parent_path)); | 445 &first_missing_parent_path)); |
| 408 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("gdata/Directory 1/New Folder 2")), | 446 EXPECT_EQ(FilePath(FPL("gdata/Directory 1/New Folder 2")), |
| 409 first_missing_parent_path); | 447 first_missing_parent_path); |
| 410 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. | 448 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. |
| 411 | 449 |
| 412 // Missing two folders on the path. | 450 // Missing two folders on the path. |
| 413 FilePath dir_path3 = dir_path2.Append(FILE_PATH_LITERAL("Another Foder")); | 451 FilePath dir_path3 = dir_path2.Append(FPL("Another Folder")); |
| 414 EXPECT_EQ( | 452 EXPECT_EQ( |
| 415 GDataFileSystem::FOUND_MISSING, | 453 GDataFileSystem::FOUND_MISSING, |
| 416 file_system_->FindFirstMissingParentDirectory(dir_path3, | 454 file_system_->FindFirstMissingParentDirectory(dir_path3, |
| 417 &last_dir_content_url, | 455 &last_dir_content_url, |
| 418 &first_missing_parent_path)); | 456 &first_missing_parent_path)); |
| 419 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("gdata/Directory 1/New Folder 2")), | 457 EXPECT_EQ(FilePath(FPL("gdata/Directory 1/New Folder 2")), |
| 420 first_missing_parent_path); | 458 first_missing_parent_path); |
| 421 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. | 459 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. |
| 422 | 460 |
| 423 // Folders on top of an existing file. | 461 // Folders on top of an existing file. |
| 424 EXPECT_EQ( | 462 EXPECT_EQ( |
| 425 GDataFileSystem::FOUND_INVALID, | 463 GDataFileSystem::FOUND_INVALID, |
| 426 file_system_->FindFirstMissingParentDirectory( | 464 file_system_->FindFirstMissingParentDirectory( |
| 427 FilePath(FILE_PATH_LITERAL("gdata/File 1.txt/BadDir")), | 465 FilePath(FPL("gdata/File 1.txt/BadDir")), |
| 428 &last_dir_content_url, | 466 &last_dir_content_url, |
| 429 &first_missing_parent_path)); | 467 &first_missing_parent_path)); |
| 430 | 468 |
| 431 // Existing folder. | 469 // Existing folder. |
| 432 EXPECT_EQ( | 470 EXPECT_EQ( |
| 433 GDataFileSystem::DIRECTORY_ALREADY_PRESENT, | 471 GDataFileSystem::DIRECTORY_ALREADY_PRESENT, |
| 434 file_system_->FindFirstMissingParentDirectory( | 472 file_system_->FindFirstMissingParentDirectory( |
| 435 FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), | 473 FilePath(FPL("gdata/Directory 1")), |
| 436 &last_dir_content_url, | 474 &last_dir_content_url, |
| 437 &first_missing_parent_path)); | 475 &first_missing_parent_path)); |
| 438 } | 476 } |
| 439 | 477 |
| 440 // TODO(satorux): Write a test for GetFile() once DocumentsService is | |
| 441 // mockable. | |
|
satorux1
2012/03/08 01:48:37
Thank you for addressing my TODO!
Greg Spencer (Chromium)
2012/03/08 19:06:35
No problem. :-)
| |
| 442 | |
| 443 TEST_F(GDataFileSystemTest, GetGDataFileInfoFromPath) { | 478 TEST_F(GDataFileSystemTest, GetGDataFileInfoFromPath) { |
| 444 LoadRootFeedDocument("root_feed.json"); | 479 LoadRootFeedDocument("root_feed.json"); |
| 445 | 480 |
| 446 GDataFileBase* file_info = file_system_->GetGDataFileInfoFromPath( | 481 GDataFileBase* file_info = file_system_->GetGDataFileInfoFromPath( |
| 447 FilePath(FILE_PATH_LITERAL("gdata/File 1.txt"))); | 482 FilePath(FPL("gdata/File 1.txt"))); |
| 448 ASSERT_TRUE(file_info != NULL); | 483 ASSERT_TRUE(file_info != NULL); |
| 449 EXPECT_EQ("https://file_link_self/", file_info->self_url().spec()); | 484 EXPECT_EQ("https://file_link_self/", file_info->self_url().spec()); |
| 450 EXPECT_EQ("https://file_content_url/", file_info->content_url().spec()); | 485 EXPECT_EQ("https://file_content_url/", file_info->content_url().spec()); |
| 451 | 486 |
| 452 GDataFileBase* non_existent = file_system_->GetGDataFileInfoFromPath( | 487 GDataFileBase* non_existent = file_system_->GetGDataFileInfoFromPath( |
| 453 FilePath(FILE_PATH_LITERAL("gdata/Nonexistent.txt"))); | 488 FilePath(FPL("gdata/Nonexistent.txt"))); |
| 454 ASSERT_TRUE(non_existent == NULL); | 489 ASSERT_TRUE(non_existent == NULL); |
| 455 } | 490 } |
| 456 | 491 |
| 492 // Create a directory through the document service | |
| 493 TEST_F(GDataFileSystemTest, CreateDirectoryWithService) { | |
| 494 LoadRootFeedDocument("root_feed.json"); | |
| 495 EXPECT_CALL(*mock_doc_service_, | |
| 496 CreateDirectory(_, "Sample Directory Title", _)).Times(1); | |
| 497 | |
| 498 // Set last error so it's not a valid error code. | |
| 499 callback_helper_->last_error_ = static_cast<base::PlatformFileError>(1); | |
| 500 file_system_->CreateDirectory( | |
| 501 FilePath(FPL("gdata/Sample Directory Title")), | |
| 502 false, // is_exclusive | |
| 503 true, // is_recursive | |
| 504 base::Bind(&CallbackHelper::FileOperationCallback, | |
| 505 callback_helper_.get())); | |
| 506 // TODO(gspencer): Uncomment this when we get a blob that | |
| 507 // works that can be returned from the mock. | |
| 508 // EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); | |
| 509 } | |
| 510 | |
| 511 TEST_F(GDataFileSystemTest, GetFile) { | |
| 512 LoadRootFeedDocument("root_feed.json"); | |
| 513 | |
| 514 GDataFileSystem::GetFileCallback callback = | |
| 515 base::Bind(&CallbackHelper::GetFileCallback, | |
| 516 callback_helper_.get()); | |
| 517 | |
| 518 EXPECT_CALL(*mock_doc_service_, | |
| 519 DownloadFile(GURL("https://file_content_url/"), _)); | |
| 520 | |
| 521 FilePath file_in_root(FPL("gdata/File 1.txt")); | |
| 522 file_system_->GetFile(file_in_root, callback); | |
| 523 EXPECT_STREQ("file_content_url/", | |
| 524 callback_helper_->download_path_.value().c_str()); | |
| 525 } | |
| 457 } // namespace gdata | 526 } // namespace gdata |
| OLD | NEW |