| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "device/usb/mock_usb_device.h" | 8 #include "device/usb/mock_usb_device.h" |
| 9 #include "device/usb/usb_descriptors.h" | 9 #include "device/usb/usb_descriptors.h" |
| 10 #include "device/usb/usb_device_filter.h" | 10 #include "device/usb/usb_device_filter.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 TEST_F(UsbFilterTest, MatchProductIdNegative) { | 63 TEST_F(UsbFilterTest, MatchProductIdNegative) { |
| 64 UsbDeviceFilter filter; | 64 UsbDeviceFilter filter; |
| 65 filter.SetVendorId(0x18d1); | 65 filter.SetVendorId(0x18d1); |
| 66 filter.SetProductId(0x4ee1); | 66 filter.SetProductId(0x4ee1); |
| 67 ASSERT_FALSE(filter.Matches(android_phone_)); | 67 ASSERT_FALSE(filter.Matches(android_phone_)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(UsbFilterTest, MatchInterfaceClass) { | 70 TEST_F(UsbFilterTest, MatchInterfaceClass) { |
| 71 UsbDeviceFilter filter; | 71 UsbDeviceFilter filter; |
| 72 filter.SetInterfaceClass(0xff); | 72 filter.SetInterfaceClass(0xff); |
| 73 EXPECT_CALL(*android_phone_.get(), GetConfiguration()) | 73 EXPECT_CALL(*android_phone_.get(), GetActiveConfiguration()) |
| 74 .WillOnce(Return(&config_)); | 74 .WillOnce(Return(&config_)); |
| 75 ASSERT_TRUE(filter.Matches(android_phone_)); | 75 ASSERT_TRUE(filter.Matches(android_phone_)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TEST_F(UsbFilterTest, MatchInterfaceClassNegative) { | 78 TEST_F(UsbFilterTest, MatchInterfaceClassNegative) { |
| 79 UsbDeviceFilter filter; | 79 UsbDeviceFilter filter; |
| 80 filter.SetInterfaceClass(0xe0); | 80 filter.SetInterfaceClass(0xe0); |
| 81 EXPECT_CALL(*android_phone_.get(), GetConfiguration()) | 81 EXPECT_CALL(*android_phone_.get(), GetActiveConfiguration()) |
| 82 .WillOnce(Return(&config_)); | 82 .WillOnce(Return(&config_)); |
| 83 ASSERT_FALSE(filter.Matches(android_phone_)); | 83 ASSERT_FALSE(filter.Matches(android_phone_)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(UsbFilterTest, MatchInterfaceSubclass) { | 86 TEST_F(UsbFilterTest, MatchInterfaceSubclass) { |
| 87 UsbDeviceFilter filter; | 87 UsbDeviceFilter filter; |
| 88 filter.SetInterfaceClass(0xff); | 88 filter.SetInterfaceClass(0xff); |
| 89 filter.SetInterfaceSubclass(0x42); | 89 filter.SetInterfaceSubclass(0x42); |
| 90 EXPECT_CALL(*android_phone_.get(), GetConfiguration()) | 90 EXPECT_CALL(*android_phone_.get(), GetActiveConfiguration()) |
| 91 .WillOnce(Return(&config_)); | 91 .WillOnce(Return(&config_)); |
| 92 ASSERT_TRUE(filter.Matches(android_phone_)); | 92 ASSERT_TRUE(filter.Matches(android_phone_)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 TEST_F(UsbFilterTest, MatchInterfaceSubclassNegative) { | 95 TEST_F(UsbFilterTest, MatchInterfaceSubclassNegative) { |
| 96 UsbDeviceFilter filter; | 96 UsbDeviceFilter filter; |
| 97 filter.SetInterfaceClass(0xff); | 97 filter.SetInterfaceClass(0xff); |
| 98 filter.SetInterfaceSubclass(0x01); | 98 filter.SetInterfaceSubclass(0x01); |
| 99 EXPECT_CALL(*android_phone_.get(), GetConfiguration()) | 99 EXPECT_CALL(*android_phone_.get(), GetActiveConfiguration()) |
| 100 .WillOnce(Return(&config_)); | 100 .WillOnce(Return(&config_)); |
| 101 ASSERT_FALSE(filter.Matches(android_phone_)); | 101 ASSERT_FALSE(filter.Matches(android_phone_)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST_F(UsbFilterTest, MatchInterfaceProtocol) { | 104 TEST_F(UsbFilterTest, MatchInterfaceProtocol) { |
| 105 UsbDeviceFilter filter; | 105 UsbDeviceFilter filter; |
| 106 filter.SetInterfaceClass(0xff); | 106 filter.SetInterfaceClass(0xff); |
| 107 filter.SetInterfaceSubclass(0x42); | 107 filter.SetInterfaceSubclass(0x42); |
| 108 filter.SetInterfaceProtocol(0x01); | 108 filter.SetInterfaceProtocol(0x01); |
| 109 EXPECT_CALL(*android_phone_.get(), GetConfiguration()) | 109 EXPECT_CALL(*android_phone_.get(), GetActiveConfiguration()) |
| 110 .WillOnce(Return(&config_)); | 110 .WillOnce(Return(&config_)); |
| 111 ASSERT_TRUE(filter.Matches(android_phone_)); | 111 ASSERT_TRUE(filter.Matches(android_phone_)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 TEST_F(UsbFilterTest, MatchInterfaceProtocolNegative) { | 114 TEST_F(UsbFilterTest, MatchInterfaceProtocolNegative) { |
| 115 UsbDeviceFilter filter; | 115 UsbDeviceFilter filter; |
| 116 filter.SetInterfaceClass(0xff); | 116 filter.SetInterfaceClass(0xff); |
| 117 filter.SetInterfaceSubclass(0x42); | 117 filter.SetInterfaceSubclass(0x42); |
| 118 filter.SetInterfaceProtocol(0x02); | 118 filter.SetInterfaceProtocol(0x02); |
| 119 EXPECT_CALL(*android_phone_.get(), GetConfiguration()) | 119 EXPECT_CALL(*android_phone_.get(), GetActiveConfiguration()) |
| 120 .WillOnce(Return(&config_)); | 120 .WillOnce(Return(&config_)); |
| 121 ASSERT_FALSE(filter.Matches(android_phone_)); | 121 ASSERT_FALSE(filter.Matches(android_phone_)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_F(UsbFilterTest, MatchAnyEmptyListNegative) { | 124 TEST_F(UsbFilterTest, MatchAnyEmptyListNegative) { |
| 125 std::vector<UsbDeviceFilter> filters; | 125 std::vector<UsbDeviceFilter> filters; |
| 126 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); | 126 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST_F(UsbFilterTest, MatchesAnyVendorId) { | 129 TEST_F(UsbFilterTest, MatchesAnyVendorId) { |
| 130 std::vector<UsbDeviceFilter> filters(1); | 130 std::vector<UsbDeviceFilter> filters(1); |
| 131 filters.back().SetVendorId(0x18d1); | 131 filters.back().SetVendorId(0x18d1); |
| 132 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); | 132 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); |
| 133 } | 133 } |
| 134 | 134 |
| 135 TEST_F(UsbFilterTest, MatchesAnyVendorIdNegative) { | 135 TEST_F(UsbFilterTest, MatchesAnyVendorIdNegative) { |
| 136 std::vector<UsbDeviceFilter> filters(1); | 136 std::vector<UsbDeviceFilter> filters(1); |
| 137 filters.back().SetVendorId(0x1d6b); | 137 filters.back().SetVendorId(0x1d6b); |
| 138 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); | 138 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 } // namespace | 141 } // namespace |
| 142 | 142 |
| 143 } // namespace device | 143 } // namespace device |
| OLD | NEW |