| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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. | |
| 4 | |
| 5 #include "base/files/file_path.h" | |
| 6 #include "base/strings/string16.h" | |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" | |
| 10 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | |
| 11 #include "chrome/browser/storage_monitor/storage_info.h" | |
| 12 #include "chrome/browser/storage_monitor/test_storage_monitor.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 std::string GalleryName(const MediaGalleryPrefInfo& gallery) { | |
| 16 string16 name = gallery.GetGalleryDisplayName(); | |
| 17 return UTF16ToASCII(name); | |
| 18 } | |
| 19 | |
| 20 TEST(MediaGalleriesDialogControllerTest, TestNameGeneration) { | |
| 21 ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); | |
| 22 MediaGalleryPrefInfo gallery; | |
| 23 gallery.pref_id = 1; | |
| 24 gallery.device_id = StorageInfo::MakeDeviceId( | |
| 25 StorageInfo::FIXED_MASS_STORAGE, "/path/to/gallery"); | |
| 26 gallery.type = MediaGalleryPrefInfo::kAutoDetected; | |
| 27 std::string galleryName("/path/to/gallery"); | |
| 28 #if defined(OS_CHROMEOS) | |
| 29 galleryName = "gallery"; | |
| 30 #endif | |
| 31 EXPECT_EQ(galleryName, GalleryName(gallery)); | |
| 32 | |
| 33 gallery.display_name = ASCIIToUTF16("override"); | |
| 34 EXPECT_EQ("override", GalleryName(gallery)); | |
| 35 | |
| 36 gallery.display_name = string16(); | |
| 37 gallery.volume_label = ASCIIToUTF16("label"); | |
| 38 EXPECT_EQ(galleryName, GalleryName(gallery)); | |
| 39 | |
| 40 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/gallery2")); | |
| 41 galleryName = "/path/to/gallery/sub/gallery2"; | |
| 42 #if defined(OS_CHROMEOS) | |
| 43 galleryName = "gallery2"; | |
| 44 #endif | |
| 45 #if defined(OS_WIN) | |
| 46 galleryName = base::FilePath(FILE_PATH_LITERAL("/path/to/gallery")) | |
| 47 .Append(gallery.path).MaybeAsASCII(); | |
| 48 #endif | |
| 49 EXPECT_EQ(galleryName, GalleryName(gallery)); | |
| 50 | |
| 51 gallery.path = base::FilePath(); | |
| 52 gallery.device_id = StorageInfo::MakeDeviceId( | |
| 53 StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, | |
| 54 "/path/to/dcim"); | |
| 55 gallery.display_name = ASCIIToUTF16("override"); | |
| 56 EXPECT_EQ("override", GalleryName(gallery)); | |
| 57 | |
| 58 gallery.volume_label = ASCIIToUTF16("volume"); | |
| 59 gallery.vendor_name = ASCIIToUTF16("vendor"); | |
| 60 gallery.model_name = ASCIIToUTF16("model"); | |
| 61 EXPECT_EQ("override", GalleryName(gallery)); | |
| 62 | |
| 63 gallery.display_name = string16(); | |
| 64 EXPECT_EQ("volume", GalleryName(gallery)); | |
| 65 | |
| 66 gallery.volume_label = string16(); | |
| 67 EXPECT_EQ("vendor, model", GalleryName(gallery)); | |
| 68 | |
| 69 gallery.total_size_in_bytes = 1000000; | |
| 70 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery)); | |
| 71 | |
| 72 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path")); | |
| 73 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery)); | |
| 74 TestStorageMonitor::RemoveSingleton(); | |
| 75 } | |
| OLD | NEW |