| 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 "chromeos/dbus/mock_bluetooth_adapter_client.h" | 5 #include "chromeos/dbus/mock_bluetooth_adapter_client.h" |
| 6 #include "chromeos/dbus/mock_bluetooth_manager_client.h" | 6 #include "chromeos/dbus/mock_bluetooth_manager_client.h" |
| 7 #include "chromeos/dbus/mock_dbus_thread_manager.h" | 7 #include "chromeos/dbus/mock_dbus_thread_manager.h" |
| 8 #include "dbus/object_path.h" | 8 #include "dbus/object_path.h" |
| 9 #include "device/bluetooth/bluetooth_adapter.h" | 9 #include "device/bluetooth/bluetooth_adapter.h" |
| 10 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 10 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 mock_manager_client_ = | 34 mock_manager_client_ = |
| 35 mock_dbus_thread_manager->mock_bluetooth_manager_client(); | 35 mock_dbus_thread_manager->mock_bluetooth_manager_client(); |
| 36 mock_adapter_client_ = | 36 mock_adapter_client_ = |
| 37 mock_dbus_thread_manager->mock_bluetooth_adapter_client(); | 37 mock_dbus_thread_manager->mock_bluetooth_adapter_client(); |
| 38 | 38 |
| 39 set_callback_called_ = false; | 39 set_callback_called_ = false; |
| 40 error_callback_called_ = false; | 40 error_callback_called_ = false; |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual void TearDown() { | 43 virtual void TearDown() { |
| 44 adapter_ = NULL; |
| 44 DBusThreadManager::Shutdown(); | 45 DBusThreadManager::Shutdown(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void SetCallback() { | 48 void SetCallback() { |
| 48 set_callback_called_ = true; | 49 set_callback_called_ = true; |
| 49 } | 50 } |
| 50 | 51 |
| 51 void ErrorCallback() { | 52 void ErrorCallback() { |
| 52 error_callback_called_ = true; | 53 error_callback_called_ = true; |
| 53 } | 54 } |
| 54 | 55 |
| 56 void SetAdapter(scoped_refptr<device::BluetoothAdapter> adapter) { |
| 57 adapter_ = adapter; |
| 58 } |
| 59 |
| 55 protected: | 60 protected: |
| 56 MockBluetoothManagerClient* mock_manager_client_; | 61 MockBluetoothManagerClient* mock_manager_client_; |
| 57 MockBluetoothAdapterClient* mock_adapter_client_; | 62 MockBluetoothAdapterClient* mock_adapter_client_; |
| 58 | 63 |
| 59 bool set_callback_called_; | 64 bool set_callback_called_; |
| 60 bool error_callback_called_; | 65 bool error_callback_called_; |
| 66 |
| 67 scoped_refptr<BluetoothAdapter> adapter_; |
| 61 }; | 68 }; |
| 62 | 69 |
| 63 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterNotPresent) { | 70 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterNotPresent) { |
| 64 // Create the default adapter instance; | 71 // Create the default adapter instance; |
| 65 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 72 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 66 // a callback to obtain the adapter path. | 73 // a callback to obtain the adapter path. |
| 67 BluetoothManagerClient::AdapterCallback adapter_callback; | 74 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 68 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 75 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 69 .WillOnce(SaveArg<0>(&adapter_callback)); | 76 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 70 | 77 |
| 71 scoped_refptr<BluetoothAdapter> adapter = | 78 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 72 BluetoothAdapterFactory::DefaultAdapter(); | 79 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 73 ASSERT_TRUE(adapter.get() != NULL); | 80 base::Unretained(this))); |
| 81 ASSERT_TRUE(adapter_ != NULL); |
| 74 | 82 |
| 75 // Call the adapter callback; make out it failed. | 83 // Call the adapter callback; make out it failed. |
| 76 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | 84 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. |
| 77 MockBluetoothAdapter::Observer adapter_observer; | 85 MockBluetoothAdapter::Observer adapter_observer; |
| 78 adapter->AddObserver(&adapter_observer); | 86 adapter_->AddObserver(&adapter_observer); |
| 79 | 87 |
| 80 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 88 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) |
| 81 .Times(0); | 89 .Times(0); |
| 82 | 90 |
| 83 adapter_callback.Run(dbus::ObjectPath(""), false); | 91 adapter_callback.Run(dbus::ObjectPath(""), false); |
| 84 | 92 |
| 85 // Adapter should not be present. | 93 // Adapter should not be present. |
| 86 EXPECT_FALSE(adapter->IsPresent()); | 94 EXPECT_FALSE(adapter_->IsPresent()); |
| 87 } | 95 } |
| 88 | 96 |
| 89 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithAddress) { | 97 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithAddress) { |
| 90 const dbus::ObjectPath adapter_path("/fake/hci0"); | 98 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 91 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 99 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 92 | 100 |
| 93 // Create the default adapter instance; | 101 // Create the default adapter instance; |
| 94 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 102 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 95 // a callback to obtain the adapter path. | 103 // a callback to obtain the adapter path. |
| 96 BluetoothManagerClient::AdapterCallback adapter_callback; | 104 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 97 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 105 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 98 .WillOnce(SaveArg<0>(&adapter_callback)); | 106 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 99 | 107 |
| 100 scoped_refptr<BluetoothAdapter> adapter = | 108 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 101 BluetoothAdapterFactory::DefaultAdapter(); | 109 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 110 base::Unretained(this))); |
| 102 | 111 |
| 103 // Call the adapter callback; | 112 // Call the adapter callback; |
| 104 // BluetoothAdapterClient::GetProperties will be called once to obtain | 113 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 105 // the property set. | 114 // the property set. |
| 106 MockBluetoothAdapterClient::Properties adapter_properties; | 115 MockBluetoothAdapterClient::Properties adapter_properties; |
| 107 adapter_properties.address.ReplaceValue(adapter_address); | 116 adapter_properties.address.ReplaceValue(adapter_address); |
| 108 | 117 |
| 109 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 118 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 110 .WillRepeatedly(Return(&adapter_properties)); | 119 .WillRepeatedly(Return(&adapter_properties)); |
| 111 | 120 |
| 112 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to | 121 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to |
| 113 // indicate the adapter is now present. | 122 // indicate the adapter is now present. |
| 114 MockBluetoothAdapter::Observer adapter_observer; | 123 MockBluetoothAdapter::Observer adapter_observer; |
| 115 adapter->AddObserver(&adapter_observer); | 124 adapter_->AddObserver(&adapter_observer); |
| 116 | 125 |
| 117 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 126 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 118 .Times(1); | 127 .Times(1); |
| 119 | 128 |
| 120 adapter_callback.Run(adapter_path, true); | 129 adapter_callback.Run(adapter_path, true); |
| 121 | 130 |
| 122 // Adapter should be present with the given address. | 131 // Adapter should be present with the given address. |
| 123 EXPECT_TRUE(adapter->IsPresent()); | 132 EXPECT_TRUE(adapter_->IsPresent()); |
| 124 EXPECT_EQ(adapter_address, adapter->address()); | 133 EXPECT_EQ(adapter_address, adapter_->address()); |
| 125 } | 134 } |
| 126 | 135 |
| 127 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithoutAddress) { | 136 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithoutAddress) { |
| 128 const dbus::ObjectPath adapter_path("/fake/hci0"); | 137 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 129 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 138 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 130 | 139 |
| 131 // Create the default adapter instance; | 140 // Create the default adapter instance; |
| 132 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 141 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 133 // a callback to obtain the adapter path. | 142 // a callback to obtain the adapter path. |
| 134 BluetoothManagerClient::AdapterCallback adapter_callback; | 143 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 135 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 144 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 136 .WillOnce(SaveArg<0>(&adapter_callback)); | 145 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 137 | 146 |
| 138 scoped_refptr<BluetoothAdapter> adapter = | 147 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 139 BluetoothAdapterFactory::DefaultAdapter(); | 148 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 149 base::Unretained(this))); |
| 140 | 150 |
| 141 // Call the adapter callback; | 151 // Call the adapter callback; |
| 142 // BluetoothAdapterClient::GetProperties will be called once to obtain | 152 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 143 // the property set. | 153 // the property set. |
| 144 MockBluetoothAdapterClient::Properties adapter_properties; | 154 MockBluetoothAdapterClient::Properties adapter_properties; |
| 145 | 155 |
| 146 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 156 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 147 .WillRepeatedly(Return(&adapter_properties)); | 157 .WillRepeatedly(Return(&adapter_properties)); |
| 148 | 158 |
| 149 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | 159 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called |
| 150 // yet. | 160 // yet. |
| 151 MockBluetoothAdapter::Observer adapter_observer; | 161 MockBluetoothAdapter::Observer adapter_observer; |
| 152 adapter->AddObserver(&adapter_observer); | 162 adapter_->AddObserver(&adapter_observer); |
| 153 | 163 |
| 154 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 164 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) |
| 155 .Times(0); | 165 .Times(0); |
| 156 | 166 |
| 157 adapter_callback.Run(adapter_path, true); | 167 adapter_callback.Run(adapter_path, true); |
| 158 | 168 |
| 159 // Adapter should not be present yet. | 169 // Adapter should not be present yet. |
| 160 EXPECT_FALSE(adapter->IsPresent()); | 170 EXPECT_FALSE(adapter_->IsPresent()); |
| 161 | 171 |
| 162 // Tell the adapter the address now; | 172 // Tell the adapter the address now; |
| 163 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | 173 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. |
| 164 adapter_properties.address.ReplaceValue(adapter_address); | 174 adapter_properties.address.ReplaceValue(adapter_address); |
| 165 | 175 |
| 166 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 176 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 167 .Times(1); | 177 .Times(1); |
| 168 | 178 |
| 169 BluetoothAdapterChromeOs* adapter_chromeos = | 179 BluetoothAdapterChromeOs* adapter_chromeos = |
| 170 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 180 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 171 | 181 |
| 172 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 182 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 173 ->AdapterPropertyChanged(adapter_path, | 183 ->AdapterPropertyChanged(adapter_path, |
| 174 adapter_properties.address.name()); | 184 adapter_properties.address.name()); |
| 175 | 185 |
| 176 // Adapter should be present with the given address. | 186 // Adapter should be present with the given address. |
| 177 EXPECT_TRUE(adapter->IsPresent()); | 187 EXPECT_TRUE(adapter_->IsPresent()); |
| 178 EXPECT_EQ(adapter_address, adapter->address()); | 188 EXPECT_EQ(adapter_address, adapter_->address()); |
| 179 } | 189 } |
| 180 | 190 |
| 181 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterBecomesPresentWithAddress) { | 191 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterBecomesPresentWithAddress) { |
| 182 const dbus::ObjectPath adapter_path("/fake/hci0"); | 192 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 183 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 193 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 184 | 194 |
| 185 // Create the default adapter instance; | 195 // Create the default adapter instance; |
| 186 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 196 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 187 // a callback to obtain the adapter path. | 197 // a callback to obtain the adapter path. |
| 188 BluetoothManagerClient::AdapterCallback adapter_callback; | 198 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 189 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 199 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 190 .WillOnce(SaveArg<0>(&adapter_callback)); | 200 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 191 | 201 |
| 192 scoped_refptr<BluetoothAdapter> adapter = | 202 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 193 BluetoothAdapterFactory::DefaultAdapter(); | 203 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 204 base::Unretained(this))); |
| 194 | 205 |
| 195 // Call the adapter callback; make out it failed. | 206 // Call the adapter callback; make out it failed. |
| 196 adapter_callback.Run(dbus::ObjectPath(""), false); | 207 adapter_callback.Run(dbus::ObjectPath(""), false); |
| 197 | 208 |
| 198 // Tell the adapter the default adapter changed; | 209 // Tell the adapter the default adapter changed; |
| 199 // BluetoothAdapterClient::GetProperties will be called once to obtain | 210 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 200 // the property set. | 211 // the property set. |
| 201 MockBluetoothAdapterClient::Properties adapter_properties; | 212 MockBluetoothAdapterClient::Properties adapter_properties; |
| 202 adapter_properties.address.ReplaceValue(adapter_address); | 213 adapter_properties.address.ReplaceValue(adapter_address); |
| 203 | 214 |
| 204 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 215 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 205 .WillRepeatedly(Return(&adapter_properties)); | 216 .WillRepeatedly(Return(&adapter_properties)); |
| 206 | 217 |
| 207 // BluetoothAdapter::Observer::AdapterPresentChanged must be called. | 218 // BluetoothAdapter::Observer::AdapterPresentChanged must be called. |
| 208 MockBluetoothAdapter::Observer adapter_observer; | 219 MockBluetoothAdapter::Observer adapter_observer; |
| 209 adapter->AddObserver(&adapter_observer); | 220 adapter_->AddObserver(&adapter_observer); |
| 210 | 221 |
| 211 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 222 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 212 .Times(1); | 223 .Times(1); |
| 213 | 224 |
| 214 BluetoothAdapterChromeOs* adapter_chromeos = | 225 BluetoothAdapterChromeOs* adapter_chromeos = |
| 215 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 226 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 216 | 227 |
| 217 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 228 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 218 ->DefaultAdapterChanged(adapter_path); | 229 ->DefaultAdapterChanged(adapter_path); |
| 219 | 230 |
| 220 // Adapter should be present with the new address. | 231 // Adapter should be present with the new address. |
| 221 EXPECT_TRUE(adapter->IsPresent()); | 232 EXPECT_TRUE(adapter_->IsPresent()); |
| 222 EXPECT_EQ(adapter_address, adapter->address()); | 233 EXPECT_EQ(adapter_address, adapter_->address()); |
| 223 } | 234 } |
| 224 | 235 |
| 225 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterReplacedWithAddress) { | 236 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterReplacedWithAddress) { |
| 226 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 237 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 227 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 238 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 228 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 239 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 229 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | 240 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; |
| 230 | 241 |
| 231 // Create the default adapter instance; | 242 // Create the default adapter instance; |
| 232 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 243 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 233 // a callback to obtain the adapter path. | 244 // a callback to obtain the adapter path. |
| 234 BluetoothManagerClient::AdapterCallback adapter_callback; | 245 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 235 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 246 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 236 .WillOnce(SaveArg<0>(&adapter_callback)); | 247 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 237 | 248 |
| 238 scoped_refptr<BluetoothAdapter> adapter = | 249 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 239 BluetoothAdapterFactory::DefaultAdapter(); | 250 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 251 base::Unretained(this))); |
| 240 | 252 |
| 241 // Call the adapter callback; | 253 // Call the adapter callback; |
| 242 // BluetoothAdapterClient::GetProperties will be called once to obtain | 254 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 243 // the property set. | 255 // the property set. |
| 244 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 256 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 245 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 257 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 246 | 258 |
| 247 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 259 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 248 .WillRepeatedly(Return(&initial_adapter_properties)); | 260 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 249 | 261 |
| 250 adapter_callback.Run(initial_adapter_path, true); | 262 adapter_callback.Run(initial_adapter_path, true); |
| 251 | 263 |
| 252 // Tell the adapter the default adapter changed; | 264 // Tell the adapter the default adapter changed; |
| 253 // BluetoothAdapterClient::GetProperties will be called once to obtain | 265 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 254 // the property set. | 266 // the property set. |
| 255 MockBluetoothAdapterClient::Properties new_adapter_properties; | 267 MockBluetoothAdapterClient::Properties new_adapter_properties; |
| 256 new_adapter_properties.address.ReplaceValue(new_adapter_address); | 268 new_adapter_properties.address.ReplaceValue(new_adapter_address); |
| 257 | 269 |
| 258 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | 270 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) |
| 259 .WillRepeatedly(Return(&new_adapter_properties)); | 271 .WillRepeatedly(Return(&new_adapter_properties)); |
| 260 | 272 |
| 261 // BluetoothAdapter::Observer::AdapterPresentChanged must be called once | 273 // BluetoothAdapter::Observer::AdapterPresentChanged must be called once |
| 262 // with false to indicate the old adapter being removed and once with true | 274 // with false to indicate the old adapter being removed and once with true |
| 263 // to announce the new adapter. | 275 // to announce the new adapter. |
| 264 MockBluetoothAdapter::Observer adapter_observer; | 276 MockBluetoothAdapter::Observer adapter_observer; |
| 265 adapter->AddObserver(&adapter_observer); | 277 adapter_->AddObserver(&adapter_observer); |
| 266 | 278 |
| 267 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 279 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 268 .Times(1); | 280 .Times(1); |
| 269 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 281 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 270 .Times(1); | 282 .Times(1); |
| 271 | 283 |
| 272 BluetoothAdapterChromeOs* adapter_chromeos = | 284 BluetoothAdapterChromeOs* adapter_chromeos = |
| 273 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 285 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 274 | 286 |
| 275 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 287 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 276 ->DefaultAdapterChanged(new_adapter_path); | 288 ->DefaultAdapterChanged(new_adapter_path); |
| 277 | 289 |
| 278 // Adapter should be present with the new address. | 290 // Adapter should be present with the new address. |
| 279 EXPECT_TRUE(adapter->IsPresent()); | 291 EXPECT_TRUE(adapter_->IsPresent()); |
| 280 EXPECT_EQ(new_adapter_address, adapter->address()); | 292 EXPECT_EQ(new_adapter_address, adapter_->address()); |
| 281 } | 293 } |
| 282 | 294 |
| 283 TEST_F(BluetoothAdapterChromeOsTest, | 295 TEST_F(BluetoothAdapterChromeOsTest, |
| 284 DefaultAdapterBecomesPresentWithoutAddress) { | 296 DefaultAdapterBecomesPresentWithoutAddress) { |
| 285 const dbus::ObjectPath adapter_path("/fake/hci0"); | 297 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 286 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 298 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 287 | 299 |
| 288 // Create the default adapter instance; | 300 // Create the default adapter instance; |
| 289 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 301 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 290 // a callback to obtain the adapter path. | 302 // a callback to obtain the adapter path. |
| 291 BluetoothManagerClient::AdapterCallback adapter_callback; | 303 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 292 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 304 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 293 .WillOnce(SaveArg<0>(&adapter_callback)); | 305 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 294 | 306 |
| 295 scoped_refptr<BluetoothAdapter> adapter = | 307 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 296 BluetoothAdapterFactory::DefaultAdapter(); | 308 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 309 base::Unretained(this))); |
| 297 | 310 |
| 298 // Call the adapter callback; make out it failed. | 311 // Call the adapter callback; make out it failed. |
| 299 adapter_callback.Run(dbus::ObjectPath(""), false); | 312 adapter_callback.Run(dbus::ObjectPath(""), false); |
| 300 | 313 |
| 301 // Tell the adapter the default adapter changed; | 314 // Tell the adapter the default adapter changed; |
| 302 // BluetoothAdapterClient::GetProperties will be called once to obtain | 315 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 303 // the property set. | 316 // the property set. |
| 304 MockBluetoothAdapterClient::Properties adapter_properties; | 317 MockBluetoothAdapterClient::Properties adapter_properties; |
| 305 | 318 |
| 306 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 319 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 307 .WillRepeatedly(Return(&adapter_properties)); | 320 .WillRepeatedly(Return(&adapter_properties)); |
| 308 | 321 |
| 309 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. | 322 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called. |
| 310 MockBluetoothAdapter::Observer adapter_observer; | 323 MockBluetoothAdapter::Observer adapter_observer; |
| 311 adapter->AddObserver(&adapter_observer); | 324 adapter_->AddObserver(&adapter_observer); |
| 312 | 325 |
| 313 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 326 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) |
| 314 .Times(0); | 327 .Times(0); |
| 315 | 328 |
| 316 BluetoothAdapterChromeOs* adapter_chromeos = | 329 BluetoothAdapterChromeOs* adapter_chromeos = |
| 317 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 330 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 318 | 331 |
| 319 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 332 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 320 ->DefaultAdapterChanged(adapter_path); | 333 ->DefaultAdapterChanged(adapter_path); |
| 321 | 334 |
| 322 // Adapter should not be present yet. | 335 // Adapter should not be present yet. |
| 323 EXPECT_FALSE(adapter->IsPresent()); | 336 EXPECT_FALSE(adapter_->IsPresent()); |
| 324 | 337 |
| 325 // Tell the adapter the address now; | 338 // Tell the adapter the address now; |
| 326 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | 339 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. |
| 327 adapter_properties.address.ReplaceValue(adapter_address); | 340 adapter_properties.address.ReplaceValue(adapter_address); |
| 328 | 341 |
| 329 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 342 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 330 .Times(1); | 343 .Times(1); |
| 331 | 344 |
| 332 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 345 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 333 ->AdapterPropertyChanged(adapter_path, | 346 ->AdapterPropertyChanged(adapter_path, |
| 334 adapter_properties.address.name()); | 347 adapter_properties.address.name()); |
| 335 | 348 |
| 336 // Adapter should be present with the new address. | 349 // Adapter should be present with the new address. |
| 337 EXPECT_TRUE(adapter->IsPresent()); | 350 EXPECT_TRUE(adapter_->IsPresent()); |
| 338 EXPECT_EQ(adapter_address, adapter->address()); | 351 EXPECT_EQ(adapter_address, adapter_->address()); |
| 339 } | 352 } |
| 340 | 353 |
| 341 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterReplacedWithoutAddress) { | 354 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterReplacedWithoutAddress) { |
| 342 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 355 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 343 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 356 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 344 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 357 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 345 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | 358 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; |
| 346 | 359 |
| 347 // Create the default adapter instance; | 360 // Create the default adapter instance; |
| 348 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 361 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 349 // a callback to obtain the adapter path. | 362 // a callback to obtain the adapter path. |
| 350 BluetoothManagerClient::AdapterCallback adapter_callback; | 363 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 351 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 364 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 352 .WillOnce(SaveArg<0>(&adapter_callback)); | 365 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 353 | 366 |
| 354 scoped_refptr<BluetoothAdapter> adapter = | 367 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 355 BluetoothAdapterFactory::DefaultAdapter(); | 368 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 369 base::Unretained(this))); |
| 356 | 370 |
| 357 // Call the adapter callback; | 371 // Call the adapter callback; |
| 358 // BluetoothAdapterClient::GetProperties will be called once to obtain | 372 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 359 // the property set. | 373 // the property set. |
| 360 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 374 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 361 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 375 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 362 | 376 |
| 363 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 377 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 364 .WillRepeatedly(Return(&initial_adapter_properties)); | 378 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 365 | 379 |
| 366 adapter_callback.Run(initial_adapter_path, true); | 380 adapter_callback.Run(initial_adapter_path, true); |
| 367 | 381 |
| 368 // Tell the adapter the default adapter changed; | 382 // Tell the adapter the default adapter changed; |
| 369 // BluetoothAdapterClient::GetProperties will be called once to obtain | 383 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 370 // the property set. | 384 // the property set. |
| 371 MockBluetoothAdapterClient::Properties new_adapter_properties; | 385 MockBluetoothAdapterClient::Properties new_adapter_properties; |
| 372 | 386 |
| 373 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | 387 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) |
| 374 .WillRepeatedly(Return(&new_adapter_properties)); | 388 .WillRepeatedly(Return(&new_adapter_properties)); |
| 375 | 389 |
| 376 // BluetoothAdapter::Observer::AdapterPresentChanged must be called to | 390 // BluetoothAdapter::Observer::AdapterPresentChanged must be called to |
| 377 // indicate the adapter has gone away. | 391 // indicate the adapter has gone away. |
| 378 MockBluetoothAdapter::Observer adapter_observer; | 392 MockBluetoothAdapter::Observer adapter_observer; |
| 379 adapter->AddObserver(&adapter_observer); | 393 adapter_->AddObserver(&adapter_observer); |
| 380 | 394 |
| 381 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 395 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 382 .Times(1); | 396 .Times(1); |
| 383 | 397 |
| 384 BluetoothAdapterChromeOs* adapter_chromeos = | 398 BluetoothAdapterChromeOs* adapter_chromeos = |
| 385 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 399 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 386 | 400 |
| 387 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 401 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 388 ->DefaultAdapterChanged(new_adapter_path); | 402 ->DefaultAdapterChanged(new_adapter_path); |
| 389 | 403 |
| 390 // Adapter should be now marked not present. | 404 // Adapter should be now marked not present. |
| 391 EXPECT_FALSE(adapter->IsPresent()); | 405 EXPECT_FALSE(adapter_->IsPresent()); |
| 392 | 406 |
| 393 // Tell the adapter the address now; | 407 // Tell the adapter the address now; |
| 394 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. | 408 // BluetoothAdapter::Observer::AdapterPresentChanged now must be called. |
| 395 new_adapter_properties.address.ReplaceValue(new_adapter_address); | 409 new_adapter_properties.address.ReplaceValue(new_adapter_address); |
| 396 | 410 |
| 397 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 411 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 398 .Times(1); | 412 .Times(1); |
| 399 | 413 |
| 400 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 414 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 401 ->AdapterPropertyChanged(new_adapter_path, | 415 ->AdapterPropertyChanged(new_adapter_path, |
| 402 new_adapter_properties.address.name()); | 416 new_adapter_properties.address.name()); |
| 403 | 417 |
| 404 // Adapter should be present with the new address. | 418 // Adapter should be present with the new address. |
| 405 EXPECT_TRUE(adapter->IsPresent()); | 419 EXPECT_TRUE(adapter_->IsPresent()); |
| 406 EXPECT_EQ(new_adapter_address, adapter->address()); | 420 EXPECT_EQ(new_adapter_address, adapter_->address()); |
| 407 } | 421 } |
| 408 | 422 |
| 409 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterRemoved) { | 423 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterRemoved) { |
| 410 const dbus::ObjectPath adapter_path("/fake/hci0"); | 424 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 411 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 425 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 412 | 426 |
| 413 // Create the default adapter instance; | 427 // Create the default adapter instance; |
| 414 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 428 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 415 // a callback to obtain the adapter path. | 429 // a callback to obtain the adapter path. |
| 416 BluetoothManagerClient::AdapterCallback adapter_callback; | 430 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 417 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 431 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 418 .WillOnce(SaveArg<0>(&adapter_callback)); | 432 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 419 | 433 |
| 420 scoped_refptr<BluetoothAdapter> adapter = | 434 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 421 BluetoothAdapterFactory::DefaultAdapter(); | 435 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 436 base::Unretained(this))); |
| 422 | 437 |
| 423 // Call the adapter callback; | 438 // Call the adapter callback; |
| 424 // BluetoothAdapterClient::GetProperties will be called once to obtain | 439 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 425 // the property set. | 440 // the property set. |
| 426 MockBluetoothAdapterClient::Properties adapter_properties; | 441 MockBluetoothAdapterClient::Properties adapter_properties; |
| 427 adapter_properties.address.ReplaceValue(adapter_address); | 442 adapter_properties.address.ReplaceValue(adapter_address); |
| 428 | 443 |
| 429 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 444 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 430 .WillRepeatedly(Return(&adapter_properties)); | 445 .WillRepeatedly(Return(&adapter_properties)); |
| 431 | 446 |
| 432 adapter_callback.Run(adapter_path, true); | 447 adapter_callback.Run(adapter_path, true); |
| 433 | 448 |
| 434 // Report that the adapter has been removed; | 449 // Report that the adapter has been removed; |
| 435 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to | 450 // BluetoothAdapter::Observer::AdapterPresentChanged will be called to |
| 436 // indicate the adapter is no longer present. | 451 // indicate the adapter is no longer present. |
| 437 MockBluetoothAdapter::Observer adapter_observer; | 452 MockBluetoothAdapter::Observer adapter_observer; |
| 438 adapter->AddObserver(&adapter_observer); | 453 adapter_->AddObserver(&adapter_observer); |
| 439 | 454 |
| 440 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 455 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 441 .Times(1); | 456 .Times(1); |
| 442 | 457 |
| 443 BluetoothAdapterChromeOs* adapter_chromeos = | 458 BluetoothAdapterChromeOs* adapter_chromeos = |
| 444 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 459 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 445 | 460 |
| 446 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 461 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 447 ->AdapterRemoved(adapter_path); | 462 ->AdapterRemoved(adapter_path); |
| 448 | 463 |
| 449 // Adapter should be no longer present. | 464 // Adapter should be no longer present. |
| 450 EXPECT_FALSE(adapter->IsPresent()); | 465 EXPECT_FALSE(adapter_->IsPresent()); |
| 451 } | 466 } |
| 452 | 467 |
| 453 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithoutAddressRemoved) { | 468 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterWithoutAddressRemoved) { |
| 454 const dbus::ObjectPath adapter_path("/fake/hci0"); | 469 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 455 | 470 |
| 456 // Create the default adapter instance; | 471 // Create the default adapter instance; |
| 457 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 472 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 458 // a callback to obtain the adapter path. | 473 // a callback to obtain the adapter path. |
| 459 BluetoothManagerClient::AdapterCallback adapter_callback; | 474 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 460 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 475 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 461 .WillOnce(SaveArg<0>(&adapter_callback)); | 476 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 462 | 477 |
| 463 scoped_refptr<BluetoothAdapter> adapter = | 478 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 464 BluetoothAdapterFactory::DefaultAdapter(); | 479 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 480 base::Unretained(this))); |
| 465 | 481 |
| 466 // Call the adapter callback; | 482 // Call the adapter callback; |
| 467 // BluetoothAdapterClient::GetProperties will be called once to obtain | 483 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 468 // the property set. | 484 // the property set. |
| 469 MockBluetoothAdapterClient::Properties adapter_properties; | 485 MockBluetoothAdapterClient::Properties adapter_properties; |
| 470 | 486 |
| 471 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 487 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 472 .WillRepeatedly(Return(&adapter_properties)); | 488 .WillRepeatedly(Return(&adapter_properties)); |
| 473 | 489 |
| 474 adapter_callback.Run(adapter_path, true); | 490 adapter_callback.Run(adapter_path, true); |
| 475 | 491 |
| 476 // Report that the adapter has been removed; | 492 // Report that the adapter has been removed; |
| 477 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called | 493 // BluetoothAdapter::Observer::AdapterPresentChanged must not be called |
| 478 // since we never should have announced it in the first place. | 494 // since we never should have announced it in the first place. |
| 479 MockBluetoothAdapter::Observer adapter_observer; | 495 MockBluetoothAdapter::Observer adapter_observer; |
| 480 adapter->AddObserver(&adapter_observer); | 496 adapter_->AddObserver(&adapter_observer); |
| 481 | 497 |
| 482 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _)) | 498 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _)) |
| 483 .Times(0); | 499 .Times(0); |
| 484 | 500 |
| 485 BluetoothAdapterChromeOs* adapter_chromeos = | 501 BluetoothAdapterChromeOs* adapter_chromeos = |
| 486 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 502 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 487 | 503 |
| 488 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 504 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 489 ->AdapterRemoved(adapter_path); | 505 ->AdapterRemoved(adapter_path); |
| 490 | 506 |
| 491 // Adapter should be still no longer present. | 507 // Adapter should be still no longer present. |
| 492 EXPECT_FALSE(adapter->IsPresent()); | 508 EXPECT_FALSE(adapter_->IsPresent()); |
| 493 } | 509 } |
| 494 | 510 |
| 495 TEST_F(BluetoothAdapterChromeOsTest, | 511 TEST_F(BluetoothAdapterChromeOsTest, |
| 496 DefaultAdapterPoweredPropertyInitiallyFalse) { | 512 DefaultAdapterPoweredPropertyInitiallyFalse) { |
| 497 const dbus::ObjectPath adapter_path("/fake/hci0"); | 513 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 498 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 514 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 499 | 515 |
| 500 // Create the default adapter instance; | 516 // Create the default adapter instance; |
| 501 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 517 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 502 // a callback to obtain the adapter path. | 518 // a callback to obtain the adapter path. |
| 503 BluetoothManagerClient::AdapterCallback adapter_callback; | 519 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 504 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 520 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 505 .WillOnce(SaveArg<0>(&adapter_callback)); | 521 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 506 | 522 |
| 507 scoped_refptr<BluetoothAdapter> adapter = | 523 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 508 BluetoothAdapterFactory::DefaultAdapter(); | 524 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 525 base::Unretained(this))); |
| 509 | 526 |
| 510 // Call the adapter callback; | 527 // Call the adapter callback; |
| 511 // BluetoothAdapterClient::GetProperties will be called once to obtain | 528 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 512 // the property set. | 529 // the property set. |
| 513 MockBluetoothAdapterClient::Properties adapter_properties; | 530 MockBluetoothAdapterClient::Properties adapter_properties; |
| 514 adapter_properties.address.ReplaceValue(adapter_address); | 531 adapter_properties.address.ReplaceValue(adapter_address); |
| 515 adapter_properties.powered.ReplaceValue(false); | 532 adapter_properties.powered.ReplaceValue(false); |
| 516 | 533 |
| 517 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 534 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 518 .WillRepeatedly(Return(&adapter_properties)); | 535 .WillRepeatedly(Return(&adapter_properties)); |
| 519 | 536 |
| 520 adapter_callback.Run(adapter_path, true); | 537 adapter_callback.Run(adapter_path, true); |
| 521 | 538 |
| 522 // Adapter should have the correct property value. | 539 // Adapter should have the correct property value. |
| 523 EXPECT_FALSE(adapter->IsPowered()); | 540 EXPECT_FALSE(adapter_->IsPowered()); |
| 524 } | 541 } |
| 525 | 542 |
| 526 TEST_F(BluetoothAdapterChromeOsTest, | 543 TEST_F(BluetoothAdapterChromeOsTest, |
| 527 DefaultAdapterPoweredPropertyInitiallyTrue) { | 544 DefaultAdapterPoweredPropertyInitiallyTrue) { |
| 528 const dbus::ObjectPath adapter_path("/fake/hci0"); | 545 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 529 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 546 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 530 | 547 |
| 531 // Create the default adapter instance; | 548 // Create the default adapter instance; |
| 532 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 549 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 533 // a callback to obtain the adapter path. | 550 // a callback to obtain the adapter path. |
| 534 BluetoothManagerClient::AdapterCallback adapter_callback; | 551 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 535 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 552 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 536 .WillOnce(SaveArg<0>(&adapter_callback)); | 553 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 537 | 554 |
| 538 scoped_refptr<BluetoothAdapter> adapter = | 555 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 539 BluetoothAdapterFactory::DefaultAdapter(); | 556 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 557 base::Unretained(this))); |
| 540 | 558 |
| 541 // Call the adapter callback; | 559 // Call the adapter callback; |
| 542 // BluetoothAdapterClient::GetProperties will be called once to obtain | 560 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 543 // the property set. | 561 // the property set. |
| 544 MockBluetoothAdapterClient::Properties adapter_properties; | 562 MockBluetoothAdapterClient::Properties adapter_properties; |
| 545 adapter_properties.address.ReplaceValue(adapter_address); | 563 adapter_properties.address.ReplaceValue(adapter_address); |
| 546 adapter_properties.powered.ReplaceValue(true); | 564 adapter_properties.powered.ReplaceValue(true); |
| 547 | 565 |
| 548 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 566 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 549 .WillRepeatedly(Return(&adapter_properties)); | 567 .WillRepeatedly(Return(&adapter_properties)); |
| 550 | 568 |
| 551 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | 569 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. |
| 552 MockBluetoothAdapter::Observer adapter_observer; | 570 MockBluetoothAdapter::Observer adapter_observer; |
| 553 adapter->AddObserver(&adapter_observer); | 571 adapter_->AddObserver(&adapter_observer); |
| 554 | 572 |
| 555 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 573 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 556 .Times(1); | 574 .Times(1); |
| 557 | 575 |
| 558 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | 576 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) |
| 559 .Times(1); | 577 .Times(1); |
| 560 | 578 |
| 561 adapter_callback.Run(adapter_path, true); | 579 adapter_callback.Run(adapter_path, true); |
| 562 | 580 |
| 563 // Adapter should have the correct property value. | 581 // Adapter should have the correct property value. |
| 564 EXPECT_TRUE(adapter->IsPowered()); | 582 EXPECT_TRUE(adapter_->IsPowered()); |
| 565 } | 583 } |
| 566 | 584 |
| 567 TEST_F(BluetoothAdapterChromeOsTest, | 585 TEST_F(BluetoothAdapterChromeOsTest, |
| 568 DefaultAdapterPoweredPropertyInitiallyTrueWithoutAddress) { | 586 DefaultAdapterPoweredPropertyInitiallyTrueWithoutAddress) { |
| 569 const dbus::ObjectPath adapter_path("/fake/hci0"); | 587 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 570 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 588 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 571 | 589 |
| 572 // Create the default adapter instance; | 590 // Create the default adapter instance; |
| 573 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 591 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 574 // a callback to obtain the adapter path. | 592 // a callback to obtain the adapter path. |
| 575 BluetoothManagerClient::AdapterCallback adapter_callback; | 593 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 576 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 594 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 577 .WillOnce(SaveArg<0>(&adapter_callback)); | 595 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 578 | 596 |
| 579 scoped_refptr<BluetoothAdapter> adapter = | 597 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 580 BluetoothAdapterFactory::DefaultAdapter(); | 598 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 599 base::Unretained(this))); |
| 581 | 600 |
| 582 // Call the adapter callback; | 601 // Call the adapter callback; |
| 583 // BluetoothAdapterClient::GetProperties will be called once to obtain | 602 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 584 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged | 603 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged |
| 585 // should not yet be called. | 604 // should not yet be called. |
| 586 MockBluetoothAdapterClient::Properties adapter_properties; | 605 MockBluetoothAdapterClient::Properties adapter_properties; |
| 587 adapter_properties.powered.ReplaceValue(true); | 606 adapter_properties.powered.ReplaceValue(true); |
| 588 | 607 |
| 589 MockBluetoothAdapter::Observer adapter_observer; | 608 MockBluetoothAdapter::Observer adapter_observer; |
| 590 adapter->AddObserver(&adapter_observer); | 609 adapter_->AddObserver(&adapter_observer); |
| 591 | 610 |
| 592 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 611 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 593 .WillRepeatedly(Return(&adapter_properties)); | 612 .WillRepeatedly(Return(&adapter_properties)); |
| 594 | 613 |
| 595 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | 614 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) |
| 596 .Times(0); | 615 .Times(0); |
| 597 | 616 |
| 598 adapter_callback.Run(adapter_path, true); | 617 adapter_callback.Run(adapter_path, true); |
| 599 | 618 |
| 600 // Adapter should not yet have the property value. | 619 // Adapter should not yet have the property value. |
| 601 EXPECT_FALSE(adapter->IsPowered()); | 620 EXPECT_FALSE(adapter_->IsPowered()); |
| 602 | 621 |
| 603 // Tell the adapter the address now, | 622 // Tell the adapter the address now, |
| 604 // BluetoothAdapter::Observer::AdapterPresentChanged and | 623 // BluetoothAdapter::Observer::AdapterPresentChanged and |
| 605 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. | 624 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. |
| 606 adapter_properties.address.ReplaceValue(adapter_address); | 625 adapter_properties.address.ReplaceValue(adapter_address); |
| 607 | 626 |
| 608 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 627 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 609 .Times(1); | 628 .Times(1); |
| 610 | 629 |
| 611 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | 630 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) |
| 612 .Times(1); | 631 .Times(1); |
| 613 | 632 |
| 614 BluetoothAdapterChromeOs* adapter_chromeos = | 633 BluetoothAdapterChromeOs* adapter_chromeos = |
| 615 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 634 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 616 | 635 |
| 617 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 636 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 618 ->AdapterPropertyChanged(adapter_path, | 637 ->AdapterPropertyChanged(adapter_path, |
| 619 adapter_properties.address.name()); | 638 adapter_properties.address.name()); |
| 620 | 639 |
| 621 // Adapter should have the correct property value. | 640 // Adapter should have the correct property value. |
| 622 EXPECT_TRUE(adapter->IsPowered()); | 641 EXPECT_TRUE(adapter_->IsPowered()); |
| 623 } | 642 } |
| 624 | 643 |
| 625 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterPoweredPropertyChanged) { | 644 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterPoweredPropertyChanged) { |
| 626 const dbus::ObjectPath adapter_path("/fake/hci0"); | 645 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 627 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 646 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 628 | 647 |
| 629 // Create the default adapter instance; | 648 // Create the default adapter instance; |
| 630 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 649 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 631 // a callback to obtain the adapter path. | 650 // a callback to obtain the adapter path. |
| 632 BluetoothManagerClient::AdapterCallback adapter_callback; | 651 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 633 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 652 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 634 .WillOnce(SaveArg<0>(&adapter_callback)); | 653 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 635 | 654 |
| 636 scoped_refptr<BluetoothAdapter> adapter = | 655 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 637 BluetoothAdapterFactory::DefaultAdapter(); | 656 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 657 base::Unretained(this))); |
| 638 | 658 |
| 639 // Call the adapter callback; | 659 // Call the adapter callback; |
| 640 // BluetoothAdapterClient::GetProperties will be called once to obtain | 660 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 641 // the property set. | 661 // the property set. |
| 642 MockBluetoothAdapterClient::Properties adapter_properties; | 662 MockBluetoothAdapterClient::Properties adapter_properties; |
| 643 adapter_properties.address.ReplaceValue(adapter_address); | 663 adapter_properties.address.ReplaceValue(adapter_address); |
| 644 adapter_properties.powered.ReplaceValue(false); | 664 adapter_properties.powered.ReplaceValue(false); |
| 645 | 665 |
| 646 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 666 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 647 .WillRepeatedly(Return(&adapter_properties)); | 667 .WillRepeatedly(Return(&adapter_properties)); |
| 648 | 668 |
| 649 adapter_callback.Run(adapter_path, true); | 669 adapter_callback.Run(adapter_path, true); |
| 650 | 670 |
| 651 // Adapter should have the correct property value. | 671 // Adapter should have the correct property value. |
| 652 EXPECT_FALSE(adapter->IsPowered()); | 672 EXPECT_FALSE(adapter_->IsPowered()); |
| 653 | 673 |
| 654 // Report that the property has been changed; | 674 // Report that the property has been changed; |
| 655 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | 675 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. |
| 656 MockBluetoothAdapter::Observer adapter_observer; | 676 MockBluetoothAdapter::Observer adapter_observer; |
| 657 adapter->AddObserver(&adapter_observer); | 677 adapter_->AddObserver(&adapter_observer); |
| 658 | 678 |
| 659 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | 679 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) |
| 660 .Times(1); | 680 .Times(1); |
| 661 | 681 |
| 662 adapter_properties.powered.ReplaceValue(true); | 682 adapter_properties.powered.ReplaceValue(true); |
| 663 | 683 |
| 664 BluetoothAdapterChromeOs* adapter_chromeos = | 684 BluetoothAdapterChromeOs* adapter_chromeos = |
| 665 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 685 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 666 | 686 |
| 667 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 687 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 668 ->AdapterPropertyChanged(adapter_path, | 688 ->AdapterPropertyChanged(adapter_path, |
| 669 adapter_properties.powered.name()); | 689 adapter_properties.powered.name()); |
| 670 | 690 |
| 671 // Adapter should have the new property values. | 691 // Adapter should have the new property values. |
| 672 EXPECT_TRUE(adapter->IsPowered()); | 692 EXPECT_TRUE(adapter_->IsPowered()); |
| 673 } | 693 } |
| 674 | 694 |
| 675 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterPoweredPropertyUnchanged) { | 695 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterPoweredPropertyUnchanged) { |
| 676 const dbus::ObjectPath adapter_path("/fake/hci0"); | 696 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 677 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 697 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 678 | 698 |
| 679 // Create the default adapter instance; | 699 // Create the default adapter instance; |
| 680 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 700 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 681 // a callback to obtain the adapter path. | 701 // a callback to obtain the adapter path. |
| 682 BluetoothManagerClient::AdapterCallback adapter_callback; | 702 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 683 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 703 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 684 .WillOnce(SaveArg<0>(&adapter_callback)); | 704 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 685 | 705 |
| 686 scoped_refptr<BluetoothAdapter> adapter = | 706 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 687 BluetoothAdapterFactory::DefaultAdapter(); | 707 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 708 base::Unretained(this))); |
| 688 | 709 |
| 689 // Call the adapter callback; | 710 // Call the adapter callback; |
| 690 // BluetoothAdapterClient::GetProperties will be called once to obtain | 711 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 691 // the property set. | 712 // the property set. |
| 692 MockBluetoothAdapterClient::Properties adapter_properties; | 713 MockBluetoothAdapterClient::Properties adapter_properties; |
| 693 adapter_properties.address.ReplaceValue(adapter_address); | 714 adapter_properties.address.ReplaceValue(adapter_address); |
| 694 adapter_properties.powered.ReplaceValue(true); | 715 adapter_properties.powered.ReplaceValue(true); |
| 695 | 716 |
| 696 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 717 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 697 .WillRepeatedly(Return(&adapter_properties)); | 718 .WillRepeatedly(Return(&adapter_properties)); |
| 698 | 719 |
| 699 adapter_callback.Run(adapter_path, true); | 720 adapter_callback.Run(adapter_path, true); |
| 700 | 721 |
| 701 // Adapter should have the correct property value. | 722 // Adapter should have the correct property value. |
| 702 EXPECT_TRUE(adapter->IsPowered()); | 723 EXPECT_TRUE(adapter_->IsPowered()); |
| 703 | 724 |
| 704 // Report that the property has been changed, but don't change the value; | 725 // Report that the property has been changed, but don't change the value; |
| 705 // BluetoothAdapter::Observer::AdapterPoweredChanged should not be called. | 726 // BluetoothAdapter::Observer::AdapterPoweredChanged should not be called. |
| 706 MockBluetoothAdapter::Observer adapter_observer; | 727 MockBluetoothAdapter::Observer adapter_observer; |
| 707 adapter->AddObserver(&adapter_observer); | 728 adapter_->AddObserver(&adapter_observer); |
| 708 | 729 |
| 709 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | 730 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) |
| 710 .Times(0); | 731 .Times(0); |
| 711 | 732 |
| 712 BluetoothAdapterChromeOs* adapter_chromeos = | 733 BluetoothAdapterChromeOs* adapter_chromeos = |
| 713 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 734 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 714 | 735 |
| 715 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 736 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 716 ->AdapterPropertyChanged(adapter_path, | 737 ->AdapterPropertyChanged(adapter_path, |
| 717 adapter_properties.powered.name()); | 738 adapter_properties.powered.name()); |
| 718 | 739 |
| 719 // Adapter should still have the same property values. | 740 // Adapter should still have the same property values. |
| 720 EXPECT_TRUE(adapter->IsPowered()); | 741 EXPECT_TRUE(adapter_->IsPowered()); |
| 721 } | 742 } |
| 722 | 743 |
| 723 TEST_F(BluetoothAdapterChromeOsTest, | 744 TEST_F(BluetoothAdapterChromeOsTest, |
| 724 DefaultAdapterPoweredPropertyChangedWithoutAddress) { | 745 DefaultAdapterPoweredPropertyChangedWithoutAddress) { |
| 725 const dbus::ObjectPath adapter_path("/fake/hci0"); | 746 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 726 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 747 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 727 | 748 |
| 728 // Create the default adapter instance; | 749 // Create the default adapter instance; |
| 729 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 750 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 730 // a callback to obtain the adapter path. | 751 // a callback to obtain the adapter path. |
| 731 BluetoothManagerClient::AdapterCallback adapter_callback; | 752 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 732 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 753 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 733 .WillOnce(SaveArg<0>(&adapter_callback)); | 754 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 734 | 755 |
| 735 scoped_refptr<BluetoothAdapter> adapter = | 756 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 736 BluetoothAdapterFactory::DefaultAdapter(); | 757 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 758 base::Unretained(this))); |
| 737 | 759 |
| 738 // Call the adapter callback; | 760 // Call the adapter callback; |
| 739 // BluetoothAdapterClient::GetProperties will be called once to obtain | 761 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 740 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged | 762 // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged |
| 741 // should not yet be called. | 763 // should not yet be called. |
| 742 MockBluetoothAdapterClient::Properties adapter_properties; | 764 MockBluetoothAdapterClient::Properties adapter_properties; |
| 743 | 765 |
| 744 MockBluetoothAdapter::Observer adapter_observer; | 766 MockBluetoothAdapter::Observer adapter_observer; |
| 745 adapter->AddObserver(&adapter_observer); | 767 adapter_->AddObserver(&adapter_observer); |
| 746 | 768 |
| 747 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 769 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 748 .WillRepeatedly(Return(&adapter_properties)); | 770 .WillRepeatedly(Return(&adapter_properties)); |
| 749 | 771 |
| 750 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | 772 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) |
| 751 .Times(0); | 773 .Times(0); |
| 752 | 774 |
| 753 adapter_callback.Run(adapter_path, true); | 775 adapter_callback.Run(adapter_path, true); |
| 754 | 776 |
| 755 // Tell the adapter that its powered property changed, the observer | 777 // Tell the adapter that its powered property changed, the observer |
| 756 // method should still not be called because there is no address for | 778 // method should still not be called because there is no address for |
| 757 // the adapter so it is not present. | 779 // the adapter so it is not present. |
| 758 adapter_properties.powered.ReplaceValue(true); | 780 adapter_properties.powered.ReplaceValue(true); |
| 759 | 781 |
| 760 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), _)) | 782 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _)) |
| 761 .Times(0); | 783 .Times(0); |
| 762 | 784 |
| 763 BluetoothAdapterChromeOs* adapter_chromeos = | 785 BluetoothAdapterChromeOs* adapter_chromeos = |
| 764 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 786 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 765 | 787 |
| 766 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 788 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 767 ->AdapterPropertyChanged(adapter_path, | 789 ->AdapterPropertyChanged(adapter_path, |
| 768 adapter_properties.powered.name()); | 790 adapter_properties.powered.name()); |
| 769 | 791 |
| 770 // Adapter should not yet have the property value. | 792 // Adapter should not yet have the property value. |
| 771 EXPECT_FALSE(adapter->IsPowered()); | 793 EXPECT_FALSE(adapter_->IsPowered()); |
| 772 | 794 |
| 773 // Tell the adapter the address now, | 795 // Tell the adapter the address now, |
| 774 // BluetoothAdapter::Observer::AdapterPresentChanged and | 796 // BluetoothAdapter::Observer::AdapterPresentChanged and |
| 775 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. | 797 // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called. |
| 776 adapter_properties.address.ReplaceValue(adapter_address); | 798 adapter_properties.address.ReplaceValue(adapter_address); |
| 777 | 799 |
| 778 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 800 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 779 .Times(1); | 801 .Times(1); |
| 780 | 802 |
| 781 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | 803 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) |
| 782 .Times(1); | 804 .Times(1); |
| 783 | 805 |
| 784 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 806 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 785 ->AdapterPropertyChanged(adapter_path, | 807 ->AdapterPropertyChanged(adapter_path, |
| 786 adapter_properties.address.name()); | 808 adapter_properties.address.name()); |
| 787 | 809 |
| 788 // Adapter should now have the correct property value. | 810 // Adapter should now have the correct property value. |
| 789 EXPECT_TRUE(adapter->IsPowered()); | 811 EXPECT_TRUE(adapter_->IsPowered()); |
| 790 } | 812 } |
| 791 | 813 |
| 792 TEST_F(BluetoothAdapterChromeOsTest, | 814 TEST_F(BluetoothAdapterChromeOsTest, |
| 793 DefaultAdapterPoweredPropertyResetOnReplace) { | 815 DefaultAdapterPoweredPropertyResetOnReplace) { |
| 794 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 816 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 795 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 817 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 796 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 818 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 797 const std::string new_adapter_address = "00:C0:11:CO:FE:FE"; | 819 const std::string new_adapter_address = "00:C0:11:CO:FE:FE"; |
| 798 | 820 |
| 799 // Create the default adapter instance; | 821 // Create the default adapter instance; |
| 800 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 822 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 801 // a callback to obtain the adapter path. | 823 // a callback to obtain the adapter path. |
| 802 BluetoothManagerClient::AdapterCallback adapter_callback; | 824 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 803 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 825 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 804 .WillOnce(SaveArg<0>(&adapter_callback)); | 826 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 805 | 827 |
| 806 scoped_refptr<BluetoothAdapter> adapter = | 828 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 807 BluetoothAdapterFactory::DefaultAdapter(); | 829 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 830 base::Unretained(this))); |
| 808 | 831 |
| 809 // Call the adapter callback; | 832 // Call the adapter callback; |
| 810 // BluetoothAdapterClient::GetProperties will be called once to obtain | 833 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 811 // the property set. | 834 // the property set. |
| 812 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 835 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 813 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 836 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 814 initial_adapter_properties.powered.ReplaceValue(true); | 837 initial_adapter_properties.powered.ReplaceValue(true); |
| 815 | 838 |
| 816 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 839 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 817 .WillRepeatedly(Return(&initial_adapter_properties)); | 840 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 818 | 841 |
| 819 adapter_callback.Run(initial_adapter_path, true); | 842 adapter_callback.Run(initial_adapter_path, true); |
| 820 | 843 |
| 821 // Tell the adapter the default adapter changed; | 844 // Tell the adapter the default adapter changed; |
| 822 // BluetoothAdapterClient::GetProperties will be called once to obtain | 845 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 823 // the property set. | 846 // the property set. |
| 824 MockBluetoothAdapterClient::Properties new_adapter_properties; | 847 MockBluetoothAdapterClient::Properties new_adapter_properties; |
| 825 new_adapter_properties.address.ReplaceValue(new_adapter_address); | 848 new_adapter_properties.address.ReplaceValue(new_adapter_address); |
| 826 | 849 |
| 827 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | 850 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) |
| 828 .WillRepeatedly(Return(&new_adapter_properties)); | 851 .WillRepeatedly(Return(&new_adapter_properties)); |
| 829 | 852 |
| 830 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | 853 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. |
| 831 MockBluetoothAdapter::Observer adapter_observer; | 854 MockBluetoothAdapter::Observer adapter_observer; |
| 832 adapter->AddObserver(&adapter_observer); | 855 adapter_->AddObserver(&adapter_observer); |
| 833 | 856 |
| 834 { | 857 { |
| 835 InSequence s; | 858 InSequence s; |
| 836 | 859 |
| 837 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 860 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 838 .Times(1); | 861 .Times(1); |
| 839 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 862 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 840 .Times(1); | 863 .Times(1); |
| 841 } | 864 } |
| 842 | 865 |
| 843 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), false)) | 866 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false)) |
| 844 .Times(1); | 867 .Times(1); |
| 845 | 868 |
| 846 BluetoothAdapterChromeOs* adapter_chromeos = | 869 BluetoothAdapterChromeOs* adapter_chromeos = |
| 847 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 870 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 848 | 871 |
| 849 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 872 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 850 ->DefaultAdapterChanged(new_adapter_path); | 873 ->DefaultAdapterChanged(new_adapter_path); |
| 851 | 874 |
| 852 // Adapter should have the new property value. | 875 // Adapter should have the new property value. |
| 853 EXPECT_FALSE(adapter->IsPowered()); | 876 EXPECT_FALSE(adapter_->IsPowered()); |
| 854 } | 877 } |
| 855 | 878 |
| 856 TEST_F(BluetoothAdapterChromeOsTest, | 879 TEST_F(BluetoothAdapterChromeOsTest, |
| 857 DefaultAdapterPoweredPropertyResetOnReplaceWhenTrue) { | 880 DefaultAdapterPoweredPropertyResetOnReplaceWhenTrue) { |
| 858 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 881 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 859 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 882 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 860 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 883 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 861 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | 884 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; |
| 862 | 885 |
| 863 // Create the default adapter instance; | 886 // Create the default adapter instance; |
| 864 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 887 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 865 // a callback to obtain the adapter path. | 888 // a callback to obtain the adapter path. |
| 866 BluetoothManagerClient::AdapterCallback adapter_callback; | 889 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 867 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 890 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 868 .WillOnce(SaveArg<0>(&adapter_callback)); | 891 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 869 | 892 |
| 870 scoped_refptr<BluetoothAdapter> adapter = | 893 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 871 BluetoothAdapterFactory::DefaultAdapter(); | 894 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 895 base::Unretained(this))); |
| 872 | 896 |
| 873 // Call the adapter callback; | 897 // Call the adapter callback; |
| 874 // BluetoothAdapterClient::GetProperties will be called once to obtain | 898 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 875 // the property set. | 899 // the property set. |
| 876 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 900 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 877 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 901 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 878 initial_adapter_properties.powered.ReplaceValue(true); | 902 initial_adapter_properties.powered.ReplaceValue(true); |
| 879 | 903 |
| 880 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 904 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 881 .WillRepeatedly(Return(&initial_adapter_properties)); | 905 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 882 | 906 |
| 883 adapter_callback.Run(initial_adapter_path, true); | 907 adapter_callback.Run(initial_adapter_path, true); |
| 884 | 908 |
| 885 // Tell the adapter the default adapter changed; | 909 // Tell the adapter the default adapter changed; |
| 886 // BluetoothAdapterClient::GetProperties will be called once to obtain | 910 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 887 // the property set. | 911 // the property set. |
| 888 MockBluetoothAdapterClient::Properties new_adapter_properties; | 912 MockBluetoothAdapterClient::Properties new_adapter_properties; |
| 889 new_adapter_properties.address.ReplaceValue(new_adapter_address); | 913 new_adapter_properties.address.ReplaceValue(new_adapter_address); |
| 890 new_adapter_properties.powered.ReplaceValue(true); | 914 new_adapter_properties.powered.ReplaceValue(true); |
| 891 | 915 |
| 892 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | 916 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) |
| 893 .WillRepeatedly(Return(&new_adapter_properties)); | 917 .WillRepeatedly(Return(&new_adapter_properties)); |
| 894 | 918 |
| 895 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called once | 919 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called once |
| 896 // to set the value to false for the previous adapter and once to set the | 920 // to set the value to false for the previous adapter and once to set the |
| 897 // value to true for the new adapter. | 921 // value to true for the new adapter. |
| 898 MockBluetoothAdapter::Observer adapter_observer; | 922 MockBluetoothAdapter::Observer adapter_observer; |
| 899 adapter->AddObserver(&adapter_observer); | 923 adapter_->AddObserver(&adapter_observer); |
| 900 | 924 |
| 901 { | 925 { |
| 902 InSequence s; | 926 InSequence s; |
| 903 | 927 |
| 904 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 928 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 905 .Times(1); | 929 .Times(1); |
| 906 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 930 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 907 .Times(1); | 931 .Times(1); |
| 908 } | 932 } |
| 909 | 933 |
| 910 { | 934 { |
| 911 InSequence s; | 935 InSequence s; |
| 912 | 936 |
| 913 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), false)) | 937 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false)) |
| 914 .Times(1); | 938 .Times(1); |
| 915 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), true)) | 939 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true)) |
| 916 .Times(1); | 940 .Times(1); |
| 917 } | 941 } |
| 918 | 942 |
| 919 BluetoothAdapterChromeOs* adapter_chromeos = | 943 BluetoothAdapterChromeOs* adapter_chromeos = |
| 920 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 944 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 921 | 945 |
| 922 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 946 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 923 ->DefaultAdapterChanged(new_adapter_path); | 947 ->DefaultAdapterChanged(new_adapter_path); |
| 924 | 948 |
| 925 // Adapter should have the new property value. | 949 // Adapter should have the new property value. |
| 926 EXPECT_TRUE(adapter->IsPowered()); | 950 EXPECT_TRUE(adapter_->IsPowered()); |
| 927 } | 951 } |
| 928 | 952 |
| 929 TEST_F(BluetoothAdapterChromeOsTest, | 953 TEST_F(BluetoothAdapterChromeOsTest, |
| 930 DefaultAdapterPoweredPropertyResetOnRemove) { | 954 DefaultAdapterPoweredPropertyResetOnRemove) { |
| 931 const dbus::ObjectPath adapter_path("/fake/hci0"); | 955 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 932 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 956 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 933 | 957 |
| 934 // Create the default adapter instance; | 958 // Create the default adapter instance; |
| 935 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 959 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 936 // a callback to obtain the adapter path. | 960 // a callback to obtain the adapter path. |
| 937 BluetoothManagerClient::AdapterCallback adapter_callback; | 961 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 938 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 962 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 939 .WillOnce(SaveArg<0>(&adapter_callback)); | 963 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 940 | 964 |
| 941 scoped_refptr<BluetoothAdapter> adapter = | 965 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 942 BluetoothAdapterFactory::DefaultAdapter(); | 966 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 967 base::Unretained(this))); |
| 943 | 968 |
| 944 // Call the adapter callback; | 969 // Call the adapter callback; |
| 945 // BluetoothAdapterClient::GetProperties will be called once to obtain | 970 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 946 // the property set. | 971 // the property set. |
| 947 MockBluetoothAdapterClient::Properties adapter_properties; | 972 MockBluetoothAdapterClient::Properties adapter_properties; |
| 948 adapter_properties.address.ReplaceValue(adapter_address); | 973 adapter_properties.address.ReplaceValue(adapter_address); |
| 949 adapter_properties.powered.ReplaceValue(true); | 974 adapter_properties.powered.ReplaceValue(true); |
| 950 | 975 |
| 951 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 976 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 952 .WillRepeatedly(Return(&adapter_properties)); | 977 .WillRepeatedly(Return(&adapter_properties)); |
| 953 | 978 |
| 954 adapter_callback.Run(adapter_path, true); | 979 adapter_callback.Run(adapter_path, true); |
| 955 | 980 |
| 956 // Report that the adapter has been removed; | 981 // Report that the adapter has been removed; |
| 957 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. | 982 // BluetoothAdapter::Observer::AdapterPoweredChanged will be called. |
| 958 MockBluetoothAdapter::Observer adapter_observer; | 983 MockBluetoothAdapter::Observer adapter_observer; |
| 959 adapter->AddObserver(&adapter_observer); | 984 adapter_->AddObserver(&adapter_observer); |
| 960 | 985 |
| 961 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 986 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 962 .Times(1); | 987 .Times(1); |
| 963 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter.get(), false)) | 988 EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false)) |
| 964 .Times(1); | 989 .Times(1); |
| 965 | 990 |
| 966 BluetoothAdapterChromeOs* adapter_chromeos = | 991 BluetoothAdapterChromeOs* adapter_chromeos = |
| 967 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 992 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 968 | 993 |
| 969 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 994 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 970 ->AdapterRemoved(adapter_path); | 995 ->AdapterRemoved(adapter_path); |
| 971 | 996 |
| 972 // Adapter should have the new property value. | 997 // Adapter should have the new property value. |
| 973 EXPECT_FALSE(adapter->IsPowered()); | 998 EXPECT_FALSE(adapter_->IsPowered()); |
| 974 } | 999 } |
| 975 | 1000 |
| 976 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterSetPowered) { | 1001 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterSetPowered) { |
| 977 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1002 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 978 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1003 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 979 | 1004 |
| 980 // Create the default adapter instance; | 1005 // Create the default adapter instance; |
| 981 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1006 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 982 // a callback to obtain the adapter path. | 1007 // a callback to obtain the adapter path. |
| 983 BluetoothManagerClient::AdapterCallback adapter_callback; | 1008 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 984 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1009 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 985 .WillOnce(SaveArg<0>(&adapter_callback)); | 1010 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 986 | 1011 |
| 987 scoped_refptr<BluetoothAdapter> adapter = | 1012 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 988 BluetoothAdapterFactory::DefaultAdapter(); | 1013 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1014 base::Unretained(this))); |
| 989 | 1015 |
| 990 // Call the adapter callback; | 1016 // Call the adapter callback; |
| 991 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1017 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 992 // the property set. | 1018 // the property set. |
| 993 MockBluetoothAdapterClient::Properties adapter_properties; | 1019 MockBluetoothAdapterClient::Properties adapter_properties; |
| 994 | 1020 |
| 995 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1021 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 996 .WillRepeatedly(Return(&adapter_properties)); | 1022 .WillRepeatedly(Return(&adapter_properties)); |
| 997 | 1023 |
| 998 adapter_callback.Run(adapter_path, true); | 1024 adapter_callback.Run(adapter_path, true); |
| 999 | 1025 |
| 1000 // Request that the powered property be changed; | 1026 // Request that the powered property be changed; |
| 1001 // MockBluetoothAdapterClient::Set should be called, passing the address | 1027 // MockBluetoothAdapterClient::Set should be called, passing the address |
| 1002 // of the powered property and a callback to receive the response. | 1028 // of the powered property and a callback to receive the response. |
| 1003 dbus::PropertySet::SetCallback set_callback; | 1029 dbus::PropertySet::SetCallback set_callback; |
| 1004 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) | 1030 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) |
| 1005 .WillOnce(SaveArg<1>(&set_callback)); | 1031 .WillOnce(SaveArg<1>(&set_callback)); |
| 1006 | 1032 |
| 1007 adapter->SetPowered(true, | 1033 adapter_->SetPowered(true, |
| 1008 base::Bind(&BluetoothAdapterChromeOsTest::SetCallback, | 1034 base::Bind(&BluetoothAdapterChromeOsTest::SetCallback, |
| 1009 base::Unretained(this)), | 1035 base::Unretained(this)), |
| 1010 base::Bind(&BluetoothAdapterChromeOsTest::ErrorCallback, | 1036 base::Bind(&BluetoothAdapterChromeOsTest::ErrorCallback, |
| 1011 base::Unretained(this))); | 1037 base::Unretained(this))); |
| 1012 | 1038 |
| 1013 // Reply to the callback to indicate success, the set callback we provided | 1039 // Reply to the callback to indicate success, the set callback we provided |
| 1014 // should be called but the properties should not be refetched. | 1040 // should be called but the properties should not be refetched. |
| 1015 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1041 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1016 .Times(0); | 1042 .Times(0); |
| 1017 | 1043 |
| 1018 set_callback.Run(true); | 1044 set_callback.Run(true); |
| 1019 | 1045 |
| 1020 EXPECT_TRUE(set_callback_called_); | 1046 EXPECT_TRUE(set_callback_called_); |
| 1021 EXPECT_FALSE(error_callback_called_); | 1047 EXPECT_FALSE(error_callback_called_); |
| 1022 } | 1048 } |
| 1023 | 1049 |
| 1024 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterSetPoweredError) { | 1050 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterSetPoweredError) { |
| 1025 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1051 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1026 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1052 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1027 | 1053 |
| 1028 // Create the default adapter instance; | 1054 // Create the default adapter instance; |
| 1029 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1055 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1030 // a callback to obtain the adapter path. | 1056 // a callback to obtain the adapter path. |
| 1031 BluetoothManagerClient::AdapterCallback adapter_callback; | 1057 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1032 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1058 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1033 .WillOnce(SaveArg<0>(&adapter_callback)); | 1059 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1034 | 1060 |
| 1035 scoped_refptr<BluetoothAdapter> adapter = | 1061 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1036 BluetoothAdapterFactory::DefaultAdapter(); | 1062 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1063 base::Unretained(this))); |
| 1037 | 1064 |
| 1038 // Call the adapter callback; | 1065 // Call the adapter callback; |
| 1039 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1066 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1040 // the property set. | 1067 // the property set. |
| 1041 MockBluetoothAdapterClient::Properties adapter_properties; | 1068 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1042 | 1069 |
| 1043 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1070 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1044 .WillRepeatedly(Return(&adapter_properties)); | 1071 .WillRepeatedly(Return(&adapter_properties)); |
| 1045 | 1072 |
| 1046 adapter_callback.Run(adapter_path, true); | 1073 adapter_callback.Run(adapter_path, true); |
| 1047 | 1074 |
| 1048 // Request that the powered property be changed; | 1075 // Request that the powered property be changed; |
| 1049 // MockBluetoothAdapterClient::Set should be called, passing the address | 1076 // MockBluetoothAdapterClient::Set should be called, passing the address |
| 1050 // of the powered property and a callback to receive the response. | 1077 // of the powered property and a callback to receive the response. |
| 1051 dbus::PropertySet::SetCallback set_callback; | 1078 dbus::PropertySet::SetCallback set_callback; |
| 1052 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) | 1079 EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _)) |
| 1053 .WillOnce(SaveArg<1>(&set_callback)); | 1080 .WillOnce(SaveArg<1>(&set_callback)); |
| 1054 | 1081 |
| 1055 adapter->SetPowered(true, | 1082 adapter_->SetPowered(true, |
| 1056 base::Bind(&BluetoothAdapterChromeOsTest::SetCallback, | 1083 base::Bind(&BluetoothAdapterChromeOsTest::SetCallback, |
| 1057 base::Unretained(this)), | 1084 base::Unretained(this)), |
| 1058 base::Bind(&BluetoothAdapterChromeOsTest::ErrorCallback, | 1085 base::Bind(&BluetoothAdapterChromeOsTest::ErrorCallback, |
| 1059 base::Unretained(this))); | 1086 base::Unretained(this))); |
| 1060 | 1087 |
| 1061 // Reply to the callback to indicate failure, the error callback we provided | 1088 // Reply to the callback to indicate failure, the error callback we provided |
| 1062 // should be called but the properties should not be refetched. | 1089 // should be called but the properties should not be refetched. |
| 1063 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1090 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1064 .Times(0); | 1091 .Times(0); |
| 1065 | 1092 |
| 1066 set_callback.Run(false); | 1093 set_callback.Run(false); |
| 1067 | 1094 |
| 1068 EXPECT_FALSE(set_callback_called_); | 1095 EXPECT_FALSE(set_callback_called_); |
| 1069 EXPECT_TRUE(error_callback_called_); | 1096 EXPECT_TRUE(error_callback_called_); |
| 1070 } | 1097 } |
| 1071 | 1098 |
| 1072 TEST_F(BluetoothAdapterChromeOsTest, | 1099 TEST_F(BluetoothAdapterChromeOsTest, |
| 1073 DefaultAdapterDiscoveringPropertyInitiallyFalse) { | 1100 DefaultAdapterDiscoveringPropertyInitiallyFalse) { |
| 1074 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1101 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1075 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1102 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1076 | 1103 |
| 1077 // Create the default adapter instance; | 1104 // Create the default adapter instance; |
| 1078 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1105 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1079 // a callback to obtain the adapter path. | 1106 // a callback to obtain the adapter path. |
| 1080 BluetoothManagerClient::AdapterCallback adapter_callback; | 1107 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1081 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1108 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1082 .WillOnce(SaveArg<0>(&adapter_callback)); | 1109 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1083 | 1110 |
| 1084 scoped_refptr<BluetoothAdapter> adapter = | 1111 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1085 BluetoothAdapterFactory::DefaultAdapter(); | 1112 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1113 base::Unretained(this))); |
| 1086 | 1114 |
| 1087 // Call the adapter callback; | 1115 // Call the adapter callback; |
| 1088 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1116 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1089 // the property set. | 1117 // the property set. |
| 1090 MockBluetoothAdapterClient::Properties adapter_properties; | 1118 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1091 adapter_properties.address.ReplaceValue(adapter_address); | 1119 adapter_properties.address.ReplaceValue(adapter_address); |
| 1092 adapter_properties.discovering.ReplaceValue(false); | 1120 adapter_properties.discovering.ReplaceValue(false); |
| 1093 | 1121 |
| 1094 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1122 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1095 .WillRepeatedly(Return(&adapter_properties)); | 1123 .WillRepeatedly(Return(&adapter_properties)); |
| 1096 | 1124 |
| 1097 adapter_callback.Run(adapter_path, true); | 1125 adapter_callback.Run(adapter_path, true); |
| 1098 | 1126 |
| 1099 // Adapter should have the correct property value. | 1127 // Adapter should have the correct property value. |
| 1100 EXPECT_FALSE(adapter->IsDiscovering()); | 1128 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1101 } | 1129 } |
| 1102 | 1130 |
| 1103 TEST_F(BluetoothAdapterChromeOsTest, | 1131 TEST_F(BluetoothAdapterChromeOsTest, |
| 1104 DefaultAdapterDiscoveringPropertyInitiallyTrue) { | 1132 DefaultAdapterDiscoveringPropertyInitiallyTrue) { |
| 1105 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1133 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1106 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1134 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1107 | 1135 |
| 1108 // Create the default adapter instance; | 1136 // Create the default adapter instance; |
| 1109 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1137 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1110 // a callback to obtain the adapter path. | 1138 // a callback to obtain the adapter path. |
| 1111 BluetoothManagerClient::AdapterCallback adapter_callback; | 1139 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1112 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1140 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1113 .WillOnce(SaveArg<0>(&adapter_callback)); | 1141 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1114 | 1142 |
| 1115 scoped_refptr<BluetoothAdapter> adapter = | 1143 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1116 BluetoothAdapterFactory::DefaultAdapter(); | 1144 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1145 base::Unretained(this))); |
| 1117 | 1146 |
| 1118 // Call the adapter callback; | 1147 // Call the adapter callback; |
| 1119 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1148 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1120 // the property set. | 1149 // the property set. |
| 1121 MockBluetoothAdapterClient::Properties adapter_properties; | 1150 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1122 adapter_properties.address.ReplaceValue(adapter_address); | 1151 adapter_properties.address.ReplaceValue(adapter_address); |
| 1123 adapter_properties.discovering.ReplaceValue(true); | 1152 adapter_properties.discovering.ReplaceValue(true); |
| 1124 | 1153 |
| 1125 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1154 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1126 .WillRepeatedly(Return(&adapter_properties)); | 1155 .WillRepeatedly(Return(&adapter_properties)); |
| 1127 | 1156 |
| 1128 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | 1157 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. |
| 1129 MockBluetoothAdapter::Observer adapter_observer; | 1158 MockBluetoothAdapter::Observer adapter_observer; |
| 1130 adapter->AddObserver(&adapter_observer); | 1159 adapter_->AddObserver(&adapter_observer); |
| 1131 | 1160 |
| 1132 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 1161 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 1133 .Times(1); | 1162 .Times(1); |
| 1134 | 1163 |
| 1135 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | 1164 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) |
| 1136 .Times(1); | 1165 .Times(1); |
| 1137 | 1166 |
| 1138 adapter_callback.Run(adapter_path, true); | 1167 adapter_callback.Run(adapter_path, true); |
| 1139 | 1168 |
| 1140 // Adapter should have the correct property value. | 1169 // Adapter should have the correct property value. |
| 1141 EXPECT_TRUE(adapter->IsDiscovering()); | 1170 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1142 } | 1171 } |
| 1143 | 1172 |
| 1144 TEST_F(BluetoothAdapterChromeOsTest, | 1173 TEST_F(BluetoothAdapterChromeOsTest, |
| 1145 DefaultAdapterDiscoveringPropertyInitiallyTrueWithoutAddress) { | 1174 DefaultAdapterDiscoveringPropertyInitiallyTrueWithoutAddress) { |
| 1146 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1175 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1147 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1176 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1148 | 1177 |
| 1149 // Create the default adapter instance; | 1178 // Create the default adapter instance; |
| 1150 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1179 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1151 // a callback to obtain the adapter path. | 1180 // a callback to obtain the adapter path. |
| 1152 BluetoothManagerClient::AdapterCallback adapter_callback; | 1181 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1153 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1182 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1154 .WillOnce(SaveArg<0>(&adapter_callback)); | 1183 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1155 | 1184 |
| 1156 scoped_refptr<BluetoothAdapter> adapter = | 1185 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1157 BluetoothAdapterFactory::DefaultAdapter(); | 1186 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1187 base::Unretained(this))); |
| 1158 | 1188 |
| 1159 // Call the adapter callback; | 1189 // Call the adapter callback; |
| 1160 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1190 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1161 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged | 1191 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged |
| 1162 // should not yet be called. | 1192 // should not yet be called. |
| 1163 MockBluetoothAdapterClient::Properties adapter_properties; | 1193 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1164 adapter_properties.discovering.ReplaceValue(true); | 1194 adapter_properties.discovering.ReplaceValue(true); |
| 1165 | 1195 |
| 1166 MockBluetoothAdapter::Observer adapter_observer; | 1196 MockBluetoothAdapter::Observer adapter_observer; |
| 1167 adapter->AddObserver(&adapter_observer); | 1197 adapter_->AddObserver(&adapter_observer); |
| 1168 | 1198 |
| 1169 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1199 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1170 .WillRepeatedly(Return(&adapter_properties)); | 1200 .WillRepeatedly(Return(&adapter_properties)); |
| 1171 | 1201 |
| 1172 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | 1202 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) |
| 1173 .Times(0); | 1203 .Times(0); |
| 1174 | 1204 |
| 1175 adapter_callback.Run(adapter_path, true); | 1205 adapter_callback.Run(adapter_path, true); |
| 1176 | 1206 |
| 1177 // Adapter should not yet have the property value. | 1207 // Adapter should not yet have the property value. |
| 1178 EXPECT_FALSE(adapter->IsDiscovering()); | 1208 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1179 | 1209 |
| 1180 // Tell the adapter the address now, | 1210 // Tell the adapter the address now, |
| 1181 // BluetoothAdapter::Observer::AdapterPresentChanged and | 1211 // BluetoothAdapter::Observer::AdapterPresentChanged and |
| 1182 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. | 1212 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. |
| 1183 adapter_properties.address.ReplaceValue(adapter_address); | 1213 adapter_properties.address.ReplaceValue(adapter_address); |
| 1184 | 1214 |
| 1185 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 1215 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 1186 .Times(1); | 1216 .Times(1); |
| 1187 | 1217 |
| 1188 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | 1218 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) |
| 1189 .Times(1); | 1219 .Times(1); |
| 1190 | 1220 |
| 1191 BluetoothAdapterChromeOs* adapter_chromeos = | 1221 BluetoothAdapterChromeOs* adapter_chromeos = |
| 1192 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 1222 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 1193 | 1223 |
| 1194 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 1224 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 1195 ->AdapterPropertyChanged(adapter_path, | 1225 ->AdapterPropertyChanged(adapter_path, |
| 1196 adapter_properties.address.name()); | 1226 adapter_properties.address.name()); |
| 1197 | 1227 |
| 1198 // Adapter should have the correct property value. | 1228 // Adapter should have the correct property value. |
| 1199 EXPECT_TRUE(adapter->IsDiscovering()); | 1229 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1200 } | 1230 } |
| 1201 | 1231 |
| 1202 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterDiscoveringPropertyChanged) { | 1232 TEST_F(BluetoothAdapterChromeOsTest, DefaultAdapterDiscoveringPropertyChanged) { |
| 1203 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1233 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1204 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1234 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1205 | 1235 |
| 1206 // Create the default adapter instance; | 1236 // Create the default adapter instance; |
| 1207 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1237 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1208 // a callback to obtain the adapter path. | 1238 // a callback to obtain the adapter path. |
| 1209 BluetoothManagerClient::AdapterCallback adapter_callback; | 1239 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1210 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1240 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1211 .WillOnce(SaveArg<0>(&adapter_callback)); | 1241 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1212 | 1242 |
| 1213 scoped_refptr<BluetoothAdapter> adapter = | 1243 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1214 BluetoothAdapterFactory::DefaultAdapter(); | 1244 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1245 base::Unretained(this))); |
| 1215 | 1246 |
| 1216 // Call the adapter callback; | 1247 // Call the adapter callback; |
| 1217 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1248 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1218 // the property set. | 1249 // the property set. |
| 1219 MockBluetoothAdapterClient::Properties adapter_properties; | 1250 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1220 adapter_properties.address.ReplaceValue(adapter_address); | 1251 adapter_properties.address.ReplaceValue(adapter_address); |
| 1221 adapter_properties.discovering.ReplaceValue(false); | 1252 adapter_properties.discovering.ReplaceValue(false); |
| 1222 | 1253 |
| 1223 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1254 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1224 .WillRepeatedly(Return(&adapter_properties)); | 1255 .WillRepeatedly(Return(&adapter_properties)); |
| 1225 | 1256 |
| 1226 adapter_callback.Run(adapter_path, true); | 1257 adapter_callback.Run(adapter_path, true); |
| 1227 | 1258 |
| 1228 // Adapter should have the correct property value. | 1259 // Adapter should have the correct property value. |
| 1229 EXPECT_FALSE(adapter->IsDiscovering()); | 1260 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1230 | 1261 |
| 1231 // Report that the property has been changed; | 1262 // Report that the property has been changed; |
| 1232 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | 1263 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. |
| 1233 MockBluetoothAdapter::Observer adapter_observer; | 1264 MockBluetoothAdapter::Observer adapter_observer; |
| 1234 adapter->AddObserver(&adapter_observer); | 1265 adapter_->AddObserver(&adapter_observer); |
| 1235 | 1266 |
| 1236 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | 1267 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) |
| 1237 .Times(1); | 1268 .Times(1); |
| 1238 | 1269 |
| 1239 adapter_properties.discovering.ReplaceValue(true); | 1270 adapter_properties.discovering.ReplaceValue(true); |
| 1240 | 1271 |
| 1241 BluetoothAdapterChromeOs* adapter_chromeos = | 1272 BluetoothAdapterChromeOs* adapter_chromeos = |
| 1242 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 1273 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 1243 | 1274 |
| 1244 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 1275 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 1245 ->AdapterPropertyChanged(adapter_path, | 1276 ->AdapterPropertyChanged(adapter_path, |
| 1246 adapter_properties.discovering.name()); | 1277 adapter_properties.discovering.name()); |
| 1247 | 1278 |
| 1248 // Adapter should have the new property values. | 1279 // Adapter should have the new property values. |
| 1249 EXPECT_TRUE(adapter->IsDiscovering()); | 1280 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1250 } | 1281 } |
| 1251 | 1282 |
| 1252 TEST_F(BluetoothAdapterChromeOsTest, | 1283 TEST_F(BluetoothAdapterChromeOsTest, |
| 1253 DefaultAdapterDiscoveringPropertyUnchanged) { | 1284 DefaultAdapterDiscoveringPropertyUnchanged) { |
| 1254 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1285 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1255 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1286 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1256 | 1287 |
| 1257 // Create the default adapter instance; | 1288 // Create the default adapter instance; |
| 1258 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1289 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1259 // a callback to obtain the adapter path. | 1290 // a callback to obtain the adapter path. |
| 1260 BluetoothManagerClient::AdapterCallback adapter_callback; | 1291 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1261 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1292 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1262 .WillOnce(SaveArg<0>(&adapter_callback)); | 1293 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1263 | 1294 |
| 1264 scoped_refptr<BluetoothAdapter> adapter = | 1295 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1265 BluetoothAdapterFactory::DefaultAdapter(); | 1296 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1297 base::Unretained(this))); |
| 1266 | 1298 |
| 1267 // Call the adapter callback; | 1299 // Call the adapter callback; |
| 1268 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1300 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1269 // the property set. | 1301 // the property set. |
| 1270 MockBluetoothAdapterClient::Properties adapter_properties; | 1302 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1271 adapter_properties.address.ReplaceValue(adapter_address); | 1303 adapter_properties.address.ReplaceValue(adapter_address); |
| 1272 adapter_properties.discovering.ReplaceValue(true); | 1304 adapter_properties.discovering.ReplaceValue(true); |
| 1273 | 1305 |
| 1274 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1306 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1275 .WillRepeatedly(Return(&adapter_properties)); | 1307 .WillRepeatedly(Return(&adapter_properties)); |
| 1276 | 1308 |
| 1277 adapter_callback.Run(adapter_path, true); | 1309 adapter_callback.Run(adapter_path, true); |
| 1278 | 1310 |
| 1279 // Adapter should have the correct property value. | 1311 // Adapter should have the correct property value. |
| 1280 EXPECT_TRUE(adapter->IsDiscovering()); | 1312 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1281 | 1313 |
| 1282 // Report that the property has been changed, but don't change the value; | 1314 // Report that the property has been changed, but don't change the value; |
| 1283 // BluetoothAdapter::Observer::AdapterDiscoveringChanged should not be | 1315 // BluetoothAdapter::Observer::AdapterDiscoveringChanged should not be |
| 1284 // called. | 1316 // called. |
| 1285 MockBluetoothAdapter::Observer adapter_observer; | 1317 MockBluetoothAdapter::Observer adapter_observer; |
| 1286 adapter->AddObserver(&adapter_observer); | 1318 adapter_->AddObserver(&adapter_observer); |
| 1287 | 1319 |
| 1288 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | 1320 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) |
| 1289 .Times(0); | 1321 .Times(0); |
| 1290 | 1322 |
| 1291 BluetoothAdapterChromeOs* adapter_chromeos = | 1323 BluetoothAdapterChromeOs* adapter_chromeos = |
| 1292 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 1324 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 1293 | 1325 |
| 1294 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 1326 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 1295 ->AdapterPropertyChanged(adapter_path, | 1327 ->AdapterPropertyChanged(adapter_path, |
| 1296 adapter_properties.discovering.name()); | 1328 adapter_properties.discovering.name()); |
| 1297 | 1329 |
| 1298 // Adapter should still have the same property values. | 1330 // Adapter should still have the same property values. |
| 1299 EXPECT_TRUE(adapter->IsDiscovering()); | 1331 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1300 } | 1332 } |
| 1301 | 1333 |
| 1302 TEST_F(BluetoothAdapterChromeOsTest, | 1334 TEST_F(BluetoothAdapterChromeOsTest, |
| 1303 DefaultAdapterDiscoveringPropertyChangedWithoutAddress) { | 1335 DefaultAdapterDiscoveringPropertyChangedWithoutAddress) { |
| 1304 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1336 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1305 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1337 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1306 | 1338 |
| 1307 // Create the default adapter instance; | 1339 // Create the default adapter instance; |
| 1308 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1340 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1309 // a callback to obtain the adapter path. | 1341 // a callback to obtain the adapter path. |
| 1310 BluetoothManagerClient::AdapterCallback adapter_callback; | 1342 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1311 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1343 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1312 .WillOnce(SaveArg<0>(&adapter_callback)); | 1344 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1313 | 1345 |
| 1314 scoped_refptr<BluetoothAdapter> adapter = | 1346 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1315 BluetoothAdapterFactory::DefaultAdapter(); | 1347 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1348 base::Unretained(this))); |
| 1316 | 1349 |
| 1317 // Call the adapter callback; | 1350 // Call the adapter callback; |
| 1318 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1351 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1319 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged | 1352 // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged |
| 1320 // should not yet be called. | 1353 // should not yet be called. |
| 1321 MockBluetoothAdapterClient::Properties adapter_properties; | 1354 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1322 | 1355 |
| 1323 MockBluetoothAdapter::Observer adapter_observer; | 1356 MockBluetoothAdapter::Observer adapter_observer; |
| 1324 adapter->AddObserver(&adapter_observer); | 1357 adapter_->AddObserver(&adapter_observer); |
| 1325 | 1358 |
| 1326 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1359 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1327 .WillRepeatedly(Return(&adapter_properties)); | 1360 .WillRepeatedly(Return(&adapter_properties)); |
| 1328 | 1361 |
| 1329 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | 1362 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) |
| 1330 .Times(0); | 1363 .Times(0); |
| 1331 | 1364 |
| 1332 adapter_callback.Run(adapter_path, true); | 1365 adapter_callback.Run(adapter_path, true); |
| 1333 | 1366 |
| 1334 // Tell the adapter that its discovering property changed, the observer | 1367 // Tell the adapter that its discovering property changed, the observer |
| 1335 // method should still not be called because there is no address for | 1368 // method should still not be called because there is no address for |
| 1336 // the adapter so it is not present. | 1369 // the adapter so it is not present. |
| 1337 adapter_properties.discovering.ReplaceValue(true); | 1370 adapter_properties.discovering.ReplaceValue(true); |
| 1338 | 1371 |
| 1339 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), _)) | 1372 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _)) |
| 1340 .Times(0); | 1373 .Times(0); |
| 1341 | 1374 |
| 1342 BluetoothAdapterChromeOs* adapter_chromeos = | 1375 BluetoothAdapterChromeOs* adapter_chromeos = |
| 1343 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 1376 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 1344 | 1377 |
| 1345 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 1378 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 1346 ->AdapterPropertyChanged(adapter_path, | 1379 ->AdapterPropertyChanged(adapter_path, |
| 1347 adapter_properties.discovering.name()); | 1380 adapter_properties.discovering.name()); |
| 1348 | 1381 |
| 1349 // Adapter should not yet have the property value. | 1382 // Adapter should not yet have the property value. |
| 1350 EXPECT_FALSE(adapter->IsDiscovering()); | 1383 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1351 | 1384 |
| 1352 // Tell the adapter the address now, | 1385 // Tell the adapter the address now, |
| 1353 // BluetoothAdapter::Observer::AdapterPresentChanged and | 1386 // BluetoothAdapter::Observer::AdapterPresentChanged and |
| 1354 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. | 1387 // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called. |
| 1355 adapter_properties.address.ReplaceValue(adapter_address); | 1388 adapter_properties.address.ReplaceValue(adapter_address); |
| 1356 | 1389 |
| 1357 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 1390 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 1358 .Times(1); | 1391 .Times(1); |
| 1359 | 1392 |
| 1360 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), true)) | 1393 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true)) |
| 1361 .Times(1); | 1394 .Times(1); |
| 1362 | 1395 |
| 1363 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) | 1396 static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos) |
| 1364 ->AdapterPropertyChanged(adapter_path, | 1397 ->AdapterPropertyChanged(adapter_path, |
| 1365 adapter_properties.address.name()); | 1398 adapter_properties.address.name()); |
| 1366 | 1399 |
| 1367 // Adapter should now have the correct property value. | 1400 // Adapter should now have the correct property value. |
| 1368 EXPECT_TRUE(adapter->IsDiscovering()); | 1401 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1369 } | 1402 } |
| 1370 | 1403 |
| 1371 TEST_F(BluetoothAdapterChromeOsTest, | 1404 TEST_F(BluetoothAdapterChromeOsTest, |
| 1372 DefaultAdapterDiscoveringPropertyResetOnReplace) { | 1405 DefaultAdapterDiscoveringPropertyResetOnReplace) { |
| 1373 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 1406 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 1374 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 1407 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 1375 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 1408 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1376 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | 1409 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; |
| 1377 | 1410 |
| 1378 // Create the default adapter instance; | 1411 // Create the default adapter instance; |
| 1379 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1412 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1380 // a callback to obtain the adapter path. | 1413 // a callback to obtain the adapter path. |
| 1381 BluetoothManagerClient::AdapterCallback adapter_callback; | 1414 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1382 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1415 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1383 .WillOnce(SaveArg<0>(&adapter_callback)); | 1416 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1384 | 1417 |
| 1385 scoped_refptr<BluetoothAdapter> adapter = | 1418 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1386 BluetoothAdapterFactory::DefaultAdapter(); | 1419 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1420 base::Unretained(this))); |
| 1387 | 1421 |
| 1388 // Call the adapter callback; | 1422 // Call the adapter callback; |
| 1389 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1423 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1390 // the property set. | 1424 // the property set. |
| 1391 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 1425 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 1392 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 1426 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 1393 initial_adapter_properties.discovering.ReplaceValue(true); | 1427 initial_adapter_properties.discovering.ReplaceValue(true); |
| 1394 | 1428 |
| 1395 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 1429 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 1396 .WillRepeatedly(Return(&initial_adapter_properties)); | 1430 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 1397 | 1431 |
| 1398 adapter_callback.Run(initial_adapter_path, true); | 1432 adapter_callback.Run(initial_adapter_path, true); |
| 1399 | 1433 |
| 1400 // Tell the adapter the default adapter changed; | 1434 // Tell the adapter the default adapter changed; |
| 1401 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1435 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1402 // the property set. | 1436 // the property set. |
| 1403 MockBluetoothAdapterClient::Properties new_adapter_properties; | 1437 MockBluetoothAdapterClient::Properties new_adapter_properties; |
| 1404 new_adapter_properties.address.ReplaceValue(new_adapter_address); | 1438 new_adapter_properties.address.ReplaceValue(new_adapter_address); |
| 1405 | 1439 |
| 1406 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | 1440 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) |
| 1407 .WillRepeatedly(Return(&new_adapter_properties)); | 1441 .WillRepeatedly(Return(&new_adapter_properties)); |
| 1408 | 1442 |
| 1409 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | 1443 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. |
| 1410 MockBluetoothAdapter::Observer adapter_observer; | 1444 MockBluetoothAdapter::Observer adapter_observer; |
| 1411 adapter->AddObserver(&adapter_observer); | 1445 adapter_->AddObserver(&adapter_observer); |
| 1412 | 1446 |
| 1413 { | 1447 { |
| 1414 InSequence s; | 1448 InSequence s; |
| 1415 | 1449 |
| 1416 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 1450 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 1417 .Times(1); | 1451 .Times(1); |
| 1418 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 1452 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 1419 .Times(1); | 1453 .Times(1); |
| 1420 } | 1454 } |
| 1421 | 1455 |
| 1422 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), false)) | 1456 EXPECT_CALL(adapter_observer, |
| 1457 AdapterDiscoveringChanged(adapter_.get(), false)) |
| 1423 .Times(1); | 1458 .Times(1); |
| 1424 | 1459 |
| 1425 BluetoothAdapterChromeOs* adapter_chromeos = | 1460 BluetoothAdapterChromeOs* adapter_chromeos = |
| 1426 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 1461 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 1427 | 1462 |
| 1428 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 1463 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 1429 ->DefaultAdapterChanged(new_adapter_path); | 1464 ->DefaultAdapterChanged(new_adapter_path); |
| 1430 | 1465 |
| 1431 // Adapter should have the new property value. | 1466 // Adapter should have the new property value. |
| 1432 EXPECT_FALSE(adapter->IsDiscovering()); | 1467 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1433 } | 1468 } |
| 1434 | 1469 |
| 1435 TEST_F(BluetoothAdapterChromeOsTest, | 1470 TEST_F(BluetoothAdapterChromeOsTest, |
| 1436 DefaultAdapterDiscoveringPropertyResetOnReplaceWhenTrue) { | 1471 DefaultAdapterDiscoveringPropertyResetOnReplaceWhenTrue) { |
| 1437 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); | 1472 const dbus::ObjectPath initial_adapter_path("/fake/hci0"); |
| 1438 const dbus::ObjectPath new_adapter_path("/fake/hci1"); | 1473 const dbus::ObjectPath new_adapter_path("/fake/hci1"); |
| 1439 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; | 1474 const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1440 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; | 1475 const std::string new_adapter_address = "BA:C0:11:CO:FE:FE"; |
| 1441 | 1476 |
| 1442 // Create the default adapter instance; | 1477 // Create the default adapter instance; |
| 1443 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1478 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1444 // a callback to obtain the adapter path. | 1479 // a callback to obtain the adapter path. |
| 1445 BluetoothManagerClient::AdapterCallback adapter_callback; | 1480 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1446 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1481 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1447 .WillOnce(SaveArg<0>(&adapter_callback)); | 1482 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1448 | 1483 |
| 1449 scoped_refptr<BluetoothAdapter> adapter = | 1484 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1450 BluetoothAdapterFactory::DefaultAdapter(); | 1485 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1486 base::Unretained(this))); |
| 1451 | 1487 |
| 1452 // Call the adapter callback; | 1488 // Call the adapter callback; |
| 1453 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1489 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1454 // the property set. | 1490 // the property set. |
| 1455 MockBluetoothAdapterClient::Properties initial_adapter_properties; | 1491 MockBluetoothAdapterClient::Properties initial_adapter_properties; |
| 1456 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); | 1492 initial_adapter_properties.address.ReplaceValue(initial_adapter_address); |
| 1457 initial_adapter_properties.discovering.ReplaceValue(true); | 1493 initial_adapter_properties.discovering.ReplaceValue(true); |
| 1458 | 1494 |
| 1459 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) | 1495 EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path)) |
| 1460 .WillRepeatedly(Return(&initial_adapter_properties)); | 1496 .WillRepeatedly(Return(&initial_adapter_properties)); |
| 1461 | 1497 |
| 1462 adapter_callback.Run(initial_adapter_path, true); | 1498 adapter_callback.Run(initial_adapter_path, true); |
| 1463 | 1499 |
| 1464 // Tell the adapter the default adapter changed; | 1500 // Tell the adapter the default adapter changed; |
| 1465 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1501 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1466 // the property set. | 1502 // the property set. |
| 1467 MockBluetoothAdapterClient::Properties new_adapter_properties; | 1503 MockBluetoothAdapterClient::Properties new_adapter_properties; |
| 1468 new_adapter_properties.address.ReplaceValue(new_adapter_address); | 1504 new_adapter_properties.address.ReplaceValue(new_adapter_address); |
| 1469 new_adapter_properties.discovering.ReplaceValue(true); | 1505 new_adapter_properties.discovering.ReplaceValue(true); |
| 1470 | 1506 |
| 1471 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) | 1507 EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path)) |
| 1472 .WillRepeatedly(Return(&new_adapter_properties)); | 1508 .WillRepeatedly(Return(&new_adapter_properties)); |
| 1473 | 1509 |
| 1474 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called once | 1510 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called once |
| 1475 // to set the value to false for the previous adapter and once to set the | 1511 // to set the value to false for the previous adapter and once to set the |
| 1476 // value to true for the new adapter. | 1512 // value to true for the new adapter. |
| 1477 MockBluetoothAdapter::Observer adapter_observer; | 1513 MockBluetoothAdapter::Observer adapter_observer; |
| 1478 adapter->AddObserver(&adapter_observer); | 1514 adapter_->AddObserver(&adapter_observer); |
| 1479 | 1515 |
| 1480 { | 1516 { |
| 1481 InSequence s; | 1517 InSequence s; |
| 1482 | 1518 |
| 1483 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 1519 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 1484 .Times(1); | 1520 .Times(1); |
| 1485 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true)) | 1521 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true)) |
| 1486 .Times(1); | 1522 .Times(1); |
| 1487 } | 1523 } |
| 1488 | 1524 |
| 1489 { | 1525 { |
| 1490 InSequence s; | 1526 InSequence s; |
| 1491 | 1527 |
| 1492 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), | 1528 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), |
| 1493 false)) | 1529 false)) |
| 1494 .Times(1); | 1530 .Times(1); |
| 1495 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), | 1531 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), |
| 1496 true)) | 1532 true)) |
| 1497 .Times(1); | 1533 .Times(1); |
| 1498 } | 1534 } |
| 1499 | 1535 |
| 1500 BluetoothAdapterChromeOs* adapter_chromeos = | 1536 BluetoothAdapterChromeOs* adapter_chromeos = |
| 1501 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 1537 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 1502 | 1538 |
| 1503 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 1539 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 1504 ->DefaultAdapterChanged(new_adapter_path); | 1540 ->DefaultAdapterChanged(new_adapter_path); |
| 1505 | 1541 |
| 1506 // Adapter should have the new property value. | 1542 // Adapter should have the new property value. |
| 1507 EXPECT_TRUE(adapter->IsDiscovering()); | 1543 EXPECT_TRUE(adapter_->IsDiscovering()); |
| 1508 } | 1544 } |
| 1509 | 1545 |
| 1510 TEST_F(BluetoothAdapterChromeOsTest, | 1546 TEST_F(BluetoothAdapterChromeOsTest, |
| 1511 DefaultAdapterDiscoveringPropertyResetOnRemove) { | 1547 DefaultAdapterDiscoveringPropertyResetOnRemove) { |
| 1512 const dbus::ObjectPath adapter_path("/fake/hci0"); | 1548 const dbus::ObjectPath adapter_path("/fake/hci0"); |
| 1513 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; | 1549 const std::string adapter_address = "CA:FE:4A:C0:FE:FE"; |
| 1514 | 1550 |
| 1515 // Create the default adapter instance; | 1551 // Create the default adapter instance; |
| 1516 // BluetoothManagerClient::DefaultAdapter will be called once, passing | 1552 // BluetoothManagerClient::DefaultAdapter will be called once, passing |
| 1517 // a callback to obtain the adapter path. | 1553 // a callback to obtain the adapter path. |
| 1518 BluetoothManagerClient::AdapterCallback adapter_callback; | 1554 BluetoothManagerClient::AdapterCallback adapter_callback; |
| 1519 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) | 1555 EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_)) |
| 1520 .WillOnce(SaveArg<0>(&adapter_callback)); | 1556 .WillOnce(SaveArg<0>(&adapter_callback)); |
| 1521 | 1557 |
| 1522 scoped_refptr<BluetoothAdapter> adapter = | 1558 BluetoothAdapterFactory::RunCallbackOnAdapterReady( |
| 1523 BluetoothAdapterFactory::DefaultAdapter(); | 1559 base::Bind(&BluetoothAdapterChromeOsTest::SetAdapter, |
| 1560 base::Unretained(this))); |
| 1524 | 1561 |
| 1525 // Call the adapter callback; | 1562 // Call the adapter callback; |
| 1526 // BluetoothAdapterClient::GetProperties will be called once to obtain | 1563 // BluetoothAdapterClient::GetProperties will be called once to obtain |
| 1527 // the property set. | 1564 // the property set. |
| 1528 MockBluetoothAdapterClient::Properties adapter_properties; | 1565 MockBluetoothAdapterClient::Properties adapter_properties; |
| 1529 adapter_properties.address.ReplaceValue(adapter_address); | 1566 adapter_properties.address.ReplaceValue(adapter_address); |
| 1530 adapter_properties.discovering.ReplaceValue(true); | 1567 adapter_properties.discovering.ReplaceValue(true); |
| 1531 | 1568 |
| 1532 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) | 1569 EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path)) |
| 1533 .WillRepeatedly(Return(&adapter_properties)); | 1570 .WillRepeatedly(Return(&adapter_properties)); |
| 1534 | 1571 |
| 1535 adapter_callback.Run(adapter_path, true); | 1572 adapter_callback.Run(adapter_path, true); |
| 1536 | 1573 |
| 1537 // Report that the adapter has been removed; | 1574 // Report that the adapter has been removed; |
| 1538 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. | 1575 // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called. |
| 1539 MockBluetoothAdapter::Observer adapter_observer; | 1576 MockBluetoothAdapter::Observer adapter_observer; |
| 1540 adapter->AddObserver(&adapter_observer); | 1577 adapter_->AddObserver(&adapter_observer); |
| 1541 | 1578 |
| 1542 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false)) | 1579 EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false)) |
| 1543 .Times(1); | 1580 .Times(1); |
| 1544 EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter.get(), false)) | 1581 EXPECT_CALL(adapter_observer, |
| 1582 AdapterDiscoveringChanged(adapter_.get(), false)) |
| 1545 .Times(1); | 1583 .Times(1); |
| 1546 | 1584 |
| 1547 BluetoothAdapterChromeOs* adapter_chromeos = | 1585 BluetoothAdapterChromeOs* adapter_chromeos = |
| 1548 static_cast<BluetoothAdapterChromeOs*>(adapter.get()); | 1586 static_cast<BluetoothAdapterChromeOs*>(adapter_.get()); |
| 1549 | 1587 |
| 1550 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) | 1588 static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos) |
| 1551 ->AdapterRemoved(adapter_path); | 1589 ->AdapterRemoved(adapter_path); |
| 1552 | 1590 |
| 1553 // Adapter should have the new property value. | 1591 // Adapter should have the new property value. |
| 1554 EXPECT_FALSE(adapter->IsDiscovering()); | 1592 EXPECT_FALSE(adapter_->IsDiscovering()); |
| 1555 } | 1593 } |
| 1556 | 1594 |
| 1557 } // namespace chromeos | 1595 } // namespace chromeos |
| OLD | NEW |