Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: chrome/browser/chromeos/bluetooth/bluetooth_adapter_dbus_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698