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