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 // MediaGalleriesPreferences unit tests. | 5 // MediaGalleriesPreferences unit tests. |
6 | 6 |
7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "sync/api/string_ordinal.h" | 26 #include "sync/api/string_ordinal.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
29 | 29 |
30 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
31 #include "chrome/browser/chromeos/login/user_manager.h" | 31 #include "chrome/browser/chromeos/login/user_manager.h" |
32 #include "chrome/browser/chromeos/settings/cros_settings.h" | 32 #include "chrome/browser/chromeos/settings/cros_settings.h" |
33 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 33 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
34 #endif | 34 #endif |
35 | 35 |
36 namespace chrome { | |
37 | |
38 namespace { | 36 namespace { |
39 | 37 |
40 class MockGalleryChangeObserver | 38 class MockGalleryChangeObserver |
41 : public MediaGalleriesPreferences::GalleryChangeObserver { | 39 : public MediaGalleriesPreferences::GalleryChangeObserver { |
42 public: | 40 public: |
43 explicit MockGalleryChangeObserver(MediaGalleriesPreferences* pref) | 41 explicit MockGalleryChangeObserver(MediaGalleriesPreferences* pref) |
44 : pref_(pref), | 42 : pref_(pref), |
45 notifications_(0) {} | 43 notifications_(0) {} |
46 virtual ~MockGalleryChangeObserver() {} | 44 virtual ~MockGalleryChangeObserver() {} |
47 | 45 |
(...skipping 24 matching lines...) Expand all Loading... |
72 | 70 |
73 MediaGalleriesPreferencesTest() | 71 MediaGalleriesPreferencesTest() |
74 : profile_(new TestingProfile()), | 72 : profile_(new TestingProfile()), |
75 default_galleries_count_(0) { | 73 default_galleries_count_(0) { |
76 } | 74 } |
77 | 75 |
78 virtual ~MediaGalleriesPreferencesTest() { | 76 virtual ~MediaGalleriesPreferencesTest() { |
79 } | 77 } |
80 | 78 |
81 virtual void SetUp() OVERRIDE { | 79 virtual void SetUp() OVERRIDE { |
82 ASSERT_TRUE(test::TestStorageMonitor::CreateAndInstall()); | 80 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); |
83 | 81 |
84 extensions::TestExtensionSystem* extension_system( | 82 extensions::TestExtensionSystem* extension_system( |
85 static_cast<extensions::TestExtensionSystem*>( | 83 static_cast<extensions::TestExtensionSystem*>( |
86 extensions::ExtensionSystem::Get(profile_.get()))); | 84 extensions::ExtensionSystem::Get(profile_.get()))); |
87 extension_system->CreateExtensionService( | 85 extension_system->CreateExtensionService( |
88 CommandLine::ForCurrentProcess(), base::FilePath(), false); | 86 CommandLine::ForCurrentProcess(), base::FilePath(), false); |
89 | 87 |
90 gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get())); | 88 gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get())); |
91 | 89 |
92 // Load the default galleries into the expectations. | 90 // Load the default galleries into the expectations. |
(...skipping 19 matching lines...) Expand all Loading... |
112 all_permission_extension = | 110 all_permission_extension = |
113 AddMediaGalleriesApp("all", all_permissions, profile_.get()); | 111 AddMediaGalleriesApp("all", all_permissions, profile_.get()); |
114 regular_permission_extension = | 112 regular_permission_extension = |
115 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); | 113 AddMediaGalleriesApp("regular", read_permissions, profile_.get()); |
116 no_permissions_extension = | 114 no_permissions_extension = |
117 AddMediaGalleriesApp("no", read_permissions, profile_.get()); | 115 AddMediaGalleriesApp("no", read_permissions, profile_.get()); |
118 } | 116 } |
119 | 117 |
120 virtual void TearDown() OVERRIDE { | 118 virtual void TearDown() OVERRIDE { |
121 Verify(); | 119 Verify(); |
122 test::TestStorageMonitor::RemoveSingleton(); | 120 TestStorageMonitor::RemoveSingleton(); |
123 } | 121 } |
124 | 122 |
125 void Verify() { | 123 void Verify() { |
126 const MediaGalleriesPrefInfoMap& known_galleries = | 124 const MediaGalleriesPrefInfoMap& known_galleries = |
127 gallery_prefs_->known_galleries(); | 125 gallery_prefs_->known_galleries(); |
128 EXPECT_EQ(expected_galleries_.size(), known_galleries.size()); | 126 EXPECT_EQ(expected_galleries_.size(), known_galleries.size()); |
129 for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); | 127 for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); |
130 it != known_galleries.end(); | 128 it != known_galleries.end(); |
131 ++it) { | 129 ++it) { |
132 VerifyGalleryInfo(it->second, it->first); | 130 VerifyGalleryInfo(it->second, it->first); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 private: | 233 private: |
236 // Needed for extension service & friends to work. | 234 // Needed for extension service & friends to work. |
237 content::TestBrowserThreadBundle thread_bundle_; | 235 content::TestBrowserThreadBundle thread_bundle_; |
238 | 236 |
239 #if defined OS_CHROMEOS | 237 #if defined OS_CHROMEOS |
240 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 238 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
241 chromeos::ScopedTestCrosSettings test_cros_settings_; | 239 chromeos::ScopedTestCrosSettings test_cros_settings_; |
242 chromeos::ScopedTestUserManager test_user_manager_; | 240 chromeos::ScopedTestUserManager test_user_manager_; |
243 #endif | 241 #endif |
244 | 242 |
245 test::TestStorageMonitor monitor_; | 243 TestStorageMonitor monitor_; |
246 scoped_ptr<TestingProfile> profile_; | 244 scoped_ptr<TestingProfile> profile_; |
247 scoped_ptr<MediaGalleriesPreferences> gallery_prefs_; | 245 scoped_ptr<MediaGalleriesPreferences> gallery_prefs_; |
248 | 246 |
249 uint64 default_galleries_count_; | 247 uint64 default_galleries_count_; |
250 | 248 |
251 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferencesTest); | 249 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferencesTest); |
252 }; | 250 }; |
253 | 251 |
254 base::FilePath MakePath(std::string dir) { | 252 base::FilePath MakePath(std::string dir) { |
255 #if defined(OS_WIN) | 253 #if defined(OS_WIN) |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 Verify(); | 797 Verify(); |
800 EXPECT_EQ(1, observer.notifications()); | 798 EXPECT_EQ(1, observer.notifications()); |
801 | 799 |
802 // No gallery for type. | 800 // No gallery for type. |
803 std::string new_device_id = | 801 std::string new_device_id = |
804 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); | 802 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); |
805 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); | 803 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); |
806 } | 804 } |
807 | 805 |
808 TEST(MediaGalleryPrefInfoTest, NameGeneration) { | 806 TEST(MediaGalleryPrefInfoTest, NameGeneration) { |
809 ASSERT_TRUE(test::TestStorageMonitor::CreateAndInstall()); | 807 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); |
810 | 808 |
811 MediaGalleryPrefInfo info; | 809 MediaGalleryPrefInfo info; |
812 info.pref_id = 1; | 810 info.pref_id = 1; |
813 info.display_name = ASCIIToUTF16("override"); | 811 info.display_name = ASCIIToUTF16("override"); |
814 info.device_id = StorageInfo::MakeDeviceId( | 812 info.device_id = StorageInfo::MakeDeviceId( |
815 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, "unique"); | 813 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, "unique"); |
816 | 814 |
817 EXPECT_EQ(ASCIIToUTF16("override"), info.GetGalleryDisplayName()); | 815 EXPECT_EQ(ASCIIToUTF16("override"), info.GetGalleryDisplayName()); |
818 | 816 |
819 info.display_name = ASCIIToUTF16("o2"); | 817 info.display_name = ASCIIToUTF16("o2"); |
(...skipping 19 matching lines...) Expand all Loading... |
839 info.display_name = string16(); | 837 info.display_name = string16(); |
840 EXPECT_EQ(ASCIIToUTF16("vol"), info.GetGalleryDisplayName()); | 838 EXPECT_EQ(ASCIIToUTF16("vol"), info.GetGalleryDisplayName()); |
841 info.volume_label = string16(); | 839 info.volume_label = string16(); |
842 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); | 840 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); |
843 | 841 |
844 info.device_id = StorageInfo::MakeDeviceId( | 842 info.device_id = StorageInfo::MakeDeviceId( |
845 StorageInfo::FIXED_MASS_STORAGE, "unique"); | 843 StorageInfo::FIXED_MASS_STORAGE, "unique"); |
846 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), | 844 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), |
847 UTF16ToUTF8(info.GetGalleryTooltip())); | 845 UTF16ToUTF8(info.GetGalleryTooltip())); |
848 | 846 |
849 test::TestStorageMonitor::RemoveSingleton(); | 847 TestStorageMonitor::RemoveSingleton(); |
850 } | 848 } |
851 | |
852 } // namespace chrome | |
OLD | NEW |