Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / browser / extensions / api / file_system / file_system_apitest.cc
blobac32e37224f3ef2878cd25df10c35859b4f803dc
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/profiles/profile.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_service.h"
16 #include "extensions/browser/extension_prefs.h"
18 namespace extensions {
20 namespace {
22 class AppInstallObserver : public content::NotificationObserver {
23 public:
24 AppInstallObserver(
25 base::Callback<void(const Extension*)> callback)
26 : callback_(callback) {
27 registrar_.Add(this,
28 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
29 content::NotificationService::AllSources());
32 virtual void Observe(int type,
33 const content::NotificationSource& source,
34 const content::NotificationDetails& details) OVERRIDE {
35 EXPECT_EQ(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, type);
36 callback_.Run(content::Details<const Extension>(details).ptr());
39 private:
40 content::NotificationRegistrar registrar_;
41 base::Callback<void(const Extension*)> callback_;
42 DISALLOW_COPY_AND_ASSIGN(AppInstallObserver);
45 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory,
46 ExtensionPrefs* prefs,
47 const Extension* extension) {
48 file_system_api::SetLastChooseEntryDirectory(
49 prefs, extension->id(), choose_entry_directory);
52 void AddSavedEntry(const base::FilePath& path_to_save,
53 bool is_directory,
54 apps::SavedFilesService* service,
55 const Extension* extension) {
56 service->RegisterFileEntry(
57 extension->id(), "magic id", path_to_save, is_directory);
60 const int kGraylistedPath = base::DIR_HOME;
62 } // namespace
64 class FileSystemApiTest : public PlatformAppBrowserTest {
65 public:
66 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
67 PlatformAppBrowserTest::SetUpCommandLine(command_line);
68 test_root_folder_ = test_data_dir_.AppendASCII("api_test")
69 .AppendASCII("file_system");
70 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
71 "test_root", test_root_folder_);
74 virtual void SetUpOnMainThread() OVERRIDE {
75 ClearCommandLineArgs();
78 virtual void TearDown() OVERRIDE {
79 FileSystemChooseEntryFunction::StopSkippingPickerForTest();
80 PlatformAppBrowserTest::TearDown();
83 protected:
84 base::FilePath TempFilePath(const std::string& destination_name,
85 bool copy_gold) {
86 if (!temp_dir_.CreateUniqueTempDir()) {
87 ADD_FAILURE() << "CreateUniqueTempDir failed";
88 return base::FilePath();
90 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
91 "test_temp", temp_dir_.path());
93 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name);
94 if (copy_gold) {
95 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
96 EXPECT_TRUE(base::CopyFile(source, destination));
98 return destination;
101 std::vector<base::FilePath> TempFilePaths(
102 const std::vector<std::string>& destination_names,
103 bool copy_gold) {
104 if (!temp_dir_.CreateUniqueTempDir()) {
105 ADD_FAILURE() << "CreateUniqueTempDir failed";
106 return std::vector<base::FilePath>();
108 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
109 "test_temp", temp_dir_.path());
111 std::vector<base::FilePath> result;
112 for (std::vector<std::string>::const_iterator it =
113 destination_names.begin();
114 it != destination_names.end(); ++it) {
115 base::FilePath destination = temp_dir_.path().AppendASCII(*it);
116 if (copy_gold) {
117 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
118 EXPECT_TRUE(base::CopyFile(source, destination));
120 result.push_back(destination);
122 return result;
125 void CheckStoredDirectoryMatches(const base::FilePath& filename) {
126 const Extension* extension = GetSingleLoadedExtension();
127 ASSERT_TRUE(extension);
128 std::string extension_id = extension->id();
129 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
130 base::FilePath stored_value =
131 file_system_api::GetLastChooseEntryDirectory(prefs, extension_id);
132 if (filename.empty()) {
133 EXPECT_TRUE(stored_value.empty());
134 } else {
135 EXPECT_EQ(base::MakeAbsoluteFilePath(filename.DirName()),
136 base::MakeAbsoluteFilePath(stored_value));
140 base::FilePath test_root_folder_;
141 base::ScopedTempDir temp_dir_;
144 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) {
145 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
146 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
147 &test_file);
148 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path"))
149 << message_;
152 #if defined(OS_WIN) || defined(OS_POSIX)
153 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) {
154 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(base::DIR_HOME,
155 test_root_folder_, false, false));
157 base::FilePath test_file = test_root_folder_.AppendASCII("gold.txt");
158 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
159 &test_file);
160 ASSERT_TRUE(RunPlatformAppTest(
161 "api_test/file_system/get_display_path_prettify")) << message_;
163 #endif
165 #if defined(OS_MACOSX)
166 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
167 FileSystemApiGetDisplayPathPrettifyMac) {
168 // On Mac, "test.localized" will be localized into just "test".
169 base::FilePath test_path = TempFilePath("test.localized", false);
170 ASSERT_TRUE(base::CreateDirectory(test_path));
172 base::FilePath test_file = test_path.AppendASCII("gold.txt");
173 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
174 EXPECT_TRUE(base::CopyFile(source, test_file));
176 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
177 &test_file);
178 ASSERT_TRUE(RunPlatformAppTest(
179 "api_test/file_system/get_display_path_prettify_mac")) << message_;
181 #endif
183 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) {
184 base::FilePath test_file = TempFilePath("open_existing.txt", true);
185 ASSERT_FALSE(test_file.empty());
186 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
187 &test_file);
188 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
189 << message_;
190 CheckStoredDirectoryMatches(test_file);
193 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
194 FileSystemApiOpenExistingFileUsingPreviousPathTest) {
195 base::FilePath test_file = TempFilePath("open_existing.txt", true);
196 ASSERT_FALSE(test_file.empty());
197 FileSystemChooseEntryFunction::
198 SkipPickerAndSelectSuggestedPathForTest();
200 AppInstallObserver observer(
201 base::Bind(SetLastChooseEntryDirectory,
202 test_file.DirName(),
203 ExtensionPrefs::Get(profile())));
204 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
205 << message_;
207 CheckStoredDirectoryMatches(test_file);
210 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
211 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) {
212 base::FilePath test_file = TempFilePath("open_existing.txt", true);
213 ASSERT_FALSE(test_file.empty());
214 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
215 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false));
216 FileSystemChooseEntryFunction::
217 SkipPickerAndSelectSuggestedPathForTest();
219 AppInstallObserver observer(base::Bind(
220 SetLastChooseEntryDirectory,
221 test_file.DirName().Append(
222 base::FilePath::FromUTF8Unsafe("fake_directory_does_not_exist")),
223 ExtensionPrefs::Get(profile())));
224 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
225 << message_;
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"))
239 << message_;
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"))
251 << message_;
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(
263 &test_files);
264 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing"))
265 << message_;
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(
273 &test_directory);
274 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
275 << message_;
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(
285 &test_directory);
286 ASSERT_TRUE(
287 RunPlatformAppTest("api_test/file_system/open_directory_with_write"))
288 << message_;
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(
298 &test_directory);
299 ASSERT_TRUE(RunPlatformAppTest(
300 "api_test/file_system/open_directory_without_permission"))
301 << message_;
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(
311 &test_directory);
312 ASSERT_TRUE(RunPlatformAppTest(
313 "api_test/file_system/open_directory_with_only_write"))
314 << message_;
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(
328 &test_directory);
329 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
330 << message_;
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(
343 &test_directory);
344 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
345 << message_;
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(
359 &parent_directory);
360 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory_cancel"))
361 << message_;
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
369 // fails.
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(
378 &test_directory);
379 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
380 << message_;
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(
390 &test_file);
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
399 #else
400 #define MAYBE_FileSystemApiOpenExistingFileWithWriteTest FileSystemApiOpenExistingFileWithWriteTest
401 #endif
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(
407 &test_file);
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(
418 &test_file);
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(
429 &test_file);
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(
443 &test_files);
444 ASSERT_TRUE(RunPlatformAppTest(
445 "api_test/file_system/open_multiple_writable_existing_with_write"))
446 << message_;
449 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) {
450 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
451 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel"))
452 << message_;
453 CheckStoredDirectoryMatches(base::FilePath());
456 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) {
457 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background"))
458 << message_;
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(
465 &test_file);
466 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new"))
467 << message_;
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(
475 &test_file);
476 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_existing"))
477 << message_;
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(
486 &test_file);
487 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new_with_write"))
488 << message_;
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(
497 &test_file);
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(
510 &test_files);
511 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_multiple"))
512 << message_;
515 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) {
516 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
517 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel"))
518 << message_;
521 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) {
522 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background"))
523 << message_;
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(
530 &test_file);
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(
540 &test_file);
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(
550 &test_file);
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(
559 &test_file);
560 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/is_writable_file_entry"))
561 << message_;
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(
569 &test_file);
570 ASSERT_TRUE(RunPlatformAppTest(
571 "api_test/file_system/is_writable_file_entry_with_write"))
572 << message_;
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(
579 &test_file);
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(
595 &test_directory);
596 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/retain_directory"))
597 << message_;
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(
610 &test_file);
611 AppInstallObserver observer(
612 base::Bind(AddSavedEntry,
613 test_file,
614 false,
615 apps::SavedFilesService::Get(profile())));
616 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry"))
617 << message_;
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(
625 &test_file);
626 AppInstallObserver observer(
627 base::Bind(AddSavedEntry,
628 test_directory,
629 true,
630 apps::SavedFilesService::Get(profile())));
631 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory"))
632 << message_;
635 } // namespace extensions