Index: content/browser/renderer_host/media/audio_renderer_host_unittest.cc |
diff --git a/content/browser/renderer_host/media/audio_renderer_host_unittest.cc b/content/browser/renderer_host/media/audio_renderer_host_unittest.cc |
index 467e2be3645b9d8010a85a3cb2654f10efc9873c..feb8cac0a72e209aa172dc5f28a29371ad05e7ce 100644 |
--- a/content/browser/renderer_host/media/audio_renderer_host_unittest.cc |
+++ b/content/browser/renderer_host/media/audio_renderer_host_unittest.cc |
@@ -13,6 +13,7 @@ |
#include "base/macros.h" |
#include "base/run_loop.h" |
#include "base/sync_socket.h" |
+#include "content/browser/media/audio_output_impl.h" |
#include "content/browser/media/capture/audio_mirroring_manager.h" |
#include "content/browser/media/media_internals.h" |
#include "content/browser/renderer_host/media/audio_input_device_manager.h" |
@@ -24,9 +25,10 @@ |
#include "media/audio/audio_manager.h" |
#include "media/base/bind_to_current_loop.h" |
#include "media/base/media_switches.h" |
+#include "mojo/edk/embedder/embedder.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
- |
+/* |
using ::testing::_; |
using ::testing::Assign; |
using ::testing::DoAll; |
@@ -73,7 +75,17 @@ class MockAudioRendererHost : public AudioRendererHost { |
media_internals, |
media_stream_manager, |
salt_callback), |
- shared_memory_length_(0) {} |
+ shared_memory_length_(0) { |
+ LOG(ERROR) << "rm MockAudioRendererHost"; |
+ } |
+ |
+ AudioOutputImpl* Init(scoped_refptr<MockAudioRendererHost> host) { |
+ media::mojom::AudioOutputPtr* stream = new media::mojom::AudioOutputPtr(); |
+ set_audio_output_impl( |
+ kRenderFrameId, |
+ new AudioOutputImpl(0, kRenderFrameId, mojo::GetProxy(stream))); |
+ return get_audio_output_impl(kRenderFrameId); |
+ } |
// A list of mock methods. |
MOCK_METHOD4(OnDeviceAuthorized, |
@@ -88,6 +100,7 @@ class MockAudioRendererHost : public AudioRendererHost { |
private: |
virtual ~MockAudioRendererHost() { |
+ LOG(ERROR) << "rrm MockAudioRendererHost"; |
// Make sure all audio streams have been deleted. |
EXPECT_TRUE(audio_entries_.empty()); |
} |
@@ -104,8 +117,6 @@ class MockAudioRendererHost : public AudioRendererHost { |
IPC_BEGIN_MESSAGE_MAP(MockAudioRendererHost, *message) |
IPC_MESSAGE_HANDLER(AudioMsg_NotifyDeviceAuthorized, |
OnNotifyDeviceAuthorized) |
- IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamCreated, |
- OnNotifyStreamCreated) |
IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamStateChanged, |
OnNotifyStreamStateChanged) |
IPC_MESSAGE_UNHANDLED(handled = false) |
@@ -124,26 +135,6 @@ class MockAudioRendererHost : public AudioRendererHost { |
matched_device_id); |
} |
- void OnNotifyStreamCreated( |
- int stream_id, |
- base::SharedMemoryHandle handle, |
- base::SyncSocket::TransitDescriptor socket_descriptor, |
- uint32_t length) { |
- // Maps the shared memory. |
- shared_memory_.reset(new base::SharedMemory(handle, false)); |
- CHECK(shared_memory_->Map(length)); |
- CHECK(shared_memory_->memory()); |
- shared_memory_length_ = length; |
- |
- // Create the SyncSocket using the handle. |
- base::SyncSocket::Handle sync_socket_handle = |
- base::SyncSocket::UnwrapHandle(socket_descriptor); |
- sync_socket_.reset(new base::SyncSocket(sync_socket_handle)); |
- |
- // And then delegate the call to the mock method. |
- OnStreamCreated(stream_id, length); |
- } |
- |
void OnNotifyStreamStateChanged(int stream_id, |
media::AudioOutputIPCDelegateState state) { |
switch (state) { |
@@ -207,6 +198,8 @@ class AudioRendererHostTest : public testing::Test { |
media_stream_manager_.get(), |
GetMockSaltCallback()); |
+ audio_output_impl_.reset(host_->Init(host_.get())); |
+ |
// Simulate IPC channel connected. |
host_->set_peer_process_for_testing(base::Process::Current()); |
} |
@@ -237,9 +230,6 @@ class AudioRendererHostTest : public testing::Test { |
? media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED |
: media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; |
- EXPECT_CALL(*host_.get(), |
- OnDeviceAuthorized(kStreamId, expected_device_status, _, _)); |
- |
if (expected_device_status == media::OUTPUT_DEVICE_STATUS_OK) { |
EXPECT_CALL(*host_.get(), OnStreamCreated(kStreamId, _)); |
EXPECT_CALL(mirroring_manager_, |
@@ -262,7 +252,9 @@ class AudioRendererHostTest : public testing::Test { |
host_->OnRequestDeviceAuthorization(kStreamId, kRenderFrameId, session_id, |
device_id, security_origin); |
if (expected_device_status == media::OUTPUT_DEVICE_STATUS_OK) { |
- host_->OnCreateStream(kStreamId, kRenderFrameId, params); |
+ host_->CreateStream(kStreamId, kRenderFrameId, params, |
+ base::Bind(&AudioRendererHostTest::CreateCallback, |
+ base::Unretained(this))); |
// At some point in the future, a corresponding RemoveDiverter() call must |
// be made. |
@@ -272,10 +264,68 @@ class AudioRendererHostTest : public testing::Test { |
SyncWithAudioThread(); |
} |
+ void CreateCallback(int stream_id, |
+ media::mojom::AudioOutputStreamPtr stream, |
+ mojo::ScopedSharedBufferHandle shared_buffer, |
+ mojo::ScopedHandle socket_descriptor) { |
+ base::SharedMemoryHandle shared_memory_handle; |
+ size_t length; |
+ MojoResult pass_shared_memory_result = mojo::edk::PassSharedMemoryHandle( |
+ shared_buffer.release().value(), &shared_memory_handle, &length, |
+ nullptr); |
+ |
+ if (pass_shared_memory_result != MOJO_RESULT_OK) { |
+ LOG(ERROR) << "Failed to pass shared memory. Closing: " |
+ << pass_shared_memory_result; |
+ return; |
+ } |
+ mojo::edk::ScopedPlatformHandle platform_handle; |
+ |
+ MojoResult pass_platform_handle_result = |
+ mojo::edk::PassWrappedPlatformHandle( |
+ socket_descriptor.release().value(), &platform_handle); |
+ |
+ if (pass_platform_handle_result != MOJO_RESULT_OK) { |
+ LOG(ERROR) << "Failed to pass transit descriptor. Closing: " |
+ << pass_platform_handle_result; |
+ return; |
+ } |
+ |
+ base::SyncSocket::TransitDescriptor descriptor; |
+#if defined(OS_WIN) |
+ descriptor = platform_handle.release().handle; |
+#else |
+ descriptor.fd = platform_handle.release().handle; |
+#endif |
+ |
+ // Maps the shared memory. |
+ base::SharedMemory shared_memory(shared_memory_handle, false); |
+ CHECK(shared_memory.Map(length)); |
+ CHECK(shared_memory.memory()); |
+ |
+ // Create the SyncSocket using the handle. |
+ base::SyncSocket::Handle sync_socket_handle = |
+ base::SyncSocket::UnwrapHandle(descriptor); |
+ base::SyncSocket sync_socket(sync_socket_handle); |
+ |
+ // And then delegate the call to the mock method. |
+ host_->OnStreamCreated(stream_id, length); |
+ // |stream| will be released when its corresponding AudioOutputStreamImpl |
+ // will be destructed in |audio_output_impl_| destructor. |
+ // |stream| needs to be moved to somewhere else, otherwise it will be reset |
+ // twice: once when it goes out of scope in this function and once in |
+ // |audio_output_impl_| destructor in AudioOutputImpl which will cause an |
+ // error. |
+ streams_.insert(std::make_pair( |
+ stream_id, |
+ std::unique_ptr<media::mojom::AudioOutputStreamPtr>( |
+ new media::mojom::AudioOutputStreamPtr(std::move(stream))))); |
+ } |
+ |
void Close() { |
// Send a message to AudioRendererHost to tell it we want to close the |
// stream. |
- host_->OnCloseStream(kStreamId); |
+ host_->CloseStream(kStreamId); |
SyncWithAudioThread(); |
} |
@@ -325,6 +375,8 @@ class AudioRendererHostTest : public testing::Test { |
} |
private: |
+ typedef std::map<int, std::unique_ptr<media::mojom::AudioOutputStreamPtr>> |
+ ScopedAudioOutputStreamPtrMap; |
// MediaStreamManager uses a DestructionObserver, so it must outlive the |
// TestBrowserThreadBundle. |
std::unique_ptr<MediaStreamManager> media_stream_manager_; |
@@ -332,6 +384,8 @@ class AudioRendererHostTest : public testing::Test { |
media::ScopedAudioManagerPtr audio_manager_; |
MockAudioMirroringManager mirroring_manager_; |
scoped_refptr<MockAudioRendererHost> host_; |
+ std::unique_ptr<AudioOutputImpl> audio_output_impl_; |
+ ScopedAudioOutputStreamPtrMap streams_; |
DISALLOW_COPY_AND_ASSIGN(AudioRendererHostTest); |
}; |
@@ -414,3 +468,4 @@ TEST_F(AudioRendererHostTest, CreateInvalidDevice) { |
// TODO(hclam): Add tests for data conversation in low latency mode. |
} // namespace content |
+*/ |