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 "apps/saved_files_service.h" | 5 #include "apps/saved_files_service.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 "test_temp", temp_dir_.path()); | 90 "test_temp", temp_dir_.path()); |
91 | 91 |
92 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name); | 92 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name); |
93 if (copy_gold) { | 93 if (copy_gold) { |
94 base::FilePath source = test_root_folder_.AppendASCII("gold.txt"); | 94 base::FilePath source = test_root_folder_.AppendASCII("gold.txt"); |
95 EXPECT_TRUE(base::CopyFile(source, destination)); | 95 EXPECT_TRUE(base::CopyFile(source, destination)); |
96 } | 96 } |
97 return destination; | 97 return destination; |
98 } | 98 } |
99 | 99 |
| 100 std::vector<base::FilePath> TempFilePaths( |
| 101 const std::vector<std::string>& destination_names, |
| 102 bool copy_gold) { |
| 103 if (!temp_dir_.CreateUniqueTempDir()) { |
| 104 ADD_FAILURE() << "CreateUniqueTempDir failed"; |
| 105 return std::vector<base::FilePath>(); |
| 106 } |
| 107 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( |
| 108 "test_temp", temp_dir_.path()); |
| 109 |
| 110 std::vector<base::FilePath> result; |
| 111 for (std::vector<std::string>::const_iterator it = |
| 112 destination_names.begin(); |
| 113 it != destination_names.end(); ++it) { |
| 114 base::FilePath destination = temp_dir_.path().AppendASCII(*it); |
| 115 if (copy_gold) { |
| 116 base::FilePath source = test_root_folder_.AppendASCII("gold.txt"); |
| 117 EXPECT_TRUE(base::CopyFile(source, destination)); |
| 118 } |
| 119 result.push_back(destination); |
| 120 } |
| 121 return result; |
| 122 } |
| 123 |
100 void CheckStoredDirectoryMatches(const base::FilePath& filename) { | 124 void CheckStoredDirectoryMatches(const base::FilePath& filename) { |
101 const Extension* extension = GetSingleLoadedExtension(); | 125 const Extension* extension = GetSingleLoadedExtension(); |
102 ASSERT_TRUE(extension); | 126 ASSERT_TRUE(extension); |
103 std::string extension_id = extension->id(); | 127 std::string extension_id = extension->id(); |
104 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 128 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
105 base::FilePath stored_value; | 129 base::FilePath stored_value; |
106 if (filename.empty()) { | 130 if (filename.empty()) { |
107 EXPECT_FALSE(file_system_api::GetLastChooseEntryDirectory( | 131 EXPECT_FALSE(file_system_api::GetLastChooseEntryDirectory( |
108 prefs, extension_id, &stored_value)); | 132 prefs, extension_id, &stored_value)); |
109 } else { | 133 } else { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 240 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
217 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); | 241 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); |
218 FileSystemChooseEntryFunction:: | 242 FileSystemChooseEntryFunction:: |
219 SkipPickerAndSelectSuggestedPathForTest(); | 243 SkipPickerAndSelectSuggestedPathForTest(); |
220 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) | 244 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) |
221 << message_; | 245 << message_; |
222 CheckStoredDirectoryMatches(test_file); | 246 CheckStoredDirectoryMatches(test_file); |
223 } | 247 } |
224 | 248 |
225 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 249 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 250 FileSystemApiOpenMultipleSuggested) { |
| 251 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 252 ASSERT_FALSE(test_file.empty()); |
| 253 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 254 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); |
| 255 FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest(); |
| 256 ASSERT_TRUE(RunPlatformAppTest( |
| 257 "api_test/file_system/open_multiple_with_suggested_name")) |
| 258 << message_; |
| 259 CheckStoredDirectoryMatches(test_file); |
| 260 } |
| 261 |
| 262 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 263 FileSystemApiOpenMultipleExistingFilesTest) { |
| 264 std::vector<std::string> names; |
| 265 names.push_back("open_existing1.txt"); |
| 266 names.push_back("open_existing2.txt"); |
| 267 std::vector<base::FilePath> test_files = TempFilePaths(names, true); |
| 268 ASSERT_EQ(2u, test_files.size()); |
| 269 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( |
| 270 &test_files); |
| 271 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing")) |
| 272 << message_; |
| 273 } |
| 274 |
| 275 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
226 FileSystemApiInvalidChooseEntryTypeTest) { | 276 FileSystemApiInvalidChooseEntryTypeTest) { |
227 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 277 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
228 ASSERT_FALSE(test_file.empty()); | 278 ASSERT_FALSE(test_file.empty()); |
229 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 279 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
230 &test_file); | 280 &test_file); |
231 ASSERT_TRUE(RunPlatformAppTest( | 281 ASSERT_TRUE(RunPlatformAppTest( |
232 "api_test/file_system/invalid_choose_file_type")) << message_; | 282 "api_test/file_system/invalid_choose_file_type")) << message_; |
233 CheckStoredDirectoryMatches(base::FilePath()); | 283 CheckStoredDirectoryMatches(base::FilePath()); |
234 } | 284 } |
235 | 285 |
(...skipping 29 matching lines...) Expand all Loading... |
265 FileSystemApiOpenWritableExistingFileWithWriteTest) { | 315 FileSystemApiOpenWritableExistingFileWithWriteTest) { |
266 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 316 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
267 ASSERT_FALSE(test_file.empty()); | 317 ASSERT_FALSE(test_file.empty()); |
268 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 318 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
269 &test_file); | 319 &test_file); |
270 ASSERT_TRUE(RunPlatformAppTest( | 320 ASSERT_TRUE(RunPlatformAppTest( |
271 "api_test/file_system/open_writable_existing_with_write")) << message_; | 321 "api_test/file_system/open_writable_existing_with_write")) << message_; |
272 CheckStoredDirectoryMatches(test_file); | 322 CheckStoredDirectoryMatches(test_file); |
273 } | 323 } |
274 | 324 |
| 325 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 326 FileSystemApiOpenMultipleWritableExistingFilesTest) { |
| 327 std::vector<std::string> names; |
| 328 names.push_back("open_existing1.txt"); |
| 329 names.push_back("open_existing2.txt"); |
| 330 std::vector<base::FilePath> test_files = TempFilePaths(names, true); |
| 331 ASSERT_EQ(2u, test_files.size()); |
| 332 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( |
| 333 &test_files); |
| 334 ASSERT_TRUE(RunPlatformAppTest( |
| 335 "api_test/file_system/open_multiple_writable_existing_with_write")) |
| 336 << message_; |
| 337 } |
| 338 |
275 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) { | 339 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) { |
276 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); | 340 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); |
277 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel")) | 341 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel")) |
278 << message_; | 342 << message_; |
279 CheckStoredDirectoryMatches(base::FilePath()); | 343 CheckStoredDirectoryMatches(base::FilePath()); |
280 } | 344 } |
281 | 345 |
282 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) { | 346 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) { |
283 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background")) | 347 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background")) |
284 << message_; | 348 << message_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 FileSystemApiSaveExistingFileWithWriteTest) { | 383 FileSystemApiSaveExistingFileWithWriteTest) { |
320 base::FilePath test_file = TempFilePath("save_existing.txt", true); | 384 base::FilePath test_file = TempFilePath("save_existing.txt", true); |
321 ASSERT_FALSE(test_file.empty()); | 385 ASSERT_FALSE(test_file.empty()); |
322 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 386 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
323 &test_file); | 387 &test_file); |
324 ASSERT_TRUE(RunPlatformAppTest( | 388 ASSERT_TRUE(RunPlatformAppTest( |
325 "api_test/file_system/save_existing_with_write")) << message_; | 389 "api_test/file_system/save_existing_with_write")) << message_; |
326 CheckStoredDirectoryMatches(test_file); | 390 CheckStoredDirectoryMatches(test_file); |
327 } | 391 } |
328 | 392 |
| 393 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveMultipleFilesTest) { |
| 394 std::vector<std::string> names; |
| 395 names.push_back("save1.txt"); |
| 396 names.push_back("save2.txt"); |
| 397 std::vector<base::FilePath> test_files = TempFilePaths(names, false); |
| 398 ASSERT_EQ(2u, test_files.size()); |
| 399 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( |
| 400 &test_files); |
| 401 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_multiple")) |
| 402 << message_; |
| 403 } |
| 404 |
329 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) { | 405 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) { |
330 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); | 406 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); |
331 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel")) | 407 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel")) |
332 << message_; | 408 << message_; |
333 } | 409 } |
334 | 410 |
335 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) { | 411 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) { |
336 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background")) | 412 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background")) |
337 << message_; | 413 << message_; |
338 } | 414 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 AppInstallObserver observer( | 573 AppInstallObserver observer( |
498 base::Bind(SetLastChooseEntryDirectoryToAppDirectory, | 574 base::Bind(SetLastChooseEntryDirectoryToAppDirectory, |
499 ExtensionPrefs::Get(profile()))); | 575 ExtensionPrefs::Get(profile()))); |
500 ASSERT_TRUE(RunPlatformAppTest( | 576 ASSERT_TRUE(RunPlatformAppTest( |
501 "api_test/file_system/open_writable_existing_non_writable")) | 577 "api_test/file_system/open_writable_existing_non_writable")) |
502 << message_; | 578 << message_; |
503 } | 579 } |
504 } | 580 } |
505 | 581 |
506 } // namespace extensions | 582 } // namespace extensions |
OLD | NEW |