Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media_galleries / media_galleries_dialog_controller_unittest.cc
blob1821d9f61e0defc937db14cc43d8b15ebc1018b5
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.
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"
15 std::string GalleryName(const MediaGalleryPrefInfo& gallery) {
16 base::string16 name = gallery.GetGalleryDisplayName();
17 return UTF16ToASCII(name);
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));
33 gallery.display_name = base::ASCIIToUTF16("override");
34 EXPECT_EQ("override", GalleryName(gallery));
36 gallery.display_name = base::string16();
37 gallery.volume_label = base::ASCIIToUTF16("label");
38 EXPECT_EQ(galleryName, GalleryName(gallery));
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));
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 = base::ASCIIToUTF16("override");
56 EXPECT_EQ("override", GalleryName(gallery));
58 gallery.volume_label = base::ASCIIToUTF16("volume");
59 gallery.vendor_name = base::ASCIIToUTF16("vendor");
60 gallery.model_name = base::ASCIIToUTF16("model");
61 EXPECT_EQ("override", GalleryName(gallery));
63 gallery.display_name = base::string16();
64 EXPECT_EQ("volume", GalleryName(gallery));
66 gallery.volume_label = base::string16();
67 EXPECT_EQ("vendor, model", GalleryName(gallery));
69 gallery.total_size_in_bytes = 1000000;
70 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery));
72 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path"));
73 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery));
74 TestStorageMonitor::RemoveSingleton();