Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc

Issue 1743203002: Replace scoped_ptr with unique_ptr in webrtc/modules/desktop_capture/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: More Windows reverts Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory>
12
11 #include "webrtc/modules/desktop_capture/mouse_cursor_monitor.h" 13 #include "webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
12 14
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/base/scoped_ptr.h"
15 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" 16 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
16 #include "webrtc/modules/desktop_capture/desktop_frame.h" 17 #include "webrtc/modules/desktop_capture/desktop_frame.h"
17 #include "webrtc/modules/desktop_capture/mouse_cursor.h" 18 #include "webrtc/modules/desktop_capture/mouse_cursor.h"
18 #include "webrtc/modules/desktop_capture/window_capturer.h" 19 #include "webrtc/modules/desktop_capture/window_capturer.h"
19 #include "webrtc/system_wrappers/include/logging.h" 20 #include "webrtc/system_wrappers/include/logging.h"
20 21
21 namespace webrtc { 22 namespace webrtc {
22 23
23 class MouseCursorMonitorTest : public testing::Test, 24 class MouseCursorMonitorTest : public testing::Test,
24 public MouseCursorMonitor::Callback { 25 public MouseCursorMonitor::Callback {
25 public: 26 public:
26 MouseCursorMonitorTest() 27 MouseCursorMonitorTest()
27 : position_received_(false) { 28 : position_received_(false) {
28 } 29 }
29 30
30 // MouseCursorMonitor::Callback interface 31 // MouseCursorMonitor::Callback interface
31 void OnMouseCursor(MouseCursor* cursor_image) override { 32 void OnMouseCursor(MouseCursor* cursor_image) override {
32 cursor_image_.reset(cursor_image); 33 cursor_image_.reset(cursor_image);
33 } 34 }
34 35
35 void OnMouseCursorPosition(MouseCursorMonitor::CursorState state, 36 void OnMouseCursorPosition(MouseCursorMonitor::CursorState state,
36 const DesktopVector& position) override { 37 const DesktopVector& position) override {
37 state_ = state; 38 state_ = state;
38 position_ = position; 39 position_ = position;
39 position_received_ = true; 40 position_received_ = true;
40 } 41 }
41 42
42 protected: 43 protected:
43 rtc::scoped_ptr<MouseCursor> cursor_image_; 44 std::unique_ptr<MouseCursor> cursor_image_;
44 MouseCursorMonitor::CursorState state_; 45 MouseCursorMonitor::CursorState state_;
45 DesktopVector position_; 46 DesktopVector position_;
46 bool position_received_; 47 bool position_received_;
47 }; 48 };
48 49
49 // TODO(sergeyu): On Mac we need to initialize NSApplication before running the 50 // TODO(sergeyu): On Mac we need to initialize NSApplication before running the
50 // tests. Figure out how to do that without breaking other tests in 51 // tests. Figure out how to do that without breaking other tests in
51 // modules_unittests and enable these tests on Mac. 52 // modules_unittests and enable these tests on Mac.
52 // https://code.google.com/p/webrtc/issues/detail?id=2532 53 // https://code.google.com/p/webrtc/issues/detail?id=2532
53 // 54 //
54 // Disabled on Windows due to flake, see: 55 // Disabled on Windows due to flake, see:
55 // https://code.google.com/p/webrtc/issues/detail?id=3408 56 // https://code.google.com/p/webrtc/issues/detail?id=3408
56 // Disabled on Linux due to flake, see: 57 // Disabled on Linux due to flake, see:
57 // https://code.google.com/p/webrtc/issues/detail?id=3245 58 // https://code.google.com/p/webrtc/issues/detail?id=3245
58 #if !defined(WEBRTC_MAC) && !defined(WEBRTC_WIN) && !defined(WEBRTC_LINUX) 59 #if !defined(WEBRTC_MAC) && !defined(WEBRTC_WIN) && !defined(WEBRTC_LINUX)
59 #define MAYBE(x) x 60 #define MAYBE(x) x
60 #else 61 #else
61 #define MAYBE(x) DISABLED_##x 62 #define MAYBE(x) DISABLED_##x
62 #endif 63 #endif
63 64
64 TEST_F(MouseCursorMonitorTest, MAYBE(FromScreen)) { 65 TEST_F(MouseCursorMonitorTest, MAYBE(FromScreen)) {
65 rtc::scoped_ptr<MouseCursorMonitor> capturer( 66 std::unique_ptr<MouseCursorMonitor> capturer(
66 MouseCursorMonitor::CreateForScreen( 67 MouseCursorMonitor::CreateForScreen(
67 DesktopCaptureOptions::CreateDefault(), 68 DesktopCaptureOptions::CreateDefault(),
68 webrtc::kFullDesktopScreenId)); 69 webrtc::kFullDesktopScreenId));
69 assert(capturer.get()); 70 assert(capturer.get());
70 capturer->Init(this, MouseCursorMonitor::SHAPE_AND_POSITION); 71 capturer->Init(this, MouseCursorMonitor::SHAPE_AND_POSITION);
71 capturer->Capture(); 72 capturer->Capture();
72 73
73 EXPECT_TRUE(cursor_image_.get()); 74 EXPECT_TRUE(cursor_image_.get());
74 EXPECT_GE(cursor_image_->hotspot().x(), 0); 75 EXPECT_GE(cursor_image_->hotspot().x(), 0);
75 EXPECT_LE(cursor_image_->hotspot().x(), 76 EXPECT_LE(cursor_image_->hotspot().x(),
76 cursor_image_->image()->size().width()); 77 cursor_image_->image()->size().width());
77 EXPECT_GE(cursor_image_->hotspot().y(), 0); 78 EXPECT_GE(cursor_image_->hotspot().y(), 0);
78 EXPECT_LE(cursor_image_->hotspot().y(), 79 EXPECT_LE(cursor_image_->hotspot().y(),
79 cursor_image_->image()->size().height()); 80 cursor_image_->image()->size().height());
80 81
81 EXPECT_TRUE(position_received_); 82 EXPECT_TRUE(position_received_);
82 EXPECT_EQ(MouseCursorMonitor::INSIDE, state_); 83 EXPECT_EQ(MouseCursorMonitor::INSIDE, state_);
83 } 84 }
84 85
85 TEST_F(MouseCursorMonitorTest, MAYBE(FromWindow)) { 86 TEST_F(MouseCursorMonitorTest, MAYBE(FromWindow)) {
86 DesktopCaptureOptions options = DesktopCaptureOptions::CreateDefault(); 87 DesktopCaptureOptions options = DesktopCaptureOptions::CreateDefault();
87 88
88 // First get list of windows. 89 // First get list of windows.
89 rtc::scoped_ptr<WindowCapturer> window_capturer( 90 std::unique_ptr<WindowCapturer> window_capturer(
90 WindowCapturer::Create(options)); 91 WindowCapturer::Create(options));
91 92
92 // If window capturing is not supported then skip this test. 93 // If window capturing is not supported then skip this test.
93 if (!window_capturer.get()) 94 if (!window_capturer.get())
94 return; 95 return;
95 96
96 WindowCapturer::WindowList windows; 97 WindowCapturer::WindowList windows;
97 EXPECT_TRUE(window_capturer->GetWindowList(&windows)); 98 EXPECT_TRUE(window_capturer->GetWindowList(&windows));
98 99
99 // Iterate over all windows and try capturing mouse cursor for each of them. 100 // Iterate over all windows and try capturing mouse cursor for each of them.
100 for (size_t i = 0; i < windows.size(); ++i) { 101 for (size_t i = 0; i < windows.size(); ++i) {
101 cursor_image_.reset(); 102 cursor_image_.reset();
102 position_received_ = false; 103 position_received_ = false;
103 104
104 rtc::scoped_ptr<MouseCursorMonitor> capturer( 105 std::unique_ptr<MouseCursorMonitor> capturer(
105 MouseCursorMonitor::CreateForWindow( 106 MouseCursorMonitor::CreateForWindow(
106 DesktopCaptureOptions::CreateDefault(), windows[i].id)); 107 DesktopCaptureOptions::CreateDefault(), windows[i].id));
107 assert(capturer.get()); 108 assert(capturer.get());
108 109
109 capturer->Init(this, MouseCursorMonitor::SHAPE_AND_POSITION); 110 capturer->Init(this, MouseCursorMonitor::SHAPE_AND_POSITION);
110 capturer->Capture(); 111 capturer->Capture();
111 112
112 EXPECT_TRUE(cursor_image_.get()); 113 EXPECT_TRUE(cursor_image_.get());
113 EXPECT_TRUE(position_received_); 114 EXPECT_TRUE(position_received_);
114 } 115 }
115 } 116 }
116 117
117 // Make sure that OnMouseCursorPosition() is not called in the SHAPE_ONLY mode. 118 // Make sure that OnMouseCursorPosition() is not called in the SHAPE_ONLY mode.
118 TEST_F(MouseCursorMonitorTest, MAYBE(ShapeOnly)) { 119 TEST_F(MouseCursorMonitorTest, MAYBE(ShapeOnly)) {
119 rtc::scoped_ptr<MouseCursorMonitor> capturer( 120 std::unique_ptr<MouseCursorMonitor> capturer(
120 MouseCursorMonitor::CreateForScreen( 121 MouseCursorMonitor::CreateForScreen(
121 DesktopCaptureOptions::CreateDefault(), 122 DesktopCaptureOptions::CreateDefault(),
122 webrtc::kFullDesktopScreenId)); 123 webrtc::kFullDesktopScreenId));
123 assert(capturer.get()); 124 assert(capturer.get());
124 capturer->Init(this, MouseCursorMonitor::SHAPE_ONLY); 125 capturer->Init(this, MouseCursorMonitor::SHAPE_ONLY);
125 capturer->Capture(); 126 capturer->Capture();
126 127
127 EXPECT_TRUE(cursor_image_.get()); 128 EXPECT_TRUE(cursor_image_.get());
128 EXPECT_FALSE(position_received_); 129 EXPECT_FALSE(position_received_);
129 } 130 }
130 131
131 } // namespace webrtc 132 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698