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