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

Unified Diff: chromeos/audio/cras_audio_handler_unittest.cc

Issue 1186293003: Implement HasInputDevices in CrasAudioManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add SetHasInputDevice in FakeAudioManager Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/audio/cras_audio_handler_unittest.cc
diff --git a/chromeos/audio/cras_audio_handler_unittest.cc b/chromeos/audio/cras_audio_handler_unittest.cc
index 7472a7f16341c747967c360ef48862b287866090..8b58f0383a207779890947da19fba39713a8b520 100644
--- a/chromeos/audio/cras_audio_handler_unittest.cc
+++ b/chromeos/audio/cras_audio_handler_unittest.cc
@@ -15,8 +15,12 @@
#include "chromeos/dbus/audio_node.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cras_audio_client.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::NiceMock;
+using testing::StrictMock;
+
namespace chromeos {
const uint64 kInternalSpeakerId = 10001;
@@ -24,11 +28,15 @@ const uint64 kHeadphoneId = 10002;
const uint64 kInternalMicId = 10003;
const uint64 kUSBMicId = 10004;
const uint64 kBluetoothHeadsetId = 10005;
-const uint64 kHDMIOutputId = 10006;
-const uint64 kUSBHeadphoneId1 = 10007;
-const uint64 kUSBHeadphoneId2 = 10008;
-const uint64 kMicJackId = 10009;
-const uint64 kKeyboardMicId = 10010;
+const uint64 kBluetoothHeadsetMicId = 10006;
+const uint64 kHDMIOutputId = 10007;
+const uint64 kUSBHeadphoneId1 = 10008;
+const uint64 kUSBHeadphoneId2 = 10009;
+const uint64 kMicJackId = 10010;
+const uint64 kKeyboardMicId = 10011;
+const uint64 kPostMixLoopbackId = 10012;
+const uint64 kPostDSPLoopbackId = 10013;
+const uint64 kAOKRId = 10014;
const uint64 kOtherTypeOutputId = 90001;
const uint64 kOtherTypeInputId = 90002;
const uint64 kUSBJabraSpeakerOutputId1 = 90003;
@@ -117,6 +125,30 @@ const AudioNode kOtherTypeInput(
0
);
+const AudioNode kPostMixLoopback(false,
+ kPostMixLoopbackId,
+ "Fake Post Mix Loopback",
+ "POST_MIX_LOOPBACK",
+ "Post Mix Loopback",
+ false,
+ 0);
+
+const AudioNode kPostDSPLoopback(false,
+ kPostDSPLoopbackId,
+ "Fake Post DSP Loopback",
+ "POST_DSP_LOOPBACK",
+ "Post DSP Loopback",
+ false,
+ 0);
+
+const AudioNode kAOKR(true,
+ kAOKRId,
+ "Fake AOKR Mic",
+ "AOKR",
+ "AOKR Mic",
+ false,
+ 0);
+
const AudioNode kBluetoothHeadset(false,
kBluetoothHeadsetId,
"Bluetooth Headset",
@@ -125,6 +157,14 @@ const AudioNode kBluetoothHeadset(false,
false,
0);
+const AudioNode kBluetoothHeadsetMic(true,
+ kBluetoothHeadsetMicId,
+ "Bluetooth Headset",
+ "BLUETOOTH",
+ "Bluetooth Headset 1",
+ false,
+ 0);
+
const AudioNode kHDMIOutput(false,
kHDMIOutputId,
"HDMI output",
@@ -279,11 +319,21 @@ class TestObserver : public chromeos::CrasAudioHandler::AudioObserver {
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
+// AudioManagerWrapper is mocked in unittest because unittest is run in an
+// environment without AudioManagerCras.
+class MockAudioManagerWrapper : public CrasAudioHandler::AudioManagerWrapper {
+ public:
+ MockAudioManagerWrapper() {}
+ ~MockAudioManagerWrapper() override {}
+ MOCK_METHOD1(SetHasInputDevices, void(bool has_input_devices));
+};
+
class CrasAudioHandlerTest : public testing::Test {
public:
- CrasAudioHandlerTest() : cras_audio_handler_(NULL),
- fake_cras_audio_client_(NULL) {
- }
+ CrasAudioHandlerTest()
+ : cras_audio_handler_(NULL),
+ fake_cras_audio_client_(NULL),
+ use_nice_mock_audio_manager_(true) {}
~CrasAudioHandlerTest() override {}
void SetUp() override {}
@@ -296,13 +346,33 @@ class CrasAudioHandlerTest : public testing::Test {
DBusThreadManager::Shutdown();
}
+ // This is for the cases where the test does not care
+ // audio manager behavior.
+ void SetUpDefaultNiceMockAudioManagerIfNeeded() {
+ if (use_nice_mock_audio_manager_)
+ mock_audio_manager_ = new NiceMock<MockAudioManagerWrapper>();
+ }
+
+ // Set the expected method and arguments on mock_audio_manager_ to
+ // check that SetHasInputDevices is called with correct argument when a
+ // list of audio nodes present in CrasAudioHandler.
+ void CheckSetHasInputDevices(AudioNodeList audio_nodes,
+ bool has_input_devices) {
+ use_nice_mock_audio_manager_ = false;
+ mock_audio_manager_ = new StrictMock<MockAudioManagerWrapper>();
+ EXPECT_CALL(*mock_audio_manager_, SetHasInputDevices(has_input_devices));
+ SetUpCrasAudioHandler(audio_nodes);
+ }
+
void SetUpCrasAudioHandler(const AudioNodeList& audio_nodes) {
DBusThreadManager::Initialize();
fake_cras_audio_client_ = static_cast<FakeCrasAudioClient*>(
DBusThreadManager::Get()->GetCrasAudioClient());
fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
audio_pref_handler_ = new AudioDevicesPrefHandlerStub();
- CrasAudioHandler::Initialize(audio_pref_handler_);
+ SetUpDefaultNiceMockAudioManagerIfNeeded();
+ CrasAudioHandler::Initialize(audio_pref_handler_,
+ make_scoped_ptr(mock_audio_manager_));
cras_audio_handler_ = CrasAudioHandler::Get();
test_observer_.reset(new TestObserver);
cras_audio_handler_->AddAudioObserver(test_observer_.get());
@@ -318,7 +388,9 @@ class CrasAudioHandlerTest : public testing::Test {
fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes);
fake_cras_audio_client_->SetActiveOutputNode(primary_active_node.id),
audio_pref_handler_ = new AudioDevicesPrefHandlerStub();
- CrasAudioHandler::Initialize(audio_pref_handler_);
+ SetUpDefaultNiceMockAudioManagerIfNeeded();
+ CrasAudioHandler::Initialize(audio_pref_handler_,
+ make_scoped_ptr(mock_audio_manager_));
cras_audio_handler_ = CrasAudioHandler::Get();
test_observer_.reset(new TestObserver);
cras_audio_handler_->AddAudioObserver(test_observer_.get());
@@ -364,6 +436,8 @@ class CrasAudioHandlerTest : public testing::Test {
FakeCrasAudioClient* fake_cras_audio_client_; // Not owned.
scoped_ptr<TestObserver> test_observer_;
scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_;
+ MockAudioManagerWrapper* mock_audio_manager_;
+ bool use_nice_mock_audio_manager_;
private:
DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest);
@@ -2597,4 +2671,78 @@ TEST_F(CrasAudioHandlerTest, HDMIOutputRediscover) {
EXPECT_FALSE(cras_audio_handler_->IsOutputMuted());
}
+// Test the case where there is no input device in the beginning.
+// SetHasInputDevices on AudioManagerWrapper is called with argument false.
+// After a mic jack is plugged, CrasAudioHandler calls SetHasInputDevices on
+// AudioManagerWrapper with argument true.
+TEST_F(CrasAudioHandlerTest, PlugMicJackAndUpdateAudioManager) {
+ use_nice_mock_audio_manager_ = false;
+ mock_audio_manager_ = new StrictMock<MockAudioManagerWrapper>();
+
+ // Set up audio handler with output nodes and input nodes for loopback.
+ // SetHasInputAudioDevices should be called with argument false.
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kInternalSpeaker);
+ audio_nodes.push_back(kPostMixLoopback);
+ audio_nodes.push_back(kPostDSPLoopback);
+ EXPECT_CALL(*mock_audio_manager_, SetHasInputDevices(false));
+ SetUpCrasAudioHandler(audio_nodes);
+
+ // Plug the Mic Jack. SetHasInputAudioDevices should get called with argument
+ // true.
+ audio_nodes.push_back(kMicJack);
+ EXPECT_CALL(*mock_audio_manager_, SetHasInputDevices(true));
+ ChangeAudioNodes(audio_nodes);
+}
+
+// Test the case where there is no input device for simple usage.
+// SetHasInputDevices on AudioManagerWrapper is called with argument false.
+TEST_F(CrasAudioHandlerTest, SetHasInputDeviceToFalse) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kHeadphone);
+ audio_nodes.push_back(kUSBHeadphone1);
+ audio_nodes.push_back(kBluetoothHeadset);
+ audio_nodes.push_back(kHDMIOutput);
+ audio_nodes.push_back(kInternalSpeaker);
+ audio_nodes.push_back(kKeyboardMic);
+ audio_nodes.push_back(kAOKR);
+ audio_nodes.push_back(kPostMixLoopback);
+ audio_nodes.push_back(kPostDSPLoopback);
+ audio_nodes.push_back(kOtherTypeOutput);
+ audio_nodes.push_back(kOtherTypeInput);
+ CheckSetHasInputDevices(audio_nodes, false);
+}
+
+// Test the case where there is an internal mic.
+// SetHasInputDevices on AudioManagerWrapper is called with argument true.
+TEST_F(CrasAudioHandlerTest, SetHasInputDeviceToTrueForInternalMic) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kInternalMic);
+ CheckSetHasInputDevices(audio_nodes, true);
+}
+
+// Test the case where there is an external mic.
+// SetHasInputDevices on AudioManagerWrapper is called with argument true.
+TEST_F(CrasAudioHandlerTest, SetHasInputDeviceToTrueForMicJack) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kMicJack);
+ CheckSetHasInputDevices(audio_nodes, true);
+}
+
+// Test the case where there is a USB mic.
+// SetHasInputDevices on AudioManagerWrapper is called with argument true.
+TEST_F(CrasAudioHandlerTest, SetHasInputDeviceToTrueForUSBMic) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kUSBMic);
+ CheckSetHasInputDevices(audio_nodes, true);
+}
+
+// Test the case where there is a bluetooth mic.
+// SetHasInputDevices on AudioManagerWrapper is called with argument true.
+TEST_F(CrasAudioHandlerTest, SetHasInputDeviceToTrueForBluetoothMic) {
+ AudioNodeList audio_nodes;
+ audio_nodes.push_back(kBluetoothHeadsetMic);
+ CheckSetHasInputDevices(audio_nodes, true);
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698