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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_apitest.cc

Issue 14607023: Add support for persistent file access in apps. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: 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
OLDNEW
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 "base/file_util.h" 6 #include "base/file_util.h"
6 #include "base/path_service.h" 7 #include "base/path_service.h"
7 #include "build/build_config.h" 8 #include "build/build_config.h"
8 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 9 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
9 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 12 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
14 15
15 using extensions::FileSystemChooseEntryFunction; 16 using extensions::FileSystemChooseEntryFunction;
16 17
17 namespace { 18 namespace {
18 19
19 class AppInstallObserver : public content::NotificationObserver { 20 class AppInstallObserver : public content::NotificationObserver {
20 public: 21 public:
21 AppInstallObserver(const base::FilePath& choose_entry_directory, 22 AppInstallObserver(
22 extensions::ExtensionPrefs* prefs) 23 base::Callback<void(const extensions::Extension*)> callback)
23 : path_(choose_entry_directory), 24 : callback_(callback) {
24 prefs_(prefs) { 25 registrar_.Add(this,
25 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 26 chrome::NOTIFICATION_EXTENSION_LOADED,
26 content::NotificationService::AllSources()); 27 content::NotificationService::AllSources());
27 } 28 }
28 29
29 virtual void Observe(int type, 30 virtual void Observe(int type,
30 const content::NotificationSource& source, 31 const content::NotificationSource& source,
31 const content::NotificationDetails& details) OVERRIDE { 32 const content::NotificationDetails& details) OVERRIDE {
32 EXPECT_EQ(chrome::NOTIFICATION_EXTENSION_LOADED, type); 33 EXPECT_EQ(chrome::NOTIFICATION_EXTENSION_LOADED, type);
33 std::string extension_id = content::Details<const extensions::Extension>( 34 callback_.Run(content::Details<const extensions::Extension>(details).ptr());
34 details).ptr()->id();
35 prefs_->SetLastChooseEntryDirectory(extension_id, path_);
36 } 35 }
37 36
38 private: 37 private:
39 content::NotificationRegistrar registrar_; 38 content::NotificationRegistrar registrar_;
40 const base::FilePath path_; 39 base::Callback<void(const extensions::Extension*)> callback_;
41 extensions::ExtensionPrefs* prefs_;
42 DISALLOW_COPY_AND_ASSIGN(AppInstallObserver); 40 DISALLOW_COPY_AND_ASSIGN(AppInstallObserver);
43 }; 41 };
44 42
43 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory,
44 extensions::ExtensionPrefs* prefs,
45 const extensions::Extension* extension) {
46 prefs->SetLastChooseEntryDirectory(extension->id(), choose_entry_directory);
47 }
48
49 void AddSavedEntry(const base::FilePath& path_to_save,
50 apps::SavedFilesService* service,
51 const extensions::Extension* extension) {
52 service->RegisterFileEntry(extension->id(), "magic id", path_to_save, true);
koz (OOO until 15th September) 2013/05/24 00:13:16 Add inline comment to true to indicate what it is
Sam McNally 2013/05/24 00:46:03 Done.
53 }
54
45 } // namespace 55 } // namespace
46 56
47 class FileSystemApiTest : public extensions::PlatformAppBrowserTest { 57 class FileSystemApiTest : public extensions::PlatformAppBrowserTest {
48 public: 58 public:
49 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 59 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
50 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); 60 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
51 test_root_folder_ = test_data_dir_.AppendASCII("api_test") 61 test_root_folder_ = test_data_dir_.AppendASCII("api_test")
52 .AppendASCII("file_system"); 62 .AppendASCII("file_system");
53 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( 63 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
54 "test_root", test_root_folder_); 64 "test_root", test_root_folder_);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 164 }
155 165
156 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, 166 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
157 FileSystemApiOpenExistingFileUsingPreviousPathTest) { 167 FileSystemApiOpenExistingFileUsingPreviousPathTest) {
158 base::FilePath test_file = TempFilePath("open_existing.txt", true); 168 base::FilePath test_file = TempFilePath("open_existing.txt", true);
159 ASSERT_FALSE(test_file.empty()); 169 ASSERT_FALSE(test_file.empty());
160 FileSystemChooseEntryFunction:: 170 FileSystemChooseEntryFunction::
161 SkipPickerAndSelectSuggestedPathForTest(); 171 SkipPickerAndSelectSuggestedPathForTest();
162 { 172 {
163 AppInstallObserver observer( 173 AppInstallObserver observer(
164 test_file.DirName(), 174 base::Bind(SetLastChooseEntryDirectory,
165 extensions::ExtensionSystem::Get( 175 test_file.DirName(),
166 profile())->extension_service()->extension_prefs()); 176 extensions::ExtensionSystem::Get(
177 profile())->extension_service()->extension_prefs()));
167 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) 178 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
168 << message_; 179 << message_;
169 } 180 }
170 CheckStoredDirectoryMatches(test_file); 181 CheckStoredDirectoryMatches(test_file);
171 } 182 }
172 183
173 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, 184 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
174 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) { 185 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) {
175 base::FilePath test_file = TempFilePath("open_existing.txt", true); 186 base::FilePath test_file = TempFilePath("open_existing.txt", true);
176 ASSERT_FALSE(test_file.empty()); 187 ASSERT_FALSE(test_file.empty());
177 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( 188 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
178 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); 189 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false));
179 FileSystemChooseEntryFunction:: 190 FileSystemChooseEntryFunction::
180 SkipPickerAndSelectSuggestedPathForTest(); 191 SkipPickerAndSelectSuggestedPathForTest();
181 { 192 {
182 AppInstallObserver observer( 193 AppInstallObserver observer(base::Bind(
183 test_file.DirName().Append(base::FilePath::FromUTF8Unsafe( 194 SetLastChooseEntryDirectory,
184 "fake_directory_does_not_exist")), 195 test_file.DirName().Append(
196 base::FilePath::FromUTF8Unsafe("fake_directory_does_not_exist")),
185 extensions::ExtensionSystem::Get( 197 extensions::ExtensionSystem::Get(
186 profile())->extension_service()->extension_prefs()); 198 profile())->extension_service()->extension_prefs()));
187 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) 199 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
188 << message_; 200 << message_;
189 } 201 }
190 CheckStoredDirectoryMatches(test_file); 202 CheckStoredDirectoryMatches(test_file);
191 } 203 }
192 204
193 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, 205 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
194 FileSystemApiOpenExistingFileDefaultPathTest) { 206 FileSystemApiOpenExistingFileDefaultPathTest) {
195 base::FilePath test_file = TempFilePath("open_existing.txt", true); 207 base::FilePath test_file = TempFilePath("open_existing.txt", true);
196 ASSERT_FALSE(test_file.empty()); 208 ASSERT_FALSE(test_file.empty());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 345
334 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) { 346 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) {
335 base::FilePath test_file = TempFilePath("writable.txt", true); 347 base::FilePath test_file = TempFilePath("writable.txt", true);
336 ASSERT_FALSE(test_file.empty()); 348 ASSERT_FALSE(test_file.empty());
337 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 349 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
338 &test_file); 350 &test_file);
339 ASSERT_TRUE(RunPlatformAppTest( 351 ASSERT_TRUE(RunPlatformAppTest(
340 "api_test/file_system/is_writable_file_entry")) << message_; 352 "api_test/file_system/is_writable_file_entry")) << message_;
341 } 353 }
342 354
343 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetEntryId) { 355 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainEntry) {
344 base::FilePath test_file = TempFilePath("writable.txt", true); 356 base::FilePath test_file = TempFilePath("writable.txt", true);
345 ASSERT_FALSE(test_file.empty()); 357 ASSERT_FALSE(test_file.empty());
346 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 358 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
347 &test_file); 359 &test_file);
348 ASSERT_TRUE(RunPlatformAppTest( 360 ASSERT_TRUE(RunPlatformAppTest(
349 "api_test/file_system/get_entry_id")) << message_; 361 "api_test/file_system/retain_entry")) << message_;
362 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get(
363 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id());
364 ASSERT_EQ(1u, file_entries.size());
365 EXPECT_EQ(test_file, file_entries[0].path);
366 EXPECT_EQ(1, file_entries[0].sequence_number);
367 EXPECT_FALSE(file_entries[0].writable);
350 } 368 }
369
370 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) {
371 base::FilePath test_file = TempFilePath("writable.txt", true);
372 ASSERT_FALSE(test_file.empty());
373 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
374 &test_file);
375 {
376 AppInstallObserver observer(base::Bind(
377 AddSavedEntry, test_file, apps::SavedFilesService::Get(profile())));
378 ASSERT_TRUE(RunPlatformAppTest(
379 "api_test/file_system/restore_entry")) << message_;
380 }
381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698