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

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

Issue 23146016: Add support for directory access to the file system API. (Closed) Base URL: http://git.chromium.org/chromium/src.git@simpler-write-permissions
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "apps/saved_files_service.h" 5 #include "apps/saved_files_service.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/apps/app_browsertest_util.h" 9 #include "chrome/browser/apps/app_browsertest_util.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 11 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/extensions/features/feature_channel.h"
14 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
16 17
17 namespace extensions { 18 namespace extensions {
18 19
19 namespace { 20 namespace {
20 21
21 class AppInstallObserver : public content::NotificationObserver { 22 class AppInstallObserver : public content::NotificationObserver {
22 public: 23 public:
23 AppInstallObserver( 24 AppInstallObserver(
(...skipping 25 matching lines...) Expand all
49 } 50 }
50 51
51 void SetLastChooseEntryDirectoryToAppDirectory( 52 void SetLastChooseEntryDirectoryToAppDirectory(
52 ExtensionPrefs* prefs, 53 ExtensionPrefs* prefs,
53 const Extension* extension) { 54 const Extension* extension) {
54 file_system_api::SetLastChooseEntryDirectory( 55 file_system_api::SetLastChooseEntryDirectory(
55 prefs, extension->id(), extension->path()); 56 prefs, extension->id(), extension->path());
56 } 57 }
57 58
58 void AddSavedEntry(const base::FilePath& path_to_save, 59 void AddSavedEntry(const base::FilePath& path_to_save,
60 bool is_directory,
59 apps::SavedFilesService* service, 61 apps::SavedFilesService* service,
60 const Extension* extension) { 62 const Extension* extension) {
61 service->RegisterFileEntry(extension->id(), "magic id", path_to_save); 63 service->RegisterFileEntry(
64 extension->id(), "magic id", path_to_save, is_directory);
62 } 65 }
63 66
64 } // namespace 67 } // namespace
65 68
66 class FileSystemApiTest : public PlatformAppBrowserTest { 69 class FileSystemApiTest : public PlatformAppBrowserTest {
67 public: 70 public:
68 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 71 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
69 PlatformAppBrowserTest::SetUpCommandLine(command_line); 72 PlatformAppBrowserTest::SetUpCommandLine(command_line);
70 test_root_folder_ = test_data_dir_.AppendASCII("api_test") 73 test_root_folder_ = test_data_dir_.AppendASCII("api_test")
71 .AppendASCII("file_system"); 74 .AppendASCII("file_system");
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 names.push_back("open_existing1.txt"); 270 names.push_back("open_existing1.txt");
268 names.push_back("open_existing2.txt"); 271 names.push_back("open_existing2.txt");
269 std::vector<base::FilePath> test_files = TempFilePaths(names, true); 272 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
270 ASSERT_EQ(2u, test_files.size()); 273 ASSERT_EQ(2u, test_files.size());
271 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest( 274 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
272 &test_files); 275 &test_files);
273 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing")) 276 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing"))
274 << message_; 277 << message_;
275 } 278 }
276 279
280 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenDirectoryTest) {
281 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN);
282 base::FilePath test_file = TempFilePath("open_existing.txt", true);
283 ASSERT_FALSE(test_file.empty());
284 base::FilePath test_directory = test_file.DirName();
285 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
286 &test_directory);
287 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory"))
288 << message_;
289 CheckStoredDirectoryMatches(test_file);
290 }
291
292 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
293 FileSystemApiOpenDirectoryWithWriteTest) {
294 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN);
295 base::FilePath test_file = TempFilePath("open_existing.txt", true);
296 ASSERT_FALSE(test_file.empty());
297 base::FilePath test_directory = test_file.DirName();
298 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
299 &test_directory);
300 ASSERT_TRUE(
301 RunPlatformAppTest("api_test/file_system/open_directory_with_write"))
302 << message_;
303 CheckStoredDirectoryMatches(test_file);
304 }
305
306 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
307 FileSystemApiOpenDirectoryWithoutPermissionTest) {
308 base::FilePath test_file = TempFilePath("open_existing.txt", true);
309 ASSERT_FALSE(test_file.empty());
310 base::FilePath test_directory = test_file.DirName();
311 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
312 &test_directory);
313 ASSERT_TRUE(RunPlatformAppTest(
314 "api_test/file_system/open_directory_without_permission"))
315 << message_;
316 CheckStoredDirectoryMatches(base::FilePath());
317 }
318
319 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
320 FileSystemApiOpenDirectoryWithOnlyWritePermissionTest) {
321 base::FilePath test_file = TempFilePath("open_existing.txt", true);
322 ASSERT_FALSE(test_file.empty());
323 base::FilePath test_directory = test_file.DirName();
324 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
325 &test_directory);
326 ASSERT_TRUE(RunPlatformAppTest(
327 "api_test/file_system/open_directory_with_only_write"))
328 << message_;
329 CheckStoredDirectoryMatches(base::FilePath());
330 }
331
277 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, 332 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
278 FileSystemApiInvalidChooseEntryTypeTest) { 333 FileSystemApiInvalidChooseEntryTypeTest) {
279 base::FilePath test_file = TempFilePath("open_existing.txt", true); 334 base::FilePath test_file = TempFilePath("open_existing.txt", true);
280 ASSERT_FALSE(test_file.empty()); 335 ASSERT_FALSE(test_file.empty());
281 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 336 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
282 &test_file); 337 &test_file);
283 ASSERT_TRUE(RunPlatformAppTest( 338 ASSERT_TRUE(RunPlatformAppTest(
284 "api_test/file_system/invalid_choose_file_type")) << message_; 339 "api_test/file_system/invalid_choose_file_type")) << message_;
285 CheckStoredDirectoryMatches(base::FilePath()); 340 CheckStoredDirectoryMatches(base::FilePath());
286 } 341 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 &test_file); 516 &test_file);
462 ASSERT_TRUE(RunPlatformAppTest( 517 ASSERT_TRUE(RunPlatformAppTest(
463 "api_test/file_system/retain_entry")) << message_; 518 "api_test/file_system/retain_entry")) << message_;
464 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get( 519 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get(
465 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id()); 520 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id());
466 ASSERT_EQ(1u, file_entries.size()); 521 ASSERT_EQ(1u, file_entries.size());
467 EXPECT_EQ(test_file, file_entries[0].path); 522 EXPECT_EQ(test_file, file_entries[0].path);
468 EXPECT_EQ(1, file_entries[0].sequence_number); 523 EXPECT_EQ(1, file_entries[0].sequence_number);
469 } 524 }
470 525
526 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRetainDirectoryEntry) {
527 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN);
528 base::FilePath test_file = TempFilePath("open_existing.txt", true);
529 ASSERT_FALSE(test_file.empty());
530 base::FilePath test_directory = test_file.DirName();
531 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
532 &test_directory);
533 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/retain_directory"))
534 << message_;
535 std::vector<apps::SavedFileEntry> file_entries = apps::SavedFilesService::Get(
536 profile())->GetAllFileEntries(GetSingleLoadedExtension()->id());
537 ASSERT_EQ(1u, file_entries.size());
538 EXPECT_EQ(test_directory, file_entries[0].path);
539 EXPECT_EQ(1, file_entries[0].sequence_number);
540 EXPECT_TRUE(file_entries[0].is_directory);
541 }
542
471 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) { 543 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) {
472 base::FilePath test_file = TempFilePath("writable.txt", true); 544 base::FilePath test_file = TempFilePath("writable.txt", true);
473 ASSERT_FALSE(test_file.empty()); 545 ASSERT_FALSE(test_file.empty());
474 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 546 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
475 &test_file); 547 &test_file);
476 { 548 AppInstallObserver observer(
477 AppInstallObserver observer(base::Bind( 549 base::Bind(AddSavedEntry,
478 AddSavedEntry, test_file, apps::SavedFilesService::Get(profile()))); 550 test_file,
479 ASSERT_TRUE(RunPlatformAppTest( 551 false,
480 "api_test/file_system/restore_entry")) << message_; 552 apps::SavedFilesService::Get(profile())));
481 } 553 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry"))
554 << message_;
555 }
556
557 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) {
558 ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN);
559 base::FilePath test_file = TempFilePath("writable.txt", true);
560 ASSERT_FALSE(test_file.empty());
561 base::FilePath test_directory = test_file.DirName();
562 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
563 &test_file);
564 AppInstallObserver observer(
565 base::Bind(AddSavedEntry,
566 test_directory,
567 true,
568 apps::SavedFilesService::Get(profile())));
569 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory"))
570 << message_;
482 } 571 }
483 572
484 } // namespace extensions 573 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/file_system/file_system_api.cc ('k') | chrome/common/extensions/api/_permission_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698