Skip to content

Commit

Permalink
Migrate MediaStream test code from content/shell/renderer/ to content…
Browse files Browse the repository at this point in the history
…/test/.

ContentRendererClient::OverrideCreateMediaStreamClient() is replaced with UseMockMediaStreams() for overriding MediaStreamClient when running layout tests with content_shell. Doing so permits migration of MediaStream-related code from webkit/ to content/ without widening content's public API solely for test purposes.

BUG=251306
R=jam@chromium.org, jochen@chromium.org

Review URL: https://codereview.chromium.org/18590002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210747 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
scherkus@chromium.org committed Jul 10, 2013
1 parent b05d3a1 commit c3bdce1
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 93 deletions.
8 changes: 2 additions & 6 deletions content/content_shell.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,10 @@
'shell/paths_mac.mm',
'shell/renderer/shell_content_renderer_client.cc',
'shell/renderer/shell_content_renderer_client.h',
'shell/renderer/shell_media_stream_client.cc',
'shell/renderer/shell_media_stream_client.h',
'shell/renderer/shell_render_process_observer.cc',
'shell/renderer/shell_render_process_observer.h',
'shell/renderer/shell_render_view_observer.cc',
'shell/renderer/shell_render_view_observer.h',
'shell/renderer/shell_video_frame_provider.cc',
'shell/renderer/shell_video_frame_provider.h',
'shell/renderer/webkit_test_runner.cc',
'shell/renderer/webkit_test_runner.h',
'shell/shell.cc',
Expand Down Expand Up @@ -137,8 +133,8 @@
'shell/shell_login_dialog.h',
'shell/shell_message_filter.cc',
'shell/shell_message_filter.h',
'shell/shell_net_log.cc',
'shell/shell_net_log.h',
'shell/shell_net_log.cc',
'shell/shell_net_log.h',
'shell/shell_network_delegate.cc',
'shell/shell_network_delegate.h',
'shell/shell_plugin_service_filter.cc',
Expand Down
4 changes: 4 additions & 0 deletions content/content_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@
'test/test_content_browser_client.h',
'test/test_content_client.cc',
'test/test_content_client.h',
'test/test_media_stream_client.cc',
'test/test_media_stream_client.h',
'test/test_render_view_host_factory.cc',
'test/test_render_view_host_factory.h',
'test/test_video_frame_provider.cc',
'test/test_video_frame_provider.h',
'test/test_web_contents.cc',
'test/test_web_contents.h',
'test/test_web_contents_view.cc',
Expand Down
5 changes: 0 additions & 5 deletions content/public/renderer/content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ ContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
return NULL;
}

webkit_media::MediaStreamClient*
ContentRendererClient::OverrideCreateMediaStreamClient() {
return NULL;
}

WebKit::WebMIDIAccessor*
ContentRendererClient::OverrideCreateMIDIAccessor(
WebKit::WebMIDIAccessorClient* client) {
Expand Down
9 changes: 0 additions & 9 deletions content/public/renderer/content_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ class PpapiInterfaceFactoryManager;
struct WebPluginInfo;
}

namespace webkit_media {
class MediaLoadDelegate;
class MediaStreamClient;
}

