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