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/file_util.h"
7 #include "base/path_service.h"
8 #include "build/build_config.h"
9 #include "chrome/browser/apps/app_browsertest_util.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_service.h"
17 namespace extensions {
21 class AppInstallObserver : public content::NotificationObserver {
24 base::Callback<void(const Extension*)> callback)
25 : callback_(callback) {
27 chrome::NOTIFICATION_EXTENSION_LOADED,
28 content::NotificationService::AllSources());
31 virtual void Observe(int type,
32 const content::NotificationSource& source,
33 const content::NotificationDetails& details) OVERRIDE {
34 EXPECT_EQ(chrome::NOTIFICATION_EXTENSION_LOADED, type);
35 callback_.Run(content::Details<const Extension>(details).ptr());
39 content::NotificationRegistrar registrar_;
40 base::Callback<void(const Extension*)> callback_;
41 DISALLOW_COPY_AND_ASSIGN(AppInstallObserver);
44 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory,
45 ExtensionPrefs* prefs,
46 const Extension* extension) {
47 file_system_api::SetLastChooseEntryDirectory(
48 prefs, extension->id(), choose_entry_directory);
51 void AddSavedEntry(const base::FilePath& path_to_save,
53 apps::SavedFilesService* service,
54 const Extension* extension) {
55 service->RegisterFileEntry(
56 extension->id(), "magic id", path_to_save, is_directory);
59 #if defined(OS_WIN) || defined(OS_POSIX)
61 const int kGraylistedPath = base::DIR_PROFILE;
62 #elif defined(OS_POSIX)
63 const int kGraylistedPath = base::DIR_HOME;
69 class FileSystemApiTest : public PlatformAppBrowserTest {
71 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
72 PlatformAppBrowserTest::SetUpCommandLine(command_line);
73 test_root_folder_ = test_data_dir_.AppendASCII("api_test")
74 .AppendASCII("file_system");
75 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
76 "test_root", test_root_folder_);
79 virtual void SetUpOnMainThread() OVERRIDE {
80 ClearCommandLineArgs();
83 virtual void TearDown() OVERRIDE {
84 FileSystemChooseEntryFunction::StopSkippingPickerForTest();
85 PlatformAppBrowserTest::TearDown();
89 base::FilePath TempFilePath(const std::string& destination_name,
91 if (!temp_dir_.CreateUniqueTempDir()) {
92 ADD_FAILURE() << "CreateUniqueTempDir failed";
93 return base::FilePath();
95 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
96 "test_temp", temp_dir_.path());
98 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name);
100 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
101 EXPECT_TRUE(base::CopyFile(source, destination));
106 std::vector<base::FilePath> TempFilePaths(
107 const std::vector<std::string>& destination_names,
109 if (!temp_dir_.CreateUniqueTempDir()) {
110 ADD_FAILURE() << "CreateUniqueTempDir failed";
111 return std::vector<base::FilePath>();
113 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
114 "test_temp", temp_dir_.path());
116 std::vector<base::FilePath> result;
117 for (std::vector<std::string>::const_iterator it =
118 destination_names.begin();
119 it != destination_names.end(); ++it) {
120 base::FilePath destination = temp_dir_.path().AppendASCII(*it);
122 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
123 EXPECT_TRUE(base::CopyFile(source, destination));
125 result.push_back(destination);
130 void CheckStoredDirectoryMatches(const base::FilePath& filename) {
131 const Extension* extension = GetSingleLoadedExtension();
132 ASSERT_TRUE(extension);
133 std::string extension_id = extension->id();
134 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
135 base::FilePath stored_value =
136 file_system_api::GetLastChooseEntryDirectory(prefs, extension_id);
137 if (filename.empty()) {
138 EXPECT_TRUE(stored_value.empty());
140 EXPECT_EQ(base::MakeAbsoluteFilePath(filename.DirName()),
141 base::MakeAbsoluteFilePath(stored_value));
145 base::FilePath test_root_folder_;
146 base::ScopedTempDir temp_dir_;
149 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) {
150 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
151 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
153 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path"))
157 #if defined(OS_WIN) || defined(OS_POSIX)
158 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) {
160 int override = base::DIR_PROFILE;
161 #elif defined(OS_POSIX)
162 int override = base::DIR_HOME;
164 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(override,
165 test_root_folder_, false));
167 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
168 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
170 ASSERT_TRUE(RunPlatformAppTest(
171 "api_test/file_system/get_display_path_prettify")) << message_;
175 #if defined(OS_MACOSX)
176 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
177 FileSystemApiGetDisplayPathPrettifyMac) {
178 // On Mac, "test.localized" will be localized into just "test".
179 base::FilePath test_path = TempFilePath("test.localized", false);
180 ASSERT_TRUE(file_util::CreateDirectory(test_path));
182 base::FilePath test_file = test_path.AppendASCII("gold.txt");
183 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
184 EXPECT_TRUE(base::CopyFile(source, test_file));
186 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
188 ASSERT_TRUE(RunPlatformAppTest(
189 "api_test/file_system/get_display_path_prettify_mac")) << message_;
193 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) {
194 base::FilePath test_file = TempFilePath("open_existing.txt", true);
195 ASSERT_FALSE(test_file.empty());
196 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
198 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
200 CheckStoredDirectoryMatches(test_file);
203 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
204 FileSystemApiOpenExistingFileUsingPreviousPathTest) {
205 base::FilePath test_file = TempFilePath("open_existing.txt", true);
206 ASSERT_FALSE(test_file.empty());
207 FileSystemChooseEntryFunction::
208 SkipPickerAndSelectSuggestedPathForTest();
210 AppInstallObserver observer(
211 base::Bind(SetLastChooseEntryDirectory,
213 ExtensionPrefs::Get(profile())));
214 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
217 CheckStoredDirectoryMatches(test_file);
220 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
221 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) {
222 base::FilePath test_file = TempFilePath("open_existing.txt", true);
223 ASSERT_FALSE(test_file.empty());
224 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
225 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false));
226 FileSystemChooseEntryFunction::
227 SkipPickerAndSelectSuggestedPathForTest();
229 AppInstallObserver observer(base::Bind(
230 SetLastChooseEntryDirectory,
231 test_file.DirName().Append(
232 base::FilePath::FromUTF8Unsafe("fake_directory_does_not_exist")),
233 ExtensionPrefs::Get(profile())));
234 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
237 CheckStoredDirectoryMatches(test_file);
240 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
241 FileSystemApiOpenExistingFileDefaultPathTest) {
242 base::FilePath test_file = TempFilePath("open_existing.txt", true);
243 ASSERT_FALSE(test_file.empty());
244 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
245 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false));
246 FileSystemChooseEntryFunction::
247 SkipPickerAndSelectSuggestedPathForTest();
248 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
250 CheckStoredDirectoryMatches(test_file);
253 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenMultipleSuggested) {
254 base::FilePath test_file = TempFilePath("open_existing.txt", true);
255 ASSERT_FALSE(test_file.empty());
256 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
257 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false));
258 FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest();
259 ASSERT_TRUE(RunPlatformAppTest(
260 "api_test/file_system/open_multiple_with_suggested_name"))
262 CheckStoredDirectoryMatches(test_file);
265 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
266 FileSystemApiOpenMultipleExistingFilesTest) {
267 std::vector<std::string> names;
268 names.push_back("open_existing1.txt");
269 names.push_back("open_existing2.txt");
270 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
271 ASSERT_EQ(2u, test_files.size());
272 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
274 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing"))
278 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenDirectoryTest) {
279 base::FilePath test_file = TempFilePath("open_existing.txt", true);
280 ASSERT_FALSE(test_file.empty());
281 base::FilePath test_directory = test_file.DirName();
282 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
284 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
286 CheckStoredDirectoryMatches(test_file);
289 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
290 FileSystemApiOpenDirectoryWithWriteTest) {
291 base::FilePath test_file = TempFilePath("open_existing.txt", true);
292 ASSERT_FALSE(test_file.empty());
293 base::FilePath test_directory = test_file.DirName();
294 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
297 RunPlatformAppTest("api_test/file_system/open_directory_with_write"))
299 CheckStoredDirectoryMatches(test_file);
302 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
303 FileSystemApiOpenDirectoryWithoutPermissionTest) {
304 base::FilePath test_file = TempFilePath("open_existing.txt", true);
305 ASSERT_FALSE(test_file.empty());
306 base::FilePath test_directory = test_file.DirName();
307 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
309 ASSERT_TRUE(RunPlatformAppTest(
310 "api_test/file_system/open_directory_without_permission"))
312 CheckStoredDirectoryMatches(base::FilePath());
315 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
316 FileSystemApiOpenDirectoryWithOnlyWritePermissionTest) {
317 base::FilePath test_file = TempFilePath("open_existing.txt", true);
318 ASSERT_FALSE(test_file.empty());
319 base::FilePath test_directory = test_file.DirName();
320 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
322 ASSERT_TRUE(RunPlatformAppTest(
323 "api_test/file_system/open_directory_with_only_write"))
325 CheckStoredDirectoryMatches(base::FilePath());
328 #if defined(OS_WIN) || defined(OS_POSIX)
329 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
330 FileSystemApiOpenDirectoryOnGraylistAndAllowTest) {
331 FileSystemChooseEntryFunction::SkipDirectoryConfirmationForTest();
332 base::FilePath test_file = TempFilePath("open_existing.txt", true);
333 ASSERT_FALSE(test_file.empty());
334 base::FilePath test_directory = test_file.DirName();
335 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
336 kGraylistedPath, test_directory, false));
337 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
339 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
341 CheckStoredDirectoryMatches(test_file);
344 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
345 FileSystemApiOpenDirectoryOnGraylistTest) {
346 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
347 base::FilePath test_file = TempFilePath("open_existing.txt", true);
348 ASSERT_FALSE(test_file.empty());
349 base::FilePath test_directory = test_file.DirName();
350 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
351 kGraylistedPath, test_directory, false));
352 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
354 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
356 CheckStoredDirectoryMatches(test_file);
359 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
360 FileSystemApiOpenDirectoryContainingGraylistTest) {
361 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
362 base::FilePath test_file = TempFilePath("open_existing.txt", true);
363 ASSERT_FALSE(test_file.empty());
364 base::FilePath test_directory = test_file.DirName();
365 base::FilePath parent_directory = test_directory.DirName();
366 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
367 kGraylistedPath, test_directory, false));
368 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
370 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
372 CheckStoredDirectoryMatches(test_directory);
375 // Test that choosing a subdirectory of a path does not require confirmation.
376 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
377 FileSystemApiOpenDirectorySubdirectoryOfGraylistTest) {
378 // If a dialog is erroneously displayed, auto cancel it, so that the test
380 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
381 base::FilePath test_file = TempFilePath("open_existing.txt", true);
382 ASSERT_FALSE(test_file.empty());
383 base::FilePath test_directory = test_file.DirName();
384 base::FilePath parent_directory = test_directory.DirName();
385 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
386 kGraylistedPath, parent_directory, false));
387 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
389 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
391 CheckStoredDirectoryMatches(test_file);
393 #endif // defined(OS_WIN) || defined(OS_POSIX)
395 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
396 FileSystemApiInvalidChooseEntryTypeTest) {
397 base::FilePath test_file = TempFilePath("open_existing.txt", true);
398 ASSERT_FALSE(test_file.empty());
399 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
401 ASSERT_TRUE(RunPlatformAppTest(
402 "api_test/file_system/invalid_choose_file_type")) << message_;
403 CheckStoredDirectoryMatches(base::FilePath());
406 // http://crbug.com/177163
407 #if defined(OS_WIN) && !defined(NDEBUG)
408 #define MAYBE_FileSystemApiOpenExistingFileWithWriteTest DISABLED_FileSystemApiOpenExistingFileWithWriteTest
410 #define MAYBE_FileSystemApiOpenExistingFileWithWriteTest FileSystemApiOpenExistingFileWithWriteTest
412 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
413 MAYBE_FileSystemApiOpenExistingFileWithWriteTest) {
414 base::FilePath test_file = TempFilePath("open_existing.txt", true);
415 ASSERT_FALSE(test_file.empty());
416 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
418 ASSERT_TRUE(RunPlatformAppTest(
419 "api_test/file_system/open_existing_with_write")) << message_;
420 CheckStoredDirectoryMatches(test_file);
423 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
424 FileSystemApiOpenWritableExistingFileTest) {
425 base::FilePath test_file = TempFilePath("open_existing.txt", true);
426 ASSERT_FALSE(test_file.empty());
427 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
429 ASSERT_TRUE(RunPlatformAppTest(
430 "api_test/file_system/open_writable_existing")) << message_;
431 CheckStoredDirectoryMatches(base::FilePath());
434 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
435 FileSystemApiOpenWritableExistingFileWithWriteTest) {
436 base::FilePath test_file = TempFilePath("open_existing.txt", true);
437 ASSERT_FALSE(test_file.empty());
438 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
440 ASSERT_TRUE(RunPlatformAppTest(
441 "api_test/file_system/open_writable_existing_with_write")) << message_;
442 CheckStoredDirectoryMatches(test_file);
445 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
446 FileSystemApiOpenMultipleWritableExistingFilesTest) {
447 std::vector<std::string> names;
448 names.push_back("open_existing1.txt");
449 names.push_back("open_existing2.txt");
450 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
451 ASSERT_EQ(2u, test_files.size());
452 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
454 ASSERT_TRUE(RunPlatformAppTest(
455 "api_test/file_system/open_multiple_writable_existing_with_write"))
459 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) {
460 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
461 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel"))
463 CheckStoredDirectoryMatches(base::FilePath());
466 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) {
467 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background"))
471 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveNewFileTest) {
472 base::FilePath test_file = TempFilePath("save_new.txt", false);
473 ASSERT_FALSE(test_file.empty());
474 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
476 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new"))
478 CheckStoredDirectoryMatches(base::FilePath());
481 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveExistingFileTest) {
482 base::FilePath test_file = TempFilePath("save_existing.txt", true);
483 ASSERT_FALSE(test_file.empty());
484 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
486 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_existing"))
488 CheckStoredDirectoryMatches(base::FilePath());
491 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
492 FileSystemApiSaveNewFileWithWriteTest) {
493 base::FilePath test_file = TempFilePath("save_new.txt", false);
494 ASSERT_FALSE(test_file.empty());
495 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
497 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new_with_write"))
499 CheckStoredDirectoryMatches(test_file);
502 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
503 FileSystemApiSaveExistingFileWithWriteTest) {
504 base::FilePath test_file = TempFilePath("save_existing.txt", true);
505 ASSERT_FALSE(test_file.empty());
506 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
508 ASSERT_TRUE(RunPlatformAppTest(
509 "api_test/file_system/save_existing_with_write")) << message_;
510 CheckStoredDirectoryMatches(test_file);
513 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveMultipleFilesTest) {
514 std::vector<std::string> names;
515 names.push_back("save1.txt");
516 names.push_back("save2.txt");
517 std::vector<base::FilePath> test_files = TempFilePaths(names, false);
518 ASSERT_EQ(2u, test_files.size());
519 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
521 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_multiple"))
525 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) {
526 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
527 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel"))
531 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) {
532 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background"))
536 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetWritableTest) {
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")) << message_;
545 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
546 FileSystemApiGetWritableWithWriteTest) {
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_file_entry_with_write")) << 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 AppInstallObserver observer(
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 AppInstallObserver observer(
627 base::Bind(AddSavedEntry,
630 apps::SavedFilesService::Get(profile())));
631 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory"))
635 } // namespace extensions