OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <CoreAudio/AudioHardware.h> | 5 #include <CoreAudio/AudioHardware.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/bind_to_current_loop.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "media/audio/mac/audio_device_listener_mac.h" | 12 #include "media/audio/mac/audio_device_listener_mac.h" |
12 #include "media/base/bind_to_current_loop.h" | |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 class AudioDeviceListenerMacTest : public testing::Test { | 18 class AudioDeviceListenerMacTest : public testing::Test { |
19 public: | 19 public: |
20 AudioDeviceListenerMacTest() { | 20 AudioDeviceListenerMacTest() { |
21 // It's important to create the device listener from the message loop in | 21 // It's important to create the device listener from the message loop in |
22 // order to ensure we don't end up with unbalanced TaskObserver calls. | 22 // order to ensure we don't end up with unbalanced TaskObserver calls. |
23 message_loop_.PostTask(FROM_HERE, base::Bind( | 23 message_loop_.PostTask(FROM_HERE, base::Bind( |
24 &AudioDeviceListenerMacTest::CreateDeviceListener, | 24 &AudioDeviceListenerMacTest::CreateDeviceListener, |
25 base::Unretained(this))); | 25 base::Unretained(this))); |
26 message_loop_.RunUntilIdle(); | 26 message_loop_.RunUntilIdle(); |
27 } | 27 } |
28 | 28 |
29 virtual ~AudioDeviceListenerMacTest() { | 29 virtual ~AudioDeviceListenerMacTest() { |
30 // It's important to destroy the device listener from the message loop in | 30 // It's important to destroy the device listener from the message loop in |
31 // order to ensure we don't end up with unbalanced TaskObserver calls. | 31 // order to ensure we don't end up with unbalanced TaskObserver calls. |
32 message_loop_.PostTask(FROM_HERE, base::Bind( | 32 message_loop_.PostTask(FROM_HERE, base::Bind( |
33 &AudioDeviceListenerMacTest::DestroyDeviceListener, | 33 &AudioDeviceListenerMacTest::DestroyDeviceListener, |
34 base::Unretained(this))); | 34 base::Unretained(this))); |
35 message_loop_.RunUntilIdle(); | 35 message_loop_.RunUntilIdle(); |
36 } | 36 } |
37 | 37 |
38 void CreateDeviceListener() { | 38 void CreateDeviceListener() { |
39 // Force a post task using BindToCurrentLoop() to ensure device listener | 39 // Force a post task using BindToCurrentLoop() to ensure device listener |
40 // internals are working correctly. | 40 // internals are working correctly. |
41 output_device_listener_.reset(new AudioDeviceListenerMac(BindToCurrentLoop( | 41 output_device_listener_.reset(new AudioDeviceListenerMac( |
42 base::Bind(&AudioDeviceListenerMacTest::OnDeviceChange, | 42 base::BindToCurrentLoop(base::Bind( |
43 base::Unretained(this))))); | 43 &AudioDeviceListenerMacTest::OnDeviceChange, |
| 44 base::Unretained(this))))); |
44 } | 45 } |
45 | 46 |
46 void DestroyDeviceListener() { | 47 void DestroyDeviceListener() { |
47 output_device_listener_.reset(); | 48 output_device_listener_.reset(); |
48 } | 49 } |
49 | 50 |
50 bool ListenerIsValid() { | 51 bool ListenerIsValid() { |
51 return !output_device_listener_->listener_cb_.is_null(); | 52 return !output_device_listener_->listener_cb_.is_null(); |
52 } | 53 } |
53 | 54 |
(...skipping 23 matching lines...) Expand all Loading... |
77 | 78 |
78 // Simulate a device change events and ensure we get the right callbacks. | 79 // Simulate a device change events and ensure we get the right callbacks. |
79 TEST_F(AudioDeviceListenerMacTest, OutputDeviceChange) { | 80 TEST_F(AudioDeviceListenerMacTest, OutputDeviceChange) { |
80 ASSERT_TRUE(ListenerIsValid()); | 81 ASSERT_TRUE(ListenerIsValid()); |
81 EXPECT_CALL(*this, OnDeviceChange()).Times(1); | 82 EXPECT_CALL(*this, OnDeviceChange()).Times(1); |
82 ASSERT_TRUE(SimulateDefaultOutputDeviceChange()); | 83 ASSERT_TRUE(SimulateDefaultOutputDeviceChange()); |
83 message_loop_.RunUntilIdle(); | 84 message_loop_.RunUntilIdle(); |
84 } | 85 } |
85 | 86 |
86 } // namespace media | 87 } // namespace media |
OLD | NEW |