Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <iostream> | 5 #include <iostream> |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
| 8 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h" | |
| 9 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_factory.h" | |
| 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" | 10 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" |
| 9 #include "chromeos/dbus/mock_bluetooth_adapter_client.h" | 11 #include "chromeos/dbus/mock_bluetooth_adapter_client.h" |
| 10 #include "chromeos/dbus/mock_bluetooth_manager_client.h" | 12 #include "chromeos/dbus/mock_bluetooth_manager_client.h" |
| 11 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 13 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 12 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 using ::testing::_; | 17 using ::testing::_; |
| 16 using ::testing::Return; | 18 using ::testing::Return; |
| 17 using ::testing::SaveArg; | 19 using ::testing::SaveArg; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 TEST_F(BluetoothAdapterTest, DefaultAdapterNotPresent) { | 47 TEST_F(BluetoothAdapterTest, DefaultAdapterNotPresent) { |
| 46 // Create the default adapter instance; | 48 // Create the default adapter instance; |
| 47 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 49 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 48 // a callback to obtain the adapter path. | 50 // a callback to obtain the adapter path. |
| 49 BluetoothManagerClient::AdapterCallback adapter_callback; | 51 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 50 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 52 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 51 .WillOnce(SaveArg<0>(&adapter_callback)); | 53 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 52 | 54 |
| 53 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 55 scoped_refptr<BluetoothAdapter> adapter = |
| 56 BluetoothAdapterFactory::DefaultAdapter(); | |
| 54 | 57 |
| 55 // Call the adapter callback; make out it failed. | 58 // Call the adapter callback; make out it failed. |
| 56 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | 59 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. |
| 57 MockBluetoothAdapter::Observer adapter_observer; | 60 MockBluetoothAdapter::Observer adapter_observer; |
| 58 adapter->AddObserver(&adapter_observer); | 61 adapter->AddObserver(&adapter_observer); |
| 59 | 62 |
| 60 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 63 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) |
| 61 .Times(0); | 64 .Times(0); |
| 62 | 65 |
| 63 adapter_callback.Run(dbus::ObjectPath(""), false); | 66 adapter_callback.Run(dbus::ObjectPath(""), false); |
| 64 | 67 |
| 65 // Adapter should not be present. | 68 // Adapter should not be present. |
| 66 EXPECT_FALSE(adapter->IsPresent()); | 69 EXPECT_FALSE(adapter->IsPresent()); |
| 67 } | 70 } |
| 68 | 71 |
| 69 TEST_F(BluetoothAdapterTest, DefaultAdapterWithAddress) { | 72 TEST_F(BluetoothAdapterTest, DefaultAdapterWithAddress) { |
| 70 const dbus::ObjectPath adapter_path("/fake/hci0"); | 73 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 71 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 74 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 72 | 75 |
| 73 // Create the default adapter instance; | 76 // Create the default adapter instance; |
| 74 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 77 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 75 // a callback to obtain the adapter path. | 78 // a callback to obtain the adapter path. |
| 76 BluetoothManagerClient::AdapterCallback adapter_callback; | 79 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 77 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 80 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 78 .WillOnce(SaveArg<0>(&adapter_callback)); | 81 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 79 | 82 |
| 80 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 83 scoped_refptr<BluetoothAdapter> adapter = |
| 84 BluetoothAdapterFactory::DefaultAdapter(); | |
| 81 | 85 |
| 82 // Call the adapter callback; | 86 // Call the adapter callback; |
| 83 // BluetoothAdapterClient::GetProperties will be called once to obtain | 87 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 84 // the property set. | 88 // the property set. |
| 85 MockBluetoothAdapterClient::Properties adapter_properties; | 89 MockBluetoothAdapterClient::Properties adapter_properties; |
| 86 adapter_properties.address.ReplaceValue(adapter_address); | 90 adapter_properties.address.ReplaceValue(adapter_address); |
| 87 | 91 |
| 88 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 92 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 89 .WillRepeatedly(Return(&adapter_properties)); | 93 .WillRepeatedly(Return(&adapter_properties)); |
| 90 | 94 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 107 const dbus::ObjectPath adapter_path("/fake/hci0"); | 111 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 108 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 112 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 109 | 113 |
| 110 // Create the default adapter instance; | 114 // Create the default adapter instance; |
| 111 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 115 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 112 // a callback to obtain the adapter path. | 116 // a callback to obtain the adapter path. |
| 113 BluetoothManagerClient::AdapterCallback adapter_callback; | 117 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 114 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 118 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 115 .WillOnce(SaveArg<0>(&adapter_callback)); | 119 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 116 | 120 |
| 117 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 121 scoped_refptr<BluetoothAdapter> adapter = |
| 122 BluetoothAdapterFactory::DefaultAdapter(); | |
| 118 | 123 |
| 119 // Call the adapter callback; | 124 // Call the adapter callback; |
| 120 // BluetoothAdapterClient::GetProperties will be called once to obtain | 125 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 121 // the property set. | 126 // the property set. |
| 122 MockBluetoothAdapterClient::Properties adapter_properties; | 127 MockBluetoothAdapterClient::Properties adapter_properties; |
| 123 | 128 |
| 124 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 129 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 125 .WillRepeatedly(Return(&adapter_properties)); | 130 .WillRepeatedly(Return(&adapter_properties)); |
| 126 | 131 |
| 127 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | 132 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called |
| 128 // yet. | 133 // yet. |
| 129 MockBluetoothAdapter::Observer adapter_observer; | 134 MockBluetoothAdapter::Observer adapter_observer; |
| 130 adapter->AddObserver(&adapter_observer); | 135 adapter->AddObserver(&adapter_observer); |
| 131 | 136 |
| 132 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 137 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) |
| 133 .Times(0); | 138 .Times(0); |
| 134 | 139 |
| 135 adapter_callback.Run(adapter_path, true); | 140 adapter_callback.Run(adapter_path, true); |
| 136 | 141 |
| 137 // Adapter should not be present yet. | 142 // Adapter should not be present yet. |
| 138 EXPECT_FALSE(adapter->IsPresent()); | 143 EXPECT_FALSE(adapter->IsPresent()); |
| 139 | 144 |
| 140 // Tell the adapter the address now; | 145 // Tell the adapter the address now; |
| 141 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | 146 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. |
| 142 adapter_properties.address.ReplaceValue(adapter_address); | 147 adapter_properties.address.ReplaceValue(adapter_address); |
| 143 | 148 |
| 144 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 149 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) |
| 145 .Times(1); | 150 .Times(1); |
| 146 | 151 |
| 147 static_cast<BluetoothAdapterClient::Observer*>(adapter.get()) | 152 BluetoothAdapterChromeOs* adapter_dbus = |
|
keybuk
2012/09/17 22:19:43
nit: adapter_chromeos
(and each occurrence)
youngki
2012/09/18 18:19:56
Done.
| |
| 153 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
| 154 | |
| 155 static_cast<BluetoothAdapterClient::Observer*>(adapter_dbus) | |
| 148 ->AdapterPropertyChanged(adapter_path, | 156 ->AdapterPropertyChanged(adapter_path, |
| 149 adapter_properties.address.name()); | 157 adapter_properties.address.name()); |
| 150 | 158 |
| 151 // Adapter should be present with the given address. | 159 // Adapter should be present with the given address. |
| 152 EXPECT_TRUE(adapter->IsPresent()); | 160 EXPECT_TRUE(adapter->IsPresent()); |
| 153 EXPECT_EQ(adapter_address, adapter->address()); | 161 EXPECT_EQ(adapter_address, adapter->address()); |
| 154 } | 162 } |
| 155 | 163 |
| 156 TEST_F(BluetoothAdapterTest, DefaultAdapterBecomesPresentWithAddress) { | 164 TEST_F(BluetoothAdapterTest, DefaultAdapterBecomesPresentWithAddress) { |
| 157 const dbus::ObjectPath adapter_path("/fake/hci0"); | 165 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 158 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 166 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 159 | 167 |
| 160 // Create the default adapter instance; | 168 // Create the default adapter instance; |
| 161 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 169 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 162 // a callback to obtain the adapter path. | 170 // a callback to obtain the adapter path. |
| 163 BluetoothManagerClient::AdapterCallback adapter_callback; | 171 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 164 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 172 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 165 .WillOnce(SaveArg<0>(&adapter_callback)); | 173 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 166 | 174 |
| 167 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 175 scoped_refptr<BluetoothAdapter> adapter = |
| 176 BluetoothAdapterFactory::DefaultAdapter(); | |
| 168 | 177 |
| 169 // Call the adapter callback; make out it failed. | 178 // Call the adapter callback; make out it failed. |
| 170 adapter_callback.Run(dbus::ObjectPath(""), false); | 179 adapter_callback.Run(dbus::ObjectPath(""), false); |
| 171 | 180 |
| 172 // Tell the adapter the default adapter changed; | 181 // Tell the adapter the default adapter changed; |
| 173 // BluetoothAdapterClient::GetProperties will be called once to obtain | 182 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 174 // the property set. | 183 // the property set. |
| 175 MockBluetoothAdapterClient::Properties adapter_properties; | 184 MockBluetoothAdapterClient::Properties adapter_properties; |
| 176 adapter_properties.address.ReplaceValue(adapter_address); | 185 adapter_properties.address.ReplaceValue(adapter_address); |
| 177 | 186 |
| 178 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 187 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 179 .WillRepeatedly(Return(&adapter_properties)); | 188 .WillRepeatedly(Return(&adapter_properties)); |
| 180 | 189 |
| 181 // BluetoothAdapter::Observer::AdapterPresentChanged must be called. | 190 // BluetoothAdapter::Observer::AdapterPresentChanged must be called. |
| 182 MockBluetoothAdapter::Observer adapter_observer; | 191 MockBluetoothAdapter::Observer adapter_observer; |
| 183 adapter->AddObserver(&adapter_observer); | 192 adapter->AddObserver(&adapter_observer); |
| 184 | 193 |
| 185 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 194 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) |
| 186 .Times(1); | 195 .Times(1); |
| 187 | 196 |
| 188 static_cast<BluetoothManagerClient::Observer*>(adapter.get()) | 197 BluetoothAdapterChromeOs* adapter_dbus = |
| 198 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
| 199 | |
| 200 static_cast<BluetoothManagerClient::Observer*>(adapter_dbus) | |
| 189 ->DefaultAdapterChanged(adapter_path); | 201 ->DefaultAdapterChanged(adapter_path); |
| 190 | 202 |
| 191 // Adapter should be present with the new address. | 203 // Adapter should be present with the new address. |
| 192 EXPECT_TRUE(adapter->IsPresent()); | 204 EXPECT_TRUE(adapter->IsPresent()); |
| 193 EXPECT_EQ(adapter_address, adapter->address()); | 205 EXPECT_EQ(adapter_address, adapter->address()); |
| 194 } | 206 } |
| 195 | 207 |
| 196 TEST_F(BluetoothAdapterTest, DefaultAdapterReplacedWithAddress) { | 208 TEST_F(BluetoothAdapterTest, DefaultAdapterReplacedWithAddress) { |
| 197 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 209 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 198 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 210 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 199 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 211 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 200 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | 212 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; |
| 201 | 213 |
| 202 // Create the default adapter instance; | 214 // Create the default adapter instance; |
| 203 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 215 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 204 // a callback to obtain the adapter path. | 216 // a callback to obtain the adapter path. |
| 205 BluetoothManagerClient::AdapterCallback adapter_callback; | 217 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 206 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 218 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 207 .WillOnce(SaveArg<0>(&adapter_callback)); | 219 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 208 | 220 |
| 209 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 221 scoped_refptr<BluetoothAdapter> adapter = |
| 222 BluetoothAdapterFactory::DefaultAdapter(); | |
| 210 | 223 |
| 211 // Call the adapter callback; | 224 // Call the adapter callback; |
| 212 // BluetoothAdapterClient::GetProperties will be called once to obtain | 225 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 213 // the property set. | 226 // the property set. |
| 214 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 227 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 215 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 228 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 216 | 229 |
| 217 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 230 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 218 .WillRepeatedly(Return(&initial_adapter_properties)); | 231 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 219 | 232 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 232 // with false to indicate the old adapter being removed and once with true | 245 // with false to indicate the old adapter being removed and once with true |
| 233 // to announce the new adapter. | 246 // to announce the new adapter. |
| 234 MockBluetoothAdapter::Observer adapter_observer; | 247 MockBluetoothAdapter::Observer adapter_observer; |
| 235 adapter->AddObserver(&adapter_observer); | 248 adapter->AddObserver(&adapter_observer); |
| 236 | 249 |
| 237 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 250 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) |
| 238 .Times(1); | 251 .Times(1); |
| 239 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 252 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) |
| 240 .Times(1); | 253 .Times(1); |
| 241 | 254 |
| 242 static_cast<BluetoothManagerClient::Observer*>(adapter.get()) | 255 BluetoothAdapterChromeOs* adapter_dbus = |
| 256 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
| 257 | |
| 258 static_cast<BluetoothManagerClient::Observer*>(adapter_dbus) | |
| 243 ->DefaultAdapterChanged(new_adapter_path); | 259 ->DefaultAdapterChanged(new_adapter_path); |
| 244 | 260 |
| 245 // Adapter should be present with the new address. | 261 // Adapter should be present with the new address. |
| 246 EXPECT_TRUE(adapter->IsPresent()); | 262 EXPECT_TRUE(adapter->IsPresent()); |
| 247 EXPECT_EQ(new_adapter_address, adapter->address()); | 263 EXPECT_EQ(new_adapter_address, adapter->address()); |
| 248 } | 264 } |
| 249 | 265 |
| 250 TEST_F(BluetoothAdapterTest, DefaultAdapterBecomesPresentWithoutAddress) { | 266 TEST_F(BluetoothAdapterTest, DefaultAdapterBecomesPresentWithoutAddress) { |
| 251 const dbus::ObjectPath adapter_path("/fake/hci0"); | 267 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 252 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 268 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 253 | 269 |
| 254 // Create the default adapter instance; | 270 // Create the default adapter instance; |
| 255 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 271 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 256 // a callback to obtain the adapter path. | 272 // a callback to obtain the adapter path. |
| 257 BluetoothManagerClient::AdapterCallback adapter_callback; | 273 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 258 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 274 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 259 .WillOnce(SaveArg<0>(&adapter_callback)); | 275 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 260 | 276 |
| 261 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 277 scoped_refptr<BluetoothAdapter> adapter = |
| 278 BluetoothAdapterFactory::DefaultAdapter(); | |
| 262 | 279 |
| 263 // Call the adapter callback; make out it failed. | 280 // Call the adapter callback; make out it failed. |
| 264 adapter_callback.Run(dbus::ObjectPath(""), false); | 281 adapter_callback.Run(dbus::ObjectPath(""), false); |
| 265 | 282 |
| 266 // Tell the adapter the default adapter changed; | 283 // Tell the adapter the default adapter changed; |
| 267 // BluetoothAdapterClient::GetProperties will be called once to obtain | 284 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 268 // the property set. | 285 // the property set. |
| 269 MockBluetoothAdapterClient::Properties adapter_properties; | 286 MockBluetoothAdapterClient::Properties adapter_properties; |
| 270 | 287 |
| 271 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 288 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 272 .WillRepeatedly(Return(&adapter_properties)); | 289 .WillRepeatedly(Return(&adapter_properties)); |
| 273 | 290 |
| 274 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | 291 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. |
| 275 MockBluetoothAdapter::Observer adapter_observer; | 292 MockBluetoothAdapter::Observer adapter_observer; |
| 276 adapter->AddObserver(&adapter_observer); | 293 adapter->AddObserver(&adapter_observer); |
| 277 | 294 |
| 278 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 295 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) |
| 279 .Times(0); | 296 .Times(0); |
| 280 | 297 |
| 281 static_cast<BluetoothManagerClient::Observer*>(adapter.get()) | 298 BluetoothAdapterChromeOs* adapter_dbus = |
| 299 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
| 300 | |
| 301 static_cast<BluetoothManagerClient::Observer*>(adapter_dbus) | |
| 282 ->DefaultAdapterChanged(adapter_path); | 302 ->DefaultAdapterChanged(adapter_path); |
| 283 | 303 |
| 284 // Adapter should not be present yet. | 304 // Adapter should not be present yet. |
| 285 EXPECT_FALSE(adapter->IsPresent()); | 305 EXPECT_FALSE(adapter->IsPresent()); |
| 286 | 306 |
| 287 // Tell the adapter the address now; | 307 // Tell the adapter the address now; |
| 288 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | 308 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. |
| 289 adapter_properties.address.ReplaceValue(adapter_address); | 309 adapter_properties.address.ReplaceValue(adapter_address); |
| 290 | 310 |
| 291 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 311 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) |
| 292 .Times(1); | 312 .Times(1); |
| 293 | 313 |
| 294 static_cast<BluetoothAdapterClient::Observer*>(adapter.get()) | 314 static_cast<BluetoothAdapterClient::Observer*>(adapter_dbus) |
| 295 ->AdapterPropertyChanged(adapter_path, | 315 ->AdapterPropertyChanged(adapter_path, |
| 296 adapter_properties.address.name()); | 316 adapter_properties.address.name()); |
| 297 | 317 |
| 298 // Adapter should be present with the new address. | 318 // Adapter should be present with the new address. |
| 299 EXPECT_TRUE(adapter->IsPresent()); | 319 EXPECT_TRUE(adapter->IsPresent()); |
| 300 EXPECT_EQ(adapter_address, adapter->address()); | 320 EXPECT_EQ(adapter_address, adapter->address()); |
| 301 } | 321 } |
| 302 | 322 |
| 303 TEST_F(BluetoothAdapterTest, DefaultAdapterReplacedWithoutAddress) { | 323 TEST_F(BluetoothAdapterTest, DefaultAdapterReplacedWithoutAddress) { |
| 304 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 324 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 305 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 325 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 306 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 326 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 307 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | 327 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; |
| 308 | 328 |
| 309 // Create the default adapter instance; | 329 // Create the default adapter instance; |
| 310 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 330 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 311 // a callback to obtain the adapter path. | 331 // a callback to obtain the adapter path. |
| 312 BluetoothManagerClient::AdapterCallback adapter_callback; | 332 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 313 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 333 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 314 .WillOnce(SaveArg<0>(&adapter_callback)); | 334 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 315 | 335 |
| 316 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 336 scoped_refptr<BluetoothAdapter> adapter = |
| 337 BluetoothAdapterFactory::DefaultAdapter(); | |
| 317 | 338 |
| 318 // Call the adapter callback; | 339 // Call the adapter callback; |
| 319 // BluetoothAdapterClient::GetProperties will be called once to obtain | 340 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 320 // the property set. | 341 // the property set. |
| 321 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 342 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 322 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 343 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 323 | 344 |
| 324 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 345 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 325 .WillRepeatedly(Return(&initial_adapter_properties)); | 346 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 326 | 347 |
| 327 adapter_callback.Run(initial_adapter_path, true); | 348 adapter_callback.Run(initial_adapter_path, true); |
| 328 | 349 |
| 329 // Tell the adapter the default adapter changed; | 350 // Tell the adapter the default adapter changed; |
| 330 // BluetoothAdapterClient::GetProperties will be called once to obtain | 351 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 331 // the property set. | 352 // the property set. |
| 332 MockBluetoothAdapterClient::Properties new_adapter_properties; | 353 MockBluetoothAdapterClient::Properties new_adapter_properties; |
| 333 | 354 |
| 334 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | 355 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) |
| 335 .WillRepeatedly(Return(&new_adapter_properties)); | 356 .WillRepeatedly(Return(&new_adapter_properties)); |
| 336 | 357 |
| 337 // BluetoothAdapter::Observer::AdapterPresentChanged must be called to | 358 // BluetoothAdapter::Observer::AdapterPresentChanged must be called to |
| 338 // indicate the adapter has gone away. | 359 // indicate the adapter has gone away. |
| 339 MockBluetoothAdapter::Observer adapter_observer; | 360 MockBluetoothAdapter::Observer adapter_observer; |
| 340 adapter->AddObserver(&adapter_observer); | 361 adapter->AddObserver(&adapter_observer); |
| 341 | 362 |
| 342 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 363 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) |
| 343 .Times(1); | 364 .Times(1); |
| 344 | 365 |
| 345 static_cast<BluetoothManagerClient::Observer*>(adapter.get()) | 366 BluetoothAdapterChromeOs* adapter_dbus = |
| 367 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
| 368 | |
| 369 static_cast<BluetoothManagerClient::Observer*>(adapter_dbus) | |
| 346 ->DefaultAdapterChanged(new_adapter_path); | 370 ->DefaultAdapterChanged(new_adapter_path); |
| 347 | 371 |
| 348 // Adapter should be now marked not present. | 372 // Adapter should be now marked not present. |
| 349 EXPECT_FALSE(adapter->IsPresent()); | 373 EXPECT_FALSE(adapter->IsPresent()); |
| 350 | 374 |
| 351 // Tell the adapter the address now; | 375 // Tell the adapter the address now; |
| 352 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | 376 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. |
| 353 new_adapter_properties.address.ReplaceValue(new_adapter_address); | 377 new_adapter_properties.address.ReplaceValue(new_adapter_address); |
| 354 | 378 |
| 355 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 379 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) |
| 356 .Times(1); | 380 .Times(1); |
| 357 | 381 |
| 358 static_cast<BluetoothAdapterClient::Observer*>(adapter.get()) | 382 static_cast<BluetoothAdapterClient::Observer*>(adapter_dbus) |
| 359 ->AdapterPropertyChanged(new_adapter_path, | 383 ->AdapterPropertyChanged(new_adapter_path, |
| 360 new_adapter_properties.address.name()); | 384 new_adapter_properties.address.name()); |
| 361 | 385 |
| 362 // Adapter should be present with the new address. | 386 // Adapter should be present with the new address. |
| 363 EXPECT_TRUE(adapter->IsPresent()); | 387 EXPECT_TRUE(adapter->IsPresent()); |
| 364 EXPECT_EQ(new_adapter_address, adapter->address()); | 388 EXPECT_EQ(new_adapter_address, adapter->address()); |
| 365 } | 389 } |
| 366 | 390 |
| 367 TEST_F(BluetoothAdapterTest, DefaultAdapterRemoved) { | 391 TEST_F(BluetoothAdapterTest, DefaultAdapterRemoved) { |
| 368 const dbus::ObjectPath adapter_path("/fake/hci0"); | 392 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 369 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 393 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 370 | 394 |
| 371 // Create the default adapter instance; | 395 // Create the default adapter instance; |
| 372 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 396 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 373 // a callback to obtain the adapter path. | 397 // a callback to obtain the adapter path. |
| 374 BluetoothManagerClient::AdapterCallback adapter_callback; | 398 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 375 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 399 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 376 .WillOnce(SaveArg<0>(&adapter_callback)); | 400 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 377 | 401 |
| 378 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 402 scoped_refptr<BluetoothAdapter> adapter = |
| 403 BluetoothAdapterFactory::DefaultAdapter(); | |
| 379 | 404 |
| 380 // Call the adapter callback; | 405 // Call the adapter callback; |
| 381 // BluetoothAdapterClient::GetProperties will be called once to obtain | 406 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 382 // the property set. | 407 // the property set. |
| 383 MockBluetoothAdapterClient::Properties adapter_properties; | 408 MockBluetoothAdapterClient::Properties adapter_properties; |
| 384 adapter_properties.address.ReplaceValue(adapter_address); | 409 adapter_properties.address.ReplaceValue(adapter_address); |
| 385 | 410 |
| 386 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 411 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 387 .WillRepeatedly(Return(&adapter_properties)); | 412 .WillRepeatedly(Return(&adapter_properties)); |
| 388 | 413 |
| 389 adapter_callback.Run(adapter_path, true); | 414 adapter_callback.Run(adapter_path, true); |
| 390 | 415 |
| 391 // Report that the adapter has been removed; | 416 // Report that the adapter has been removed; |
| 392 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to | 417 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to |
| 393 // indicate the adapter is no longer present. | 418 // indicate the adapter is no longer present. |
| 394 MockBluetoothAdapter::Observer adapter_observer; | 419 MockBluetoothAdapter::Observer adapter_observer; |
| 395 adapter->AddObserver(&adapter_observer); | 420 adapter->AddObserver(&adapter_observer); |
| 396 | 421 |
| 397 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 422 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) |
| 398 .Times(1); | 423 .Times(1); |
| 399 | 424 |
| 400 static_cast<BluetoothManagerClient::Observer*>(adapter.get()) | 425 BluetoothAdapterChromeOs* adapter_dbus = |
| 426 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
| 427 | |
| 428 static_cast<BluetoothManagerClient::Observer*>(adapter_dbus) | |
| 401 ->AdapterRemoved(adapter_path); | 429 ->AdapterRemoved(adapter_path); |
| 402 | 430 |
| 403 // Adapter should be no longer present. | 431 // Adapter should be no longer present. |
| 404 EXPECT_FALSE(adapter->IsPresent()); | 432 EXPECT_FALSE(adapter->IsPresent()); |
| 405 } | 433 } |
| 406 | 434 |
| 407 TEST_F(BluetoothAdapterTest, DefaultAdapterWithoutAddressRemoved) { | 435 TEST_F(BluetoothAdapterTest, DefaultAdapterWithoutAddressRemoved) { |
| 408 const dbus::ObjectPath adapter_path("/fake/hci0"); | 436 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 409 | 437 |
| 410 // Create the default adapter instance; | 438 // Create the default adapter instance; |
| 411 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 439 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 412 // a callback to obtain the adapter path. | 440 // a callback to obtain the adapter path. |
| 413 BluetoothManagerClient::AdapterCallback adapter_callback; | 441 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 414 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 442 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 415 .WillOnce(SaveArg<0>(&adapter_callback)); | 443 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 416 | 444 |
| 417 scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter(); | 445 scoped_refptr<BluetoothAdapter> adapter = |
| 446 BluetoothAdapterFactory::DefaultAdapter(); | |
| 418 | 447 |
| 419 // Call the adapter callback; | 448 // Call the adapter callback; |
| 420 // BluetoothAdapterClient::GetProperties will be called once to obtain | 449 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 421 // the property set. | 450 // the property set. |
| 422 MockBluetoothAdapterClient::Properties adapter_properties; | 451 MockBluetoothAdapterClient::Properties adapter_properties; |
| 423 | 452 |
| 424 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 453 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 425 .WillRepeatedly(Return(&adapter_properties)); | 454 .WillRepeatedly(Return(&adapter_properties)); |
| 426 | 455 |
| 427 adapter_callback.Run(adapter_path, true); | 456 adapter_callback.Run(adapter_path, true); |
| 428 | 457 |
| 429 // Report that the adapter has been removed; | 458 // Report that the adapter has been removed; |
| 430 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | 459 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called |
| 431 // since we never should have announced it in the first place. | 460 // since we never should have announced it in the first place. |
| 432 MockBluetoothAdapter::Observer adapter_observer; | 461 MockBluetoothAdapter::Observer adapter_observer; |
| 433 adapter->AddObserver(&adapter_observer); | 462 adapter->AddObserver(&adapter_observer); |
| 434 | 463 |
| 435 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 464 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) |
| 436 .Times(0); | 465 .Times(0); |
| 437 | 466 |
| 438 static_cast<BluetoothManagerClient::Observer*>(adapter.get()) | 467 BluetoothAdapterChromeOs* adapter_dbus = |
| 468 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | |
| 469 | |
| 470 static_cast<BluetoothManagerClient::Observer*>(adapter_dbus) | |
| 439 ->AdapterRemoved(adapter_path); | 471 ->AdapterRemoved(adapter_path); |
| 440 | 472 |
| 441 // Adapter should be still no longer present. | 473 // Adapter should be still no longer present. |
| 442 EXPECT_FALSE(adapter->IsPresent()); | 474 EXPECT_FALSE(adapter->IsPresent()); |
| 443 } | 475 } |
| 444 | 476 |
| 445 } // namespace chromeos | 477 } // namespace chromeos |
| OLD | NEW |