1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
media / audio / mac / audio_device_listener_mac_unittest.cc [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/audio/mac/audio_device_listener_mac.h"
#include <CoreAudio/AudioHardware.h>
#include <memory>
#include <optional>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::Return;
namespace media {
class AudioDeviceListenerMacUnderTest final : public AudioDeviceListenerMac {
public:
AudioDeviceListenerMacUnderTest(base::RepeatingClosure listener_cb,
bool monitor_output_sample_rate_changes,
bool monitor_default_input,
bool monitor_addition_removal,
bool monitor_sources)
: AudioDeviceListenerMac(std::move(listener_cb),
monitor_output_sample_rate_changes,
monitor_default_input,
monitor_addition_removal,
monitor_sources) {}
~AudioDeviceListenerMacUnderTest() final = default;
MOCK_METHOD0(GetAllAudioDeviceIDs, std::vector<AudioObjectID>());
MOCK_METHOD1(IsOutputDevice, bool(AudioObjectID));
MOCK_METHOD2(GetDeviceSource, std::optional<uint32_t>(AudioObjectID, bool));
OSStatus AddPropertyListener(AudioObjectID inObjectID,
const AudioObjectPropertyAddress* inAddress,
AudioObjectPropertyListenerProc inListener,
void* inClientData) final {
return noErr;
}
OSStatus RemovePropertyListener(AudioObjectID inObjectID,
const AudioObjectPropertyAddress* inAddress,
AudioObjectPropertyListenerProc inListener,
void* inClientData) final {
return noErr;
}
};
class AudioDeviceListenerMacTest : public testing::Test {
public:
AudioDeviceListenerMacTest() = default;
AudioDeviceListenerMacTest(const AudioDeviceListenerMacTest&) = delete;
AudioDeviceListenerMacTest& operator=(const AudioDeviceListenerMacTest&) =
delete;
~AudioDeviceListenerMacTest() override = default;
static bool SimulateEvent(const AudioObjectPropertyAddress& address,
std::vector<void*>& contexts) {
// Include multiple addresses to ensure only a single device change event
// occurs.
const AudioObjectPropertyAddress addresses[] = {
address,
{kAudioHardwarePropertySleepingIsAllowed,
kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMain}};
for (void* context : contexts) {
OSStatus status = AudioDeviceListenerMac::SimulateEventForTesting(
kAudioObjectSystemObject, 2, addresses, context);
if (status != noErr)
return false;
}
return true;
}
static bool SimulateDeviceEvent(AudioObjectID id,
std::vector<void*>& contexts,
const AudioObjectPropertyAddress& address) {
const AudioObjectPropertyAddress addresses[] = {address};
for (void* context : contexts) {
OSStatus status = AudioDeviceListenerMac::SimulateEventForTesting(
id, 1, addresses, context);
if (status != noErr)
return false;
}
return true;
}
static bool SimulateSampleRateChange(AudioObjectID id,
std::vector<void*>& contexts) {
return SimulateDeviceEvent(
id, contexts, AudioDeviceListenerMac::kPropertyOutputSampleRateChanged);
}
static bool SimulateOutputSourceChange(AudioObjectID id,
std::vector<void*>& contexts) {
return SimulateDeviceEvent(
id, contexts, AudioDeviceListenerMac::kPropertyOutputSourceChanged);
}
static bool SimluateInputSourceChange(AudioObjectID id,
std::vector<void*>& contexts) {
return SimulateDeviceEvent(
id, contexts, AudioDeviceListenerMac::kPropertyInputSourceChanged);
}
static void CreatePropertyListeners(AudioDeviceListenerMac* device_listener) {
return device_listener->CreatePropertyListeners();
}
static std::vector<void*> GetPropertyListeners(
AudioDeviceListenerMac* device_listener) {
return device_listener->GetPropertyListenersForTesting();
}
static bool SimulateDefaultOutputDeviceChange(std::vector<void*>& contexts) {
return SimulateEvent(
AudioDeviceListenerMac::kDefaultOutputDeviceChangePropertyAddress,
contexts);
}
static bool SimulateDefaultInputDeviceChange(std::vector<void*>& contexts) {
return SimulateEvent(
AudioDeviceListenerMac::kDefaultInputDeviceChangePropertyAddress,
contexts);
}
static bool SimulateDeviceAdditionRemoval(std::vector<void*>& contexts) {
return SimulateEvent(AudioDeviceListenerMac::kDevicesPropertyAddress,
contexts);
}
MOCK_METHOD0(OnDeviceChange, void());
protected:
base::test::SingleThreadTaskEnvironment task_environment_;
std::unique_ptr<AudioDeviceListenerMac> device_listener_;
};
// Simulate a device change event and ensure we get the right callback.
TEST_F(AudioDeviceListenerMacTest, Events_DeviceMonitoring) {
auto device_listener = AudioDeviceListenerMac::Create(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/false,
/*monitor_default_input=*/true, /*monitor_addition_removal=*/true,
/*monitor_sources*/ false);
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output, default input, addition-removal.
EXPECT_EQ(property_listeners.size(), 3u);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateDefaultOutputDeviceChange(property_listeners));
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(this);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateDefaultInputDeviceChange(property_listeners));
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(this);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
base::RunLoop().RunUntilIdle();
device_listener.reset();
base::RunLoop().RunUntilIdle();
}
TEST_F(AudioDeviceListenerMacTest, Events_DefaultOutput) {
auto device_listener = AudioDeviceListenerMac::Create(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/false,
/*monitor_default_input=*/false, /*monitor_addition_removal=*/false,
/*monitor_sources*/ false);
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output.
EXPECT_EQ(property_listeners.size(), 1u);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
ASSERT_TRUE(SimulateDefaultOutputDeviceChange(property_listeners));
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(this);
EXPECT_CALL(*this, OnDeviceChange()).Times(0);
ASSERT_TRUE(SimulateDefaultInputDeviceChange(property_listeners));
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
base::RunLoop().RunUntilIdle();
}
TEST_F(AudioDeviceListenerMacTest, EventsNotProcessedAfterLisneterDeletion) {
auto device_listener = AudioDeviceListenerMac::Create(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/false,
/*monitor_default_input=*/true, /*monitor_addition_removal=*/true,
/*monitor_sources*/ false);
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output, default input, addition-removal.
EXPECT_EQ(property_listeners.size(), 3u);
// AudioDeviceListenerMac is destroyed, but property listener destructions are
// delayed. Notifications on them should still work, but should not result
// in OnDeviceChange call.
device_listener.reset();
EXPECT_CALL(*this, OnDeviceChange()).Times(0);
ASSERT_TRUE(SimulateDefaultOutputDeviceChange(property_listeners));
ASSERT_TRUE(SimulateDefaultInputDeviceChange(property_listeners));
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
base::RunLoop().RunUntilIdle();
// Now all property listeners are destroyed.
}
TEST_F(AudioDeviceListenerMacTest, SampleRateChangeSubscription) {
auto device_listener = std::make_unique<AudioDeviceListenerMacUnderTest>(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/true,
/*monitor_default_input=*/false, /*monitor_addition_removal=*/false,
/*monitor_sources*/ false);
AudioDeviceListenerMacUnderTest& system_audio_mock = *device_listener.get();
EXPECT_CALL(system_audio_mock, GetAllAudioDeviceIDs())
.WillOnce(Return(std::vector<AudioObjectID>{1, 2, 3, 4}));
EXPECT_CALL(system_audio_mock, IsOutputDevice(1)).WillOnce(Return(true));
EXPECT_CALL(system_audio_mock, IsOutputDevice(2)).WillOnce(Return(false));
EXPECT_CALL(system_audio_mock, IsOutputDevice(3)).WillOnce(Return(true));
EXPECT_CALL(system_audio_mock, IsOutputDevice(4)).WillOnce(Return(false));
CreatePropertyListeners(device_listener.get());
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output, addition-removal and two output devices
EXPECT_EQ(property_listeners.size(), 4u);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
// Output.
SimulateSampleRateChange(1, property_listeners);
// Not output - no callback.
SimulateSampleRateChange(2, property_listeners);
device_listener.reset();
base::RunLoop().RunUntilIdle();
}
TEST_F(AudioDeviceListenerMacTest,
SampleRateChangeSubscriptionUpdatedWhenDevicesAddedRemoved) {
auto device_listener = std::make_unique<AudioDeviceListenerMacUnderTest>(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/true,
/*monitor_default_input=*/false, /*monitor_addition_removal=*/false,
/*monitor_sources*/ false);
AudioDeviceListenerMacUnderTest& system_audio_mock = *device_listener.get();
EXPECT_CALL(system_audio_mock, GetAllAudioDeviceIDs())
.WillOnce(Return(std::vector<AudioObjectID>{1}))
.WillOnce(Return(std::vector<AudioObjectID>{}))
.WillOnce(Return(std::vector<AudioObjectID>{1}))
.WillOnce(Return(std::vector<AudioObjectID>{1, 2}));
EXPECT_CALL(system_audio_mock, IsOutputDevice(1))
.Times(3)
.WillRepeatedly(Return(true));
EXPECT_CALL(system_audio_mock, IsOutputDevice(2)).WillOnce(Return(true));
// We only change the subscription, nothing notification-worthy.
EXPECT_CALL(*this, OnDeviceChange()).Times(0);
CreatePropertyListeners(device_listener.get());
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output, addition-removal and one output device
EXPECT_EQ(property_listeners.size(), 3u);
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and no output device
EXPECT_EQ(property_listeners.size(), 2u);
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and one output device
EXPECT_EQ(property_listeners.size(), 3u);
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and two output device
EXPECT_EQ(property_listeners.size(), 4u);
device_listener.reset();
base::RunLoop().RunUntilIdle();
}
TEST_F(AudioDeviceListenerMacTest,
SampleRateChangeNotificationsForAddedDevices) {
auto device_listener = std::make_unique<AudioDeviceListenerMacUnderTest>(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/true,
/*monitor_default_input=*/false, /*monitor_addition_removal=*/false,
/*monitor_sources*/ false);
AudioDeviceListenerMacUnderTest& system_audio_mock = *device_listener.get();
EXPECT_CALL(system_audio_mock, GetAllAudioDeviceIDs())
.WillOnce(Return(std::vector<AudioObjectID>{}))
.WillOnce(Return(std::vector<AudioObjectID>{1}))
.WillOnce(Return(std::vector<AudioObjectID>{1, 2}));
EXPECT_CALL(system_audio_mock, IsOutputDevice(1))
.Times(2)
.WillRepeatedly(Return(true));
EXPECT_CALL(system_audio_mock, IsOutputDevice(2)).WillOnce(Return(true));
CreatePropertyListeners(device_listener.get());
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output, addition-removal and none output device
EXPECT_EQ(property_listeners.size(), 2u);
{
EXPECT_CALL(*this, OnDeviceChange()).Times(0);
SimulateSampleRateChange(1, property_listeners);
SimulateSampleRateChange(2, property_listeners);
SimulateSampleRateChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
}
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and one output device
EXPECT_EQ(property_listeners.size(), 3u);
{
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
SimulateSampleRateChange(1, property_listeners);
SimulateSampleRateChange(2, property_listeners);
SimulateSampleRateChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
}
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and two output device
EXPECT_EQ(property_listeners.size(), 4u);
{
EXPECT_CALL(*this, OnDeviceChange()).Times(2);
SimulateSampleRateChange(1, property_listeners);
SimulateSampleRateChange(2, property_listeners);
SimulateSampleRateChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
}
device_listener.reset();
base::RunLoop().RunUntilIdle();
}
TEST_F(AudioDeviceListenerMacTest,
SourceChangeSubscriptionUpdatedWhenDevicesAddedRemoved) {
auto device_listener = std::make_unique<AudioDeviceListenerMacUnderTest>(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/false,
/*monitor_default_input=*/false, /*monitor_addition_removal=*/true,
/*monitor_sources*/ true);
AudioDeviceListenerMacUnderTest& system_audio_mock = *device_listener.get();
EXPECT_CALL(system_audio_mock, GetAllAudioDeviceIDs())
.WillOnce(Return(std::vector<AudioObjectID>{1}))
.WillOnce(Return(std::vector<AudioObjectID>{}))
.WillOnce(Return(std::vector<AudioObjectID>{1, 2}))
.WillOnce(Return(std::vector<AudioObjectID>{1, 3}));
// Device 1 is an input device.
EXPECT_CALL(system_audio_mock, GetDeviceSource(1, false))
.Times(3)
.WillRepeatedly(Return(std::optional<uint32_t>()));
EXPECT_CALL(system_audio_mock, GetDeviceSource(1, true))
.Times(3)
.WillRepeatedly(Return(123));
// Device 2 is an output device.
EXPECT_CALL(system_audio_mock, GetDeviceSource(2, false))
.WillOnce(Return(123));
EXPECT_CALL(system_audio_mock, GetDeviceSource(2, true))
.WillOnce(Return(std::optional<uint32_t>()));
// Device 3 is both an input and output device.
EXPECT_CALL(system_audio_mock, GetDeviceSource(3, false))
.WillOnce(Return(123));
EXPECT_CALL(system_audio_mock, GetDeviceSource(3, true))
.WillOnce(Return(123));
// We add or remove devices three times, expect a call for each of them.
EXPECT_CALL(*this, OnDeviceChange()).Times(3);
CreatePropertyListeners(device_listener.get());
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output, addition-removal and one device source
EXPECT_EQ(property_listeners.size(), 3u);
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and no device source
EXPECT_EQ(property_listeners.size(), 2u);
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and two device sources
EXPECT_EQ(property_listeners.size(), 4u);
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and three device sources
EXPECT_EQ(property_listeners.size(), 5u);
device_listener.reset();
base::RunLoop().RunUntilIdle();
}
TEST_F(AudioDeviceListenerMacTest, SourceChangeNotifications) {
auto device_listener = std::make_unique<AudioDeviceListenerMacUnderTest>(
base::BindRepeating(&AudioDeviceListenerMacTest::OnDeviceChange,
base::Unretained(this)),
/*monitor_output_sample_rate_changes=*/false,
/*monitor_default_input=*/false, /*monitor_addition_removal=*/true,
/*monitor_sources*/ true);
AudioDeviceListenerMacUnderTest& system_audio_mock = *device_listener.get();
EXPECT_CALL(system_audio_mock, GetAllAudioDeviceIDs())
.WillOnce(Return(std::vector<AudioObjectID>{1}))
.WillOnce(Return(std::vector<AudioObjectID>{}))
.WillOnce(Return(std::vector<AudioObjectID>{1, 2}))
.WillOnce(Return(std::vector<AudioObjectID>{1, 3}));
// Device 1 is an input device.
EXPECT_CALL(system_audio_mock, GetDeviceSource(1, false))
.Times(3)
.WillRepeatedly(Return(std::optional<uint32_t>()));
EXPECT_CALL(system_audio_mock, GetDeviceSource(1, true))
.Times(3)
.WillRepeatedly(Return(123));
// Device 2 is an output device.
EXPECT_CALL(system_audio_mock, GetDeviceSource(2, false))
.WillOnce(Return(123));
EXPECT_CALL(system_audio_mock, GetDeviceSource(2, true))
.WillOnce(Return(std::optional<uint32_t>()));
// Device 3 is both an input and output device.
EXPECT_CALL(system_audio_mock, GetDeviceSource(3, false))
.WillOnce(Return(123));
EXPECT_CALL(system_audio_mock, GetDeviceSource(3, true))
.WillOnce(Return(123));
CreatePropertyListeners(device_listener.get());
std::vector<void*> property_listeners =
GetPropertyListeners(device_listener.get());
// Default output, addition-removal and one device source
EXPECT_EQ(property_listeners.size(), 3u);
{
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
SimluateInputSourceChange(1, property_listeners);
SimluateInputSourceChange(2, property_listeners);
SimluateInputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
EXPECT_CALL(*this, OnDeviceChange()).Times(0);
SimulateOutputSourceChange(1, property_listeners);
SimulateOutputSourceChange(2, property_listeners);
SimulateOutputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
}
EXPECT_CALL(*this, OnDeviceChange());
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and no device source
EXPECT_EQ(property_listeners.size(), 2u);
{
EXPECT_CALL(*this, OnDeviceChange()).Times(0);
SimluateInputSourceChange(1, property_listeners);
SimluateInputSourceChange(2, property_listeners);
SimluateInputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
EXPECT_CALL(*this, OnDeviceChange()).Times(0);
SimulateOutputSourceChange(1, property_listeners);
SimulateOutputSourceChange(2, property_listeners);
SimulateOutputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
}
EXPECT_CALL(*this, OnDeviceChange());
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and two device sources
EXPECT_EQ(property_listeners.size(), 4u);
{
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
SimluateInputSourceChange(1, property_listeners);
SimluateInputSourceChange(2, property_listeners);
SimluateInputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
SimulateOutputSourceChange(1, property_listeners);
SimulateOutputSourceChange(2, property_listeners);
SimulateOutputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
}
EXPECT_CALL(*this, OnDeviceChange());
ASSERT_TRUE(SimulateDeviceAdditionRemoval(property_listeners));
property_listeners = GetPropertyListeners(device_listener.get());
// Default output, addition-removal and three device sources
EXPECT_EQ(property_listeners.size(), 5u);
{
EXPECT_CALL(*this, OnDeviceChange()).Times(2);
SimluateInputSourceChange(1, property_listeners);
SimluateInputSourceChange(2, property_listeners);
SimluateInputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
EXPECT_CALL(*this, OnDeviceChange()).Times(1);
SimulateOutputSourceChange(1, property_listeners);
SimulateOutputSourceChange(2, property_listeners);
SimulateOutputSourceChange(3, property_listeners);
testing::Mock::VerifyAndClearExpectations(this);
}
device_listener.reset();
base::RunLoop().RunUntilIdle();
}
} // namespace media