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

Side by Side Diff: device/usb/usb_device_filter_unittest.cc

Issue 2615353002: Typemap device.usb.DeviceFilter to device::UsbDeviceFilter. (Closed)
Patch Set: Addressed juncai@'s feedback. Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « device/usb/usb_device_filter.cc ('k') | extensions/browser/api/device_permissions_prompt.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 scoped_refptr<MockUsbDevice> android_phone_; 30 scoped_refptr<MockUsbDevice> android_phone_;
31 }; 31 };
32 32
33 TEST_F(UsbFilterTest, MatchAny) { 33 TEST_F(UsbFilterTest, MatchAny) {
34 UsbDeviceFilter filter; 34 UsbDeviceFilter filter;
35 ASSERT_TRUE(filter.Matches(android_phone_)); 35 ASSERT_TRUE(filter.Matches(android_phone_));
36 } 36 }
37 37
38 TEST_F(UsbFilterTest, MatchVendorId) { 38 TEST_F(UsbFilterTest, MatchVendorId) {
39 UsbDeviceFilter filter; 39 UsbDeviceFilter filter;
40 filter.SetVendorId(0x18d1); 40 filter.vendor_id = 0x18d1;
41 ASSERT_TRUE(filter.Matches(android_phone_)); 41 ASSERT_TRUE(filter.Matches(android_phone_));
42 } 42 }
43 43
44 TEST_F(UsbFilterTest, MatchVendorIdNegative) { 44 TEST_F(UsbFilterTest, MatchVendorIdNegative) {
45 UsbDeviceFilter filter; 45 UsbDeviceFilter filter;
46 filter.SetVendorId(0x1d6b); 46 filter.vendor_id = 0x1d6b;
47 ASSERT_FALSE(filter.Matches(android_phone_)); 47 ASSERT_FALSE(filter.Matches(android_phone_));
48 } 48 }
49 49
50 TEST_F(UsbFilterTest, MatchProductId) { 50 TEST_F(UsbFilterTest, MatchProductId) {
51 UsbDeviceFilter filter; 51 UsbDeviceFilter filter;
52 filter.SetVendorId(0x18d1); 52 filter.vendor_id = 0x18d1;
53 filter.SetProductId(0x4ee2); 53 filter.product_id = 0x4ee2;
54 ASSERT_TRUE(filter.Matches(android_phone_)); 54 ASSERT_TRUE(filter.Matches(android_phone_));
55 } 55 }
56 56
57 TEST_F(UsbFilterTest, MatchProductIdNegative) { 57 TEST_F(UsbFilterTest, MatchProductIdNegative) {
58 UsbDeviceFilter filter; 58 UsbDeviceFilter filter;
59 filter.SetVendorId(0x18d1); 59 filter.vendor_id = 0x18d1;
60 filter.SetProductId(0x4ee1); 60 filter.product_id = 0x4ee1;
61 ASSERT_FALSE(filter.Matches(android_phone_)); 61 ASSERT_FALSE(filter.Matches(android_phone_));
62 } 62 }
63 63
64 TEST_F(UsbFilterTest, MatchInterfaceClass) { 64 TEST_F(UsbFilterTest, MatchInterfaceClass) {
65 UsbDeviceFilter filter; 65 UsbDeviceFilter filter;
66 filter.SetInterfaceClass(0xff); 66 filter.interface_class = 0xff;
67 ASSERT_TRUE(filter.Matches(android_phone_)); 67 ASSERT_TRUE(filter.Matches(android_phone_));
68 } 68 }
69 69
70 TEST_F(UsbFilterTest, MatchInterfaceClassNegative) { 70 TEST_F(UsbFilterTest, MatchInterfaceClassNegative) {
71 UsbDeviceFilter filter; 71 UsbDeviceFilter filter;
72 filter.SetInterfaceClass(0xe0); 72 filter.interface_class = 0xe0;
73 ASSERT_FALSE(filter.Matches(android_phone_)); 73 ASSERT_FALSE(filter.Matches(android_phone_));
74 } 74 }
75 75
76 TEST_F(UsbFilterTest, MatchInterfaceSubclass) { 76 TEST_F(UsbFilterTest, MatchInterfaceSubclass) {
77 UsbDeviceFilter filter; 77 UsbDeviceFilter filter;
78 filter.SetInterfaceClass(0xff); 78 filter.interface_class = 0xff;
79 filter.SetInterfaceSubclass(0x42); 79 filter.interface_subclass = 0x42;
80 ASSERT_TRUE(filter.Matches(android_phone_)); 80 ASSERT_TRUE(filter.Matches(android_phone_));
81 } 81 }
82 82
83 TEST_F(UsbFilterTest, MatchInterfaceSubclassNegative) { 83 TEST_F(UsbFilterTest, MatchInterfaceSubclassNegative) {
84 UsbDeviceFilter filter; 84 UsbDeviceFilter filter;
85 filter.SetInterfaceClass(0xff); 85 filter.interface_class = 0xff;
86 filter.SetInterfaceSubclass(0x01); 86 filter.interface_subclass = 0x01;
87 ASSERT_FALSE(filter.Matches(android_phone_)); 87 ASSERT_FALSE(filter.Matches(android_phone_));
88 } 88 }
89 89
90 TEST_F(UsbFilterTest, MatchInterfaceProtocol) { 90 TEST_F(UsbFilterTest, MatchInterfaceProtocol) {
91 UsbDeviceFilter filter; 91 UsbDeviceFilter filter;
92 filter.SetInterfaceClass(0xff); 92 filter.interface_class = 0xff;
93 filter.SetInterfaceSubclass(0x42); 93 filter.interface_subclass = 0x42;
94 filter.SetInterfaceProtocol(0x01); 94 filter.interface_protocol = 0x01;
95 ASSERT_TRUE(filter.Matches(android_phone_)); 95 ASSERT_TRUE(filter.Matches(android_phone_));
96 } 96 }
97 97
98 TEST_F(UsbFilterTest, MatchInterfaceProtocolNegative) { 98 TEST_F(UsbFilterTest, MatchInterfaceProtocolNegative) {
99 UsbDeviceFilter filter; 99 UsbDeviceFilter filter;
100 filter.SetInterfaceClass(0xff); 100 filter.interface_class = 0xff;
101 filter.SetInterfaceSubclass(0x42); 101 filter.interface_subclass = 0x42;
102 filter.SetInterfaceProtocol(0x02); 102 filter.interface_protocol = 0x02;
103 ASSERT_FALSE(filter.Matches(android_phone_)); 103 ASSERT_FALSE(filter.Matches(android_phone_));
104 } 104 }
105 105
106 TEST_F(UsbFilterTest, MatchAnyEmptyList) { 106 TEST_F(UsbFilterTest, MatchAnyEmptyList) {
107 std::vector<UsbDeviceFilter> filters; 107 std::vector<UsbDeviceFilter> filters;
108 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); 108 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters));
109 } 109 }
110 110
111 TEST_F(UsbFilterTest, MatchesAnyVendorId) { 111 TEST_F(UsbFilterTest, MatchesAnyVendorId) {
112 std::vector<UsbDeviceFilter> filters(1); 112 std::vector<UsbDeviceFilter> filters(1);
113 filters.back().SetVendorId(0x18d1); 113 filters.back().vendor_id = 0x18d1;
114 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); 114 ASSERT_TRUE(UsbDeviceFilter::MatchesAny(android_phone_, filters));
115 } 115 }
116 116
117 TEST_F(UsbFilterTest, MatchesAnyVendorIdNegative) { 117 TEST_F(UsbFilterTest, MatchesAnyVendorIdNegative) {
118 std::vector<UsbDeviceFilter> filters(1); 118 std::vector<UsbDeviceFilter> filters(1);
119 filters.back().SetVendorId(0x1d6b); 119 filters.back().vendor_id = 0x1d6b;
120 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(android_phone_, filters)); 120 ASSERT_FALSE(UsbDeviceFilter::MatchesAny(android_phone_, filters));
121 } 121 }
122 122
123 } // namespace 123 } // namespace
124 124
125 } // namespace device 125 } // namespace device
OLDNEW
« no previous file with comments | « device/usb/usb_device_filter.cc ('k') | extensions/browser/api/device_permissions_prompt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698