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

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

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Rebase Created 4 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_allowed_devices_map.h" 5 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "content/common/bluetooth/web_bluetooth_device_id.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 10 #include "url/gurl.h"
10 11
11 using device::BluetoothUUID; 12 using device::BluetoothUUID;
12 13
13 namespace content { 14 namespace content {
14 namespace { 15 namespace {
15 const url::Origin kTestOrigin1(GURL("https://www.example1.com")); 16 const url::Origin kTestOrigin1(GURL("https://www.example1.com"));
16 const url::Origin kTestOrigin2(GURL("https://www.example2.com")); 17 const url::Origin kTestOrigin2(GURL("https://www.example2.com"));
17 18
(...skipping 28 matching lines...) Expand all
46 BluetoothAllowedDevicesMap allowed_devices_map; 47 BluetoothAllowedDevicesMap allowed_devices_map;
47 48
48 EXPECT_DEATH_IF_SUPPORTED(allowed_devices_map.AddDevice( 49 EXPECT_DEATH_IF_SUPPORTED(allowed_devices_map.AddDevice(
49 url::Origin(), kDeviceAddress1, empty_options_), 50 url::Origin(), kDeviceAddress1, empty_options_),
50 ""); 51 "");
51 } 52 }
52 53
53 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { 54 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) {
54 BluetoothAllowedDevicesMap allowed_devices_map; 55 BluetoothAllowedDevicesMap allowed_devices_map;
55 56
56 const std::string& device_id = allowed_devices_map.AddDevice( 57 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice(
57 kTestOrigin1, kDeviceAddress1, empty_options_); 58 kTestOrigin1, kDeviceAddress1, empty_options_);
58 59
59 // Test that we can retrieve the device address/id. 60 // Test that we can retrieve the device address/id.
60 EXPECT_EQ(device_id, 61 EXPECT_EQ(device_id,
61 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 62 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
62 EXPECT_EQ(kDeviceAddress1, 63 EXPECT_EQ(kDeviceAddress1,
63 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id)); 64 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id));
64 } 65 }
65 66
66 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) { 67 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) {
67 BluetoothAllowedDevicesMap allowed_devices_map; 68 BluetoothAllowedDevicesMap allowed_devices_map;
68 const std::string& device_id1 = allowed_devices_map.AddDevice( 69 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
69 kTestOrigin1, kDeviceAddress1, empty_options_); 70 kTestOrigin1, kDeviceAddress1, empty_options_);
70 const std::string& device_id2 = allowed_devices_map.AddDevice( 71 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
71 kTestOrigin1, kDeviceAddress1, empty_options_); 72 kTestOrigin1, kDeviceAddress1, empty_options_);
72 73
73 EXPECT_EQ(device_id1, device_id2); 74 EXPECT_EQ(device_id1, device_id2);
74 75
75 // Test that we can retrieve the device address/id. 76 // Test that we can retrieve the device address/id.
76 EXPECT_EQ(device_id1, 77 EXPECT_EQ(device_id1,
77 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 78 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
78 EXPECT_EQ(kDeviceAddress1, 79 EXPECT_EQ(kDeviceAddress1,
79 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); 80 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1));
80 } 81 }
81 82
82 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { 83 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) {
83 BluetoothAllowedDevicesMap allowed_devices_map; 84 BluetoothAllowedDevicesMap allowed_devices_map;
84 const std::string& device_id1 = allowed_devices_map.AddDevice( 85 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
85 kTestOrigin1, kDeviceAddress1, empty_options_); 86 kTestOrigin1, kDeviceAddress1, empty_options_);
86 const std::string& device_id2 = allowed_devices_map.AddDevice( 87 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
87 kTestOrigin1, kDeviceAddress2, empty_options_); 88 kTestOrigin1, kDeviceAddress2, empty_options_);
88 89
89 EXPECT_NE(device_id1, device_id2); 90 EXPECT_NE(device_id1, device_id2);
90 91
91 // Test that we can retrieve the device address/id. 92 // Test that we can retrieve the device address/id.
92 EXPECT_EQ(device_id1, 93 EXPECT_EQ(device_id1,
93 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 94 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
94 EXPECT_EQ(device_id2, 95 EXPECT_EQ(device_id2,
95 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); 96 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2));
96 97
97 EXPECT_EQ(kDeviceAddress1, 98 EXPECT_EQ(kDeviceAddress1,
98 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); 99 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1));
99 EXPECT_EQ(kDeviceAddress2, 100 EXPECT_EQ(kDeviceAddress2,
100 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); 101 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2));
101 } 102 }
102 103
103 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { 104 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) {
104 BluetoothAllowedDevicesMap allowed_devices_map; 105 BluetoothAllowedDevicesMap allowed_devices_map;
105 const std::string& device_id1 = allowed_devices_map.AddDevice( 106 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
106 kTestOrigin1, kDeviceAddress1, empty_options_); 107 kTestOrigin1, kDeviceAddress1, empty_options_);
107 const std::string& device_id2 = allowed_devices_map.AddDevice( 108 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
108 kTestOrigin2, kDeviceAddress2, empty_options_); 109 kTestOrigin2, kDeviceAddress2, empty_options_);
109 110
110 EXPECT_NE(device_id1, device_id2); 111 EXPECT_NE(device_id1, device_id2);
111 112
112 // Test that the wrong origin doesn't have access to the device. 113 // Test that the wrong origin doesn't have access to the device.
113 114
114 EXPECT_EQ(base::EmptyString(), 115 EXPECT_EQ(nullptr,
115 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); 116 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2));
116 EXPECT_EQ(base::EmptyString(), 117 EXPECT_EQ(nullptr,
117 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1)); 118 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1));
118 119
119 EXPECT_EQ(base::EmptyString(), 120 EXPECT_EQ(base::EmptyString(),
120 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); 121 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2));
121 EXPECT_EQ(base::EmptyString(), 122 EXPECT_EQ(base::EmptyString(),
122 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); 123 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1));
123 124
124 // Test that we can retrieve the device address/id. 125 // Test that we can retrieve the device address/id.
125 EXPECT_EQ(device_id1, 126 EXPECT_EQ(device_id1,
126 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 127 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
127 EXPECT_EQ(device_id2, 128 EXPECT_EQ(device_id2,
128 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2)); 129 *allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2));
129 130
130 EXPECT_EQ(kDeviceAddress1, 131 EXPECT_EQ(kDeviceAddress1,
131 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); 132 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1));
132 EXPECT_EQ(kDeviceAddress2, 133 EXPECT_EQ(kDeviceAddress2,
133 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id2)); 134 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id2));
134 } 135 }
135 136
136 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { 137 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) {
137 BluetoothAllowedDevicesMap allowed_devices_map; 138 BluetoothAllowedDevicesMap allowed_devices_map;
138 const std::string& device_id1 = allowed_devices_map.AddDevice( 139 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice(
139 kTestOrigin1, kDeviceAddress1, empty_options_); 140 kTestOrigin1, kDeviceAddress1, empty_options_);
140 const std::string& device_id2 = allowed_devices_map.AddDevice( 141 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice(
141 kTestOrigin2, kDeviceAddress1, empty_options_); 142 kTestOrigin2, kDeviceAddress1, empty_options_);
142 143
143 EXPECT_NE(device_id1, device_id2); 144 EXPECT_NE(device_id1, device_id2);
144 145
145 // Test that the wrong origin doesn't have access to the device. 146 // Test that the wrong origin doesn't have access to the device.
146 EXPECT_EQ(base::EmptyString(), 147 EXPECT_EQ(base::EmptyString(),
147 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); 148 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2));
148 EXPECT_EQ(base::EmptyString(), 149 EXPECT_EQ(base::EmptyString(),
149 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); 150 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1));
150 } 151 }
151 152
152 TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { 153 TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) {
153 BluetoothAllowedDevicesMap allowed_devices_map; 154 BluetoothAllowedDevicesMap allowed_devices_map;
154 const std::string device_id_first_time = allowed_devices_map.AddDevice( 155 const WebBluetoothDeviceId device_id_first_time =
155 kTestOrigin1, kDeviceAddress1, empty_options_); 156 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1,
157 empty_options_);
156 158
157 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 159 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1);
158 160
159 const std::string device_id_second_time = allowed_devices_map.AddDevice( 161 const WebBluetoothDeviceId device_id_second_time =
160 kTestOrigin1, kDeviceAddress1, empty_options_); 162 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1,
163 empty_options_);
161 164
162 EXPECT_NE(device_id_first_time, device_id_second_time); 165 EXPECT_NE(device_id_first_time, device_id_second_time);
163 } 166 }
164 167
165 TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { 168 TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) {
166 BluetoothAllowedDevicesMap allowed_devices_map; 169 BluetoothAllowedDevicesMap allowed_devices_map;
167 170
168 const std::string& device_id = allowed_devices_map.AddDevice( 171 const WebBluetoothDeviceId device_id = allowed_devices_map.AddDevice(
169 kTestOrigin1, kDeviceAddress1, empty_options_); 172 kTestOrigin1, kDeviceAddress1, empty_options_);
170 173
171 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 174 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1);
172 175
176 EXPECT_EQ(nullptr,
177 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1));
173 EXPECT_EQ(base::EmptyString(), 178 EXPECT_EQ(base::EmptyString(),
174 allowed_devices_map.GetDeviceId(kTestOrigin1, device_id)); 179 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id));
175 EXPECT_EQ(base::EmptyString(), allowed_devices_map.GetDeviceAddress(
176 kTestOrigin1, kDeviceAddress1));
177 } 180 }
178 181
179 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { 182 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) {
180 BluetoothAllowedDevicesMap allowed_devices_map; 183 BluetoothAllowedDevicesMap allowed_devices_map;
181 184
182 // Setup device. 185 // Setup device.
183 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 186 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
184 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 187 blink::mojom::WebBluetoothRequestDeviceOptions::New();
185 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = 188 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 =
186 blink::mojom::WebBluetoothScanFilter::New(); 189 blink::mojom::WebBluetoothScanFilter::New();
187 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 190 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 =
188 blink::mojom::WebBluetoothScanFilter::New(); 191 blink::mojom::WebBluetoothScanFilter::New();
189 192
190 scanFilter1->services.push_back(kGlucoseUUID); 193 scanFilter1->services.push_back(kGlucoseUUID);
191 options->filters.push_back(scanFilter1.Clone()); 194 options->filters.push_back(scanFilter1.Clone());
192 195
193 scanFilter2->services.push_back(kHeartRateUUID); 196 scanFilter2->services.push_back(kHeartRateUUID);
194 options->filters.push_back(scanFilter2.Clone()); 197 options->filters.push_back(scanFilter2.Clone());
195 198
196 options->optional_services.push_back(kBatteryServiceUUID); 199 options->optional_services.push_back(kBatteryServiceUUID);
197 options->optional_services.push_back(kHeartRateUUID); 200 options->optional_services.push_back(kHeartRateUUID);
198 201
199 // Add to map. 202 // Add to map.
200 const std::string device_id1 = 203 const WebBluetoothDeviceId device_id1 =
201 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 204 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options);
202 205
203 // Access allowed services. 206 // Access allowed services.
204 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 207 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
205 kTestOrigin1, device_id1, kGlucoseUUID)); 208 kTestOrigin1, device_id1, kGlucoseUUID));
206 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 209 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
207 kTestOrigin1, device_id1, kHeartRateUUID)); 210 kTestOrigin1, device_id1, kHeartRateUUID));
208 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 211 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
209 kTestOrigin1, device_id1, kBatteryServiceUUID)); 212 kTestOrigin1, device_id1, kBatteryServiceUUID));
210 213
(...skipping 11 matching lines...) Expand all
222 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 225 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
223 kTestOrigin1, device_id1, kBatteryServiceUUID)); 226 kTestOrigin1, device_id1, kBatteryServiceUUID));
224 227
225 // Add device back. 228 // Add device back.
226 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 229 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
227 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 230 blink::mojom::WebBluetoothRequestDeviceOptions::New();
228 231
229 options2->filters.push_back(scanFilter1.Clone()); 232 options2->filters.push_back(scanFilter1.Clone());
230 options2->filters.push_back(scanFilter2.Clone()); 233 options2->filters.push_back(scanFilter2.Clone());
231 234
232 const std::string device_id2 = 235 const WebBluetoothDeviceId device_id2 =
233 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 236 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2);
234 237
235 // Access allowed services. 238 // Access allowed services.
236 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 239 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
237 kTestOrigin1, device_id2, kGlucoseUUID)); 240 kTestOrigin1, device_id2, kGlucoseUUID));
238 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 241 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
239 kTestOrigin1, device_id2, kHeartRateUUID)); 242 kTestOrigin1, device_id2, kHeartRateUUID));
240 243
241 // Try to access a non-allowed service. 244 // Try to access a non-allowed service.
242 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 245 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService(
(...skipping 27 matching lines...) Expand all
270 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 273 blink::mojom::WebBluetoothRequestDeviceOptions::New();
271 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 274 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 =
272 blink::mojom::WebBluetoothScanFilter::New(); 275 blink::mojom::WebBluetoothScanFilter::New();
273 276
274 scanFilter2->services.push_back(kBatteryServiceUUID); 277 scanFilter2->services.push_back(kBatteryServiceUUID);
275 options2->filters.push_back(std::move(scanFilter2)); 278 options2->filters.push_back(std::move(scanFilter2));
276 279
277 options2->optional_services.push_back(kBloodPressureUUID); 280 options2->optional_services.push_back(kBloodPressureUUID);
278 281
279 // Add devices to map. 282 // Add devices to map.
280 const std::string& device_id1 = 283 const WebBluetoothDeviceId& device_id1 =
281 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 284 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
282 const std::string& device_id2 = 285 const WebBluetoothDeviceId& device_id2 =
283 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); 286 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2);
284 287
285 // Access allowed services. 288 // Access allowed services.
286 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 289 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
287 kTestOrigin1, device_id1, kGlucoseUUID)); 290 kTestOrigin1, device_id1, kGlucoseUUID));
288 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 291 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
289 kTestOrigin1, device_id1, kHeartRateUUID)); 292 kTestOrigin1, device_id1, kHeartRateUUID));
290 293
291 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 294 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
292 kTestOrigin1, device_id2, kBatteryServiceUUID)); 295 kTestOrigin1, device_id2, kBatteryServiceUUID));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 330 blink::mojom::WebBluetoothRequestDeviceOptions::New();
328 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 331 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 =
329 blink::mojom::WebBluetoothScanFilter::New(); 332 blink::mojom::WebBluetoothScanFilter::New();
330 333
331 scanFilter2->services.push_back(kBatteryServiceUUID); 334 scanFilter2->services.push_back(kBatteryServiceUUID);
332 options2->filters.push_back(std::move(scanFilter2)); 335 options2->filters.push_back(std::move(scanFilter2));
333 336
334 options2->optional_services.push_back(kBloodPressureUUID); 337 options2->optional_services.push_back(kBloodPressureUUID);
335 338
336 // Add devices to map. 339 // Add devices to map.
337 const std::string& device_id1 = 340 const WebBluetoothDeviceId& device_id1 =
338 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 341 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
339 const std::string& device_id2 = 342 const WebBluetoothDeviceId& device_id2 =
340 allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2); 343 allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2);
341 344
342 // Access allowed services. 345 // Access allowed services.
343 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 346 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
344 kTestOrigin1, device_id1, kGlucoseUUID)); 347 kTestOrigin1, device_id1, kGlucoseUUID));
345 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 348 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
346 kTestOrigin1, device_id1, kHeartRateUUID)); 349 kTestOrigin1, device_id1, kHeartRateUUID));
347 350
348 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 351 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
349 kTestOrigin2, device_id2, kBatteryServiceUUID)); 352 kTestOrigin2, device_id2, kBatteryServiceUUID));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 391 blink::mojom::WebBluetoothRequestDeviceOptions::New();
389 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 = 392 blink::mojom::WebBluetoothScanFilterPtr scanFilter1 =
390 blink::mojom::WebBluetoothScanFilter::New(); 393 blink::mojom::WebBluetoothScanFilter::New();
391 394
392 scanFilter1->services.push_back(kGlucoseUUID); 395 scanFilter1->services.push_back(kGlucoseUUID);
393 options1->filters.push_back(std::move(scanFilter1)); 396 options1->filters.push_back(std::move(scanFilter1));
394 397
395 options1->optional_services.push_back(kBatteryServiceUUID); 398 options1->optional_services.push_back(kBatteryServiceUUID);
396 399
397 // Add to map. 400 // Add to map.
398 const std::string device_id1 = 401 const WebBluetoothDeviceId device_id1 =
399 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 402 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1);
400 403
401 // Setup second request. 404 // Setup second request.
402 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 405 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
403 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 406 blink::mojom::WebBluetoothRequestDeviceOptions::New();
404 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 = 407 blink::mojom::WebBluetoothScanFilterPtr scanFilter2 =
405 blink::mojom::WebBluetoothScanFilter::New(); 408 blink::mojom::WebBluetoothScanFilter::New();
406 409
407 scanFilter2->services.push_back(kHeartRateUUID); 410 scanFilter2->services.push_back(kHeartRateUUID);
408 options2->filters.push_back(std::move(scanFilter2)); 411 options2->filters.push_back(std::move(scanFilter2));
409 412
410 options2->optional_services.push_back(kBloodPressureUUID); 413 options2->optional_services.push_back(kBloodPressureUUID);
411 414
412 // Add to map again. 415 // Add to map again.
413 const std::string device_id2 = 416 const WebBluetoothDeviceId device_id2 =
414 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 417 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2);
415 418
416 EXPECT_EQ(device_id1, device_id2); 419 EXPECT_EQ(device_id1, device_id2);
417 420
418 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 421 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
419 kTestOrigin1, device_id1, kGlucoseUUID)); 422 kTestOrigin1, device_id1, kGlucoseUUID));
420 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 423 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
421 kTestOrigin1, device_id1, kBatteryServiceUUID)); 424 kTestOrigin1, device_id1, kBatteryServiceUUID));
422 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 425 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
423 kTestOrigin1, device_id1, kHeartRateUUID)); 426 kTestOrigin1, device_id1, kHeartRateUUID));
424 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 427 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService(
425 kTestOrigin1, device_id1, kBloodPressureUUID)); 428 kTestOrigin1, device_id1, kBloodPressureUUID));
426 } 429 }
427 430
428 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { 431 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) {
429 BluetoothAllowedDevicesMap allowed_devices_map; 432 BluetoothAllowedDevicesMap allowed_devices_map;
430 433
431 const std::string& device_id = allowed_devices_map.AddDevice( 434 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice(
432 kTestOrigin1, kDeviceAddress1, empty_options_); 435 kTestOrigin1, kDeviceAddress1, empty_options_);
433 436
434 EXPECT_TRUE(device_id.size() == 24) 437 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str()));
435 << "Expected Lenghth of a 128bit string encoded to Base64.";
436 EXPECT_TRUE((device_id[22] == '=') && (device_id[23] == '='))
437 << "Expected padding characters for a 128bit string encoded to Base64.";
438 } 438 }
439 439
440 } // namespace content 440 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698