1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/media/desktop_capture_device_aura.h"
7 #include "base/synchronization/waitable_event.h"
8 #include "content/browser/browser_thread_impl.h"
9 #include "media/video/capture/video_capture_types.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/aura/client/window_tree_client.h"
13 #include "ui/aura/test/aura_test_helper.h"
14 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/window.h"
18 using ::testing::AnyNumber
;
19 using ::testing::DoAll
;
20 using ::testing::Expectation
;
21 using ::testing::InvokeWithoutArgs
;
22 using ::testing::SaveArg
;
27 const int kFrameRate
= 30;
29 class MockDeviceClient
: public media::VideoCaptureDevice::Client
{
31 MOCK_METHOD2(ReserveOutputBuffer
,
32 scoped_refptr
<Buffer
>(media::VideoFrame::Format format
,
33 const gfx::Size
& dimensions
));
34 MOCK_METHOD0(OnError
, void());
35 MOCK_METHOD7(OnIncomingCapturedFrame
,
36 void(const uint8
* data
,
42 const media::VideoCaptureFormat
& frame_format
));
43 MOCK_METHOD5(OnIncomingCapturedBuffer
,
44 void(const scoped_refptr
<Buffer
>& buffer
,
45 media::VideoFrame::Format format
,
46 const gfx::Size
& dimensions
,
51 // Test harness that sets up a minimal environment with necessary stubs.
52 class DesktopCaptureDeviceAuraTest
: public testing::Test
{
54 DesktopCaptureDeviceAuraTest()
55 : browser_thread_for_ui_(BrowserThread::UI
, &message_loop_
) {}
56 virtual ~DesktopCaptureDeviceAuraTest() {}
59 virtual void SetUp() OVERRIDE
{
60 helper_
.reset(new aura::test::AuraTestHelper(&message_loop_
));
63 // We need a window to cover desktop area so that DesktopCaptureDeviceAura
64 // can use gfx::NativeWindow::GetWindowAtScreenPoint() to locate the
65 // root window associated with the primary display.
66 gfx::Rect desktop_bounds
= root_window()->bounds();
67 window_delegate_
.reset(new aura::test::TestWindowDelegate());
68 desktop_window_
.reset(new aura::Window(window_delegate_
.get()));
69 desktop_window_
->Init(ui::LAYER_TEXTURED
);
70 desktop_window_
->SetBounds(desktop_bounds
);
71 aura::client::ParentWindowWithContext(
72 desktop_window_
.get(), root_window(), desktop_bounds
);
73 desktop_window_
->Show();
76 virtual void TearDown() OVERRIDE
{
77 helper_
->RunAllPendingInMessageLoop();
78 root_window()->RemoveChild(desktop_window_
.get());
79 desktop_window_
.reset();
80 window_delegate_
.reset();
84 aura::Window
* root_window() { return helper_
->root_window(); }
87 base::MessageLoopForUI message_loop_
;
88 BrowserThreadImpl browser_thread_for_ui_
;
89 scoped_ptr
<aura::test::AuraTestHelper
> helper_
;
90 scoped_ptr
<aura::Window
> desktop_window_
;
91 scoped_ptr
<aura::test::TestWindowDelegate
> window_delegate_
;
93 DISALLOW_COPY_AND_ASSIGN(DesktopCaptureDeviceAuraTest
);
96 TEST_F(DesktopCaptureDeviceAuraTest
, StartAndStop
) {
97 DesktopMediaID
source(DesktopMediaID::TYPE_SCREEN
, 0);
98 scoped_ptr
<media::VideoCaptureDevice
> capture_device(
99 DesktopCaptureDeviceAura::Create(source
));
101 scoped_ptr
<MockDeviceClient
> client(new MockDeviceClient());
102 EXPECT_CALL(*client
, OnError()).Times(0);
104 media::VideoCaptureParams capture_params
;
105 capture_params
.requested_format
.frame_size
.SetSize(640, 480);
106 capture_params
.requested_format
.frame_rate
= kFrameRate
;
107 capture_params
.requested_format
.pixel_format
= media::PIXEL_FORMAT_I420
;
108 capture_params
.allow_resolution_change
= false;
109 capture_device
->AllocateAndStart(
110 capture_params
, client
.PassAs
<media::VideoCaptureDevice::Client
>());
111 capture_device
->StopAndDeAllocate();
115 } // namespace content