| Index: chrome/browser/extensions/api/file_system/file_system_apitest.cc
|
| diff --git a/chrome/browser/extensions/api/file_system/file_system_apitest.cc b/chrome/browser/extensions/api/file_system/file_system_apitest.cc
|
| index 018b74913f747cdfca2e05a52107ccd6d9bbed23..ec551de6cf6cf7302c006b3138d8dd64f3b92892 100644
|
| --- a/chrome/browser/extensions/api/file_system/file_system_apitest.cc
|
| +++ b/chrome/browser/extensions/api/file_system/file_system_apitest.cc
|
| @@ -6,6 +6,7 @@
|
| #include "base/path_service.h"
|
| #include "build/build_config.h"
|
| #include "chrome/browser/extensions/api/file_system/file_system_api.h"
|
| +#include "chrome/browser/extensions/api/file_system/saved_files_service.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_system.h"
|
| #include "chrome/browser/extensions/platform_app_browsertest_util.h"
|
| @@ -16,13 +17,16 @@ using extensions::FileSystemChooseEntryFunction;
|
|
|
| namespace {
|
|
|
| -class AppInstallObserver : public content::NotificationObserver {
|
| +class SetLastChooseEntryDirectoryObserver
|
| + : public content::NotificationObserver {
|
| public:
|
| - AppInstallObserver(const base::FilePath& choose_entry_directory,
|
| - extensions::ExtensionPrefs* prefs)
|
| + SetLastChooseEntryDirectoryObserver(
|
| + const base::FilePath& choose_entry_directory,
|
| + extensions::ExtensionPrefs* prefs)
|
| : path_(choose_entry_directory),
|
| prefs_(prefs) {
|
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
|
| + registrar_.Add(this,
|
| + chrome::NOTIFICATION_EXTENSION_LOADED,
|
| content::NotificationService::AllSources());
|
| }
|
|
|
| @@ -30,8 +34,8 @@ class AppInstallObserver : public content::NotificationObserver {
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) OVERRIDE {
|
| EXPECT_EQ(chrome::NOTIFICATION_EXTENSION_LOADED, type);
|
| - std::string extension_id = content::Details<const extensions::Extension>(
|
| - details).ptr()->id();
|
| + std::string extension_id =
|
| + content::Details<const extensions::Extension>(details).ptr()->id();
|
| prefs_->SetLastChooseEntryDirectory(extension_id, path_);
|
| }
|
|
|
| @@ -39,7 +43,34 @@ class AppInstallObserver : public content::NotificationObserver {
|
| content::NotificationRegistrar registrar_;
|
| const base::FilePath path_;
|
| extensions::ExtensionPrefs* prefs_;
|
| - DISALLOW_COPY_AND_ASSIGN(AppInstallObserver);
|
| + DISALLOW_COPY_AND_ASSIGN(SetLastChooseEntryDirectoryObserver);
|
| +};
|
| +
|
| +class AddSavedEntryObserver : public content::NotificationObserver {
|
| + public:
|
| + AddSavedEntryObserver(const base::FilePath& path_to_save,
|
| + extensions::SavedFilesService* service)
|
| + : path_(path_to_save),
|
| + service_(service) {
|
| + registrar_.Add(this,
|
| + chrome::NOTIFICATION_EXTENSION_LOADED,
|
| + content::NotificationService::AllSources());
|
| + }
|
| +
|
| + virtual void Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) OVERRIDE {
|
| + EXPECT_EQ(chrome::NOTIFICATION_EXTENSION_LOADED, type);
|
| + std::string extension_id =
|
| + content::Details<const extensions::Extension>(details).ptr()->id();
|
| + service_->AddFileEntry(extension_id, "magic id", path_, true);
|
| + }
|
| +
|
| + private:
|
| + content::NotificationRegistrar registrar_;
|
| + const base::FilePath path_;
|
| + extensions::SavedFilesService* service_;
|
| + DISALLOW_COPY_AND_ASSIGN(AddSavedEntryObserver);
|
| };
|
|
|
| } // namespace
|
| @@ -160,7 +191,7 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
|
| FileSystemChooseEntryFunction::
|
| SkipPickerAndSelectSuggestedPathForTest();
|
| {
|
| - AppInstallObserver observer(
|
| + SetLastChooseEntryDirectoryObserver observer(
|
| test_file.DirName(),
|
| extensions::ExtensionSystem::Get(
|
| profile())->extension_service()->extension_prefs());
|
| @@ -179,7 +210,7 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
|
| FileSystemChooseEntryFunction::
|
| SkipPickerAndSelectSuggestedPathForTest();
|
| {
|
| - AppInstallObserver observer(
|
| + SetLastChooseEntryDirectoryObserver observer(
|
| test_file.DirName().Append(base::FilePath::FromUTF8Unsafe(
|
| "fake_directory_does_not_exist")),
|
| extensions::ExtensionSystem::Get(
|
| @@ -340,11 +371,31 @@ IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) {
|
| "api_test/file_system/is_writable_file_entry")) << message_;
|
| }
|
|
|
| -IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetEntryId) {
|
| +IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainEntry) {
|
| base::FilePath test_file = TempFilePath("writable.txt", true);
|
| ASSERT_FALSE(test_file.empty());
|
| FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
|
| &test_file);
|
| ASSERT_TRUE(RunPlatformAppTest(
|
| - "api_test/file_system/get_entry_id")) << message_;
|
| + "api_test/file_system/retain_entry")) << message_;
|
| + std::vector<extensions::SavedFileEntry> file_entries;
|
| + extensions::SavedFilesService::Get(profile())->GetFileEntries(
|
| + GetSingleLoadedExtension()->id(), &file_entries);
|
| + ASSERT_EQ(1u, file_entries.size());
|
| + EXPECT_EQ(test_file, file_entries[0].path);
|
| + EXPECT_EQ(1, file_entries[0].sequence_number);
|
| + EXPECT_FALSE(file_entries[0].writable);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) {
|
| + base::FilePath test_file = TempFilePath("writable.txt", true);
|
| + ASSERT_FALSE(test_file.empty());
|
| + FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
|
| + &test_file);
|
| + {
|
| + AddSavedEntryObserver observer(
|
| + test_file, extensions::SavedFilesService::Get(profile()));
|
| + ASSERT_TRUE(RunPlatformAppTest(
|
| + "api_test/file_system/restore_entry")) << message_;
|
| + }
|
| }
|
|
|