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

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

Issue 2718583002: Refactor WebBluetoothServiceClient in the web_bluetooth.mojom (Closed)
Patch Set: rebase Created 3 years, 9 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 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 CreateServerClient() {
43 blink::mojom::WebBluetoothServerClientAssociatedPtr client;
44 mojo::MakeIsolatedRequest(&client);
45 return client;
46 }
47
41 } // namespace 48 } // namespace
42 49
43 class FrameConnectedBluetoothDevicesTest 50 class FrameConnectedBluetoothDevicesTest
44 : public RenderViewHostImplTestHarness { 51 : public RenderViewHostImplTestHarness {
45 public: 52 public:
46 FrameConnectedBluetoothDevicesTest() 53 FrameConnectedBluetoothDevicesTest()
47 : adapter_(new NiceMockBluetoothAdapter()), 54 : adapter_(new NiceMockBluetoothAdapter()),
48 device0_(adapter_.get(), 55 device0_(adapter_.get(),
49 0 /* class */, 56 0 /* class */,
50 kDeviceName0, 57 kDeviceName0,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 FrameConnectedBluetoothDevices* map1_; 122 FrameConnectedBluetoothDevices* map1_;
116 WebBluetoothServiceImpl* service1_; 123 WebBluetoothServiceImpl* service1_;
117 124
118 private: 125 private:
119 scoped_refptr<NiceMockBluetoothAdapter> adapter_; 126 scoped_refptr<NiceMockBluetoothAdapter> adapter_;
120 NiceMockBluetoothDevice device0_; 127 NiceMockBluetoothDevice device0_;
121 NiceMockBluetoothDevice device1_; 128 NiceMockBluetoothDevice device1_;
122 }; 129 };
123 130
124 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Once) { 131 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Once) {
125 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 132 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
133 CreateServerClient());
126 134
127 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 135 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
128 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 136 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
129 } 137 }
130 138
131 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Twice) { 139 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_Twice) {
132 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 140 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
133 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 141 CreateServerClient());
142 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
143 CreateServerClient());
134 144
135 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 145 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
136 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 146 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
137 } 147 }
138 148
139 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoDevices) { 149 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoDevices) {
140 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 150 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
141 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 151 CreateServerClient());
152 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
153 CreateServerClient());
142 154
143 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 155 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
144 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 156 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
145 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 157 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
146 } 158 }
147 159
148 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoMaps) { 160 TEST_F(FrameConnectedBluetoothDevicesTest, Insert_TwoMaps) {
149 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 161 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
150 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 162 CreateServerClient());
163 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
164 CreateServerClient());
151 165
152 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 166 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
153 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 167 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
154 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 168 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
155 } 169 }
156 170
157 TEST_F(FrameConnectedBluetoothDevicesTest, 171 TEST_F(FrameConnectedBluetoothDevicesTest,
158 CloseConnectionId_OneDevice_AddOnce_RemoveOnce) { 172 CloseConnectionId_OneDevice_AddOnce_RemoveOnce) {
159 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 173 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
174 CreateServerClient());
160 175
161 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 176 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
162 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 177 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
163 178
164 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 179 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
165 180
166 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 181 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
167 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 182 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
168 } 183 }
169 184
170 TEST_F(FrameConnectedBluetoothDevicesTest, 185 TEST_F(FrameConnectedBluetoothDevicesTest,
171 CloseConnectionId_OneDevice_AddOnce_RemoveTwice) { 186 CloseConnectionId_OneDevice_AddOnce_RemoveTwice) {
172 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 187 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
188 CreateServerClient());
173 189
174 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 190 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
175 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 191 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
176 192
177 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 193 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
178 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 194 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
179 195
180 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 196 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
181 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 197 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
182 } 198 }
183 199
184 TEST_F(FrameConnectedBluetoothDevicesTest, 200 TEST_F(FrameConnectedBluetoothDevicesTest,
185 CloseConnectionId_OneDevice_AddTwice_RemoveOnce) { 201 CloseConnectionId_OneDevice_AddTwice_RemoveOnce) {
186 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 202 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
187 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 203 CreateServerClient());
204 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
205 CreateServerClient());
188 206
189 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 207 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
190 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 208 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
191 209
192 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 210 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
193 211
194 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 212 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
195 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 213 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
196 } 214 }
197 215
198 TEST_F(FrameConnectedBluetoothDevicesTest, 216 TEST_F(FrameConnectedBluetoothDevicesTest,
199 CloseConnectionId_OneDevice_AddTwice_RemoveTwice) { 217 CloseConnectionId_OneDevice_AddTwice_RemoveTwice) {
200 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 218 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
201 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 219 CreateServerClient());
220 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
221 CreateServerClient());
202 222
203 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 223 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
204 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 224 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
205 225
206 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 226 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
207 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 227 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
208 228
209 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 229 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
210 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 230 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
211 } 231 }
212 232
213 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoDevices) { 233 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoDevices) {
214 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 234 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
215 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 235 CreateServerClient());
236 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
237 CreateServerClient());
216 238
217 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 239 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
218 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 240 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
219 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 241 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
220 242
221 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 243 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
222 244
223 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 245 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
224 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 246 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
225 247
226 map0_->CloseConnectionToDeviceWithId(kDeviceId1); 248 map0_->CloseConnectionToDeviceWithId(kDeviceId1);
227 249
228 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 250 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
229 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 251 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
230 } 252 }
231 253
232 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoMaps) { 254 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionId_TwoMaps) {
233 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 255 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
234 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 256 CreateServerClient());
257 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
258 CreateServerClient());
235 259
236 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 260 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
237 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 261 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
238 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 262 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
239 263
240 map0_->CloseConnectionToDeviceWithId(kDeviceId0); 264 map0_->CloseConnectionToDeviceWithId(kDeviceId0);
241 265
242 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 266 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
243 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 267 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
244 268
245 map1_->CloseConnectionToDeviceWithId(kDeviceId1); 269 map1_->CloseConnectionToDeviceWithId(kDeviceId1);
246 270
247 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 271 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
248 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 272 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
249 } 273 }
250 274
251 TEST_F(FrameConnectedBluetoothDevicesTest, 275 TEST_F(FrameConnectedBluetoothDevicesTest,
252 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) { 276 CloseConnectionAddress_OneDevice_AddOnce_RemoveOnce) {
253 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 277 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
278 CreateServerClient());
254 279
255 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 280 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
256 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 281 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
257 282
258 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), 283 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
259 kDeviceId0); 284 kDeviceId0);
260 285
261 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 286 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
262 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 287 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
263 } 288 }
264 289
265 TEST_F(FrameConnectedBluetoothDevicesTest, 290 TEST_F(FrameConnectedBluetoothDevicesTest,
266 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) { 291 CloseConnectionAddress_OneDevice_AddOnce_RemoveTwice) {
267 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 292 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
293 CreateServerClient());
268 294
269 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 295 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
270 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 296 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
271 297
272 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), 298 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
273 kDeviceId0); 299 kDeviceId0);
274 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0)); 300 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0));
275 301
276 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 302 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
277 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 303 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
278 } 304 }
279 305
280 TEST_F(FrameConnectedBluetoothDevicesTest, 306 TEST_F(FrameConnectedBluetoothDevicesTest,
281 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) { 307 CloseConnectionAddress_OneDevice_AddTwice_RemoveOnce) {
282 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 308 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
283 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 309 CreateServerClient());
310 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
311 CreateServerClient());
284 312
285 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 313 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
286 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 314 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
287 315
288 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), 316 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
289 kDeviceId0); 317 kDeviceId0);
290 318
291 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 319 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
292 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 320 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
293 } 321 }
294 322
295 TEST_F(FrameConnectedBluetoothDevicesTest, 323 TEST_F(FrameConnectedBluetoothDevicesTest,
296 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) { 324 CloseConnectionAddress_OneDevice_AddTwice_RemoveTwice) {
297 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 325 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
298 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 326 CreateServerClient());
327 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
328 CreateServerClient());
299 329
300 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 330 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
301 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 331 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
302 332
303 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), 333 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
304 kDeviceId0); 334 kDeviceId0);
305 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0)); 335 EXPECT_FALSE(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0));
306 336
307 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 337 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
308 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 338 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
309 } 339 }
310 340
311 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) { 341 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoDevices) {
312 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 342 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
313 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 343 CreateServerClient());
344 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
345 CreateServerClient());
314 346
315 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 347 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
316 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 348 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
317 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 349 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
318 350
319 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), 351 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
320 kDeviceId0); 352 kDeviceId0);
321 353
322 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 354 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
323 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 355 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
324 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 356 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
325 357
326 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(), 358 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(),
327 kDeviceId1); 359 kDeviceId1);
328 360
329 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 361 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
330 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1)); 362 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId1));
331 } 363 }
332 364
333 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) { 365 TEST_F(FrameConnectedBluetoothDevicesTest, CloseConnectionAddress_TwoMaps) {
334 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 366 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
335 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 367 CreateServerClient());
368 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
369 CreateServerClient());
336 370
337 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 371 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
338 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 372 EXPECT_TRUE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
339 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 373 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
340 374
341 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(), 375 EXPECT_EQ(map0_->CloseConnectionToDeviceWithAddress(kDeviceAddress0).value(),
342 kDeviceId0); 376 kDeviceId0);
343 377
344 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 378 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
345 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0)); 379 EXPECT_FALSE(map0_->IsConnectedToDeviceWithId(kDeviceId0));
346 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 380 EXPECT_TRUE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
347 381
348 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(), 382 EXPECT_EQ(map1_->CloseConnectionToDeviceWithAddress(kDeviceAddress1).value(),
349 kDeviceId1); 383 kDeviceId1);
350 384
351 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 385 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
352 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1)); 386 EXPECT_FALSE(map1_->IsConnectedToDeviceWithId(kDeviceId1));
353 } 387 }
354 388
355 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) { 389 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleDevices) {
356 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 390 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
357 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 391 CreateServerClient());
392 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
393 CreateServerClient());
358 394
359 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 395 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
360 396
361 ResetService0(); 397 ResetService0();
362 398
363 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 399 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
364 } 400 }
365 401
366 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleMaps) { 402 TEST_F(FrameConnectedBluetoothDevicesTest, Destruction_MultipleMaps) {
367 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 403 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
368 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 404 CreateServerClient());
405 map0_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
406 CreateServerClient());
369 407
370 map1_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 408 map1_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
371 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1)); 409 CreateServerClient());
410 map1_->Insert(kDeviceId1, GetConnection(kDeviceAddress1),
411 CreateServerClient());
372 412
373 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 413 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
374 414
375 ResetService0(); 415 ResetService0();
376 416
377 // WebContents should still be connected because of map1_. 417 // WebContents should still be connected because of map1_.
378 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice()); 418 EXPECT_TRUE(contents()->IsConnectedToBluetoothDevice());
379 419
380 ResetService1(); 420 ResetService1();
381 421
382 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice()); 422 EXPECT_FALSE(contents()->IsConnectedToBluetoothDevice());
383 } 423 }
384 424
385 TEST_F(FrameConnectedBluetoothDevicesTest, 425 TEST_F(FrameConnectedBluetoothDevicesTest,
386 DestroyedByWebContentsImplDestruction) { 426 DestroyedByWebContentsImplDestruction) {
387 // Tests that we don't crash when FrameConnectedBluetoothDevices contains 427 // Tests that we don't crash when FrameConnectedBluetoothDevices contains
388 // at least one device, and it is destroyed while WebContentsImpl is being 428 // at least one device, and it is destroyed while WebContentsImpl is being
389 // destroyed. 429 // destroyed.
390 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0)); 430 map0_->Insert(kDeviceId0, GetConnection(kDeviceAddress0),
431 CreateServerClient());
391 DeleteContents(); 432 DeleteContents();
392 } 433 }
393 434
394 } // namespace content 435 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/frame_connected_bluetooth_devices.cc ('k') | content/browser/bluetooth/web_bluetooth_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698