summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 17:35:01 +0000
committerneb@chromium.org <neb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 17:35:01 +0000
commit90b721e6713f6429a24fe03d4f0dbab588f7dc46 (patch)
tree51d7864d9870feccdf0be9cf1fe63129fa7e66c3
parentc847d9f297af987bf24a5ccf17c3a29675f582aa (diff)
downloadchromium_src-90b721e6713f6429a24fe03d4f0dbab588f7dc46.zip
chromium_src-90b721e6713f6429a24fe03d4f0dbab588f7dc46.tar.gz
chromium_src-90b721e6713f6429a24fe03d4f0dbab588f7dc46.tar.bz2
Pepper audio basic functionality unit test, take 3.
Also changed TestSink to be derived from IPC::Channel and made MockRenderThread service AddFilter/RemoveFilter, so that it can be used by MessageFilters. Review URL: http://codereview.chromium.org/1591009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43623 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/ipc_test_sink.cc8
-rw-r--r--chrome/common/ipc_test_sink.h9
-rw-r--r--chrome/renderer/mock_render_thread.cc12
-rw-r--r--chrome/renderer/mock_render_thread.h8
-rw-r--r--chrome/renderer/pepper_devices.cc4
-rw-r--r--chrome/renderer/pepper_devices_unittest.cc26
-rw-r--r--ipc/ipc_channel.h9
7 files changed, 63 insertions, 13 deletions
diff --git a/chrome/common/ipc_test_sink.cc b/chrome/common/ipc_test_sink.cc
index 6a0e45b..04fd065 100644
--- a/chrome/common/ipc_test_sink.cc
+++ b/chrome/common/ipc_test_sink.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,6 +12,12 @@ TestSink::TestSink() {
TestSink::~TestSink() {
}
+bool TestSink::Send(IPC::Message* message) {
+ OnMessageReceived(*message);
+ delete message;
+ return true;
+}
+
void TestSink::OnMessageReceived(const Message& msg) {
messages_.push_back(Message(msg));
}
diff --git a/chrome/common/ipc_test_sink.h b/chrome/common/ipc_test_sink.h
index 973fc71..96e91c0 100644
--- a/chrome/common/ipc_test_sink.h
+++ b/chrome/common/ipc_test_sink.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,6 +9,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "ipc/ipc_channel.h"
#include "ipc/ipc_message.h"
namespace IPC {
@@ -40,11 +41,15 @@ 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();
+ // Interface in IPC::Channel. This copies the message to the sink and then
+ // deletes it.
+ virtual bool Send(IPC::Message* message);
+
// 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);
diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc
index 1fa513f..cda4fef 100644
--- a/chrome/renderer/mock_render_thread.cc
+++ b/chrome/renderer/mock_render_thread.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -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.
diff --git a/chrome/renderer/mock_render_thread.h b/chrome/renderer/mock_render_thread.h
index 4f3b1d9..03fe08f 100644
--- a/chrome/renderer/mock_render_thread.h
+++ b/chrome/renderer/mock_render_thread.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -40,9 +40,9 @@ class MockRenderThread : public RenderThreadBase {
// class.
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) { }
+ // Filtering support.
+ 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.cc b/chrome/renderer/pepper_devices.cc
index 67301fa..494884c 100644
--- a/chrome/renderer/pepper_devices.cc
+++ b/chrome/renderer/pepper_devices.cc
@@ -168,10 +168,6 @@ NPError AudioDeviceContext::Initialize(AudioMessageFilter* filter,
// TODO(neb): figure out if this number is grounded in reality
params.buffer_capacity = params.packet_size * 3;
- LOG(INFO) << "Initializing Pepper Audio Context (" <<
- config->sampleFrameCount << "Hz, " << params.bits_per_sample <<
- " bits, " << config->outputChannelMap << "channels";
-
stream_id_ = filter_->AddDelegate(this);
filter->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, true));
return NPERR_NO_ERROR;
diff --git a/chrome/renderer/pepper_devices_unittest.cc b/chrome/renderer/pepper_devices_unittest.cc
index de4941e..02a93cb 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,22 @@ 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(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..d1dbd03 100644
--- a/ipc/ipc_channel.h
+++ b/ipc/ipc_channel.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -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;