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

Unified Diff: chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc

Issue 207383004: Adds a new removable storage provider for imageWriterPrivate on Chrome OS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months 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/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc
diff --git a/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc b/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..faa33387a1f41724cb21cf9ed67c404458df865a
--- /dev/null
+++ b/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_chromeos_unittest.cc
@@ -0,0 +1,175 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"
+#include "chromeos/disks/mock_disk_mount_manager.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+namespace {
+
+using chromeos::disks::MockDiskMountManager;
+using chromeos::disks::DiskMountManager;
+
+const char kDevicePath[] = "/dev/d1";
+const char kDeviceId[] = "FFFF-FFFF";
+const char kDeviceName[] = "USB Disk 1";
+const char kVendorName[] = "Vendor";
+const char kProductName[] = "Product";
+const uint64 kDeviceSize = 1024 * 1024 * 1024;
+
+const char kUnknownSDDiskModel[] = "SD Card";
+const char kUnknownUSBDiskModel[] = "USB Drive";
+
+class RemovableStorageProviderChromeOsUnitTest : public testing::Test {
+ public:
+ virtual void SetUp() OVERRIDE {
+ disk_mount_manager_mock_ = new MockDiskMountManager();
tbarzic 2014/03/22 02:01:02 Mock is not really what you need here, but since w
Drew Haven 2014/03/24 22:33:25 Acknowledged.
+ DiskMountManager::InitializeForTesting(disk_mount_manager_mock_);
+ disk_mount_manager_mock_->SetupDefaultReplies();
+ }
+
+ virtual void TearDown() OVERRIDE { DiskMountManager::Shutdown(); }
+
+ void DevicesCallback(scoped_refptr<StorageDeviceList> devices, bool success) {
+ devices_ = devices;
+ }
+
+ DiskMountManager::Disk* CreateDisk(const std::string& device_path,
+ chromeos::DeviceType device_type,
+ bool is_parent,
+ bool has_media,
+ bool on_boot_device) {
+ return CreateDisk(device_path,
+ kVendorName,
+ kProductName,
+ device_type,
+ is_parent,
+ has_media,
+ on_boot_device);
+ }
+
+ DiskMountManager::Disk* CreateDisk(const std::string& device_path,
+ const std::string& vendor_name,
+ const std::string& product_name,
+ chromeos::DeviceType device_type,
+ bool is_parent,
+ bool has_media,
+ bool on_boot_device) {
+ return new DiskMountManager::Disk(device_path, // device_path
+ std::string(), // mount_point
+ std::string(), // system_path
+ kDevicePath, // file_path
+ kDeviceName, // device_label
+ std::string(), // drive_label
+ std::string(), // vendor_id
+ vendor_name, // vendor_name
+ std::string(), // product_id
+ product_name, // product_name
+ kDeviceId, // fs_uuid
+ std::string(), // system_path_prefix
+ device_type, // device_type
+ kDeviceSize, // size
+ is_parent, // is_parent
+ false, // is_read_only
+ has_media, // has_media
+ on_boot_device, // on_boot_device
+ false); // is_hidden
+ }
+
+ MockDiskMountManager* disk_mount_manager_mock_;
+ scoped_refptr<StorageDeviceList> devices_;
+};
+
+} // namespace
+
+// Tests that GetAllDevices works as expected, only exposing USB and SD cards
+// that are parents, have media and are not boot devices. Other flags are
+// uninteresting or should not occur for these device types.
+TEST_F(RemovableStorageProviderChromeOsUnitTest, GetAllDevices) {
+ disk_mount_manager_mock_->AddDiskEntry(
+ CreateDisk("USB", chromeos::DEVICE_TYPE_USB, true, true, false));
+ disk_mount_manager_mock_->AddDiskEntry(
+ CreateDisk("SD", chromeos::DEVICE_TYPE_SD, true, true, false));
+ disk_mount_manager_mock_->AddDiskEntry(
+ CreateDisk("NotParent", chromeos::DEVICE_TYPE_USB, false, true, false));
+ disk_mount_manager_mock_->AddDiskEntry(
+ CreateDisk("NoMedia", chromeos::DEVICE_TYPE_USB, true, false, false));
+ disk_mount_manager_mock_->AddDiskEntry(
+ CreateDisk("OnBootDevice", chromeos::DEVICE_TYPE_USB, true, true, true));
+
+ scoped_ptr<RemovableStorageProvider> provider(new RemovableStorageProvider());
+
+ provider->GetAllDevices(
tbarzic 2014/03/22 02:01:02 GetAllDevices is static, right? I'd suggest callin
Drew Haven 2014/03/24 22:33:25 Whoops, so for some reason I forgot this was a sta
+ base::Bind(&RemovableStorageProviderChromeOsUnitTest::DevicesCallback,
+ base::Unretained(this)));
+
+ ASSERT_EQ(2U, devices_->data.size());
+
+ linked_ptr<api::image_writer_private::RemovableStorageDevice> device1 =
+ devices_->data[0];
+
+ EXPECT_EQ(kDevicePath, device1->storage_unit_id);
+ EXPECT_EQ(kVendorName, device1->vendor);
+ EXPECT_EQ(kProductName, device1->model);
+ EXPECT_EQ(kDeviceSize, device1->capacity);
+
+ linked_ptr<api::image_writer_private::RemovableStorageDevice> device2 =
+ devices_->data[1];
+
+ EXPECT_EQ(kDevicePath, device2->storage_unit_id);
+ EXPECT_EQ(kVendorName, device2->vendor);
+ EXPECT_EQ(kProductName, device2->model);
+ EXPECT_EQ(kDeviceSize, device2->capacity);
+}
+
+// Tests that a USB drive with an empty vendor and product gets a generic name.
+TEST_F(RemovableStorageProviderChromeOsUnitTest,
+ EmptyProductAndModelForUsbDrive) {
+ disk_mount_manager_mock_->AddDiskEntry(
+ CreateDisk("USB", "", "", chromeos::DEVICE_TYPE_USB, true, true, false));
+
+ scoped_ptr<RemovableStorageProvider> provider(new RemovableStorageProvider());
+
+ provider->GetAllDevices(
+ base::Bind(&RemovableStorageProviderChromeOsUnitTest::DevicesCallback,
+ base::Unretained(this)));
+
+ ASSERT_EQ(1U, devices_->data.size());
+
+ linked_ptr<api::image_writer_private::RemovableStorageDevice> device =
+ devices_->data[0];
+
+ EXPECT_EQ(kDevicePath, device->storage_unit_id);
+ EXPECT_EQ("", device->vendor);
+ EXPECT_EQ(kUnknownUSBDiskModel, device->model);
+ EXPECT_EQ(kDeviceSize, device->capacity);
+}
+
+// Tests that a SD card with an empty vendor and product gets a generic name.
+TEST_F(RemovableStorageProviderChromeOsUnitTest,
+ EmptyProductAndModelForSdCard) {
+ disk_mount_manager_mock_->AddDiskEntry(
+ CreateDisk("SD", "", "", chromeos::DEVICE_TYPE_SD, true, true, false));
+
+ scoped_ptr<RemovableStorageProvider> provider(new RemovableStorageProvider());
+
+ provider->GetAllDevices(
+ base::Bind(&RemovableStorageProviderChromeOsUnitTest::DevicesCallback,
+ base::Unretained(this)));
+
+ ASSERT_EQ(1U, devices_->data.size());
+
+ linked_ptr<api::image_writer_private::RemovableStorageDevice> device =
+ devices_->data[0];
+
+ EXPECT_EQ(kDevicePath, device->storage_unit_id);
+ EXPECT_EQ("", device->vendor);
+ EXPECT_EQ(kUnknownSDDiskModel, device->model);
+ EXPECT_EQ(kDeviceSize, device->capacity);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698