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

Side by Side Diff: remoting/host/mouse_shape_pump_unittest.cc

Issue 883673004: Cleanup VideoFramePump. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename_scheduler
Patch Set: Created 5 years, 10 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
« no previous file with comments | « remoting/host/mouse_shape_pump.cc ('k') | remoting/host/video_frame_pump.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/mouse_shape_pump.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h"
11 #include "remoting/base/auto_thread.h"
12 #include "remoting/base/auto_thread_task_runner.h"
13 #include "remoting/host/host_mock_objects.h"
14 #include "remoting/proto/control.pb.h"
15 #include "remoting/proto/video.pb.h"
16 #include "remoting/protocol/protocol_mock_objects.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
20 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h"
21 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
22
23 using ::remoting::protocol::MockClientStub;
24
25 using ::testing::_;
26 using ::testing::DoAll;
27 using ::testing::InSequence;
28 using ::testing::InvokeWithoutArgs;
29
30 namespace remoting {
31
32 static const int kCursorWidth = 64;
33 static const int kCursorHeight = 32;
34 static const int kHotspotX = 11;
35 static const int kHotspotY = 12;
36
37 class ThreadCheckMouseCursorMonitor : public webrtc::MouseCursorMonitor {
38 public:
39 ThreadCheckMouseCursorMonitor(
40 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
41 : task_runner_(task_runner), callback_(nullptr) {
42 }
43 ~ThreadCheckMouseCursorMonitor() override {
44 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
45 }
46
47 void Init(Callback* callback, Mode mode) override {
48 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
49 EXPECT_FALSE(callback_);
50 EXPECT_TRUE(callback);
51
52 callback_ = callback;
53 }
54
55 void Capture() override {
56 EXPECT_TRUE(task_runner_->BelongsToCurrentThread());
57 ASSERT_TRUE(callback_);
58
59 scoped_ptr<webrtc::MouseCursor> mouse_cursor(new webrtc::MouseCursor(
60 new webrtc::BasicDesktopFrame(
61 webrtc::DesktopSize(kCursorWidth, kCursorHeight)),
62 webrtc::DesktopVector(kHotspotX, kHotspotY)));
63
64 callback_->OnMouseCursor(mouse_cursor.release());
65 }
66
67 private:
68 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
69
70 Callback* callback_;
71
72 DISALLOW_COPY_AND_ASSIGN(ThreadCheckMouseCursorMonitor);
73 };
74
75 class MouseShapePumpTest : public testing::Test {
76 public:
77 void SetUp() override;
78 void TearDown() override;
79
80 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape);
81
82 protected:
83 base::MessageLoop message_loop_;
84 base::RunLoop run_loop_;
85 scoped_refptr<AutoThreadTaskRunner> capture_task_runner_;
86 scoped_refptr<AutoThreadTaskRunner> main_task_runner_;
87 scoped_ptr<MouseShapePump> pump_;
88
89 MockClientStub client_stub_;
90 };
91
92 void MouseShapePumpTest::SetUp() {
93 main_task_runner_ = new AutoThreadTaskRunner(
94 message_loop_.message_loop_proxy(), run_loop_.QuitClosure());
95 capture_task_runner_ = AutoThread::Create("capture", main_task_runner_);
96 }
97
98 void MouseShapePumpTest::TearDown() {
99 pump_.reset();
100
101 // Release the task runners, so that the test can quit.
102 capture_task_runner_ = nullptr;
103 main_task_runner_ = nullptr;
104
105 // Run the MessageLoop until everything has torn down.
106 run_loop_.Run();
107 }
108
109 void MouseShapePumpTest::SetCursorShape(
110 const protocol::CursorShapeInfo& cursor_shape) {
111 EXPECT_TRUE(cursor_shape.has_width());
112 EXPECT_EQ(kCursorWidth, cursor_shape.width());
113 EXPECT_TRUE(cursor_shape.has_height());
114 EXPECT_EQ(kCursorHeight, cursor_shape.height());
115 EXPECT_TRUE(cursor_shape.has_hotspot_x());
116 EXPECT_EQ(kHotspotX, cursor_shape.hotspot_x());
117 EXPECT_TRUE(cursor_shape.has_hotspot_y());
118 EXPECT_EQ(kHotspotY, cursor_shape.hotspot_y());
119 EXPECT_TRUE(cursor_shape.has_data());
120 EXPECT_EQ(kCursorWidth * kCursorHeight * webrtc::DesktopFrame::kBytesPerPixel,
121 static_cast<int>(cursor_shape.data().size()));
122 }
123
124 // This test mocks MouseCursorMonitor and ClientStub to verify that the
125 // MouseShapePump sends the cursor successfully.
126 TEST_F(MouseShapePumpTest, FirstCursor) {
127 scoped_ptr<ThreadCheckMouseCursorMonitor> cursor_monitor(
128 new ThreadCheckMouseCursorMonitor(capture_task_runner_));
129
130 base::RunLoop run_loop;
131
132 // Stop the |run_loop| once it has captured the cursor.
133 EXPECT_CALL(client_stub_, SetCursorShape(_))
134 .WillOnce(DoAll(
135 Invoke(this, &MouseShapePumpTest::SetCursorShape),
136 InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)))
137 .RetiresOnSaturation();
138
139 // Start the pump.
140 pump_.reset(new MouseShapePump(capture_task_runner_, cursor_monitor.Pass(),
141 &client_stub_));
142
143 run_loop.Run();
144 }
145
146 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/mouse_shape_pump.cc ('k') | remoting/host/video_frame_pump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698