• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <base/bind.h>
18 #include <base/logging.h>
19 #include <base/message_loop/message_loop.h>
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 
23 #include "avrcp_internal.h"
24 #include "avrcp_test_helper.h"
25 #include "connection_handler.h"
26 
27 using ::testing::_;
28 using ::testing::Return;
29 using ::testing::SaveArg;
30 using ::testing::SaveArgPointee;
31 using ::testing::SetArgPointee;
32 using ::testing::MockFunction;
33 using ::testing::NiceMock;
34 using ::testing::StrictMock;
35 
36 namespace bluetooth {
37 namespace avrcp {
38 
39 using device_ptr = std::shared_ptr<Device>;
40 
41 class AvrcpConnectionHandlerTest : public testing::Test {
42  public:
SetUp()43   void SetUp() override {
44     ON_CALL(mock_avrcp_, Close(_)).WillByDefault(Return(0));
45   }
46 
SetUpSdp(tAVRC_FIND_CBACK * sdp_cb,bool browsing,bool absolute_volume)47   void SetUpSdp(tAVRC_FIND_CBACK* sdp_cb, bool browsing, bool absolute_volume) {
48     EXPECT_CALL(mock_avrcp_, FindService(_, _, _, _))
49         .Times(1)
50         .WillOnce(DoAll(SaveArg<3>(sdp_cb), Return(0)));
51 
52     static tSDP_DISC_ATTR fake_features;
53 
54     fake_features = {
55         .p_next_attr = nullptr,
56         .attr_id = 0,
57         .attr_len_type = 0,
58         .attr_value.v.u16 = 0,
59     };
60 
61     if (browsing) fake_features.attr_value.v.u16 |= AVRC_SUPF_CT_BROWSE;
62     if (absolute_volume) fake_features.attr_value.v.u16 |= AVRC_SUPF_CT_CAT2;
63 
64     EXPECT_CALL(mock_sdp_, FindAttributeInRec(_, _))
65         .Times(4)
66         .WillRepeatedly(Return(&fake_features));
67 
68     EXPECT_CALL(mock_sdp_, FindServiceInDb(_, _, _))
69         .Times(2)
70         .WillOnce(Return((tSDP_DISC_REC*)0x01))   // Return any non null pointer
71         .WillOnce(Return((tSDP_DISC_REC*)0x01));  // Return any non null pointer
72 
73     EXPECT_CALL(mock_sdp_, FindProfileVersionInRec(_, _, _))
74         .Times(2)
75         .WillRepeatedly(DoAll(SetArgPointee<2>(AVRC_REV_1_6), Return(true)));
76   }
77 
78  protected:
79   ConnectionHandler* connection_handler_ = nullptr;
80 
81   // We use NiceMock's here because each function of this code does quite a few
82   // operations. This way it is much easier to write a higher number of smaller
83   // tests without having a large amount of warnings.
84   NiceMock<MockFunction<void(device_ptr)>> device_cb;
85   NiceMock<MockAvrcpInterface> mock_avrcp_;
86   NiceMock<MockSdpInterface> mock_sdp_;
87   NiceMock<MockVolumeInterface> mock_volume_;
88 };
89 
TEST_F(AvrcpConnectionHandlerTest,initializeTest)90 TEST_F(AvrcpConnectionHandlerTest, initializeTest) {
91   // Set an Expectation that Open will be called as an acceptor and save the
92   // connection callback once it is called
93   tAVRC_CONN_CB conn_cb;
94   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
95       .Times(1)
96       .WillOnce(
97           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)));
98 
99   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
100                                    base::Unretained(&device_cb));
101   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
102                                             &mock_sdp_, &mock_volume_));
103   connection_handler_ = ConnectionHandler::Get();
104 
105   // Check that the callback was sent with us as the acceptor
106   ASSERT_EQ(conn_cb.conn, 1);
107 
108   connection_handler_ = nullptr;
109   ConnectionHandler::CleanUp();
110 }
111 
112 // Check that disconnecting without an active connection
TEST_F(AvrcpConnectionHandlerTest,notConnectedDisconnectTest)113 TEST_F(AvrcpConnectionHandlerTest, notConnectedDisconnectTest) {
114   // Set an Expectation that Open will be called twice as an acceptor and save
115   // the connection callback once it is called.
116   tAVRC_CONN_CB conn_cb;
117   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
118       .Times(1)
119       .WillOnce(
120           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)));
121 
122   // Initialize the interface
123   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
124                                    base::Unretained(&device_cb));
125   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
126                                             &mock_sdp_, &mock_volume_));
127   connection_handler_ = ConnectionHandler::Get();
128 
129   // Call the callback with a message saying the connection has closed
130   conn_cb.ctrl_cback.Run(1, AVRC_CLOSE_IND_EVT, 0, &RawAddress::kAny);
131 
132   connection_handler_ = nullptr;
133   ConnectionHandler::CleanUp();
134 };
135 
136 // Test calling the connection callback after the handler is cleaned up
TEST_F(AvrcpConnectionHandlerTest,disconnectAfterCleanupTest)137 TEST_F(AvrcpConnectionHandlerTest, disconnectAfterCleanupTest) {
138   // Set an Expectation that Open will be called twice as an acceptor and save
139   // the connection callback once it is called.
140   tAVRC_CONN_CB conn_cb;
141   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
142       .Times(1)
143       .WillOnce(
144           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)));
145 
146   // Initialize the interface
147   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
148                                    base::Unretained(&device_cb));
149   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
150                                             &mock_sdp_, &mock_volume_));
151   connection_handler_ = ConnectionHandler::Get();
152 
153   connection_handler_ = nullptr;
154   ConnectionHandler::CleanUp();
155 
156   // Call the callback with a message saying the connection has closed
157   conn_cb.ctrl_cback.Run(1, AVRC_CLOSE_IND_EVT, 0, &RawAddress::kAny);
158 };
159 
160 // Check that we can handle having a remote device connect to us, start SDP, and
161 // open another acceptor connection
TEST_F(AvrcpConnectionHandlerTest,remoteDeviceConnectionTest)162 TEST_F(AvrcpConnectionHandlerTest, remoteDeviceConnectionTest) {
163   // Set an Expectation that Open will be called twice as an acceptor and save
164   // the connection callback once it is called.
165   tAVRC_CONN_CB conn_cb;
166   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
167       .Times(2)
168       .WillOnce(
169           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)))
170       .WillOnce(
171           DoAll(SetArgPointee<0>(2), SaveArgPointee<1>(&conn_cb), Return(0)));
172 
173   // Initialize the interface
174   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
175                                    base::Unretained(&device_cb));
176   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
177                                             &mock_sdp_, &mock_volume_));
178   connection_handler_ = ConnectionHandler::Get();
179 
180   // Check that the callback was sent with us as the acceptor
181   ASSERT_EQ(conn_cb.conn, 1);
182 
183   // Set an Expectations that SDP will be performed
184   tAVRC_FIND_CBACK sdp_cb;
185   SetUpSdp(&sdp_cb, false, false);
186 
187   // Set an expectation that a device will be created
188   EXPECT_CALL(device_cb, Call(_)).Times(1);
189 
190   // Set an Expectation that OpenBrowse will be called in acceptor mode when the
191   // device connects.
192   EXPECT_CALL(mock_avrcp_, OpenBrowse(1, AVCT_ACP)).Times(1);
193 
194   // Call the callback with a message saying that a remote device has connected
195   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny);
196 
197   // Run the SDP callback with status success
198   sdp_cb.Run(0);
199 
200   connection_handler_ = nullptr;
201   ConnectionHandler::CleanUp();
202 }
203 
204 // Check that when a device does not support absolute volume, that the
205 // handler reports that via the volume interface.
TEST_F(AvrcpConnectionHandlerTest,noAbsoluteVolumeTest)206 TEST_F(AvrcpConnectionHandlerTest, noAbsoluteVolumeTest) {
207   // Set an Expectation that Open will be called twice as an acceptor and save
208   // the connection callback once it is called.
209   tAVRC_CONN_CB conn_cb;
210   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
211       .Times(2)
212       .WillOnce(
213           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)))
214       .WillOnce(
215           DoAll(SetArgPointee<0>(2), SaveArgPointee<1>(&conn_cb), Return(0)));
216 
217   // Initialize the interface
218   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
219                                    base::Unretained(&device_cb));
220   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
221                                             &mock_sdp_, &mock_volume_));
222   connection_handler_ = ConnectionHandler::Get();
223 
224   // Set an Expectations that SDP will be performed
225   tAVRC_FIND_CBACK sdp_cb;
226   SetUpSdp(&sdp_cb, false, false);
227 
228   EXPECT_CALL(mock_volume_, DeviceConnected(RawAddress::kAny)).Times(1);
229 
230   // Call the callback with a message saying that a remote device has connected
231   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny);
232 
233   // Run the SDP callback with status success
234   sdp_cb.Run(0);
235 
236   connection_handler_ = nullptr;
237   ConnectionHandler::CleanUp();
238 }
239 
240 // Check that when a device does support absolute volume, that the handler
241 // doesn't report it. Instead that will be left up to the device.
TEST_F(AvrcpConnectionHandlerTest,absoluteVolumeTest)242 TEST_F(AvrcpConnectionHandlerTest, absoluteVolumeTest) {
243   // Set an Expectation that Open will be called twice as an acceptor and save
244   // the connection callback once it is called.
245   tAVRC_CONN_CB conn_cb;
246   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
247       .Times(2)
248       .WillOnce(
249           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)))
250       .WillOnce(
251           DoAll(SetArgPointee<0>(2), SaveArgPointee<1>(&conn_cb), Return(0)));
252 
253   // Initialize the interface
254   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
255                                    base::Unretained(&device_cb));
256 
257   StrictMock<MockVolumeInterface> strict_volume;
258   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
259                                             &mock_sdp_, &strict_volume));
260   connection_handler_ = ConnectionHandler::Get();
261 
262   // Set an Expectations that SDP will be performed with absolute volume
263   // supported
264   tAVRC_FIND_CBACK sdp_cb;
265   SetUpSdp(&sdp_cb, false, true);
266 
267   // Call the callback with a message saying that a remote device has connected
268   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny);
269 
270   // Run the SDP callback with status success
271   sdp_cb.Run(0);
272 
273   connection_handler_ = nullptr;
274   ConnectionHandler::CleanUp();
275 }
276 
TEST_F(AvrcpConnectionHandlerTest,disconnectTest)277 TEST_F(AvrcpConnectionHandlerTest, disconnectTest) {
278   // Set an Expectation that Open will be called twice as an acceptor and save
279   // the connection callback once it is called.
280   tAVRC_CONN_CB conn_cb;
281   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
282       .Times(2)
283       .WillOnce(
284           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)))
285       .WillOnce(DoAll(SetArgPointee<0>(2), Return(0)));
286 
287   // Initialize the interface
288   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
289                                    base::Unretained(&device_cb));
290   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
291                                             &mock_sdp_, &mock_volume_));
292   connection_handler_ = ConnectionHandler::Get();
293 
294   // Call the callback with a message saying that a remote device has connected
295   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny);
296 
297   // Set up the expectation that Close will be called
298   EXPECT_CALL(mock_avrcp_, Close(1)).Times(1);
299 
300   // Call the callback with a message saying that a remote device has
301   // disconnected
302   conn_cb.ctrl_cback.Run(1, AVRC_CLOSE_IND_EVT, 0, &RawAddress::kAny);
303 
304   connection_handler_ = nullptr;
305   ConnectionHandler::CleanUp();
306 }
307 
308 // Check that we can handle having a remote device connect to us, start SDP, and
309 // open another acceptor connection
TEST_F(AvrcpConnectionHandlerTest,multipleRemoteDeviceConnectionTest)310 TEST_F(AvrcpConnectionHandlerTest, multipleRemoteDeviceConnectionTest) {
311   // Set an Expectation that Open will be called three times as an acceptor and
312   // save the connection callback once it is called.
313   tAVRC_CONN_CB conn_cb;
314   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
315       .Times(3)
316       .WillOnce(
317           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)))
318       .WillOnce(
319           DoAll(SetArgPointee<0>(2), SaveArgPointee<1>(&conn_cb), Return(0)))
320       .WillOnce(
321           DoAll(SetArgPointee<0>(3), SaveArgPointee<1>(&conn_cb), Return(0)));
322 
323   // Initialize the interface
324   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
325                                    base::Unretained(&device_cb));
326   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
327                                             &mock_sdp_, &mock_volume_));
328   connection_handler_ = ConnectionHandler::Get();
329 
330   // Check that the callback was sent with us as the acceptor
331   ASSERT_EQ(conn_cb.conn, 1);
332 
333   // Set an Expectations that SDP will be performed
334   tAVRC_FIND_CBACK sdp_cb;
335   SetUpSdp(&sdp_cb, false, false);
336 
337   // Set an expectation that a device will be created
338   EXPECT_CALL(device_cb, Call(_)).Times(1);
339 
340   // Set an Expectation that OpenBrowse will be called in acceptor mode when the
341   // device connects on handle 1
342   EXPECT_CALL(mock_avrcp_, OpenBrowse(1, AVCT_ACP)).Times(1);
343 
344   // Call the callback with a message saying that a remote device has connected
345   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny);
346 
347   // Run the SDP callback with status success
348   sdp_cb.Run(0);
349 
350   // Set an Expectations that SDP will be performed again
351   SetUpSdp(&sdp_cb, false, false);
352 
353   // Set an expectation that a device will be created again
354   EXPECT_CALL(device_cb, Call(_)).Times(1);
355 
356   // Set an Expectation that OpenBrowse will be called in acceptor mode when the
357   // device connects on handle 2
358   EXPECT_CALL(mock_avrcp_, OpenBrowse(2, AVCT_ACP)).Times(1);
359 
360   // Call the callback with a message saying that a remote device has connected
361   // with a different address
362   conn_cb.ctrl_cback.Run(2, AVRC_OPEN_IND_EVT, 0, &RawAddress::kEmpty);
363 
364   // Run the SDP callback with status success
365   sdp_cb.Run(0);
366 
367   connection_handler_ = nullptr;
368   ConnectionHandler::CleanUp();
369 }
370 
TEST_F(AvrcpConnectionHandlerTest,cleanupTest)371 TEST_F(AvrcpConnectionHandlerTest, cleanupTest) {
372   // Set Up Expectations for Initialize
373   tAVRC_CONN_CB conn_cb;
374   EXPECT_CALL(mock_avrcp_, Open(_, _, _))
375       .WillOnce(
376           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)))
377       .WillOnce(
378           DoAll(SetArgPointee<0>(2), SaveArgPointee<1>(&conn_cb), Return(0)))
379       .WillOnce(
380           DoAll(SetArgPointee<0>(3), SaveArgPointee<1>(&conn_cb), Return(0)));
381 
382   // Initialize the interface
383   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
384                                    base::Unretained(&device_cb));
385   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
386                                             &mock_sdp_, &mock_volume_));
387   connection_handler_ = ConnectionHandler::Get();
388 
389   // Call the callback twice with a message saying that a remote device has
390   // connected
391   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny);
392   conn_cb.ctrl_cback.Run(2, AVRC_OPEN_IND_EVT, 0, &RawAddress::kEmpty);
393 
394   // Set an Expectation that Close will be called twice with handles 1 and 2
395   EXPECT_CALL(mock_avrcp_, Close(1));
396   EXPECT_CALL(mock_avrcp_, Close(2));
397 
398   // Cleanup the object causing all open connections to be closed
399   connection_handler_ = nullptr;
400   ConnectionHandler::CleanUp();
401 }
402 
TEST_F(AvrcpConnectionHandlerTest,connectToRemoteDeviceTest)403 TEST_F(AvrcpConnectionHandlerTest, connectToRemoteDeviceTest) {
404   // Initialize the interface
405   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
406                                    base::Unretained(&device_cb));
407   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
408                                             &mock_sdp_, &mock_volume_));
409   connection_handler_ = ConnectionHandler::Get();
410 
411   // Set an Expectation that SDP will be performed
412   tAVRC_FIND_CBACK sdp_cb;
413   SetUpSdp(&sdp_cb, false, false);
414 
415   // Connect to the device which starts SDP
416   connection_handler_->ConnectDevice(RawAddress::kEmpty);
417 
418   // Set an expectation that the handler will try to open an AVRCP connection
419   // after doing SDP
420   tAVRC_CONN_CB conn_cb;
421   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kEmpty))
422       .Times(1)
423       .WillOnce(
424           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)));
425 
426   // Complete SDP
427   sdp_cb.Run(0);
428 
429   // Check that the callback was sent with us as the initiator
430   ASSERT_EQ(conn_cb.conn, 0);
431 
432   // Set an expectation that a device will be created
433   EXPECT_CALL(device_cb, Call(_)).Times(1);
434 
435   // Set an Expectation that OpenBrowse will NOT be called since the SDP entry
436   // didn't list browsing as a feature
437   EXPECT_CALL(mock_avrcp_, OpenBrowse(_, _)).Times(0);
438 
439   // Call the callback with a message saying that a remote device has connected
440   // with a different address
441   conn_cb.ctrl_cback.Run(2, AVRC_OPEN_IND_EVT, 0, &RawAddress::kEmpty);
442 
443   // Cleanup the object causing all open connections to be closed
444   connection_handler_ = nullptr;
445   ConnectionHandler::CleanUp();
446 }
447 
TEST_F(AvrcpConnectionHandlerTest,connectToBrowsableRemoteDeviceTest)448 TEST_F(AvrcpConnectionHandlerTest, connectToBrowsableRemoteDeviceTest) {
449   // Initialize the interface
450   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
451                                    base::Unretained(&device_cb));
452   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
453                                             &mock_sdp_, &mock_volume_));
454   connection_handler_ = ConnectionHandler::Get();
455 
456   // Set an Expectation that SDP will be performed
457   tAVRC_FIND_CBACK sdp_cb;
458   SetUpSdp(&sdp_cb, true, false);
459 
460   // Connect to the device which starts SDP
461   connection_handler_->ConnectDevice(RawAddress::kEmpty);
462 
463   // Set an expectation that the handler will try to open an AVRCP connection
464   // after doing SDP
465   tAVRC_CONN_CB conn_cb;
466   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kEmpty))
467       .Times(1)
468       .WillOnce(
469           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)));
470 
471   // Complete SDP
472   sdp_cb.Run(0);
473 
474   // Check that the callback was sent with us as the initiator
475   ASSERT_EQ(conn_cb.conn, 0);
476 
477   // Set an expectation that a device will be created
478   EXPECT_CALL(device_cb, Call(_)).Times(1);
479 
480   // Set an Expectation that OpenBrowse will be called since browsing is listed
481   // as supported in SDP
482   EXPECT_CALL(mock_avrcp_, OpenBrowse(1, AVCT_INT)).Times(1);
483 
484   // Call the callback with a message saying that a remote device has connected
485   // with a different address
486   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kEmpty);
487 
488   // Cleanup the object causing all open connections to be closed
489   connection_handler_ = nullptr;
490   ConnectionHandler::CleanUp();
491 }
492 
TEST_F(AvrcpConnectionHandlerTest,disconnectWhileDoingSdpTest)493 TEST_F(AvrcpConnectionHandlerTest, disconnectWhileDoingSdpTest) {
494   // Set an Expectation that Open will be called twice as an acceptor and save
495   // the connection callback once it is called.
496   tAVRC_CONN_CB conn_cb;
497   EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny))
498       .Times(2)
499       .WillOnce(
500           DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0)))
501       .WillOnce(DoAll(SetArgPointee<0>(2), Return(0)));
502 
503   // Initialize the interface
504   auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call,
505                                    base::Unretained(&device_cb));
506   ASSERT_TRUE(ConnectionHandler::Initialize(bound_callback, &mock_avrcp_,
507                                             &mock_sdp_, &mock_volume_));
508   connection_handler_ = ConnectionHandler::Get();
509 
510   // Set an Expectation that SDP will be performed
511   tAVRC_FIND_CBACK sdp_cb;
512   SetUpSdp(&sdp_cb, true, false);
513 
514   // Call the callback with a message saying that a remote device has connected
515   conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny);
516 
517   // Call the callback with a message saying that a remote device has
518   // disconnected
519   conn_cb.ctrl_cback.Run(1, AVRC_CLOSE_IND_EVT, 0, &RawAddress::kAny);
520 
521   // Signal that SDP has completed
522   sdp_cb.Run(0);
523 
524   connection_handler_ = nullptr;
525   ConnectionHandler::CleanUp();
526 }
527 
528 }  // namespace avrcp
529 }  // namespace bluetooth
530