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

Unified Diff: media/audio/audio_output_device_unittest.cc

Issue 1184473002: Add support for the audio-output-device switching IPC mechanism to the renderer lower layers (media… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build dependencies for audio_unittests 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
« no previous file with comments | « media/audio/audio_output_device.cc ('k') | media/audio/audio_output_ipc.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_output_device_unittest.cc
diff --git a/media/audio/audio_output_device_unittest.cc b/media/audio/audio_output_device_unittest.cc
index d80348389d877855270e685b37839907151db21c..3b3ee512f5eedcc2df5137a9260276427e6aec74 100644
--- a/media/audio/audio_output_device_unittest.cc
+++ b/media/audio/audio_output_device_unittest.cc
@@ -5,11 +5,15 @@
#include <vector>
#include "base/at_exit.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop.h"
#include "base/process/process_handle.h"
#include "base/sync_socket.h"
+#include "base/task_runner.h"
#include "base/test/test_timeouts.h"
+#include "base/thread_task_runner_handle.h"
#include "media/audio/audio_output_device.h"
#include "media/audio/sample_rates.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -52,6 +56,15 @@ class MockAudioOutputIPC : public AudioOutputIPC {
MOCK_METHOD0(PauseStream, void());
MOCK_METHOD0(CloseStream, void());
MOCK_METHOD1(SetVolume, void(double volume));
+ MOCK_METHOD3(SwitchOutputDevice,
+ void(const std::string& device_id,
+ const GURL& security_origin,
+ int request_id));
+};
+
+class MockSwitchOutputDeviceCallback {
+ public:
+ MOCK_METHOD1(Callback, void(media::SwitchOutputDeviceResult result));
};
ACTION_P2(SendPendingBytes, socket, pending_bytes) {
@@ -78,6 +91,7 @@ class AudioOutputDeviceTest
void ExpectRenderCallback();
void WaitUntilRenderCallback();
void StopAudioDevice();
+ void SwitchOutputDevice();
protected:
// Used to clean up TLS pointers that the test(s) will initialize.
@@ -88,9 +102,11 @@ class AudioOutputDeviceTest
StrictMock<MockRenderCallback> callback_;
MockAudioOutputIPC* audio_output_ipc_; // owned by audio_device_
scoped_refptr<AudioOutputDevice> audio_device_;
+ MockSwitchOutputDeviceCallback switch_output_device_callback_;
private:
int CalculateMemorySize();
+ void SwitchOutputDeviceCallback(SwitchOutputDeviceResult result);
SharedMemory shared_memory_;
CancelableSyncSocket browser_socket_;
@@ -196,6 +212,28 @@ void AudioOutputDeviceTest::StopAudioDevice() {
io_loop_.RunUntilIdle();
}
+void AudioOutputDeviceTest::SwitchOutputDevice() {
+ const GURL security_origin("http://localhost");
+ const std::string device_id;
+ const int request_id = 1;
+
+ // Switch the output device and check that the IPC message is sent
+ EXPECT_CALL(*audio_output_ipc_,
+ SwitchOutputDevice(device_id, security_origin, request_id));
+ audio_device_->SwitchOutputDevice(
+ device_id, security_origin,
+ base::Bind(&MockSwitchOutputDeviceCallback::Callback,
+ base::Unretained(&switch_output_device_callback_)));
+ io_loop_.RunUntilIdle();
+
+ // Simulate the reception of a successful response from the browser
+ EXPECT_CALL(switch_output_device_callback_,
+ Callback(SWITCH_OUTPUT_DEVICE_RESULT_SUCCESS));
+ audio_device_->OnOutputDeviceSwitched(request_id,
+ SWITCH_OUTPUT_DEVICE_RESULT_SUCCESS);
+ io_loop_.RunUntilIdle();
+}
+
TEST_P(AudioOutputDeviceTest, Initialize) {
// Tests that the object can be constructed, initialized and destructed
// without having ever been started/stopped.
@@ -239,6 +277,13 @@ TEST_P(AudioOutputDeviceTest, CreateStream) {
StopAudioDevice();
}
+// Switch the output device
+TEST_P(AudioOutputDeviceTest, SwitchOutputDevice) {
+ StartAudioDevice();
+ SwitchOutputDevice();
+ StopAudioDevice();
+}
+
INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false));
} // namespace media.
« no previous file with comments | « media/audio/audio_output_device.cc ('k') | media/audio/audio_output_ipc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698