OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" | 5 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" | 9 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" |
10 #include "content/test/test_render_view_host.h" | 10 #include "content/test/test_render_view_host.h" |
11 #include "content/test/test_web_contents.h" | 11 #include "content/test/test_web_contents.h" |
12 #include "device/bluetooth/bluetooth_gatt_connection.h" | 12 #include "device/bluetooth/bluetooth_gatt_connection.h" |
13 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 13 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
14 #include "device/bluetooth/test/mock_bluetooth_device.h" | 14 #include "device/bluetooth/test/mock_bluetooth_device.h" |
15 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" | 15 #include "device/bluetooth/test/mock_bluetooth_gatt_connection.h" |
| 16 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 typedef testing::NiceMock<device::MockBluetoothAdapter> | 22 typedef testing::NiceMock<device::MockBluetoothAdapter> |
22 NiceMockBluetoothAdapter; | 23 NiceMockBluetoothAdapter; |
23 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice; | 24 typedef testing::NiceMock<device::MockBluetoothDevice> NiceMockBluetoothDevice; |
24 typedef testing::NiceMock<device::MockBluetoothGattConnection> | 25 typedef testing::NiceMock<device::MockBluetoothGattConnection> |
25 NiceMockBluetoothGattConnection; | 26 NiceMockBluetoothGattConnection; |
26 | 27 |
27 using testing::Return; | 28 using testing::Return; |
28 using testing::StrEq; | 29 using testing::StrEq; |
29 using testing::_; | 30 using testing::_; |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 const WebBluetoothDeviceId kDeviceId0("000000000000000000000A=="); | 34 const WebBluetoothDeviceId kDeviceId0("000000000000000000000A=="); |
34 constexpr char kDeviceAddress0[] = "0"; | 35 constexpr char kDeviceAddress0[] = "0"; |
35 constexpr char kDeviceName0[] = "Device0"; | 36 constexpr char kDeviceName0[] = "Device0"; |
36 | 37 |
37 const WebBluetoothDeviceId kDeviceId1("111111111111111111111A=="); | 38 const WebBluetoothDeviceId kDeviceId1("111111111111111111111A=="); |
38 constexpr char kDeviceAddress1[] = "1"; | 39 constexpr char kDeviceAddress1[] = "1"; |
39 constexpr char kDeviceName1[] = "Device1"; | 40 constexpr char kDeviceName1[] = "Device1"; |
40 | 41 |
| 42 blink::mojom::WebBluetoothServerClientAssociatedPtr |
| 43 CreateWebBluetoothServerClientAssociatedPtr() { |
| 44 blink::mojom::WebBluetoothServerClientAssociatedPtr client; |
| 45 mojo::GetIsolatedProxy(&client); |
| 46 return client; |
| 47 } |
| 48 |
41 } // namespace | 49 } // namespace |
42 | 50 |
43 class FrameConnectedBluetoothDevicesTest | 51 class FrameConnectedBluetoothDevicesTest |
44 : public RenderViewHostImplTestHarness { | 52 : public RenderViewHostImplTestHarness { |
45 public: | 53 public: |
46 FrameConnectedBluetoothDevicesTest() | 54 FrameConnectedBluetoothDevicesTest() |
47 : adapter_(new NiceMockBluetoothAdapter()), | 55 : adapter_(new NiceMockBluetoothAdapter()), |
48 device0_(adapter_.get(), | 56 device0_(adapter_.get(), |
49 0 /* class */, | 57 0 /* class */, |
50 kDeviceName0, | 58 kDeviceName0, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 FrameConnectedBluetoothDevices* map1_; | 123 FrameConnectedBluetoothDevices* map1_; |
116 WebBluetoothServiceImpl* service1_; | 124 WebBluetoothServiceImpl* service1_; |
117 | 125 |
118 private: | 126 private: |
119 scoped_refptr<NiceMockBluetoothAdapter> adapter_; | 127 scoped_refptr<NiceMockBluetoothAdapter> adapter_; |
120 NiceMockBluetoothDevice device0_; | 128 NiceMockBluetoothDevice device0_; |
121 NiceMockBluetoothDevice device1_; | 129 NiceMockBluetoothDevice device1_; |
122 }; | 130 }; |
123 | 131 |
124 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Once) { | 132 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Once) { |
125 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 133 auto client = CreateWebBluetoothServerClientAssociatedPtr(); |
| 134 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client)); |
126 | 135 |
127 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 136 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
128 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 137 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
129 } | 138 } |
130 | 139 |
131 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Twice) { | 140 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Twice) { |
132 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 141 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
133 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 142 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 143 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 144 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client2)); |
134 | 145 |
135 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 146 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
136 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 147 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
137 } | 148 } |
138 | 149 |
139 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoDevices) { | 150 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoDevices) { |
140 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 151 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
141 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 152 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 153 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 154 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
142 | 155 |
143 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 156 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
144 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 157 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
145 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); | 158 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); |
146 } | 159 } |
147 | 160 |
148 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoMaps) { | 161 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoMaps) { |
149 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 162 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
150 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 163 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 164 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 165 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
151 | 166 |
152 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 167 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
153 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 168 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
154 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); | 169 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); |
155 } | 170 } |
156 | 171 |
157 TEST_F(FrameConnectedBluetoothDevicesTest, | 172 TEST_F(FrameConnectedBluetoothDevicesTest, |
158 CloseConnectionId_OneDevice_AddOnce_RemoveOnce) { | 173 CloseConnectionId_OneDevice_AddOnce_RemoveOnce) { |
159 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 174 auto client = CreateWebBluetoothServerClientAssociatedPtr(); |
| 175 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client)); |
160 | 176 |
161 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 177 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
162 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 178 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
163 | 179 |
164 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 180 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
165 | 181 |
166 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 182 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
167 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 183 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
168 } | 184 } |
169 | 185 |
170 TEST_F(FrameConnectedBluetoothDevicesTest, | 186 TEST_F(FrameConnectedBluetoothDevicesTest, |
171 CloseConnectionId_OneDevice_AddOnce_RemoveTwice) { | 187 CloseConnectionId_OneDevice_AddOnce_RemoveTwice) { |
172 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 188 auto client = CreateWebBluetoothServerClientAssociatedPtr(); |
| 189 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client)); |
173 | 190 |
174 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 191 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
175 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 192 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
176 | 193 |
177 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 194 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
178 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 195 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
179 | 196 |
180 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 197 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
181 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 198 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
182 } | 199 } |
183 | 200 |
184 TEST_F(FrameConnectedBluetoothDevicesTest, | 201 TEST_F(FrameConnectedBluetoothDevicesTest, |
185 CloseConnectionId_OneDevice_AddTwice_RemoveOnce) { | 202 CloseConnectionId_OneDevice_AddTwice_RemoveOnce) { |
186 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 203 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
187 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 204 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 205 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 206 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client2)); |
188 | 207 |
189 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 208 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
190 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 209 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
191 | 210 |
192 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 211 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
193 | 212 |
194 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 213 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
195 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 214 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
196 } | 215 } |
197 | 216 |
198 TEST_F(FrameConnectedBluetoothDevicesTest, | 217 TEST_F(FrameConnectedBluetoothDevicesTest, |
199 CloseConnectionId_OneDevice_AddTwice_RemoveTwice) { | 218 CloseConnectionId_OneDevice_AddTwice_RemoveTwice) { |
200 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 219 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
201 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 220 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 221 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 222 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client2)); |
202 | 223 |
203 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 224 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
204 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 225 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
205 | 226 |
206 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 227 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
207 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 228 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
208 | 229 |
209 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 230 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
210 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 231 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
211 } | 232 } |
212 | 233 |
213 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoDevices) { | 234 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoDevices) { |
214 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 235 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
215 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 236 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 237 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 238 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
216 | 239 |
217 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 240 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
218 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 241 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
219 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); | 242 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); |
220 | 243 |
221 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 244 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
222 | 245 |
223 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 246 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
224 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 247 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
225 | 248 |
226 map0_->CloseConnectionToDeviceWithId(kDeviceId1); | 249 map0_->CloseConnectionToDeviceWithId(kDeviceId1); |
227 | 250 |
228 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 251 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
229 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); | 252 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); |
230 } | 253 } |
231 | 254 |
232 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoMaps) { | 255 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoMaps) { |
233 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 256 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
234 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 257 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 258 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 259 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
235 | 260 |
236 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 261 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
237 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 262 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
238 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); | 263 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); |
239 | 264 |
240 map0_->CloseConnectionToDeviceWithId(kDeviceId0); | 265 map0_->CloseConnectionToDeviceWithId(kDeviceId0); |
241 | 266 |
242 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 267 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
243 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 268 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
244 | 269 |
245 map1_->CloseConnectionToDeviceWithId(kDeviceId1); | 270 map1_->CloseConnectionToDeviceWithId(kDeviceId1); |
246 | 271 |
247 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 272 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
248 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); | 273 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); |
249 } | 274 } |
250 | 275 |
251 TEST_F(FrameConnectedBluetoothDevicesTest, | 276 TEST_F(FrameConnectedBluetoothDevicesTest, |
252 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) { | 277 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) { |
253 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 278 auto client = CreateWebBluetoothServerClientAssociatedPtr(); |
| 279 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client)); |
254 | 280 |
255 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 281 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
256 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 282 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
257 | 283 |
258 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), | 284 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), |
259 kDeviceId0); | 285 kDeviceId0); |
260 | 286 |
261 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 287 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
262 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 288 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
263 } | 289 } |
264 | 290 |
265 TEST_F(FrameConnectedBluetoothDevicesTest, | 291 TEST_F(FrameConnectedBluetoothDevicesTest, |
266 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) { | 292 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) { |
267 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 293 auto client = CreateWebBluetoothServerClientAssociatedPtr(); |
| 294 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client)); |
268 | 295 |
269 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 296 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
270 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 297 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
271 | 298 |
272 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), | 299 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), |
273 kDeviceId0); | 300 kDeviceId0); |
274 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0)); | 301 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0)); |
275 | 302 |
276 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 303 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
277 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 304 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
278 } | 305 } |
279 | 306 |
280 TEST_F(FrameConnectedBluetoothDevicesTest, | 307 TEST_F(FrameConnectedBluetoothDevicesTest, |
281 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) { | 308 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) { |
282 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 309 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
283 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 310 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 311 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 312 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client2)); |
284 | 313 |
285 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 314 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
286 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 315 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
287 | 316 |
288 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), | 317 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), |
289 kDeviceId0); | 318 kDeviceId0); |
290 | 319 |
291 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 320 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
292 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 321 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
293 } | 322 } |
294 | 323 |
295 TEST_F(FrameConnectedBluetoothDevicesTest, | 324 TEST_F(FrameConnectedBluetoothDevicesTest, |
296 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) { | 325 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) { |
297 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 326 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
298 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 327 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 328 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 329 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client2)); |
299 | 330 |
300 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 331 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
301 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 332 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
302 | 333 |
303 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), | 334 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), |
304 kDeviceId0); | 335 kDeviceId0); |
305 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0)); | 336 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0)); |
306 | 337 |
307 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 338 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
308 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 339 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
309 } | 340 } |
310 | 341 |
311 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) { | 342 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) { |
312 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 343 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
313 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 344 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 345 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 346 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
314 | 347 |
315 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 348 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
316 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 349 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
317 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); | 350 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); |
318 | 351 |
319 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), | 352 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), |
320 kDeviceId0); | 353 kDeviceId0); |
321 | 354 |
322 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 355 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
323 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 356 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
324 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); | 357 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); |
325 | 358 |
326 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(), | 359 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(), |
327 kDeviceId1); | 360 kDeviceId1); |
328 | 361 |
329 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 362 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
330 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); | 363 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); |
331 } | 364 } |
332 | 365 |
333 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) { | 366 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) { |
334 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 367 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
335 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 368 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 369 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 370 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
336 | 371 |
337 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 372 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
338 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 373 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
339 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); | 374 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); |
340 | 375 |
341 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), | 376 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), |
342 kDeviceId0); | 377 kDeviceId0); |
343 | 378 |
344 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 379 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
345 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); | 380 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); |
346 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); | 381 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); |
347 | 382 |
348 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(), | 383 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(), |
349 kDeviceId1); | 384 kDeviceId1); |
350 | 385 |
351 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 386 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
352 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); | 387 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); |
353 } | 388 } |
354 | 389 |
355 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) { | 390 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) { |
356 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 391 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
357 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 392 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 393 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 394 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
358 | 395 |
359 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 396 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
360 | 397 |
361 ResetService0(); | 398 ResetService0(); |
362 | 399 |
363 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 400 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
364 } | 401 } |
365 | 402 |
366 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleMaps) { | 403 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleMaps) { |
367 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 404 auto client1 = CreateWebBluetoothServerClientAssociatedPtr(); |
368 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 405 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client1)); |
| 406 auto client2 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 407 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client2)); |
369 | 408 |
370 map1_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 409 auto client3 = CreateWebBluetoothServerClientAssociatedPtr(); |
371 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); | 410 map1_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client3)); |
| 411 auto client4 = CreateWebBluetoothServerClientAssociatedPtr(); |
| 412 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1), std::move(client4)); |
372 | 413 |
373 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 414 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
374 | 415 |
375 ResetService0(); | 416 ResetService0(); |
376 | 417 |
377 // WebContents should still be connected because of map1_. | 418 // WebContents should still be connected because of map1_. |
378 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); | 419 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); |
379 | 420 |
380 ResetService1(); | 421 ResetService1(); |
381 | 422 |
382 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); | 423 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); |
383 } | 424 } |
384 | 425 |
385 TEST_F(FrameConnectedBluetoothDevicesTest, | 426 TEST_F(FrameConnectedBluetoothDevicesTest, |
386 DestroyedByWebContentsImplDestruction) { | 427 DestroyedByWebContentsImplDestruction) { |
387 // Tests that we don't crash when FrameConnectedBluetoothDevices contains | 428 // Tests that we don't crash when FrameConnectedBluetoothDevices contains |
388 // at least one device, and it is destroyed while WebContentsImpl is being | 429 // at least one device, and it is destroyed while WebContentsImpl is being |
389 // destroyed. | 430 // destroyed. |
390 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); | 431 auto client = CreateWebBluetoothServerClientAssociatedPtr(); |
| 432 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0), std::move(client)); |
391 DeleteContents(); | 433 DeleteContents(); |
392 } | 434 } |
393 | 435 |
394 } // namespace content | 436 } // namespace content |
OLD | NEW |