Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / file_system / file_system_apitest.cc
blob519093f8163b54be3e807e6012854cec21424711
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"
18 namespace content {
19 class BrowserContext;
22 namespace extensions {
24 namespace {
26 class AppLoadObserver : public ExtensionRegistryObserver {
27 public:
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);
39 private:
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,
54 bool is_directory,
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;
63 } // namespace
65 class FileSystemApiTest : public PlatformAppBrowserTest {
66 public:
67 FileSystemApiTest() {
68 set_open_about_blank_on_browser_launch(false);
71 void SetUpCommandLine(base::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 void TearDown() override {
80 FileSystemChooseEntryFunction::StopSkippingPickerForTest();
81 PlatformAppBrowserTest::TearDown();
84 protected:
85 base::FilePath TempFilePath(const std::string& destination_name,
86 bool copy_gold) {
87 if (!temp_dir_.CreateUniqueTempDir()) {
88 ADD_FAILURE() << "CreateUniqueTempDir failed";
89 return base::FilePath();
91 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
92 "test_temp", temp_dir_.path());
94 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name);
95 if (copy_gold) {
96 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
97 EXPECT_TRUE(base::CopyFile(source, destination));
99 return destination;
102 std::vector<base::FilePath> TempFilePaths(
103 const std::vector<std::string>& destination_names,
104 bool copy_gold) {
105 if (!temp_dir_.CreateUniqueTempDir()) {
106 ADD_FAILURE() << "CreateUniqueTempDir failed";
107 return std::vector<base::FilePath>();
109 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
110 "test_temp", temp_dir_.path());
112 std::vector<base::FilePath> result;
113 for (std::vector<std::string>::const_iterator it =
114 destination_names.begin();
115 it != destination_names.end(); ++it) {
116 base::FilePath destination = temp_dir_.path().AppendASCII(*it);
117 if (copy_gold) {
118 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
119 EXPECT_TRUE(base::CopyFile(source, destination));
121 result.push_back(destination);
123 return result;
126 void CheckStoredDirectoryMatches(const base::FilePath& filename) {
127 const Extension* extension = GetSingleLoadedExtension();
128 ASSERT_TRUE(extension);
129 std::string extension_id = extension->id();
130 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
131 base::FilePath stored_value =
132 file_system_api::GetLastChooseEntryDirectory(prefs, extension_id);
133 if (filename.empty()) {
134 EXPECT_TRUE(stored_value.empty());
135 } else {
136 EXPECT_EQ(base::MakeAbsoluteFilePath(filename.DirName()),
137 base::MakeAbsoluteFilePath(stored_value));
141 base::FilePath test_root_folder_;
142 base::ScopedTempDir temp_dir_;
145 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) {
146 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
147 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
148 &test_file);
149 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path"))
150 << message_;
153 #if defined(OS_WIN) || defined(OS_POSIX)
154 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) {
155 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(base::DIR_HOME,
156 test_root_folder_, false, false));
158 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
159 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
160 &test_file);
161 ASSERT_TRUE(RunPlatformAppTest(
162 "api_test/file_system/get_display_path_prettify")) << message_;
164 #endif
166 #if defined(OS_MACOSX)
167 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
168 FileSystemApiGetDisplayPathPrettifyMac) {
169 // On Mac, "test.localized" will be localized into just "test".
170 base::FilePath test_path = TempFilePath("test.localized", false);
171 ASSERT_TRUE(base::CreateDirectory(test_path));
173 base::FilePath test_file = test_path.AppendASCII("gold.txt");
174 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
175 EXPECT_TRUE(base::CopyFile(source, test_file));
177 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
178 &test_file);
179 ASSERT_TRUE(RunPlatformAppTest(
180 "api_test/file_system/get_display_path_prettify_mac")) << message_;
182 #endif
184 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) {
185 base::FilePath test_file = TempFilePath("open_existing.txt", true);
186 ASSERT_FALSE(test_file.empty());
187 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
188 &test_file);
189 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
190 << message_;
191 CheckStoredDirectoryMatches(test_file);
194 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
195 FileSystemApiOpenExistingFileUsingPreviousPathTest) {
196 base::FilePath test_file = TempFilePath("open_existing.txt", true);
197 ASSERT_FALSE(test_file.empty());
198 FileSystemChooseEntryFunction::
199 SkipPickerAndSelectSuggestedPathForTest();
201 AppLoadObserver observer(profile(),
202 base::Bind(SetLastChooseEntryDirectory,
203 test_file.DirName(),
204 ExtensionPrefs::Get(profile())));
205 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
206 << message_;
208 CheckStoredDirectoryMatches(test_file);
211 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
212 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) {
213 base::FilePath test_file = TempFilePath("open_existing.txt", true);
214 ASSERT_FALSE(test_file.empty());
215 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
216 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
217 FileSystemChooseEntryFunction::
218 SkipPickerAndSelectSuggestedPathForTest();
220 AppLoadObserver observer(
221 profile(),
222 base::Bind(SetLastChooseEntryDirectory,
223 test_file.DirName().Append(base::FilePath::FromUTF8Unsafe(
224 "fake_directory_does_not_exist")),
225 ExtensionPrefs::Get(profile())));
226 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
227 << message_;
229 CheckStoredDirectoryMatches(test_file);
232 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
233 FileSystemApiOpenExistingFileDefaultPathTest) {
234 base::FilePath test_file = TempFilePath("open_existing.txt", true);
235 ASSERT_FALSE(test_file.empty());
236 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
237 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
238 FileSystemChooseEntryFunction::
239 SkipPickerAndSelectSuggestedPathForTest();
240 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
241 << message_;
242 CheckStoredDirectoryMatches(test_file);
245 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenMultipleSuggested) {
246 base::FilePath test_file = TempFilePath("open_existing.txt", true);
247 ASSERT_FALSE(test_file.empty());
248 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
249 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
250 FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest();
251 ASSERT_TRUE(RunPlatformAppTest(
252 "api_test/file_system/open_multiple_with_suggested_name"))
253 << message_;
254 CheckStoredDirectoryMatches(test_file);
257 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
258 FileSystemApiOpenMultipleExistingFilesTest) {
259 std::vector<std::string> names;
260 names.push_back("open_existing1.txt");
261 names.push_back("open_existing2.txt");
262 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
263 ASSERT_EQ(2u, test_files.size());
264 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
265 &test_files);
266 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing"))
267 << message_;
270 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenDirectoryTest) {
271 base::FilePath test_file = TempFilePath("open_existing.txt", true);
272 ASSERT_FALSE(test_file.empty());
273 base::FilePath test_directory = test_file.DirName();
274 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
275 &test_directory);
276 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
277 << message_;
278 CheckStoredDirectoryMatches(test_file);
281 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
282 FileSystemApiOpenDirectoryWithWriteTest) {
283 base::FilePath test_file = TempFilePath("open_existing.txt", true);
284 ASSERT_FALSE(test_file.empty());
285 base::FilePath test_directory = test_file.DirName();
286 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
287 &test_directory);
288 ASSERT_TRUE(
289 RunPlatformAppTest("api_test/file_system/open_directory_with_write"))
290 << message_;
291 CheckStoredDirectoryMatches(test_file);
294 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
295 FileSystemApiOpenDirectoryWithoutPermissionTest) {
296 base::FilePath test_file = TempFilePath("open_existing.txt", true);
297 ASSERT_FALSE(test_file.empty());
298 base::FilePath test_directory = test_file.DirName();
299 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
300 &test_directory);
301 ASSERT_TRUE(RunPlatformAppTest(
302 "api_test/file_system/open_directory_without_permission"))
303 << message_;
304 CheckStoredDirectoryMatches(base::FilePath());
307 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
308 FileSystemApiOpenDirectoryWithOnlyWritePermissionTest) {
309 base::FilePath test_file = TempFilePath("open_existing.txt", true);
310 ASSERT_FALSE(test_file.empty());
311 base::FilePath test_directory = test_file.DirName();
312 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
313 &test_directory);
314 ASSERT_TRUE(RunPlatformAppTest(
315 "api_test/file_system/open_directory_with_only_write"))
316 << message_;
317 CheckStoredDirectoryMatches(base::FilePath());
320 #if defined(OS_WIN) || defined(OS_POSIX)
321 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
322 FileSystemApiOpenDirectoryOnGraylistAndAllowTest) {
323 FileSystemChooseEntryFunction::SkipDirectoryConfirmationForTest();
324 base::FilePath test_file = TempFilePath("open_existing.txt", true);
325 ASSERT_FALSE(test_file.empty());
326 base::FilePath test_directory = test_file.DirName();
327 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
328 kGraylistedPath, test_directory, false, false));
329 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
330 &test_directory);
331 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
332 << message_;
333 CheckStoredDirectoryMatches(test_file);
336 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
337 FileSystemApiOpenDirectoryOnGraylistTest) {
338 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
339 base::FilePath test_file = TempFilePath("open_existing.txt", true);
340 ASSERT_FALSE(test_file.empty());
341 base::FilePath test_directory = test_file.DirName();
342 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
343 kGraylistedPath, test_directory, false, false));
344 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
345 &test_directory);
346 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
347 << message_;
348 CheckStoredDirectoryMatches(test_file);
351 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
352 FileSystemApiOpenDirectoryContainingGraylistTest) {
353 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
354 base::FilePath test_file = TempFilePath("open_existing.txt", true);
355 ASSERT_FALSE(test_file.empty());
356 base::FilePath test_directory = test_file.DirName();
357 base::FilePath parent_directory = test_directory.DirName();
358 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
359 kGraylistedPath, test_directory, false, false));
360 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
361 &parent_directory);
362 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
363 << message_;
364 CheckStoredDirectoryMatches(test_directory);
367 // Test that choosing a subdirectory of a path does not require confirmation.
368 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
369 FileSystemApiOpenDirectorySubdirectoryOfGraylistTest) {
370 // If a dialog is erroneously displayed, auto cancel it, so that the test
371 // fails.
372 FileSystemChooseEntryFunction::AutoCancelDirectoryConfirmationForTest();
373 base::FilePath test_file = TempFilePath("open_existing.txt", true);
374 ASSERT_FALSE(test_file.empty());
375 base::FilePath test_directory = test_file.DirName();
376 base::FilePath parent_directory = test_directory.DirName();
377 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
378 kGraylistedPath, parent_directory, false, false));
379 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
380 &test_directory);
381 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
382 << message_;
383 CheckStoredDirectoryMatches(test_file);
385 #endif // defined(OS_WIN) || defined(OS_POSIX)
387 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
388 FileSystemApiInvalidChooseEntryTypeTest) {
389 base::FilePath test_file = TempFilePath("open_existing.txt", true);
390 ASSERT_FALSE(test_file.empty());
391 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
392 &test_file);
393 ASSERT_TRUE(RunPlatformAppTest(
394 "api_test/file_system/invalid_choose_file_type")) << message_;
395 CheckStoredDirectoryMatches(base::FilePath());
398 // http://crbug.com/177163
399 #if defined(OS_WIN) && !defined(NDEBUG)
400 #define MAYBE_FileSystemApiOpenExistingFileWithWriteTest DISABLED_FileSystemApiOpenExistingFileWithWriteTest
401 #else
402 #define MAYBE_FileSystemApiOpenExistingFileWithWriteTest FileSystemApiOpenExistingFileWithWriteTest
403 #endif
404 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
405 MAYBE_FileSystemApiOpenExistingFileWithWriteTest) {
406 base::FilePath test_file = TempFilePath("open_existing.txt", true);
407 ASSERT_FALSE(test_file.empty());
408 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
409 &test_file);
410 ASSERT_TRUE(RunPlatformAppTest(
411 "api_test/file_system/open_existing_with_write")) << message_;
412 CheckStoredDirectoryMatches(test_file);
415 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
416 FileSystemApiOpenWritableExistingFileTest) {
417 base::FilePath test_file = TempFilePath("open_existing.txt", true);
418 ASSERT_FALSE(test_file.empty());
419 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
420 &test_file);
421 ASSERT_TRUE(RunPlatformAppTest(
422 "api_test/file_system/open_writable_existing")) << message_;
423 CheckStoredDirectoryMatches(base::FilePath());
426 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
427 FileSystemApiOpenWritableExistingFileWithWriteTest) {
428 base::FilePath test_file = TempFilePath("open_existing.txt", true);
429 ASSERT_FALSE(test_file.empty());
430 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
431 &test_file);
432 ASSERT_TRUE(RunPlatformAppTest(
433 "api_test/file_system/open_writable_existing_with_write")) << message_;
434 CheckStoredDirectoryMatches(test_file);
437 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
438 FileSystemApiOpenMultipleWritableExistingFilesTest) {
439 std::vector<std::string> names;
440 names.push_back("open_existing1.txt");
441 names.push_back("open_existing2.txt");
442 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
443 ASSERT_EQ(2u, test_files.size());
444 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
445 &test_files);
446 ASSERT_TRUE(RunPlatformAppTest(
447 "api_test/file_system/open_multiple_writable_existing_with_write"))
448 << message_;
451 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) {
452 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
453 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel"))
454 << message_;
455 CheckStoredDirectoryMatches(base::FilePath());
458 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) {
459 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background"))
460 << message_;
463 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveNewFileTest) {
464 base::FilePath test_file = TempFilePath("save_new.txt", false);
465 ASSERT_FALSE(test_file.empty());
466 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
467 &test_file);
468 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new"))
469 << message_;
470 CheckStoredDirectoryMatches(base::FilePath());
473 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveExistingFileTest) {
474 base::FilePath test_file = TempFilePath("save_existing.txt", true);
475 ASSERT_FALSE(test_file.empty());
476 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
477 &test_file);
478 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_existing"))
479 << message_;
480 CheckStoredDirectoryMatches(base::FilePath());
483 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
484 FileSystemApiSaveNewFileWithWriteTest) {
485 base::FilePath test_file = TempFilePath("save_new.txt", false);
486 ASSERT_FALSE(test_file.empty());
487 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
488 &test_file);
489 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new_with_write"))
490 << message_;
491 CheckStoredDirectoryMatches(test_file);
494 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
495 FileSystemApiSaveExistingFileWithWriteTest) {
496 base::FilePath test_file = TempFilePath("save_existing.txt", true);
497 ASSERT_FALSE(test_file.empty());
498 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
499 &test_file);
500 ASSERT_TRUE(RunPlatformAppTest(
501 "api_test/file_system/save_existing_with_write")) << message_;
502 CheckStoredDirectoryMatches(test_file);
505 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveMultipleFilesTest) {
506 std::vector<std::string> names;
507 names.push_back("save1.txt");
508 names.push_back("save2.txt");
509 std::vector<base::FilePath> test_files = TempFilePaths(names, false);
510 ASSERT_EQ(2u, test_files.size());
511 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
512 &test_files);
513 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_multiple"))
514 << message_;
517 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) {
518 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
519 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel"))
520 << message_;
523 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) {
524 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background"))
525 << message_;
528 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetWritableTest) {
529 base::FilePath test_file = TempFilePath("writable.txt", true);
530 ASSERT_FALSE(test_file.empty());
531 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
532 &test_file);
533 ASSERT_TRUE(RunPlatformAppTest(
534 "api_test/file_system/get_writable_file_entry")) << message_;
537 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
538 FileSystemApiGetWritableWithWriteTest) {
539 base::FilePath test_file = TempFilePath("writable.txt", true);
540 ASSERT_FALSE(test_file.empty());
541 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
542 &test_file);
543 ASSERT_TRUE(RunPlatformAppTest(
544 "api_test/file_system/get_writable_file_entry_with_write")) << message_;
547 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
548 FileSystemApiGetWritableRootEntryTest) {
549 base::FilePath test_file = TempFilePath("writable.txt", true);
550 ASSERT_FALSE(test_file.empty());
551 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
552 &test_file);
553 ASSERT_TRUE(RunPlatformAppTest(
554 "api_test/file_system/get_writable_root_entry")) << message_;
557 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) {
558 base::FilePath test_file = TempFilePath("writable.txt", true);
559 ASSERT_FALSE(test_file.empty());
560 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
561 &test_file);
562 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/is_writable_file_entry"))
563 << message_;
566 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
567 FileSystemApiIsWritableWithWritePermissionTest) {
568 base::FilePath test_file = TempFilePath("writable.txt", true);
569 ASSERT_FALSE(test_file.empty());
570 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
571 &test_file);
572 ASSERT_TRUE(RunPlatformAppTest(
573 "api_test/file_system/is_writable_file_entry_with_write"))
574 << message_;
577 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainEntry) {
578 base::FilePath test_file = TempFilePath("writable.txt", true);
579 ASSERT_FALSE(test_file.empty());
580 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
581 &test_file);
582 ASSERT_TRUE(RunPlatformAppTest(
583 "api_test/file_system/retain_entry")) << message_;
584 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get(
585 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id());
586 ASSERT_EQ(1u, file_entries.size());
587 EXPECT_EQ(test_file, file_entries[0].path);
588 EXPECT_EQ(1, file_entries[0].sequence_number);
589 EXPECT_FALSE(file_entries[0].is_directory);
592 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) {
593 base::FilePath test_file = TempFilePath("open_existing.txt", true);
594 ASSERT_FALSE(test_file.empty());
595 base::FilePath test_directory = test_file.DirName();
596 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
597 &test_directory);
598 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/retain_directory"))
599 << message_;
600 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get(
601 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id());
602 ASSERT_EQ(1u, file_entries.size());
603 EXPECT_EQ(test_directory, file_entries[0].path);
604 EXPECT_EQ(1, file_entries[0].sequence_number);
605 EXPECT_TRUE(file_entries[0].is_directory);
608 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) {
609 base::FilePath test_file = TempFilePath("writable.txt", true);
610 ASSERT_FALSE(test_file.empty());
611 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
612 &test_file);
613 AppLoadObserver observer(profile(),
614 base::Bind(AddSavedEntry,
615 test_file,
616 false,
617 apps::SavedFilesService::Get(profile())));
618 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry"))
619 << message_;
622 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) {
623 base::FilePath test_file = TempFilePath("writable.txt", true);
624 ASSERT_FALSE(test_file.empty());
625 base::FilePath test_directory = test_file.DirName();
626 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
627 &test_file);
628 AppLoadObserver observer(profile(),
629 base::Bind(AddSavedEntry,
630 test_directory,
631 true,
632 apps::SavedFilesService::Get(profile())));
633 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory"))
634 << message_;
637 #if !defined(OS_CHROMEOS)
638 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, RequestFileSystem_NotChromeOS) {
639 ASSERT_TRUE(RunPlatformAppTestWithFlags(
640 "api_test/file_system/request_file_system_not_chromeos",
641 kFlagIgnoreManifestWarnings))
642 << message_;
644 #endif
646 } // namespace extensions