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