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/extensions/api/file_system/file_system_api.h" | 9 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
10 #include "chrome/browser/extensions/extension_prefs.h" | 10 #include "chrome/browser/extensions/extension_prefs.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(file_util::CopyFile(source, destination)); | 95 EXPECT_TRUE(file_util::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(file_util::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 FileSystemApiOpenMultipleExistingFilesTest) { |
| 251 std::vector<std::string> names; |
| 252 names.push_back("open_existing1.txt"); |
| 253 names.push_back("open_existing2.txt"); |
| 254 std::vector<base::FilePath> test_files = TempFilePaths(names, true); |
| 255 ASSERT_EQ(2u, test_files.size()); |
| 256 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( |
| 257 &test_files); |
| 258 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing")) |
| 259 << message_; |
| 260 } |
| 261 |
| 262 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
226 FileSystemApiInvalidChooseEntryTypeTest) { | 263 FileSystemApiInvalidChooseEntryTypeTest) { |
227 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 264 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
228 ASSERT_FALSE(test_file.empty()); | 265 ASSERT_FALSE(test_file.empty()); |
229 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 266 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
230 &test_file); | 267 &test_file); |
231 ASSERT_TRUE(RunPlatformAppTest( | 268 ASSERT_TRUE(RunPlatformAppTest( |
232 "api_test/file_system/invalid_choose_file_type")) << message_; | 269 "api_test/file_system/invalid_choose_file_type")) << message_; |
233 CheckStoredDirectoryMatches(base::FilePath()); | 270 CheckStoredDirectoryMatches(base::FilePath()); |
234 } | 271 } |
235 | 272 |
(...skipping 29 matching lines...) Expand all Loading... |
265 FileSystemApiOpenWritableExistingFileWithWriteTest) { | 302 FileSystemApiOpenWritableExistingFileWithWriteTest) { |
266 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 303 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
267 ASSERT_FALSE(test_file.empty()); | 304 ASSERT_FALSE(test_file.empty()); |
268 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 305 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
269 &test_file); | 306 &test_file); |
270 ASSERT_TRUE(RunPlatformAppTest( | 307 ASSERT_TRUE(RunPlatformAppTest( |
271 "api_test/file_system/open_writable_existing_with_write")) << message_; | 308 "api_test/file_system/open_writable_existing_with_write")) << message_; |
272 CheckStoredDirectoryMatches(test_file); | 309 CheckStoredDirectoryMatches(test_file); |
273 } | 310 } |
274 | 311 |
| 312 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 313 FileSystemApiOpenMultipleWritableExistingFilesTest) { |
| 314 std::vector<std::string> names; |
| 315 names.push_back("open_existing1.txt"); |
| 316 names.push_back("open_existing2.txt"); |
| 317 std::vector<base::FilePath> test_files = TempFilePaths(names, true); |
| 318 ASSERT_EQ(2u, test_files.size()); |
| 319 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( |
| 320 &test_files); |
| 321 ASSERT_TRUE(RunPlatformAppTest( |
| 322 "api_test/file_system/open_multiple_writable_existing_with_write")) |
| 323 << message_; |
| 324 } |
| 325 |
275 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) { | 326 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) { |
276 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); | 327 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); |
277 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel")) | 328 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel")) |
278 << message_; | 329 << message_; |
279 CheckStoredDirectoryMatches(base::FilePath()); | 330 CheckStoredDirectoryMatches(base::FilePath()); |
280 } | 331 } |
281 | 332 |
282 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) { | 333 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) { |
283 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background")) | 334 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background")) |
284 << message_; | 335 << message_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 FileSystemApiSaveExistingFileWithWriteTest) { | 370 FileSystemApiSaveExistingFileWithWriteTest) { |
320 base::FilePath test_file = TempFilePath("save_existing.txt", true); | 371 base::FilePath test_file = TempFilePath("save_existing.txt", true); |
321 ASSERT_FALSE(test_file.empty()); | 372 ASSERT_FALSE(test_file.empty()); |
322 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 373 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
323 &test_file); | 374 &test_file); |
324 ASSERT_TRUE(RunPlatformAppTest( | 375 ASSERT_TRUE(RunPlatformAppTest( |
325 "api_test/file_system/save_existing_with_write")) << message_; | 376 "api_test/file_system/save_existing_with_write")) << message_; |
326 CheckStoredDirectoryMatches(test_file); | 377 CheckStoredDirectoryMatches(test_file); |
327 } | 378 } |
328 | 379 |
| 380 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveMultipleFilesTest) { |
| 381 std::vector<std::string> names; |
| 382 names.push_back("save1.txt"); |
| 383 names.push_back("save2.txt"); |
| 384 std::vector<base::FilePath> test_files = TempFilePaths(names, false); |
| 385 ASSERT_EQ(2u, test_files.size()); |
| 386 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( |
| 387 &test_files); |
| 388 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_multiple")) |
| 389 << message_; |
| 390 } |
| 391 |
329 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) { | 392 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) { |
330 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); | 393 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); |
331 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel")) | 394 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel")) |
332 << message_; | 395 << message_; |
333 } | 396 } |
334 | 397 |
335 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) { | 398 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) { |
336 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background")) | 399 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background")) |
337 << message_; | 400 << message_; |
338 } | 401 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 AppInstallObserver observer( | 560 AppInstallObserver observer( |
498 base::Bind(SetLastChooseEntryDirectoryToAppDirectory, | 561 base::Bind(SetLastChooseEntryDirectoryToAppDirectory, |
499 ExtensionPrefs::Get(profile()))); | 562 ExtensionPrefs::Get(profile()))); |
500 ASSERT_TRUE(RunPlatformAppTest( | 563 ASSERT_TRUE(RunPlatformAppTest( |
501 "api_test/file_system/open_writable_existing_non_writable")) | 564 "api_test/file_system/open_writable_existing_non_writable")) |
502 << message_; | 565 << message_; |
503 } | 566 } |
504 } | 567 } |
505 | 568 |
506 } // namespace extensions | 569 } // namespace extensions |
OLD | NEW |