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

Unified Diff: chrome/browser/media_galleries/media_galleries_preferences_unittest.cc

Issue 19489006: Media Galleries: Move gallery name generation back to StorageMonitor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media_galleries/media_galleries_preferences_unittest.cc
===================================================================
--- chrome/browser/media_galleries/media_galleries_preferences_unittest.cc (revision 218837)
+++ chrome/browser/media_galleries/media_galleries_preferences_unittest.cc (working copy)
@@ -173,7 +173,8 @@
return default_galleries_count_;
}
- void AddGalleryExpectation(MediaGalleryPrefId id, string16 display_name,
+ void AddGalleryExpectation(MediaGalleryPrefId id,
+ const string16& display_name,
std::string device_id,
base::FilePath relative_path,
MediaGalleryPrefInfo::Type type) {
@@ -270,30 +271,30 @@
path = MakePath("new_auto");
StorageInfo info;
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(default_galleries_count() + 1UL, id);
auto_id = id;
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
// Add it again (as user), nothing should happen.
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, true /*auto*/);
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ true /*auto*/);
EXPECT_EQ(auto_id, id);
Verify();
// Add a new user added gallery.
path = MakePath("new_user");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewUserGallery"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, true /*user*/);
+ gallery_name = base::ASCIIToUTF16("NewUserGallery");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ true /*user*/);
EXPECT_EQ(default_galleries_count() + 2UL, id);
user_added_id = id;
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kUserAdded);
Verify();
@@ -383,11 +384,11 @@
// Add an auto detected gallery in the prefs version 0 format.
path = MakePath("new_auto");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
- id = AddGalleryWithNameV0(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
+ id = AddGalleryWithNameV0(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(default_galleries_count() + 1UL, id);
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
@@ -423,12 +424,12 @@
// Add a new auto detect gallery to test with.
path = MakePath("new_auto");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(default_galleries_count() + 1UL, id);
auto_id = id;
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
@@ -441,7 +442,7 @@
// Add the gallery again as a user action.
id = gallery_prefs()->AddGalleryByPath(path);
EXPECT_EQ(auto_id, id);
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
@@ -452,8 +453,8 @@
Verify();
// Try adding the gallery again automatically and it should be a no-op.
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(auto_id, id);
Verify();
}
@@ -464,24 +465,23 @@
StorageInfo info;
base::FilePath relative_path;
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
- MediaGalleryPrefId id =
- AddGalleryWithNameV2(info.device_id(), info.name(),
- relative_path, false /*auto*/);
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
+ MediaGalleryPrefId id = AddGalleryWithNameV2(info.device_id(), gallery_name,
+ relative_path, false /*auto*/);
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
// Won't override the name -- don't change any expectation.
- info.set_name(string16());
- AddGalleryWithNameV2(info.device_id(), info.name(), relative_path, false);
+ gallery_name = base::string16();
+ AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, false);
Verify();
- info.set_name(ASCIIToUTF16("NewName"));
- id = AddGalleryWithNameV2(info.device_id(), info.name(),
- relative_path, false);
+ gallery_name = base::ASCIIToUTF16("NewName");
+ id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
+ false);
// Note: will really just update the existing expectation.
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
}
@@ -496,34 +496,34 @@
// Add some galleries to test with.
path = MakePath("new_user");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewUserGallery"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, true /*user*/);
+ base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ true /*user*/);
EXPECT_EQ(default_galleries_count() + 1UL, id);
user_added_id = id;
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kUserAdded);
Verify();
path = MakePath("new_auto");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ gallery_name = base::ASCIIToUTF16("NewAutoGallery");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(default_galleries_count() + 2UL, id);
auto_id = id;
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
path = MakePath("to_blacklist");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("ToBlacklistGallery"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ gallery_name = base::ASCIIToUTF16("ToBlacklistGallery");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(default_galleries_count() + 3UL, id);
to_blacklist_id = id;
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
@@ -614,21 +614,21 @@
// Add a new auto detect gallery to test with.
path = MakePath("new_auto");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(default_galleries_count() + 1UL, id);
auto_id = id;
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
// Update the device name and add the gallery again.
- info.set_name(ASCIIToUTF16("AutoGallery2"));
- id = AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, false /*auto*/);
+ gallery_name = base::ASCIIToUTF16("AutoGallery2");
+ id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path,
+ false /*auto*/);
EXPECT_EQ(auto_id, id);
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
}
@@ -642,12 +642,11 @@
// Add a regular gallery
path = MakePath("new_user");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewUserGallery"));
- MediaGalleryPrefId user_added_id =
- AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, true /*user*/);
+ base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery");
+ MediaGalleryPrefId user_added_id = AddGalleryWithNameV1(
+ info.device_id(), gallery_name, relative_path, true /*user*/);
EXPECT_EQ(default_galleries_count() + 1UL, user_added_id);
- AddGalleryExpectation(user_added_id, info.name(), info.device_id(),
+ AddGalleryExpectation(user_added_id, gallery_name, info.device_id(),
relative_path, MediaGalleryPrefInfo::kUserAdded);
Verify();
@@ -664,46 +663,46 @@
// Add some galleries on the same device.
relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1"));
- info.set_name(ASCIIToUTF16("Device1Path1"));
+ gallery_name = base::ASCIIToUTF16("Device1Path1");
std::string device_id = "path:device1";
MediaGalleryPrefId dev1_path1_id = AddGalleryWithNameV1(
- device_id, info.name(), relative_path, true /*user*/);
+ device_id, gallery_name, relative_path, true /*user*/);
EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id);
- AddGalleryExpectation(dev1_path1_id, info.name(), device_id, relative_path,
+ AddGalleryExpectation(dev1_path1_id, gallery_name, device_id, relative_path,
MediaGalleryPrefInfo::kUserAdded);
Verify();
relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1"));
- info.set_name(ASCIIToUTF16("Device1Path2"));
+ gallery_name = base::ASCIIToUTF16("Device1Path2");
MediaGalleryPrefId dev1_path2_id = AddGalleryWithNameV1(
- device_id, info.name(), relative_path, true /*user*/);
+ device_id, gallery_name, relative_path, true /*user*/);
EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id);
- AddGalleryExpectation(dev1_path2_id, info.name(), device_id, relative_path,
+ AddGalleryExpectation(dev1_path2_id, gallery_name, device_id, relative_path,
MediaGalleryPrefInfo::kUserAdded);
Verify();
relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2"));
- info.set_name(ASCIIToUTF16("Device2Path1"));
+ gallery_name = base::ASCIIToUTF16("Device2Path1");
device_id = "path:device2";
MediaGalleryPrefId dev2_path1_id = AddGalleryWithNameV1(
- device_id, info.name(), relative_path, true /*user*/);
+ device_id, gallery_name, relative_path, true /*user*/);
EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id);
- AddGalleryExpectation(dev2_path1_id, info.name(), device_id, relative_path,
+ AddGalleryExpectation(dev2_path1_id, gallery_name, device_id, relative_path,
MediaGalleryPrefInfo::kUserAdded);
Verify();
relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2"));
- info.set_name(ASCIIToUTF16("Device2Path2"));
+ gallery_name = base::ASCIIToUTF16("Device2Path2");
MediaGalleryPrefId dev2_path2_id = AddGalleryWithNameV1(
- device_id, info.name(), relative_path, true /*user*/);
+ device_id, gallery_name, relative_path, true /*user*/);
EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id);
- AddGalleryExpectation(dev2_path2_id, info.name(), device_id, relative_path,
+ AddGalleryExpectation(dev2_path2_id, gallery_name, device_id, relative_path,
MediaGalleryPrefInfo::kUserAdded);
Verify();
// Check that adding one of them again works as expected.
MediaGalleryPrefId id = AddGalleryWithNameV1(
- device_id, info.name(), relative_path, true /*user*/);
+ device_id, gallery_name, relative_path, true /*user*/);
EXPECT_EQ(dev2_path2_id, id);
Verify();
}
@@ -718,11 +717,11 @@
StorageInfo info;
base::FilePath relative_path;
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
+ base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
MediaGalleryPrefId auto_id = AddGalleryWithNameV1(
- info.device_id(), info.name(), relative_path, false /*auto*/);
+ info.device_id(), gallery_name, relative_path, false /*auto*/);
EXPECT_EQ(default_galleries_count() + 1UL, auto_id);
- AddGalleryExpectation(auto_id, info.name(), info.device_id(),
+ AddGalleryExpectation(auto_id, gallery_name, info.device_id(),
relative_path, MediaGalleryPrefInfo::kAutoDetected);
EXPECT_EQ(1, observer1.notifications());
@@ -733,11 +732,10 @@
// Add a new user added gallery.
path = MakePath("new_user");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewUserGallery"));
- MediaGalleryPrefId user_added_id =
- AddGalleryWithNameV1(info.device_id(), info.name(),
- relative_path, true /*user*/);
- AddGalleryExpectation(user_added_id, info.name(), info.device_id(),
+ gallery_name = base::ASCIIToUTF16("NewUserGallery");
+ MediaGalleryPrefId user_added_id = AddGalleryWithNameV1(
+ info.device_id(), gallery_name, relative_path, true /*user*/);
+ AddGalleryExpectation(user_added_id, gallery_name, info.device_id(),
relative_path, MediaGalleryPrefInfo::kUserAdded);
EXPECT_EQ(default_galleries_count() + 2UL, user_added_id);
EXPECT_EQ(2, observer1.notifications());
@@ -773,13 +771,13 @@
// Add a new auto detect gallery to test with.
path = MakePath("new_auto");
MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path);
- info.set_name(ASCIIToUTF16("NewAutoGallery"));
+ base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery");
info.set_device_id(StorageInfo::MakeDeviceId(StorageInfo::ITUNES,
path.AsUTF8Unsafe()));
- id = AddGalleryWithNameV2(info.device_id(), info.name(), relative_path,
+ id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path,
false /*auto*/);
EXPECT_EQ(default_galleries_count() + 1UL, id);
- AddGalleryExpectation(id, info.name(), info.device_id(), relative_path,
+ AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path,
MediaGalleryPrefInfo::kAutoDetected);
Verify();
@@ -791,7 +789,7 @@
std::string updated_device_id =
StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe());
EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id));
- AddGalleryExpectation(id, info.name(), updated_device_id, relative_path,
+ AddGalleryExpectation(id, gallery_name, updated_device_id, relative_path,
MediaGalleryPrefInfo::kAutoDetected);
expected_device_map[info.device_id()].erase(id);
expected_device_map[updated_device_id].insert(id);
@@ -835,9 +833,9 @@
info.model_name = ASCIIToUTF16("model");
EXPECT_EQ(ASCIIToUTF16("o2"), info.GetGalleryDisplayName());
- info.display_name = string16();
+ info.display_name = base::string16();
EXPECT_EQ(ASCIIToUTF16("vol"), info.GetGalleryDisplayName());
- info.volume_label = string16();
+ info.volume_label = base::string16();
EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName());
info.device_id = StorageInfo::MakeDeviceId(

Powered by Google App Engine
This is Rietveld 408576698