summaryrefslogtreecommitdiffstats
path: root/extensions/common/permissions/usb_device_permission_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/common/permissions/usb_device_permission_unittest.cc')
-rw-r--r--extensions/common/permissions/usb_device_permission_unittest.cc77
1 files changed, 66 insertions, 11 deletions
diff --git a/extensions/common/permissions/usb_device_permission_unittest.cc b/extensions/common/permissions/usb_device_permission_unittest.cc
index 25d3137..345a000 100644
--- a/extensions/common/permissions/usb_device_permission_unittest.cc
+++ b/extensions/common/permissions/usb_device_permission_unittest.cc
@@ -27,31 +27,86 @@ TEST(USBDevicePermissionTest, PermissionDataOrder) {
UsbDevicePermissionData(0x02ad, 0x138c, 0));
}
-TEST(USBDevicePermissionTest, PermissionMessage) {
+TEST(USBDevicePermissionTest, SingleDevicePermissionMessages) {
const char* const kMessages[] = {
- "Access the USB device PVR Mass Storage from HUMAX Co., Ltd.",
- "Access the USB device from HUMAX Co., Ltd.",
- "Access the USB device",
+ "Access any PVR Mass Storage from HUMAX Co., Ltd. via USB",
+ "Access USB devices from HUMAX Co., Ltd.",
+ "Access USB devices from an unknown vendor",
};
+ {
+ scoped_ptr<base::ListValue> permission_list(new base::ListValue());
+ permission_list->Append(
+ UsbDevicePermissionData(0x02ad, 0x138c, -1).ToValue().release());
+
+ UsbDevicePermission permission(
+ PermissionsInfo::GetInstance()->GetByID(APIPermission::kUsbDevice));
+ ASSERT_TRUE(permission.FromValue(permission_list.get(), NULL, NULL));
+
+ PermissionMessages messages = permission.GetMessages();
+ ASSERT_EQ(1U, messages.size());
+ EXPECT_EQ(base::ASCIIToUTF16(kMessages[0]), messages.at(0).message());
+ }
+ {
+ scoped_ptr<base::ListValue> permission_list(new base::ListValue());
+ permission_list->Append(
+ UsbDevicePermissionData(0x02ad, 0x138d, -1).ToValue().release());
+
+ UsbDevicePermission permission(
+ PermissionsInfo::GetInstance()->GetByID(APIPermission::kUsbDevice));
+ ASSERT_TRUE(permission.FromValue(permission_list.get(), NULL, NULL));
+
+ PermissionMessages messages = permission.GetMessages();
+ ASSERT_EQ(1U, messages.size());
+ EXPECT_EQ(base::ASCIIToUTF16(kMessages[1]), messages.at(0).message());
+ }
+ {
+ scoped_ptr<base::ListValue> permission_list(new base::ListValue());
+ permission_list->Append(
+ UsbDevicePermissionData(0x02ae, 0x138d, -1).ToValue().release());
+
+ UsbDevicePermission permission(
+ PermissionsInfo::GetInstance()->GetByID(APIPermission::kUsbDevice));
+ ASSERT_TRUE(permission.FromValue(permission_list.get(), NULL, NULL));
+
+ PermissionMessages messages = permission.GetMessages();
+ ASSERT_EQ(1U, messages.size());
+ EXPECT_EQ(base::ASCIIToUTF16(kMessages[2]), messages.at(0).message());
+ }
+}
+
+TEST(USBDevicePermissionTest, MultipleDevicePermissionMessage) {
+ const char* const kMessage = "Access any of these USB devices";
+ const char* const kDetails =
+ "PVR Mass Storage from HUMAX Co., Ltd.\n"
+ "unknown devices from HUMAX Co., Ltd.\n"
+ "devices from an unknown vendor";
+
// Prepare data set
scoped_ptr<base::ListValue> permission_list(new base::ListValue());
permission_list->Append(
- UsbDevicePermissionData(0x02ad, 0x138c, -1).ToValue()->DeepCopy());
+ UsbDevicePermissionData(0x02ad, 0x138c, -1).ToValue().release());
+ // This device's product ID is not in Chrome's database.
+ permission_list->Append(
+ UsbDevicePermissionData(0x02ad, 0x138d, -1).ToValue().release());
+ // This additional unknown product will be collapsed into the entry above.
+ permission_list->Append(
+ UsbDevicePermissionData(0x02ad, 0x138e, -1).ToValue().release());
+ // This device's vendor ID is not in Chrome's database.
permission_list->Append(
- UsbDevicePermissionData(0x02ad, 0x138d, -1).ToValue()->DeepCopy());
+ UsbDevicePermissionData(0x02ae, 0x138d, -1).ToValue().release());
+ // This additional unknown vendor will be collapsed into the entry above.
permission_list->Append(
- UsbDevicePermissionData(0x02ae, 0x138d, -1).ToValue()->DeepCopy());
+ UsbDevicePermissionData(0x02af, 0x138d, -1).ToValue().release());
UsbDevicePermission permission(
PermissionsInfo::GetInstance()->GetByID(APIPermission::kUsbDevice));
ASSERT_TRUE(permission.FromValue(permission_list.get(), NULL, NULL));
PermissionMessages messages = permission.GetMessages();
- ASSERT_EQ(3U, messages.size());
- EXPECT_EQ(base::ASCIIToUTF16(kMessages[0]), messages.at(0).message());
- EXPECT_EQ(base::ASCIIToUTF16(kMessages[1]), messages.at(1).message());
- EXPECT_EQ(base::ASCIIToUTF16(kMessages[2]), messages.at(2).message());
+ ASSERT_EQ(1U, messages.size());
+ EXPECT_EQ(base::ASCIIToUTF16(kMessage), messages.at(0).message());
+ EXPECT_EQ(base::ASCIIToUTF16(kDetails), messages.at(0).details());
}
} // namespace extensions