| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> |
| 5 #include <vector> | 6 #include <vector> |
| 6 | 7 |
| 7 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 8 #include "device/usb/mock_usb_device.h" | 9 #include "device/usb/mock_usb_device.h" |
| 9 #include "device/usb/usb_descriptors.h" | 10 #include "device/usb/usb_descriptors.h" |
| 10 #include "device/usb/usb_device_filter.h" | 11 #include "device/usb/usb_device_filter.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace device { | 15 namespace device { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 26 android_phone_ = new MockUsbDevice(0x18d1, 0x4ee2, "Google Inc.", "Nexus 5", | 27 android_phone_ = new MockUsbDevice(0x18d1, 0x4ee2, "Google Inc.", "Nexus 5", |
| 27 "ABC123", {config}); | 28 "ABC123", {config}); |
| 28 } | 29 } |
| 29 | 30 |
| 30 protected: | 31 protected: |
| 31 scoped_refptr<MockUsbDevice> android_phone_; | 32 scoped_refptr<MockUsbDevice> android_phone_; |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 TEST_F(UsbFilterTest, MatchAny) { | 35 TEST_F(UsbFilterTest, MatchAny) { |
| 35 UsbDeviceFilter filter; | 36 UsbDeviceFilter filter; |
| 36 ASSERT_TRUE(filter.Matches(android_phone_)); | 37 ASSERT_TRUE(filter.Matches(*android_phone_)); |
| 37 } | 38 } |
| 38 | 39 |
| 39 TEST_F(UsbFilterTest, MatchVendorId) { | 40 TEST_F(UsbFilterTest, MatchVendorId) { |
| 40 UsbDeviceFilter filter; | 41 UsbDeviceFilter filter; |
| 41 filter.vendor_id = 0x18d1; | 42 filter.vendor_id = 0x18d1; |
| 42 ASSERT_TRUE(filter.Matches(android_phone_)); | 43 ASSERT_TRUE(filter.Matches(*android_phone_)); |
| 43 } | 44 } |
| 44 | 45 |
| 45 TEST_F(UsbFilterTest, MatchVendorIdNegative) { | 46 TEST_F(UsbFilterTest, MatchVendorIdNegative) { |
| 46 UsbDeviceFilter filter; | 47 UsbDeviceFilter filter; |
| 47 filter.vendor_id = 0x1d6b; | 48 filter.vendor_id = 0x1d6b; |
| 48 ASSERT_FALSE(filter.Matches(android_phone_)); | 49 ASSERT_FALSE(filter.Matches(*android_phone_)); |
| 49 } | 50 } |
| 50 | 51 |
| 51 TEST_F(UsbFilterTest, MatchProductId) { | 52 TEST_F(UsbFilterTest, MatchProductId) { |
| 52 UsbDeviceFilter filter; | 53 UsbDeviceFilter filter; |
| 53 filter.vendor_id = 0x18d1; | 54 filter.vendor_id = 0x18d1; |
| 54 filter.product_id = 0x4ee2; | 55 filter.product_id = 0x4ee2; |
| 55 ASSERT_TRUE(filter.Matches(android_phone_)); | 56 ASSERT_TRUE(filter.Matches(*android_phone_)); |
| 56 } | 57 } |
| 57 | 58 |
| 58 TEST_F(UsbFilterTest, MatchProductIdNegative) { | 59 TEST_F(UsbFilterTest, MatchProductIdNegative) { |
| 59 UsbDeviceFilter filter; | 60 UsbDeviceFilter filter; |
| 60 filter.vendor_id = 0x18d1; | 61 filter.vendor_id = 0x18d1; |
| 61 filter.product_id = 0x4ee1; | 62 filter.product_id = 0x4ee1; |
| 62 ASSERT_FALSE(filter.Matches(android_phone_)); | 63 ASSERT_FALSE(filter.Matches(*android_phone_)); |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST_F(UsbFilterTest, MatchInterfaceClass) { | 66 TEST_F(UsbFilterTest, MatchInterfaceClass) { |
| 66 UsbDeviceFilter filter; | 67 UsbDeviceFilter filter; |
| 67 filter.interface_class = 0xff; | 68 filter.interface_class = 0xff; |
| 68 ASSERT_TRUE(filter.Matches(android_phone_)); | 69 ASSERT_TRUE(filter.Matches(*android_phone_)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 TEST_F(UsbFilterTest, MatchInterfaceClassNegative) { | 72 TEST_F(UsbFilterTest, MatchInterfaceClassNegative) { |
| 72 UsbDeviceFilter filter; | 73 UsbDeviceFilter filter; |
| 73 filter.interface_class = 0xe0; | 74 filter.interface_class = 0xe0; |
| 74 ASSERT_FALSE(filter.Matches(android_phone_)); | 75 ASSERT_FALSE(filter.Matches(*android_phone_)); |
| 75 } | 76 } |
| 76 | 77 |
| 77 TEST_F(UsbFilterTest, MatchInterfaceSubclass) { | 78 TEST_F(UsbFilterTest, MatchInterfaceSubclass) { |
| 78 UsbDeviceFilter filter; | 79 UsbDeviceFilter filter; |
| 79 filter.interface_class = 0xff; | 80 filter.interface_class = 0xff; |
| 80 filter.interface_subclass = 0x42; | 81 filter.interface_subclass = 0x42; |
| 81 ASSERT_TRUE(filter.Matches(android_phone_)); | 82 ASSERT_TRUE(filter.Matches(*android_phone_)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 TEST_F(UsbFilterTest, MatchInterfaceSubclassNegative) { | 85 TEST_F(UsbFilterTest, MatchInterfaceSubclassNegative) { |
| 85 UsbDeviceFilter filter; | 86 UsbDeviceFilter filter; |
| 86 filter.interface_class = 0xff; | 87 filter.interface_class = 0xff; |
| 87 filter.interface_subclass = 0x01; | 88 filter.interface_subclass = 0x01; |
| 88 ASSERT_FALSE(filter.Matches(android_phone_)); | 89 ASSERT_FALSE(filter.Matches(*android_phone_)); |
| 89 } | 90 } |
| 90 | 91 |
| 91 TEST_F(UsbFilterTest, MatchInterfaceProtocol) { | 92 TEST_F(UsbFilterTest, MatchInterfaceProtocol) { |
| 92 UsbDeviceFilter filter; | 93 UsbDeviceFilter filter; |
| 93 filter.interface_class = 0xff; | 94 filter.interface_class = 0xff; |
| 94 filter.interface_subclass = 0x42; | 95 filter.interface_subclass = 0x42; |
| 95 filter.interface_protocol = 0x01; | 96 filter.interface_protocol = 0x01; |
| 96 ASSERT_TRUE(filter.Matches(android_phone_)); | 97 ASSERT_TRUE(filter.Matches(*android_phone_)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 TEST_F(UsbFilterTest, MatchInterfaceProtocolNegative) { | 100 TEST_F(UsbFilterTest, MatchInterfaceProtocolNegative) { |
| 100 UsbDeviceFilter filter; | 101 UsbDeviceFilter filter; |
| 101 filter.interface_class = 0xff; | 102 filter.interface_class = 0xff; |
| 102 filter.interface_subclass = 0x42; | 103 filter.interface_subclass = 0x42; |
| 103 filter.interface_protocol = 0x02; | 104 filter.interface_protocol = 0x02; |
| 104 ASSERT_FALSE(filter.Matches(android_phone_)); | 105 ASSERT_FALSE(filter.Matches(*android_phone_)); |
| 105 } | 106 } |
| 106 | 107 |
| 107 TEST_F(UsbFilterTest, MatchSerialNumber) { | 108 TEST_F(UsbFilterTest, MatchSerialNumber) { |
| 108 UsbDeviceFilter filter; | 109 UsbDeviceFilter filter; |
| 109 filter.serial_number = std::string("ABC123"); | 110 filter.serial_number = std::string("ABC123"); |
| 110 EXPECT_TRUE(filter.Matches(android_phone_)); | 111 EXPECT_TRUE(filter.Matches(*android_phone_)); |
| 111 filter.vendor_id = 0x18d1; | 112 filter.vendor_id = 0x18d1; |
| 112 EXPECT_TRUE(filter.Matches(android_phone_)); | 113 EXPECT_TRUE(filter.Matches(*android_phone_)); |
| 113 filter.vendor_id = 0x18d2; | 114 filter.vendor_id = 0x18d2; |
| 114 EXPECT_FALSE(filter.Matches(android_phone_)); | 115 EXPECT_FALSE(filter.Matches(*android_phone_)); |
| 115 filter.vendor_id = 0x18d1; | 116 filter.vendor_id = 0x18d1; |
| 116 filter.serial_number = std::string("DIFFERENT"); | 117 filter.serial_number = std::string("DIFFERENT"); |
| 117 EXPECT_FALSE(filter.Matches(android_phone_)); | 118 EXPECT_FALSE(filter.Matches(*android_phone_)); |
| 118 } | 119 } |
| 119 | 120 |
| 120 TEST_F(UsbFilterTest, MatchAnyEmptyList) { | 121 TEST_F(UsbFilterTest, MatchAnyEmptyList) { |
| 121 std::vector<UsbDeviceFilter> filters; | 122 std::vector<UsbDeviceFilter> filters; |
| 122 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); | 123 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(*android_phone_, filters)); |
| 123 } | 124 } |
| 124 | 125 |
| 125 TEST_F(UsbFilterTest, MatchesAnyVendorId) { | 126 TEST_F(UsbFilterTest, MatchesAnyVendorId) { |
| 126 std::vector<UsbDeviceFilter> filters(1); | 127 std::vector<UsbDeviceFilter> filters(1); |
| 127 filters.back().vendor_id = 0x18d1; | 128 filters.back().vendor_id = 0x18d1; |
| 128 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); | 129 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(*android_phone_, filters)); |
| 129 } | 130 } |
| 130 | 131 |
| 131 TEST_F(UsbFilterTest, MatchesAnyVendorIdNegative) { | 132 TEST_F(UsbFilterTest, MatchesAnyVendorIdNegative) { |
| 132 std::vector<UsbDeviceFilter> filters(1); | 133 std::vector<UsbDeviceFilter> filters(1); |
| 133 filters.back().vendor_id = 0x1d6b; | 134 filters.back().vendor_id = 0x1d6b; |
| 134 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); | 135 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(*android_phone_, filters)); |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace | 138 } // namespace |
| 138 | 139 |
| 139 } // namespace device | 140 } // namespace device |
| OLD | NEW |