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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 expected_galleries_.erase(user_added_id); | 1079 expected_galleries_.erase(user_added_id); |
1080 expected_device_map[info.device_id()].erase(user_added_id); | 1080 expected_device_map[info.device_id()].erase(user_added_id); |
1081 | 1081 |
1082 EXPECT_EQ(2, observer1.notifications()); | 1082 EXPECT_EQ(2, observer1.notifications()); |
1083 EXPECT_EQ(3, observer2.notifications()); | 1083 EXPECT_EQ(3, observer2.notifications()); |
1084 } | 1084 } |
1085 | 1085 |
1086 TEST_F(MediaGalleriesPreferencesTest, UpdateSingletonDeviceIdType) { | 1086 TEST_F(MediaGalleriesPreferencesTest, UpdateSingletonDeviceIdType) { |
1087 MediaGalleryPrefId id; | 1087 MediaGalleryPrefId id; |
1088 base::FilePath path; | 1088 base::FilePath path; |
1089 StorageInfo info; | |
1090 base::FilePath relative_path; | |
1091 Verify(); | 1089 Verify(); |
1092 | 1090 |
1093 // Add a new auto detect gallery to test with. | 1091 // Add a new auto detect gallery to test with. |
1094 path = MakeMediaGalleriesTestingPath("new_auto"); | 1092 path = MakeMediaGalleriesTestingPath("new_auto"); |
1095 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); | |
1096 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); | 1093 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); |
1097 info.set_device_id(StorageInfo::MakeDeviceId(StorageInfo::ITUNES, | 1094 std::string device_id = StorageInfo::MakeDeviceId(StorageInfo::ITUNES, |
1098 path.AsUTF8Unsafe())); | 1095 path.AsUTF8Unsafe()); |
1099 id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, | 1096 id = AddGalleryWithNameV2(device_id, gallery_name, base::FilePath(), |
1100 MediaGalleryPrefInfo::kAutoDetected); | 1097 MediaGalleryPrefInfo::kAutoDetected); |
1101 EXPECT_EQ(default_galleries_count() + 1UL, id); | 1098 EXPECT_EQ(default_galleries_count() + 1UL, id); |
1102 AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, | 1099 AddGalleryExpectation(id, gallery_name, device_id, base::FilePath(), |
1103 MediaGalleryPrefInfo::kAutoDetected); | 1100 MediaGalleryPrefInfo::kAutoDetected); |
1104 Verify(); | 1101 Verify(); |
1105 | 1102 |
1106 // Update the device id. | 1103 // Update the device id. |
1107 MockGalleryChangeObserver observer(gallery_prefs()); | 1104 MockGalleryChangeObserver observer(gallery_prefs()); |
1108 gallery_prefs()->AddGalleryChangeObserver(&observer); | 1105 gallery_prefs()->AddGalleryChangeObserver(&observer); |
1109 | 1106 |
1110 path = MakeMediaGalleriesTestingPath("updated_path"); | 1107 path = MakeMediaGalleriesTestingPath("updated_path"); |
1111 std::string updated_device_id = | 1108 std::string updated_device_id = |
1112 StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe()); | 1109 StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe()); |
1113 EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id)); | 1110 EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id)); |
1114 AddGalleryExpectation(id, gallery_name, updated_device_id, relative_path, | 1111 AddGalleryExpectation(id, gallery_name, updated_device_id, base::FilePath(), |
1115 MediaGalleryPrefInfo::kAutoDetected); | 1112 MediaGalleryPrefInfo::kAutoDetected); |
1116 expected_device_map[info.device_id()].erase(id); | 1113 expected_device_map[device_id].erase(id); |
1117 expected_device_map[updated_device_id].insert(id); | 1114 expected_device_map[updated_device_id].insert(id); |
1118 Verify(); | 1115 Verify(); |
1119 EXPECT_EQ(1, observer.notifications()); | 1116 EXPECT_EQ(1, observer.notifications()); |
1120 | 1117 |
1121 // No gallery for type. | 1118 // No gallery for type. |
1122 std::string new_device_id = | 1119 std::string new_device_id = |
1123 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); | 1120 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); |
1124 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); | 1121 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); |
1125 } | 1122 } |
1126 | 1123 |
| 1124 TEST_F(MediaGalleriesPreferencesTest, LookupImportedGalleryByPath) { |
| 1125 MediaGalleryPrefId id; |
| 1126 base::FilePath path; |
| 1127 Verify(); |
| 1128 |
| 1129 // iTunes device path points to an XML file in the library directory. |
| 1130 path = MakeMediaGalleriesTestingPath("new_auto").AppendASCII("library.xml"); |
| 1131 base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); |
| 1132 std::string device_id = StorageInfo::MakeDeviceId(StorageInfo::ITUNES, |
| 1133 path.AsUTF8Unsafe()); |
| 1134 id = AddGalleryWithNameV2(device_id, gallery_name, base::FilePath(), |
| 1135 MediaGalleryPrefInfo::kAutoDetected); |
| 1136 EXPECT_EQ(default_galleries_count() + 1UL, id); |
| 1137 AddGalleryExpectation(id, gallery_name, device_id, base::FilePath(), |
| 1138 MediaGalleryPrefInfo::kAutoDetected); |
| 1139 Verify(); |
| 1140 |
| 1141 // Verify we can look up the imported gallery by its path. |
| 1142 MediaGalleryPrefInfo gallery_info; |
| 1143 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(path.DirName(), |
| 1144 &gallery_info)); |
| 1145 EXPECT_EQ(id, gallery_info.pref_id); |
| 1146 } |
| 1147 |
1127 TEST_F(MediaGalleriesPreferencesTest, ScanResults) { | 1148 TEST_F(MediaGalleriesPreferencesTest, ScanResults) { |
1128 MediaGalleryPrefId id; | 1149 MediaGalleryPrefId id; |
1129 base::FilePath path; | 1150 base::FilePath path; |
1130 StorageInfo info; | 1151 StorageInfo info; |
1131 base::FilePath relative_path; | 1152 base::FilePath relative_path; |
1132 base::Time now = base::Time::Now(); | 1153 base::Time now = base::Time::Now(); |
1133 Verify(); | 1154 Verify(); |
1134 | 1155 |
1135 // Add a new scan result gallery to test with. | 1156 // Add a new scan result gallery to test with. |
1136 path = MakeMediaGalleriesTestingPath("new_scan"); | 1157 path = MakeMediaGalleriesTestingPath("new_scan"); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 info.volume_label = base::string16(); | 1242 info.volume_label = base::string16(); |
1222 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); | 1243 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); |
1223 | 1244 |
1224 info.device_id = StorageInfo::MakeDeviceId( | 1245 info.device_id = StorageInfo::MakeDeviceId( |
1225 StorageInfo::FIXED_MASS_STORAGE, "unique"); | 1246 StorageInfo::FIXED_MASS_STORAGE, "unique"); |
1226 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), | 1247 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), |
1227 base::UTF16ToUTF8(info.GetGalleryTooltip())); | 1248 base::UTF16ToUTF8(info.GetGalleryTooltip())); |
1228 | 1249 |
1229 TestStorageMonitor::Destroy(); | 1250 TestStorageMonitor::Destroy(); |
1230 } | 1251 } |
OLD | NEW |