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

Unified Diff: chrome/browser/storage_monitor/storage_info_unittest.cc

Issue 120303003: [StorageMonitor] Move gallery name generation to StorageInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 7 years 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/storage_monitor/storage_info_unittest.cc
diff --git a/chrome/browser/storage_monitor/storage_info_unittest.cc b/chrome/browser/storage_monitor/storage_info_unittest.cc
index 36229c5699d9944b9296d44cd22d9f3eda763542..9e9fd1844628dfe200c2e075252a26f6b37b4b98 100644
--- a/chrome/browser/storage_monitor/storage_info_unittest.cc
+++ b/chrome/browser/storage_monitor/storage_info_unittest.cc
@@ -4,6 +4,8 @@
#include <string>
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/storage_monitor/media_storage_util.h"
#include "chrome/browser/storage_monitor/storage_info.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -36,3 +38,90 @@ TEST(StorageInfoTest, TestImageCaptureDeviceId) {
EXPECT_EQ(StorageInfo::MAC_IMAGE_CAPTURE, type);
EXPECT_EQ("xyz", id);
}
+
+TEST(StorageInfoTest, NameGenerationRemovableDevice) {
+ StorageInfo storageInfo(
+ StorageInfo::MakeDeviceId(StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM,
+ "unique"),
+ ASCIIToUTF16("override"), // device_name
+ base::FilePath::StringType(), // no location
+ string16(), // no storage label
+ string16(), // no storage vendor
+ string16(), // no storage model
+ 0 // 0 capacity
+ );
+ EXPECT_EQ(ASCIIToUTF16("override"),
+ storageInfo.GetDisplayName());
+ storageInfo.set_name(ASCIIToUTF16("o2"));
+ EXPECT_EQ(ASCIIToUTF16("o2"),
+ storageInfo.GetDisplayName());
+
+ storageInfo.set_storage_label(ASCIIToUTF16("vol"));
+ storageInfo.set_vendor_name(ASCIIToUTF16("vendor"));
+ storageInfo.set_model_name(ASCIIToUTF16("model"));
+ EXPECT_EQ(ASCIIToUTF16("o2"),
+ storageInfo.GetDisplayName());
+
+ storageInfo.set_name(string16());
+ EXPECT_EQ(ASCIIToUTF16("vol"),
+ storageInfo.GetDisplayName());
+ storageInfo.set_storage_label(string16());
+ EXPECT_EQ(ASCIIToUTF16("vendor, model"),
+ storageInfo.GetDisplayName());
+
+ storageInfo.set_total_size_in_bytes(1000000);
+ EXPECT_EQ(ASCIIToUTF16("977 KB vendor, model"),
+ storageInfo.GetDisplayName());
+
+ // Root directory
+ storageInfo.set_location(FILE_PATH_LITERAL(
+ "/"));
+ EXPECT_EQ(ASCIIToUTF16("977 KB vendor, model"),
+ storageInfo.GetDisplayName());
+ // Subfolder directory
+ storageInfo.set_location(FILE_PATH_LITERAL(
+ "/sub/path"));
+ EXPECT_EQ(ASCIIToUTF16("path - 977 KB vendor, model"),
+ storageInfo.GetDisplayName());
+ // drive letter directory
+ storageInfo.set_location(FILE_PATH_LITERAL(
+ "C:\\"));
+ EXPECT_EQ(ASCIIToUTF16("\\ - 977 KB vendor, model"),
+ storageInfo.GetDisplayName());
+}
+
+TEST(StorageInfoTest, NameGenerationFixedDevice) {
+ std::string device_id = StorageInfo::MakeDeviceId(
+ StorageInfo::FIXED_MASS_STORAGE, "/path/to/gallery");
+ StorageInfo storageInfo(
+ device_id,
+ string16(), // no device_name
+ MediaStorageUtil::FindDevicePathById(device_id).value(),
+ //base::FilePath::StringType(), // no location
+ string16(), // no storage label
+ string16(), // no storage vendor
+ string16(), // no storage model
+ 0 // 0 capacity
+ );
+ std::string galleryName("/path/to/gallery");
+#if defined(OS_CHROMEOS)
+ galleryName = "gallery";
+#endif
+ EXPECT_EQ(ASCIIToUTF16(galleryName), storageInfo.GetDisplayName());
+
+ storageInfo.set_name(ASCIIToUTF16("override"));
+ EXPECT_EQ(ASCIIToUTF16("override"),
+ storageInfo.GetDisplayName());
+
+ storageInfo.set_name(string16());
+ storageInfo.set_storage_label(ASCIIToUTF16("label"));
+ EXPECT_EQ(ASCIIToUTF16(galleryName), storageInfo.GetDisplayName());
+
+ galleryName = "/path/to/gallery/sub/gallery2";
+ storageInfo.set_location(FILE_PATH_LITERAL(
+ "/path/to/gallery/sub/gallery2"));
+#if defined(OS_CHROMEOS)
+ galleryName = "gallery2";
+#endif
+ EXPECT_EQ(ASCIIToUTF16(galleryName), storageInfo.GetDisplayName());
+}

Powered by Google App Engine
This is Rietveld 408576698