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

Side by Side Diff: device/bluetooth/bluetooth_audio_sink_chromeos_unittest.cc

Issue 939753004: device/bluetooth: Implement Unregister() of BlueotoothAudioSinkChromeOS and disconnection-related c… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 new uint16_t(FakeBluetoothMediaTransportClient::kTransportDelay)); 80 new uint16_t(FakeBluetoothMediaTransportClient::kTransportDelay));
81 properties_.volume.reset( 81 properties_.volume.reset(
82 new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume)); 82 new uint16_t(FakeBluetoothMediaTransportClient::kTransportVolume));
83 83
84 GetAdapter(); 84 GetAdapter();
85 } 85 }
86 86
87 void TearDown() override { 87 void TearDown() override {
88 callback_count_ = 0; 88 callback_count_ = 0;
89 error_callback_count_ = 0; 89 error_callback_count_ = 0;
90 observer_.reset();
90 91
91 // The adapter should outlive audio sink. 92 // The adapter should outlive audio sink.
92 audio_sink_ = nullptr; 93 audio_sink_ = nullptr;
93 adapter_ = nullptr; 94 adapter_ = nullptr;
94 DBusThreadManager::Shutdown(); 95 DBusThreadManager::Shutdown();
95 } 96 }
96 97
97 // Gets the existing Bluetooth adapter. 98 // Gets the existing Bluetooth adapter.
98 void GetAdapter() { 99 void GetAdapter() {
99 BluetoothAdapterFactory::GetAdapter( 100 BluetoothAdapterFactory::GetAdapter(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35})); 132 std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35}));
132 133
133 // Registers |audio_sink_| with valid codec and capabilities 134 // Registers |audio_sink_| with valid codec and capabilities
134 adapter_->RegisterAudioSink( 135 adapter_->RegisterAudioSink(
135 options, 136 options,
136 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterCallback, 137 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterCallback,
137 base::Unretained(this)), 138 base::Unretained(this)),
138 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback, 139 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback,
139 base::Unretained(this))); 140 base::Unretained(this)));
140 141
142 observer_.reset(new TestAudioSinkObserver(audio_sink_));
141 EXPECT_EQ(callback_count_, 1); 143 EXPECT_EQ(callback_count_, 1);
142 EXPECT_EQ(error_callback_count_, 0); 144 EXPECT_EQ(error_callback_count_, 0);
145 EXPECT_EQ(observer_->state_changed_count_, 0);
146 EXPECT_EQ(observer_->volume_changed_count_, 0);
147 }
148
149 void GetFakeMediaEndpoint() {
150 BluetoothAudioSinkChromeOS* audio_sink_chromeos =
151 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get());
152 ASSERT_NE(audio_sink_chromeos, nullptr);
153
154 media_endpoint_ = static_cast<FakeBluetoothMediaEndpointServiceProvider*>(
155 audio_sink_chromeos->GetEndpointServiceProvider());
143 } 156 }
144 157
145 // Called whenever RegisterAudioSink is completed successfully. 158 // Called whenever RegisterAudioSink is completed successfully.
146 void RegisterCallback( 159 void RegisterCallback(
147 scoped_refptr<BluetoothAudioSink> audio_sink) { 160 scoped_refptr<BluetoothAudioSink> audio_sink) {
148 ++callback_count_; 161 ++callback_count_;
149 audio_sink_ = audio_sink; 162 audio_sink_ = audio_sink;
150 ASSERT_NE(audio_sink_.get(), nullptr); 163 ASSERT_NE(audio_sink_.get(), nullptr);
151 ASSERT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); 164 ASSERT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
152 } 165 }
(...skipping 21 matching lines...) Expand all
174 void ErrorCallback() { 187 void ErrorCallback() {
175 ++error_callback_count_; 188 ++error_callback_count_;
176 } 189 }
177 190
178 protected: 191 protected:
179 int callback_count_; 192 int callback_count_;
180 int error_callback_count_; 193 int error_callback_count_;
181 194
182 base::MessageLoop message_loop_; 195 base::MessageLoop message_loop_;
183 196
197 FakeBluetoothMediaEndpointServiceProvider* media_endpoint_;
198 scoped_ptr<TestAudioSinkObserver> observer_;
184 scoped_refptr<BluetoothAdapter> adapter_; 199 scoped_refptr<BluetoothAdapter> adapter_;
185 scoped_refptr<BluetoothAudioSink> audio_sink_; 200 scoped_refptr<BluetoothAudioSink> audio_sink_;
186 201
187 // The default property set used while calling SetConfiguration on a media 202 // The default property set used while calling SetConfiguration on a media
188 // endpoint object. 203 // endpoint object.
189 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties 204 BluetoothMediaEndpointServiceProvider::Delegate::TransportProperties
190 properties_; 205 properties_;
191 }; 206 };
192 207
193 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterSucceeded) { 208 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterSucceeded) {
194 GetAudioSink(); 209 GetAudioSink();
195
196 // Adds an observer for |audio_sink_|.
197 TestAudioSinkObserver observer(audio_sink_);
198 EXPECT_EQ(observer.state_changed_count_, 0);
199 EXPECT_EQ(observer.volume_changed_count_, 0);
200 } 210 }
201 211
202 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterFailedWithInvalidOptions) { 212 TEST_F(BluetoothAudioSinkChromeOSTest, RegisterFailedWithInvalidOptions) {
203 // Sets options with an invalid codec and valid capabilities. 213 // Sets options with an invalid codec and valid capabilities.
204 BluetoothAudioSink::Options options; 214 BluetoothAudioSink::Options options;
205 options.codec = 0xff; 215 options.codec = 0xff;
206 options.capabilities = std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35}); 216 options.capabilities = std::vector<uint8_t>({0x3f, 0xff, 0x12, 0x35});
207 217
208 adapter_->RegisterAudioSink( 218 adapter_->RegisterAudioSink(
209 options, 219 options,
(...skipping 14 matching lines...) Expand all
224 base::Unretained(this)), 234 base::Unretained(this)),
225 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback, 235 base::Bind(&BluetoothAudioSinkChromeOSTest::RegisterErrorCallback,
226 base::Unretained(this))); 236 base::Unretained(this)));
227 237
228 EXPECT_EQ(callback_count_, 0); 238 EXPECT_EQ(callback_count_, 0);
229 EXPECT_EQ(error_callback_count_, 2); 239 EXPECT_EQ(error_callback_count_, 2);
230 } 240 }
231 241
232 TEST_F(BluetoothAudioSinkChromeOSTest, SelectConfiguration) { 242 TEST_F(BluetoothAudioSinkChromeOSTest, SelectConfiguration) {
233 GetAudioSink(); 243 GetAudioSink();
234 244 GetFakeMediaEndpoint();
235 // Adds an observer for |audio_sink_|. 245 ASSERT_NE(media_endpoint_, nullptr);
236 TestAudioSinkObserver observer(audio_sink_);
237 EXPECT_EQ(observer.state_changed_count_, 0);
238 EXPECT_EQ(observer.volume_changed_count_, 0);
239 246
240 // Simulates calling SelectConfiguration on the media endpoint object owned by 247 // Simulates calling SelectConfiguration on the media endpoint object owned by
241 // |audio_sink_| with some fake capabilities. 248 // |audio_sink_| with some fake capabilities.
242 BluetoothAudioSinkChromeOS* audio_sink_chromeos = 249 media_endpoint_->SelectConfiguration(
243 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get());
244 FakeBluetoothMediaEndpointServiceProvider* media_endpoint =
245 static_cast<FakeBluetoothMediaEndpointServiceProvider*>(
246 audio_sink_chromeos->GetEndpointServiceProvider());
247 ASSERT_NE(media_endpoint, nullptr);
248
249 media_endpoint->SelectConfiguration(
250 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}), 250 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}),
251 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback, 251 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback,
252 base::Unretained(this))); 252 base::Unretained(this)));
253 253
254 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); 254 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
255 EXPECT_EQ(callback_count_, 2); 255 EXPECT_EQ(callback_count_, 2);
256 EXPECT_EQ(error_callback_count_, 0); 256 EXPECT_EQ(error_callback_count_, 0);
257 EXPECT_EQ(observer.state_changed_count_, 0); 257 EXPECT_EQ(observer_->state_changed_count_, 0);
258 EXPECT_EQ(observer.volume_changed_count_, 0); 258 EXPECT_EQ(observer_->volume_changed_count_, 0);
259 } 259 }
260 260
261 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfiguration) { 261 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfiguration) {
262 GetAudioSink(); 262 GetAudioSink();
263 263 GetFakeMediaEndpoint();
264 // Adds an observer for |audio_sink_|. 264 ASSERT_NE(media_endpoint_, nullptr);
265 TestAudioSinkObserver observer(audio_sink_);
266 EXPECT_EQ(observer.state_changed_count_, 0);
267 EXPECT_EQ(observer.volume_changed_count_, 0);
268 265
269 // Simulates calling SetConfiguration on the media endpoint object owned by 266 // Simulates calling SetConfiguration on the media endpoint object owned by
270 // |audio_sink_| with a fake transport path and a 267 // |audio_sink_| with a fake transport path and a
271 // Delegate::TransportProperties structure. 268 // Delegate::TransportProperties structure.
272 BluetoothAudioSinkChromeOS* audio_sink_chromeos = 269 media_endpoint_->SetConfiguration(
273 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get());
274 FakeBluetoothMediaEndpointServiceProvider* media_endpoint =
275 static_cast<FakeBluetoothMediaEndpointServiceProvider*>(
276 audio_sink_chromeos->GetEndpointServiceProvider());
277 ASSERT_NE(media_endpoint, nullptr);
278
279 media_endpoint->SetConfiguration(
280 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath), 270 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
281 properties_); 271 properties_);
282 272
283 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); 273 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
284 EXPECT_EQ(callback_count_, 1); 274 EXPECT_EQ(callback_count_, 1);
285 EXPECT_EQ(error_callback_count_, 0); 275 EXPECT_EQ(error_callback_count_, 0);
286 EXPECT_EQ(observer.state_changed_count_, 1); 276 EXPECT_EQ(observer_->state_changed_count_, 1);
287 EXPECT_EQ(observer.volume_changed_count_, 1); 277 EXPECT_EQ(observer_->volume_changed_count_, 1);
288 } 278 }
289 279
290 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) { 280 TEST_F(BluetoothAudioSinkChromeOSTest, SetConfigurationWithUnexpectedState) {
291 GetAudioSink(); 281 GetAudioSink();
292 282 GetFakeMediaEndpoint();
293 // Adds an observer for |audio_sink_|. 283 ASSERT_NE(media_endpoint_, nullptr);
294 TestAudioSinkObserver observer(audio_sink_);
295 EXPECT_EQ(observer.state_changed_count_, 0);
296 EXPECT_EQ(observer.volume_changed_count_, 0);
297
298 // Simulates calling SetConfiguration on the media endpoint object owned by
299 // |audio_sink_| with a fake transport path and a
300 // Delegate::TransportProperties structure.
301 BluetoothAudioSinkChromeOS* audio_sink_chromeos =
302 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get());
303 FakeBluetoothMediaEndpointServiceProvider* media_endpoint =
304 static_cast<FakeBluetoothMediaEndpointServiceProvider*>(
305 audio_sink_chromeos->GetEndpointServiceProvider());
306 ASSERT_NE(media_endpoint, nullptr);
307 284
308 // Set state of Delegate::TransportProperties with an unexpected value. 285 // Set state of Delegate::TransportProperties with an unexpected value.
309 properties_.state = "active"; 286 properties_.state = "active";
310 287
311 media_endpoint->SetConfiguration( 288 media_endpoint_->SetConfiguration(
312 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath), 289 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
313 properties_); 290 properties_);
314 291
315 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); 292 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
316 EXPECT_EQ(callback_count_, 1); 293 EXPECT_EQ(callback_count_, 1);
317 EXPECT_EQ(error_callback_count_, 0); 294 EXPECT_EQ(error_callback_count_, 0);
318 EXPECT_EQ(observer.state_changed_count_, 0); 295 EXPECT_EQ(observer_->state_changed_count_, 0);
319 EXPECT_EQ(observer.volume_changed_count_, 0); 296 EXPECT_EQ(observer_->volume_changed_count_, 0);
320 } 297 }
321 298
322 // Checks if the observer is notified while the media object is 299 // TODO(mcchou): Adds test on media-removed events for STATE_PENDING and
323 // removed(invisible). Once the media object is removed, the audio sink is no 300 // STATE_ACTIVE.
324 // longer valid. 301 // Checks if the observer is notified on media-removed event when the state of
325 TEST_F(BluetoothAudioSinkChromeOSTest, ObserverNotifiedWhenMediaRemoved) { 302 // |audio_sink_| is STATE_DISCONNECTED. Once the media object is removed, the
303 // audio sink is no longer valid.
304 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringDisconnectedState) {
326 GetAudioSink(); 305 GetAudioSink();
327 306 GetFakeMediaEndpoint();
328 // Adds an observer for |audio_sink_|. 307 ASSERT_NE(media_endpoint_, nullptr);
329 TestAudioSinkObserver observer(audio_sink_);
330 EXPECT_EQ(observer.state_changed_count_, 0);
331 EXPECT_EQ(observer.volume_changed_count_, 0);
332 308
333 // Gets the media object and makes it invisible to see if the state of the 309 // Gets the media object and makes it invisible to see if the state of the
334 // audio sink changes accordingly. 310 // audio sink changes accordingly.
335 FakeBluetoothMediaClient* media = static_cast<FakeBluetoothMediaClient*>( 311 FakeBluetoothMediaClient* media = static_cast<FakeBluetoothMediaClient*>(
336 DBusThreadManager::Get()->GetBluetoothMediaClient()); 312 DBusThreadManager::Get()->GetBluetoothMediaClient());
337 media->SetVisible(false); 313 media->SetVisible(false);
338 314
339 BluetoothAudioSinkChromeOS* audio_sink_chromeos = 315 GetFakeMediaEndpoint();
340 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get());
341 FakeBluetoothMediaEndpointServiceProvider* media_endpoint =
342 static_cast<FakeBluetoothMediaEndpointServiceProvider*>(
343 audio_sink_chromeos->GetEndpointServiceProvider());
344 316
345 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID); 317 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID);
346 EXPECT_EQ(media_endpoint, nullptr); 318 EXPECT_EQ(media_endpoint_, nullptr);
319 EXPECT_EQ(observer_->state_changed_count_, 1);
320 EXPECT_EQ(observer_->volume_changed_count_, 0);
347 } 321 }
348 322
349 // Checks if the observer is notified while the media transport is 323 // Checks if the observer is notified on media-removed event when the state of
350 // removed(invisible). Once the media transport object is removed, the audio 324 // |audio_sink_| is STATE_IDLE. Once the media object is removed, the audio sink
351 // sink is disconnected. 325 // is no longer valid.
352 TEST_F(BluetoothAudioSinkChromeOSTest, ObserverNotifiedWhenTransportRemoved) { 326 TEST_F(BluetoothAudioSinkChromeOSTest, MediaRemovedDuringIdleState) {
353 GetAudioSink(); 327 GetAudioSink();
328 GetFakeMediaEndpoint();
329 ASSERT_NE(media_endpoint_, nullptr);
354 330
355 // Adds an observer for |audio_sink_|. 331 media_endpoint_->SetConfiguration(
356 TestAudioSinkObserver observer(audio_sink_);
357 EXPECT_EQ(observer.state_changed_count_, 0);
358 EXPECT_EQ(observer.volume_changed_count_, 0);
359
360 // Simulates calling SetConfiguration on the media endpoint object owned by
361 // |audio_sink_| with a fake transport path and a
362 // Delegate::TransportProperties structure.
363 BluetoothAudioSinkChromeOS* audio_sink_chromeos =
364 static_cast<BluetoothAudioSinkChromeOS*>(audio_sink_.get());
365 FakeBluetoothMediaEndpointServiceProvider* media_endpoint =
366 static_cast<FakeBluetoothMediaEndpointServiceProvider*>(
367 audio_sink_chromeos->GetEndpointServiceProvider());
368 ASSERT_NE(media_endpoint, nullptr);
369
370 media_endpoint->SetConfiguration(
371 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath), 332 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
372 properties_); 333 properties_);
373 334
374 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE); 335 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
375 EXPECT_EQ(callback_count_, 1); 336 EXPECT_EQ(callback_count_, 1);
376 EXPECT_EQ(error_callback_count_, 0); 337 EXPECT_EQ(error_callback_count_, 0);
377 EXPECT_EQ(observer.state_changed_count_, 1); 338 EXPECT_EQ(observer_->state_changed_count_, 1);
378 EXPECT_EQ(observer.volume_changed_count_, 1); 339 EXPECT_EQ(observer_->volume_changed_count_, 1);
340
341 // Gets the media object and makes it invisible to see if the state of the
342 // audio sink changes accordingly.
343 FakeBluetoothMediaClient* media = static_cast<FakeBluetoothMediaClient*>(
344 DBusThreadManager::Get()->GetBluetoothMediaClient());
345 media->SetVisible(false);
346
347 GetFakeMediaEndpoint();
348
349 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID);
350 EXPECT_EQ(media_endpoint_, nullptr);
351 // The state becomes disconnted and then invalid, since the removal of
352 // transport object should happend before media becomes invisible.
353 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID
354 EXPECT_EQ(observer_->state_changed_count_, 3);
355 EXPECT_EQ(observer_->volume_changed_count_, 2);
356 }
357
358 // TODO(mcchou): Add tests on media-removed event for STATE_PENDING and
359 // STATE_ACTIVE.
360
361 // Checks if the observer is notified on transport-removed event when the state
362 // of |audio_sink_| is STATE_IDEL. Once the media transport object is removed,
363 // the audio sink is disconnected.
364 TEST_F(BluetoothAudioSinkChromeOSTest, TransportRemovedDuringIdleState) {
365 GetAudioSink();
366 GetFakeMediaEndpoint();
367 ASSERT_NE(media_endpoint_, nullptr);
368
369 media_endpoint_->SetConfiguration(
370 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
371 properties_);
372
373 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
374 EXPECT_EQ(callback_count_, 1);
375 EXPECT_EQ(error_callback_count_, 0);
376 EXPECT_EQ(observer_->state_changed_count_, 1);
377 EXPECT_EQ(observer_->volume_changed_count_, 1);
379 378
380 // Gets the media transport object and makes it invalid to see if the state 379 // Gets the media transport object and makes it invalid to see if the state
381 // of the audio sink changes accordingly. 380 // of the audio sink changes accordingly.
382 FakeBluetoothMediaTransportClient* transport = 381 FakeBluetoothMediaTransportClient* transport =
383 static_cast<FakeBluetoothMediaTransportClient*>( 382 static_cast<FakeBluetoothMediaTransportClient*>(
384 DBusThreadManager::Get()->GetBluetoothMediaTransportClient()); 383 DBusThreadManager::Get()->GetBluetoothMediaTransportClient());
385 384
386 transport->SetValid(media_endpoint->object_path(), false); 385 transport->SetValid(media_endpoint_->object_path(), false);
387 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED); 386
388 EXPECT_NE(media_endpoint, nullptr); 387 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
388 EXPECT_NE(media_endpoint_, nullptr);
389 EXPECT_EQ(observer_->state_changed_count_, 2);
390 EXPECT_EQ(observer_->volume_changed_count_, 2);
391 }
392
393 // TODO(mcchou): Add tests on transport-removed event for STATE_PENDING and
394 // STATE_ACTIVE.
395
396 TEST_F(BluetoothAudioSinkChromeOSTest,
397 AdapterPoweredChangedDuringDisconnectedState) {
398 GetAudioSink();
399
400 adapter_->SetPowered(
401 false,
402 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback,
403 base::Unretained(this)),
404 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback,
405 base::Unretained(this)));
406
407 EXPECT_TRUE(adapter_->IsPresent());
408 EXPECT_FALSE(adapter_->IsPowered());
409 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
410 EXPECT_EQ(callback_count_, 2);
411 EXPECT_EQ(error_callback_count_, 0);
412 EXPECT_EQ(observer_->state_changed_count_, 0);
413 EXPECT_EQ(observer_->volume_changed_count_, 0);
414
415 adapter_->SetPowered(
416 true,
417 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback,
418 base::Unretained(this)),
419 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback,
420 base::Unretained(this)));
421
422 EXPECT_TRUE(adapter_->IsPresent());
423 EXPECT_TRUE(adapter_->IsPowered());
424 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
425 EXPECT_EQ(callback_count_, 3);
426 EXPECT_EQ(error_callback_count_, 0);
427 EXPECT_EQ(observer_->state_changed_count_, 0);
428 EXPECT_EQ(observer_->volume_changed_count_, 0);
429 }
430
431 TEST_F(BluetoothAudioSinkChromeOSTest, AdapterPoweredChangedDuringIdleState) {
432 GetAudioSink();
433 GetFakeMediaEndpoint();
434 ASSERT_NE(media_endpoint_, nullptr);
435
436 media_endpoint_->SetConfiguration(
437 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
438 properties_);
439
440 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
441 EXPECT_EQ(callback_count_, 1);
442 EXPECT_EQ(error_callback_count_, 0);
443 EXPECT_EQ(observer_->state_changed_count_, 1);
444 EXPECT_EQ(observer_->volume_changed_count_, 1);
445
446 adapter_->SetPowered(
447 false,
448 base::Bind(&BluetoothAudioSinkChromeOSTest::Callback,
449 base::Unretained(this)),
450 base::Bind(&BluetoothAudioSinkChromeOSTest::ErrorCallback,
451 base::Unretained(this)));
452 GetFakeMediaEndpoint();
453
454 EXPECT_TRUE(adapter_->IsPresent());
455 EXPECT_FALSE(adapter_->IsPowered());
456 EXPECT_NE(media_endpoint_, nullptr);
457
458 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
459 EXPECT_EQ(callback_count_, 2);
460 EXPECT_EQ(error_callback_count_, 0);
461 EXPECT_EQ(observer_->state_changed_count_, 2);
462 EXPECT_EQ(observer_->volume_changed_count_, 2);
463 }
464
465 // TODO(mcchou): Add tests on AdapterPoweredChanged event for STATE_PENDING and
466 // STATE_ACTIVE.
467
468 TEST_F(BluetoothAudioSinkChromeOSTest, ClearConfiguration) {
469 GetAudioSink();
470 GetFakeMediaEndpoint();
471 ASSERT_NE(media_endpoint_, nullptr);
472
473 media_endpoint_->SetConfiguration(
474 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
475 properties_);
476
477 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
478 EXPECT_EQ(callback_count_, 1);
479 EXPECT_EQ(error_callback_count_, 0);
480 EXPECT_EQ(observer_->state_changed_count_, 1);
481 EXPECT_EQ(observer_->volume_changed_count_, 1);
482
483 // Simulates calling ClearConfiguration on the media endpoint object with the
484 // transport path.
485 media_endpoint_->ClearConfiguration(
486 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath));
487
488 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
489 EXPECT_EQ(observer_->state_changed_count_, 2);
490 EXPECT_EQ(observer_->volume_changed_count_, 2);
491 }
492
493 TEST_F(BluetoothAudioSinkChromeOSTest, ClearConfigurationWithIrrelevantPath) {
494 GetAudioSink();
495 GetFakeMediaEndpoint();
496 ASSERT_NE(media_endpoint_, nullptr);
497
498 media_endpoint_->SetConfiguration(
499 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
500 properties_);
501
502 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
503 EXPECT_EQ(callback_count_, 1);
504 EXPECT_EQ(error_callback_count_, 0);
505 EXPECT_EQ(observer_->state_changed_count_, 1);
506 EXPECT_EQ(observer_->volume_changed_count_, 1);
507
508 // Simulates calling ClearConfiguration on the media endpoint object with an
509 // irrelevant transport path.
510 media_endpoint_->ClearConfiguration(ObjectPath("IrrelevantPath"));
511
512 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
513 EXPECT_EQ(observer_->state_changed_count_, 1);
514 EXPECT_EQ(observer_->volume_changed_count_, 1);
515 }
516
517 TEST_F(BluetoothAudioSinkChromeOSTest, EndpointReleased) {
Miao 2015/02/23 21:04:25 Removed this test. This can be included in Unregis
518 GetAudioSink();
519 GetFakeMediaEndpoint();
520 ASSERT_NE(media_endpoint_, nullptr);
521
522 media_endpoint_->SetConfiguration(
523 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
524 properties_);
525
526 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
527 EXPECT_EQ(callback_count_, 1);
528 EXPECT_EQ(error_callback_count_, 0);
529 EXPECT_EQ(observer_->state_changed_count_, 1);
530 EXPECT_EQ(observer_->volume_changed_count_, 1);
531
532 // Simulates calling Release on the media endpoint object.
533 media_endpoint_->Released();
534
535 GetFakeMediaEndpoint();
536
537 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID);
538 EXPECT_EQ(media_endpoint_, nullptr);
539 EXPECT_EQ(observer_->state_changed_count_, 2);
540 EXPECT_EQ(observer_->volume_changed_count_, 2);
541 }
542
543 TEST_F(BluetoothAudioSinkChromeOSTest, UnregisterAudioSinkDuringIdleState) {
544 GetAudioSink();
545 GetFakeMediaEndpoint();
546 ASSERT_NE(media_endpoint_, nullptr);
547
548 media_endpoint_->SelectConfiguration(
549 std::vector<uint8_t>({0x21, 0x15, 0x33, 0x2C}),
550 base::Bind(&BluetoothAudioSinkChromeOSTest::SelectConfigurationCallback,
551 base::Unretained(this)));
552
553 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_DISCONNECTED);
554 EXPECT_EQ(callback_count_, 2);
555 EXPECT_EQ(error_callback_count_, 0);
556 EXPECT_EQ(observer_->state_changed_count_, 0);
557 EXPECT_EQ(observer_->volume_changed_count_, 0);
558
559 media_endpoint_->SetConfiguration(
560 ObjectPath(FakeBluetoothMediaTransportClient::kTransportPath),
561 properties_);
562
563 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_IDLE);
564 EXPECT_EQ(callback_count_, 2);
565 EXPECT_EQ(error_callback_count_, 0);
566 EXPECT_EQ(observer_->state_changed_count_, 1);
567 EXPECT_EQ(observer_->volume_changed_count_, 1);
568
569 audio_sink_->Unregister(base::Bind(&BluetoothAudioSinkChromeOSTest::Callback,
570 base::Unretained(this)));
571
572 EXPECT_EQ(audio_sink_->GetState(), BluetoothAudioSink::STATE_INVALID);
573 EXPECT_EQ(callback_count_, 3);
574 EXPECT_EQ(error_callback_count_, 0);
575
576 // The state becomes disconnted and then invalid, since the removal of
577 // transport object should happend before the unregistration of endpoint.
578 // State: STATE_IDLE -> STATE_DISCONNECTED -> STATE_INVALID
579 EXPECT_EQ(observer_->state_changed_count_, 3);
580 EXPECT_EQ(observer_->volume_changed_count_, 2);
389 } 581 }
390 582
391 } // namespace chromeos 583 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698