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

Side by Side Diff: chrome/browser/media_galleries/media_galleries_preferences_unittest.cc

Issue 140033003: Media galleries preferences also needs to track file counts for scan results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
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 // 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 void VerifyGalleryInfo(const MediaGalleryPrefInfo& actual, 185 void VerifyGalleryInfo(const MediaGalleryPrefInfo& actual,
186 MediaGalleryPrefId expected_id) const { 186 MediaGalleryPrefId expected_id) const {
187 MediaGalleriesPrefInfoMap::const_iterator in_expectation = 187 MediaGalleriesPrefInfoMap::const_iterator in_expectation =
188 expected_galleries_.find(expected_id); 188 expected_galleries_.find(expected_id);
189 ASSERT_FALSE(in_expectation == expected_galleries_.end()) << expected_id; 189 ASSERT_FALSE(in_expectation == expected_galleries_.end()) << expected_id;
190 EXPECT_EQ(in_expectation->second.pref_id, actual.pref_id); 190 EXPECT_EQ(in_expectation->second.pref_id, actual.pref_id);
191 EXPECT_EQ(in_expectation->second.display_name, actual.display_name); 191 EXPECT_EQ(in_expectation->second.display_name, actual.display_name);
192 EXPECT_EQ(in_expectation->second.device_id, actual.device_id); 192 EXPECT_EQ(in_expectation->second.device_id, actual.device_id);
193 EXPECT_EQ(in_expectation->second.path.value(), actual.path.value()); 193 EXPECT_EQ(in_expectation->second.path.value(), actual.path.value());
194 EXPECT_EQ(in_expectation->second.type, actual.type); 194 EXPECT_EQ(in_expectation->second.type, actual.type);
195 EXPECT_EQ(in_expectation->second.image_count, actual.image_count);
196 EXPECT_EQ(in_expectation->second.music_count, actual.music_count);
197 EXPECT_EQ(in_expectation->second.video_count, actual.video_count);
195 } 198 }
196 199
197 MediaGalleriesPreferences* gallery_prefs() { 200 MediaGalleriesPreferences* gallery_prefs() {
198 return gallery_prefs_.get(); 201 return gallery_prefs_.get();
199 } 202 }
200 203
201 uint64 default_galleries_count() { 204 uint64 default_galleries_count() {
202 return default_galleries_count_; 205 return default_galleries_count_;
203 } 206 }
204 207
205 void AddGalleryExpectation(MediaGalleryPrefId id, base::string16 display_name, 208 void AddGalleryExpectation(MediaGalleryPrefId id, base::string16 display_name,
206 std::string device_id, 209 std::string device_id,
207 base::FilePath relative_path, 210 base::FilePath relative_path,
208 MediaGalleryPrefInfo::Type type) { 211 MediaGalleryPrefInfo::Type type) {
209 expected_galleries_[id].pref_id = id; 212 expected_galleries_[id].pref_id = id;
210 expected_galleries_[id].display_name = display_name; 213 expected_galleries_[id].display_name = display_name;
211 expected_galleries_[id].device_id = device_id; 214 expected_galleries_[id].device_id = device_id;
212 expected_galleries_[id].path = relative_path.NormalizePathSeparators(); 215 expected_galleries_[id].path = relative_path.NormalizePathSeparators();
213 expected_galleries_[id].type = type; 216 expected_galleries_[id].type = type;
214 217
215 if (type == MediaGalleryPrefInfo::kAutoDetected) 218 if (type == MediaGalleryPrefInfo::kAutoDetected)
216 expected_galleries_for_all.insert(id); 219 expected_galleries_for_all.insert(id);
217 220
218 expected_device_map[device_id].insert(id); 221 expected_device_map[device_id].insert(id);
219 } 222 }
220 223
224 void AddScanResultExpectation(MediaGalleryPrefId id,
225 base::string16 display_name,
226 std::string device_id,
227 base::FilePath relative_path,
228 int image_count,
229 int music_count,
230 int video_count) {
231 AddGalleryExpectation(id, display_name, device_id, relative_path,
232 MediaGalleryPrefInfo::kScanResult);
233 expected_galleries_[id].image_count = image_count;
234 expected_galleries_[id].music_count = music_count;
235 expected_galleries_[id].video_count = video_count;
236 }
237
221 MediaGalleryPrefId AddGalleryWithNameV0(const std::string& device_id, 238 MediaGalleryPrefId AddGalleryWithNameV0(const std::string& device_id,
222 const base::string16& display_name, 239 const base::string16& display_name,
223 const base::FilePath& relative_path, 240 const base::FilePath& relative_path,
224 bool user_added) { 241 bool user_added) {
225 MediaGalleryPrefInfo::Type type = 242 MediaGalleryPrefInfo::Type type =
226 user_added ? MediaGalleryPrefInfo::kUserAdded 243 user_added ? MediaGalleryPrefInfo::kUserAdded
227 : MediaGalleryPrefInfo::kAutoDetected; 244 : MediaGalleryPrefInfo::kAutoDetected;
228 return gallery_prefs()->AddGalleryInternal( 245 return gallery_prefs()->AddGalleryInternal(
229 device_id, display_name, relative_path, type, 246 device_id, display_name, relative_path, type,
230 base::string16(), base::string16(), base::string16(), 0, base::Time(), 247 base::string16(), base::string16(), base::string16(), 0, base::Time(),
231 false, 0); 248 false, 0, 0, 0, 0);
232 } 249 }
233 250
234 MediaGalleryPrefId AddGalleryWithNameV1(const std::string& device_id, 251 MediaGalleryPrefId AddGalleryWithNameV1(const std::string& device_id,
235 const base::string16& display_name, 252 const base::string16& display_name,
236 const base::FilePath& relative_path, 253 const base::FilePath& relative_path,
237 bool user_added) { 254 bool user_added) {
238 MediaGalleryPrefInfo::Type type = 255 MediaGalleryPrefInfo::Type type =
239 user_added ? MediaGalleryPrefInfo::kUserAdded 256 user_added ? MediaGalleryPrefInfo::kUserAdded
240 : MediaGalleryPrefInfo::kAutoDetected; 257 : MediaGalleryPrefInfo::kAutoDetected;
241 return gallery_prefs()->AddGalleryInternal( 258 return gallery_prefs()->AddGalleryInternal(
242 device_id, display_name, relative_path, type, 259 device_id, display_name, relative_path, type,
243 base::string16(), base::string16(), base::string16(), 0, base::Time(), 260 base::string16(), base::string16(), base::string16(), 0, base::Time(),
244 false, 1); 261 false, 0, 0, 0, 1);
245 } 262 }
246 263
247 MediaGalleryPrefId AddGalleryWithNameV2(const std::string& device_id, 264 MediaGalleryPrefId AddGalleryWithNameV2(const std::string& device_id,
248 const base::string16& display_name, 265 const base::string16& display_name,
249 const base::FilePath& relative_path, 266 const base::FilePath& relative_path,
250 MediaGalleryPrefInfo::Type type) { 267 MediaGalleryPrefInfo::Type type) {
251 return gallery_prefs()->AddGalleryInternal( 268 return gallery_prefs()->AddGalleryInternal(
252 device_id, display_name, relative_path, type, 269 device_id, display_name, relative_path, type,
253 base::string16(), base::string16(), base::string16(), 0, base::Time(), 270 base::string16(), base::string16(), base::string16(), 0, base::Time(),
254 false, 2); 271 false, 0, 0, 0, 2);
255 } 272 }
256 273
257 bool UpdateDeviceIDForSingletonType(const std::string& device_id) { 274 bool UpdateDeviceIDForSingletonType(const std::string& device_id) {
258 return gallery_prefs()->UpdateDeviceIDForSingletonType(device_id); 275 return gallery_prefs()->UpdateDeviceIDForSingletonType(device_id);
259 } 276 }
260 277
261 scoped_refptr<extensions::Extension> all_permission_extension; 278 scoped_refptr<extensions::Extension> all_permission_extension;
262 scoped_refptr<extensions::Extension> regular_permission_extension; 279 scoped_refptr<extensions::Extension> regular_permission_extension;
263 scoped_refptr<extensions::Extension> no_permissions_extension; 280 scoped_refptr<extensions::Extension> no_permissions_extension;
264 281
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 Verify(); 460 Verify();
444 461
445 // Add a new auto detected gallery. 462 // Add a new auto detected gallery.
446 path = MakePath("new_auto"); 463 path = MakePath("new_auto");
447 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 464 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
448 id = gallery_prefs()->AddGallery(info.device_id(), relative_path, 465 id = gallery_prefs()->AddGallery(info.device_id(), relative_path,
449 MediaGalleryPrefInfo::kAutoDetected, 466 MediaGalleryPrefInfo::kAutoDetected,
450 ASCIIToUTF16("volume label"), 467 ASCIIToUTF16("volume label"),
451 ASCIIToUTF16("vendor name"), 468 ASCIIToUTF16("vendor name"),
452 ASCIIToUTF16("model name"), 469 ASCIIToUTF16("model name"),
453 1000000ULL, now); 470 1000000ULL, now, 0, 0, 0);
454 EXPECT_EQ(default_galleries_count() + 1UL, id); 471 EXPECT_EQ(default_galleries_count() + 1UL, id);
455 AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path, 472 AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path,
456 MediaGalleryPrefInfo::kAutoDetected); 473 MediaGalleryPrefInfo::kAutoDetected);
457 Verify(); 474 Verify();
458 475
459 MediaGalleryPrefInfo gallery_info; 476 MediaGalleryPrefInfo gallery_info;
460 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), 477 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"),
461 &gallery_info)); 478 &gallery_info));
462 EXPECT_TRUE(gallery_info.volume_metadata_valid); 479 EXPECT_TRUE(gallery_info.volume_metadata_valid);
463 EXPECT_EQ(ASCIIToUTF16("volume label"), gallery_info.volume_label); 480 EXPECT_EQ(ASCIIToUTF16("volume label"), gallery_info.volume_label);
(...skipping 25 matching lines...) Expand all
489 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path, 506 AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
490 MediaGalleryPrefInfo::kAutoDetected); 507 MediaGalleryPrefInfo::kAutoDetected);
491 Verify(); 508 Verify();
492 509
493 metadata_id = gallery_prefs()->AddGallery(info.device_id(), 510 metadata_id = gallery_prefs()->AddGallery(info.device_id(),
494 relative_path, 511 relative_path,
495 MediaGalleryPrefInfo::kAutoDetected, 512 MediaGalleryPrefInfo::kAutoDetected,
496 ASCIIToUTF16("volume label"), 513 ASCIIToUTF16("volume label"),
497 ASCIIToUTF16("vendor name"), 514 ASCIIToUTF16("vendor name"),
498 ASCIIToUTF16("model name"), 515 ASCIIToUTF16("model name"),
499 1000000ULL, now); 516 1000000ULL, now, 0, 0, 0);
500 EXPECT_EQ(id, metadata_id); 517 EXPECT_EQ(id, metadata_id);
501 AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path, 518 AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path,
502 MediaGalleryPrefInfo::kAutoDetected); 519 MediaGalleryPrefInfo::kAutoDetected);
503 520
504 // Make sure the display_name is set to empty now, as the metadata 521 // Make sure the display_name is set to empty now, as the metadata
505 // upgrade should set the manual override name empty. 522 // upgrade should set the manual override name empty.
506 Verify(); 523 Verify();
507 } 524 }
508 525
509 // Whenever an "AutoDetected" gallery is removed, it is moved to a black listed 526 // Whenever an "AutoDetected" gallery is removed, it is moved to a black listed
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 expected_device_map[updated_device_id].insert(id); 1012 expected_device_map[updated_device_id].insert(id);
996 Verify(); 1013 Verify();
997 EXPECT_EQ(1, observer.notifications()); 1014 EXPECT_EQ(1, observer.notifications());
998 1015
999 // No gallery for type. 1016 // No gallery for type.
1000 std::string new_device_id = 1017 std::string new_device_id =
1001 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); 1018 StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe());
1002 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); 1019 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id));
1003 } 1020 }
1004 1021
1022 TEST_F(MediaGalleriesPreferencesTest, ScanResults) {
1023 MediaGalleryPrefId id;
1024 base::FilePath path;
1025 StorageInfo info;
1026 base::FilePath relative_path;
1027 base::Time now = base::Time::Now();
1028 Verify();
1029
1030 // Add a new scan result gallery to test with.
1031 path = MakePath("new_scan");
1032 MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
1033 id = gallery_prefs()->AddGallery(info.device_id(), relative_path,
1034 MediaGalleryPrefInfo::kScanResult,
1035 ASCIIToUTF16("volume label"),
1036 ASCIIToUTF16("vendor name"),
1037 ASCIIToUTF16("model name"),
1038 1000000ULL, now, 1, 2, 3);
1039 EXPECT_EQ(default_galleries_count() + 1UL, id);
1040 AddScanResultExpectation(id, base::string16(), info.device_id(),
1041 relative_path, 1, 2, 3);
1042 Verify();
1043
1044 // Update the found media count.
1045 id = gallery_prefs()->AddGallery(info.device_id(), relative_path,
1046 MediaGalleryPrefInfo::kScanResult,
1047 ASCIIToUTF16("volume label"),
1048 ASCIIToUTF16("vendor name"),
1049 ASCIIToUTF16("model name"),
1050 1000000ULL, now, 4, 5, 6);
1051 EXPECT_EQ(default_galleries_count() + 1UL, id);
1052 AddScanResultExpectation(id, base::string16(), info.device_id(),
1053 relative_path, 4, 5, 6);
1054 Verify();
1055
1056 // Remove a scan result (i.e. make it blacklisted).
1057 gallery_prefs()->ForgetGalleryById(id);
1058 expected_galleries_[id].type = MediaGalleryPrefInfo::kRemovedScan;
1059 expected_galleries_[id].image_count = 0;
1060 expected_galleries_[id].music_count = 0;
1061 expected_galleries_[id].video_count = 0;
1062 Verify();
1063
1064 // Try adding the gallery again as a scan result it should be a no-op.
1065 id = gallery_prefs()->AddGallery(info.device_id(), relative_path,
1066 MediaGalleryPrefInfo::kScanResult,
1067 ASCIIToUTF16("volume label"),
1068 ASCIIToUTF16("vendor name"),
1069 ASCIIToUTF16("model name"),
1070 1000000ULL, now, 7, 8, 9);
1071 EXPECT_EQ(default_galleries_count() + 1UL, id);
1072 Verify();
1073
1074 // Add the gallery again as a user action.
1075 id = gallery_prefs()->AddGalleryByPath(path,
1076 MediaGalleryPrefInfo::kUserAdded);
1077 EXPECT_EQ(default_galleries_count() + 1UL, id);
1078 AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path,
1079 MediaGalleryPrefInfo::kUserAdded);
1080 Verify();
1081 }
1082
1005 TEST(MediaGalleriesPrefInfoTest, NameGeneration) { 1083 TEST(MediaGalleriesPrefInfoTest, NameGeneration) {
1006 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); 1084 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall());
1007 1085
1008 MediaGalleryPrefInfo info; 1086 MediaGalleryPrefInfo info;
1009 info.pref_id = 1; 1087 info.pref_id = 1;
1010 info.display_name = ASCIIToUTF16("override"); 1088 info.display_name = ASCIIToUTF16("override");
1011 info.device_id = StorageInfo::MakeDeviceId( 1089 info.device_id = StorageInfo::MakeDeviceId(
1012 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, "unique"); 1090 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, "unique");
1013 1091
1014 EXPECT_EQ(ASCIIToUTF16("override"), info.GetGalleryDisplayName()); 1092 EXPECT_EQ(ASCIIToUTF16("override"), info.GetGalleryDisplayName());
(...skipping 23 matching lines...) Expand all
1038 info.volume_label = base::string16(); 1116 info.volume_label = base::string16();
1039 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); 1117 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName());
1040 1118
1041 info.device_id = StorageInfo::MakeDeviceId( 1119 info.device_id = StorageInfo::MakeDeviceId(
1042 StorageInfo::FIXED_MASS_STORAGE, "unique"); 1120 StorageInfo::FIXED_MASS_STORAGE, "unique");
1043 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), 1121 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(),
1044 base::UTF16ToUTF8(info.GetGalleryTooltip())); 1122 base::UTF16ToUTF8(info.GetGalleryTooltip()));
1045 1123
1046 TestStorageMonitor::RemoveSingleton(); 1124 TestStorageMonitor::RemoveSingleton();
1047 } 1125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698