| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.h" | 5 #include "content/browser/media/capture/desktop_capture_device.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 18 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 17 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" | 19 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 18 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" | 20 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" |
| 19 | 21 |
| 20 using ::testing::_; | 22 using ::testing::_; |
| 21 using ::testing::AnyNumber; | 23 using ::testing::AnyNumber; |
| 22 using ::testing::DoAll; | 24 using ::testing::DoAll; |
| 23 using ::testing::Expectation; | 25 using ::testing::Expectation; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 private: | 132 private: |
| 131 Callback* callback_; | 133 Callback* callback_; |
| 132 int frame_index_; | 134 int frame_index_; |
| 133 bool generate_inverted_frames_; | 135 bool generate_inverted_frames_; |
| 134 }; | 136 }; |
| 135 | 137 |
| 136 } // namespace | 138 } // namespace |
| 137 | 139 |
| 138 class DesktopCaptureDeviceTest : public testing::Test { | 140 class DesktopCaptureDeviceTest : public testing::Test { |
| 139 public: | 141 public: |
| 140 virtual void SetUp() OVERRIDE { | |
| 141 worker_pool_ = new base::SequencedWorkerPool(3, "TestCaptureThread"); | |
| 142 } | |
| 143 | |
| 144 void CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer> capturer) { | 142 void CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer> capturer) { |
| 143 scoped_refptr<base::SequencedWorkerPool> worker_pool = |
| 144 BrowserThread::GetBlockingPool(); |
| 145 capture_device_.reset(new DesktopCaptureDevice( | 145 capture_device_.reset(new DesktopCaptureDevice( |
| 146 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), | 146 worker_pool->GetSequencedTaskRunner(worker_pool->GetSequenceToken()), |
| 147 thread_.Pass(), | 147 scoped_ptr<base::Thread>(), |
| 148 capturer.Pass(), | 148 capturer.Pass(), |
| 149 DesktopMediaID::TYPE_SCREEN)); | 149 DesktopMediaID::TYPE_SCREEN)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 protected: | 152 protected: |
| 153 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 153 TestBrowserThreadBundle thread_bundle_; |
| 154 scoped_ptr<base::Thread> thread_; | |
| 155 scoped_ptr<DesktopCaptureDevice> capture_device_; | 154 scoped_ptr<DesktopCaptureDevice> capture_device_; |
| 156 }; | 155 }; |
| 157 | 156 |
| 158 // There is currently no screen capturer implementation for ozone. So disable | 157 // There is currently no screen capturer implementation for ozone. So disable |
| 159 // the test that uses a real screen-capturer instead of FakeScreenCapturer. | 158 // the test that uses a real screen-capturer instead of FakeScreenCapturer. |
| 160 // http://crbug.com/260318 | 159 // http://crbug.com/260318 |
| 161 #if defined(USE_OZONE) | 160 #if defined(USE_OZONE) |
| 162 #define MAYBE_Capture DISABLED_Capture | 161 #define MAYBE_Capture DISABLED_Capture |
| 163 #else | 162 #else |
| 164 #define MAYBE_Capture Capture | 163 #define MAYBE_Capture Capture |
| (...skipping 23 matching lines...) Expand all Loading... |
| 188 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); | 187 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); |
| 189 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 188 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 190 capture_device_->StopAndDeAllocate(); | 189 capture_device_->StopAndDeAllocate(); |
| 191 | 190 |
| 192 EXPECT_GT(format.frame_size.width(), 0); | 191 EXPECT_GT(format.frame_size.width(), 0); |
| 193 EXPECT_GT(format.frame_size.height(), 0); | 192 EXPECT_GT(format.frame_size.height(), 0); |
| 194 EXPECT_EQ(kFrameRate, format.frame_rate); | 193 EXPECT_EQ(kFrameRate, format.frame_rate); |
| 195 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); | 194 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); |
| 196 | 195 |
| 197 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); | 196 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); |
| 198 worker_pool_->FlushForTesting(); | 197 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 199 } | 198 } |
| 200 | 199 |
| 201 // Test that screen capturer behaves correctly if the source frame size changes | 200 // Test that screen capturer behaves correctly if the source frame size changes |
| 202 // but the caller cannot cope with variable resolution output. | 201 // but the caller cannot cope with variable resolution output. |
| 203 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { | 202 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { |
| 204 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 203 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
| 205 | 204 |
| 206 CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 205 CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
| 207 | 206 |
| 208 media::VideoCaptureFormat format; | 207 media::VideoCaptureFormat format; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 233 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 232 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 234 | 233 |
| 235 capture_device_->StopAndDeAllocate(); | 234 capture_device_->StopAndDeAllocate(); |
| 236 | 235 |
| 237 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); | 236 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); |
| 238 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); | 237 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); |
| 239 EXPECT_EQ(kFrameRate, format.frame_rate); | 238 EXPECT_EQ(kFrameRate, format.frame_rate); |
| 240 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); | 239 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); |
| 241 | 240 |
| 242 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); | 241 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); |
| 243 worker_pool_->FlushForTesting(); | 242 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 244 } | 243 } |
| 245 | 244 |
| 246 // Test that screen capturer behaves correctly if the source frame size changes | 245 // Test that screen capturer behaves correctly if the source frame size changes |
| 247 // and the caller can cope with variable resolution output. | 246 // and the caller can cope with variable resolution output. |
| 248 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { | 247 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { |
| 249 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 248 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
| 250 | 249 |
| 251 CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 250 CreateScreenCaptureDevice(scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
| 252 | 251 |
| 253 media::VideoCaptureFormat format; | 252 media::VideoCaptureFormat format; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 276 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 275 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 277 done_event.Reset(); | 276 done_event.Reset(); |
| 278 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 277 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 279 | 278 |
| 280 capture_device_->StopAndDeAllocate(); | 279 capture_device_->StopAndDeAllocate(); |
| 281 | 280 |
| 282 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); | 281 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); |
| 283 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); | 282 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); |
| 284 EXPECT_EQ(kFrameRate, format.frame_rate); | 283 EXPECT_EQ(kFrameRate, format.frame_rate); |
| 285 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); | 284 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); |
| 286 worker_pool_->FlushForTesting(); | 285 BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 287 } | 286 } |
| 288 | 287 |
| 289 } // namespace content | 288 } // namespace content |
| OLD | NEW |