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

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

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

Powered by Google App Engine
This is Rietveld 408576698