| Index: chrome/browser/extensions/api/image_writer_private/removable_storage_provider_mac_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_mac_unittest.cc b/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_mac_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9cbb3a745a5b20750dcc91258e312cbe0e0c2aeb
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/image_writer_private/removable_storage_provider_mac_unittest.cc
|
| @@ -0,0 +1,199 @@
|
| +// Copyright 2014 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 <IOKit/storage/IOStorageProtocolCharacteristics.h>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/run_loop.h"
|
| +#include "base/strings/sys_string_conversions.h"
|
| +#include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"
|
| +#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace {
|
| +
|
| +class RemovableStorageProviderMacUnitTest : public testing::Test {
|
| + public:
|
| + RemovableStorageProviderMacUnitTest() : callback_called_(false) {}
|
| +
|
| + virtual void SetUp() OVERRIDE {
|
| + fixed_disk_ = CreateDiskDictionary("disk0",
|
| + "Fixed Vendor",
|
| + "Fixed Model",
|
| + (int64)1 << 40,
|
| + DriveType::FIXED);
|
| + cd_drive_ = CreateDiskDictionary(
|
| + "disk1", "CD Vendor", "CD Model", 0, DriveType::CD);
|
| + usb_stick_ = CreateDiskDictionary(
|
| + "disk2", "USB Vendor", "USB Model", (int64)1 << 32, DriveType::USB);
|
| + sd_card_ = CreateDiskDictionary(
|
| + "disk3", "SD Vendor", "SD Model", (int64)1 << 33, DriveType::SD);
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {}
|
| +
|
| + // Records the result of a GetDeviceList call.
|
| + void DevicesCallback(scoped_refptr<StorageDeviceList> devices, bool success) {
|
| + callback_called_ = true;
|
| + callback_success_ = success;
|
| + devices_ = devices;
|
| + }
|
| +
|
| + protected:
|
| + scoped_refptr<StorageDeviceList> devices_;
|
| + bool callback_called_;
|
| + bool callback_success_;
|
| +
|
| + base::ScopedCFTypeRef<CFDictionaryRef> fixed_disk_;
|
| + base::ScopedCFTypeRef<CFDictionaryRef> usb_stick_;
|
| + base::ScopedCFTypeRef<CFDictionaryRef> sd_card_;
|
| + base::ScopedCFTypeRef<CFDictionaryRef> cd_drive_;
|
| +
|
| + private:
|
| + // The different types of disks we want to configure.
|
| + typedef enum DriveType {
|
| + FIXED,
|
| + USB,
|
| + SD,
|
| + CD,
|
| + } DriveType;
|
| +
|
| + // Creates a disk-description dictionary.
|
| + base::ScopedCFTypeRef<CFDictionaryRef> CreateDiskDictionary(
|
| + const std::string& bsd_name,
|
| + const std::string& vendor,
|
| + const std::string& model,
|
| + int64 capacity,
|
| + DriveType type) {
|
| + CFMutableDictionaryRef dict =
|
| + CFDictionaryCreateMutable(kCFAllocatorDefault,
|
| + 0,
|
| + &kCFTypeDictionaryKeyCallBacks,
|
| + &kCFTypeDictionaryValueCallBacks);
|
| +
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionMediaBSDNameKey,
|
| + base::SysUTF8ToCFStringRef(bsd_name));
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionDeviceVendorKey,
|
| + base::SysUTF8ToCFStringRef(vendor));
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionDeviceModelKey,
|
| + base::SysUTF8ToCFStringRef(model));
|
| + CFDictionaryAddValue(dict, kDADiskDescriptionMediaWholeKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict,
|
| + kDADiskDescriptionMediaSizeKey,
|
| + CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &capacity));
|
| +
|
| + if (type == DriveType::FIXED) {
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionDeviceProtocolKey,
|
| + CFSTR(kIOPropertyPhysicalInterconnectTypeSerialATA));
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionDeviceInternalKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaEjectableKey, kCFBooleanFalse);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaRemovableKey, kCFBooleanFalse);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaKindKey, CFSTR("IOMedia"));
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionDevicePathKey, CFSTR("Fixed Device Path"));
|
| + } else if (type == DriveType::USB) {
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionDeviceProtocolKey,
|
| + CFSTR(kIOPropertyPhysicalInterconnectTypeUSB));
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionDeviceInternalKey, kCFBooleanFalse);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaEjectableKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaRemovableKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaKindKey, CFSTR("IOMedia"));
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionDevicePathKey, CFSTR("USB Device Path"));
|
| + } else if (type == DriveType::CD) {
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionDeviceProtocolKey,
|
| + CFSTR(kIOPropertyPhysicalInterconnectTypeSerialATA));
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionDeviceInternalKey, kCFBooleanFalse);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaEjectableKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaRemovableKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaKindKey, CFSTR("IOCDMedia"));
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionDevicePathKey, CFSTR("CD Device Path"));
|
| + } else if (type == DriveType::SD) {
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionDeviceProtocolKey,
|
| + CFSTR(kIOPropertyPhysicalInterconnectTypeUSB));
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionDeviceInternalKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaEjectableKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaRemovableKey, kCFBooleanTrue);
|
| + CFDictionaryAddValue(
|
| + dict, kDADiskDescriptionMediaKindKey, CFSTR("IOMedia"));
|
| + CFDictionaryAddValue(dict,
|
| + kDADiskDescriptionDevicePathKey,
|
| + CFSTR("SD Device Path e.g. AppleUSBCardReader"));
|
| + }
|
| +
|
| + return base::ScopedCFTypeRef<CFDictionaryRef>(dict);
|
| + }
|
| +
|
| + content::TestBrowserThreadBundle thread_bundle_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +// Tests DiskIsValidTarget.
|
| +TEST_F(RemovableStorageProviderMacUnitTest, DiskIsValidTarget) {
|
| + ASSERT_FALSE(DAWrapperSpouse::DiskIsValidTarget(fixed_disk_));
|
| + ASSERT_FALSE(DAWrapperSpouse::DiskIsValidTarget(cd_drive_));
|
| + ASSERT_TRUE(DAWrapperSpouse::DiskIsValidTarget(usb_stick_));
|
| + ASSERT_TRUE(DAWrapperSpouse::DiskIsValidTarget(sd_card_));
|
| +}
|
| +
|
| +// Tests ProcessDisk and AddDisk.
|
| +TEST_F(RemovableStorageProviderMacUnitTest, ProcessDisks) {
|
| + scoped_ptr<DAWrapper> da_wrapper(new DAWrapper);
|
| + DAWrapperSpouse spouse(da_wrapper.get());
|
| +
|
| + spouse.SetCallback(
|
| + base::Bind(&RemovableStorageProviderMacUnitTest::DevicesCallback,
|
| + base::Unretained(this)));
|
| + spouse.SetDeviceList(scoped_refptr<StorageDeviceList>(new StorageDeviceList));
|
| +
|
| + spouse.ProcessDisk(fixed_disk_);
|
| + spouse.ProcessDisk(usb_stick_);
|
| + spouse.ProcessDisk(sd_card_);
|
| + spouse.ProcessDisk(cd_drive_);
|
| +
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + ASSERT_TRUE(callback_called_);
|
| + ASSERT_TRUE(callback_success_);
|
| + ASSERT_EQ(2UL, devices_->data.size());
|
| +
|
| + ASSERT_EQ("disk2", devices_->data[0]->storage_unit_id);
|
| + ASSERT_EQ("USB Vendor", devices_->data[0]->vendor);
|
| + ASSERT_EQ("USB Model", devices_->data[0]->model);
|
| + ASSERT_EQ((int64)1 << 32, devices_->data[0]->capacity);
|
| +
|
| + ASSERT_EQ("disk3", devices_->data[1]->storage_unit_id);
|
| + ASSERT_EQ("SD Vendor", devices_->data[1]->vendor);
|
| + ASSERT_EQ("SD Model", devices_->data[1]->model);
|
| + ASSERT_EQ((int64)1 << 33, devices_->data[1]->capacity);
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|