Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: apps/app_restore_service_browsertest.cc

Issue 14607023: Add support for persistent file access in apps. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « apps/app_restore_service.cc ('k') | apps/apps.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/app_restore_service.h" 5 #include "apps/app_restore_service.h"
6 #include "apps/app_restore_service_factory.h" 6 #include "apps/app_restore_service_factory.h"
7 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 7 #include "apps/saved_files_service.h"
8 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 8 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
9 #include "chrome/browser/extensions/extension_prefs.h" 9 #include "chrome/browser/extensions/extension_prefs.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
11 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 11 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "content/public/test/test_utils.h" 13 #include "content/public/test/test_utils.h"
14 14
15 using extensions::app_file_handler_util::SavedFileEntry;
16 using extensions::Extension; 15 using extensions::Extension;
17 using extensions::ExtensionPrefs; 16 using extensions::ExtensionPrefs;
18 using extensions::ExtensionSystem; 17 using extensions::ExtensionSystem;
19 using extensions::FileSystemChooseEntryFunction; 18 using extensions::FileSystemChooseEntryFunction;
20 19
21 // TODO(benwells): Move PlatformAppBrowserTest to apps namespace in apps 20 // TODO(benwells): Move PlatformAppBrowserTest to apps namespace in apps
22 // component. 21 // component.
23 using extensions::PlatformAppBrowserTest; 22 using extensions::PlatformAppBrowserTest;
24 23
25 namespace apps { 24 namespace apps {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 70
72 ExtensionTestMessageListener file_written_listener("fileWritten", false); 71 ExtensionTestMessageListener file_written_listener("fileWritten", false);
73 ExtensionTestMessageListener access_ok_listener( 72 ExtensionTestMessageListener access_ok_listener(
74 "restartedFileAccessOK", false); 73 "restartedFileAccessOK", false);
75 74
76 const Extension* extension = 75 const Extension* extension =
77 LoadAndLaunchPlatformApp("file_access_saved_to_prefs_test"); 76 LoadAndLaunchPlatformApp("file_access_saved_to_prefs_test");
78 ASSERT_TRUE(extension); 77 ASSERT_TRUE(extension);
79 file_written_listener.WaitUntilSatisfied(); 78 file_written_listener.WaitUntilSatisfied();
80 79
81 ExtensionPrefs* extension_prefs = 80 SavedFilesService* saved_files_service = SavedFilesService::Get(profile());
82 ExtensionPrefs::Get(browser()->profile());
83 81
84 // Record the file entries in prefs because when the app gets suspended it 82 std::vector<SavedFileEntry> file_entries =
85 // will have them all cleared. 83 saved_files_service->GetAllFileEntries(extension->id());
86 std::vector<SavedFileEntry> file_entries;
87 extensions::app_file_handler_util::GetSavedFileEntries(
88 extension_prefs, extension->id(), &file_entries);
89 // One for the read-only file entry and one for the writable file entry. 84 // One for the read-only file entry and one for the writable file entry.
90 ASSERT_EQ(2u, file_entries.size()); 85 ASSERT_EQ(2u, file_entries.size());
91 86
92 extension_suspended.Wait(); 87 extension_suspended.Wait();
93 file_entries.clear(); 88 file_entries = saved_files_service->GetAllFileEntries(extension->id());
94 extensions::app_file_handler_util::GetSavedFileEntries(
95 extension_prefs, extension->id(), &file_entries);
96 // File entries should be cleared when the extension is suspended. 89 // File entries should be cleared when the extension is suspended.
97 ASSERT_TRUE(file_entries.empty()); 90 ASSERT_TRUE(file_entries.empty());
98 } 91 }
99 92
100 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) { 93 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) {
101 content::WindowedNotificationObserver extension_suspended( 94 content::WindowedNotificationObserver extension_suspended(
102 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 95 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
103 content::NotificationService::AllSources()); 96 content::NotificationService::AllSources());
104 97
105 base::ScopedTempDir temp_directory; 98 base::ScopedTempDir temp_directory;
(...skipping 11 matching lines...) Expand all
117 ExtensionTestMessageListener access_ok_listener( 110 ExtensionTestMessageListener access_ok_listener(
118 "restartedFileAccessOK", false); 111 "restartedFileAccessOK", false);
119 112
120 const Extension* extension = 113 const Extension* extension =
121 LoadAndLaunchPlatformApp("file_access_restored_test"); 114 LoadAndLaunchPlatformApp("file_access_restored_test");
122 ASSERT_TRUE(extension); 115 ASSERT_TRUE(extension);
123 file_written_listener.WaitUntilSatisfied(); 116 file_written_listener.WaitUntilSatisfied();
124 117
125 ExtensionPrefs* extension_prefs = 118 ExtensionPrefs* extension_prefs =
126 ExtensionPrefs::Get(browser()->profile()); 119 ExtensionPrefs::Get(browser()->profile());
127 // Record the file entries in prefs because when the app gets suspended it 120 SavedFilesService* saved_files_service = SavedFilesService::Get(profile());
128 // will have them all cleared. 121 std::vector<SavedFileEntry> file_entries =
129 std::vector<SavedFileEntry> file_entries; 122 saved_files_service->GetAllFileEntries(extension->id());
130 extensions::app_file_handler_util::GetSavedFileEntries(extension_prefs,
131 extension->id(),
132 &file_entries);
133 extension_suspended.Wait(); 123 extension_suspended.Wait();
134 124
135 // Simulate a restart by populating the preferences as if the browser didn't 125 // Simulate a restart by populating the preferences as if the browser didn't
136 // get time to clean itself up. 126 // get time to clean itself up.
137 extension_prefs->SetExtensionRunning(extension->id(), true); 127 extension_prefs->SetExtensionRunning(extension->id(), true);
138 for (std::vector<SavedFileEntry>::const_iterator it = file_entries.begin(); 128 for (std::vector<SavedFileEntry>::const_iterator it = file_entries.begin();
139 it != file_entries.end(); ++it) { 129 it != file_entries.end(); ++it) {
140 extensions::app_file_handler_util::AddSavedFileEntry( 130 saved_files_service->RegisterFileEntry(
141 extension_prefs, extension->id(), it->id, it->path, it->writable); 131 extension->id(), it->id, it->path, it->writable);
142 } 132 }
143 133
144 apps::AppRestoreServiceFactory::GetForProfile(browser()->profile())-> 134 apps::AppRestoreServiceFactory::GetForProfile(browser()->profile())->
145 HandleStartup(true); 135 HandleStartup(true);
146 136
147 access_ok_listener.WaitUntilSatisfied(); 137 access_ok_listener.WaitUntilSatisfied();
148 } 138 }
149 139
150 } // namespace apps 140 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_restore_service.cc ('k') | apps/apps.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698