summaryrefslogtreecommitdiffstats
path: root/apps/app_restore_service_browsertest.cc
diff options
context:
space:
mode:
authorkoz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-27 05:17:08 +0000
committerkoz@chromium.org <koz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-27 05:17:08 +0000
commit4fe61bc24f343a6a1381a782dec4fb45b2f6c437 (patch)
tree8e77431d19888f90a707503ec231d23f7f6b2b56 /apps/app_restore_service_browsertest.cc
parente946986518a345ef3bc7c31e4af4a043734e74c3 (diff)
downloadchromium_src-4fe61bc24f343a6a1381a782dec4fb45b2f6c437.zip
chromium_src-4fe61bc24f343a6a1381a782dec4fb45b2f6c437.tar.gz
chromium_src-4fe61bc24f343a6a1381a782dec4fb45b2f6c437.tar.bz2
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
Diffstat (limited to 'apps/app_restore_service_browsertest.cc')
-rw-r--r--apps/app_restore_service_browsertest.cc46
1 files changed, 46 insertions, 0 deletions
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<SavedFileEntry> 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