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