Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: content/browser/renderer_host/media/desktop_capture_device_aura_unittest.cc

Issue 172003004: Fixit: Move tab and desktop capture code to new location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "content/browser/renderer_host/media/desktop_capture_device_aura.h"
6
7 #include "base/synchronization/waitable_event.h"
8 #include "content/browser/browser_thread_impl.h"
9 #include "content/public/browser/desktop_media_id.h"
10 #include "media/video/capture/video_capture_types.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/aura/client/window_tree_client.h"
14 #include "ui/aura/test/aura_test_helper.h"
15 #include "ui/aura/test/test_window_delegate.h"
16 #include "ui/aura/window.h"
17 #include "ui/compositor/test/context_factories_for_test.h"
18
19 using ::testing::_;
20 using ::testing::AnyNumber;
21 using ::testing::DoAll;
22 using ::testing::Expectation;
23 using ::testing::InvokeWithoutArgs;
24 using ::testing::SaveArg;
25
26 namespace content {
27 namespace {
28
29 const int kFrameRate = 30;
30
31 class MockDeviceClient : public media::VideoCaptureDevice::Client {
32 public:
33 MOCK_METHOD2(ReserveOutputBuffer,
34 scoped_refptr<Buffer>(media::VideoFrame::Format format,
35 const gfx::Size& dimensions));
36 MOCK_METHOD1(OnError, void(const std::string& reason));
37 MOCK_METHOD5(OnIncomingCapturedFrame,
38 void(const uint8* data,
39 int length,
40 base::TimeTicks timestamp,
41 int rotation,
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,
47 base::TimeTicks timestamp,
48 int frame_rate));
49 };
50
51 // Test harness that sets up a minimal environment with necessary stubs.
52 class DesktopCaptureDeviceAuraTest : public testing::Test {
53 public:
54 DesktopCaptureDeviceAuraTest()
55 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {}
56 virtual ~DesktopCaptureDeviceAuraTest() {}
57
58 protected:
59 virtual void SetUp() OVERRIDE {
60 // The ContextFactory must exist before any Compositors are created.
61 bool enable_pixel_output = false;
62 ui::InitializeContextFactoryForTests(enable_pixel_output);
63 helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
64 helper_->SetUp();
65
66 // We need a window to cover desktop area so that DesktopCaptureDeviceAura
67 // can use gfx::NativeWindow::GetWindowAtScreenPoint() to locate the
68 // root window associated with the primary display.
69 gfx::Rect desktop_bounds = root_window()->bounds();
70 window_delegate_.reset(new aura::test::TestWindowDelegate());
71 desktop_window_.reset(new aura::Window(window_delegate_.get()));
72 desktop_window_->Init(aura::WINDOW_LAYER_TEXTURED);
73 desktop_window_->SetBounds(desktop_bounds);
74 aura::client::ParentWindowWithContext(
75 desktop_window_.get(), root_window(), desktop_bounds);
76 desktop_window_->Show();
77 }
78
79 virtual void TearDown() OVERRIDE {
80 helper_->RunAllPendingInMessageLoop();
81 root_window()->RemoveChild(desktop_window_.get());
82 desktop_window_.reset();
83 window_delegate_.reset();
84 helper_->TearDown();
85 ui::TerminateContextFactoryForTests();
86 }
87
88 aura::Window* root_window() { return helper_->root_window(); }
89
90 private:
91 base::MessageLoopForUI message_loop_;
92 BrowserThreadImpl browser_thread_for_ui_;
93 scoped_ptr<aura::test::AuraTestHelper> helper_;
94 scoped_ptr<aura::Window> desktop_window_;
95 scoped_ptr<aura::test::TestWindowDelegate> window_delegate_;
96
97 DISALLOW_COPY_AND_ASSIGN(DesktopCaptureDeviceAuraTest);
98 };
99
100 TEST_F(DesktopCaptureDeviceAuraTest, StartAndStop) {
101 scoped_ptr<media::VideoCaptureDevice> capture_device(
102 DesktopCaptureDeviceAura::Create(
103 content::DesktopMediaID::RegisterAuraWindow(root_window())));
104
105 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
106 EXPECT_CALL(*client, OnError(_)).Times(0);
107
108 media::VideoCaptureParams capture_params;
109 capture_params.requested_format.frame_size.SetSize(640, 480);
110 capture_params.requested_format.frame_rate = kFrameRate;
111 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
112 capture_params.allow_resolution_change = false;
113 capture_device->AllocateAndStart(
114 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
115 capture_device->StopAndDeAllocate();
116 }
117
118 } // namespace
119 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698