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

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

Issue 2658473002: Refactor BluetoothAllowedDevicesMap (Closed)
Patch Set: cleaned up layout 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/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.
114 EXPECT_EQ(nullptr, allowed_devices1.GetDeviceId(kDeviceAddress2));
115 EXPECT_EQ(nullptr, allowed_devices2.GetDeviceId(kDeviceAddress1));
116 116
117 EXPECT_EQ(nullptr, 117 EXPECT_EQ(base::EmptyString(), allowed_devices1.GetDeviceAddress(device_id2));
118 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress2)); 118 EXPECT_EQ(base::EmptyString(), allowed_devices2.GetDeviceAddress(device_id1));
119 EXPECT_EQ(nullptr,
120 allowed_devices_map.GetDeviceId(kTestOrigin2, kDeviceAddress1));
121
122 EXPECT_EQ(base::EmptyString(),
123 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2));
124 EXPECT_EQ(base::EmptyString(),
125 allowed_devices_map.GetDeviceAddress(kTestOrigin2, 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 scoped_refptr<BluetoothAllowedDevicesMap> allowed_devices_map =
141 const WebBluetoothDeviceId& device_id1 = allowed_devices_map.AddDevice( 130 new BluetoothAllowedDevicesMap();
142 kTestOrigin1, kDeviceAddress1, empty_options_); 131 content::BluetoothAllowedDevices& allowed_devices1 =
143 const WebBluetoothDeviceId& device_id2 = allowed_devices_map.AddDevice( 132 allowed_devices_map->GetOrCreateAllowedDevices(kTestOrigin1);
144 kTestOrigin2, kDeviceAddress1, empty_options_); 133 content::BluetoothAllowedDevices& allowed_devices2 =
134 allowed_devices_map->GetOrCreateAllowedDevices(kTestOrigin2);
135
136 const WebBluetoothDeviceId& device_id1 =
137 allowed_devices1.AddDevice(kDeviceAddress1, empty_options_);
138 const WebBluetoothDeviceId& device_id2 =
139 allowed_devices2.AddDevice(kDeviceAddress1, empty_options_);
145 140
146 EXPECT_NE(device_id1, device_id2); 141 EXPECT_NE(device_id1, device_id2);
147 142
148 // Test that the wrong origin doesn't have access to the device. 143 // Test that the wrong origin doesn't have access to the device.
149 EXPECT_EQ(base::EmptyString(), 144 EXPECT_EQ(base::EmptyString(), allowed_devices1.GetDeviceAddress(device_id2));
150 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id2)); 145 EXPECT_EQ(base::EmptyString(), allowed_devices2.GetDeviceAddress(device_id1));
151 EXPECT_EQ(base::EmptyString(),
152 allowed_devices_map.GetDeviceAddress(kTestOrigin2, device_id1));
153 } 146 }
154 147
155 TEST_F(BluetoothAllowedDevicesMapTest, AddRemoveAddDeviceToMap) { 148 TEST_F(BluetoothAllowedDevicesTest, AddRemoveAddDevice) {
156 BluetoothAllowedDevicesMap allowed_devices_map; 149 BluetoothAllowedDevices allowed_devices;
157 const WebBluetoothDeviceId device_id_first_time = 150 const WebBluetoothDeviceId device_id_first_time =
158 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, 151 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
159 empty_options_);
160 152
161 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 153 allowed_devices.RemoveDevice(kDeviceAddress1);
162 154
163 const WebBluetoothDeviceId device_id_second_time = 155 const WebBluetoothDeviceId device_id_second_time =
164 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, 156 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
165 empty_options_);
166 157
167 EXPECT_NE(device_id_first_time, device_id_second_time); 158 EXPECT_NE(device_id_first_time, device_id_second_time);
168 } 159 }
169 160
170 TEST_F(BluetoothAllowedDevicesMapTest, RemoveDeviceFromMap) { 161 TEST_F(BluetoothAllowedDevicesTest, RemoveDevice) {
171 BluetoothAllowedDevicesMap allowed_devices_map; 162 BluetoothAllowedDevices allowed_devices;
172 163
173 const WebBluetoothDeviceId device_id = allowed_devices_map.AddDevice( 164 const WebBluetoothDeviceId device_id =
174 kTestOrigin1, kDeviceAddress1, empty_options_); 165 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
175 166
176 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 167 allowed_devices.RemoveDevice(kDeviceAddress1);
177 168
178 EXPECT_EQ(nullptr, 169 EXPECT_EQ(nullptr, allowed_devices.GetDeviceId(kDeviceAddress1));
179 allowed_devices_map.GetDeviceId(kTestOrigin1, kDeviceAddress1)); 170 EXPECT_EQ(base::EmptyString(), allowed_devices.GetDeviceAddress(device_id));
180 EXPECT_EQ(base::EmptyString(),
181 allowed_devices_map.GetDeviceAddress(kTestOrigin1, device_id));
182 } 171 }
183 172
184 TEST_F(BluetoothAllowedDevicesMapTest, NoPermissionForAnyService) { 173 TEST_F(BluetoothAllowedDevicesTest, NoPermissionForAnyService) {
185 BluetoothAllowedDevicesMap allowed_devices_map; 174 BluetoothAllowedDevices allowed_devices;
186 175
187 // Setup device. 176 // Setup device.
188 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 177 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
189 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 178 blink::mojom::WebBluetoothRequestDeviceOptions::New();
190 blink::mojom::WebBluetoothScanFilterPtr scan_filter = 179 blink::mojom::WebBluetoothScanFilterPtr scan_filter =
191 blink::mojom::WebBluetoothScanFilter::New(); 180 blink::mojom::WebBluetoothScanFilter::New();
192 181
193 scan_filter->name = kDeviceName; 182 scan_filter->name = kDeviceName;
194 options->filters.emplace(); 183 options->filters.emplace();
195 options->filters->push_back({scan_filter.Clone()}); 184 options->filters->push_back({scan_filter.Clone()});
196 185
197 // Add to map. 186 // Add to map.
198 const WebBluetoothDeviceId device_id = 187 const WebBluetoothDeviceId device_id =
199 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 188 allowed_devices.AddDevice(kDeviceAddress1, options);
200 189
201 // Try to access at least one service. 190 // Try to access at least one service.
202 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 191 EXPECT_FALSE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id));
203 kTestOrigin1, device_id)); 192 EXPECT_FALSE(
204 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 193 allowed_devices.IsAllowedToAccessService(device_id, kGlucoseUUID));
205 kTestOrigin1, device_id, kGlucoseUUID));
206 } 194 }
207 195
208 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginOneDevice) { 196 TEST_F(BluetoothAllowedDevicesTest, AllowedServices_OneDevice) {
209 BluetoothAllowedDevicesMap allowed_devices_map; 197 BluetoothAllowedDevices allowed_devices;
210 198
211 // Setup device. 199 // Setup device.
212 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 200 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
213 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 201 blink::mojom::WebBluetoothRequestDeviceOptions::New();
214 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 = 202 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
215 blink::mojom::WebBluetoothScanFilter::New(); 203 blink::mojom::WebBluetoothScanFilter::New();
216 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 = 204 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
217 blink::mojom::WebBluetoothScanFilter::New(); 205 blink::mojom::WebBluetoothScanFilter::New();
218 206
219 scan_filter1->services.emplace(); 207 scan_filter1->services.emplace();
220 scan_filter1->services->push_back(kGlucoseUUID); 208 scan_filter1->services->push_back(kGlucoseUUID);
221 options->filters.emplace(); 209 options->filters.emplace();
222 options->filters->push_back(scan_filter1.Clone()); 210 options->filters->push_back(scan_filter1.Clone());
223 211
224 scan_filter2->services.emplace(); 212 scan_filter2->services.emplace();
225 scan_filter2->services->push_back(kHeartRateUUID); 213 scan_filter2->services->push_back(kHeartRateUUID);
226 options->filters->push_back(scan_filter2.Clone()); 214 options->filters->push_back(scan_filter2.Clone());
227 215
228 options->optional_services.push_back(kBatteryServiceUUID); 216 options->optional_services.push_back(kBatteryServiceUUID);
229 options->optional_services.push_back(kHeartRateUUID); 217 options->optional_services.push_back(kHeartRateUUID);
230 218
231 // Add to map. 219 // Add to map.
232 const WebBluetoothDeviceId device_id1 = 220 const WebBluetoothDeviceId device_id1 =
233 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 221 allowed_devices.AddDevice(kDeviceAddress1, options);
234 222
235 // Access allowed services. 223 // Access allowed services.
236 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 224 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
237 kTestOrigin1, device_id1)); 225 EXPECT_TRUE(
238 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 226 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
239 kTestOrigin1, device_id1, kGlucoseUUID)); 227 EXPECT_TRUE(
240 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 228 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
241 kTestOrigin1, device_id1, kHeartRateUUID)); 229 EXPECT_TRUE(allowed_devices.IsAllowedToAccessService(device_id1,
242 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 230 kBatteryServiceUUID));
243 kTestOrigin1, device_id1, kBatteryServiceUUID));
244 231
245 // Try to access a non-allowed service. 232 // Try to access a non-allowed service.
246 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 233 EXPECT_FALSE(
247 kTestOrigin1, device_id1, kBloodPressureUUID)); 234 allowed_devices.IsAllowedToAccessService(device_id1, kBloodPressureUUID));
248 235
249 // Try to access allowed services after removing device. 236 // Try to access allowed services after removing device.
250 allowed_devices_map.RemoveDevice(kTestOrigin1, kDeviceAddress1); 237 allowed_devices.RemoveDevice(kDeviceAddress1);
251 238
252 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 239 EXPECT_FALSE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
253 kTestOrigin1, device_id1)); 240 EXPECT_FALSE(
254 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 241 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
255 kTestOrigin1, device_id1, kGlucoseUUID)); 242 EXPECT_FALSE(
256 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 243 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
257 kTestOrigin1, device_id1, kHeartRateUUID)); 244 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id1,
258 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 245 kBatteryServiceUUID));
259 kTestOrigin1, device_id1, kBatteryServiceUUID));
260 246
261 // Add device back. 247 // Add device back.
262 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 248 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
263 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 249 blink::mojom::WebBluetoothRequestDeviceOptions::New();
264 250
265 options2->filters.emplace(); 251 options2->filters.emplace();
266 options2->filters->push_back(scan_filter1.Clone()); 252 options2->filters->push_back(scan_filter1.Clone());
267 options2->filters->push_back(scan_filter2.Clone()); 253 options2->filters->push_back(scan_filter2.Clone());
268 254
269 const WebBluetoothDeviceId device_id2 = 255 const WebBluetoothDeviceId device_id2 =
270 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 256 allowed_devices.AddDevice(kDeviceAddress1, options2);
271 257
272 // Access allowed services. 258 // Access allowed services.
273 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 259 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id2));
274 kTestOrigin1, device_id2)); 260 EXPECT_TRUE(
275 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 261 allowed_devices.IsAllowedToAccessService(device_id2, kGlucoseUUID));
276 kTestOrigin1, device_id2, kGlucoseUUID)); 262 EXPECT_TRUE(
277 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 263 allowed_devices.IsAllowedToAccessService(device_id2, kHeartRateUUID));
278 kTestOrigin1, device_id2, kHeartRateUUID));
279 264
280 // Try to access a non-allowed service. 265 // Try to access a non-allowed service.
281 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 266 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id2,
282 kTestOrigin1, device_id2, kBatteryServiceUUID)); 267 kBatteryServiceUUID));
283 268
284 // Try to access services from old device. 269 // Try to access services from old device.
285 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 270 EXPECT_FALSE(
286 kTestOrigin1, device_id1, kGlucoseUUID)); 271 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
287 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 272 EXPECT_FALSE(
288 kTestOrigin1, device_id1, kHeartRateUUID)); 273 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
289 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 274 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id1,
290 kTestOrigin1, device_id1, kBatteryServiceUUID)); 275 kBatteryServiceUUID));
291 } 276 }
292 277
293 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_OneOriginTwoDevices) { 278 TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoDevices) {
294 BluetoothAllowedDevicesMap allowed_devices_map; 279 BluetoothAllowedDevices allowed_devices;
295 280
296 // Setup request for device #1. 281 // Setup request for device #1.
297 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 282 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
298 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 283 blink::mojom::WebBluetoothRequestDeviceOptions::New();
299 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 = 284 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
300 blink::mojom::WebBluetoothScanFilter::New(); 285 blink::mojom::WebBluetoothScanFilter::New();
301 286
302 scan_filter1->services.emplace(); 287 scan_filter1->services.emplace();
303 scan_filter1->services->push_back(kGlucoseUUID); 288 scan_filter1->services->push_back(kGlucoseUUID);
304 options1->filters.emplace(); 289 options1->filters.emplace();
305 options1->filters->push_back(std::move(scan_filter1)); 290 options1->filters->push_back(std::move(scan_filter1));
306 291
307 options1->optional_services.push_back(kHeartRateUUID); 292 options1->optional_services.push_back(kHeartRateUUID);
308 293
309 // Setup request for device #2. 294 // Setup request for device #2.
310 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 295 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
311 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 296 blink::mojom::WebBluetoothRequestDeviceOptions::New();
312 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 = 297 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
313 blink::mojom::WebBluetoothScanFilter::New(); 298 blink::mojom::WebBluetoothScanFilter::New();
314 299
315 scan_filter2->services.emplace(); 300 scan_filter2->services.emplace();
316 scan_filter2->services->push_back(kBatteryServiceUUID); 301 scan_filter2->services->push_back(kBatteryServiceUUID);
317 options2->filters.emplace(); 302 options2->filters.emplace();
318 options2->filters->push_back(std::move(scan_filter2)); 303 options2->filters->push_back(std::move(scan_filter2));
319 304
320 options2->optional_services.push_back(kBloodPressureUUID); 305 options2->optional_services.push_back(kBloodPressureUUID);
321 306
322 // Add devices to map. 307 // Add devices to map.
323 const WebBluetoothDeviceId& device_id1 = 308 const WebBluetoothDeviceId& device_id1 =
324 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 309 allowed_devices.AddDevice(kDeviceAddress1, options1);
325 const WebBluetoothDeviceId& device_id2 = 310 const WebBluetoothDeviceId& device_id2 =
326 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress2, options2); 311 allowed_devices.AddDevice(kDeviceAddress2, options2);
327 312
328 // Access allowed services. 313 // Access allowed services.
329 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 314 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
330 kTestOrigin1, device_id1)); 315 EXPECT_TRUE(
331 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 316 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
332 kTestOrigin1, device_id1, kGlucoseUUID)); 317 EXPECT_TRUE(
333 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 318 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
334 kTestOrigin1, device_id1, kHeartRateUUID));
335 319
336 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 320 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id2));
337 kTestOrigin1, device_id2)); 321 EXPECT_TRUE(allowed_devices.IsAllowedToAccessService(device_id2,
338 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 322 kBatteryServiceUUID));
339 kTestOrigin1, device_id2, kBatteryServiceUUID)); 323 EXPECT_TRUE(
340 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 324 allowed_devices.IsAllowedToAccessService(device_id2, kBloodPressureUUID));
341 kTestOrigin1, device_id2, kBloodPressureUUID));
342 325
343 // Try to access non-allowed services. 326 // Try to access non-allowed services.
344 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 327 EXPECT_FALSE(allowed_devices.IsAllowedToAccessService(device_id1,
345 kTestOrigin1, device_id1, kBatteryServiceUUID)); 328 kBatteryServiceUUID));
346 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 329 EXPECT_FALSE(
347 kTestOrigin1, device_id1, kBloodPressureUUID)); 330 allowed_devices.IsAllowedToAccessService(device_id1, kBloodPressureUUID));
348 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 331 EXPECT_FALSE(
349 kTestOrigin1, device_id1, kCyclingPowerUUID)); 332 allowed_devices.IsAllowedToAccessService(device_id1, kCyclingPowerUUID));
350 333
351 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 334 EXPECT_FALSE(
352 kTestOrigin1, device_id2, kGlucoseUUID)); 335 allowed_devices.IsAllowedToAccessService(device_id2, kGlucoseUUID));
353 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 336 EXPECT_FALSE(
354 kTestOrigin1, device_id2, kHeartRateUUID)); 337 allowed_devices.IsAllowedToAccessService(device_id2, kHeartRateUUID));
355 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 338 EXPECT_FALSE(
356 kTestOrigin1, device_id2, kCyclingPowerUUID)); 339 allowed_devices.IsAllowedToAccessService(device_id2, kCyclingPowerUUID));
357 } 340 }
358 341
359 TEST_F(BluetoothAllowedDevicesMapTest, AllowedServices_TwoOriginsOneDevice) { 342 TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoOriginsOneDevice) {
360 BluetoothAllowedDevicesMap allowed_devices_map; 343 scoped_refptr<BluetoothAllowedDevicesMap> allowed_devices_map =
344 new BluetoothAllowedDevicesMap();
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(allowed_devices1.IsAllowedToAccessAtLeastOneService(device_id2));
415 kTestOrigin1, device_id2)); 401 EXPECT_FALSE(
416 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 402 allowed_devices1.IsAllowedToAccessService(device_id2, kGlucoseUUID));
417 kTestOrigin1, device_id2, kGlucoseUUID)); 403 EXPECT_FALSE(
418 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 404 allowed_devices1.IsAllowedToAccessService(device_id2, kHeartRateUUID));
419 kTestOrigin1, device_id2, kHeartRateUUID)); 405 EXPECT_FALSE(allowed_devices1.IsAllowedToAccessService(device_id2,
420 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 406 kBatteryServiceUUID));
421 kTestOrigin1, device_id2, kBatteryServiceUUID)); 407 EXPECT_FALSE(allowed_devices1.IsAllowedToAccessService(device_id2,
422 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 408 kBloodPressureUUID));
423 kTestOrigin1, device_id2, kBloodPressureUUID));
424 409
425 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 410 EXPECT_FALSE(
426 kTestOrigin2, device_id2, kGlucoseUUID)); 411 allowed_devices2.IsAllowedToAccessService(device_id2, kGlucoseUUID));
427 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 412 EXPECT_FALSE(
428 kTestOrigin2, device_id2, kHeartRateUUID)); 413 allowed_devices2.IsAllowedToAccessService(device_id2, kHeartRateUUID));
429 414
430 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 415 EXPECT_FALSE(allowed_devices2.IsAllowedToAccessAtLeastOneService(device_id1));
431 kTestOrigin2, device_id1)); 416 EXPECT_FALSE(
432 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 417 allowed_devices2.IsAllowedToAccessService(device_id1, kGlucoseUUID));
433 kTestOrigin2, device_id1, kGlucoseUUID)); 418 EXPECT_FALSE(
434 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 419 allowed_devices2.IsAllowedToAccessService(device_id1, kHeartRateUUID));
435 kTestOrigin2, device_id1, kHeartRateUUID)); 420 EXPECT_FALSE(allowed_devices2.IsAllowedToAccessService(device_id1,
436 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 421 kBatteryServiceUUID));
437 kTestOrigin2, device_id1, kBatteryServiceUUID)); 422 EXPECT_FALSE(allowed_devices2.IsAllowedToAccessService(device_id1,
438 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessService( 423 kBloodPressureUUID));
439 kTestOrigin2, device_id1, kBloodPressureUUID));
440 } 424 }
441 425
442 TEST_F(BluetoothAllowedDevicesMapTest, MergeServices) { 426 TEST_F(BluetoothAllowedDevicesTest, MergeServices) {
443 BluetoothAllowedDevicesMap allowed_devices_map; 427 BluetoothAllowedDevices allowed_devices;
444 428
445 // Setup first request. 429 // Setup first request.
446 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 = 430 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options1 =
447 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 431 blink::mojom::WebBluetoothRequestDeviceOptions::New();
448 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 = 432 blink::mojom::WebBluetoothScanFilterPtr scan_filter1 =
449 blink::mojom::WebBluetoothScanFilter::New(); 433 blink::mojom::WebBluetoothScanFilter::New();
450 434
451 scan_filter1->services.emplace(); 435 scan_filter1->services.emplace();
452 scan_filter1->services->push_back(kGlucoseUUID); 436 scan_filter1->services->push_back(kGlucoseUUID);
453 options1->filters.emplace(); 437 options1->filters.emplace();
454 options1->filters->push_back(std::move(scan_filter1)); 438 options1->filters->push_back(std::move(scan_filter1));
455 439
456 options1->optional_services.push_back(kBatteryServiceUUID); 440 options1->optional_services.push_back(kBatteryServiceUUID);
457 441
458 // Add to map. 442 // Add to map.
459 const WebBluetoothDeviceId device_id1 = 443 const WebBluetoothDeviceId device_id1 =
460 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options1); 444 allowed_devices.AddDevice(kDeviceAddress1, options1);
461 445
462 // Setup second request. 446 // Setup second request.
463 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 = 447 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options2 =
464 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 448 blink::mojom::WebBluetoothRequestDeviceOptions::New();
465 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 = 449 blink::mojom::WebBluetoothScanFilterPtr scan_filter2 =
466 blink::mojom::WebBluetoothScanFilter::New(); 450 blink::mojom::WebBluetoothScanFilter::New();
467 451
468 scan_filter2->services.emplace(); 452 scan_filter2->services.emplace();
469 scan_filter2->services->push_back(kHeartRateUUID); 453 scan_filter2->services->push_back(kHeartRateUUID);
470 options2->filters.emplace(); 454 options2->filters.emplace();
471 options2->filters->push_back(std::move(scan_filter2)); 455 options2->filters->push_back(std::move(scan_filter2));
472 456
473 options2->optional_services.push_back(kBloodPressureUUID); 457 options2->optional_services.push_back(kBloodPressureUUID);
474 458
475 // Add to map again. 459 // Add to map again.
476 const WebBluetoothDeviceId device_id2 = 460 const WebBluetoothDeviceId device_id2 =
477 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options2); 461 allowed_devices.AddDevice(kDeviceAddress1, options2);
478 462
479 EXPECT_EQ(device_id1, device_id2); 463 EXPECT_EQ(device_id1, device_id2);
480 464
481 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 465 EXPECT_TRUE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id1));
482 kTestOrigin1, device_id1)); 466 EXPECT_TRUE(
483 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 467 allowed_devices.IsAllowedToAccessService(device_id1, kGlucoseUUID));
484 kTestOrigin1, device_id1, kGlucoseUUID)); 468 EXPECT_TRUE(allowed_devices.IsAllowedToAccessService(device_id1,
485 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 469 kBatteryServiceUUID));
486 kTestOrigin1, device_id1, kBatteryServiceUUID)); 470 EXPECT_TRUE(
487 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 471 allowed_devices.IsAllowedToAccessService(device_id1, kHeartRateUUID));
488 kTestOrigin1, device_id1, kHeartRateUUID)); 472 EXPECT_TRUE(
489 EXPECT_TRUE(allowed_devices_map.IsOriginAllowedToAccessService( 473 allowed_devices.IsAllowedToAccessService(device_id1, kBloodPressureUUID));
490 kTestOrigin1, device_id1, kBloodPressureUUID));
491 } 474 }
492 475
493 TEST_F(BluetoothAllowedDevicesMapTest, CorrectIdFormat) { 476 TEST_F(BluetoothAllowedDevicesTest, CorrectIdFormat) {
494 BluetoothAllowedDevicesMap allowed_devices_map; 477 BluetoothAllowedDevices allowed_devices;
495 478
496 const WebBluetoothDeviceId& device_id = allowed_devices_map.AddDevice( 479 const WebBluetoothDeviceId& device_id =
497 kTestOrigin1, kDeviceAddress1, empty_options_); 480 allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
498 481
499 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str())); 482 EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str()));
500 } 483 }
501 484
502 TEST_F(BluetoothAllowedDevicesMapTest, NoFilterServices) { 485 TEST_F(BluetoothAllowedDevicesTest, NoFilterServices) {
503 BluetoothAllowedDevicesMap allowed_devices_map; 486 BluetoothAllowedDevices allowed_devices;
504 487
505 // Setup request. 488 // Setup request.
506 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options = 489 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options =
507 blink::mojom::WebBluetoothRequestDeviceOptions::New(); 490 blink::mojom::WebBluetoothRequestDeviceOptions::New();
508 blink::mojom::WebBluetoothScanFilterPtr scan_filter = 491 blink::mojom::WebBluetoothScanFilterPtr scan_filter =
509 blink::mojom::WebBluetoothScanFilter::New(); 492 blink::mojom::WebBluetoothScanFilter::New();
510 493
511 options->filters.emplace(); 494 options->filters.emplace();
512 options->filters->push_back(std::move(scan_filter)); 495 options->filters->push_back(std::move(scan_filter));
513 496
514 // Add to map. 497 // Add to map.
515 const WebBluetoothDeviceId device_id = 498 const WebBluetoothDeviceId device_id =
516 allowed_devices_map.AddDevice(kTestOrigin1, kDeviceAddress1, options); 499 allowed_devices.AddDevice(kDeviceAddress1, options);
517 500
518 EXPECT_FALSE(allowed_devices_map.IsOriginAllowedToAccessAtLeastOneService( 501 EXPECT_FALSE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id));
519 kTestOrigin1, device_id));
520 } 502 }
521 503
522 } // namespace content 504 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698