| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "content/browser/browser_thread_impl.h" | |
| 15 #include "content/public/browser/desktop_media_id.h" | 14 #include "content/public/browser/desktop_media_id.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "media/capture/video_capture_types.h" | 16 #include "media/capture/video_capture_types.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/aura/client/window_parenting_client.h" | 19 #include "ui/aura/client/window_parenting_client.h" |
| 20 #include "ui/aura/test/aura_test_helper.h" | 20 #include "ui/aura/test/aura_test_helper.h" |
| 21 #include "ui/aura/test/test_window_delegate.h" | 21 #include "ui/aura/test/test_window_delegate.h" |
| 22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 23 #include "ui/compositor/test/context_factories_for_test.h" | 23 #include "ui/compositor/test/context_factories_for_test.h" |
| 24 #include "ui/wm/core/default_activation_client.h" | 24 #include "ui/wm/core/default_activation_client.h" |
| 25 | 25 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 EXPECT_EQ(media::PIXEL_STORAGE_CPU, storage); | 85 EXPECT_EQ(media::PIXEL_STORAGE_CPU, storage); |
| 86 DoResurrectLastOutputBuffer(); | 86 DoResurrectLastOutputBuffer(); |
| 87 return std::unique_ptr<Buffer>(); | 87 return std::unique_ptr<Buffer>(); |
| 88 } | 88 } |
| 89 double GetBufferPoolUtilization() const override { return 0.0; } | 89 double GetBufferPoolUtilization() const override { return 0.0; } |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 // Test harness that sets up a minimal environment with necessary stubs. | 92 // Test harness that sets up a minimal environment with necessary stubs. |
| 93 class DesktopCaptureDeviceAuraTest : public testing::Test { | 93 class DesktopCaptureDeviceAuraTest : public testing::Test { |
| 94 public: | 94 public: |
| 95 DesktopCaptureDeviceAuraTest() | 95 DesktopCaptureDeviceAuraTest() = default; |
| 96 : browser_thread_for_ui_(BrowserThread::UI, &message_loop_) {} | 96 ~DesktopCaptureDeviceAuraTest() override = default; |
| 97 ~DesktopCaptureDeviceAuraTest() override {} | |
| 98 | 97 |
| 99 protected: | 98 protected: |
| 100 void SetUp() override { | 99 void SetUp() override { |
| 101 // The ContextFactory must exist before any Compositors are created. | 100 // The ContextFactory must exist before any Compositors are created. |
| 102 bool enable_pixel_output = false; | 101 bool enable_pixel_output = false; |
| 103 ui::ContextFactory* context_factory = | 102 ui::ContextFactory* context_factory = |
| 104 ui::InitializeContextFactoryForTests(enable_pixel_output); | 103 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 105 helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 104 helper_.reset( |
| 105 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); |
| 106 helper_->SetUp(context_factory); | 106 helper_->SetUp(context_factory); |
| 107 new wm::DefaultActivationClient(helper_->root_window()); | 107 new wm::DefaultActivationClient(helper_->root_window()); |
| 108 | 108 |
| 109 // We need a window to cover desktop area so that DesktopCaptureDeviceAura | 109 // We need a window to cover desktop area so that DesktopCaptureDeviceAura |
| 110 // can use gfx::NativeWindow::GetWindowAtScreenPoint() to locate the | 110 // can use gfx::NativeWindow::GetWindowAtScreenPoint() to locate the |
| 111 // root window associated with the primary display. | 111 // root window associated with the primary display. |
| 112 gfx::Rect desktop_bounds = root_window()->bounds(); | 112 gfx::Rect desktop_bounds = root_window()->bounds(); |
| 113 window_delegate_.reset(new aura::test::TestWindowDelegate()); | 113 window_delegate_.reset(new aura::test::TestWindowDelegate()); |
| 114 desktop_window_.reset(new aura::Window(window_delegate_.get())); | 114 desktop_window_.reset(new aura::Window(window_delegate_.get())); |
| 115 desktop_window_->Init(ui::LAYER_TEXTURED); | 115 desktop_window_->Init(ui::LAYER_TEXTURED); |
| 116 desktop_window_->SetBounds(desktop_bounds); | 116 desktop_window_->SetBounds(desktop_bounds); |
| 117 aura::client::ParentWindowWithContext( | 117 aura::client::ParentWindowWithContext( |
| 118 desktop_window_.get(), root_window(), desktop_bounds); | 118 desktop_window_.get(), root_window(), desktop_bounds); |
| 119 desktop_window_->Show(); | 119 desktop_window_->Show(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void TearDown() override { | 122 void TearDown() override { |
| 123 helper_->RunAllPendingInMessageLoop(); | 123 helper_->RunAllPendingInMessageLoop(); |
| 124 root_window()->RemoveChild(desktop_window_.get()); | 124 root_window()->RemoveChild(desktop_window_.get()); |
| 125 desktop_window_.reset(); | 125 desktop_window_.reset(); |
| 126 window_delegate_.reset(); | 126 window_delegate_.reset(); |
| 127 helper_->TearDown(); | 127 helper_->TearDown(); |
| 128 ui::TerminateContextFactoryForTests(); | 128 ui::TerminateContextFactoryForTests(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 aura::Window* root_window() { return helper_->root_window(); } | 131 aura::Window* root_window() { return helper_->root_window(); } |
| 132 | 132 |
| 133 private: | 133 private: |
| 134 base::MessageLoopForUI message_loop_; | 134 TestBrowserThreadBundle thread_bundle_; |
| 135 BrowserThreadImpl browser_thread_for_ui_; | |
| 136 std::unique_ptr<aura::test::AuraTestHelper> helper_; | 135 std::unique_ptr<aura::test::AuraTestHelper> helper_; |
| 137 std::unique_ptr<aura::Window> desktop_window_; | 136 std::unique_ptr<aura::Window> desktop_window_; |
| 138 std::unique_ptr<aura::test::TestWindowDelegate> window_delegate_; | 137 std::unique_ptr<aura::test::TestWindowDelegate> window_delegate_; |
| 139 | 138 |
| 140 DISALLOW_COPY_AND_ASSIGN(DesktopCaptureDeviceAuraTest); | 139 DISALLOW_COPY_AND_ASSIGN(DesktopCaptureDeviceAuraTest); |
| 141 }; | 140 }; |
| 142 | 141 |
| 143 TEST_F(DesktopCaptureDeviceAuraTest, StartAndStop) { | 142 TEST_F(DesktopCaptureDeviceAuraTest, StartAndStop) { |
| 144 std::unique_ptr<media::VideoCaptureDevice> capture_device = | 143 std::unique_ptr<media::VideoCaptureDevice> capture_device = |
| 145 DesktopCaptureDeviceAura::Create( | 144 DesktopCaptureDeviceAura::Create( |
| 146 content::DesktopMediaID::RegisterAuraWindow( | 145 content::DesktopMediaID::RegisterAuraWindow( |
| 147 content::DesktopMediaID::TYPE_SCREEN, root_window())); | 146 content::DesktopMediaID::TYPE_SCREEN, root_window())); |
| 148 ASSERT_TRUE(capture_device); | 147 ASSERT_TRUE(capture_device); |
| 149 | 148 |
| 150 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); | 149 std::unique_ptr<MockDeviceClient> client(new MockDeviceClient()); |
| 151 EXPECT_CALL(*client, OnError(_, _)).Times(0); | 150 EXPECT_CALL(*client, OnError(_, _)).Times(0); |
| 152 | 151 |
| 153 media::VideoCaptureParams capture_params; | 152 media::VideoCaptureParams capture_params; |
| 154 capture_params.requested_format.frame_size.SetSize(640, 480); | 153 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 155 capture_params.requested_format.frame_rate = kFrameRate; | 154 capture_params.requested_format.frame_rate = kFrameRate; |
| 156 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 155 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 157 capture_device->AllocateAndStart(capture_params, std::move(client)); | 156 capture_device->AllocateAndStart(capture_params, std::move(client)); |
| 158 capture_device->StopAndDeAllocate(); | 157 capture_device->StopAndDeAllocate(); |
| 159 } | 158 } |
| 160 | 159 |
| 161 } // namespace | 160 } // namespace |
| 162 } // namespace content | 161 } // namespace content |
| OLD | NEW |