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
3 // found in the LICENSE file.
5 // MediaGalleriesPreferences unit tests.
7 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
9 #include "base/command_line.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/values.h"
15 #include "chrome/browser/extensions/extension_system.h"
16 #include "chrome/browser/extensions/test_extension_system.h"
17 #include "chrome/browser/media_galleries/media_file_system_registry.h"
18 #include "chrome/browser/media_galleries/media_galleries_test_util.h"
19 #include "chrome/browser/storage_monitor/media_storage_util.h"
20 #include "chrome/browser/storage_monitor/storage_monitor.h"
21 #include "chrome/browser/storage_monitor/test_storage_monitor.h"
22 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "extensions/common/extension.h"
25 #include "extensions/common/manifest_handlers/background_info.h"
26 #include "grit/generated_resources.h"
27 #include "sync/api/string_ordinal.h"
28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/base/l10n/l10n_util.h"
31 #if defined(OS_CHROMEOS)
32 #include "chrome/browser/chromeos/login/user_manager.h"
33 #include "chrome/browser/chromeos/settings/cros_settings.h"
34 #include "chrome/browser/chromeos/settings/device_settings_service.h"
37 using base::ASCIIToUTF16
;
41 class MockGalleryChangeObserver
42 : public MediaGalleriesPreferences::GalleryChangeObserver
{
44 explicit MockGalleryChangeObserver(MediaGalleriesPreferences
* pref
)
47 virtual ~MockGalleryChangeObserver() {}
49 int notifications() const { return notifications_
;}
52 // MediaGalleriesPreferences::GalleryChangeObserver implementation.
53 virtual void OnPermissionAdded(MediaGalleriesPreferences
* pref
,
54 const std::string
& extension_id
,
55 MediaGalleryPrefId pref_id
) OVERRIDE
{
56 EXPECT_EQ(pref_
, pref
);
60 virtual void OnPermissionRemoved(MediaGalleriesPreferences
* pref
,
61 const std::string
& extension_id
,
62 MediaGalleryPrefId pref_id
) OVERRIDE
{
63 EXPECT_EQ(pref_
, pref
);
67 virtual void OnGalleryAdded(MediaGalleriesPreferences
* pref
,
68 MediaGalleryPrefId pref_id
) OVERRIDE
{
69 EXPECT_EQ(pref_
, pref
);
73 virtual void OnGalleryRemoved(MediaGalleriesPreferences
* pref
,
74 MediaGalleryPrefId pref_id
) OVERRIDE
{
75 EXPECT_EQ(pref_
, pref
);
79 virtual void OnGalleryInfoUpdated(MediaGalleriesPreferences
* pref
,
80 MediaGalleryPrefId pref_id
) OVERRIDE
{
81 EXPECT_EQ(pref_
, pref
);
85 MediaGalleriesPreferences
* pref_
;
88 DISALLOW_COPY_AND_ASSIGN(MockGalleryChangeObserver
);
93 class MediaGalleriesPreferencesTest
: public testing::Test
{
95 typedef std::map
<std::string
/*device id*/, MediaGalleryPrefIdSet
>
98 MediaGalleriesPreferencesTest()
99 : profile_(new TestingProfile()),
100 default_galleries_count_(0) {
103 virtual ~MediaGalleriesPreferencesTest() {
106 virtual void SetUp() OVERRIDE
{
107 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall());
109 extensions::TestExtensionSystem
* extension_system(
110 static_cast<extensions::TestExtensionSystem
*>(
111 extensions::ExtensionSystem::Get(profile_
.get())));
112 extension_system
->CreateExtensionService(
113 CommandLine::ForCurrentProcess(), base::FilePath(), false);
115 gallery_prefs_
.reset(new MediaGalleriesPreferences(profile_
.get()));
117 gallery_prefs_
->EnsureInitialized(loop
.QuitClosure());
120 // Load the default galleries into the expectations.
121 const MediaGalleriesPrefInfoMap
& known_galleries
=
122 gallery_prefs_
->known_galleries();
123 if (known_galleries
.size()) {
124 ASSERT_EQ(3U, known_galleries
.size());
125 default_galleries_count_
= 3;
126 MediaGalleriesPrefInfoMap::const_iterator it
;
127 for (it
= known_galleries
.begin(); it
!= known_galleries
.end(); ++it
) {
128 expected_galleries_
[it
->first
] = it
->second
;
129 if (it
->second
.type
== MediaGalleryPrefInfo::kAutoDetected
)
130 expected_galleries_for_all
.insert(it
->first
);
134 std::vector
<std::string
> all_permissions
;
135 all_permissions
.push_back("allAutoDetected");
136 all_permissions
.push_back("read");
137 std::vector
<std::string
> read_permissions
;
138 read_permissions
.push_back("read");
140 all_permission_extension
=
141 AddMediaGalleriesApp("all", all_permissions
, profile_
.get());
142 regular_permission_extension
=
143 AddMediaGalleriesApp("regular", read_permissions
, profile_
.get());
144 no_permissions_extension
=
145 AddMediaGalleriesApp("no", read_permissions
, profile_
.get());
148 virtual void TearDown() OVERRIDE
{
150 TestStorageMonitor::RemoveSingleton();
154 const MediaGalleriesPrefInfoMap
& known_galleries
=
155 gallery_prefs_
->known_galleries();
156 EXPECT_EQ(expected_galleries_
.size(), known_galleries
.size());
157 for (MediaGalleriesPrefInfoMap::const_iterator it
= known_galleries
.begin();
158 it
!= known_galleries
.end();
160 VerifyGalleryInfo(it
->second
, it
->first
);
163 for (DeviceIdPrefIdsMap::const_iterator it
= expected_device_map
.begin();
164 it
!= expected_device_map
.end();
166 MediaGalleryPrefIdSet actual_id_set
=
167 gallery_prefs_
->LookUpGalleriesByDeviceId(it
->first
);
168 EXPECT_EQ(it
->second
, actual_id_set
);
171 std::set
<MediaGalleryPrefId
> galleries_for_all
=
172 gallery_prefs_
->GalleriesForExtension(*all_permission_extension
.get());
173 EXPECT_EQ(expected_galleries_for_all
, galleries_for_all
);
175 std::set
<MediaGalleryPrefId
> galleries_for_regular
=
176 gallery_prefs_
->GalleriesForExtension(
177 *regular_permission_extension
.get());
178 EXPECT_EQ(expected_galleries_for_regular
, galleries_for_regular
);
180 std::set
<MediaGalleryPrefId
> galleries_for_no
=
181 gallery_prefs_
->GalleriesForExtension(*no_permissions_extension
.get());
182 EXPECT_EQ(0U, galleries_for_no
.size());
185 void VerifyGalleryInfo(const MediaGalleryPrefInfo
& actual
,
186 MediaGalleryPrefId expected_id
) const {
187 MediaGalleriesPrefInfoMap::const_iterator in_expectation
=
188 expected_galleries_
.find(expected_id
);
189 ASSERT_FALSE(in_expectation
== expected_galleries_
.end()) << expected_id
;
190 EXPECT_EQ(in_expectation
->second
.pref_id
, actual
.pref_id
);
191 EXPECT_EQ(in_expectation
->second
.display_name
, actual
.display_name
);
192 EXPECT_EQ(in_expectation
->second
.device_id
, actual
.device_id
);
193 EXPECT_EQ(in_expectation
->second
.path
.value(), actual
.path
.value());
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
);
200 MediaGalleriesPreferences
* gallery_prefs() {
201 return gallery_prefs_
.get();
204 uint64
default_galleries_count() {
205 return default_galleries_count_
;
208 void AddGalleryExpectation(MediaGalleryPrefId id
, base::string16 display_name
,
209 std::string device_id
,
210 base::FilePath relative_path
,
211 MediaGalleryPrefInfo::Type type
) {
212 expected_galleries_
[id
].pref_id
= id
;
213 expected_galleries_
[id
].display_name
= display_name
;
214 expected_galleries_
[id
].device_id
= device_id
;
215 expected_galleries_
[id
].path
= relative_path
.NormalizePathSeparators();
216 expected_galleries_
[id
].type
= type
;
218 if (type
== MediaGalleryPrefInfo::kAutoDetected
)
219 expected_galleries_for_all
.insert(id
);
221 expected_device_map
[device_id
].insert(id
);
224 void AddScanResultExpectation(MediaGalleryPrefId id
,
225 base::string16 display_name
,
226 std::string device_id
,
227 base::FilePath relative_path
,
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
;
238 MediaGalleryPrefId
AddGalleryWithNameV0(const std::string
& device_id
,
239 const base::string16
& display_name
,
240 const base::FilePath
& relative_path
,
242 MediaGalleryPrefInfo::Type type
=
243 user_added
? MediaGalleryPrefInfo::kUserAdded
244 : MediaGalleryPrefInfo::kAutoDetected
;
245 return gallery_prefs()->AddGalleryInternal(
246 device_id
, display_name
, relative_path
, type
,
247 base::string16(), base::string16(), base::string16(), 0, base::Time(),
251 MediaGalleryPrefId
AddGalleryWithNameV1(const std::string
& device_id
,
252 const base::string16
& display_name
,
253 const base::FilePath
& relative_path
,
255 MediaGalleryPrefInfo::Type type
=
256 user_added
? MediaGalleryPrefInfo::kUserAdded
257 : MediaGalleryPrefInfo::kAutoDetected
;
258 return gallery_prefs()->AddGalleryInternal(
259 device_id
, display_name
, relative_path
, type
,
260 base::string16(), base::string16(), base::string16(), 0, base::Time(),
264 MediaGalleryPrefId
AddGalleryWithNameV2(const std::string
& device_id
,
265 const base::string16
& display_name
,
266 const base::FilePath
& relative_path
,
267 MediaGalleryPrefInfo::Type type
) {
268 return gallery_prefs()->AddGalleryInternal(
269 device_id
, display_name
, relative_path
, type
,
270 base::string16(), base::string16(), base::string16(), 0, base::Time(),
274 bool UpdateDeviceIDForSingletonType(const std::string
& device_id
) {
275 return gallery_prefs()->UpdateDeviceIDForSingletonType(device_id
);
278 scoped_refptr
<extensions::Extension
> all_permission_extension
;
279 scoped_refptr
<extensions::Extension
> regular_permission_extension
;
280 scoped_refptr
<extensions::Extension
> no_permissions_extension
;
282 std::set
<MediaGalleryPrefId
> expected_galleries_for_all
;
283 std::set
<MediaGalleryPrefId
> expected_galleries_for_regular
;
285 DeviceIdPrefIdsMap expected_device_map
;
287 MediaGalleriesPrefInfoMap expected_galleries_
;
290 // Needed for extension service & friends to work.
291 content::TestBrowserThreadBundle thread_bundle_
;
293 EnsureMediaDirectoriesExists mock_gallery_locations_
;
295 #if defined OS_CHROMEOS
296 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_
;
297 chromeos::ScopedTestCrosSettings test_cros_settings_
;
298 chromeos::ScopedTestUserManager test_user_manager_
;
301 TestStorageMonitor monitor_
;
302 scoped_ptr
<TestingProfile
> profile_
;
303 scoped_ptr
<MediaGalleriesPreferences
> gallery_prefs_
;
305 uint64 default_galleries_count_
;
307 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferencesTest
);
310 base::FilePath
MakePath(std::string dir
) {
313 base::FilePath(FILE_PATH_LITERAL("C:\\")).Append(base::UTF8ToWide(dir
));
314 #elif defined(OS_POSIX)
315 return base::FilePath(FILE_PATH_LITERAL("/")).Append(dir
);
321 TEST_F(MediaGalleriesPreferencesTest
, GalleryManagement
) {
322 MediaGalleryPrefId auto_id
, user_added_id
, scan_id
, id
;
324 base::FilePath relative_path
;
327 // Add a new auto detected gallery.
328 path
= MakePath("new_auto");
330 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
331 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
332 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
333 relative_path
, MediaGalleryPrefInfo::kAutoDetected
);
334 EXPECT_EQ(default_galleries_count() + 1UL, id
);
336 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
337 MediaGalleryPrefInfo::kAutoDetected
);
340 // Add it as other types, nothing should happen.
341 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
342 relative_path
, MediaGalleryPrefInfo::kUserAdded
);
343 EXPECT_EQ(auto_id
, id
);
345 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
346 relative_path
, MediaGalleryPrefInfo::kAutoDetected
);
347 EXPECT_EQ(auto_id
, id
);
349 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
350 relative_path
, MediaGalleryPrefInfo::kScanResult
);
351 EXPECT_EQ(auto_id
, id
);
353 // Add a new user added gallery.
354 path
= MakePath("new_user");
355 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
356 info
.set_name(ASCIIToUTF16("NewUserGallery"));
357 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
358 relative_path
, MediaGalleryPrefInfo::kUserAdded
);
359 EXPECT_EQ(default_galleries_count() + 2UL, id
);
361 const std::string user_added_device_id
= info
.device_id();
362 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
363 MediaGalleryPrefInfo::kUserAdded
);
366 // Add it as other types, nothing should happen.
367 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
368 relative_path
, MediaGalleryPrefInfo::kUserAdded
);
369 EXPECT_EQ(user_added_id
, id
);
371 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
372 relative_path
, MediaGalleryPrefInfo::kAutoDetected
);
373 EXPECT_EQ(user_added_id
, id
);
375 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
376 relative_path
, MediaGalleryPrefInfo::kScanResult
);
377 EXPECT_EQ(user_added_id
, id
);
380 // Add a new scan result gallery.
381 path
= MakePath("new_scan");
382 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
383 info
.set_name(ASCIIToUTF16("NewScanGallery"));
384 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
385 relative_path
, MediaGalleryPrefInfo::kScanResult
);
386 EXPECT_EQ(default_galleries_count() + 3UL, id
);
388 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
389 MediaGalleryPrefInfo::kScanResult
);
392 // Add it as other types, nothing should happen.
393 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
394 relative_path
, MediaGalleryPrefInfo::kUserAdded
);
395 EXPECT_EQ(scan_id
, id
);
397 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
398 relative_path
, MediaGalleryPrefInfo::kAutoDetected
);
399 EXPECT_EQ(scan_id
, id
);
401 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
402 relative_path
, MediaGalleryPrefInfo::kScanResult
);
403 EXPECT_EQ(scan_id
, id
);
406 // Lookup some galleries.
407 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"), NULL
));
408 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"), NULL
));
409 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_scan"), NULL
));
410 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(MakePath("other"), NULL
));
412 // Check that we always get the gallery info.
413 MediaGalleryPrefInfo gallery_info
;
414 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"),
416 VerifyGalleryInfo(gallery_info
, auto_id
);
417 EXPECT_FALSE(gallery_info
.volume_metadata_valid
);
418 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_user"),
420 VerifyGalleryInfo(gallery_info
, user_added_id
);
421 EXPECT_FALSE(gallery_info
.volume_metadata_valid
);
422 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_scan"),
424 VerifyGalleryInfo(gallery_info
, scan_id
);
425 EXPECT_FALSE(gallery_info
.volume_metadata_valid
);
427 path
= MakePath("other");
428 EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(path
, &gallery_info
));
429 EXPECT_EQ(kInvalidMediaGalleryPrefId
, gallery_info
.pref_id
);
431 StorageInfo other_info
;
432 MediaStorageUtil::GetDeviceInfoFromPath(path
, &other_info
, &relative_path
);
433 EXPECT_EQ(other_info
.device_id(), gallery_info
.device_id
);
434 EXPECT_EQ(relative_path
.value(), gallery_info
.path
.value());
436 // Remove an auto added gallery (i.e. make it blacklisted).
437 gallery_prefs()->ForgetGalleryById(auto_id
);
438 expected_galleries_
[auto_id
].type
= MediaGalleryPrefInfo::kBlackListed
;
439 expected_galleries_for_all
.erase(auto_id
);
442 // Remove a scan result (i.e. make it blacklisted).
443 gallery_prefs()->ForgetGalleryById(scan_id
);
444 expected_galleries_
[scan_id
].type
= MediaGalleryPrefInfo::kRemovedScan
;
447 // Remove a user added gallery and it should go away.
448 gallery_prefs()->ForgetGalleryById(user_added_id
);
449 expected_galleries_
.erase(user_added_id
);
450 expected_device_map
[user_added_device_id
].erase(user_added_id
);
454 TEST_F(MediaGalleriesPreferencesTest
, AddGalleryWithVolumeMetadata
) {
455 MediaGalleryPrefId id
;
458 base::FilePath relative_path
;
459 base::Time now
= base::Time::Now();
462 // Add a new auto detected gallery.
463 path
= MakePath("new_auto");
464 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
465 id
= gallery_prefs()->AddGallery(info
.device_id(), relative_path
,
466 MediaGalleryPrefInfo::kAutoDetected
,
467 ASCIIToUTF16("volume label"),
468 ASCIIToUTF16("vendor name"),
469 ASCIIToUTF16("model name"),
470 1000000ULL, now
, 0, 0, 0);
471 EXPECT_EQ(default_galleries_count() + 1UL, id
);
472 AddGalleryExpectation(id
, base::string16(), info
.device_id(), relative_path
,
473 MediaGalleryPrefInfo::kAutoDetected
);
476 MediaGalleryPrefInfo gallery_info
;
477 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(MakePath("new_auto"),
479 EXPECT_TRUE(gallery_info
.volume_metadata_valid
);
480 EXPECT_EQ(ASCIIToUTF16("volume label"), gallery_info
.volume_label
);
481 EXPECT_EQ(ASCIIToUTF16("vendor name"), gallery_info
.vendor_name
);
482 EXPECT_EQ(ASCIIToUTF16("model name"), gallery_info
.model_name
);
483 EXPECT_EQ(1000000ULL, gallery_info
.total_size_in_bytes
);
484 // Note: we put the microseconds time into a double, so there'll
485 // be some possible rounding errors. If it's less than 100, we don't
487 EXPECT_LE(abs(now
.ToInternalValue() -
488 gallery_info
.last_attach_time
.ToInternalValue()), 100);
491 TEST_F(MediaGalleriesPreferencesTest
, ReplaceGalleryWithVolumeMetadata
) {
492 MediaGalleryPrefId id
, metadata_id
;
495 base::FilePath relative_path
;
496 base::Time now
= base::Time::Now();
499 // Add an auto detected gallery in the prefs version 0 format.
500 path
= MakePath("new_auto");
501 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
502 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
503 id
= AddGalleryWithNameV0(info
.device_id(), info
.name(),
504 relative_path
, false /*auto*/);
505 EXPECT_EQ(default_galleries_count() + 1UL, id
);
506 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
507 MediaGalleryPrefInfo::kAutoDetected
);
510 metadata_id
= gallery_prefs()->AddGallery(info
.device_id(),
512 MediaGalleryPrefInfo::kAutoDetected
,
513 ASCIIToUTF16("volume label"),
514 ASCIIToUTF16("vendor name"),
515 ASCIIToUTF16("model name"),
516 1000000ULL, now
, 0, 0, 0);
517 EXPECT_EQ(id
, metadata_id
);
518 AddGalleryExpectation(id
, base::string16(), info
.device_id(), relative_path
,
519 MediaGalleryPrefInfo::kAutoDetected
);
521 // Make sure the display_name is set to empty now, as the metadata
522 // upgrade should set the manual override name empty.
526 // Whenever an "AutoDetected" gallery is removed, it is moved to a black listed
527 // state. When the gallery is added again, the black listed state is updated
528 // back to the "AutoDetected" type.
529 TEST_F(MediaGalleriesPreferencesTest
, AutoAddedBlackListing
) {
530 MediaGalleryPrefId auto_id
, id
;
533 base::FilePath relative_path
;
536 // Add a new auto detect gallery to test with.
537 path
= MakePath("new_auto");
538 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
539 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
540 id
= AddGalleryWithNameV1(info
.device_id(), info
.name(),
541 relative_path
, false /*auto*/);
542 EXPECT_EQ(default_galleries_count() + 1UL, id
);
544 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
545 MediaGalleryPrefInfo::kAutoDetected
);
548 // Remove an auto added gallery (i.e. make it blacklisted).
549 gallery_prefs()->ForgetGalleryById(auto_id
);
550 expected_galleries_
[auto_id
].type
= MediaGalleryPrefInfo::kBlackListed
;
551 expected_galleries_for_all
.erase(auto_id
);
554 // Try adding the gallery again automatically and it should be a no-op.
555 id
= AddGalleryWithNameV1(info
.device_id(), info
.name(),
556 relative_path
, false /*auto*/);
557 EXPECT_EQ(auto_id
, id
);
560 // Add the gallery again as a user action.
561 id
= gallery_prefs()->AddGalleryByPath(path
,
562 MediaGalleryPrefInfo::kUserAdded
);
563 EXPECT_EQ(auto_id
, id
);
564 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
565 MediaGalleryPrefInfo::kAutoDetected
);
569 // Whenever a "ScanResult" gallery is removed, it is moved to a black listed
570 // state. When the gallery is added again, the black listed state is updated
571 // back to the "ScanResult" type.
572 TEST_F(MediaGalleriesPreferencesTest
, ScanResultBlackListing
) {
573 MediaGalleryPrefId scan_id
, id
;
576 base::FilePath relative_path
;
579 // Add a new scan result gallery to test with.
580 path
= MakePath("new_scan");
581 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
582 info
.set_name(ASCIIToUTF16("NewScanGallery"));
583 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
584 relative_path
, MediaGalleryPrefInfo::kScanResult
);
585 EXPECT_EQ(default_galleries_count() + 1UL, id
);
587 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
588 MediaGalleryPrefInfo::kScanResult
);
591 // Remove a scan result gallery (i.e. make it blacklisted).
592 gallery_prefs()->ForgetGalleryById(scan_id
);
593 expected_galleries_
[scan_id
].type
= MediaGalleryPrefInfo::kRemovedScan
;
594 expected_galleries_for_all
.erase(scan_id
);
597 // Try adding the gallery again as a scan result it should be a no-op.
598 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
599 relative_path
, MediaGalleryPrefInfo::kScanResult
);
600 EXPECT_EQ(scan_id
, id
);
603 // Add the gallery again as a user action.
604 id
= gallery_prefs()->AddGalleryByPath(path
,
605 MediaGalleryPrefInfo::kUserAdded
);
606 EXPECT_EQ(scan_id
, id
);
607 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
608 MediaGalleryPrefInfo::kUserAdded
);
612 TEST_F(MediaGalleriesPreferencesTest
, UpdateGalleryNameV2
) {
613 // Add a new auto detect gallery to test with.
614 base::FilePath path
= MakePath("new_auto");
616 base::FilePath relative_path
;
617 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
618 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
619 MediaGalleryPrefId id
=
620 AddGalleryWithNameV2(info
.device_id(), info
.name(),
621 relative_path
, MediaGalleryPrefInfo::kAutoDetected
);
622 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
623 MediaGalleryPrefInfo::kAutoDetected
);
626 // Won't override the name -- don't change any expectation.
627 info
.set_name(base::string16());
628 AddGalleryWithNameV2(info
.device_id(), info
.name(), relative_path
,
629 MediaGalleryPrefInfo::kAutoDetected
);
632 info
.set_name(ASCIIToUTF16("NewName"));
633 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
634 relative_path
, MediaGalleryPrefInfo::kAutoDetected
);
635 // Note: will really just update the existing expectation.
636 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
637 MediaGalleryPrefInfo::kAutoDetected
);
641 TEST_F(MediaGalleriesPreferencesTest
, GalleryPermissions
) {
642 MediaGalleryPrefId auto_id
, user_added_id
, to_blacklist_id
, scan_id
,
643 to_scan_remove_id
, id
;
646 base::FilePath relative_path
;
649 // Add some galleries to test with.
650 path
= MakePath("new_user");
651 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
652 info
.set_name(ASCIIToUTF16("NewUserGallery"));
653 id
= AddGalleryWithNameV1(info
.device_id(), info
.name(),
654 relative_path
, true /*user*/);
655 EXPECT_EQ(default_galleries_count() + 1UL, id
);
657 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
658 MediaGalleryPrefInfo::kUserAdded
);
661 path
= MakePath("new_auto");
662 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
663 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
664 id
= AddGalleryWithNameV1(info
.device_id(), info
.name(),
665 relative_path
, false /*auto*/);
666 EXPECT_EQ(default_galleries_count() + 2UL, id
);
668 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
669 MediaGalleryPrefInfo::kAutoDetected
);
672 path
= MakePath("to_blacklist");
673 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
674 info
.set_name(ASCIIToUTF16("ToBlacklistGallery"));
675 id
= AddGalleryWithNameV1(info
.device_id(), info
.name(),
676 relative_path
, false /*auto*/);
677 EXPECT_EQ(default_galleries_count() + 3UL, id
);
678 to_blacklist_id
= id
;
679 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
680 MediaGalleryPrefInfo::kAutoDetected
);
683 path
= MakePath("new_scan");
684 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
685 info
.set_name(ASCIIToUTF16("NewScanGallery"));
686 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
687 relative_path
, MediaGalleryPrefInfo::kScanResult
);
688 EXPECT_EQ(default_galleries_count() + 4UL, id
);
690 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
691 MediaGalleryPrefInfo::kScanResult
);
694 path
= MakePath("to_scan_remove");
695 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
696 info
.set_name(ASCIIToUTF16("ToScanRemoveGallery"));
697 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(),
698 relative_path
, MediaGalleryPrefInfo::kScanResult
);
699 EXPECT_EQ(default_galleries_count() + 5UL, id
);
700 to_scan_remove_id
= id
;
701 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
702 MediaGalleryPrefInfo::kScanResult
);
705 // Remove permission for all galleries from the all-permission extension.
706 gallery_prefs()->SetGalleryPermissionForExtension(
707 *all_permission_extension
.get(), auto_id
, false);
708 expected_galleries_for_all
.erase(auto_id
);
711 gallery_prefs()->SetGalleryPermissionForExtension(
712 *all_permission_extension
.get(), user_added_id
, false);
713 expected_galleries_for_all
.erase(user_added_id
);
716 gallery_prefs()->SetGalleryPermissionForExtension(
717 *all_permission_extension
.get(), to_blacklist_id
, false);
718 expected_galleries_for_all
.erase(to_blacklist_id
);
721 gallery_prefs()->SetGalleryPermissionForExtension(
722 *all_permission_extension
.get(), scan_id
, false);
723 expected_galleries_for_all
.erase(scan_id
);
726 gallery_prefs()->SetGalleryPermissionForExtension(
727 *all_permission_extension
.get(), to_scan_remove_id
, false);
728 expected_galleries_for_all
.erase(to_scan_remove_id
);
731 // Add permission back for all galleries to the all-permission extension.
732 gallery_prefs()->SetGalleryPermissionForExtension(
733 *all_permission_extension
.get(), auto_id
, true);
734 expected_galleries_for_all
.insert(auto_id
);
737 gallery_prefs()->SetGalleryPermissionForExtension(
738 *all_permission_extension
.get(), user_added_id
, true);
739 expected_galleries_for_all
.insert(user_added_id
);
742 gallery_prefs()->SetGalleryPermissionForExtension(
743 *all_permission_extension
.get(), to_blacklist_id
, true);
744 expected_galleries_for_all
.insert(to_blacklist_id
);
747 gallery_prefs()->SetGalleryPermissionForExtension(
748 *all_permission_extension
.get(), scan_id
, true);
749 expected_galleries_for_all
.insert(scan_id
);
752 gallery_prefs()->SetGalleryPermissionForExtension(
753 *all_permission_extension
.get(), to_scan_remove_id
, true);
754 expected_galleries_for_all
.insert(to_scan_remove_id
);
757 // Add permission for all galleries to the regular permission extension.
758 gallery_prefs()->SetGalleryPermissionForExtension(
759 *regular_permission_extension
.get(), auto_id
, true);
760 expected_galleries_for_regular
.insert(auto_id
);
763 gallery_prefs()->SetGalleryPermissionForExtension(
764 *regular_permission_extension
.get(), user_added_id
, true);
765 expected_galleries_for_regular
.insert(user_added_id
);
768 gallery_prefs()->SetGalleryPermissionForExtension(
769 *regular_permission_extension
.get(), to_blacklist_id
, true);
770 expected_galleries_for_regular
.insert(to_blacklist_id
);
773 gallery_prefs()->SetGalleryPermissionForExtension(
774 *regular_permission_extension
.get(), scan_id
, true);
775 expected_galleries_for_regular
.insert(scan_id
);
778 gallery_prefs()->SetGalleryPermissionForExtension(
779 *regular_permission_extension
.get(), to_scan_remove_id
, true);
780 expected_galleries_for_regular
.insert(to_scan_remove_id
);
783 // Blacklist the to be black listed gallery
784 gallery_prefs()->ForgetGalleryById(to_blacklist_id
);
785 expected_galleries_
[to_blacklist_id
].type
=
786 MediaGalleryPrefInfo::kBlackListed
;
787 expected_galleries_for_all
.erase(to_blacklist_id
);
788 expected_galleries_for_regular
.erase(to_blacklist_id
);
791 gallery_prefs()->ForgetGalleryById(to_scan_remove_id
);
792 expected_galleries_
[to_scan_remove_id
].type
=
793 MediaGalleryPrefInfo::kRemovedScan
;
794 expected_galleries_for_all
.erase(to_scan_remove_id
);
795 expected_galleries_for_regular
.erase(to_scan_remove_id
);
798 // Remove permission for all galleries to the regular permission extension.
799 gallery_prefs()->SetGalleryPermissionForExtension(
800 *regular_permission_extension
.get(), auto_id
, false);
801 expected_galleries_for_regular
.erase(auto_id
);
804 gallery_prefs()->SetGalleryPermissionForExtension(
805 *regular_permission_extension
.get(), user_added_id
, false);
806 expected_galleries_for_regular
.erase(user_added_id
);
809 gallery_prefs()->SetGalleryPermissionForExtension(
810 *regular_permission_extension
.get(), scan_id
, false);
811 expected_galleries_for_regular
.erase(scan_id
);
814 // Add permission for an invalid gallery id.
815 gallery_prefs()->SetGalleryPermissionForExtension(
816 *regular_permission_extension
.get(), 9999L, true);
820 // What an existing gallery is added again, update the gallery information if
822 TEST_F(MediaGalleriesPreferencesTest
, UpdateGalleryDetails
) {
823 MediaGalleryPrefId auto_id
, id
;
826 base::FilePath relative_path
;
829 // Add a new auto detect gallery to test with.
830 path
= MakePath("new_auto");
831 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
832 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
833 id
= AddGalleryWithNameV1(info
.device_id(), info
.name(),
834 relative_path
, false /*auto*/);
835 EXPECT_EQ(default_galleries_count() + 1UL, id
);
837 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
838 MediaGalleryPrefInfo::kAutoDetected
);
841 // Update the device name and add the gallery again.
842 info
.set_name(ASCIIToUTF16("AutoGallery2"));
843 id
= AddGalleryWithNameV1(info
.device_id(), info
.name(),
844 relative_path
, false /*auto*/);
845 EXPECT_EQ(auto_id
, id
);
846 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
847 MediaGalleryPrefInfo::kAutoDetected
);
851 TEST_F(MediaGalleriesPreferencesTest
, MultipleGalleriesPerDevices
) {
854 base::FilePath relative_path
;
857 // Add a regular gallery
858 path
= MakePath("new_user");
859 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
860 info
.set_name(ASCIIToUTF16("NewUserGallery"));
861 MediaGalleryPrefId user_added_id
=
862 AddGalleryWithNameV1(info
.device_id(), info
.name(),
863 relative_path
, true /*user*/);
864 EXPECT_EQ(default_galleries_count() + 1UL, user_added_id
);
865 AddGalleryExpectation(user_added_id
, info
.name(), info
.device_id(),
866 relative_path
, MediaGalleryPrefInfo::kUserAdded
);
869 // Find it by device id and fail to find something related.
870 MediaGalleryPrefIdSet pref_id_set
;
871 pref_id_set
= gallery_prefs()->LookUpGalleriesByDeviceId(info
.device_id());
872 EXPECT_EQ(1U, pref_id_set
.size());
873 EXPECT_TRUE(pref_id_set
.find(user_added_id
) != pref_id_set
.end());
875 MediaStorageUtil::GetDeviceInfoFromPath(MakePath("new_user/foo"), &info
,
877 pref_id_set
= gallery_prefs()->LookUpGalleriesByDeviceId(info
.device_id());
878 EXPECT_EQ(0U, pref_id_set
.size());
880 // Add some galleries on the same device.
881 relative_path
= base::FilePath(FILE_PATH_LITERAL("path1/on/device1"));
882 info
.set_name(ASCIIToUTF16("Device1Path1"));
883 std::string device_id
= "path:device1";
884 MediaGalleryPrefId dev1_path1_id
= AddGalleryWithNameV1(
885 device_id
, info
.name(), relative_path
, true /*user*/);
886 EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id
);
887 AddGalleryExpectation(dev1_path1_id
, info
.name(), device_id
, relative_path
,
888 MediaGalleryPrefInfo::kUserAdded
);
891 relative_path
= base::FilePath(FILE_PATH_LITERAL("path2/on/device1"));
892 info
.set_name(ASCIIToUTF16("Device1Path2"));
893 MediaGalleryPrefId dev1_path2_id
= AddGalleryWithNameV1(
894 device_id
, info
.name(), relative_path
, true /*user*/);
895 EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id
);
896 AddGalleryExpectation(dev1_path2_id
, info
.name(), device_id
, relative_path
,
897 MediaGalleryPrefInfo::kUserAdded
);
900 relative_path
= base::FilePath(FILE_PATH_LITERAL("path1/on/device2"));
901 info
.set_name(ASCIIToUTF16("Device2Path1"));
902 device_id
= "path:device2";
903 MediaGalleryPrefId dev2_path1_id
= AddGalleryWithNameV1(
904 device_id
, info
.name(), relative_path
, true /*user*/);
905 EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id
);
906 AddGalleryExpectation(dev2_path1_id
, info
.name(), device_id
, relative_path
,
907 MediaGalleryPrefInfo::kUserAdded
);
910 relative_path
= base::FilePath(FILE_PATH_LITERAL("path2/on/device2"));
911 info
.set_name(ASCIIToUTF16("Device2Path2"));
912 MediaGalleryPrefId dev2_path2_id
= AddGalleryWithNameV1(
913 device_id
, info
.name(), relative_path
, true /*user*/);
914 EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id
);
915 AddGalleryExpectation(dev2_path2_id
, info
.name(), device_id
, relative_path
,
916 MediaGalleryPrefInfo::kUserAdded
);
919 // Check that adding one of them again works as expected.
920 MediaGalleryPrefId id
= AddGalleryWithNameV1(
921 device_id
, info
.name(), relative_path
, true /*user*/);
922 EXPECT_EQ(dev2_path2_id
, id
);
926 TEST_F(MediaGalleriesPreferencesTest
, GalleryChangeObserver
) {
927 // Start with one observer.
928 MockGalleryChangeObserver
observer1(gallery_prefs());
929 gallery_prefs()->AddGalleryChangeObserver(&observer1
);
931 // Add a new auto detected gallery.
932 base::FilePath path
= MakePath("new_auto");
934 base::FilePath relative_path
;
935 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
936 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
937 MediaGalleryPrefId auto_id
= AddGalleryWithNameV1(
938 info
.device_id(), info
.name(), relative_path
, false /*auto*/);
939 EXPECT_EQ(default_galleries_count() + 1UL, auto_id
);
940 AddGalleryExpectation(auto_id
, info
.name(), info
.device_id(),
941 relative_path
, MediaGalleryPrefInfo::kAutoDetected
);
942 EXPECT_EQ(1, observer1
.notifications());
944 // Add a second observer.
945 MockGalleryChangeObserver
observer2(gallery_prefs());
946 gallery_prefs()->AddGalleryChangeObserver(&observer2
);
948 // Add a new user added gallery.
949 path
= MakePath("new_user");
950 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
951 info
.set_name(ASCIIToUTF16("NewUserGallery"));
952 MediaGalleryPrefId user_added_id
=
953 AddGalleryWithNameV1(info
.device_id(), info
.name(),
954 relative_path
, true /*user*/);
955 AddGalleryExpectation(user_added_id
, info
.name(), info
.device_id(),
956 relative_path
, MediaGalleryPrefInfo::kUserAdded
);
957 EXPECT_EQ(default_galleries_count() + 2UL, user_added_id
);
958 EXPECT_EQ(2, observer1
.notifications());
959 EXPECT_EQ(1, observer2
.notifications());
961 // Remove the first observer.
962 gallery_prefs()->RemoveGalleryChangeObserver(&observer1
);
964 // Remove an auto added gallery (i.e. make it blacklisted).
965 gallery_prefs()->ForgetGalleryById(auto_id
);
966 expected_galleries_
[auto_id
].type
= MediaGalleryPrefInfo::kBlackListed
;
967 expected_galleries_for_all
.erase(auto_id
);
969 EXPECT_EQ(2, observer1
.notifications());
970 EXPECT_EQ(2, observer2
.notifications());
972 // Remove a user added gallery and it should go away.
973 gallery_prefs()->ForgetGalleryById(user_added_id
);
974 expected_galleries_
.erase(user_added_id
);
975 expected_device_map
[info
.device_id()].erase(user_added_id
);
977 EXPECT_EQ(2, observer1
.notifications());
978 EXPECT_EQ(3, observer2
.notifications());
981 TEST_F(MediaGalleriesPreferencesTest
, UpdateSingletonDeviceIdType
) {
982 MediaGalleryPrefId id
;
985 base::FilePath relative_path
;
988 // Add a new auto detect gallery to test with.
989 path
= MakePath("new_auto");
990 MediaStorageUtil::GetDeviceInfoFromPath(path
, &info
, &relative_path
);
991 info
.set_name(ASCIIToUTF16("NewAutoGallery"));
992 info
.set_device_id(StorageInfo::MakeDeviceId(StorageInfo::ITUNES
,
993 path
.AsUTF8Unsafe()));
994 id
= AddGalleryWithNameV2(info
.device_id(), info
.name(), relative_path
,
995 MediaGalleryPrefInfo::kAutoDetected
);
996 EXPECT_EQ(default_galleries_count() + 1UL, id
);
997 AddGalleryExpectation(id
, info
.name(), info
.device_id(), relative_path
,
998 MediaGalleryPrefInfo::kAutoDetected
);
1001 // Update the device id.
1002 MockGalleryChangeObserver
observer(gallery_prefs());
1003 gallery_prefs()->AddGalleryChangeObserver(&observer
);
1005 path
= MakePath("updated_path");
1006 std::string updated_device_id
=
1007 StorageInfo::MakeDeviceId(StorageInfo::ITUNES
, path
.AsUTF8Unsafe());
1008 EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id
));
1009 AddGalleryExpectation(id
, info
.name(), updated_device_id
, relative_path
,
1010 MediaGalleryPrefInfo::kAutoDetected
);
1011 expected_device_map
[info
.device_id()].erase(id
);
1012 expected_device_map
[updated_device_id
].insert(id
);
1014 EXPECT_EQ(1, observer
.notifications());
1016 // No gallery for type.
1017 std::string new_device_id
=
1018 StorageInfo::MakeDeviceId(StorageInfo::PICASA
, path
.AsUTF8Unsafe());
1019 EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id
));
1022 TEST_F(MediaGalleriesPreferencesTest
, ScanResults
) {
1023 MediaGalleryPrefId id
;
1024 base::FilePath path
;
1026 base::FilePath relative_path
;
1027 base::Time now
= base::Time::Now();
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);
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);
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;
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
);
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
);
1083 TEST(MediaGalleriesPrefInfoTest
, NameGeneration
) {
1084 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall());
1086 MediaGalleryPrefInfo info
;
1088 info
.display_name
= ASCIIToUTF16("override");
1089 info
.device_id
= StorageInfo::MakeDeviceId(
1090 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM
, "unique");
1092 EXPECT_EQ(ASCIIToUTF16("override"), info
.GetGalleryDisplayName());
1094 info
.display_name
= ASCIIToUTF16("o2");
1095 EXPECT_EQ(ASCIIToUTF16("o2"), info
.GetGalleryDisplayName());
1097 EXPECT_EQ(l10n_util::GetStringUTF16(
1098 IDS_MEDIA_GALLERIES_DIALOG_DEVICE_NOT_ATTACHED
),
1099 info
.GetGalleryAdditionalDetails());
1101 info
.last_attach_time
= base::Time::Now();
1102 EXPECT_NE(l10n_util::GetStringUTF16(
1103 IDS_MEDIA_GALLERIES_DIALOG_DEVICE_NOT_ATTACHED
),
1104 info
.GetGalleryAdditionalDetails());
1105 EXPECT_NE(l10n_util::GetStringUTF16(
1106 IDS_MEDIA_GALLERIES_DIALOG_DEVICE_ATTACHED
),
1107 info
.GetGalleryAdditionalDetails());
1109 info
.volume_label
= ASCIIToUTF16("vol");
1110 info
.vendor_name
= ASCIIToUTF16("vendor");
1111 info
.model_name
= ASCIIToUTF16("model");
1112 EXPECT_EQ(ASCIIToUTF16("o2"), info
.GetGalleryDisplayName());
1114 info
.display_name
= base::string16();
1115 EXPECT_EQ(ASCIIToUTF16("vol"), info
.GetGalleryDisplayName());
1116 info
.volume_label
= base::string16();
1117 EXPECT_EQ(ASCIIToUTF16("vendor, model"), info
.GetGalleryDisplayName());
1119 info
.device_id
= StorageInfo::MakeDeviceId(
1120 StorageInfo::FIXED_MASS_STORAGE
, "unique");
1121 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(),
1122 base::UTF16ToUTF8(info
.GetGalleryTooltip()));
1124 TestStorageMonitor::RemoveSingleton();