diff options
-rw-r--r-- | chrome/browser/renderer_host/mock_render_process_host.cc | 4 | ||||
-rw-r--r-- | chrome/common/ipc_test_sink.cc | 5 | ||||
-rw-r--r-- | chrome/common/ipc_test_sink.h | 5 | ||||
-rw-r--r-- | chrome/renderer/mock_render_thread.cc | 12 | ||||
-rw-r--r-- | chrome/renderer/mock_render_thread.h | 4 | ||||
-rw-r--r-- | chrome/renderer/pepper_devices_unittest.cc | 27 | ||||
-rw-r--r-- | ipc/ipc_channel.h | 7 |
7 files changed, 55 insertions, 9 deletions
diff --git a/chrome/browser/renderer_host/mock_render_process_host.cc b/chrome/browser/renderer_host/mock_render_process_host.cc index b18cc50..7319c99 100644 --- a/chrome/browser/renderer_host/mock_render_process_host.cc +++ b/chrome/browser/renderer_host/mock_render_process_host.cc @@ -73,14 +73,14 @@ bool MockRenderProcessHost::FastShutdownIfPossible() { bool MockRenderProcessHost::SendWithTimeout(IPC::Message* msg, int timeout_ms) { // Save the message in the sink. Just ignore timeout_ms. - sink_.OnMessageReceived(*msg); + sink_.Send(msg); delete msg; return true; } bool MockRenderProcessHost::Send(IPC::Message* msg) { // Save the message in the sink. - sink_.OnMessageReceived(*msg); + sink_.Send(msg); delete msg; return true; } diff --git a/chrome/common/ipc_test_sink.cc b/chrome/common/ipc_test_sink.cc index 6a0e45b..2979e6a 100644 --- a/chrome/common/ipc_test_sink.cc +++ b/chrome/common/ipc_test_sink.cc @@ -12,8 +12,9 @@ TestSink::TestSink() { TestSink::~TestSink() { } -void TestSink::OnMessageReceived(const Message& msg) { - messages_.push_back(Message(msg)); +bool TestSink::Send(Message* msg) { + messages_.push_back(Message(*msg)); + return true; } void TestSink::ClearMessages() { diff --git a/chrome/common/ipc_test_sink.h b/chrome/common/ipc_test_sink.h index 973fc71..056cb4c 100644 --- a/chrome/common/ipc_test_sink.h +++ b/chrome/common/ipc_test_sink.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "ipc/ipc_message.h" +#include "ipc/ipc_channel.h" namespace IPC { @@ -40,14 +41,14 @@ namespace IPC { // // To hook up the sink, all you need to do is call OnMessageReceived when a // message is received. -class TestSink { +class TestSink : public IPC::Channel { public: TestSink(); ~TestSink(); // Used by the source of the messages to send the message to the sink. This // will make a copy of the message and store it in the list. - void OnMessageReceived(const Message& msg); + virtual bool Send(Message* message); // Returns the number of messages in the queue. size_t message_count() const { return messages_.size(); } diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc index 1fa513f..35383cb 100644 --- a/chrome/renderer/mock_render_thread.cc +++ b/chrome/renderer/mock_render_thread.cc @@ -34,6 +34,16 @@ void MockRenderThread::RemoveRoute(int32 routing_id) { widget_ = NULL; } +// Called by, for example, RenderView::Init(), when adding a new message filter +void MockRenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { + filter->OnFilterAdded(&sink()); +} + +// Called when the filter is removed +void MockRenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { + filter->OnFilterRemoved(); +} + // Called by the Widget. Used to send messages to the browser. // We short-circuit the mechanim and handle the messages right here on this // class. @@ -66,7 +76,7 @@ void MockRenderThread::SendCloseMessage() { void MockRenderThread::OnMessageReceived(const IPC::Message& msg) { // Save the message in the sink. - sink_.OnMessageReceived(msg); + sink_.Send(const_cast<IPC::Message*>(&msg)); // Some messages we do special handling. bool handled = true; diff --git a/chrome/renderer/mock_render_thread.h b/chrome/renderer/mock_render_thread.h index 4f3b1d9..24d646e 100644 --- a/chrome/renderer/mock_render_thread.h +++ b/chrome/renderer/mock_render_thread.h @@ -41,8 +41,8 @@ class MockRenderThread : public RenderThreadBase { virtual bool Send(IPC::Message* msg); // Our mock thread doesn't do filtering. - virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter) { } - virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { } + virtual void AddFilter(IPC::ChannelProxy::MessageFilter* filter); + virtual void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter); // Our mock thread doesn't deal with hidden and restored tabs. virtual void WidgetHidden() { } diff --git a/chrome/renderer/pepper_devices_unittest.cc b/chrome/renderer/pepper_devices_unittest.cc index b793a4e..d7d2a6e 100644 --- a/chrome/renderer/pepper_devices_unittest.cc +++ b/chrome/renderer/pepper_devices_unittest.cc @@ -117,6 +117,9 @@ class PepperDeviceTest : public RenderViewTest { NPError err, NPUserData* user_data); + // Audio callback, currently empty. + static void AudioCallback(NPDeviceContextAudio* context); + // A log of flush commands we can use to check the async callbacks. struct FlushData { NPP instance; @@ -218,6 +221,10 @@ void PepperDeviceTest::FlushCalled(NPP instance, that->flush_calls_.push_back(flush_data); } +void PepperDeviceTest::AudioCallback(NPDeviceContextAudio* context) { +} + + // ----------------------------------------------------------------------------- // TODO(brettw) this crashes on Mac. Figure out why and enable. @@ -250,3 +257,23 @@ TEST_F(PepperDeviceTest, Flush) { EXPECT_EQ(1u, flush_calls_.size()); } #endif + +TEST_F(PepperDeviceTest, AudioInit) { + NPDeviceContextAudioConfig config; + config.sampleRate = NPAudioSampleRate44100Hz; + config.sampleType = NPAudioSampleTypeInt16; + config.outputChannelMap = NPAudioChannelStereo; + config.callback = &AudioCallback; + config.userData = this; + NPDeviceContextAudio context; + EXPECT_EQ(NPERR_NO_ERROR, + pepper_plugin()->DeviceAudioInitializeContext(&config, &context)); + EXPECT_TRUE(render_thread_.sink().GetFirstMessageMatching( + ViewHostMsg_CreateAudioStream::ID)); + EXPECT_EQ(0, memcmp(&config, &context.config, sizeof(config))); + EXPECT_EQ(NPERR_NO_ERROR, + pepper_plugin()->DeviceAudioDestroyContext(&context)); + EXPECT_TRUE(render_thread_.sink().GetFirstMessageMatching( + ViewHostMsg_CloseAudioStream::ID)); +} + diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index a7a9a34..8468d7c 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -96,6 +96,13 @@ class Channel : public Message::Sender { int GetClientFileDescriptor() const; #endif // defined(OS_POSIX) + protected: + // Used in Chrome by the TestSink to provide a dummy channel implementation + // for testing. TestSink overrides the "interesting" functions in Channel so + // no actual implementation is needed. This will cause un-overridden calls to + // segfault. Do not use outside of test code! + Channel() : channel_impl_(0) { } + private: // PIMPL to which all channel calls are delegated. class ChannelImpl; |