| 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..f753457cd2455a48762de0f6fedd51697c959cf3 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,6 +25,8 @@
 | 
|  #include "media/audio/audio_manager.h"
 | 
|  #include "media/base/bind_to_current_loop.h"
 | 
|  #include "media/base/media_switches.h"
 | 
| +#include "media/mojo/common/media_type_converters.h"
 | 
| +#include "mojo/edk/embedder/embedder.h"
 | 
|  #include "testing/gmock/include/gmock/gmock.h"
 | 
|  #include "testing/gtest/include/gtest/gtest.h"
 | 
|  
 | 
| @@ -75,6 +78,13 @@ class MockAudioRendererHost : public AudioRendererHost {
 | 
|                            salt_callback),
 | 
|          shared_memory_length_(0) {}
 | 
|  
 | 
| +  AudioOutputImpl* Init(scoped_refptr<MockAudioRendererHost> host) {
 | 
| +    media::mojom::AudioOutputPtr* stream =
 | 
| +        new media::mojom::AudioOutputPtr();
 | 
| +    audio_output_impl_ = (new AudioOutputImpl(0, mojo::GetProxy(stream)));
 | 
| +    return audio_output_impl_;
 | 
| +  }
 | 
| +
 | 
|    // A list of mock methods.
 | 
|    MOCK_METHOD4(OnDeviceAuthorized,
 | 
|                 void(int stream_id,
 | 
| @@ -86,6 +96,26 @@ class MockAudioRendererHost : public AudioRendererHost {
 | 
|    MOCK_METHOD1(OnStreamPaused, void(int stream_id));
 | 
|    MOCK_METHOD1(OnStreamError, void(int stream_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);
 | 
| +  }
 | 
| +
 | 
|   private:
 | 
|    virtual ~MockAudioRendererHost() {
 | 
|      // Make sure all audio streams have been deleted.
 | 
| @@ -104,8 +134,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 +152,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 +215,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());
 | 
|    }
 | 
| @@ -262,7 +272,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,6 +284,50 @@ 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
 | 
| +
 | 
| +    host_->OnNotifyStreamCreated(stream_id, shared_memory_handle, descriptor,
 | 
| +                                 length);
 | 
| +
 | 
| +    streams_.insert(
 | 
| +        std::pair<int, std::unique_ptr<media::mojom::AudioOutputStreamPtr>>
 | 
| +            (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.
 | 
| @@ -325,6 +381,9 @@ 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 +391,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);
 | 
|  };
 | 
| 
 |