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

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

Issue 2658473002: Refactor BluetoothAllowedDevicesMap (Closed)
Patch Set: updated test code Created 3 years, 10 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.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 "content/common/bluetooth/web_bluetooth_device_id.h"
9 #include "content/public/browser/bluetooth_allowed_devices_map_base.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h" 11 #include "url/gurl.h"
11 12
12 using device::BluetoothUUID; 13 using device::BluetoothUUID;
13 14
14 namespace content { 15 namespace content {
15 namespace { 16 namespace {
16 const url::Origin kTestOrigin1(GURL("https://www.example1.com")); 17 const url::Origin kTestOrigin1(GURL("https://www.example1.com"));
17 const url::Origin kTestOrigin2(GURL("https://www.example2.com")); 18 const url::Origin kTestOrigin2(GURL("https://www.example2.com"));
18 19
19 const std::string kDeviceAddress1 = "00:00:00"; 20 const std::string kDeviceAddress1 = "00:00:00";
20 const std::string kDeviceAddress2 = "11:11:11"; 21 const std::string kDeviceAddress2 = "11:11:11";
21 22
22 const std::string kDeviceName = "TestName"; 23 const std::string kDeviceName = "TestName";
23 24
24 const char kGlucoseUUIDString[] = "00001808-0000-1000-8000-00805f9b34fb"; 25 const char kGlucoseUUIDString[] = "00001808-0000-1000-8000-00805f9b34fb";
25 const char kHeartRateUUIDString[] = "0000180d-0000-1000-8000-00805f9b34fb"; 26 const char kHeartRateUUIDString[] = "0000180d-0000-1000-8000-00805f9b34fb";
26 const char kBatteryServiceUUIDString[] = "0000180f-0000-1000-8000-00805f9b34fb"; 27 const char kBatteryServiceUUIDString[] = "0000180f-0000-1000-8000-00805f9b34fb";
27 const char kBloodPressureUUIDString[] = "00001813-0000-1000-8000-00805f9b34fb"; 28 const char kBloodPressureUUIDString[] = "00001813-0000-1000-8000-00805f9b34fb";
28 const char kCyclingPowerUUIDString[] = "00001818-0000-1000-8000-00805f9b34fb"; 29 const char kCyclingPowerUUIDString[] = "00001818-0000-1000-8000-00805f9b34fb";
29 const BluetoothUUID kGlucoseUUID(kGlucoseUUIDString); 30 const BluetoothUUID kGlucoseUUID(kGlucoseUUIDString);
30 const BluetoothUUID kHeartRateUUID(kHeartRateUUIDString); 31 const BluetoothUUID kHeartRateUUID(kHeartRateUUIDString);
31 const BluetoothUUID kBatteryServiceUUID(kBatteryServiceUUIDString); 32 const BluetoothUUID kBatteryServiceUUID(kBatteryServiceUUIDString);
32 const BluetoothUUID kBloodPressureUUID(kBloodPressureUUIDString); 33 const BluetoothUUID kBloodPressureUUID(kBloodPressureUUIDString);
33 const BluetoothUUID kCyclingPowerUUID(kCyclingPowerUUIDString); 34 const BluetoothUUID kCyclingPowerUUID(kCyclingPowerUUIDString);
34 35
35 class BluetoothAllowedDevicesMapTest : public testing::Test { 36 class BluetoothAllowedDevicesTest : public testing::Test {
36 protected: 37 protected:
37 BluetoothAllowedDevicesMapTest() { 38 BluetoothAllowedDevicesTest() {
38 empty_options_ = blink::mojom::WebBluetoothRequestDeviceOptions::New(); 39 empty_options_ = blink::mojom::WebBluetoothRequestDeviceOptions::New();
39 } 40 }
40 41
41 ~BluetoothAllowedDevicesMapTest() override {} 42 ~BluetoothAllowedDevicesTest() override {}
42 43
43 blink::mojom::WebBluetoothRequestDeviceOptionsPtr empty_options_; 44 blink::mojom::WebBluetoothRequestDeviceOptionsPtr empty_options_;
44 }; 45 };
45 46
46 } // namespace 47 } // namespace
47 48
48 TEST_F(BluetoothAllowedDevicesMapTest, UniqueOriginNotSupported) { 49 TEST_F(BluetoothAllowedDevicesTest, UniqueOriginNotSupported) {
49 BluetoothAllowedDevicesMap allowed_devices_map; 50 BluetoothAllowedDevicesMapBase allowed_devices_map;
50 51 EXPECT_DEATH_IF_SUPPORTED(
51 EXPECT_DEATH_IF_SUPPORTED(allowed_devices_map.AddDevice( 52 allowed_devices_map.GetOrCreateAllowedDevices(url::Origin()), "");
52 url::Origin(), kDeviceAddress1, empty_options_),
53 "");
54 } 53 }
55 54
56 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMap) { 55 TEST_F(BluetoothAllowedDevicesTest, AddDevice) {
57 BluetoothAllowedDevicesMap allowed_devices_map; 56 BluetoothAllowedDevices allowed_devices;
58 57
59 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice( 58 const WebBluetoothDeviceId& device_id =
60 kTestOrigin1, kDeviceAddress1, empty_options_); 59 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
61 60
62 // Test that we can retrieve the device address/id. 61 // Test that we can retrieve the device address/id.
63 EXPECT_EQ(device_id, 62 EXPECT_EQ(device_id, *allowed_devices.GetDeviceId(kDeviceAddress1));
64 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 63 EXPECT_EQ(kDeviceAddress1, allowed_devices.GetDeviceAddress(device_id));
65 EXPECT_EQ(kDeviceAddress1,
66 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id));
67 } 64 }
68 65
69 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceToMapTwice) { 66 TEST_F(BluetoothAllowedDevicesTest, AddDeviceTwice) {
70 BluetoothAllowedDevicesMap allowed_devices_map; 67 BluetoothAllowedDevices allowed_devices;
71 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( 68 const WebBluetoothDeviceId& device_id1 =
72 kTestOrigin1, kDeviceAddress1, empty_options_); 69 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
73 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( 70 const WebBluetoothDeviceId& device_id2 =
74 kTestOrigin1, kDeviceAddress1, empty_options_); 71 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
75 72
76 EXPECT_EQ(device_id1, device_id2); 73 EXPECT_EQ(device_id1, device_id2);
77 74
78 // Test that we can retrieve the device address/id. 75 // Test that we can retrieve the device address/id.
79 EXPECT_EQ(device_id1, 76 EXPECT_EQ(device_id1, *allowed_devices.GetDeviceId(kDeviceAddress1));
80 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 77 EXPECT_EQ(kDeviceAddress1, allowed_devices.GetDeviceAddress(device_id1));
81 EXPECT_EQ(kDeviceAddress1,
82 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1));
83 } 78 }
84 79
85 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromSameOriginToMap) { 80 TEST_F(BluetoothAllowedDevicesTest, AddTwoDevices) {
86 BluetoothAllowedDevicesMap allowed_devices_map; 81 BluetoothAllowedDevices allowed_devices;
87 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( 82 const WebBluetoothDeviceId& device_id1 =
88 kTestOrigin1, kDeviceAddress1, empty_options_); 83 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
89 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( 84 const WebBluetoothDeviceId& device_id2 =
90 kTestOrigin1, kDeviceAddress2, empty_options_); 85 allowed_devices.AddDevice(kDeviceAddress2, empty_options_);
91 86
92 EXPECT_NE(device_id1, device_id2); 87 EXPECT_NE(device_id1, device_id2);
93 88
94 // Test that we can retrieve the device address/id. 89 // Test that we can retrieve the device address/id.
95 EXPECT_EQ(device_id1, 90 EXPECT_EQ(device_id1, *allowed_devices.GetDeviceId(kDeviceAddress1));
96 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 91 EXPECT_EQ(device_id2, *allowed_devices.GetDeviceId(kDeviceAddress2));
97 EXPECT_EQ(device_id2,
98 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2));
99 92
100 EXPECT_EQ(kDeviceAddress1, 93 EXPECT_EQ(kDeviceAddress1, allowed_devices.GetDeviceAddress(device_id1));
101 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); 94 EXPECT_EQ(kDeviceAddress2, allowed_devices.GetDeviceAddress(device_id2));
102 EXPECT_EQ(kDeviceAddress2,
103 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2));
104 } 95 }
105 96
106 TEST_F(BluetoothAllowedDevicesMapTest, AddTwoDevicesFromTwoOriginsToMap) { 97 TEST_F(BluetoothAllowedDevicesTest, AddTwoDevicesFromTwoOriginsToMap) {
107 BluetoothAllowedDevicesMap allowed_devices_map; 98 BluetoothAllowedDevicesMapBase allowed_devices_map;
108 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( 99 content::BluetoothAllowedDevices* allowed_devices1 =
109 kTestOrigin1, kDeviceAddress1, empty_options_); 100 allowed_devices_map.GetOrCreateAllowedDevices(kTestOrigin1);
110 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( 101 content::BluetoothAllowedDevices* allowed_devices2 =
111 kTestOrigin2, kDeviceAddress2, empty_options_); 102 allowed_devices_map.GetOrCreateAllowedDevices(kTestOrigin2);
103
104 const WebBluetoothDeviceId& device_id1 =
105 allowed_devices1->AddDevice(kDeviceAddress1, empty_options_);
106 const WebBluetoothDeviceId& device_id2 =
107 allowed_devices2->AddDevice(kDeviceAddress2, empty_options_);
112 108
113 EXPECT_NE(device_id1, device_id2); 109 EXPECT_NE(device_id1, device_id2);
114 110
115 // Test that the wrong origin doesn't have access to the device. 111 // Test that the wrong origin doesn't have access to the device.
116 112 EXPECT_EQ(nullptr, allowed_devices1->GetDeviceId(kDeviceAddress2));
117 EXPECT_EQ(nullptr, 113 EXPECT_EQ(nullptr, allowed_devices2->GetDeviceId(kDeviceAddress1));
118 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2));
119 EXPECT_EQ(nullptr,
120 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1));
121 114
122 EXPECT_EQ(base::EmptyString(), 115 EXPECT_EQ(base::EmptyString(),
123 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); 116 allowed_devices1->GetDeviceAddress(device_id2));
124 EXPECT_EQ(base::EmptyString(), 117 EXPECT_EQ(base::EmptyString(),
125 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); 118 allowed_devices2->GetDeviceAddress(device_id1));
126 119
127 // Test that we can retrieve the device address/id. 120 // Test that we can retrieve the device address/id.
128 EXPECT_EQ(device_id1, 121 EXPECT_EQ(device_id1, *(allowed_devices1->GetDeviceId(kDeviceAddress1)));
129 *allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 122 EXPECT_EQ(device_id2, *(allowed_devices2->GetDeviceId(kDeviceAddress2)));
130 EXPECT_EQ(device_id2,
131 *allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress2));
132 123
133 EXPECT_EQ(kDeviceAddress1, 124 EXPECT_EQ(kDeviceAddress1, allowed_devices1->GetDeviceAddress(device_id1));
134 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id1)); 125 EXPECT_EQ(kDeviceAddress2, allowed_devices2->GetDeviceAddress(device_id2));
135 EXPECT_EQ(kDeviceAddress2,
136 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id2));
137 } 126 }
138 127
139 TEST_F(BluetoothAllowedDevicesMapTest, AddDeviceFromTwoOriginsToMap) { 128 TEST_F(BluetoothAllowedDevicesTest, AddDeviceFromTwoOriginsToMap) {
140 BluetoothAllowedDevicesMap allowed_devices_map; 129 BluetoothAllowedDevicesMapBase allowed_devices_map;
141 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( 130 content::BluetoothAllowedDevices* allowed_devices1 =
142 kTestOrigin1, kDeviceAddress1, empty_options_); 131 allowed_devices_map.GetOrCreateAllowedDevices(kTestOrigin1);
143 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( 132 content::BluetoothAllowedDevices* allowed_devices2 =
144 kTestOrigin2, kDeviceAddress1, empty_options_); 133 allowed_devices_map.GetOrCreateAllowedDevices(kTestOrigin2);
134
135 const WebBluetoothDeviceId& device_id1 =
136 allowed_devices1->AddDevice(kDeviceAddress1, empty_options_);
137 const WebBluetoothDeviceId& device_id2 =
138 allowed_devices2->AddDevice(kDeviceAddress1, empty_options_);
145 139
146 EXPECT_NE(device_id1, device_id2); 140 EXPECT_NE(device_id1, device_id2);
147 141
148 // Test that the wrong origin doesn't have access to the device. 142 // Test that the wrong origin doesn't have access to the device.
149 EXPECT_EQ(base::EmptyString(), 143 EXPECT_EQ(base::EmptyString(),
150 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); 144 allowed_devices1->GetDeviceAddress(device_id2));
151 EXPECT_EQ(base::EmptyString(), 145 EXPECT_EQ(base::EmptyString(),
152 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1)); 146 allowed_devices2->GetDeviceAddress(device_id1));
153 } 147 }
154 148
155 TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { 149 TEST_F(BluetoothAllowedDevicesTest, AddRemoveAddDevice) {
156 BluetoothAllowedDevicesMap allowed_devices_map; 150 BluetoothAllowedDevices allowed_devices;
157 const WebBluetoothDeviceId device_id_first_time = 151 const WebBluetoothDeviceId device_id_first_time =
158 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, 152 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
159 empty_options_);
160 153
161 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 154 allowed_devices.RemoveDevice(kDeviceAddress1);
162 155
163 const WebBluetoothDeviceId device_id_second_time = 156 const WebBluetoothDeviceId device_id_second_time =
164 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, 157 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
165 empty_options_);
166 158
167 EXPECT_NE(device_id_first_time, device_id_second_time); 159 EXPECT_NE(device_id_first_time, device_id_second_time);
168 } 160 }
169 161
170 TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { 162 TEST_F(BluetoothAllowedDevicesTest, RemoveDevice) {
171 BluetoothAllowedDevicesMap allowed_devices_map; 163 BluetoothAllowedDevices allowed_devices;
172 164
173 const WebBluetoothDeviceId device_id = allowed_devices_map.AddDevice( 165 const WebBluetoothDeviceId device_id =
174 kTestOrigin1, kDeviceAddress1, empty_options_); 166 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
175 167
176 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 168 allowed_devices.RemoveDevice(kDeviceAddress1);
177 169
178 EXPECT_EQ(nullptr, 170 EXPECT_EQ(nullptr, allowed_devices.GetDeviceId(kDeviceAddress1));
179 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 171 EXPECT_EQ(base::EmptyString(), allowed_devices.GetDeviceAddress(device_id));
180 EXPECT_EQ(base::EmptyString(),
181 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id));
182 } 172 }
183 173
184 TEST_F(BluetoothAllowedDevicesMapTest, NoPermissionForAnyService) { 174 TEST_F(BluetoothAllowedDevicesTest, NoPermissionForAnyService) {
185 BluetoothAllowedDevicesMap allowed_devices_map; 175 BluetoothAllowedDevices allowed_devices;
186 176
187 // Setup device. 177 // Setup device.
188 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 178 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
189 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 179 blink::mojom::WebBluetoothRequestDeviceOptions::New();
190 blink::mojom::WebBluetoothScanFilterPtr scan_filter = 180 blink::mojom::WebBluetoothScanFilterPtr scan_filter =
191 blink::mojom::WebBluetoothScanFilter::New(); 181 blink::mojom::WebBluetoothScanFilter::New();
192 182
193 scan_filter->name = kDeviceName; 183 scan_filter->name = kDeviceName;
194 options->filters.emplace(); 184 options->filters.emplace();
195 options->filters->push_back({scan_filter.Clone()}); 185 options->filters->push_back({scan_filter.Clone()});
196 186
197 // Add to map. 187 // Add to map.
198 const WebBluetoothDeviceId device_id = 188 const WebBluetoothDeviceId device_id =
199 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 189 allowed_devices.AddDevice(kDeviceAddress1, options);
200 190
201 // Try to access at least one service. 191 // Try to access at least one service.
202 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 192 EXPECT_FALSE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id));
203 kTestOrigin1, device_id)); 193 EXPECT_FALSE(
204 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 194 allowed_devices.IsAllowedToAccessService(device_id, kGlucoseUUID));
205 kTestOrigin1, device_id, kGlucoseUUID));
206 } 195 }
207 196
208 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { 197 TEST_F(BluetoothAllowedDevicesTest, AllowedServices_OneDevice) {
209 BluetoothAllowedDevicesMap allowed_devices_map; 198 BluetoothAllowedDevices allowed_devices;
210 199
211 // Setup device. 200 // Setup device.
212 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 201 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
213 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 202 blink::mojom::WebBluetoothRequestDeviceOptions::New();
214 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 = 203 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
215 blink::mojom::WebBluetoothScanFilter::New(); 204 blink::mojom::WebBluetoothScanFilter::New();
216 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 = 205 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
217 blink::mojom::WebBluetoothScanFilter::New(); 206 blink::mojom::WebBluetoothScanFilter::New();
218 207
219 scan_filter1->services.emplace(); 208 scan_filter1->services.emplace();
220 scan_filter1->services->push_back(kGlucoseUUID); 209 scan_filter1->services->push_back(kGlucoseUUID);
221 options->filters.emplace(); 210 options->filters.emplace();
222 options->filters->push_back(scan_filter1.Clone()); 211 options->filters->push_back(scan_filter1.Clone());
223 212
224 scan_filter2->services.emplace(); 213 scan_filter2->services.emplace();
225 scan_filter2->services->push_back(kHeartRateUUID); 214 scan_filter2->services->push_back(kHeartRateUUID);
226 options->filters->push_back(scan_filter2.Clone()); 215 options->filters->push_back(scan_filter2.Clone());
227 216
228 options->optional_services.push_back(kBatteryServiceUUID); 217 options->optional_services.push_back(kBatteryServiceUUID);
229 options->optional_services.push_back(kHeartRateUUID); 218 options->optional_services.push_back(kHeartRateUUID);
230 219
231 // Add to map. 220 // Add to map.
232 const WebBluetoothDeviceId device_id1 = 221 const WebBluetoothDeviceId device_id1 =
233 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 222 allowed_devices.AddDevice(kDeviceAddress1, options);
234 223
235 // Access allowed services. 224 // Access allowed services.
236 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 225 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
237 kTestOrigin1, device_id1)); 226 EXPECT_TRUE(
238 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 227 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
239 kTestOrigin1, device_id1, kGlucoseUUID)); 228 EXPECT_TRUE(
240 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 229 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
241 kTestOrigin1, device_id1, kHeartRateUUID)); 230 EXPECT_TRUE(allowed_devices.IsAllowedToAccessService(device_id1,
242 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 231 kBatteryServiceUUID));
243 kTestOrigin1, device_id1, kBatteryServiceUUID));
244 232
245 // Try to access a non-allowed service. 233 // Try to access a non-allowed service.
246 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 234 EXPECT_FALSE(
247 kTestOrigin1, device_id1, kBloodPressureUUID)); 235 allowed_devices.IsAllowedToAccessService(device_id1, kBloodPressureUUID));
248 236
249 // Try to access allowed services after removing device. 237 // Try to access allowed services after removing device.
250 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 238 allowed_devices.RemoveDevice(kDeviceAddress1);
251 239
252 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 240 EXPECT_FALSE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
253 kTestOrigin1, device_id1)); 241 EXPECT_FALSE(
254 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 242 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
255 kTestOrigin1, device_id1, kGlucoseUUID)); 243 EXPECT_FALSE(
256 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 244 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
257 kTestOrigin1, device_id1, kHeartRateUUID)); 245 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id1,
258 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 246 kBatteryServiceUUID));
259 kTestOrigin1, device_id1, kBatteryServiceUUID));
260 247
261 // Add device back. 248 // Add device back.
262 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 249 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
263 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 250 blink::mojom::WebBluetoothRequestDeviceOptions::New();
264 251
265 options2->filters.emplace(); 252 options2->filters.emplace();
266 options2->filters->push_back(scan_filter1.Clone()); 253 options2->filters->push_back(scan_filter1.Clone());
267 options2->filters->push_back(scan_filter2.Clone()); 254 options2->filters->push_back(scan_filter2.Clone());
268 255
269 const WebBluetoothDeviceId device_id2 = 256 const WebBluetoothDeviceId device_id2 =
270 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 257 allowed_devices.AddDevice(kDeviceAddress1, options2);
271 258
272 // Access allowed services. 259 // Access allowed services.
273 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 260 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id2));
274 kTestOrigin1, device_id2)); 261 EXPECT_TRUE(
275 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 262 allowed_devices.IsAllowedToAccessService(device_id2, kGlucoseUUID));
276 kTestOrigin1, device_id2, kGlucoseUUID)); 263 EXPECT_TRUE(
277 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 264 allowed_devices.IsAllowedToAccessService(device_id2, kHeartRateUUID));
278 kTestOrigin1, device_id2, kHeartRateUUID));
279 265
280 // Try to access a non-allowed service. 266 // Try to access a non-allowed service.
281 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 267 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id2,
282 kTestOrigin1, device_id2, kBatteryServiceUUID)); 268 kBatteryServiceUUID));
283 269
284 // Try to access services from old device. 270 // Try to access services from old device.
285 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 271 EXPECT_FALSE(
286 kTestOrigin1, device_id1, kGlucoseUUID)); 272 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
287 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 273 EXPECT_FALSE(
288 kTestOrigin1, device_id1, kHeartRateUUID)); 274 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
289 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 275 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id1,
290 kTestOrigin1, device_id1, kBatteryServiceUUID)); 276 kBatteryServiceUUID));
291 } 277 }
292 278
293 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) { 279 TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoDevices) {
294 BluetoothAllowedDevicesMap allowed_devices_map; 280 BluetoothAllowedDevices allowed_devices;
295 281
296 // Setup request for device #1. 282 // Setup request for device #1.
297 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 283 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
298 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 284 blink::mojom::WebBluetoothRequestDeviceOptions::New();
299 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 = 285 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
300 blink::mojom::WebBluetoothScanFilter::New(); 286 blink::mojom::WebBluetoothScanFilter::New();
301 287
302 scan_filter1->services.emplace(); 288 scan_filter1->services.emplace();
303 scan_filter1->services->push_back(kGlucoseUUID); 289 scan_filter1->services->push_back(kGlucoseUUID);
304 options1->filters.emplace(); 290 options1->filters.emplace();
305 options1->filters->push_back(std::move(scan_filter1)); 291 options1->filters->push_back(std::move(scan_filter1));
306 292
307 options1->optional_services.push_back(kHeartRateUUID); 293 options1->optional_services.push_back(kHeartRateUUID);
308 294
309 // Setup request for device #2. 295 // Setup request for device #2.
310 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 296 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
311 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 297 blink::mojom::WebBluetoothRequestDeviceOptions::New();
312 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 = 298 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
313 blink::mojom::WebBluetoothScanFilter::New(); 299 blink::mojom::WebBluetoothScanFilter::New();
314 300
315 scan_filter2->services.emplace(); 301 scan_filter2->services.emplace();
316 scan_filter2->services->push_back(kBatteryServiceUUID); 302 scan_filter2->services->push_back(kBatteryServiceUUID);
317 options2->filters.emplace(); 303 options2->filters.emplace();
318 options2->filters->push_back(std::move(scan_filter2)); 304 options2->filters->push_back(std::move(scan_filter2));
319 305
320 options2->optional_services.push_back(kBloodPressureUUID); 306 options2->optional_services.push_back(kBloodPressureUUID);
321 307
322 // Add devices to map. 308 // Add devices to map.
323 const WebBluetoothDeviceId& device_id1 = 309 const WebBluetoothDeviceId& device_id1 =
324 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 310 allowed_devices.AddDevice(kDeviceAddress1, options1);
325 const WebBluetoothDeviceId& device_id2 = 311 const WebBluetoothDeviceId& device_id2 =
326 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); 312 allowed_devices.AddDevice(kDeviceAddress2, options2);
327 313
328 // Access allowed services. 314 // Access allowed services.
329 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 315 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
330 kTestOrigin1, device_id1)); 316 EXPECT_TRUE(
331 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 317 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
332 kTestOrigin1, device_id1, kGlucoseUUID)); 318 EXPECT_TRUE(
333 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 319 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
334 kTestOrigin1, device_id1, kHeartRateUUID));
335 320
336 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 321 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id2));
337 kTestOrigin1, device_id2)); 322 EXPECT_TRUE(allowed_devices.IsAllowedToAccessService(device_id2,
338 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 323 kBatteryServiceUUID));
339 kTestOrigin1, device_id2, kBatteryServiceUUID)); 324 EXPECT_TRUE(
340 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 325 allowed_devices.IsAllowedToAccessService(device_id2, kBloodPressureUUID));
341 kTestOrigin1, device_id2, kBloodPressureUUID));
342 326
343 // Try to access non-allowed services. 327 // Try to access non-allowed services.
344 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 328 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id1,
345 kTestOrigin1, device_id1, kBatteryServiceUUID)); 329 kBatteryServiceUUID));
346 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 330 EXPECT_FALSE(
347 kTestOrigin1, device_id1, kBloodPressureUUID)); 331 allowed_devices.IsAllowedToAccessService(device_id1, kBloodPressureUUID));
348 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 332 EXPECT_FALSE(
349 kTestOrigin1, device_id1, kCyclingPowerUUID)); 333 allowed_devices.IsAllowedToAccessService(device_id1, kCyclingPowerUUID));
350 334
351 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 335 EXPECT_FALSE(
352 kTestOrigin1, device_id2, kGlucoseUUID)); 336 allowed_devices.IsAllowedToAccessService(device_id2, kGlucoseUUID));
353 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 337 EXPECT_FALSE(
354 kTestOrigin1, device_id2, kHeartRateUUID)); 338 allowed_devices.IsAllowedToAccessService(device_id2, kHeartRateUUID));
355 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 339 EXPECT_FALSE(
356 kTestOrigin1, device_id2, kCyclingPowerUUID)); 340 allowed_devices.IsAllowedToAccessService(device_id2, kCyclingPowerUUID));
357 } 341 }
358 342
359 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) { 343 TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoOriginsOneDevice) {
360 BluetoothAllowedDevicesMap allowed_devices_map; 344 BluetoothAllowedDevicesMapBase allowed_devices_map;
345 content::BluetoothAllowedDevices* allowed_devices1 =
346 allowed_devices_map.GetOrCreateAllowedDevices(kTestOrigin1);
347 content::BluetoothAllowedDevices* allowed_devices2 =
348 allowed_devices_map.GetOrCreateAllowedDevices(kTestOrigin2);
361 // Setup request #1 for device. 349 // Setup request #1 for device.
362 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 350 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
363 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 351 blink::mojom::WebBluetoothRequestDeviceOptions::New();
364 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 = 352 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
365 blink::mojom::WebBluetoothScanFilter::New(); 353 blink::mojom::WebBluetoothScanFilter::New();
366 354
367 scan_filter1->services.emplace(); 355 scan_filter1->services.emplace();
368 scan_filter1->services->push_back(kGlucoseUUID); 356 scan_filter1->services->push_back(kGlucoseUUID);
369 options1->filters.emplace(); 357 options1->filters.emplace();
370 options1->filters->push_back(std::move(scan_filter1)); 358 options1->filters->push_back(std::move(scan_filter1));
371 359
372 options1->optional_services.push_back(kHeartRateUUID); 360 options1->optional_services.push_back(kHeartRateUUID);
373 361
374 // Setup request #2 for device. 362 // Setup request #2 for device.
375 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 363 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
376 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 364 blink::mojom::WebBluetoothRequestDeviceOptions::New();
377 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 = 365 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
378 blink::mojom::WebBluetoothScanFilter::New(); 366 blink::mojom::WebBluetoothScanFilter::New();
379 367
380 scan_filter2->services.emplace(); 368 scan_filter2->services.emplace();
381 scan_filter2->services->push_back(kBatteryServiceUUID); 369 scan_filter2->services->push_back(kBatteryServiceUUID);
382 options2->filters.emplace(); 370 options2->filters.emplace();
383 options2->filters->push_back(std::move(scan_filter2)); 371 options2->filters->push_back(std::move(scan_filter2));
384 372
385 options2->optional_services.push_back(kBloodPressureUUID); 373 options2->optional_services.push_back(kBloodPressureUUID);
386 374
387 // Add devices to map. 375 // Add devices to map.
388 const WebBluetoothDeviceId& device_id1 = 376 const WebBluetoothDeviceId& device_id1 =
389 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 377 allowed_devices1->AddDevice(kDeviceAddress1, options1);
390 const WebBluetoothDeviceId& device_id2 = 378 const WebBluetoothDeviceId& device_id2 =
391 allowed_devices_map.AddDevice(kTestOrigin2, kDeviceAddress1, options2); 379 allowed_devices2->AddDevice(kDeviceAddress1, options2);
392 380
393 // Access allowed services. 381 // Access allowed services.
394 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 382 EXPECT_TRUE(allowed_devices1->IsAllowedToAccessAtLeastOneService(device_id1));
395 kTestOrigin1, device_id1)); 383 EXPECT_TRUE(
396 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 384 allowed_devices1->IsAllowedToAccessService(device_id1, kGlucoseUUID));
397 kTestOrigin1, device_id1, kGlucoseUUID)); 385 EXPECT_TRUE(
398 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 386 allowed_devices1->IsAllowedToAccessService(device_id1, kHeartRateUUID));
399 kTestOrigin1, device_id1, kHeartRateUUID));
400 387
401 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 388 EXPECT_TRUE(allowed_devices2->IsAllowedToAccessAtLeastOneService(device_id2));
402 kTestOrigin2, device_id2)); 389 EXPECT_TRUE(allowed_devices2->IsAllowedToAccessService(device_id2,
403 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 390 kBatteryServiceUUID));
404 kTestOrigin2, device_id2, kBatteryServiceUUID)); 391 EXPECT_TRUE(allowed_devices2->IsAllowedToAccessService(device_id2,
405 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 392 kBloodPressureUUID));
406 kTestOrigin2, device_id2, kBloodPressureUUID));
407 393
408 // Try to access non-allowed services. 394 // Try to access non-allowed services.
409 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 395 EXPECT_FALSE(allowed_devices1->IsAllowedToAccessService(device_id1,
410 kTestOrigin1, device_id1, kBatteryServiceUUID)); 396 kBatteryServiceUUID));
411 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 397 EXPECT_FALSE(allowed_devices1->IsAllowedToAccessService(device_id1,
412 kTestOrigin1, device_id1, kBloodPressureUUID)); 398 kBloodPressureUUID));
413 399
414 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 400 EXPECT_FALSE(
415 kTestOrigin1, device_id2)); 401 allowed_devices1->IsAllowedToAccessAtLeastOneService(device_id2));
416 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 402 EXPECT_FALSE(
417 kTestOrigin1, device_id2, kGlucoseUUID)); 403 allowed_devices1->IsAllowedToAccessService(device_id2, kGlucoseUUID));
418 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 404 EXPECT_FALSE(
419 kTestOrigin1, device_id2, kHeartRateUUID)); 405 allowed_devices1->IsAllowedToAccessService(device_id2, kHeartRateUUID));
420 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 406 EXPECT_FALSE(allowed_devices1->IsAllowedToAccessService(device_id2,
421 kTestOrigin1, device_id2, kBatteryServiceUUID)); 407 kBatteryServiceUUID));
422 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 408 EXPECT_FALSE(allowed_devices1->IsAllowedToAccessService(device_id2,
423 kTestOrigin1, device_id2, kBloodPressureUUID)); 409 kBloodPressureUUID));
424 410
425 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 411 EXPECT_FALSE(
426 kTestOrigin2, device_id2, kGlucoseUUID)); 412 allowed_devices2->IsAllowedToAccessService(device_id2, kGlucoseUUID));
427 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 413 EXPECT_FALSE(
428 kTestOrigin2, device_id2, kHeartRateUUID)); 414 allowed_devices2->IsAllowedToAccessService(device_id2, kHeartRateUUID));
429 415
430 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 416 EXPECT_FALSE(
431 kTestOrigin2, device_id1)); 417 allowed_devices2->IsAllowedToAccessAtLeastOneService(device_id1));
432 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 418 EXPECT_FALSE(
433 kTestOrigin2, device_id1, kGlucoseUUID)); 419 allowed_devices2->IsAllowedToAccessService(device_id1, kGlucoseUUID));
434 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 420 EXPECT_FALSE(
435 kTestOrigin2, device_id1, kHeartRateUUID)); 421 allowed_devices2->IsAllowedToAccessService(device_id1, kHeartRateUUID));
436 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 422 EXPECT_FALSE(allowed_devices2->IsAllowedToAccessService(device_id1,
437 kTestOrigin2, device_id1, kBatteryServiceUUID)); 423 kBatteryServiceUUID));
438 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 424 EXPECT_FALSE(allowed_devices2->IsAllowedToAccessService(device_id1,
439 kTestOrigin2, device_id1, kBloodPressureUUID)); 425 kBloodPressureUUID));
440 } 426 }
441 427
442 TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { 428 TEST_F(BluetoothAllowedDevicesTest, MergeServices) {
443 BluetoothAllowedDevicesMap allowed_devices_map; 429 BluetoothAllowedDevices allowed_devices;
444 430
445 // Setup first request. 431 // Setup first request.
446 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 432 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
447 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 433 blink::mojom::WebBluetoothRequestDeviceOptions::New();
448 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 = 434 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
449 blink::mojom::WebBluetoothScanFilter::New(); 435 blink::mojom::WebBluetoothScanFilter::New();
450 436
451 scan_filter1->services.emplace(); 437 scan_filter1->services.emplace();
452 scan_filter1->services->push_back(kGlucoseUUID); 438 scan_filter1->services->push_back(kGlucoseUUID);
453 options1->filters.emplace(); 439 options1->filters.emplace();
454 options1->filters->push_back(std::move(scan_filter1)); 440 options1->filters->push_back(std::move(scan_filter1));
455 441
456 options1->optional_services.push_back(kBatteryServiceUUID); 442 options1->optional_services.push_back(kBatteryServiceUUID);
457 443
458 // Add to map. 444 // Add to map.
459 const WebBluetoothDeviceId device_id1 = 445 const WebBluetoothDeviceId device_id1 =
460 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 446 allowed_devices.AddDevice(kDeviceAddress1, options1);
461 447
462 // Setup second request. 448 // Setup second request.
463 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 449 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
464 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 450 blink::mojom::WebBluetoothRequestDeviceOptions::New();
465 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 = 451 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
466 blink::mojom::WebBluetoothScanFilter::New(); 452 blink::mojom::WebBluetoothScanFilter::New();
467 453
468 scan_filter2->services.emplace(); 454 scan_filter2->services.emplace();
469 scan_filter2->services->push_back(kHeartRateUUID); 455 scan_filter2->services->push_back(kHeartRateUUID);
470 options2->filters.emplace(); 456 options2->filters.emplace();
471 options2->filters->push_back(std::move(scan_filter2)); 457 options2->filters->push_back(std::move(scan_filter2));
472 458
473 options2->optional_services.push_back(kBloodPressureUUID); 459 options2->optional_services.push_back(kBloodPressureUUID);
474 460
475 // Add to map again. 461 // Add to map again.
476 const WebBluetoothDeviceId device_id2 = 462 const WebBluetoothDeviceId device_id2 =
477 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 463 allowed_devices.AddDevice(kDeviceAddress1, options2);
478 464
479 EXPECT_EQ(device_id1, device_id2); 465 EXPECT_EQ(device_id1, device_id2);
480 466
481 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 467 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
482 kTestOrigin1, device_id1)); 468 EXPECT_TRUE(
483 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 469 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
484 kTestOrigin1, device_id1, kGlucoseUUID)); 470 EXPECT_TRUE(allowed_devices.IsAllowedToAccessService(device_id1,
485 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 471 kBatteryServiceUUID));
486 kTestOrigin1, device_id1, kBatteryServiceUUID)); 472 EXPECT_TRUE(
487 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 473 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
488 kTestOrigin1, device_id1, kHeartRateUUID)); 474 EXPECT_TRUE(
489 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 475 allowed_devices.IsAllowedToAccessService(device_id1, kBloodPressureUUID));
490 kTestOrigin1, device_id1, kBloodPressureUUID));
491 } 476 }
492 477
493 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { 478 TEST_F(BluetoothAllowedDevicesTest, CorrectIdFormat) {
494 BluetoothAllowedDevicesMap allowed_devices_map; 479 BluetoothAllowedDevices allowed_devices;
495 480
496 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice( 481 const WebBluetoothDeviceId& device_id =
497 kTestOrigin1, kDeviceAddress1, empty_options_); 482 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
498 483
499 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str())); 484 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str()));
500 } 485 }
501 486
502 TEST_F(BluetoothAllowedDevicesMapTest, NoFilterServices) { 487 TEST_F(BluetoothAllowedDevicesTest, NoFilterServices) {
503 BluetoothAllowedDevicesMap allowed_devices_map; 488 BluetoothAllowedDevices allowed_devices;
504 489
505 // Setup request. 490 // Setup request.
506 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 491 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
507 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 492 blink::mojom::WebBluetoothRequestDeviceOptions::New();
508 blink::mojom::WebBluetoothScanFilterPtr scan_filter = 493 blink::mojom::WebBluetoothScanFilterPtr scan_filter =
509 blink::mojom::WebBluetoothScanFilter::New(); 494 blink::mojom::WebBluetoothScanFilter::New();
510 495
511 options->filters.emplace(); 496 options->filters.emplace();
512 options->filters->push_back(std::move(scan_filter)); 497 options->filters->push_back(std::move(scan_filter));
513 498
514 // Add to map. 499 // Add to map.
515 const WebBluetoothDeviceId device_id = 500 const WebBluetoothDeviceId device_id =
516 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 501 allowed_devices.AddDevice(kDeviceAddress1, options);
517 502
518 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 503 EXPECT_FALSE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id));
519 kTestOrigin1, device_id));
520 } 504 }
521 505
522 } // namespace content 506 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698