| Index: chromeos/dbus/cras_audio_client_unittest.cc
|
| diff --git a/chromeos/dbus/cras_audio_client_unittest.cc b/chromeos/dbus/cras_audio_client_unittest.cc
|
| index a2993bd370c1fc5f2fe2207720c395af241dff83..d25552315d9dabba5be664fcf2814b769746ac2e 100644
|
| --- a/chromeos/dbus/cras_audio_client_unittest.cc
|
| +++ b/chromeos/dbus/cras_audio_client_unittest.cc
|
| @@ -69,6 +69,7 @@ class MockObserver : public CrasAudioClient::Observer {
|
| MOCK_METHOD0(NodesChanged, void());
|
| MOCK_METHOD1(ActiveOutputNodeChanged, void(uint64_t node_id));
|
| MOCK_METHOD1(ActiveInputNodeChanged, void(uint64_t node_id));
|
| + MOCK_METHOD2(OutputNodeVolumeChanged, void(uint64_t node_id, int volume));
|
| };
|
|
|
| // Expect the reader to be empty.
|
| @@ -281,6 +282,16 @@ class CrasAudioClientTest : public testing::Test {
|
| Invoke(this,
|
| &CrasAudioClientTest::OnConnectToActiveInputNodeChanged));
|
|
|
| + // Set an expectation so mock_cras_proxy's monitoring
|
| + // OutputNodeVolumeChanged ConnectToSignal will use
|
| + // OnConnectToOutputNodeVolumeChanged() to run the callback.
|
| + EXPECT_CALL(
|
| + *mock_cras_proxy_.get(),
|
| + ConnectToSignal(interface_name_, cras::kOutputNodeVolumeChanged, _, _))
|
| + .WillRepeatedly(
|
| + Invoke(this,
|
| + &CrasAudioClientTest::OnConnectToOutputNodeVolumeChanged));
|
| +
|
| // Set an expectation so mock_bus's GetObjectProxy() for the given
|
| // service name and the object path will return mock_cras_proxy_.
|
| EXPECT_CALL(*mock_bus_.get(),
|
| @@ -344,6 +355,12 @@ class CrasAudioClientTest : public testing::Test {
|
| active_input_node_changed_handler_.Run(signal);
|
| }
|
|
|
| + // Send output node volume changed signal to the tested client.
|
| + void SendOutputNodeVolumeChangedSignal(dbus::Signal *signal) {
|
| + ASSERT_FALSE(output_node_volume_changed_handler_.is_null());
|
| + output_node_volume_changed_handler_.Run(signal);
|
| + }
|
| +
|
| // The interface name.
|
| const std::string interface_name_;
|
| // The client to be tested.
|
| @@ -364,6 +381,8 @@ class CrasAudioClientTest : public testing::Test {
|
| dbus::ObjectProxy::SignalCallback active_output_node_changed_handler_;
|
| // The ActiveInputNodeChanged signal handler given by the tested client.
|
| dbus::ObjectProxy::SignalCallback active_input_node_changed_handler_;
|
| + // The OutputNodeVolumeChanged signal handler given by the tested client.
|
| + dbus::ObjectProxy::SignalCallback output_node_volume_changed_handler_;
|
| // The name of the method which is expected to be called.
|
| std::string expected_method_name_;
|
| // The response which the mock cras proxy returns.
|
| @@ -452,6 +471,22 @@ class CrasAudioClientTest : public testing::Test {
|
| success));
|
| }
|
|
|
| + // Checks the requested interface name and signal name.
|
| + // Used to implement the mock cras proxy.
|
| + void OnConnectToOutputNodeVolumeChanged(
|
| + const std::string& interface_name,
|
| + const std::string& signal_name,
|
| + const dbus::ObjectProxy::SignalCallback& signal_callback,
|
| + const dbus::ObjectProxy::OnConnectedCallback& on_connected_callback) {
|
| + output_node_volume_changed_handler_ = signal_callback;
|
| + const bool success = true;
|
| + message_loop_.task_runner()->PostTask(FROM_HERE,
|
| + base::Bind(on_connected_callback,
|
| + interface_name,
|
| + signal_name,
|
| + success));
|
| + }
|
| +
|
| // Checks the content of the method call and returns the response.
|
| // Used to implement the mock cras proxy.
|
| void OnCallMethod(dbus::MethodCall* method_call,
|
| @@ -617,6 +652,36 @@ TEST_F(CrasAudioClientTest, ActiveInputNodeChanged) {
|
| message_loop_.RunUntilIdle();
|
| }
|
|
|
| +TEST_F(CrasAudioClientTest, OutputNodeVolumeChanged) {
|
| + const uint64_t kNodeId = 20003;
|
| + const int32_t volume = 82;
|
| + // Create a signal
|
| + dbus::Signal signal(cras::kCrasControlInterface,
|
| + cras::kOutputNodeVolumeChanged);
|
| + dbus::MessageWriter writer(&signal);
|
| + writer.AppendUint64(kNodeId);
|
| + writer.AppendInt32(volume);
|
| +
|
| + // Set expectations
|
| + MockObserver observer;
|
| + EXPECT_CALL(observer, OutputNodeVolumeChanged(kNodeId, volume)).Times(1);
|
| +
|
| + // Add the observer.
|
| + client_->AddObserver(&observer);
|
| +
|
| + // Run the signal callback.
|
| + SendOutputNodeVolumeChangedSignal(&signal);
|
| +
|
| + // Remove the observer.
|
| + client_->RemoveObserver(&observer);
|
| + EXPECT_CALL(observer, OutputNodeVolumeChanged(_, _)).Times(0);
|
| +
|
| + // Run the signal callback again and make sure the observer isn't called.
|
| + SendOutputNodeVolumeChangedSignal(&signal);
|
| +
|
| + message_loop_.RunUntilIdle();
|
| +}
|
| +
|
| TEST_F(CrasAudioClientTest, GetNodes) {
|
| // Create the expected value.
|
| AudioNodeList expected_node_list;
|
|
|