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

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

Issue 18331017: Support choosing multiple files with fileSystem.chooseEntry. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 4 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/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 10 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 "test_temp", temp_dir_.path()); 90 "test_temp", temp_dir_.path());
91 91
92 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name); 92 base::FilePath destination = temp_dir_.path().AppendASCII(destination_name);
93 if (copy_gold) { 93 if (copy_gold) {
94 base::FilePath source = test_root_folder_.AppendASCII("gold.txt"); 94 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
95 EXPECT_TRUE(base::CopyFile(source, destination)); 95 EXPECT_TRUE(base::CopyFile(source, destination));
96 } 96 }
97 return destination; 97 return destination;
98 } 98 }
99 99
100 std::vector<base::FilePath> TempFilePaths(
101 const std::vector<std::string>& destination_names,
102 bool copy_gold) {
103 if (!temp_dir_.CreateUniqueTempDir()) {
104 ADD_FAILURE() << "CreateUniqueTempDir failed";
105 return std::vector<base::FilePath>();
106 }
107 FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest(
108 "test_temp", temp_dir_.path());
109
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);
115 if (copy_gold) {
116 base::FilePath source = test_root_folder_.AppendASCII("gold.txt");
117 EXPECT_TRUE(base::CopyFile(source, destination));
118 }
119 result.push_back(destination);
120 }
121 return result;
122 }
123
100 void CheckStoredDirectoryMatches(const base::FilePath& filename) { 124 void CheckStoredDirectoryMatches(const base::FilePath& filename) {
101 const Extension* extension = GetSingleLoadedExtension(); 125 const Extension* extension = GetSingleLoadedExtension();
102 ASSERT_TRUE(extension); 126 ASSERT_TRUE(extension);
103 std::string extension_id = extension->id(); 127 std::string extension_id = extension->id();
104 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); 128 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
105 base::FilePath stored_value; 129 base::FilePath stored_value;
106 if (filename.empty()) { 130 if (filename.empty()) {
107 EXPECT_FALSE(file_system_api::GetLastChooseEntryDirectory( 131 EXPECT_FALSE(file_system_api::GetLastChooseEntryDirectory(
108 prefs, extension_id, &stored_value)); 132 prefs, extension_id, &stored_value));
109 } else { 133 } else {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 ASSERT_FALSE(test_file.empty()); 239 ASSERT_FALSE(test_file.empty());
216 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( 240 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
217 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false)); 241 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false));
218 FileSystemChooseEntryFunction:: 242 FileSystemChooseEntryFunction::
219 SkipPickerAndSelectSuggestedPathForTest(); 243 SkipPickerAndSelectSuggestedPathForTest();
220 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) 244 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing"))
221 << message_; 245 << message_;
222 CheckStoredDirectoryMatches(test_file); 246 CheckStoredDirectoryMatches(test_file);
223 } 247 }
224 248
249 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenMultipleSuggested) {
250 base::FilePath test_file = TempFilePath("open_existing.txt", true);
251 ASSERT_FALSE(test_file.empty());
252 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(
253 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false));
254 FileSystemChooseEntryFunction::SkipPickerAndSelectSuggestedPathForTest();
255 ASSERT_TRUE(RunPlatformAppTest(
256 "api_test/file_system/open_multiple_with_suggested_name"))
257 << message_;
258 CheckStoredDirectoryMatches(test_file);
259 }
260
261 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
262 FileSystemApiOpenMultipleExistingFilesTest) {
263 std::vector<std::string> names;
264 names.push_back("open_existing1.txt");
265 names.push_back("open_existing2.txt");
266 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
267 ASSERT_EQ(2u, test_files.size());
268 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
269 &test_files);
270 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_multiple_existing"))
271 << message_;
272 }
273
225 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, 274 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
226 FileSystemApiInvalidChooseEntryTypeTest) { 275 FileSystemApiInvalidChooseEntryTypeTest) {
227 base::FilePath test_file = TempFilePath("open_existing.txt", true); 276 base::FilePath test_file = TempFilePath("open_existing.txt", true);
228 ASSERT_FALSE(test_file.empty()); 277 ASSERT_FALSE(test_file.empty());
229 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 278 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
230 &test_file); 279 &test_file);
231 ASSERT_TRUE(RunPlatformAppTest( 280 ASSERT_TRUE(RunPlatformAppTest(
232 "api_test/file_system/invalid_choose_file_type")) << message_; 281 "api_test/file_system/invalid_choose_file_type")) << message_;
233 CheckStoredDirectoryMatches(base::FilePath()); 282 CheckStoredDirectoryMatches(base::FilePath());
234 } 283 }
(...skipping 30 matching lines...) Expand all
265 FileSystemApiOpenWritableExistingFileWithWriteTest) { 314 FileSystemApiOpenWritableExistingFileWithWriteTest) {
266 base::FilePath test_file = TempFilePath("open_existing.txt", true); 315 base::FilePath test_file = TempFilePath("open_existing.txt", true);
267 ASSERT_FALSE(test_file.empty()); 316 ASSERT_FALSE(test_file.empty());
268 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 317 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
269 &test_file); 318 &test_file);
270 ASSERT_TRUE(RunPlatformAppTest( 319 ASSERT_TRUE(RunPlatformAppTest(
271 "api_test/file_system/open_writable_existing_with_write")) << message_; 320 "api_test/file_system/open_writable_existing_with_write")) << message_;
272 CheckStoredDirectoryMatches(test_file); 321 CheckStoredDirectoryMatches(test_file);
273 } 322 }
274 323
324 IN_PROC_BROWSER_TEST_F(FileSystemApiTest,
325 FileSystemApiOpenMultipleWritableExistingFilesTest) {
326 std::vector<std::string> names;
327 names.push_back("open_existing1.txt");
328 names.push_back("open_existing2.txt");
329 std::vector<base::FilePath> test_files = TempFilePaths(names, true);
330 ASSERT_EQ(2u, test_files.size());
331 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
332 &test_files);
333 ASSERT_TRUE(RunPlatformAppTest(
334 "api_test/file_system/open_multiple_writable_existing_with_write"))
335 << message_;
336 }
337
275 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) { 338 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) {
276 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); 339 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
277 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel")) 340 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel"))
278 << message_; 341 << message_;
279 CheckStoredDirectoryMatches(base::FilePath()); 342 CheckStoredDirectoryMatches(base::FilePath());
280 } 343 }
281 344
282 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) { 345 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) {
283 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background")) 346 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background"))
284 << message_; 347 << message_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 FileSystemApiSaveExistingFileWithWriteTest) { 382 FileSystemApiSaveExistingFileWithWriteTest) {
320 base::FilePath test_file = TempFilePath("save_existing.txt", true); 383 base::FilePath test_file = TempFilePath("save_existing.txt", true);
321 ASSERT_FALSE(test_file.empty()); 384 ASSERT_FALSE(test_file.empty());
322 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( 385 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
323 &test_file); 386 &test_file);
324 ASSERT_TRUE(RunPlatformAppTest( 387 ASSERT_TRUE(RunPlatformAppTest(
325 "api_test/file_system/save_existing_with_write")) << message_; 388 "api_test/file_system/save_existing_with_write")) << message_;
326 CheckStoredDirectoryMatches(test_file); 389 CheckStoredDirectoryMatches(test_file);
327 } 390 }
328 391
392 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveMultipleFilesTest) {
393 std::vector<std::string> names;
394 names.push_back("save1.txt");
395 names.push_back("save2.txt");
396 std::vector<base::FilePath> test_files = TempFilePaths(names, false);
397 ASSERT_EQ(2u, test_files.size());
398 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathsForTest(
399 &test_files);
400 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_multiple"))
401 << message_;
402 }
403
329 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) { 404 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) {
330 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); 405 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest();
331 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel")) 406 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel"))
332 << message_; 407 << message_;
333 } 408 }
334 409
335 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) { 410 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) {
336 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background")) 411 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background"))
337 << message_; 412 << message_;
338 } 413 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 AppInstallObserver observer( 572 AppInstallObserver observer(
498 base::Bind(SetLastChooseEntryDirectoryToAppDirectory, 573 base::Bind(SetLastChooseEntryDirectoryToAppDirectory,
499 ExtensionPrefs::Get(profile()))); 574 ExtensionPrefs::Get(profile())));
500 ASSERT_TRUE(RunPlatformAppTest( 575 ASSERT_TRUE(RunPlatformAppTest(
501 "api_test/file_system/open_writable_existing_non_writable")) 576 "api_test/file_system/open_writable_existing_non_writable"))
502 << message_; 577 << message_;
503 } 578 }
504 } 579 }
505 580
506 } // namespace extensions 581 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/file_system/file_system_api.cc ('k') | chrome/common/extensions/api/file_system.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698