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
3 // found in the LICENSE file.
5 #include "apps/saved_files_service.h"
6 #include "base/files/file_util.h"
7 #include "base/path_service.h"
8 #include "base/scoped_observer.h"
9 #include "build/build_config.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "extensions/browser/extension_prefs.h"
15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/browser/extension_registry_observer.h"
22 namespace extensions {
26 class AppLoadObserver : public ExtensionRegistryObserver {
28 AppLoadObserver(content::BrowserContext* browser_context,
29 base::Callback<void(const Extension*)> callback)
30 : callback_(callback), extension_registry_observer_(this) {
31 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context));
34 void OnExtensionLoaded(content::BrowserContext* browser_context,
35 const Extension* extension) override {
36 callback_.Run(extension);
40 base::Callback<void(const Extension*)> callback_;
41 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
42 extension_registry_observer_;
43 DISALLOW_COPY_AND_ASSIGN(AppLoadObserver);
46 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory,
47 ExtensionPrefs* prefs,
48 const Extension* extension) {
49 file_system_api::SetLastChooseEntryDirectory(
50 prefs, extension->id(), choose_entry_directory);
53 void AddSavedEntry(const base::FilePath& path_to_save,
55 apps::SavedFilesService* service,
56 const Extension* extension) {
57 service->RegisterFileEntry(
58 extension->id(), "magic id", path_to_save, is_directory);
61 const int kGraylistedPath = base::DIR_HOME;
65 class FileSystemApiTest : public PlatformAppBrowserTest {
67 void SetUpCommandLine(CommandLine* command_line) override {
68 PlatformAppBrowserTest::SetUpCommandLine(command_line);
69 test_root_folder_ = test_data_dir_.AppendASCII("api_test")
70 .AppendASCII("file_system");
71 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
72 "test_root", test_root_folder_);
75 void SetUpOnMainThread() override { ClearCommandLineArgs(); }
77 void TearDown() override {
78 FileSystemChooseEntryFunction::StopSkippingPickerForTest();
79 PlatformAppBrowserTest::TearDown();
83 base::FilePath TempFilePath(const std::string& destination_name,
85 if (!temp_dir_.CreateUniqueTempDir()) {
86 ADD_FAILURE() << "CreateUniqueTempDir failed";
87 return base::FilePath();
89 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
90 "test_temp", temp_dir_.path());
92 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name);
94 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
95 EXPECT_TRUE(base::CopyFile(source, destination));
100 std::vector<base::FilePath> TempFilePaths(
101 const std::vector<std::string>& destination_names,
103 if (!temp_dir_.CreateUniqueTempDir()) {
104 ADD_FAILURE() << "CreateUniqueTempDir failed";
105 return std::vector<base::FilePath>();
107 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
108 "test_temp", temp_dir_.path());
110 std::vector<base::FilePath> result;
111 for (std::vector<std::string>::const_iterator it =
112 destination_names.begin();
113 it != destination_names.end(); ++it) {
114 base::FilePath destination = temp_dir_.path().AppendASCII(*it);
116 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
117 EXPECT_TRUE(base::CopyFile(source, destination));
119 result.push_back(destination);
124 void CheckStoredDirectoryMatches(const base::FilePath& filename) {
125 const Extension* extension = GetSingleLoadedExtension();
126 ASSERT_TRUE(extension);
127 std::string extension_id = extension->id();
128 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
129 base::FilePath stored_value =
130 file_system_api::GetLastChooseEntryDirectory(prefs, extension_id);
131 if (filename.empty()) {
132 EXPECT_TRUE(stored_value.empty());
134 EXPECT_EQ(base::MakeAbsoluteFilePath(filename.DirName()),
135 base::MakeAbsoluteFilePath(stored_value));
139 base::FilePath test_root_folder_;
140 base::ScopedTempDir temp_dir_;
143 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) {
144 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
145 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
147 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path"))
151 #if defined(OS_WIN) || defined(OS_POSIX)
152 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) {
153 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(base::DIR_HOME,
154 test_root_folder_, false, false));
156 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
157 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
159 ASSERT_TRUE(RunPlatformAppTest(
160 "api_test/file_system/get_display_path_prettify")) << message_;
164 #if defined(OS_MACOSX)
165 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
166 FileSystemApiGetDisplayPathPrettifyMac) {
167 // On Mac, "test.localized" will be localized into just "test".
168 base::FilePath test_path = TempFilePath("test.localized", false);
169 ASSERT_TRUE(base::CreateDirectory(test_path));
171 base::FilePath test_file = test_path.AppendASCII("gold.txt");
172 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
173 EXPECT_TRUE(base::CopyFile(source, test_file));
175 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
177 ASSERT_TRUE(RunPlatformAppTest(
178 "api_test/file_system/get_display_path_prettify_mac")) << message_;
182 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) {
183 base::FilePath test_file = TempFilePath("open_existing.txt", true);
184 ASSERT_FALSE(test_file.empty());
185 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
187 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
189 CheckStoredDirectoryMatches(test_file);
192 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
193 FileSystemApiOpenExistingFileUsingPreviousPathTest) {
194 base::FilePath test_file = TempFilePath("open_existing.txt", true);
195 ASSERT_FALSE(test_file.empty());
196 FileSystemChooseEntryFunction::
197 SkipPickerAndSelectSuggestedPathForTest();
199 AppLoadObserver observer(profile(),
200 base::Bind(SetLastChooseEntryDirectory,
202 ExtensionPrefs::Get(profile())));
203 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
206 CheckStoredDirectoryMatches(test_file);
209 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
210 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) {
211 base::FilePath test_file = TempFilePath("open_existing.txt", true);
212 ASSERT_FALSE(test_file.empty());
213 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
214 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
215 FileSystemChooseEntryFunction::
216 SkipPickerAndSelectSuggestedPathForTest();
218 AppLoadObserver observer(
220 base::Bind(SetLastChooseEntryDirectory,
221 test_file.DirName().Append(base::FilePath::FromUTF8Unsafe(
222 "fake_directory_does_not_exist")),
223 ExtensionPrefs::Get(profile())));
224 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
227 CheckStoredDirectoryMatches(test_file);
230 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
231 FileSystemApiOpenExistingFileDefaultPathTest) {
232 base::FilePath test_file = TempFilePath("open_existing.txt", true);
233 ASSERT_FALSE(test_file.empty());
234 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
235 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
236 FileSystemChooseEntryFunction::
237 SkipPickerAndSelectSuggestedPathForTest();
238 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
240 CheckStoredDirectoryMatches(test_file);
243 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenMultipleSuggested) {
244 base::FilePath test_file = TempFilePath("open_existing.txt", true);
245 ASSERT_FALSE(test_file.empty());
246 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
247 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
248 FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest();
249 ASSERT_TRUE(RunPlatformAppTest(
250 "api_test/file_system/open_multiple_with_suggested_name"))
252 CheckStoredDirectoryMatches(test_file);
255 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
256 FileSystemApiOpenMultipleExistingFilesTest) {
257 std::vector<std::string> names;
258 names.push_back("open_existing1.txt");
259 names.push_back("open_existing2.txt");
260 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
261 ASSERT_EQ(2u, test_files.size());
262 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
264 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing"))
268 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenDirectoryTest) {
269 base::FilePath test_file = TempFilePath("open_existing.txt", true);
270 ASSERT_FALSE(test_file.empty());
271 base::FilePath test_directory = test_file.DirName();
272 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
274 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
276 CheckStoredDirectoryMatches(test_file);
279 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
280 FileSystemApiOpenDirectoryWithWriteTest) {
281 base::FilePath test_file = TempFilePath("open_existing.txt", true);
282 ASSERT_FALSE(test_file.empty());
283 base::FilePath test_directory = test_file.DirName();
284 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
287 RunPlatformAppTest("api_test/file_system/open_directory_with_write"))
289 CheckStoredDirectoryMatches(test_file);
292 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
293 FileSystemApiOpenDirectoryWithoutPermissionTest) {
294 base::FilePath test_file = TempFilePath("open_existing.txt", true);
295 ASSERT_FALSE(test_file.empty());
296 base::FilePath test_directory = test_file.DirName();
297 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
299 ASSERT_TRUE(RunPlatformAppTest(
300 "api_test/file_system/open_directory_without_permission"))
302 CheckStoredDirectoryMatches(base::FilePath());
305 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
306 FileSystemApiOpenDirectoryWithOnlyWritePermissionTest) {
307 base::FilePath test_file = TempFilePath("open_existing.txt", true);
308 ASSERT_FALSE(test_file.empty());
309 base::FilePath test_directory = test_file.DirName();
310 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
312 ASSERT_TRUE(RunPlatformAppTest(
313 "api_test/file_system/open_directory_with_only_write"))
315 CheckStoredDirectoryMatches(base::FilePath());
318 #if defined(OS_WIN) || defined(OS_POSIX)
319 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
320 FileSystemApiOpenDirectoryOnGraylistAndAllowTest) {
321 FileSystemChooseEntryFunction::SkipDirectoryConfirmationForTest();
322 base::FilePath test_file = TempFilePath("open_existing.txt", true);
323 ASSERT_FALSE(test_file.empty());
324 base::FilePath test_directory = test_file.DirName();
325 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
326 kGraylistedPath, test_directory, false, false));
327 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
329 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
331 CheckStoredDirectoryMatches(test_file);
334 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
335 FileSystemApiOpenDirectoryOnGraylistTest) {
336 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
337 base::FilePath test_file = TempFilePath("open_existing.txt", true);
338 ASSERT_FALSE(test_file.empty());
339 base::FilePath test_directory = test_file.DirName();
340 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
341 kGraylistedPath, test_directory, false, false));
342 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
344 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
346 CheckStoredDirectoryMatches(test_file);
349 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
350 FileSystemApiOpenDirectoryContainingGraylistTest) {
351 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
352 base::FilePath test_file = TempFilePath("open_existing.txt", true);
353 ASSERT_FALSE(test_file.empty());
354 base::FilePath test_directory = test_file.DirName();
355 base::FilePath parent_directory = test_directory.DirName();
356 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
357 kGraylistedPath, test_directory, false, false));
358 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
360 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
362 CheckStoredDirectoryMatches(test_directory);
365 // Test that choosing a subdirectory of a path does not require confirmation.
366 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
367 FileSystemApiOpenDirectorySubdirectoryOfGraylistTest) {
368 // If a dialog is erroneously displayed, auto cancel it, so that the test
370 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
371 base::FilePath test_file = TempFilePath("open_existing.txt", true);
372 ASSERT_FALSE(test_file.empty());
373 base::FilePath test_directory = test_file.DirName();
374 base::FilePath parent_directory = test_directory.DirName();
375 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
376 kGraylistedPath, parent_directory, false, false));
377 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
379 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
381 CheckStoredDirectoryMatches(test_file);
383 #endif // defined(OS_WIN) || defined(OS_POSIX)
385 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
386 FileSystemApiInvalidChooseEntryTypeTest) {
387 base::FilePath test_file = TempFilePath("open_existing.txt", true);
388 ASSERT_FALSE(test_file.empty());
389 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
391 ASSERT_TRUE(RunPlatformAppTest(
392 "api_test/file_system/invalid_choose_file_type")) << message_;
393 CheckStoredDirectoryMatches(base::FilePath());
396 // http://crbug.com/177163
397 #if defined(OS_WIN) && !defined(NDEBUG)
398 #define MAYBE_FileSystemApiOpenExistingFileWithWriteTest DISABLED_FileSystemApiOpenExistingFileWithWriteTest
400 #define MAYBE_FileSystemApiOpenExistingFileWithWriteTest FileSystemApiOpenExistingFileWithWriteTest
402 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
403 MAYBE_FileSystemApiOpenExistingFileWithWriteTest) {
404 base::FilePath test_file = TempFilePath("open_existing.txt", true);
405 ASSERT_FALSE(test_file.empty());
406 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
408 ASSERT_TRUE(RunPlatformAppTest(
409 "api_test/file_system/open_existing_with_write")) << message_;
410 CheckStoredDirectoryMatches(test_file);
413 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
414 FileSystemApiOpenWritableExistingFileTest) {
415 base::FilePath test_file = TempFilePath("open_existing.txt", true);
416 ASSERT_FALSE(test_file.empty());
417 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
419 ASSERT_TRUE(RunPlatformAppTest(
420 "api_test/file_system/open_writable_existing")) << message_;
421 CheckStoredDirectoryMatches(base::FilePath());
424 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
425 FileSystemApiOpenWritableExistingFileWithWriteTest) {
426 base::FilePath test_file = TempFilePath("open_existing.txt", true);
427 ASSERT_FALSE(test_file.empty());
428 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
430 ASSERT_TRUE(RunPlatformAppTest(
431 "api_test/file_system/open_writable_existing_with_write")) << message_;
432 CheckStoredDirectoryMatches(test_file);
435 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
436 FileSystemApiOpenMultipleWritableExistingFilesTest) {
437 std::vector<std::string> names;
438 names.push_back("open_existing1.txt");
439 names.push_back("open_existing2.txt");
440 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
441 ASSERT_EQ(2u, test_files.size());
442 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
444 ASSERT_TRUE(RunPlatformAppTest(
445 "api_test/file_system/open_multiple_writable_existing_with_write"))
449 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) {
450 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
451 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel"))
453 CheckStoredDirectoryMatches(base::FilePath());
456 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) {
457 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background"))
461 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveNewFileTest) {
462 base::FilePath test_file = TempFilePath("save_new.txt", false);
463 ASSERT_FALSE(test_file.empty());
464 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
466 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new"))
468 CheckStoredDirectoryMatches(base::FilePath());
471 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveExistingFileTest) {
472 base::FilePath test_file = TempFilePath("save_existing.txt", true);
473 ASSERT_FALSE(test_file.empty());
474 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
476 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_existing"))
478 CheckStoredDirectoryMatches(base::FilePath());
481 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
482 FileSystemApiSaveNewFileWithWriteTest) {
483 base::FilePath test_file = TempFilePath("save_new.txt", false);
484 ASSERT_FALSE(test_file.empty());
485 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
487 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new_with_write"))
489 CheckStoredDirectoryMatches(test_file);
492 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
493 FileSystemApiSaveExistingFileWithWriteTest) {
494 base::FilePath test_file = TempFilePath("save_existing.txt", true);
495 ASSERT_FALSE(test_file.empty());
496 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
498 ASSERT_TRUE(RunPlatformAppTest(
499 "api_test/file_system/save_existing_with_write")) << message_;
500 CheckStoredDirectoryMatches(test_file);
503 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveMultipleFilesTest) {
504 std::vector<std::string> names;
505 names.push_back("save1.txt");
506 names.push_back("save2.txt");
507 std::vector<base::FilePath> test_files = TempFilePaths(names, false);
508 ASSERT_EQ(2u, test_files.size());
509 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
511 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_multiple"))
515 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) {
516 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
517 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel"))
521 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) {
522 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background"))
526 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetWritableTest) {
527 base::FilePath test_file = TempFilePath("writable.txt", true);
528 ASSERT_FALSE(test_file.empty());
529 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
531 ASSERT_TRUE(RunPlatformAppTest(
532 "api_test/file_system/get_writable_file_entry")) << message_;
535 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
536 FileSystemApiGetWritableWithWriteTest) {
537 base::FilePath test_file = TempFilePath("writable.txt", true);
538 ASSERT_FALSE(test_file.empty());
539 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
541 ASSERT_TRUE(RunPlatformAppTest(
542 "api_test/file_system/get_writable_file_entry_with_write")) << message_;
545 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
546 FileSystemApiGetWritableRootEntryTest) {
547 base::FilePath test_file = TempFilePath("writable.txt", true);
548 ASSERT_FALSE(test_file.empty());
549 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
551 ASSERT_TRUE(RunPlatformAppTest(
552 "api_test/file_system/get_writable_root_entry")) << message_;
555 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) {
556 base::FilePath test_file = TempFilePath("writable.txt", true);
557 ASSERT_FALSE(test_file.empty());
558 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
560 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/is_writable_file_entry"))
564 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
565 FileSystemApiIsWritableWithWritePermissionTest) {
566 base::FilePath test_file = TempFilePath("writable.txt", true);
567 ASSERT_FALSE(test_file.empty());
568 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
570 ASSERT_TRUE(RunPlatformAppTest(
571 "api_test/file_system/is_writable_file_entry_with_write"))
575 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainEntry) {
576 base::FilePath test_file = TempFilePath("writable.txt", true);
577 ASSERT_FALSE(test_file.empty());
578 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
580 ASSERT_TRUE(RunPlatformAppTest(
581 "api_test/file_system/retain_entry")) << message_;
582 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get(
583 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id());
584 ASSERT_EQ(1u, file_entries.size());
585 EXPECT_EQ(test_file, file_entries[0].path);
586 EXPECT_EQ(1, file_entries[0].sequence_number);
587 EXPECT_FALSE(file_entries[0].is_directory);
590 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) {
591 base::FilePath test_file = TempFilePath("open_existing.txt", true);
592 ASSERT_FALSE(test_file.empty());
593 base::FilePath test_directory = test_file.DirName();
594 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
596 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/retain_directory"))
598 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get(
599 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id());
600 ASSERT_EQ(1u, file_entries.size());
601 EXPECT_EQ(test_directory, file_entries[0].path);
602 EXPECT_EQ(1, file_entries[0].sequence_number);
603 EXPECT_TRUE(file_entries[0].is_directory);
606 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) {
607 base::FilePath test_file = TempFilePath("writable.txt", true);
608 ASSERT_FALSE(test_file.empty());
609 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
611 AppLoadObserver observer(profile(),
612 base::Bind(AddSavedEntry,
615 apps::SavedFilesService::Get(profile())));
616 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry"))
620 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) {
621 base::FilePath test_file = TempFilePath("writable.txt", true);
622 ASSERT_FALSE(test_file.empty());
623 base::FilePath test_directory = test_file.DirName();
624 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
626 AppLoadObserver observer(profile(),
627 base::Bind(AddSavedEntry,
630 apps::SavedFilesService::Get(profile())));
631 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory"))
635 } // namespace extensions