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

Side by Side Diff: content/browser/bluetooth/bluetooth_blocklist_unittest.cc

Issue 2554253002: bluetooth: web: Rename Blacklist to Blocklist (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/bluetooth/bluetooth_blacklist.h" 5 #include "content/browser/bluetooth/bluetooth_blocklist.h"
6 6
7 #include "device/bluetooth/bluetooth_uuid.h" 7 #include "device/bluetooth/bluetooth_uuid.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using device::BluetoothUUID; 10 using device::BluetoothUUID;
11 11
12 namespace content { 12 namespace content {
13 13
14 namespace { 14 namespace {
15 15
16 base::Optional<BluetoothUUID> Canonicalize(const std::string& str) { 16 base::Optional<BluetoothUUID> Canonicalize(const std::string& str) {
17 return base::make_optional(device::BluetoothUUID(str)); 17 return base::make_optional(device::BluetoothUUID(str));
18 } 18 }
19 19
20 } // namespace 20 } // namespace
21 21
22 class BluetoothBlacklistTest : public ::testing::Test { 22 class BluetoothBlocklistTest : public ::testing::Test {
23 public: 23 public:
24 BluetoothBlacklistTest() : list_(BluetoothBlacklist::Get()) { 24 BluetoothBlocklistTest() : list_(BluetoothBlocklist::Get()) {
25 // Because BluetoothBlacklist is used via a singleton instance, the data 25 // Because BluetoothBlocklist is used via a singleton instance, the data
26 // must be reset for each test. 26 // must be reset for each test.
27 list_.ResetToDefaultValuesForTest(); 27 list_.ResetToDefaultValuesForTest();
28 } 28 }
29 BluetoothBlacklist& list_; 29 BluetoothBlocklist& list_;
30 }; 30 };
31 31
32 TEST_F(BluetoothBlacklistTest, NonExcludedUUID) { 32 TEST_F(BluetoothBlocklistTest, NonExcludedUUID) {
33 BluetoothUUID non_excluded_uuid("00000000-0000-0000-0000-000000000000"); 33 BluetoothUUID non_excluded_uuid("00000000-0000-0000-0000-000000000000");
34 EXPECT_FALSE(list_.IsExcluded(non_excluded_uuid)); 34 EXPECT_FALSE(list_.IsExcluded(non_excluded_uuid));
35 EXPECT_FALSE(list_.IsExcludedFromReads(non_excluded_uuid)); 35 EXPECT_FALSE(list_.IsExcludedFromReads(non_excluded_uuid));
36 EXPECT_FALSE(list_.IsExcludedFromWrites(non_excluded_uuid)); 36 EXPECT_FALSE(list_.IsExcludedFromWrites(non_excluded_uuid));
37 } 37 }
38 38
39 TEST_F(BluetoothBlacklistTest, ExcludeUUID) { 39 TEST_F(BluetoothBlocklistTest, ExcludeUUID) {
40 BluetoothUUID excluded_uuid("eeee"); 40 BluetoothUUID excluded_uuid("eeee");
41 list_.Add(excluded_uuid, BluetoothBlacklist::Value::EXCLUDE); 41 list_.Add(excluded_uuid, BluetoothBlocklist::Value::EXCLUDE);
42 EXPECT_TRUE(list_.IsExcluded(excluded_uuid)); 42 EXPECT_TRUE(list_.IsExcluded(excluded_uuid));
43 EXPECT_TRUE(list_.IsExcludedFromReads(excluded_uuid)); 43 EXPECT_TRUE(list_.IsExcludedFromReads(excluded_uuid));
44 EXPECT_TRUE(list_.IsExcludedFromWrites(excluded_uuid)); 44 EXPECT_TRUE(list_.IsExcludedFromWrites(excluded_uuid));
45 } 45 }
46 46
47 TEST_F(BluetoothBlacklistTest, ExcludeReadsUUID) { 47 TEST_F(BluetoothBlocklistTest, ExcludeReadsUUID) {
48 BluetoothUUID exclude_reads_uuid("eeee"); 48 BluetoothUUID exclude_reads_uuid("eeee");
49 list_.Add(exclude_reads_uuid, BluetoothBlacklist::Value::EXCLUDE_READS); 49 list_.Add(exclude_reads_uuid, BluetoothBlocklist::Value::EXCLUDE_READS);
50 EXPECT_FALSE(list_.IsExcluded(exclude_reads_uuid)); 50 EXPECT_FALSE(list_.IsExcluded(exclude_reads_uuid));
51 EXPECT_TRUE(list_.IsExcludedFromReads(exclude_reads_uuid)); 51 EXPECT_TRUE(list_.IsExcludedFromReads(exclude_reads_uuid));
52 EXPECT_FALSE(list_.IsExcludedFromWrites(exclude_reads_uuid)); 52 EXPECT_FALSE(list_.IsExcludedFromWrites(exclude_reads_uuid));
53 } 53 }
54 54
55 TEST_F(BluetoothBlacklistTest, ExcludeWritesUUID) { 55 TEST_F(BluetoothBlocklistTest, ExcludeWritesUUID) {
56 BluetoothUUID exclude_writes_uuid("eeee"); 56 BluetoothUUID exclude_writes_uuid("eeee");
57 list_.Add(exclude_writes_uuid, BluetoothBlacklist::Value::EXCLUDE_WRITES); 57 list_.Add(exclude_writes_uuid, BluetoothBlocklist::Value::EXCLUDE_WRITES);
58 EXPECT_FALSE(list_.IsExcluded(exclude_writes_uuid)); 58 EXPECT_FALSE(list_.IsExcluded(exclude_writes_uuid));
59 EXPECT_FALSE(list_.IsExcludedFromReads(exclude_writes_uuid)); 59 EXPECT_FALSE(list_.IsExcludedFromReads(exclude_writes_uuid));
60 EXPECT_TRUE(list_.IsExcludedFromWrites(exclude_writes_uuid)); 60 EXPECT_TRUE(list_.IsExcludedFromWrites(exclude_writes_uuid));
61 } 61 }
62 62
63 TEST_F(BluetoothBlacklistTest, InvalidUUID) { 63 TEST_F(BluetoothBlocklistTest, InvalidUUID) {
64 BluetoothUUID empty_string_uuid(""); 64 BluetoothUUID empty_string_uuid("");
65 EXPECT_DEATH_IF_SUPPORTED( 65 EXPECT_DEATH_IF_SUPPORTED(
66 list_.Add(empty_string_uuid, BluetoothBlacklist::Value::EXCLUDE), ""); 66 list_.Add(empty_string_uuid, BluetoothBlocklist::Value::EXCLUDE), "");
67 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(empty_string_uuid), ""); 67 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(empty_string_uuid), "");
68 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(empty_string_uuid), ""); 68 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(empty_string_uuid), "");
69 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromWrites(empty_string_uuid), ""); 69 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromWrites(empty_string_uuid), "");
70 70
71 BluetoothUUID invalid_string_uuid("Not a valid UUID string."); 71 BluetoothUUID invalid_string_uuid("Not a valid UUID string.");
72 EXPECT_DEATH_IF_SUPPORTED( 72 EXPECT_DEATH_IF_SUPPORTED(
73 list_.Add(invalid_string_uuid, BluetoothBlacklist::Value::EXCLUDE), ""); 73 list_.Add(invalid_string_uuid, BluetoothBlocklist::Value::EXCLUDE), "");
74 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(invalid_string_uuid), ""); 74 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcluded(invalid_string_uuid), "");
75 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(invalid_string_uuid), ""); 75 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromReads(invalid_string_uuid), "");
76 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromWrites(invalid_string_uuid), 76 EXPECT_DEATH_IF_SUPPORTED(list_.IsExcludedFromWrites(invalid_string_uuid),
77 ""); 77 "");
78 } 78 }
79 79
80 // Abreviated UUIDs used to create, or test against, the blacklist work 80 // Abreviated UUIDs used to create, or test against, the blocklist work
81 // correctly compared to full UUIDs. 81 // correctly compared to full UUIDs.
82 TEST_F(BluetoothBlacklistTest, AbreviatedUUIDs) { 82 TEST_F(BluetoothBlocklistTest, AbreviatedUUIDs) {
83 list_.Add(BluetoothUUID("aaaa"), BluetoothBlacklist::Value::EXCLUDE); 83 list_.Add(BluetoothUUID("aaaa"), BluetoothBlocklist::Value::EXCLUDE);
84 EXPECT_TRUE( 84 EXPECT_TRUE(
85 list_.IsExcluded(BluetoothUUID("0000aaaa-0000-1000-8000-00805f9b34fb"))); 85 list_.IsExcluded(BluetoothUUID("0000aaaa-0000-1000-8000-00805f9b34fb")));
86 86
87 list_.Add(BluetoothUUID("0000bbbb-0000-1000-8000-00805f9b34fb"), 87 list_.Add(BluetoothUUID("0000bbbb-0000-1000-8000-00805f9b34fb"),
88 BluetoothBlacklist::Value::EXCLUDE); 88 BluetoothBlocklist::Value::EXCLUDE);
89 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("bbbb"))); 89 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("bbbb")));
90 } 90 }
91 91
92 // Tests permutations of previous values and then Add() with a new value, 92 // Tests permutations of previous values and then Add() with a new value,
93 // requiring result to be strictest result of the combination. 93 // requiring result to be strictest result of the combination.
94 TEST_F(BluetoothBlacklistTest, Add_MergingExcludeValues) { 94 TEST_F(BluetoothBlocklistTest, Add_MergingExcludeValues) {
95 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE); 95 list_.Add(BluetoothUUID("ee01"), BluetoothBlocklist::Value::EXCLUDE);
96 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE); 96 list_.Add(BluetoothUUID("ee01"), BluetoothBlocklist::Value::EXCLUDE);
97 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee01"))); 97 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee01")));
98 98
99 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE); 99 list_.Add(BluetoothUUID("ee02"), BluetoothBlocklist::Value::EXCLUDE);
100 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_READS); 100 list_.Add(BluetoothUUID("ee02"), BluetoothBlocklist::Value::EXCLUDE_READS);
101 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee02"))); 101 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee02")));
102 102
103 list_.Add(BluetoothUUID("ee03"), BluetoothBlacklist::Value::EXCLUDE); 103 list_.Add(BluetoothUUID("ee03"), BluetoothBlocklist::Value::EXCLUDE);
104 list_.Add(BluetoothUUID("ee03"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 104 list_.Add(BluetoothUUID("ee03"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
105 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee03"))); 105 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee03")));
106 106
107 list_.Add(BluetoothUUID("ee04"), BluetoothBlacklist::Value::EXCLUDE_READS); 107 list_.Add(BluetoothUUID("ee04"), BluetoothBlocklist::Value::EXCLUDE_READS);
108 list_.Add(BluetoothUUID("ee04"), BluetoothBlacklist::Value::EXCLUDE); 108 list_.Add(BluetoothUUID("ee04"), BluetoothBlocklist::Value::EXCLUDE);
109 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee04"))); 109 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee04")));
110 110
111 list_.Add(BluetoothUUID("ee05"), BluetoothBlacklist::Value::EXCLUDE_READS); 111 list_.Add(BluetoothUUID("ee05"), BluetoothBlocklist::Value::EXCLUDE_READS);
112 list_.Add(BluetoothUUID("ee05"), BluetoothBlacklist::Value::EXCLUDE_READS); 112 list_.Add(BluetoothUUID("ee05"), BluetoothBlocklist::Value::EXCLUDE_READS);
113 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("ee05"))); 113 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("ee05")));
114 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("ee05"))); 114 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("ee05")));
115 115
116 list_.Add(BluetoothUUID("ee06"), BluetoothBlacklist::Value::EXCLUDE_READS); 116 list_.Add(BluetoothUUID("ee06"), BluetoothBlocklist::Value::EXCLUDE_READS);
117 list_.Add(BluetoothUUID("ee06"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 117 list_.Add(BluetoothUUID("ee06"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
118 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee06"))); 118 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee06")));
119 119
120 list_.Add(BluetoothUUID("ee07"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 120 list_.Add(BluetoothUUID("ee07"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
121 list_.Add(BluetoothUUID("ee07"), BluetoothBlacklist::Value::EXCLUDE); 121 list_.Add(BluetoothUUID("ee07"), BluetoothBlocklist::Value::EXCLUDE);
122 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee07"))); 122 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee07")));
123 123
124 list_.Add(BluetoothUUID("ee08"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 124 list_.Add(BluetoothUUID("ee08"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
125 list_.Add(BluetoothUUID("ee08"), BluetoothBlacklist::Value::EXCLUDE_READS); 125 list_.Add(BluetoothUUID("ee08"), BluetoothBlocklist::Value::EXCLUDE_READS);
126 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee08"))); 126 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("ee08")));
127 127
128 list_.Add(BluetoothUUID("ee09"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 128 list_.Add(BluetoothUUID("ee09"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
129 list_.Add(BluetoothUUID("ee09"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 129 list_.Add(BluetoothUUID("ee09"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
130 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("ee09"))); 130 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("ee09")));
131 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("ee09"))); 131 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("ee09")));
132 } 132 }
133 133
134 // Tests Add() with string that contains many UUID:exclusion value pairs, 134 // Tests Add() with string that contains many UUID:exclusion value pairs,
135 // checking that the correct blacklist entries are created for them. 135 // checking that the correct blocklist entries are created for them.
136 TEST_F(BluetoothBlacklistTest, Add_StringWithValidEntries) { 136 TEST_F(BluetoothBlocklistTest, Add_StringWithValidEntries) {
137 list_.Add( 137 list_.Add(
138 "0001:e,0002:r,0003:w, " // Single items. 138 "0001:e,0002:r,0003:w, " // Single items.
139 "0004:r,0004:r, " // Duplicate items. 139 "0004:r,0004:r, " // Duplicate items.
140 "0005:r,0005:w, " // Items that merge. 140 "0005:r,0005:w, " // Items that merge.
141 "00000006:e, " // 8 char UUID. 141 "00000006:e, " // 8 char UUID.
142 "00000007-0000-1000-8000-00805f9b34fb:e"); 142 "00000007-0000-1000-8000-00805f9b34fb:e");
143 143
144 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0001"))); 144 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0001")));
145 145
146 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("0002"))); 146 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("0002")));
147 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("0002"))); 147 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("0002")));
148 148
149 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("0003"))); 149 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("0003")));
150 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("0003"))); 150 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("0003")));
151 151
152 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("0004"))); 152 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("0004")));
153 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("0004"))); 153 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("0004")));
154 154
155 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0005"))); 155 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0005")));
156 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0006"))); 156 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0006")));
157 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0007"))); 157 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0007")));
158 } 158 }
159 159
160 // Tests Add() with strings that contain no valid UUID:exclusion value. 160 // Tests Add() with strings that contain no valid UUID:exclusion value.
161 TEST_F(BluetoothBlacklistTest, Add_StringsWithNoValidEntries) { 161 TEST_F(BluetoothBlocklistTest, Add_StringsWithNoValidEntries) {
162 size_t previous_list_size = list_.size(); 162 size_t previous_list_size = list_.size();
163 list_.Add(""); 163 list_.Add("");
164 list_.Add("~!@#$%^&*()-_=+[]{}/*-"); 164 list_.Add("~!@#$%^&*()-_=+[]{}/*-");
165 list_.Add(":"); 165 list_.Add(":");
166 list_.Add(","); 166 list_.Add(",");
167 list_.Add(",,"); 167 list_.Add(",,");
168 list_.Add(",:,"); 168 list_.Add(",:,");
169 list_.Add("1234:"); 169 list_.Add("1234:");
170 list_.Add("1234:q"); 170 list_.Add("1234:q");
171 list_.Add("1234:E"); 171 list_.Add("1234:E");
172 list_.Add("1234:R"); 172 list_.Add("1234:R");
173 list_.Add("1234:W"); 173 list_.Add("1234:W");
174 list_.Add("1234:ee"); 174 list_.Add("1234:ee");
175 list_.Add("1234 :e"); 175 list_.Add("1234 :e");
176 list_.Add("1234: e"); 176 list_.Add("1234: e");
177 list_.Add("1:e"); 177 list_.Add("1:e");
178 list_.Add("1:r"); 178 list_.Add("1:r");
179 list_.Add("1:w"); 179 list_.Add("1:w");
180 list_.Add("00001800-0000-1000-8000-00805f9b34fb:ee"); 180 list_.Add("00001800-0000-1000-8000-00805f9b34fb:ee");
181 list_.Add("z0001800-0000-1000-8000-00805f9b34fb:e"); 181 list_.Add("z0001800-0000-1000-8000-00805f9b34fb:e");
182 list_.Add("☯"); 182 list_.Add("☯");
183 EXPECT_EQ(previous_list_size, list_.size()); 183 EXPECT_EQ(previous_list_size, list_.size());
184 } 184 }
185 185
186 // Tests Add() with strings that contain exactly one valid UUID:exclusion value 186 // Tests Add() with strings that contain exactly one valid UUID:exclusion value
187 // pair, and optionally other issues in the string that are ignored. 187 // pair, and optionally other issues in the string that are ignored.
188 TEST_F(BluetoothBlacklistTest, Add_StringsWithOneValidEntry) { 188 TEST_F(BluetoothBlocklistTest, Add_StringsWithOneValidEntry) {
189 size_t previous_list_size = list_.size(); 189 size_t previous_list_size = list_.size();
190 list_.Add("0001:e"); 190 list_.Add("0001:e");
191 EXPECT_EQ(++previous_list_size, list_.size()); 191 EXPECT_EQ(++previous_list_size, list_.size());
192 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0001"))); 192 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0001")));
193 193
194 list_.Add("00000002:e"); 194 list_.Add("00000002:e");
195 EXPECT_EQ(++previous_list_size, list_.size()); 195 EXPECT_EQ(++previous_list_size, list_.size());
196 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0002"))); 196 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0002")));
197 197
198 list_.Add("00000003-0000-1000-8000-00805f9b34fb:e"); 198 list_.Add("00000003-0000-1000-8000-00805f9b34fb:e");
(...skipping 14 matching lines...) Expand all
213 213
214 list_.Add("0007:, 0008:e"); 214 list_.Add("0007:, 0008:e");
215 EXPECT_EQ(++previous_list_size, list_.size()); 215 EXPECT_EQ(++previous_list_size, list_.size());
216 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0008"))); 216 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0008")));
217 217
218 list_.Add("\r\n0009:e\n\r"); 218 list_.Add("\r\n0009:e\n\r");
219 EXPECT_EQ(++previous_list_size, list_.size()); 219 EXPECT_EQ(++previous_list_size, list_.size());
220 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009"))); 220 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("0009")));
221 } 221 }
222 222
223 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) { 223 TEST_F(BluetoothBlocklistTest, IsExcluded_BluetoothScanFilter_ReturnsFalse) {
224 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 224 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE);
225 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 225 list_.Add(BluetoothUUID("ee01"), BluetoothBlocklist::Value::EXCLUDE_READS);
226 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 226 list_.Add(BluetoothUUID("ee02"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
227 { 227 {
228 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> empty_filters; 228 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> empty_filters;
229 EXPECT_FALSE(list_.IsExcluded(empty_filters)); 229 EXPECT_FALSE(list_.IsExcluded(empty_filters));
230 } 230 }
231 { 231 {
232 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1); 232 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_empty_filter(1);
233 233
234 single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); 234 single_empty_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
235 single_empty_filter[0]->services = 235 single_empty_filter[0]->services =
236 mojo::Array<base::Optional<BluetoothUUID>>(); 236 mojo::Array<base::Optional<BluetoothUUID>>();
(...skipping 21 matching lines...) Expand all
258 258
259 multiple_non_matching_filters[1] = 259 multiple_non_matching_filters[1] =
260 blink::mojom::WebBluetoothScanFilter::New(); 260 blink::mojom::WebBluetoothScanFilter::New();
261 multiple_non_matching_filters[1]->services.push_back(Canonicalize("ee02")); 261 multiple_non_matching_filters[1]->services.push_back(Canonicalize("ee02"));
262 multiple_non_matching_filters[1]->services.push_back(Canonicalize("0003")); 262 multiple_non_matching_filters[1]->services.push_back(Canonicalize("0003"));
263 263
264 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters)); 264 EXPECT_FALSE(list_.IsExcluded(multiple_non_matching_filters));
265 } 265 }
266 } 266 }
267 267
268 TEST_F(BluetoothBlacklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) { 268 TEST_F(BluetoothBlocklistTest, IsExcluded_BluetoothScanFilter_ReturnsTrue) {
269 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 269 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE);
270 { 270 {
271 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter( 271 mojo::Array<blink::mojom::WebBluetoothScanFilterPtr> single_matching_filter(
272 1); 272 1);
273 273
274 single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New(); 274 single_matching_filter[0] = blink::mojom::WebBluetoothScanFilter::New();
275 single_matching_filter[0]->services.push_back(Canonicalize("eeee")); 275 single_matching_filter[0]->services.push_back(Canonicalize("eeee"));
276 276
277 EXPECT_TRUE(list_.IsExcluded(single_matching_filter)); 277 EXPECT_TRUE(list_.IsExcluded(single_matching_filter));
278 } 278 }
279 { 279 {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 multiple_matching_filters[0]->services.push_back(Canonicalize("eeee")); 313 multiple_matching_filters[0]->services.push_back(Canonicalize("eeee"));
314 314
315 multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New(); 315 multiple_matching_filters[1] = blink::mojom::WebBluetoothScanFilter::New();
316 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee")); 316 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee"));
317 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee")); 317 multiple_matching_filters[1]->services.push_back(Canonicalize("eeee"));
318 318
319 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters)); 319 EXPECT_TRUE(list_.IsExcluded(multiple_matching_filters));
320 } 320 }
321 } 321 }
322 322
323 TEST_F(BluetoothBlacklistTest, RemoveExcludedUUIDs_NonMatching) { 323 TEST_F(BluetoothBlocklistTest, RemoveExcludedUUIDs_NonMatching) {
324 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 324 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE);
325 list_.Add(BluetoothUUID("ee01"), BluetoothBlacklist::Value::EXCLUDE_READS); 325 list_.Add(BluetoothUUID("ee01"), BluetoothBlocklist::Value::EXCLUDE_READS);
326 list_.Add(BluetoothUUID("ee02"), BluetoothBlacklist::Value::EXCLUDE_WRITES); 326 list_.Add(BluetoothUUID("ee02"), BluetoothBlocklist::Value::EXCLUDE_WRITES);
327 327
328 // options.optional_services should be the same before and after 328 // options.optional_services should be the same before and after
329 // RemoveExcludedUUIDs(). 329 // RemoveExcludedUUIDs().
330 { 330 {
331 // Empty optional_services. 331 // Empty optional_services.
332 blink::mojom::WebBluetoothRequestDeviceOptions options; 332 blink::mojom::WebBluetoothRequestDeviceOptions options;
333 options.optional_services = mojo::Array<base::Optional<BluetoothUUID>>(); 333 options.optional_services = mojo::Array<base::Optional<BluetoothUUID>>();
334 334
335 mojo::Array<base::Optional<BluetoothUUID>> expected = 335 mojo::Array<base::Optional<BluetoothUUID>> expected =
336 options.optional_services.Clone(); 336 options.optional_services.Clone();
(...skipping 21 matching lines...) Expand all
358 options.optional_services.push_back(Canonicalize("0003")); 358 options.optional_services.push_back(Canonicalize("0003"));
359 359
360 mojo::Array<base::Optional<BluetoothUUID>> expected = 360 mojo::Array<base::Optional<BluetoothUUID>> expected =
361 options.optional_services.Clone(); 361 options.optional_services.Clone();
362 362
363 list_.RemoveExcludedUUIDs(&options); 363 list_.RemoveExcludedUUIDs(&options);
364 EXPECT_TRUE(options.optional_services.Equals(expected)); 364 EXPECT_TRUE(options.optional_services.Equals(expected));
365 } 365 }
366 } 366 }
367 367
368 TEST_F(BluetoothBlacklistTest, RemoveExcludedUuids_Matching) { 368 TEST_F(BluetoothBlocklistTest, RemoveExcludedUuids_Matching) {
369 list_.Add(BluetoothUUID("eeee"), BluetoothBlacklist::Value::EXCLUDE); 369 list_.Add(BluetoothUUID("eeee"), BluetoothBlocklist::Value::EXCLUDE);
370 list_.Add(BluetoothUUID("eee2"), BluetoothBlacklist::Value::EXCLUDE); 370 list_.Add(BluetoothUUID("eee2"), BluetoothBlocklist::Value::EXCLUDE);
371 list_.Add(BluetoothUUID("eee3"), BluetoothBlacklist::Value::EXCLUDE); 371 list_.Add(BluetoothUUID("eee3"), BluetoothBlocklist::Value::EXCLUDE);
372 list_.Add(BluetoothUUID("eee4"), BluetoothBlacklist::Value::EXCLUDE); 372 list_.Add(BluetoothUUID("eee4"), BluetoothBlocklist::Value::EXCLUDE);
373 { 373 {
374 // Single matching service in optional_services. 374 // Single matching service in optional_services.
375 blink::mojom::WebBluetoothRequestDeviceOptions options; 375 blink::mojom::WebBluetoothRequestDeviceOptions options;
376 options.optional_services.push_back(Canonicalize("eeee")); 376 options.optional_services.push_back(Canonicalize("eeee"));
377 377
378 mojo::Array<base::Optional<BluetoothUUID>> expected; 378 mojo::Array<base::Optional<BluetoothUUID>> expected;
379 379
380 list_.RemoveExcludedUUIDs(&options); 380 list_.RemoveExcludedUUIDs(&options);
381 381
382 EXPECT_TRUE(options.optional_services.Equals(expected)); 382 EXPECT_TRUE(options.optional_services.Equals(expected));
(...skipping 20 matching lines...) Expand all
403 options.optional_services.push_back(Canonicalize("eee3")); 403 options.optional_services.push_back(Canonicalize("eee3"));
404 options.optional_services.push_back(Canonicalize("eeee")); 404 options.optional_services.push_back(Canonicalize("eeee"));
405 405
406 mojo::Array<base::Optional<BluetoothUUID>> expected; 406 mojo::Array<base::Optional<BluetoothUUID>> expected;
407 407
408 list_.RemoveExcludedUUIDs(&options); 408 list_.RemoveExcludedUUIDs(&options);
409 EXPECT_TRUE(options.optional_services.Equals(expected)); 409 EXPECT_TRUE(options.optional_services.Equals(expected));
410 } 410 }
411 } 411 }
412 412
413 TEST_F(BluetoothBlacklistTest, VerifyDefaultBlacklistSize) { 413 TEST_F(BluetoothBlocklistTest, VerifyDefaultBlocklistSize) {
414 // REMINDER: ADD new blacklist items to tests below for each exclusion type. 414 // REMINDER: ADD new blocklist items to tests below for each exclusion type.
415 EXPECT_EQ(13u, list_.size()); 415 EXPECT_EQ(13u, list_.size());
416 } 416 }
417 417
418 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeList) { 418 TEST_F(BluetoothBlocklistTest, VerifyDefaultExcludeList) {
419 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("1800"))); 419 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("1800")));
420 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("1801"))); 420 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("1801")));
421 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("1812"))); 421 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("1812")));
422 EXPECT_TRUE( 422 EXPECT_TRUE(
423 list_.IsExcluded(BluetoothUUID("00001530-1212-efde-1523-785feabcd123"))); 423 list_.IsExcluded(BluetoothUUID("00001530-1212-efde-1523-785feabcd123")));
424 EXPECT_TRUE( 424 EXPECT_TRUE(
425 list_.IsExcluded(BluetoothUUID("f000ffc0-0451-4000-b000-000000000000"))); 425 list_.IsExcluded(BluetoothUUID("f000ffc0-0451-4000-b000-000000000000")));
426 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("00060000"))); 426 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("00060000")));
427 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("fffd"))); 427 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("fffd")));
428 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("2a02"))); 428 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("2a02")));
429 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("2a03"))); 429 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("2a03")));
430 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("2a25"))); 430 EXPECT_TRUE(list_.IsExcluded(BluetoothUUID("2a25")));
431 EXPECT_FALSE( 431 EXPECT_FALSE(
432 list_.IsExcluded(BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135"))); 432 list_.IsExcluded(BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135")));
433 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("2902"))); 433 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("2902")));
434 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("2903"))); 434 EXPECT_FALSE(list_.IsExcluded(BluetoothUUID("2903")));
435 EXPECT_TRUE( 435 EXPECT_TRUE(
436 list_.IsExcluded(BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); 436 list_.IsExcluded(BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c")));
437 EXPECT_FALSE( 437 EXPECT_FALSE(
438 list_.IsExcluded(BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114"))); 438 list_.IsExcluded(BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114")));
439 } 439 }
440 440
441 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeReadList) { 441 TEST_F(BluetoothBlocklistTest, VerifyDefaultExcludeReadList) {
442 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("1800"))); 442 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("1800")));
443 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("1801"))); 443 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("1801")));
444 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("1812"))); 444 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("1812")));
445 EXPECT_TRUE(list_.IsExcludedFromReads( 445 EXPECT_TRUE(list_.IsExcludedFromReads(
446 BluetoothUUID("00001530-1212-efde-1523-785feabcd123"))); 446 BluetoothUUID("00001530-1212-efde-1523-785feabcd123")));
447 EXPECT_TRUE(list_.IsExcludedFromReads( 447 EXPECT_TRUE(list_.IsExcludedFromReads(
448 BluetoothUUID("f000ffc0-0451-4000-b000-000000000000"))); 448 BluetoothUUID("f000ffc0-0451-4000-b000-000000000000")));
449 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("00060000"))); 449 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("00060000")));
450 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("fffd"))); 450 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("fffd")));
451 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("2a02"))); 451 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("2a02")));
452 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("2a03"))); 452 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("2a03")));
453 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("2a25"))); 453 EXPECT_TRUE(list_.IsExcludedFromReads(BluetoothUUID("2a25")));
454 EXPECT_TRUE(list_.IsExcludedFromReads( 454 EXPECT_TRUE(list_.IsExcludedFromReads(
455 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135"))); 455 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135")));
456 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("2902"))); 456 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("2902")));
457 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("2903"))); 457 EXPECT_FALSE(list_.IsExcludedFromReads(BluetoothUUID("2903")));
458 EXPECT_TRUE(list_.IsExcludedFromReads( 458 EXPECT_TRUE(list_.IsExcludedFromReads(
459 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); 459 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c")));
460 EXPECT_TRUE(list_.IsExcludedFromReads( 460 EXPECT_TRUE(list_.IsExcludedFromReads(
461 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114"))); 461 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114")));
462 } 462 }
463 463
464 TEST_F(BluetoothBlacklistTest, VerifyDefaultExcludeWriteList) { 464 TEST_F(BluetoothBlocklistTest, VerifyDefaultExcludeWriteList) {
465 EXPECT_FALSE(list_.IsExcludedFromWrites(BluetoothUUID("1800"))); 465 EXPECT_FALSE(list_.IsExcludedFromWrites(BluetoothUUID("1800")));
466 EXPECT_FALSE(list_.IsExcludedFromWrites(BluetoothUUID("1801"))); 466 EXPECT_FALSE(list_.IsExcludedFromWrites(BluetoothUUID("1801")));
467 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("1812"))); 467 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("1812")));
468 EXPECT_TRUE(list_.IsExcludedFromWrites( 468 EXPECT_TRUE(list_.IsExcludedFromWrites(
469 BluetoothUUID("00001530-1212-efde-1523-785feabcd123"))); 469 BluetoothUUID("00001530-1212-efde-1523-785feabcd123")));
470 EXPECT_TRUE(list_.IsExcludedFromWrites( 470 EXPECT_TRUE(list_.IsExcludedFromWrites(
471 BluetoothUUID("f000ffc0-0451-4000-b000-000000000000"))); 471 BluetoothUUID("f000ffc0-0451-4000-b000-000000000000")));
472 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("00060000"))); 472 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("00060000")));
473 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("fffd"))); 473 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("fffd")));
474 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a02"))); 474 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a02")));
475 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a03"))); 475 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a03")));
476 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a25"))); 476 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2a25")));
477 EXPECT_FALSE(list_.IsExcludedFromWrites( 477 EXPECT_FALSE(list_.IsExcludedFromWrites(
478 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135"))); 478 BluetoothUUID("bad1c9a2-9a5b-4015-8b60-1579bbbf2135")));
479 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902"))); 479 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2902")));
480 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903"))); 480 EXPECT_TRUE(list_.IsExcludedFromWrites(BluetoothUUID("2903")));
481 EXPECT_TRUE(list_.IsExcludedFromWrites( 481 EXPECT_TRUE(list_.IsExcludedFromWrites(
482 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c"))); 482 BluetoothUUID("bad2ddcf-60db-45cd-bef9-fd72b153cf7c")));
483 EXPECT_FALSE(list_.IsExcludedFromWrites( 483 EXPECT_FALSE(list_.IsExcludedFromWrites(
484 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114"))); 484 BluetoothUUID("bad3ec61-3cc3-4954-9702-7977df514114")));
485 } 485 }
486 486
487 } // namespace content 487 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_blocklist.cc ('k') | content/browser/bluetooth/bluetooth_device_chooser_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698