Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / remoting / host / host_extension_session_manager_unittest.cc
blobf2c875c562ffcd9d21b023156a9537e536d9988e
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 "remoting/codec/video_encoder.h"
6 #include "remoting/host/fake_host_extension.h"
7 #include "remoting/host/host_extension_session_manager.h"
8 #include "remoting/host/host_mock_objects.h"
9 #include "remoting/proto/control.pb.h"
10 #include "remoting/protocol/protocol_mock_objects.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
14 namespace remoting {
16 class HostExtensionSessionManagerTest : public testing::Test {
17 public:
18 HostExtensionSessionManagerTest()
19 : extension1_("ext1", "cap1"),
20 extension2_("ext2", ""),
21 extension3_("ext3", "cap3") {
22 extensions_.push_back(&extension1_);
23 extensions_.push_back(&extension2_);
24 extensions_.push_back(&extension3_);
26 virtual ~HostExtensionSessionManagerTest() {}
28 protected:
29 // Fake HostExtensions for testing.
30 FakeExtension extension1_;
31 FakeExtension extension2_;
32 FakeExtension extension3_;
33 std::vector<HostExtension*> extensions_;
35 // Mocks of interfaces provided by ClientSession.
36 MockClientSessionControl client_session_control_;
37 protocol::MockClientStub client_stub_;
40 // Verifies that messages are passed to be handled by the correct extension.
41 TEST_F(HostExtensionSessionManagerTest, ExtensionMessages_MessageHandled) {
42 HostExtensionSessionManager extension_manager(extensions_,
43 &client_session_control_);
44 extension_manager.OnNegotiatedCapabilities(
45 &client_stub_, extension_manager.GetCapabilities());
47 protocol::ExtensionMessage message;
48 message.set_type("ext2");
49 extension_manager.OnExtensionMessage(message);
51 EXPECT_FALSE(extension1_.has_handled_message());
52 EXPECT_TRUE(extension2_.has_handled_message());
53 EXPECT_FALSE(extension3_.has_handled_message());
56 // Verifies that extension messages not handled by extensions don't result in a
57 // crash.
58 TEST_F(HostExtensionSessionManagerTest, ExtensionMessages_MessageNotHandled) {
59 HostExtensionSessionManager extension_manager(extensions_,
60 &client_session_control_);
61 extension_manager.OnNegotiatedCapabilities(
62 &client_stub_, extension_manager.GetCapabilities());
64 protocol::ExtensionMessage message;
65 message.set_type("ext4");
66 extension_manager.OnExtensionMessage(message);
68 EXPECT_FALSE(extension1_.has_handled_message());
69 EXPECT_FALSE(extension2_.has_handled_message());
70 EXPECT_FALSE(extension3_.has_handled_message());
73 // Verifies that the correct set of capabilities are reported to the client,
74 // based on the registered extensions.
75 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreReported) {
76 HostExtensionSessionManager extension_manager(extensions_,
77 &client_session_control_);
79 EXPECT_EQ(extension_manager.GetCapabilities(), "cap1 cap3");
82 // Verifies that an extension is not instantiated if the client does not
83 // support its required capability, and that it does not receive messages.
84 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreChecked) {
85 HostExtensionSessionManager extension_manager(extensions_,
86 &client_session_control_);
87 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
89 protocol::ExtensionMessage message;
90 message.set_type("ext3");
91 extension_manager.OnExtensionMessage(message);
93 EXPECT_TRUE(extension1_.was_instantiated());
94 EXPECT_TRUE(extension2_.was_instantiated());
95 EXPECT_FALSE(extension3_.was_instantiated());
98 // Verifies that matching extensions are given the opportunity to wrap or
99 // replace the video capturer.
100 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoCapturer) {
101 HostExtensionSessionManager extension_manager(extensions_,
102 &client_session_control_);
104 // Set up all the extensions to request to modify the video pipeline.
105 extension1_.set_steal_video_capturer(true);
106 extension2_.set_steal_video_capturer(true);
107 extension3_.set_steal_video_capturer(true);
108 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
110 extension_manager.OnCreateVideoCapturer(
111 scoped_ptr<webrtc::DesktopCapturer>());
113 EXPECT_FALSE(extension1_.has_wrapped_video_encoder());
114 EXPECT_TRUE(extension1_.has_wrapped_video_capturer());
115 EXPECT_FALSE(extension2_.has_wrapped_video_encoder());
116 EXPECT_TRUE(extension2_.has_wrapped_video_capturer());
117 EXPECT_FALSE(extension3_.was_instantiated());
120 // Verifies that matching extensions are given the opportunity to wrap or
121 // replace the video encoders.
122 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoEncoder) {
123 HostExtensionSessionManager extension_manager(extensions_,
124 &client_session_control_);
126 // Set up all the extensions to request to modify the video pipeline.
127 extension1_.set_steal_video_capturer(true);
128 extension2_.set_steal_video_capturer(true);
129 extension3_.set_steal_video_capturer(true);
130 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
132 extension_manager.OnCreateVideoEncoder(scoped_ptr<VideoEncoder>());
134 EXPECT_TRUE(extension1_.has_wrapped_video_encoder());
135 EXPECT_FALSE(extension1_.has_wrapped_video_capturer());
136 EXPECT_TRUE(extension2_.has_wrapped_video_encoder());
137 EXPECT_FALSE(extension2_.has_wrapped_video_capturer());
138 EXPECT_FALSE(extension3_.was_instantiated());
141 // Verifies that only extensions which report that they modify the video
142 // pipeline actually get called to modify it.
143 TEST_F(HostExtensionSessionManagerTest, RespectModifiesVideoPipeline) {
144 HostExtensionSessionManager extension_manager(extensions_,
145 &client_session_control_);
147 // Set up the second extension to request to modify the video pipeline.
148 extension2_.set_steal_video_capturer(true);
149 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
151 extension_manager.OnCreateVideoCapturer(
152 scoped_ptr<webrtc::DesktopCapturer>());
153 extension_manager.OnCreateVideoEncoder(scoped_ptr<VideoEncoder>());
155 EXPECT_FALSE(extension1_.has_wrapped_video_encoder());
156 EXPECT_FALSE(extension1_.has_wrapped_video_capturer());
157 EXPECT_TRUE(extension2_.has_wrapped_video_encoder());
158 EXPECT_TRUE(extension2_.has_wrapped_video_capturer());
159 EXPECT_FALSE(extension3_.was_instantiated());
162 // Verifies that if an extension reports that they modify the video pipeline
163 // then ResetVideoPipeline() is called on the ClientSessionControl interface.
164 TEST_F(HostExtensionSessionManagerTest, CallsResetVideoPipeline) {
165 HostExtensionSessionManager extension_manager(extensions_,
166 &client_session_control_);
168 EXPECT_CALL(client_session_control_, ResetVideoPipeline());
170 // Set up only the first extension to request to modify the video pipeline.
171 extension1_.set_steal_video_capturer(true);
173 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1");
177 } // namespace remoting