From 4fe61bc24f343a6a1381a782dec4fb45b2f6c437 Mon Sep 17 00:00:00 2001 From: "koz@chromium.org" Date: Wed, 27 Feb 2013 05:17:08 +0000 Subject: Track and persist what file entries an extension has access to. Note this change doesn't re-grant permissions to the extensions at any point. Subsequent patches will cause chrome to restore access to the file entries an extension had in the case of an unexpected crash (ie: onRestarted()). BUG=165832 Review URL: https://chromiumcodereview.appspot.com/11857009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184878 0039d316-1c4b-4281-b951-d872f2087c98 --- apps/app_restore_service_browsertest.cc | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'apps/app_restore_service_browsertest.cc') diff --git a/apps/app_restore_service_browsertest.cc b/apps/app_restore_service_browsertest.cc index 094812d..3eaf3ff 100644 --- a/apps/app_restore_service_browsertest.cc +++ b/apps/app_restore_service_browsertest.cc @@ -4,6 +4,8 @@ #include "apps/app_restore_service.h" #include "apps/app_restore_service_factory.h" +#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" +#include "chrome/browser/extensions/api/file_system/file_system_api.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" @@ -12,9 +14,12 @@ #include "chrome/common/extensions/extension.h" #include "content/public/test/test_utils.h" +using extensions::app_file_handler_util::SavedFileEntry; using extensions::Extension; using extensions::ExtensionPrefs; using extensions::ExtensionSystem; +using extensions::FileSystemChooseEntryFunction; + // TODO(benwells): Move PlatformAppBrowserTest to apps namespace in apps // component. using extensions::PlatformAppBrowserTest; @@ -52,4 +57,45 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, RunningAppsAreRecorded) { restart_listener.WaitUntilSatisfied(); } +IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsSavedToPrefs) { + content::WindowedNotificationObserver extension_suspended( + chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, + content::NotificationService::AllSources()); + + base::ScopedTempDir temp_directory; + ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); + base::FilePath temp_file; + ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_directory.path(), + &temp_file)); + + FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( + &temp_file); + + ExtensionTestMessageListener file_written_listener("fileWritten", false); + ExtensionTestMessageListener access_ok_listener( + "restartedFileAccessOK", false); + + const Extension* extension = + LoadAndLaunchPlatformApp("file_access_saved_to_prefs_test"); + ASSERT_TRUE(extension); + file_written_listener.WaitUntilSatisfied(); + + ExtensionService* extension_service = + ExtensionSystem::Get(browser()->profile())->extension_service(); + ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); + + // Record the file entries in prefs because when the app gets suspended it + // will have them all cleared. + std::vector file_entries; + extension_prefs->GetSavedFileEntries(extension->id(), &file_entries); + // One for the read-only file entry and one for the writable file entry. + ASSERT_EQ(2u, file_entries.size()); + + extension_suspended.Wait(); + file_entries.clear(); + extension_prefs->GetSavedFileEntries(extension->id(), &file_entries); + // File entries should be cleared when the extension is suspended. + ASSERT_TRUE(file_entries.empty()); +} + } // namespace apps -- cgit v1.1