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_impl.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/scoped_observer.h" | 9 #include "base/scoped_observer.h" |
10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/browser/apps/app_browsertest_util.h" | 12 #include "chrome/browser/apps/app_browsertest_util.h" |
13 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 13 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "extensions/browser/api/file_system/saved_files_service.h" |
16 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/browser/extension_registry_observer.h" | 19 #include "extensions/browser/extension_registry_observer.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 class BrowserContext; | 22 class BrowserContext; |
22 } | 23 } |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
(...skipping 21 matching lines...) Expand all Loading... |
47 | 48 |
48 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory, | 49 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory, |
49 ExtensionPrefs* prefs, | 50 ExtensionPrefs* prefs, |
50 const Extension* extension) { | 51 const Extension* extension) { |
51 file_system_api::SetLastChooseEntryDirectory( | 52 file_system_api::SetLastChooseEntryDirectory( |
52 prefs, extension->id(), choose_entry_directory); | 53 prefs, extension->id(), choose_entry_directory); |
53 } | 54 } |
54 | 55 |
55 void AddSavedEntry(const base::FilePath& path_to_save, | 56 void AddSavedEntry(const base::FilePath& path_to_save, |
56 bool is_directory, | 57 bool is_directory, |
57 apps::SavedFilesService* service, | 58 apps::SavedFilesServiceImpl* service, |
58 const Extension* extension) { | 59 const Extension* extension) { |
59 service->RegisterFileEntry( | 60 service->RegisterFileEntry( |
60 extension->id(), "magic id", path_to_save, is_directory); | 61 extension->id(), "magic id", path_to_save, is_directory); |
61 } | 62 } |
62 | 63 |
63 const int kGraylistedPath = base::DIR_HOME; | 64 const int kGraylistedPath = base::DIR_HOME; |
64 | 65 |
65 } // namespace | 66 } // namespace |
66 | 67 |
67 class FileSystemApiTest : public PlatformAppBrowserTest { | 68 class FileSystemApiTest : public PlatformAppBrowserTest { |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 << message_; | 609 << message_; |
609 } | 610 } |
610 | 611 |
611 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainEntry) { | 612 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainEntry) { |
612 base::FilePath test_file = TempFilePath("writable.txt", true); | 613 base::FilePath test_file = TempFilePath("writable.txt", true); |
613 ASSERT_FALSE(test_file.empty()); | 614 ASSERT_FALSE(test_file.empty()); |
614 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 615 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
615 &test_file); | 616 &test_file); |
616 ASSERT_TRUE(RunPlatformAppTest( | 617 ASSERT_TRUE(RunPlatformAppTest( |
617 "api_test/file_system/retain_entry")) << message_; | 618 "api_test/file_system/retain_entry")) << message_; |
618 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get( | 619 std::vector<SavedFilesService::Entry> file_entries = |
619 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id()); | 620 apps::SavedFilesServiceImpl::Get(profile())->GetAllFileEntries( |
| 621 GetSingleLoadedExtension()->id()); |
620 ASSERT_EQ(1u, file_entries.size()); | 622 ASSERT_EQ(1u, file_entries.size()); |
621 EXPECT_EQ(test_file, file_entries[0].path); | 623 EXPECT_EQ(test_file, file_entries[0].path); |
622 EXPECT_EQ(1, file_entries[0].sequence_number); | 624 EXPECT_EQ(1, file_entries[0].sequence_number); |
623 EXPECT_FALSE(file_entries[0].is_directory); | 625 EXPECT_FALSE(file_entries[0].is_directory); |
624 } | 626 } |
625 | 627 |
626 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) { | 628 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) { |
627 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 629 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
628 ASSERT_FALSE(test_file.empty()); | 630 ASSERT_FALSE(test_file.empty()); |
629 base::FilePath test_directory = test_file.DirName(); | 631 base::FilePath test_directory = test_file.DirName(); |
630 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 632 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
631 &test_directory); | 633 &test_directory); |
632 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/retain_directory")) | 634 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/retain_directory")) |
633 << message_; | 635 << message_; |
634 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get( | 636 std::vector<SavedFilesService::Entry> file_entries = |
635 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id()); | 637 apps::SavedFilesServiceImpl::Get(profile())->GetAllFileEntries( |
| 638 GetSingleLoadedExtension()->id()); |
636 ASSERT_EQ(1u, file_entries.size()); | 639 ASSERT_EQ(1u, file_entries.size()); |
637 EXPECT_EQ(test_directory, file_entries[0].path); | 640 EXPECT_EQ(test_directory, file_entries[0].path); |
638 EXPECT_EQ(1, file_entries[0].sequence_number); | 641 EXPECT_EQ(1, file_entries[0].sequence_number); |
639 EXPECT_TRUE(file_entries[0].is_directory); | 642 EXPECT_TRUE(file_entries[0].is_directory); |
640 } | 643 } |
641 | 644 |
642 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) { | 645 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) { |
643 base::FilePath test_file = TempFilePath("writable.txt", true); | 646 base::FilePath test_file = TempFilePath("writable.txt", true); |
644 ASSERT_FALSE(test_file.empty()); | 647 ASSERT_FALSE(test_file.empty()); |
645 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 648 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
646 &test_file); | 649 &test_file); |
647 AppLoadObserver observer(profile(), | 650 AppLoadObserver observer( |
648 base::Bind(AddSavedEntry, | 651 profile(), base::Bind(AddSavedEntry, test_file, false, |
649 test_file, | 652 apps::SavedFilesServiceImpl::Get(profile()))); |
650 false, | |
651 apps::SavedFilesService::Get(profile()))); | |
652 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry")) | 653 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry")) |
653 << message_; | 654 << message_; |
654 } | 655 } |
655 | 656 |
656 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) { | 657 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) { |
657 base::FilePath test_file = TempFilePath("writable.txt", true); | 658 base::FilePath test_file = TempFilePath("writable.txt", true); |
658 ASSERT_FALSE(test_file.empty()); | 659 ASSERT_FALSE(test_file.empty()); |
659 base::FilePath test_directory = test_file.DirName(); | 660 base::FilePath test_directory = test_file.DirName(); |
660 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 661 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
661 &test_file); | 662 &test_file); |
662 AppLoadObserver observer(profile(), | 663 AppLoadObserver observer( |
663 base::Bind(AddSavedEntry, | 664 profile(), base::Bind(AddSavedEntry, test_directory, true, |
664 test_directory, | 665 apps::SavedFilesServiceImpl::Get(profile()))); |
665 true, | |
666 apps::SavedFilesService::Get(profile()))); | |
667 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory")) | 666 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory")) |
668 << message_; | 667 << message_; |
669 } | 668 } |
670 | 669 |
671 #if !defined(OS_CHROMEOS) | 670 #if !defined(OS_CHROMEOS) |
672 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, RequestFileSystem_NotChromeOS) { | 671 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, RequestFileSystem_NotChromeOS) { |
673 ASSERT_TRUE(RunPlatformAppTestWithFlags( | 672 ASSERT_TRUE(RunPlatformAppTestWithFlags( |
674 "api_test/file_system/request_file_system_not_chromeos", | 673 "api_test/file_system/request_file_system_not_chromeos", |
675 kFlagIgnoreManifestWarnings)) | 674 kFlagIgnoreManifestWarnings)) |
676 << message_; | 675 << message_; |
677 } | 676 } |
678 #endif | 677 #endif |
679 | 678 |
680 } // namespace extensions | 679 } // namespace extensions |
OLD | NEW |