| 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/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); | 145 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); |
| 146 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 146 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 147 &test_file); | 147 &test_file); |
| 148 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path")) | 148 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path")) |
| 149 << message_; | 149 << message_; |
| 150 } | 150 } |
| 151 | 151 |
| 152 #if defined(OS_WIN) || defined(OS_POSIX) | 152 #if defined(OS_WIN) || defined(OS_POSIX) |
| 153 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) { | 153 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) { |
| 154 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(base::DIR_HOME, | 154 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(base::DIR_HOME, |
| 155 test_root_folder_, false, false)); | 155 test_root_folder_, false)); |
| 156 | 156 |
| 157 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); | 157 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); |
| 158 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 158 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 159 &test_file); | 159 &test_file); |
| 160 ASSERT_TRUE(RunPlatformAppTest( | 160 ASSERT_TRUE(RunPlatformAppTest( |
| 161 "api_test/file_system/get_display_path_prettify")) << message_; | 161 "api_test/file_system/get_display_path_prettify")) << message_; |
| 162 } | 162 } |
| 163 #endif | 163 #endif |
| 164 | 164 |
| 165 #if defined(OS_MACOSX) | 165 #if defined(OS_MACOSX) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 << message_; | 205 << message_; |
| 206 } | 206 } |
| 207 CheckStoredDirectoryMatches(test_file); | 207 CheckStoredDirectoryMatches(test_file); |
| 208 } | 208 } |
| 209 | 209 |
| 210 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 210 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 211 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) { | 211 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) { |
| 212 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 212 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 213 ASSERT_FALSE(test_file.empty()); | 213 ASSERT_FALSE(test_file.empty()); |
| 214 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 214 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 215 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false)); | 215 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); |
| 216 FileSystemChooseEntryFunction:: | 216 FileSystemChooseEntryFunction:: |
| 217 SkipPickerAndSelectSuggestedPathForTest(); | 217 SkipPickerAndSelectSuggestedPathForTest(); |
| 218 { | 218 { |
| 219 AppInstallObserver observer(base::Bind( | 219 AppInstallObserver observer(base::Bind( |
| 220 SetLastChooseEntryDirectory, | 220 SetLastChooseEntryDirectory, |
| 221 test_file.DirName().Append( | 221 test_file.DirName().Append( |
| 222 base::FilePath::FromUTF8Unsafe("fake_directory_does_not_exist")), | 222 base::FilePath::FromUTF8Unsafe("fake_directory_does_not_exist")), |
| 223 ExtensionPrefs::Get(profile()))); | 223 ExtensionPrefs::Get(profile()))); |
| 224 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) | 224 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) |
| 225 << message_; | 225 << message_; |
| 226 } | 226 } |
| 227 CheckStoredDirectoryMatches(test_file); | 227 CheckStoredDirectoryMatches(test_file); |
| 228 } | 228 } |
| 229 | 229 |
| 230 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 230 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 231 FileSystemApiOpenExistingFileDefaultPathTest) { | 231 FileSystemApiOpenExistingFileDefaultPathTest) { |
| 232 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 232 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 233 ASSERT_FALSE(test_file.empty()); | 233 ASSERT_FALSE(test_file.empty()); |
| 234 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 234 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 235 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false)); | 235 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); |
| 236 FileSystemChooseEntryFunction:: | 236 FileSystemChooseEntryFunction:: |
| 237 SkipPickerAndSelectSuggestedPathForTest(); | 237 SkipPickerAndSelectSuggestedPathForTest(); |
| 238 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) | 238 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) |
| 239 << message_; | 239 << message_; |
| 240 CheckStoredDirectoryMatches(test_file); | 240 CheckStoredDirectoryMatches(test_file); |
| 241 } | 241 } |
| 242 | 242 |
| 243 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenMultipleSuggested) { | 243 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenMultipleSuggested) { |
| 244 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 244 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 245 ASSERT_FALSE(test_file.empty()); | 245 ASSERT_FALSE(test_file.empty()); |
| 246 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 246 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 247 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false)); | 247 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); |
| 248 FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest(); | 248 FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest(); |
| 249 ASSERT_TRUE(RunPlatformAppTest( | 249 ASSERT_TRUE(RunPlatformAppTest( |
| 250 "api_test/file_system/open_multiple_with_suggested_name")) | 250 "api_test/file_system/open_multiple_with_suggested_name")) |
| 251 << message_; | 251 << message_; |
| 252 CheckStoredDirectoryMatches(test_file); | 252 CheckStoredDirectoryMatches(test_file); |
| 253 } | 253 } |
| 254 | 254 |
| 255 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 255 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 256 FileSystemApiOpenMultipleExistingFilesTest) { | 256 FileSystemApiOpenMultipleExistingFilesTest) { |
| 257 std::vector<std::string> names; | 257 std::vector<std::string> names; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 316 } |
| 317 | 317 |
| 318 #if defined(OS_WIN) || defined(OS_POSIX) | 318 #if defined(OS_WIN) || defined(OS_POSIX) |
| 319 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 319 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 320 FileSystemApiOpenDirectoryOnGraylistAndAllowTest) { | 320 FileSystemApiOpenDirectoryOnGraylistAndAllowTest) { |
| 321 FileSystemChooseEntryFunction::SkipDirectoryConfirmationForTest(); | 321 FileSystemChooseEntryFunction::SkipDirectoryConfirmationForTest(); |
| 322 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 322 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 323 ASSERT_FALSE(test_file.empty()); | 323 ASSERT_FALSE(test_file.empty()); |
| 324 base::FilePath test_directory = test_file.DirName(); | 324 base::FilePath test_directory = test_file.DirName(); |
| 325 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 325 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 326 kGraylistedPath, test_directory, false, false)); | 326 kGraylistedPath, test_directory, false)); |
| 327 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 327 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 328 &test_directory); | 328 &test_directory); |
| 329 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory")) | 329 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory")) |
| 330 << message_; | 330 << message_; |
| 331 CheckStoredDirectoryMatches(test_file); | 331 CheckStoredDirectoryMatches(test_file); |
| 332 } | 332 } |
| 333 | 333 |
| 334 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 334 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 335 FileSystemApiOpenDirectoryOnGraylistTest) { | 335 FileSystemApiOpenDirectoryOnGraylistTest) { |
| 336 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest(); | 336 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest(); |
| 337 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 337 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 338 ASSERT_FALSE(test_file.empty()); | 338 ASSERT_FALSE(test_file.empty()); |
| 339 base::FilePath test_directory = test_file.DirName(); | 339 base::FilePath test_directory = test_file.DirName(); |
| 340 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 340 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 341 kGraylistedPath, test_directory, false, false)); | 341 kGraylistedPath, test_directory, false)); |
| 342 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 342 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 343 &test_directory); | 343 &test_directory); |
| 344 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel")) | 344 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel")) |
| 345 << message_; | 345 << message_; |
| 346 CheckStoredDirectoryMatches(test_file); | 346 CheckStoredDirectoryMatches(test_file); |
| 347 } | 347 } |
| 348 | 348 |
| 349 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 349 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 350 FileSystemApiOpenDirectoryContainingGraylistTest) { | 350 FileSystemApiOpenDirectoryContainingGraylistTest) { |
| 351 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest(); | 351 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest(); |
| 352 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 352 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 353 ASSERT_FALSE(test_file.empty()); | 353 ASSERT_FALSE(test_file.empty()); |
| 354 base::FilePath test_directory = test_file.DirName(); | 354 base::FilePath test_directory = test_file.DirName(); |
| 355 base::FilePath parent_directory = test_directory.DirName(); | 355 base::FilePath parent_directory = test_directory.DirName(); |
| 356 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 356 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 357 kGraylistedPath, test_directory, false, false)); | 357 kGraylistedPath, test_directory, false)); |
| 358 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 358 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 359 &parent_directory); | 359 &parent_directory); |
| 360 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel")) | 360 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel")) |
| 361 << message_; | 361 << message_; |
| 362 CheckStoredDirectoryMatches(test_directory); | 362 CheckStoredDirectoryMatches(test_directory); |
| 363 } | 363 } |
| 364 | 364 |
| 365 // Test that choosing a subdirectory of a path does not require confirmation. | 365 // Test that choosing a subdirectory of a path does not require confirmation. |
| 366 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 366 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 367 FileSystemApiOpenDirectorySubdirectoryOfGraylistTest) { | 367 FileSystemApiOpenDirectorySubdirectoryOfGraylistTest) { |
| 368 // If a dialog is erroneously displayed, auto cancel it, so that the test | 368 // If a dialog is erroneously displayed, auto cancel it, so that the test |
| 369 // fails. | 369 // fails. |
| 370 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest(); | 370 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest(); |
| 371 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 371 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 372 ASSERT_FALSE(test_file.empty()); | 372 ASSERT_FALSE(test_file.empty()); |
| 373 base::FilePath test_directory = test_file.DirName(); | 373 base::FilePath test_directory = test_file.DirName(); |
| 374 base::FilePath parent_directory = test_directory.DirName(); | 374 base::FilePath parent_directory = test_directory.DirName(); |
| 375 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 375 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
| 376 kGraylistedPath, parent_directory, false, false)); | 376 kGraylistedPath, parent_directory, false)); |
| 377 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 377 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 378 &test_directory); | 378 &test_directory); |
| 379 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory")) | 379 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory")) |
| 380 << message_; | 380 << message_; |
| 381 CheckStoredDirectoryMatches(test_file); | 381 CheckStoredDirectoryMatches(test_file); |
| 382 } | 382 } |
| 383 #endif // defined(OS_WIN) || defined(OS_POSIX) | 383 #endif // defined(OS_WIN) || defined(OS_POSIX) |
| 384 | 384 |
| 385 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 385 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 386 FileSystemApiInvalidChooseEntryTypeTest) { | 386 FileSystemApiInvalidChooseEntryTypeTest) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 AppInstallObserver observer( | 626 AppInstallObserver observer( |
| 627 base::Bind(AddSavedEntry, | 627 base::Bind(AddSavedEntry, |
| 628 test_directory, | 628 test_directory, |
| 629 true, | 629 true, |
| 630 apps::SavedFilesService::Get(profile()))); | 630 apps::SavedFilesService::Get(profile()))); |
| 631 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory")) | 631 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory")) |
| 632 << message_; | 632 << message_; |
| 633 } | 633 } |
| 634 | 634 |
| 635 } // namespace extensions | 635 } // namespace extensions |
| OLD | NEW |