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