namespace content {

class RenderView;
Expand Down Expand Up @@ -141,10 +136,6 @@ class CONTENT_EXPORT ContentRendererClient {
OverrideCreateWebRTCPeerConnectionHandler(
WebKit::WebRTCPeerConnectionHandlerClient* client);

// Allows the embedder to override creating a MediaStreamClient. If it returns
// NULL the content layer will create the media stream client.
virtual webkit_media::MediaStreamClient* OverrideCreateMediaStreamClient();

// Allows the embedder to override creating a WebMIDIAccessor. If it
// returns NULL the content layer will create the MIDI accessor.
virtual WebKit::WebMIDIAccessor* OverrideCreateMIDIAccessor(
Expand Down
3 changes: 3 additions & 0 deletions content/public/test/layouttest_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void EnableAutoResizeMode(RenderView* render_view,
void DisableAutoResizeMode(RenderView* render_view,
const WebKit::WebSize& new_size);

// Forces the |render_view| to use mock media streams.
void UseMockMediaStreams(RenderView* render_view);

} // namespace content

#endif // CONTENT_PUBLIC_TEST_LAYOUTTEST_SUPPORT_H_
38 changes: 21 additions & 17 deletions content/renderer/render_view_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ RenderViewImpl::RenderViewImpl(RenderViewImplParams* params)
device_orientation_dispatcher_(NULL),
media_stream_dispatcher_(NULL),
browser_plugin_manager_(NULL),
media_stream_impl_(NULL),
media_stream_client_(NULL),
web_user_media_client_(NULL),
devtools_agent_(NULL),
accessibility_mode_(AccessibilityModeOff),
renderer_accessibility_(NULL),
Expand Down Expand Up @@ -2876,22 +2877,16 @@ WebMediaPlayer* RenderViewImpl::createMediaPlayer(

const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
#if defined(ENABLE_WEBRTC)
webkit_media::MediaStreamClient* media_stream_client =
GetContentClient()->renderer()->OverrideCreateMediaStreamClient();
if (!media_stream_client) {
EnsureMediaStreamImpl();
media_stream_client = media_stream_impl_;
}

EnsureMediaStreamClient();
#if !defined(GOOGLE_TV)
if (media_stream_client->IsMediaStream(url)) {
if (media_stream_client_->IsMediaStream(url)) {
#if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
bool found_neon =
(android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
UMA_HISTOGRAM_BOOLEAN("Platform.WebRtcNEONFound", found_neon);
#endif // defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL)
return new webkit_media::WebMediaPlayerMS(
frame, client, AsWeakPtr(), media_stream_client, new RenderMediaLog());
frame, client, AsWeakPtr(), media_stream_client_, new RenderMediaLog());
}
#endif // !defined(GOOGLE_TV)
#endif // defined(ENABLE_WEBRTC)
Expand Down Expand Up @@ -2927,13 +2922,13 @@ WebMediaPlayer* RenderViewImpl::createMediaPlayer(
context_provider->Context3d(), gpu_channel_host, routing_id_),
new RenderMediaLog()));
#if defined(ENABLE_WEBRTC) && defined(GOOGLE_TV)
if (media_stream_client->IsMediaStream(url)) {
if (media_stream_client_->IsMediaStream(url)) {
RTCVideoDecoderFactoryTv* factory = RenderThreadImpl::current()
->GetMediaStreamDependencyFactory()->decoder_factory_tv();
// |media_stream_client| and |factory| outlives |web_media_player_android|.
if (!factory->AcquireDemuxer() ||
!web_media_player_android->InjectMediaStream(
media_stream_client,
media_stream_client_,
factory,
base::Bind(
base::IgnoreResult(&RTCVideoDecoderFactoryTv::ReleaseDemuxer),
Expand Down Expand Up @@ -4280,7 +4275,7 @@ BrowserPluginManager* RenderViewImpl::GetBrowserPluginManager() {
return browser_plugin_manager_.get();
}

void RenderViewImpl::EnsureMediaStreamImpl() {
void RenderViewImpl::EnsureMediaStreamClient() {
if (!RenderThreadImpl::current()) // Will be NULL during unit tests.
return;

Expand All @@ -4293,11 +4288,13 @@ void RenderViewImpl::EnsureMediaStreamImpl() {
if (!media_stream_dispatcher_)
media_stream_dispatcher_ = new MediaStreamDispatcher(this);

if (!media_stream_impl_) {
media_stream_impl_ = new MediaStreamImpl(
if (!media_stream_client_) {
MediaStreamImpl* media_stream_impl = new MediaStreamImpl(
this,
media_stream_dispatcher_,
RenderThreadImpl::current()->GetMediaStreamDependencyFactory());
media_stream_client_ = media_stream_impl;
web_user_media_client_ = media_stream_impl;
}
#endif
}
Expand Down Expand Up @@ -6518,8 +6515,8 @@ WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
}

WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
EnsureMediaStreamImpl();
return media_stream_impl_;
EnsureMediaStreamClient();
return web_user_media_client_;
}

void RenderViewImpl::draggableRegionsChanged() {
Expand Down Expand Up @@ -6788,6 +6785,13 @@ void RenderViewImpl::DisableAutoResizeForTesting(const gfx::Size& new_size) {
OnDisableAutoResize(new_size);
}

void RenderViewImpl::SetMediaStreamClientForTesting(
webkit_media::MediaStreamClient* media_stream_client) {
DCHECK(!media_stream_client_);
DCHECK(!web_user_media_client_);
media_stream_client_ = media_stream_client;
}

void RenderViewImpl::OnReleaseDisambiguationPopupDIB(
TransportDIB::Handle dib_handle) {
TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
Expand Down
18 changes: 14 additions & 4 deletions content/renderer/render_view_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ class PluginInstance;

} // namespace webkit

namespace webkit_media {
class MediaStreamClient;
}

namespace WebKit {
class WebApplicationCacheHost;
class WebApplicationCacheHostClient;
Expand Down Expand Up @@ -147,7 +151,6 @@ class InputTagSpeechDispatcher;
class JavaBridgeDispatcher;
class LoadProgressTracker;
class MediaStreamDispatcher;
class MediaStreamImpl;
class MouseLockDispatcher;
class NavigationState;
class NotificationProvider;
Expand Down Expand Up @@ -388,6 +391,11 @@ class CONTENT_EXPORT RenderViewImpl
const gfx::Size& max_size);
void DisableAutoResizeForTesting(const gfx::Size& new_size);

// Overrides the MediaStreamClient used when creating MediaStream players.
// Must be called before any players are created.
void SetMediaStreamClientForTesting(
webkit_media::MediaStreamClient* media_stream_client);

// IPC::Listener implementation ----------------------------------------------

virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
Expand Down Expand Up @@ -1097,7 +1105,8 @@ class CONTENT_EXPORT RenderViewImpl
// Check whether the preferred size has changed.
void CheckPreferredSize();

void EnsureMediaStreamImpl();
// Initializes |media_stream_client_| if needed.
void EnsureMediaStreamClient();

// This callback is triggered when DownloadFavicon completes, either
// succesfully or with a failure. See DownloadFavicon for more
Expand Down Expand Up @@ -1418,8 +1427,9 @@ class CONTENT_EXPORT RenderViewImpl
// BrowserPluginManager attached to this view; lazily initialized.
scoped_refptr<BrowserPluginManager> browser_plugin_manager_;

// MediaStreamImpl attached to this view; lazily initialized.
MediaStreamImpl* media_stream_impl_;
// MediaStreamClient attached to this view; lazily initialized.
webkit_media::MediaStreamClient* media_stream_client_;
WebKit::WebUserMediaClient* web_user_media_client_;

DevToolsAgent* devtools_agent_;

Expand Down
3 changes: 0 additions & 3 deletions content/shell/renderer/DEPS

This file was deleted.

8 changes: 0 additions & 8 deletions content/shell/renderer/shell_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "content/public/renderer/render_view.h"
#include "content/public/test/layouttest_support.h"
#include "content/shell/common/shell_switches.h"
#include "content/shell/renderer/shell_media_stream_client.h"
#include "content/shell/renderer/shell_render_process_observer.h"
#include "content/shell/renderer/shell_render_view_observer.h"
#include "content/shell/renderer/webkit_test_runner.h"
Expand Down Expand Up @@ -146,13 +145,6 @@ ShellContentRendererClient::OverrideCreateWebRTCPeerConnectionHandler(
#endif
}

webkit_media::MediaStreamClient*
ShellContentRendererClient::OverrideCreateMediaStreamClient() {
if (!shell_media_stream_client_)
shell_media_stream_client_.reset(new ShellMediaStreamClient());
return shell_media_stream_client_.get();
}

WebMIDIAccessor*
ShellContentRendererClient::OverrideCreateMIDIAccessor(
WebMIDIAccessorClient* client) {
Expand Down
4 changes: 0 additions & 4 deletions content/shell/renderer/shell_content_renderer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class MockWebClipboardImpl;

namespace content {

class ShellMediaStreamClient;
class ShellRenderProcessObserver;

class ShellContentRendererClient : public ContentRendererClient {
Expand All @@ -53,8 +52,6 @@ class ShellContentRendererClient : public ContentRendererClient {
virtual WebKit::WebRTCPeerConnectionHandler*
OverrideCreateWebRTCPeerConnectionHandler(
WebKit::WebRTCPeerConnectionHandlerClient* client) OVERRIDE;
virtual webkit_media::MediaStreamClient* OverrideCreateMediaStreamClient()
OVERRIDE;
virtual WebKit::WebMIDIAccessor* OverrideCreateMIDIAccessor(
WebKit::WebMIDIAccessorClient* client) OVERRIDE;
virtual WebKit::WebClipboard* OverrideWebClipboard() OVERRIDE;
Expand All @@ -67,7 +64,6 @@ class ShellContentRendererClient : public ContentRendererClient {
void WebTestProxyCreated(RenderView* render_view,
WebTestRunner::WebTestProxyBase* proxy);

scoped_ptr<ShellMediaStreamClient> shell_media_stream_client_;
scoped_ptr<ShellRenderProcessObserver> shell_observer_;
scoped_ptr<MockWebClipboardImpl> clipboard_;
scoped_ptr<webkit_glue::MockWebHyphenator> hyphenator_;
Expand Down
1 change: 1 addition & 0 deletions content/shell/renderer/webkit_test_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ WebKitTestRunner::WebKitTestRunner(RenderView* render_view)
focused_view_(NULL),
is_main_window_(false),
focus_on_next_commit_(false) {
UseMockMediaStreams(render_view);
}

WebKitTestRunner::~WebKitTestRunner() {
Expand Down
7 changes: 7 additions & 0 deletions content/test/layouttest_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
#include "content/renderer/renderer_webkitplatformsupport_impl.h"
#include "content/test/test_media_stream_client.h"
#include "third_party/WebKit/public/platform/WebGamepads.h"
#include "third_party/WebKit/public/testing/WebFrameTestProxy.h"
#include "third_party/WebKit/public/testing/WebTestProxy.h"
Expand Down Expand Up @@ -130,4 +131,10 @@ void DisableAutoResizeMode(RenderView* render_view, const WebSize& new_size) {
->DisableAutoResizeForTesting(new_size);
}

void UseMockMediaStreams(RenderView* render_view) {
RenderViewImpl* render_view_impl = static_cast<RenderViewImpl*>(render_view);
render_view_impl->SetMediaStreamClientForTesting(
new TestMediaStreamClient(render_view_impl));
}

} // namespace content
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/shell/renderer/shell_media_stream_client.h"
#include "content/test/test_media_stream_client.h"

#include "content/shell/renderer/shell_video_frame_provider.h"
#include "content/test/test_video_frame_provider.h"
#include "third_party/WebKit/public/platform/WebMediaStream.h"
#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
#include "third_party/WebKit/public/platform/WebVector.h"
Expand Down Expand Up @@ -38,31 +38,32 @@ bool IsMockMediaStreamWithVideo(const WebURL& url) {

namespace content {

ShellMediaStreamClient::ShellMediaStreamClient() {}
TestMediaStreamClient::TestMediaStreamClient(RenderView* render_view)
: RenderViewObserver(render_view) {}

ShellMediaStreamClient::~ShellMediaStreamClient() {}
TestMediaStreamClient::~TestMediaStreamClient() {}

bool ShellMediaStreamClient::IsMediaStream(const GURL& url) {
bool TestMediaStreamClient::IsMediaStream(const GURL& url) {
return IsMockMediaStreamWithVideo(url);
}

scoped_refptr<webkit_media::VideoFrameProvider>
ShellMediaStreamClient::GetVideoFrameProvider(
TestMediaStreamClient::GetVideoFrameProvider(
const GURL& url,
const base::Closure& error_cb,
const webkit_media::VideoFrameProvider::RepaintCB& repaint_cb) {
if (!IsMockMediaStreamWithVideo(url))
return NULL;

return new ShellVideoFrameProvider(
return new TestVideoFrameProvider(
gfx::Size(kVideoCaptureWidth, kVideoCaptureHeight),
base::TimeDelta::FromMilliseconds(kVideoCaptureFrameDurationMs),
error_cb,
repaint_cb);
}

scoped_refptr<webkit_media::MediaStreamAudioRenderer>
ShellMediaStreamClient::GetAudioRenderer(const GURL& url) {
TestMediaStreamClient::GetAudioRenderer(const GURL& url) {
return NULL;
}

Expand Down
Loading

0 comments on commit c3bdce1

Please sign in to comment.