2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/modules/desktop_capture/window_capturer.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
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"
22 class WindowCapturerTest : public testing::Test,
23 public DesktopCapturer::Callback {
25 void SetUp() OVERRIDE {
27 WindowCapturer::Create(DesktopCaptureOptions::CreateDefault()));
30 void TearDown() OVERRIDE {
33 // DesktopCapturer::Callback interface
34 virtual SharedMemory* CreateSharedMemory(size_t size) OVERRIDE {
38 virtual void OnCaptureCompleted(DesktopFrame* frame) OVERRIDE {
43 scoped_ptr<WindowCapturer> capturer_;
44 scoped_ptr<DesktopFrame> frame_;
47 // Verify that we can enumerate windows.
48 TEST_F(WindowCapturerTest, Enumerate) {
49 WindowCapturer::WindowList windows;
50 EXPECT_TRUE(capturer_->GetWindowList(&windows));
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());
59 // Verify we can capture a window.
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));
71 // Verify that we can select and capture each window.
72 for (WindowCapturer::WindowList::iterator it = windows.begin();
73 it != windows.end(); ++it) {
75 if (capturer_->SelectWindow(it->id)) {
76 capturer_->Capture(DesktopRegion());
79 // If we failed to capture a window make sure it no longer exists.
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);
90 EXPECT_GT(frame_->size().width(), 0);
91 EXPECT_GT(frame_->size().height(), 0);