Commit 6283c34d authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Add chromeos::disk:Disk::Builder.

Use it in tests instead of using a 23 argument constructor.

BUG=None

Change-Id: If5f6f2bf44363f99a02ac4f67774e1744c1ce53f
Reviewed-on: https://chromium-review.googlesource.com/1159560
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581446}
parent 0ded0728
......@@ -72,9 +72,13 @@ class DeviceEventRouterTest : public testing::Test {
Disk CreateTestDisk(const std::string& device_path,
const std::string& mount_path,
bool is_read_only_hardware) {
return Disk(device_path, mount_path, false, "", "", "", "", "", "", "", "",
"", device_path, chromeos::DEVICE_TYPE_UNKNOWN, 0, false,
is_read_only_hardware, false, false, false, false, "vfat", "");
return *Disk::Builder()
.SetDevicePath(device_path)
.SetMountPath(mount_path)
.SetSystemPathPrefix(device_path)
.SetIsReadOnlyHardware(is_read_only_hardware)
.SetFileSystemType("vfat")
.Build();
}
std::unique_ptr<DeviceEventRouterImpl> device_event_router;
......
......@@ -285,31 +285,39 @@ class FileManagerPrivateApiTest : public extensions::ExtensionApiTest {
if (static_cast<size_t>(disk_info_index) >= arraysize(kTestDisks))
return;
std::unique_ptr<Disk> disk =
Disk::Builder()
.SetDevicePath(kTestMountPoints[i].source_path)
.SetMountPath(kTestMountPoints[i].mount_path)
.SetWriteDisabledByPolicy(
kTestDisks[disk_info_index].write_disabled_by_policy)
.SetSystemPath(kTestDisks[disk_info_index].system_path)
.SetFilePath(kTestDisks[disk_info_index].file_path)
.SetDeviceLabel(kTestDisks[disk_info_index].device_label)
.SetDriveLabel(kTestDisks[disk_info_index].drive_label)
.SetVendorId(kTestDisks[disk_info_index].vendor_id)
.SetVendorName(kTestDisks[disk_info_index].vendor_name)
.SetProductId(kTestDisks[disk_info_index].product_id)
.SetProductName(kTestDisks[disk_info_index].product_name)
.SetFileSystemUUID(kTestDisks[disk_info_index].fs_uuid)
.SetSystemPathPrefix(
kTestDisks[disk_info_index].system_path_prefix)
.SetDeviceType(kTestDisks[disk_info_index].device_type)
.SetSizeInBytes(kTestDisks[disk_info_index].size_in_bytes)
.SetIsParent(kTestDisks[disk_info_index].is_parent)
.SetIsReadOnlyHardware(
kTestDisks[disk_info_index].is_read_only_hardware)
.SetHasMedia(kTestDisks[disk_info_index].has_media)
.SetOnBootDevice(kTestDisks[disk_info_index].on_boot_device)
.SetOnRemovableDevice(
kTestDisks[disk_info_index].on_removable_device)
.SetIsHidden(kTestDisks[disk_info_index].is_hidden)
.SetFileSystemType(kTestDisks[disk_info_index].file_system_type)
.SetBaseMountPath(kTestDisks[disk_info_index].base_mount_path)
.Build();
volumes_.insert(DiskMountManager::DiskMap::value_type(
kTestMountPoints[i].source_path,
std::make_unique<Disk>(
kTestMountPoints[i].source_path, kTestMountPoints[i].mount_path,
kTestDisks[disk_info_index].write_disabled_by_policy,
kTestDisks[disk_info_index].system_path,
kTestDisks[disk_info_index].file_path,
kTestDisks[disk_info_index].device_label,
kTestDisks[disk_info_index].drive_label,
kTestDisks[disk_info_index].vendor_id,
kTestDisks[disk_info_index].vendor_name,
kTestDisks[disk_info_index].product_id,
kTestDisks[disk_info_index].product_name,
kTestDisks[disk_info_index].fs_uuid,
kTestDisks[disk_info_index].system_path_prefix,
kTestDisks[disk_info_index].device_type,
kTestDisks[disk_info_index].size_in_bytes,
kTestDisks[disk_info_index].is_parent,
kTestDisks[disk_info_index].is_read_only_hardware,
kTestDisks[disk_info_index].has_media,
kTestDisks[disk_info_index].on_boot_device,
kTestDisks[disk_info_index].on_removable_device,
kTestDisks[disk_info_index].is_hidden,
kTestDisks[disk_info_index].file_system_type,
kTestDisks[disk_info_index].base_mount_path)));
kTestMountPoints[i].source_path, std::move(disk)));
}
}
}
......
......@@ -4,6 +4,10 @@
#include "chromeos/disks/disk.h"
#include <utility>
#include "base/memory/ptr_util.h"
namespace chromeos {
namespace disks {
......@@ -40,52 +44,7 @@ Disk::Disk(const DiskInfo& disk_info,
file_system_type_(disk_info.file_system_type()),
base_mount_path_(base_mount_path) {}
Disk::Disk(const std::string& device_path,
const std::string& mount_path,
bool write_disabled_by_policy,
const std::string& system_path,
const std::string& file_path,
const std::string& device_label,
const std::string& drive_label,
const std::string& vendor_id,
const std::string& vendor_name,
const std::string& product_id,
const std::string& product_name,
const std::string& fs_uuid,
const std::string& system_path_prefix,
DeviceType device_type,
uint64_t total_size_in_bytes,
bool is_parent,
bool is_read_only_hardware,
bool has_media,
bool on_boot_device,
bool on_removable_device,
bool is_hidden,
const std::string& file_system_type,
const std::string& base_mount_path)
: device_path_(device_path),
mount_path_(mount_path),
write_disabled_by_policy_(write_disabled_by_policy),
system_path_(system_path),
file_path_(file_path),
device_label_(device_label),
drive_label_(drive_label),
vendor_id_(vendor_id),
vendor_name_(vendor_name),
product_id_(product_id),
product_name_(product_name),
fs_uuid_(fs_uuid),
system_path_prefix_(system_path_prefix),
device_type_(device_type),
total_size_in_bytes_(total_size_in_bytes),
is_parent_(is_parent),
is_read_only_hardware_(is_read_only_hardware),
has_media_(has_media),
on_boot_device_(on_boot_device),
on_removable_device_(on_removable_device),
is_hidden_(is_hidden),
file_system_type_(file_system_type),
base_mount_path_(base_mount_path) {}
Disk::Disk() = default;
Disk::Disk(const Disk&) = default;
......@@ -102,5 +61,129 @@ bool Disk::IsStatefulPartition() const {
return mount_path_ == kStatefulPartition;
}
Disk::Builder::Builder() : disk_(base::WrapUnique(new Disk())) {}
Disk::Builder::~Builder() = default;
Disk::Builder& Disk::Builder::SetDevicePath(const std::string& device_path) {
disk_->device_path_ = device_path;
return *this;
}
Disk::Builder& Disk::Builder::SetMountPath(const std::string& mount_path) {
disk_->mount_path_ = mount_path;
return *this;
}
Disk::Builder& Disk::Builder::SetWriteDisabledByPolicy(
bool write_disabled_by_policy) {
disk_->write_disabled_by_policy_ = write_disabled_by_policy;
return *this;
}
Disk::Builder& Disk::Builder::SetSystemPath(const std::string& system_path) {
disk_->system_path_ = system_path;
return *this;
}
Disk::Builder& Disk::Builder::SetFilePath(const std::string& file_path) {
disk_->file_path_ = file_path;
return *this;
}
Disk::Builder& Disk::Builder::SetDeviceLabel(const std::string& device_label) {
disk_->device_label_ = device_label;
return *this;
}
Disk::Builder& Disk::Builder::SetDriveLabel(const std::string& drive_label) {
disk_->drive_label_ = drive_label;
return *this;
}
Disk::Builder& Disk::Builder::SetVendorId(const std::string& vendor_id) {
disk_->vendor_id_ = vendor_id;
return *this;
}
Disk::Builder& Disk::Builder::SetVendorName(const std::string& vendor_name) {
disk_->vendor_name_ = vendor_name;
return *this;
}
Disk::Builder& Disk::Builder::SetProductId(const std::string& product_id) {
disk_->product_id_ = product_id;
return *this;
}
Disk::Builder& Disk::Builder::SetProductName(const std::string& product_name) {
disk_->product_name_ = product_name;
return *this;
}
Disk::Builder& Disk::Builder::SetFileSystemUUID(const std::string& fs_uuid) {
disk_->fs_uuid_ = fs_uuid;
return *this;
}
Disk::Builder& Disk::Builder::SetSystemPathPrefix(
const std::string& system_path_prefix) {
disk_->system_path_prefix_ = system_path_prefix;
return *this;
}
Disk::Builder& Disk::Builder::SetDeviceType(DeviceType device_type) {
disk_->device_type_ = device_type;
return *this;
}
Disk::Builder& Disk::Builder::SetSizeInBytes(uint64_t total_size_in_bytes) {
disk_->total_size_in_bytes_ = total_size_in_bytes;
return *this;
}
Disk::Builder& Disk::Builder::SetIsParent(bool is_parent) {
disk_->is_parent_ = is_parent;
return *this;
}
Disk::Builder& Disk::Builder::SetIsReadOnlyHardware(
bool is_read_only_hardware) {
disk_->is_read_only_hardware_ = is_read_only_hardware;
return *this;
}
Disk::Builder& Disk::Builder::SetHasMedia(bool has_media) {
disk_->has_media_ = has_media;
return *this;
}
Disk::Builder& Disk::Builder::SetOnBootDevice(bool on_boot_device) {
disk_->on_boot_device_ = on_boot_device;
return *this;
}
Disk::Builder& Disk::Builder::SetOnRemovableDevice(bool on_removable_device) {
disk_->on_removable_device_ = on_removable_device;
return *this;
}
Disk::Builder& Disk::Builder::SetIsHidden(bool is_hidden) {
disk_->is_hidden_ = is_hidden;
return *this;
}
Disk::Builder& Disk::Builder::SetFileSystemType(
const std::string& file_system_type) {
disk_->file_system_type_ = file_system_type;
return *this;
}
Disk::Builder& Disk::Builder::SetBaseMountPath(
const std::string& base_mount_path) {
disk_->base_mount_path_ = base_mount_path;
return *this;
}
std::unique_ptr<Disk> Disk::Builder::Build() {
return std::move(disk_);
}
} // namespace disks
} // namespace chromeos
......@@ -5,8 +5,10 @@
#ifndef CHROMEOS_DISKS_DISK_H_
#define CHROMEOS_DISKS_DISK_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/cros_disks_client.h"
......@@ -15,6 +17,8 @@ namespace disks {
class CHROMEOS_EXPORT Disk {
public:
class Builder;
Disk(const DiskInfo& disk_info,
// Whether the device is mounted in read-only mode by the policy.
// Valid only when the device mounted and mount_path_ is non-empty.
......@@ -23,32 +27,7 @@ class CHROMEOS_EXPORT Disk {
const std::string& base_mount_path);
// For tests.
// TODO(amistry): Replace with a builder.
Disk(const std::string& device_path,
// The path to the mount point of this device. Empty if not mounted.
// (e.g. /media/removable/VOLUME)
const std::string& mount_path,
bool write_disabled_by_policy,
const std::string& system_path,
const std::string& file_path,
const std::string& device_label,
const std::string& drive_label,
const std::string& vendor_id,
const std::string& vendor_name,
const std::string& product_id,
const std::string& product_name,
const std::string& fs_uuid,
const std::string& system_path_prefix,
DeviceType device_type,
uint64_t total_size_in_bytes,
bool is_parent,
bool is_read_only_hardware,
bool has_media,
bool on_boot_device,
bool on_removable_device,
bool is_hidden,
const std::string& file_system_type,
const std::string& base_mount_path);
// TODO(amistry): Eliminate this copy constructor. It is only used in tests.
Disk(const Disk&);
~Disk();
......@@ -152,11 +131,13 @@ class CHROMEOS_EXPORT Disk {
bool IsStatefulPartition() const;
private:
Disk() = delete;
friend class Builder;
Disk();
std::string device_path_;
std::string mount_path_;
bool write_disabled_by_policy_;
bool write_disabled_by_policy_ = false;
std::string system_path_;
std::string file_path_;
std::string device_label_;
......@@ -167,19 +148,56 @@ class CHROMEOS_EXPORT Disk {
std::string product_name_;
std::string fs_uuid_;
std::string system_path_prefix_;
DeviceType device_type_;
uint64_t total_size_in_bytes_;
bool is_parent_;
bool is_read_only_hardware_;
bool has_media_;
bool on_boot_device_;
bool on_removable_device_;
bool is_hidden_;
DeviceType device_type_ = DEVICE_TYPE_UNKNOWN;
uint64_t total_size_in_bytes_ = 0;
bool is_parent_ = false;
bool is_read_only_hardware_ = false;
bool has_media_ = false;
bool on_boot_device_ = false;
bool on_removable_device_ = false;
bool is_hidden_ = false;
bool is_auto_mountable_ = false;
std::string file_system_type_;
std::string base_mount_path_;
};
class CHROMEOS_EXPORT Disk::Builder {
public:
Builder();
~Builder();
Builder& SetDevicePath(const std::string& device_path);
Builder& SetMountPath(const std::string& mount_path);
Builder& SetWriteDisabledByPolicy(bool write_disabled_by_policy);
Builder& SetSystemPath(const std::string& system_path);
Builder& SetFilePath(const std::string& file_path);
Builder& SetDeviceLabel(const std::string& device_label);
Builder& SetDriveLabel(const std::string& drive_label);
Builder& SetVendorId(const std::string& vendor_id);
Builder& SetVendorName(const std::string& vendor_name);
Builder& SetProductId(const std::string& product_id);
Builder& SetProductName(const std::string& product_name);
Builder& SetFileSystemUUID(const std::string& fs_uuid);
Builder& SetSystemPathPrefix(const std::string& system_path_prefix);
Builder& SetDeviceType(DeviceType device_type);
Builder& SetSizeInBytes(uint64_t total_size_in_bytes);
Builder& SetIsParent(bool is_parent);
Builder& SetIsReadOnlyHardware(bool is_read_only_hardware);
Builder& SetHasMedia(bool has_media);
Builder& SetOnBootDevice(bool on_boot_device);
Builder& SetOnRemovableDevice(bool on_removable_device);
Builder& SetIsHidden(bool is_hidden);
Builder& SetFileSystemType(const std::string& file_system_type);
Builder& SetBaseMountPath(const std::string& base_mount_path);
std::unique_ptr<Disk> Build();
private:
std::unique_ptr<Disk> disk_;
DISALLOW_COPY_AND_ASSIGN(Builder);
};
} // namespace disks
} // namespace chromeos
......
......@@ -43,7 +43,6 @@ const char kFileSystemType2[] = "exfat";
struct TestDiskInfo {
const char* source_path;
const char* mount_path;
bool write_disabled_by_policy;
const char* system_path;
const char* file_path;
const char* device_label;
......@@ -56,14 +55,8 @@ struct TestDiskInfo {
const char* system_path_prefix;
chromeos::DeviceType device_type;
uint64_t size_in_bytes;
bool is_parent;
bool is_read_only;
bool has_media;
bool on_boot_device;
bool on_removable_device;
bool is_hidden;
const char* file_system_type;
const char* base_mount_path;
};
// Holds information to create a DiskMOuntManager::MountPointInfo instance.
......@@ -79,7 +72,6 @@ const TestDiskInfo kTestDisks[] = {
{
kDevice1SourcePath,
kDevice1MountPath,
false, // write_disabled_by_policy
"/device/prefix/system_path",
"/device/file_path",
"/device/device_label",
......@@ -92,19 +84,12 @@ const TestDiskInfo kTestDisks[] = {
"/device/prefix",
chromeos::DEVICE_TYPE_USB,
1073741824, // size in bytes
false, // is parent
false, // is read only
true, // has media
false, // is on boot device
true, // is on removable device
false, // is hidden
kFileSystemType1,
"" // base mount path
},
{
kDevice2SourcePath,
"", // not mounted initially
false, // write_disabled_by_policy
"/device/prefix/system_path2",
"/device/file_path2",
"/device/device_label2",
......@@ -117,19 +102,12 @@ const TestDiskInfo kTestDisks[] = {
"/device/prefix2",
chromeos::DEVICE_TYPE_SD,
1073741824, // size in bytes
false, // is parent
false, // is read only
true, // has media
false, // is on boot device
true, // is on removable device
false, // is hidden
kFileSystemType2,
"" // base mount path
},
{
kReadOnlyDeviceSourcePath,
kReadOnlyDeviceMountPath,
false, // write_disabled_by_policy
"/device/prefix/system_path_3",
"/device/file_path_3",
"/device/device_label_3",
......@@ -142,14 +120,8 @@ const TestDiskInfo kTestDisks[] = {
"/device/prefix",
chromeos::DEVICE_TYPE_USB,
1073741824, // size in bytes
false, // is parent
true, // is read only
true, // has media
false, // is on boot device
true, // is on removable device
false, // is hidden
kFileSystemType2,
"" // base mount path
},
};
......@@ -556,16 +528,29 @@ class DiskMountManagerTest : public testing::Test {
private:
// Adds a new disk to the disk mount manager.
void AddTestDisk(const TestDiskInfo& disk) {
std::unique_ptr<Disk> test_disk =
Disk::Builder()
.SetDevicePath(disk.source_path)
.SetMountPath(disk.mount_path)
.SetSystemPath(disk.system_path)
.SetFilePath(disk.file_path)
.SetDeviceLabel(disk.device_label)
.SetDriveLabel(disk.drive_label)
.SetVendorId(disk.vendor_id)
.SetVendorName(disk.vendor_name)
.SetProductId(disk.product_id)
.SetProductName(disk.product_name)
.SetFileSystemUUID(disk.fs_uuid)
.SetSystemPathPrefix(disk.system_path_prefix)
.SetDeviceType(disk.device_type)
.SetSizeInBytes(disk.size_in_bytes)
.SetIsReadOnlyHardware(disk.is_read_only)
.SetHasMedia(true)
.SetOnRemovableDevice(true)
.SetFileSystemType(disk.file_system_type)
.Build();
EXPECT_TRUE(
DiskMountManager::GetInstance()->AddDiskForTest(std::make_unique<Disk>(
disk.source_path, disk.mount_path, disk.write_disabled_by_policy,
disk.system_path, disk.file_path, disk.device_label,
disk.drive_label, disk.vendor_id, disk.vendor_name, disk.product_id,
disk.product_name, disk.fs_uuid, disk.system_path_prefix,
disk.device_type, disk.size_in_bytes, disk.is_parent,
disk.is_read_only, disk.has_media, disk.on_boot_device,
disk.on_removable_device, disk.is_hidden, disk.file_system_type,
disk.base_mount_path)));
DiskMountManager::GetInstance()->AddDiskForTest(std::move(test_disk)));
}
// Adds a new mount point to the disk mount manager.
......
......@@ -36,6 +36,24 @@ const char kTestProductName[] = "A product";
const char kTestUuid[] = "FFFF-FFFF";
const char kTestFileSystemType[] = "vfat";
std::unique_ptr<Disk::Builder> MakeDiskBuilder() {
std::unique_ptr<Disk::Builder> builder = std::make_unique<Disk::Builder>();
builder->SetDevicePath(kTestDevicePath)
.SetSystemPath(kTestSystemPath)
.SetFilePath(kTestFilePath)
.SetDriveLabel(kTestDriveLabel)
.SetVendorId(kTestVendorId)
.SetVendorName(kTestVendorName)
.SetProductId(kTestProductId)
.SetProductName(kTestProductName)
.SetFileSystemUUID(kTestUuid)
.SetSystemPathPrefix(kTestSystemPathPrefix)
.SetHasMedia(true)
.SetOnRemovableDevice(true)
.SetFileSystemType(kTestFileSystemType);
return builder;
}
} // namespace
void MockDiskMountManager::AddObserverInternal(
......@@ -69,21 +87,10 @@ MockDiskMountManager::MockDiskMountManager() {
MockDiskMountManager::~MockDiskMountManager() = default;
void MockDiskMountManager::NotifyDeviceInsertEvents() {
std::unique_ptr<Disk> disk1_ptr = std::make_unique<Disk>(
std::string(kTestDevicePath), std::string(),
false, // write_disabled_by_policy
std::string(kTestSystemPath), std::string(kTestFilePath), std::string(),
std::string(kTestDriveLabel), std::string(kTestVendorId),
std::string(kTestVendorName), std::string(kTestProductId),
std::string(kTestProductName), std::string(kTestUuid),
std::string(kTestSystemPathPrefix), DEVICE_TYPE_USB, 4294967295U,
false, // is_parent
false, // is_read_only
true, // has_media
false, // on_boot_device
true, // on_removable_device
false, // is_hidden
std::string(kTestFileSystemType), std::string());
std::unique_ptr<Disk> disk1_ptr = MakeDiskBuilder()
->SetDeviceType(DEVICE_TYPE_USB)
.SetSizeInBytes(4294967295U)
.Build();
Disk* disk1 = disk1_ptr.get();
disks_.clear();
......@@ -96,22 +103,11 @@ void MockDiskMountManager::NotifyDeviceInsertEvents() {
NotifyDiskChanged(DISK_ADDED, disk1);
// Disk Changed
std::unique_ptr<Disk> disk2_ptr = std::make_unique<Disk>(
std::string(kTestDevicePath), std::string(kTestMountPath),
false, // write_disabled_by_policy
std::string(kTestSystemPath), std::string(kTestFilePath),
std::string(kTestDeviceLabel), std::string(kTestDriveLabel),
std::string(kTestVendorId), std::string(kTestVendorName),
std::string(kTestProductId), std::string(kTestProductName),
std::string(kTestUuid), std::string(kTestSystemPathPrefix),
DEVICE_TYPE_MOBILE, 1073741824,
false, // is_parent
false, // is_read_only
true, // has_media
false, // on_boot_device
true, // on_removable_device
false, // is_hidden
std::string(kTestFileSystemType), std::string());
std::unique_ptr<Disk> disk2_ptr = MakeDiskBuilder()
->SetMountPath(kTestMountPath)
.SetDeviceType(DEVICE_TYPE_MOBILE)
.SetSizeInBytes(1073741824)
.Build();
Disk* disk2 = disk2_ptr.get();
disks_.clear();
disks_[std::string(kTestDevicePath)] = std::move(disk2_ptr);
......@@ -119,22 +115,12 @@ void MockDiskMountManager::NotifyDeviceInsertEvents() {
}
void MockDiskMountManager::NotifyDeviceRemoveEvents() {
std::unique_ptr<Disk> disk_ptr = std::make_unique<Disk>(
std::string(kTestDevicePath), std::string(kTestMountPath),
false, // write_disabled_by_policy
std::string(kTestSystemPath), std::string(kTestFilePath),
std::string(kTestDeviceLabel), std::string(kTestDriveLabel),
std::string(kTestVendorId), std::string(kTestVendorName),
std::string(kTestProductId), std::string(kTestProductName),
std::string(kTestUuid), std::string(kTestSystemPathPrefix),
DEVICE_TYPE_SD, 1073741824,
false, // is_parent
false, // is_read_only
true, // has_media
false, // on_boot_device
true, // on_removable_device
false, // is_hidden
std::string(kTestFileSystemType), std::string());
std::unique_ptr<Disk> disk_ptr = MakeDiskBuilder()
->SetMountPath(kTestMountPath)
.SetDeviceLabel(kTestDeviceLabel)
.SetDeviceType(DEVICE_TYPE_SD)
.SetSizeInBytes(1073741824)
.Build();
Disk* disk = disk_ptr.get();
disks_.clear();
disks_[std::string(kTestDevicePath)] = std::move(disk_ptr);
......@@ -184,22 +170,22 @@ void MockDiskMountManager::CreateDiskEntryForMountDevice(
bool on_removable_device,
const std::string& file_system_type) {
std::unique_ptr<Disk> disk_ptr =
std::make_unique<Disk>(mount_info.source_path, mount_info.mount_path,
false, // write_disabled_by_policy
std::string(), // system_path
mount_info.source_path, device_label,
std::string(), // drive_label
std::string(), // vendor_id
vendor_name,
std::string(), // product_id
product_name,
device_id, // fs_uuid
std::string(), // system_path_prefix
device_type, total_size_in_bytes, is_parent,
false, // is_read_only
has_media, on_boot_device, on_removable_device,
false, // is_hidden
file_system_type, std::string());
Disk::Builder()
.SetDevicePath(mount_info.source_path)
.SetMountPath(mount_info.mount_path)
.SetFilePath(mount_info.source_path)
.SetDeviceLabel(device_label)
.SetVendorName(vendor_name)
.SetProductName(product_name)
.SetFileSystemUUID(device_id)
.SetDeviceType(device_type)
.SetSizeInBytes(total_size_in_bytes)
.SetIsParent(is_parent)
.SetHasMedia(has_media)
.SetOnBootDevice(on_boot_device)
.SetOnRemovableDevice(on_removable_device)
.SetFileSystemType(file_system_type)
.Build();
disks_[std::string(mount_info.source_path)] = std::move(disk_ptr);
}
......
......@@ -31,6 +31,7 @@ namespace storage_monitor {
namespace {
using chromeos::disks::Disk;
using chromeos::disks::DiskMountManager;
using testing::_;
......@@ -549,24 +550,28 @@ TEST_F(StorageMonitorCrosTest, FixedStroageTest) {
// Fixed storage (stateful partition) added.
const std::string label = "fixed1";
const chromeos::disks::Disk disk("", mount_point, false, "", "", label, "",
"", "", "", "", uuid, "",
chromeos::DEVICE_TYPE_UNKNOWN, 0, false,
false, false, false, false, false, "", "");
std::unique_ptr<const Disk> disk = Disk::Builder()
.SetMountPath(mount_point)
.SetDeviceLabel(label)
.SetFileSystemUUID(uuid)
.Build();
monitor_->OnBootDeviceDiskEvent(DiskMountManager::DiskEvent::DISK_ADDED,
disk);
*disk);
std::vector<StorageInfo> disks = monitor_->GetAllAvailableStorages();
ASSERT_EQ(1U, disks.size());
EXPECT_EQ(mount_point, disks[0].location());
EXPECT_EQ(base::ASCIIToUTF16(label), disks[0].storage_label());
// Fixed storage (not stateful partition) added - ignore.
const chromeos::disks::Disk ignored_disk(
"", "usr/share/OEM", false, "", "", "fixed2", "", "", "", "", "",
"fixed2-uuid", "", chromeos::DEVICE_TYPE_UNKNOWN, 0, false, false, false,
false, false, false, "", "");
std::unique_ptr<const Disk> ignored_disk =
Disk::Builder()
.SetMountPath("usr/share/OEM")
.SetDeviceLabel("fixed2")
.SetFileSystemUUID("fixed2-uuid")
.Build();
monitor_->OnBootDeviceDiskEvent(DiskMountManager::DiskEvent::DISK_ADDED,
ignored_disk);
*ignored_disk);
disks = monitor_->GetAllAvailableStorages();
ASSERT_EQ(1U, disks.size());
EXPECT_EQ(mount_point, disks[0].location());
......@@ -574,7 +579,7 @@ TEST_F(StorageMonitorCrosTest, FixedStroageTest) {
// Fixed storage (stateful partition) removed.
monitor_->OnBootDeviceDiskEvent(DiskMountManager::DiskEvent::DISK_REMOVED,
disk);
*disk);
disks = monitor_->GetAllAvailableStorages();
EXPECT_EQ(0U, disks.size());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment