sergeyu@chromium.org | e032f9f | 2013-05-19 07:02:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/modules/desktop_capture/window_capturer.h" |
| 12 | |
| 13 | #include "gtest/gtest.h" |
sergeyu@chromium.org | 91685dc | 2013-10-12 22:40:05 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
sergeyu@chromium.org | e032f9f | 2013-05-19 07:02:48 +0000 | [diff] [blame] | 15 | #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 16 | #include "webrtc/modules/desktop_capture/desktop_region.h" |
| 17 | #include "webrtc/system_wrappers/interface/logging.h" |
| 18 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class WindowCapturerTest : public testing::Test, |
| 23 | public DesktopCapturer::Callback { |
| 24 | public: |
| 25 | void SetUp() OVERRIDE { |
sergeyu@chromium.org | 91685dc | 2013-10-12 22:40:05 +0000 | [diff] [blame] | 26 | capturer_.reset( |
| 27 | WindowCapturer::Create(DesktopCaptureOptions::CreateDefault())); |
sergeyu@chromium.org | e032f9f | 2013-05-19 07:02:48 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void TearDown() OVERRIDE { |
| 31 | } |
| 32 | |
| 33 | // DesktopCapturer::Callback interface |
| 34 | virtual SharedMemory* CreateSharedMemory(size_t size) OVERRIDE { |
| 35 | return NULL; |
| 36 | } |
| 37 | |
| 38 | virtual void OnCaptureCompleted(DesktopFrame* frame) OVERRIDE { |
| 39 | frame_.reset(frame); |
| 40 | } |
| 41 | |
| 42 | protected: |
| 43 | scoped_ptr<WindowCapturer> capturer_; |
| 44 | scoped_ptr<DesktopFrame> frame_; |
| 45 | }; |
| 46 | |
| 47 | // Verify that we can enumerate windows. |
| 48 | TEST_F(WindowCapturerTest, Enumerate) { |
| 49 | WindowCapturer::WindowList windows; |
| 50 | EXPECT_TRUE(capturer_->GetWindowList(&windows)); |
| 51 | |
sergeyu@chromium.org | e032f9f | 2013-05-19 07:02:48 +0000 | [diff] [blame] | 52 | // Verify that window titles are set. |
| 53 | for (WindowCapturer::WindowList::iterator it = windows.begin(); |
| 54 | it != windows.end(); ++it) { |
| 55 | EXPECT_FALSE(it->title.empty()); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Verify we can capture a window. |
| 60 | // |
| 61 | // TODO(sergeyu): Currently this test just looks at the windows that already |
| 62 | // exist. Ideally it should create a test window and capture from it, but there |
| 63 | // is no easy cross-platform way to create new windows (potentially we could |
| 64 | // have a python script showing Tk dialog, but launching code will differ |
| 65 | // between platforms). |
| 66 | TEST_F(WindowCapturerTest, Capture) { |
| 67 | WindowCapturer::WindowList windows; |
| 68 | capturer_->Start(this); |
| 69 | EXPECT_TRUE(capturer_->GetWindowList(&windows)); |
| 70 | |
| 71 | // Verify that we can select and capture each window. |
| 72 | for (WindowCapturer::WindowList::iterator it = windows.begin(); |
| 73 | it != windows.end(); ++it) { |
| 74 | frame_.reset(); |
| 75 | if (capturer_->SelectWindow(it->id)) { |
| 76 | capturer_->Capture(DesktopRegion()); |
| 77 | } |
| 78 | |
| 79 | // If we failed to capture a window make sure it no longer exists. |
| 80 | if (!frame_.get()) { |
| 81 | WindowCapturer::WindowList new_list; |
| 82 | EXPECT_TRUE(capturer_->GetWindowList(&new_list)); |
| 83 | for (WindowCapturer::WindowList::iterator new_list_it = windows.begin(); |
| 84 | new_list_it != windows.end(); ++new_list_it) { |
| 85 | EXPECT_FALSE(it->id == new_list_it->id); |
| 86 | } |
| 87 | continue; |
| 88 | } |
| 89 | |
| 90 | EXPECT_GT(frame_->size().width(), 0); |
| 91 | EXPECT_GT(frame_->size().height(), 0); |
| 92 | } |
| 93 | } |
| 94 | |
sergeyu@chromium.org | e032f9f | 2013-05-19 07:02:48 +0000 | [diff] [blame] | 95 | } // namespace webrtc |