| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/storage_monitor/media_storage_util.h" |
| 7 #include "chrome/browser/storage_monitor/storage_info.h" | 9 #include "chrome/browser/storage_monitor/storage_info.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 11 |
| 10 const char kMtpDeviceId[] = "mtp:VendorModelSerial:ABC:1233:1237912873"; | 12 const char kMtpDeviceId[] = "mtp:VendorModelSerial:ABC:1233:1237912873"; |
| 11 const char kUniqueId[] = "VendorModelSerial:ABC:1233:1237912873"; | 13 const char kUniqueId[] = "VendorModelSerial:ABC:1233:1237912873"; |
| 12 const char kImageCaptureDeviceId[] = "ic:xyz"; | 14 const char kImageCaptureDeviceId[] = "ic:xyz"; |
| 13 | 15 |
| 14 // Test to verify |MakeDeviceId| functionality using a sample | 16 // Test to verify |MakeDeviceId| functionality using a sample |
| 15 // mtp device unique id. | 17 // mtp device unique id. |
| 16 TEST(StorageInfoTest, MakeMtpDeviceId) { | 18 TEST(StorageInfoTest, MakeMtpDeviceId) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 29 EXPECT_EQ(StorageInfo::MTP_OR_PTP, type); | 31 EXPECT_EQ(StorageInfo::MTP_OR_PTP, type); |
| 30 } | 32 } |
| 31 | 33 |
| 32 TEST(StorageInfoTest, TestImageCaptureDeviceId) { | 34 TEST(StorageInfoTest, TestImageCaptureDeviceId) { |
| 33 StorageInfo::Type type; | 35 StorageInfo::Type type; |
| 34 std::string id; | 36 std::string id; |
| 35 ASSERT_TRUE(StorageInfo::CrackDeviceId(kImageCaptureDeviceId, &type, &id)); | 37 ASSERT_TRUE(StorageInfo::CrackDeviceId(kImageCaptureDeviceId, &type, &id)); |
| 36 EXPECT_EQ(StorageInfo::MAC_IMAGE_CAPTURE, type); | 38 EXPECT_EQ(StorageInfo::MAC_IMAGE_CAPTURE, type); |
| 37 EXPECT_EQ("xyz", id); | 39 EXPECT_EQ("xyz", id); |
| 38 } | 40 } |
| 41 |
| 42 TEST(StorageInfoTest, NameGenerationRemovableDevice) { |
| 43 StorageInfo storageInfo( |
| 44 StorageInfo::MakeDeviceId(StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, |
| 45 "unique"), |
| 46 ASCIIToUTF16("override"), // device_name |
| 47 base::FilePath::StringType(), // no location |
| 48 string16(), // no storage label |
| 49 string16(), // no storage vendor |
| 50 string16(), // no storage model |
| 51 0 // 0 capacity |
| 52 ); |
| 53 EXPECT_EQ(ASCIIToUTF16("override"), |
| 54 storageInfo.GetDisplayName()); |
| 55 storageInfo.set_name(ASCIIToUTF16("o2")); |
| 56 EXPECT_EQ(ASCIIToUTF16("o2"), |
| 57 storageInfo.GetDisplayName()); |
| 58 |
| 59 storageInfo.set_storage_label(ASCIIToUTF16("vol")); |
| 60 storageInfo.set_vendor_name(ASCIIToUTF16("vendor")); |
| 61 storageInfo.set_model_name(ASCIIToUTF16("model")); |
| 62 EXPECT_EQ(ASCIIToUTF16("o2"), |
| 63 storageInfo.GetDisplayName()); |
| 64 |
| 65 storageInfo.set_name(string16()); |
| 66 EXPECT_EQ(ASCIIToUTF16("vol"), |
| 67 storageInfo.GetDisplayName()); |
| 68 storageInfo.set_storage_label(string16()); |
| 69 EXPECT_EQ(ASCIIToUTF16("vendor, model"), |
| 70 storageInfo.GetDisplayName()); |
| 71 |
| 72 storageInfo.set_total_size_in_bytes(1000000); |
| 73 EXPECT_EQ(ASCIIToUTF16("977 KB vendor, model"), |
| 74 storageInfo.GetDisplayName()); |
| 75 |
| 76 // Root directory |
| 77 storageInfo.set_location(FILE_PATH_LITERAL( |
| 78 "/")); |
| 79 EXPECT_EQ(ASCIIToUTF16("977 KB vendor, model"), |
| 80 storageInfo.GetDisplayName()); |
| 81 // Subfolder directory |
| 82 storageInfo.set_location(FILE_PATH_LITERAL( |
| 83 "/sub/path")); |
| 84 EXPECT_EQ(ASCIIToUTF16("path - 977 KB vendor, model"), |
| 85 storageInfo.GetDisplayName()); |
| 86 // drive letter directory |
| 87 storageInfo.set_location(FILE_PATH_LITERAL( |
| 88 "C:\\")); |
| 89 EXPECT_EQ(ASCIIToUTF16("\\ - 977 KB vendor, model"), |
| 90 storageInfo.GetDisplayName()); |
| 91 } |
| 92 |
| 93 TEST(StorageInfoTest, NameGenerationFixedDevice) { |
| 94 std::string device_id = StorageInfo::MakeDeviceId( |
| 95 StorageInfo::FIXED_MASS_STORAGE, "/path/to/gallery"); |
| 96 StorageInfo storageInfo( |
| 97 device_id, |
| 98 string16(), // no device_name |
| 99 MediaStorageUtil::FindDevicePathById(device_id).value(), |
| 100 //base::FilePath::StringType(), // no location |
| 101 string16(), // no storage label |
| 102 string16(), // no storage vendor |
| 103 string16(), // no storage model |
| 104 0 // 0 capacity |
| 105 ); |
| 106 std::string galleryName("/path/to/gallery"); |
| 107 #if defined(OS_CHROMEOS) |
| 108 galleryName = "gallery"; |
| 109 #endif |
| 110 EXPECT_EQ(ASCIIToUTF16(galleryName), storageInfo.GetDisplayName()); |
| 111 |
| 112 storageInfo.set_name(ASCIIToUTF16("override")); |
| 113 EXPECT_EQ(ASCIIToUTF16("override"), |
| 114 storageInfo.GetDisplayName()); |
| 115 |
| 116 storageInfo.set_name(string16()); |
| 117 storageInfo.set_storage_label(ASCIIToUTF16("label")); |
| 118 EXPECT_EQ(ASCIIToUTF16(galleryName), storageInfo.GetDisplayName()); |
| 119 |
| 120 galleryName = "/path/to/gallery/sub/gallery2"; |
| 121 storageInfo.set_location(FILE_PATH_LITERAL( |
| 122 "/path/to/gallery/sub/gallery2")); |
| 123 #if defined(OS_CHROMEOS) |
| 124 galleryName = "gallery2"; |
| 125 #endif |
| 126 EXPECT_EQ(ASCIIToUTF16(galleryName), storageInfo.GetDisplayName()); |
| 127 } |
| OLD | NEW |