OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/media/capture/desktop_capture_device_aura.h" | 5 #include "content/browser/media/capture/desktop_capture_device_aura.h" |
6 | 6 |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
9 #include "content/public/browser/desktop_media_id.h" | 9 #include "content/public/browser/desktop_media_id.h" |
10 #include "media/video/capture/video_capture_types.h" | 10 #include "media/video/capture/video_capture_types.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/aura/client/window_tree_client.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" | 14 #include "ui/aura/test/test_window_delegate.h" |
16 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
17 #include "ui/compositor/test/context_factories_for_test.h" | 16 #include "ui/compositor/test/context_factories_for_test.h" |
| 17 #include "ui/wm/test/wm_test_helper.h" |
18 | 18 |
19 using ::testing::_; | 19 using ::testing::_; |
20 using ::testing::AnyNumber; | 20 using ::testing::AnyNumber; |
21 using ::testing::DoAll; | 21 using ::testing::DoAll; |
22 using ::testing::Expectation; | 22 using ::testing::Expectation; |
23 using ::testing::InvokeWithoutArgs; | 23 using ::testing::InvokeWithoutArgs; |
24 using ::testing::SaveArg; | 24 using ::testing::SaveArg; |
25 | 25 |
26 namespace media { | 26 namespace media { |
27 class VideoFrame; | 27 class VideoFrame; |
(...skipping 28 matching lines...) Expand all Loading... |
56 public: | 56 public: |
57 DesktopCaptureDeviceAuraTest() | 57 DesktopCaptureDeviceAuraTest() |
58 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 58 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} |
59 virtual ~DesktopCaptureDeviceAuraTest() {} | 59 virtual ~DesktopCaptureDeviceAuraTest() {} |
60 | 60 |
61 protected: | 61 protected: |
62 virtual void SetUp() OVERRIDE { | 62 virtual void SetUp() OVERRIDE { |
63 // The ContextFactory must exist before any Compositors are created. | 63 // The ContextFactory must exist before any Compositors are created. |
64 bool enable_pixel_output = false; | 64 bool enable_pixel_output = false; |
65 ui::InitializeContextFactoryForTests(enable_pixel_output); | 65 ui::InitializeContextFactoryForTests(enable_pixel_output); |
66 helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 66 helper_.reset(new wm::WMTestHelper); |
67 helper_->SetUp(); | 67 helper_->SetUp(); |
68 | 68 |
69 // We need a window to cover desktop area so that DesktopCaptureDeviceAura | 69 // We need a window to cover desktop area so that DesktopCaptureDeviceAura |
70 // can use gfx::NativeWindow::GetWindowAtScreenPoint() to locate the | 70 // can use gfx::NativeWindow::GetWindowAtScreenPoint() to locate the |
71 // root window associated with the primary display. | 71 // root window associated with the primary display. |
72 gfx::Rect desktop_bounds = root_window()->bounds(); | 72 gfx::Rect desktop_bounds = root_window()->bounds(); |
73 window_delegate_.reset(new aura::test::TestWindowDelegate()); | 73 window_delegate_.reset(new aura::test::TestWindowDelegate()); |
74 desktop_window_.reset(new aura::Window(window_delegate_.get())); | 74 desktop_window_.reset(new aura::Window(window_delegate_.get())); |
75 desktop_window_->Init(aura::WINDOW_LAYER_TEXTURED); | 75 desktop_window_->Init(aura::WINDOW_LAYER_TEXTURED); |
76 desktop_window_->SetBounds(desktop_bounds); | 76 desktop_window_->SetBounds(desktop_bounds); |
77 aura::client::ParentWindowWithContext( | 77 aura::client::ParentWindowWithContext( |
78 desktop_window_.get(), root_window(), desktop_bounds); | 78 desktop_window_.get(), root_window(), desktop_bounds); |
79 desktop_window_->Show(); | 79 desktop_window_->Show(); |
80 } | 80 } |
81 | 81 |
82 virtual void TearDown() OVERRIDE { | 82 virtual void TearDown() OVERRIDE { |
83 helper_->RunAllPendingInMessageLoop(); | 83 helper_->RunAllPendingInMessageLoop(); |
84 root_window()->RemoveChild(desktop_window_.get()); | 84 root_window()->RemoveChild(desktop_window_.get()); |
85 desktop_window_.reset(); | 85 desktop_window_.reset(); |
86 window_delegate_.reset(); | 86 window_delegate_.reset(); |
87 helper_->TearDown(); | 87 helper_->TearDown(); |
88 ui::TerminateContextFactoryForTests(); | 88 ui::TerminateContextFactoryForTests(); |
89 } | 89 } |
90 | 90 |
91 aura::Window* root_window() { return helper_->root_window(); } | 91 aura::Window* root_window() { return helper_->root_window(); } |
92 | 92 |
93 private: | 93 private: |
94 base::MessageLoopForUI message_loop_; | 94 base::MessageLoopForUI message_loop_; |
95 BrowserThreadImpl browser_thread_for_ui_; | 95 BrowserThreadImpl browser_thread_for_ui_; |
96 scoped_ptr<aura::test::AuraTestHelper> helper_; | 96 scoped_ptr<wm::WMTestHelper> helper_; |
97 scoped_ptr<aura::Window> desktop_window_; | 97 scoped_ptr<aura::Window> desktop_window_; |
98 scoped_ptr<aura::test::TestWindowDelegate> window_delegate_; | 98 scoped_ptr<aura::test::TestWindowDelegate> window_delegate_; |
99 | 99 |
100 DISALLOW_COPY_AND_ASSIGN(DesktopCaptureDeviceAuraTest); | 100 DISALLOW_COPY_AND_ASSIGN(DesktopCaptureDeviceAuraTest); |
101 }; | 101 }; |
102 | 102 |
103 TEST_F(DesktopCaptureDeviceAuraTest, StartAndStop) { | 103 TEST_F(DesktopCaptureDeviceAuraTest, StartAndStop) { |
104 scoped_ptr<media::VideoCaptureDevice> capture_device( | 104 scoped_ptr<media::VideoCaptureDevice> capture_device( |
105 DesktopCaptureDeviceAura::Create( | 105 DesktopCaptureDeviceAura::Create( |
106 content::DesktopMediaID::RegisterAuraWindow(root_window()))); | 106 content::DesktopMediaID::RegisterAuraWindow(root_window()))); |
107 | 107 |
108 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); | 108 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); |
109 EXPECT_CALL(*client, OnError(_)).Times(0); | 109 EXPECT_CALL(*client, OnError(_)).Times(0); |
110 | 110 |
111 media::VideoCaptureParams capture_params; | 111 media::VideoCaptureParams capture_params; |
112 capture_params.requested_format.frame_size.SetSize(640, 480); | 112 capture_params.requested_format.frame_size.SetSize(640, 480); |
113 capture_params.requested_format.frame_rate = kFrameRate; | 113 capture_params.requested_format.frame_rate = kFrameRate; |
114 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 114 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
115 capture_params.allow_resolution_change = false; | 115 capture_params.allow_resolution_change = false; |
116 capture_device->AllocateAndStart( | 116 capture_device->AllocateAndStart( |
117 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); | 117 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); |
118 capture_device->StopAndDeAllocate(); | 118 capture_device->StopAndDeAllocate(); |
119 } | 119 } |
120 | 120 |
121 } // namespace | 121 } // namespace |
122 } // namespace content | 122 } // namespace content |
OLD | NEW |