| 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" |
| 11 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 11 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 12 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/extensions/features/feature_channel.h" |
| 14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class AppInstallObserver : public content::NotificationObserver { | 22 class AppInstallObserver : public content::NotificationObserver { |
| 22 public: | 23 public: |
| 23 AppInstallObserver( | 24 AppInstallObserver( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 49 } | 50 } |
| 50 | 51 |
| 51 void SetLastChooseEntryDirectoryToAppDirectory( | 52 void SetLastChooseEntryDirectoryToAppDirectory( |
| 52 ExtensionPrefs* prefs, | 53 ExtensionPrefs* prefs, |
| 53 const Extension* extension) { | 54 const Extension* extension) { |
| 54 file_system_api::SetLastChooseEntryDirectory( | 55 file_system_api::SetLastChooseEntryDirectory( |
| 55 prefs, extension->id(), extension->path()); | 56 prefs, extension->id(), extension->path()); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void AddSavedEntry(const base::FilePath& path_to_save, | 59 void AddSavedEntry(const base::FilePath& path_to_save, |
| 60 bool is_directory, |
| 59 apps::SavedFilesService* service, | 61 apps::SavedFilesService* service, |
| 60 const Extension* extension) { | 62 const Extension* extension) { |
| 61 service->RegisterFileEntry(extension->id(), "magic id", path_to_save); | 63 service->RegisterFileEntry( |
| 64 extension->id(), "magic id", path_to_save, is_directory); |
| 62 } | 65 } |
| 63 | 66 |
| 64 } // namespace | 67 } // namespace |
| 65 | 68 |
| 66 class FileSystemApiTest : public PlatformAppBrowserTest { | 69 class FileSystemApiTest : public PlatformAppBrowserTest { |
| 67 public: | 70 public: |
| 68 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 71 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 69 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 72 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 70 test_root_folder_ = test_data_dir_.AppendASCII("api_test") | 73 test_root_folder_ = test_data_dir_.AppendASCII("api_test") |
| 71 .AppendASCII("file_system"); | 74 .AppendASCII("file_system"); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 names.push_back("open_existing1.txt"); | 266 names.push_back("open_existing1.txt"); |
| 264 names.push_back("open_existing2.txt"); | 267 names.push_back("open_existing2.txt"); |
| 265 std::vector<base::FilePath> test_files = TempFilePaths(names, true); | 268 std::vector<base::FilePath> test_files = TempFilePaths(names, true); |
| 266 ASSERT_EQ(2u, test_files.size()); | 269 ASSERT_EQ(2u, test_files.size()); |
| 267 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( | 270 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( |
| 268 &test_files); | 271 &test_files); |
| 269 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing")) | 272 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing")) |
| 270 << message_; | 273 << message_; |
| 271 } | 274 } |
| 272 | 275 |
| 276 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenDirectoryTest) { |
| 277 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN); |
| 278 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 279 ASSERT_FALSE(test_file.empty()); |
| 280 base::FilePath test_directory = test_file.DirName(); |
| 281 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 282 &test_directory); |
| 283 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory")) |
| 284 << message_; |
| 285 CheckStoredDirectoryMatches(test_file); |
| 286 } |
| 287 |
| 288 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 289 FileSystemApiOpenDirectoryWithWriteTest) { |
| 290 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN); |
| 291 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 292 ASSERT_FALSE(test_file.empty()); |
| 293 base::FilePath test_directory = test_file.DirName(); |
| 294 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 295 &test_directory); |
| 296 ASSERT_TRUE( |
| 297 RunPlatformAppTest("api_test/file_system/open_directory_with_write")) |
| 298 << message_; |
| 299 CheckStoredDirectoryMatches(test_file); |
| 300 } |
| 301 |
| 302 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 303 FileSystemApiOpenDirectoryWithoutPermissionTest) { |
| 304 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 305 ASSERT_FALSE(test_file.empty()); |
| 306 base::FilePath test_directory = test_file.DirName(); |
| 307 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 308 &test_directory); |
| 309 ASSERT_TRUE(RunPlatformAppTest( |
| 310 "api_test/file_system/open_directory_without_permission")) |
| 311 << message_; |
| 312 CheckStoredDirectoryMatches(base::FilePath()); |
| 313 } |
| 314 |
| 273 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 315 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 274 FileSystemApiInvalidChooseEntryTypeTest) { | 316 FileSystemApiInvalidChooseEntryTypeTest) { |
| 275 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 317 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 276 ASSERT_FALSE(test_file.empty()); | 318 ASSERT_FALSE(test_file.empty()); |
| 277 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 319 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 278 &test_file); | 320 &test_file); |
| 279 ASSERT_TRUE(RunPlatformAppTest( | 321 ASSERT_TRUE(RunPlatformAppTest( |
| 280 "api_test/file_system/invalid_choose_file_type")) << message_; | 322 "api_test/file_system/invalid_choose_file_type")) << message_; |
| 281 CheckStoredDirectoryMatches(base::FilePath()); | 323 CheckStoredDirectoryMatches(base::FilePath()); |
| 282 } | 324 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 &test_file); | 499 &test_file); |
| 458 ASSERT_TRUE(RunPlatformAppTest( | 500 ASSERT_TRUE(RunPlatformAppTest( |
| 459 "api_test/file_system/retain_entry")) << message_; | 501 "api_test/file_system/retain_entry")) << message_; |
| 460 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get( | 502 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get( |
| 461 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id()); | 503 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id()); |
| 462 ASSERT_EQ(1u, file_entries.size()); | 504 ASSERT_EQ(1u, file_entries.size()); |
| 463 EXPECT_EQ(test_file, file_entries[0].path); | 505 EXPECT_EQ(test_file, file_entries[0].path); |
| 464 EXPECT_EQ(1, file_entries[0].sequence_number); | 506 EXPECT_EQ(1, file_entries[0].sequence_number); |
| 465 } | 507 } |
| 466 | 508 |
| 509 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) { |
| 510 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN); |
| 511 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
| 512 ASSERT_FALSE(test_file.empty()); |
| 513 base::FilePath test_directory = test_file.DirName(); |
| 514 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 515 &test_directory); |
| 516 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/retain_directory")) |
| 517 << message_; |
| 518 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get( |
| 519 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id()); |
| 520 ASSERT_EQ(1u, file_entries.size()); |
| 521 EXPECT_EQ(test_directory, file_entries[0].path); |
| 522 EXPECT_EQ(1, file_entries[0].sequence_number); |
| 523 EXPECT_TRUE(file_entries[0].is_directory); |
| 524 } |
| 525 |
| 467 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) { | 526 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) { |
| 468 base::FilePath test_file = TempFilePath("writable.txt", true); | 527 base::FilePath test_file = TempFilePath("writable.txt", true); |
| 469 ASSERT_FALSE(test_file.empty()); | 528 ASSERT_FALSE(test_file.empty()); |
| 470 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 529 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 471 &test_file); | 530 &test_file); |
| 472 { | 531 { |
| 473 AppInstallObserver observer(base::Bind( | 532 AppInstallObserver observer( |
| 474 AddSavedEntry, test_file, apps::SavedFilesService::Get(profile()))); | 533 base::Bind(AddSavedEntry, |
| 534 test_file, |
| 535 false, |
| 536 apps::SavedFilesService::Get(profile()))); |
| 475 ASSERT_TRUE(RunPlatformAppTest( | 537 ASSERT_TRUE(RunPlatformAppTest( |
| 476 "api_test/file_system/restore_entry")) << message_; | 538 "api_test/file_system/restore_entry")) << message_; |
| 477 } | 539 } |
| 478 } | 540 } |
| 479 | 541 |
| 542 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) { |
| 543 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN); |
| 544 base::FilePath test_file = TempFilePath("writable.txt", true); |
| 545 ASSERT_FALSE(test_file.empty()); |
| 546 base::FilePath test_directory = test_file.DirName(); |
| 547 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 548 &test_file); |
| 549 { |
| 550 AppInstallObserver observer( |
| 551 base::Bind(AddSavedEntry, |
| 552 test_directory, |
| 553 true, |
| 554 apps::SavedFilesService::Get(profile()))); |
| 555 ASSERT_TRUE(RunPlatformAppTest( |
| 556 "api_test/file_system/restore_directory")) << message_; |
| 557 } |
| 558 } |
| 559 |
| 480 } // namespace extensions | 560 } // namespace extensions |
| OLD | NEW |