MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / remoting / host / host_extension_session_manager_unittest.cc
blob5be438b9db70a9156de7638b6366137ce27237ca
1 // Copyright 2014 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.
5 #include "base/strings/string_split.h"
6 #include "base/strings/string_util.h"
7 #include "remoting/codec/video_encoder.h"
8 #include "remoting/host/fake_host_extension.h"
9 #include "remoting/host/host_extension_session_manager.h"
10 #include "remoting/host/host_mock_objects.h"
11 #include "remoting/proto/control.pb.h"
12 #include "remoting/protocol/protocol_mock_objects.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
16 namespace remoting {
18 class HostExtensionSessionManagerTest : public testing::Test {
19 public:
20 HostExtensionSessionManagerTest()
21 : extension1_("ext1", "cap1"),
22 extension2_("ext2", std::string()),
23 extension3_("ext3", "cap3") {
24 extensions_.push_back(&extension1_);
25 extensions_.push_back(&extension2_);
26 extensions_.push_back(&extension3_);
28 ~HostExtensionSessionManagerTest() override {}
30 protected:
31 // Fake HostExtensions for testing.
32 FakeExtension extension1_;
33 FakeExtension extension2_;
34 FakeExtension extension3_;
35 HostExtensionSessionManager::HostExtensions extensions_;
37 // Mocks of interfaces provided by ClientSession.
38 MockClientSessionControl client_session_control_;
39 protocol::MockClientStub client_stub_;
41 DISALLOW_COPY_AND_ASSIGN(HostExtensionSessionManagerTest);
44 // Verifies that messages are handled by the correct extension.
45 TEST_F(HostExtensionSessionManagerTest, ExtensionMessages_MessageHandled) {
46 HostExtensionSessionManager extension_manager(extensions_,
47 &client_session_control_);
48 extension_manager.OnNegotiatedCapabilities(
49 &client_stub_, extension_manager.GetCapabilities());
51 protocol::ExtensionMessage message;
52 message.set_type("ext2");
53 extension_manager.OnExtensionMessage(message);
55 EXPECT_FALSE(extension1_.has_handled_message());
56 EXPECT_TRUE(extension2_.has_handled_message());
57 EXPECT_FALSE(extension3_.has_handled_message());
60 // Verifies that extension messages not handled by extensions don't result in a
61 // crash.
62 TEST_F(HostExtensionSessionManagerTest, ExtensionMessages_MessageNotHandled) {
63 HostExtensionSessionManager extension_manager(extensions_,
64 &client_session_control_);
65 extension_manager.OnNegotiatedCapabilities(
66 &client_stub_, extension_manager.GetCapabilities());
68 protocol::ExtensionMessage message;
69 message.set_type("ext4");
70 extension_manager.OnExtensionMessage(message);
72 EXPECT_FALSE(extension1_.has_handled_message());
73 EXPECT_FALSE(extension2_.has_handled_message());
74 EXPECT_FALSE(extension3_.has_handled_message());
77 // Verifies that the correct set of capabilities are reported to the client,
78 // based on the registered extensions.
79 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreReported) {
80 HostExtensionSessionManager extension_manager(extensions_,
81 &client_session_control_);
83 std::vector<std::string> reported_caps = base::SplitString(
84 extension_manager.GetCapabilities(), " ", base::KEEP_WHITESPACE,
85 base::SPLIT_WANT_NONEMPTY);
86 std::sort(reported_caps.begin(), reported_caps.end());
88 ASSERT_EQ(2U, reported_caps.size());
89 EXPECT_EQ("cap1", reported_caps[0]);
90 EXPECT_EQ("cap3", reported_caps[1]);
93 // Verifies that an extension is not instantiated if the client does not
94 // support its required capability, and that it does not receive messages.
95 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreChecked) {
96 HostExtensionSessionManager extension_manager(extensions_,
97 &client_session_control_);
98 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
100 protocol::ExtensionMessage message;
101 message.set_type("ext3");
102 extension_manager.OnExtensionMessage(message);
104 EXPECT_TRUE(extension1_.was_instantiated());
105 EXPECT_TRUE(extension2_.was_instantiated());
106 EXPECT_FALSE(extension3_.was_instantiated());
109 // Verifies that matching extensions are given the opportunity to wrap or
110 // replace the video capturer.
111 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoCapturer) {
112 HostExtensionSessionManager extension_manager(extensions_,
113 &client_session_control_);
115 // Set up all the extensions to request to modify the video pipeline.
116 extension1_.set_steal_video_capturer(true);
117 extension2_.set_steal_video_capturer(true);
118 extension3_.set_steal_video_capturer(true);
119 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
121 scoped_ptr<webrtc::DesktopCapturer> dummy_capturer;
122 extension_manager.OnCreateVideoCapturer(&dummy_capturer);
124 EXPECT_FALSE(extension1_.has_wrapped_video_encoder());
125 EXPECT_TRUE(extension1_.has_wrapped_video_capturer());
126 EXPECT_FALSE(extension2_.has_wrapped_video_encoder());
127 EXPECT_TRUE(extension2_.has_wrapped_video_capturer());
128 EXPECT_FALSE(extension3_.was_instantiated());
131 // Verifies that matching extensions are given the opportunity to wrap or
132 // replace the video encoders.
133 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoEncoder) {
134 HostExtensionSessionManager extension_manager(extensions_,
135 &client_session_control_);
137 // Set up all the extensions to request to modify the video pipeline.
138 extension1_.set_steal_video_capturer(true);
139 extension2_.set_steal_video_capturer(true);
140 extension3_.set_steal_video_capturer(true);
141 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
143 scoped_ptr<VideoEncoder> dummy_encoder;
144 extension_manager.OnCreateVideoEncoder(&dummy_encoder);
146 EXPECT_TRUE(extension1_.has_wrapped_video_encoder());
147 EXPECT_FALSE(extension1_.has_wrapped_video_capturer());
148 EXPECT_TRUE(extension2_.has_wrapped_video_encoder());
149 EXPECT_FALSE(extension2_.has_wrapped_video_capturer());
150 EXPECT_FALSE(extension3_.was_instantiated());
153 // Verifies that only extensions which report that they modify the video
154 // pipeline actually get called to modify it.
155 TEST_F(HostExtensionSessionManagerTest, RespectModifiesVideoPipeline) {
156 HostExtensionSessionManager extension_manager(extensions_,
157 &client_session_control_);
159 // Set up the second extension to request to modify the video pipeline.
160 extension2_.set_steal_video_capturer(true);
161 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
163 scoped_ptr<webrtc::DesktopCapturer> dummy_capturer;
164 extension_manager.OnCreateVideoCapturer(&dummy_capturer);
165 scoped_ptr<VideoEncoder> dummy_encoder;
166 extension_manager.OnCreateVideoEncoder(&dummy_encoder);
168 EXPECT_FALSE(extension1_.has_wrapped_video_encoder());
169 EXPECT_FALSE(extension1_.has_wrapped_video_capturer());
170 EXPECT_TRUE(extension2_.has_wrapped_video_encoder());
171 EXPECT_TRUE(extension2_.has_wrapped_video_capturer());
172 EXPECT_FALSE(extension3_.was_instantiated());
175 // Verifies that if an extension reports that it modifies the video pipeline
176 // then ResetVideoPipeline() is called on the ClientSessionControl interface.
177 TEST_F(HostExtensionSessionManagerTest, CallsResetVideoPipeline) {
178 HostExtensionSessionManager extension_manager(extensions_,
179 &client_session_control_);
181 EXPECT_CALL(client_session_control_, ResetVideoPipeline());
183 // Set up only the first extension to request to modify the video pipeline.
184 extension1_.set_steal_video_capturer(true);
186 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
190 } // namespace remoting