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

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

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

Powered by Google App Engine
This is Rietveld 408576698