Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/callback.h" | |
| 6 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 9 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "chrome/browser/apps/app_browsertest_util.h" | 15 #include "chrome/browser/apps/app_browsertest_util.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" | |
| 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 18 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 17 #include "chrome/browser/media_galleries/media_folder_finder.h" | 19 #include "chrome/browser/media_galleries/media_folder_finder.h" |
| 18 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 20 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 21 #include "chrome/browser/media_galleries/media_galleries_scan_result_dialog_cont roller.h" | |
| 19 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 22 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| 20 #include "chrome/browser/media_galleries/media_scan_manager.h" | 23 #include "chrome/browser/media_galleries/media_scan_manager.h" |
| 21 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 22 #include "components/storage_monitor/storage_info.h" | 25 #include "components/storage_monitor/storage_info.h" |
| 23 #include "components/storage_monitor/storage_monitor.h" | 26 #include "components/storage_monitor/storage_monitor.h" |
| 27 #include "content/public/browser/web_contents.h" | |
| 24 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
| 25 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
| 30 #include "extensions/common/extension.h" | |
| 26 | 31 |
| 27 #if defined(OS_WIN) || defined(OS_MACOSX) | 32 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 28 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" | 33 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
| 29 #include "chrome/common/media_galleries/picasa_test_util.h" | 34 #include "chrome/common/media_galleries/picasa_test_util.h" |
| 30 #include "chrome/common/media_galleries/picasa_types.h" | 35 #include "chrome/common/media_galleries/picasa_types.h" |
| 31 #include "chrome/common/media_galleries/pmp_test_util.h" | 36 #include "chrome/common/media_galleries/pmp_test_util.h" |
| 32 #endif | 37 #endif |
| 33 | 38 |
| 34 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
| 35 #include "base/mac/foundation_util.h" | 40 #include "base/mac/foundation_util.h" |
| 36 #include "base/strings/sys_string_conversions.h" | 41 #include "base/strings/sys_string_conversions.h" |
| 37 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h" | 42 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h" |
| 38 #endif // OS_MACOSX | 43 #endif // OS_MACOSX |
| 39 | 44 |
| 40 using extensions::PlatformAppBrowserTest; | 45 using extensions::PlatformAppBrowserTest; |
| 41 | 46 |
| 42 namespace { | 47 namespace { |
| 43 | 48 |
| 44 // Dummy device properties. | 49 // Dummy device properties. |
| 45 const char kDeviceId[] = "testDeviceId"; | 50 const char kDeviceId[] = "testDeviceId"; |
| 46 const char kDeviceName[] = "foobar"; | 51 const char kDeviceName[] = "foobar"; |
| 47 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 52 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
| 48 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); | 53 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("C:\\qux"); |
| 49 #else | 54 #else |
| 50 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux"); | 55 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux"); |
| 51 #endif | 56 #endif |
| 52 | 57 |
| 53 void DoNothingMediaFolderFinderResultCallback( | |
| 54 bool /*success*/, | |
| 55 const MediaFolderFinder::MediaFolderFinderResults& /*results*/) { | |
| 56 } | |
| 57 | |
| 58 class DoNothingMediaFolderFinder : public MediaFolderFinder { | 58 class DoNothingMediaFolderFinder : public MediaFolderFinder { |
| 59 public: | 59 public: |
| 60 explicit DoNothingMediaFolderFinder( | 60 explicit DoNothingMediaFolderFinder( |
| 61 const MediaFolderFinderResultsCallback& callback) | 61 const MediaFolderFinderResultsCallback& callback) |
| 62 : MediaFolderFinder(callback) { | 62 : MediaFolderFinder(callback) { |
| 63 } | 63 } |
| 64 virtual ~DoNothingMediaFolderFinder() {} | 64 virtual ~DoNothingMediaFolderFinder() {} |
| 65 | 65 |
| 66 static MediaFolderFinder* CreateDoNothingMediaFolderFinder( | 66 static MediaFolderFinder* CreateDoNothingMediaFolderFinder( |
| 67 const MediaFolderFinderResultsCallback& callback) { | 67 const MediaFolderFinderResultsCallback& callback) { |
| 68 return new DoNothingMediaFolderFinder( | 68 return new DoNothingMediaFolderFinder(callback); |
| 69 base::Bind(&DoNothingMediaFolderFinderResultCallback)); | |
| 70 } | 69 } |
| 71 | 70 |
| 72 virtual void StartScan() OVERRIDE {} | 71 virtual void StartScan() OVERRIDE {} |
| 73 | 72 |
| 74 private: | 73 private: |
| 75 }; | 74 }; |
| 76 | 75 |
| 77 } // namespace | 76 } // namespace |
| 78 | 77 |
| 78 class TestMediaGalleriesAddScanResultsFunction | |
| 79 : public extensions::MediaGalleriesAddScanResultsFunction { | |
| 80 public: | |
| 81 static ExtensionFunction* Factory() { | |
| 82 return new TestMediaGalleriesAddScanResultsFunction; | |
| 83 } | |
| 84 | |
| 85 protected: | |
| 86 virtual ~TestMediaGalleriesAddScanResultsFunction() {} | |
| 87 | |
| 88 // Accepts the dialog as soon as it is created. | |
| 89 virtual MediaGalleriesScanResultDialogController* MakeDialog( | |
| 90 content::WebContents* web_contents, | |
| 91 const extensions::Extension& extension, | |
| 92 const base::Closure& on_finish) OVERRIDE { | |
| 93 MediaGalleriesScanResultDialogController* controller = | |
| 94 extensions::MediaGalleriesAddScanResultsFunction::MakeDialog( | |
| 95 web_contents, extension, on_finish); | |
| 96 controller->dialog_->AcceptDialogForTesting(); | |
| 97 // The dialog is closing or closed so don't return it. | |
| 98 return NULL; | |
| 99 } | |
| 100 }; | |
| 101 | |
| 79 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { | 102 class MediaGalleriesPlatformAppBrowserTest : public PlatformAppBrowserTest { |
| 80 protected: | 103 protected: |
| 81 MediaGalleriesPlatformAppBrowserTest() : test_jpg_size_(0) {} | 104 MediaGalleriesPlatformAppBrowserTest() : test_jpg_size_(0) {} |
| 82 virtual ~MediaGalleriesPlatformAppBrowserTest() {} | 105 virtual ~MediaGalleriesPlatformAppBrowserTest() {} |
| 83 | 106 |
| 84 virtual void SetUpOnMainThread() OVERRIDE { | 107 virtual void SetUpOnMainThread() OVERRIDE { |
| 85 PlatformAppBrowserTest::SetUpOnMainThread(); | 108 PlatformAppBrowserTest::SetUpOnMainThread(); |
| 86 ensure_media_directories_exists_.reset(new EnsureMediaDirectoriesExists); | 109 ensure_media_directories_exists_.reset(new EnsureMediaDirectoriesExists); |
| 87 | 110 |
| 88 int64 file_size; | 111 int64 file_size; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 return ensure_media_directories_exists_.get(); | 374 return ensure_media_directories_exists_.get(); |
| 352 } | 375 } |
| 353 | 376 |
| 354 void InstallDoNothingFolderFinder() { | 377 void InstallDoNothingFolderFinder() { |
| 355 MediaScanManager * scan_manager = | 378 MediaScanManager * scan_manager = |
| 356 g_browser_process->media_file_system_registry()->media_scan_manager(); | 379 g_browser_process->media_file_system_registry()->media_scan_manager(); |
| 357 scan_manager->SetMediaFolderFinderFactory(base::Bind( | 380 scan_manager->SetMediaFolderFinderFactory(base::Bind( |
| 358 &DoNothingMediaFolderFinder::CreateDoNothingMediaFolderFinder)); | 381 &DoNothingMediaFolderFinder::CreateDoNothingMediaFolderFinder)); |
| 359 } | 382 } |
| 360 | 383 |
| 384 void SetRootsForFolderFinder(const std::vector<base::FilePath>& roots) { | |
| 385 MediaScanManager* scan_manager = | |
| 386 g_browser_process->media_file_system_registry()->media_scan_manager(); | |
| 387 scan_manager->SetMediaFolderFinderFactory(base::Bind( | |
| 388 &MediaGalleriesPlatformAppBrowserTest::CreateMediaFolderFinderWithRoots, | |
| 389 roots)); | |
| 390 } | |
| 391 | |
| 361 private: | 392 private: |
| 393 static MediaFolderFinder* CreateMediaFolderFinderWithRoots( | |
| 394 const std::vector<base::FilePath>& roots, | |
| 395 const MediaFolderFinder::MediaFolderFinderResultsCallback& callback) { | |
| 396 MediaFolderFinder* finder = new MediaFolderFinder(callback); | |
| 397 finder->SetRootsForTesting(roots); | |
| 398 return finder; | |
| 399 } | |
| 400 | |
| 362 MediaGalleriesPreferences* GetAndInitializePreferences() { | 401 MediaGalleriesPreferences* GetAndInitializePreferences() { |
| 363 MediaGalleriesPreferences* preferences = | 402 MediaGalleriesPreferences* preferences = |
| 364 g_browser_process->media_file_system_registry()->GetPreferences( | 403 g_browser_process->media_file_system_registry()->GetPreferences( |
| 365 browser()->profile()); | 404 browser()->profile()); |
| 366 base::RunLoop runloop; | 405 base::RunLoop runloop; |
| 367 preferences->EnsureInitialized(runloop.QuitClosure()); | 406 preferences->EnsureInitialized(runloop.QuitClosure()); |
| 368 runloop.Run(); | 407 runloop.Run(); |
| 369 return preferences; | 408 return preferences; |
| 370 } | 409 } |
| 371 | 410 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 ensure_media_directories_exists()->GetFakeIPhotoRootPath()); | 512 ensure_media_directories_exists()->GetFakeIPhotoRootPath()); |
| 474 | 513 |
| 475 base::ListValue custom_args; | 514 base::ListValue custom_args; |
| 476 custom_args.AppendInteger(test_jpg_size()); | 515 custom_args.AppendInteger(test_jpg_size()); |
| 477 ASSERT_TRUE(RunMediaGalleriesTestWithArg("iphoto", custom_args)) << message_; | 516 ASSERT_TRUE(RunMediaGalleriesTestWithArg("iphoto", custom_args)) << message_; |
| 478 | 517 |
| 479 iapps::SetMacPreferencesForTesting(NULL); | 518 iapps::SetMacPreferencesForTesting(NULL); |
| 480 } | 519 } |
| 481 #endif // defined(OS_MACOSX) | 520 #endif // defined(OS_MACOSX) |
| 482 | 521 |
| 483 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, Scan) { | 522 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, CancelScan) { |
| 484 InstallDoNothingFolderFinder(); | 523 InstallDoNothingFolderFinder(); |
| 524 ASSERT_TRUE(RunMediaGalleriesTest("cancel_scan")) << message_; | |
| 525 } | |
| 526 | |
| 527 // The scan result dialog is not implemented on GTK. | |
|
Lei Zhang
2014/02/20 23:51:34
Isn't it clearer to write:
#if defined(TOOLKIT_GT
vandebo (ex-Chrome)
2014/02/20 23:59:44
I actually think it's clearer to have the positive
vandebo (ex-Chrome)
2014/02/21 00:09:13
Done.
| |
| 528 #if defined (USE_AURA) || defined(OS_MACOSX) | |
| 529 #define MAYBE_Scan Scan | |
| 530 #else | |
| 531 #define MAYBE_Scan DISABLED_Scan | |
| 532 #endif // defined (USE_AURA) || defined(OS_MACOSX) | |
| 533 | |
| 534 IN_PROC_BROWSER_TEST_F(MediaGalleriesPlatformAppBrowserTest, MAYBE_Scan) { | |
| 535 base::ScopedTempDir scan_root; | |
| 536 ASSERT_TRUE(scan_root.CreateUniqueTempDir()); | |
| 537 std::vector<base::FilePath> roots; | |
| 538 roots.push_back(scan_root.path()); | |
| 539 SetRootsForFolderFinder(roots); | |
| 540 | |
| 541 // Override addScanResults so that the dialog is accepted as soon as it is | |
| 542 // created. | |
| 543 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( | |
| 544 "mediaGalleries.addScanResults", | |
| 545 &TestMediaGalleriesAddScanResultsFunction::Factory)); | |
| 546 | |
| 547 // Add some files and directories to the scan root for testing. Only the | |
| 548 // "f" directory should be found. | |
| 549 std::string dummy_data; | |
| 550 dummy_data.resize(1); | |
| 551 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("a/b"))); | |
| 552 ASSERT_EQ(static_cast<int>(dummy_data.size()), | |
| 553 file_util::WriteFile(scan_root.path().AppendASCII("a/b/c.jpg"), | |
| 554 dummy_data.c_str(), dummy_data.size())); | |
| 555 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("a/d"))); | |
| 556 dummy_data.resize(201 * 1024); // 200k is the min size for the folder finder. | |
| 557 ASSERT_EQ(static_cast<int>(dummy_data.size()), | |
| 558 file_util::WriteFile(scan_root.path().AppendASCII("a/d/e.txt"), | |
| 559 dummy_data.c_str(), dummy_data.size())); | |
| 560 ASSERT_TRUE(base::CreateDirectory(scan_root.path().AppendASCII("f"))); | |
| 561 ASSERT_EQ(static_cast<int>(dummy_data.size()), | |
| 562 file_util::WriteFile(scan_root.path().AppendASCII("f/g.jpg"), | |
| 563 dummy_data.c_str(), dummy_data.size())); | |
| 564 | |
| 485 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_; | 565 ASSERT_TRUE(RunMediaGalleriesTest("scan")) << message_; |
| 486 } | 566 } |
| OLD | NEW |