| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/strings/string_util.h" |
| 5 #include "remoting/codec/video_encoder.h" | 6 #include "remoting/codec/video_encoder.h" |
| 6 #include "remoting/host/fake_host_extension.h" | 7 #include "remoting/host/fake_host_extension.h" |
| 7 #include "remoting/host/host_extension_session_manager.h" | 8 #include "remoting/host/host_extension_session_manager.h" |
| 8 #include "remoting/host/host_mock_objects.h" | 9 #include "remoting/host/host_mock_objects.h" |
| 9 #include "remoting/proto/control.pb.h" | 10 #include "remoting/proto/control.pb.h" |
| 10 #include "remoting/protocol/protocol_mock_objects.h" | 11 #include "remoting/protocol/protocol_mock_objects.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" | 13 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" |
| 13 | 14 |
| 14 namespace remoting { | 15 namespace remoting { |
| 15 | 16 |
| 16 class HostExtensionSessionManagerTest : public testing::Test { | 17 class HostExtensionSessionManagerTest : public testing::Test { |
| 17 public: | 18 public: |
| 18 HostExtensionSessionManagerTest() | 19 HostExtensionSessionManagerTest() |
| 19 : extension1_("ext1", "cap1"), | 20 : extension1_("ext1", "cap1"), |
| 20 extension2_("ext2", ""), | 21 extension2_("ext2", std::string()), |
| 21 extension3_("ext3", "cap3") { | 22 extension3_("ext3", "cap3") { |
| 22 extensions_.push_back(&extension1_); | 23 extensions_.push_back(&extension1_); |
| 23 extensions_.push_back(&extension2_); | 24 extensions_.push_back(&extension2_); |
| 24 extensions_.push_back(&extension3_); | 25 extensions_.push_back(&extension3_); |
| 25 } | 26 } |
| 26 virtual ~HostExtensionSessionManagerTest() {} | 27 virtual ~HostExtensionSessionManagerTest() {} |
| 27 | 28 |
| 28 protected: | 29 protected: |
| 29 // Fake HostExtensions for testing. | 30 // Fake HostExtensions for testing. |
| 30 FakeExtension extension1_; | 31 FakeExtension extension1_; |
| 31 FakeExtension extension2_; | 32 FakeExtension extension2_; |
| 32 FakeExtension extension3_; | 33 FakeExtension extension3_; |
| 33 std::vector<HostExtension*> extensions_; | 34 HostExtensionSessionManager::HostExtensions extensions_; |
| 34 | 35 |
| 35 // Mocks of interfaces provided by ClientSession. | 36 // Mocks of interfaces provided by ClientSession. |
| 36 MockClientSessionControl client_session_control_; | 37 MockClientSessionControl client_session_control_; |
| 37 protocol::MockClientStub client_stub_; | 38 protocol::MockClientStub client_stub_; |
| 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(HostExtensionSessionManagerTest); |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 // Verifies that messages are passed to be handled by the correct extension. | 43 // Verifies that messages are handled by the correct extension. |
| 41 TEST_F(HostExtensionSessionManagerTest, ExtensionMessages_MessageHandled) { | 44 TEST_F(HostExtensionSessionManagerTest, ExtensionMessages_MessageHandled) { |
| 42 HostExtensionSessionManager extension_manager(extensions_, | 45 HostExtensionSessionManager extension_manager(extensions_, |
| 43 &client_session_control_); | 46 &client_session_control_); |
| 44 extension_manager.OnNegotiatedCapabilities( | 47 extension_manager.OnNegotiatedCapabilities( |
| 45 &client_stub_, extension_manager.GetCapabilities()); | 48 &client_stub_, extension_manager.GetCapabilities()); |
| 46 | 49 |
| 47 protocol::ExtensionMessage message; | 50 protocol::ExtensionMessage message; |
| 48 message.set_type("ext2"); | 51 message.set_type("ext2"); |
| 49 extension_manager.OnExtensionMessage(message); | 52 extension_manager.OnExtensionMessage(message); |
| 50 | 53 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 69 EXPECT_FALSE(extension2_.has_handled_message()); | 72 EXPECT_FALSE(extension2_.has_handled_message()); |
| 70 EXPECT_FALSE(extension3_.has_handled_message()); | 73 EXPECT_FALSE(extension3_.has_handled_message()); |
| 71 } | 74 } |
| 72 | 75 |
| 73 // Verifies that the correct set of capabilities are reported to the client, | 76 // Verifies that the correct set of capabilities are reported to the client, |
| 74 // based on the registered extensions. | 77 // based on the registered extensions. |
| 75 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreReported) { | 78 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreReported) { |
| 76 HostExtensionSessionManager extension_manager(extensions_, | 79 HostExtensionSessionManager extension_manager(extensions_, |
| 77 &client_session_control_); | 80 &client_session_control_); |
| 78 | 81 |
| 79 EXPECT_EQ(extension_manager.GetCapabilities(), "cap1 cap3"); | 82 std::vector<std::string> reported_caps; |
| 83 Tokenize(extension_manager.GetCapabilities(), " ", &reported_caps); |
| 84 std::sort(reported_caps.begin(), reported_caps.end()); |
| 85 |
| 86 ASSERT_EQ(2U, reported_caps.size()); |
| 87 EXPECT_EQ("cap1", reported_caps[0]); |
| 88 EXPECT_EQ("cap3", reported_caps[1]); |
| 80 } | 89 } |
| 81 | 90 |
| 82 // Verifies that an extension is not instantiated if the client does not | 91 // Verifies that an extension is not instantiated if the client does not |
| 83 // support its required capability, and that it does not receive messages. | 92 // support its required capability, and that it does not receive messages. |
| 84 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreChecked) { | 93 TEST_F(HostExtensionSessionManagerTest, ExtensionCapabilities_AreChecked) { |
| 85 HostExtensionSessionManager extension_manager(extensions_, | 94 HostExtensionSessionManager extension_manager(extensions_, |
| 86 &client_session_control_); | 95 &client_session_control_); |
| 87 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); | 96 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); |
| 88 | 97 |
| 89 protocol::ExtensionMessage message; | 98 protocol::ExtensionMessage message; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoCapturer) { | 109 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoCapturer) { |
| 101 HostExtensionSessionManager extension_manager(extensions_, | 110 HostExtensionSessionManager extension_manager(extensions_, |
| 102 &client_session_control_); | 111 &client_session_control_); |
| 103 | 112 |
| 104 // Set up all the extensions to request to modify the video pipeline. | 113 // Set up all the extensions to request to modify the video pipeline. |
| 105 extension1_.set_steal_video_capturer(true); | 114 extension1_.set_steal_video_capturer(true); |
| 106 extension2_.set_steal_video_capturer(true); | 115 extension2_.set_steal_video_capturer(true); |
| 107 extension3_.set_steal_video_capturer(true); | 116 extension3_.set_steal_video_capturer(true); |
| 108 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); | 117 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); |
| 109 | 118 |
| 110 extension_manager.OnCreateVideoCapturer( | 119 scoped_ptr<webrtc::DesktopCapturer> dummy_capturer; |
| 111 scoped_ptr<webrtc::DesktopCapturer>()); | 120 extension_manager.OnCreateVideoCapturer(&dummy_capturer); |
| 112 | 121 |
| 113 EXPECT_FALSE(extension1_.has_wrapped_video_encoder()); | 122 EXPECT_FALSE(extension1_.has_wrapped_video_encoder()); |
| 114 EXPECT_TRUE(extension1_.has_wrapped_video_capturer()); | 123 EXPECT_TRUE(extension1_.has_wrapped_video_capturer()); |
| 115 EXPECT_FALSE(extension2_.has_wrapped_video_encoder()); | 124 EXPECT_FALSE(extension2_.has_wrapped_video_encoder()); |
| 116 EXPECT_TRUE(extension2_.has_wrapped_video_capturer()); | 125 EXPECT_TRUE(extension2_.has_wrapped_video_capturer()); |
| 117 EXPECT_FALSE(extension3_.was_instantiated()); | 126 EXPECT_FALSE(extension3_.was_instantiated()); |
| 118 } | 127 } |
| 119 | 128 |
| 120 // Verifies that matching extensions are given the opportunity to wrap or | 129 // Verifies that matching extensions are given the opportunity to wrap or |
| 121 // replace the video encoders. | 130 // replace the video encoders. |
| 122 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoEncoder) { | 131 TEST_F(HostExtensionSessionManagerTest, CanWrapVideoEncoder) { |
| 123 HostExtensionSessionManager extension_manager(extensions_, | 132 HostExtensionSessionManager extension_manager(extensions_, |
| 124 &client_session_control_); | 133 &client_session_control_); |
| 125 | 134 |
| 126 // Set up all the extensions to request to modify the video pipeline. | 135 // Set up all the extensions to request to modify the video pipeline. |
| 127 extension1_.set_steal_video_capturer(true); | 136 extension1_.set_steal_video_capturer(true); |
| 128 extension2_.set_steal_video_capturer(true); | 137 extension2_.set_steal_video_capturer(true); |
| 129 extension3_.set_steal_video_capturer(true); | 138 extension3_.set_steal_video_capturer(true); |
| 130 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); | 139 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); |
| 131 | 140 |
| 132 extension_manager.OnCreateVideoEncoder(scoped_ptr<VideoEncoder>()); | 141 scoped_ptr<VideoEncoder> dummy_encoder; |
| 142 extension_manager.OnCreateVideoEncoder(&dummy_encoder); |
| 133 | 143 |
| 134 EXPECT_TRUE(extension1_.has_wrapped_video_encoder()); | 144 EXPECT_TRUE(extension1_.has_wrapped_video_encoder()); |
| 135 EXPECT_FALSE(extension1_.has_wrapped_video_capturer()); | 145 EXPECT_FALSE(extension1_.has_wrapped_video_capturer()); |
| 136 EXPECT_TRUE(extension2_.has_wrapped_video_encoder()); | 146 EXPECT_TRUE(extension2_.has_wrapped_video_encoder()); |
| 137 EXPECT_FALSE(extension2_.has_wrapped_video_capturer()); | 147 EXPECT_FALSE(extension2_.has_wrapped_video_capturer()); |
| 138 EXPECT_FALSE(extension3_.was_instantiated()); | 148 EXPECT_FALSE(extension3_.was_instantiated()); |
| 139 } | 149 } |
| 140 | 150 |
| 141 // Verifies that only extensions which report that they modify the video | 151 // Verifies that only extensions which report that they modify the video |
| 142 // pipeline actually get called to modify it. | 152 // pipeline actually get called to modify it. |
| 143 TEST_F(HostExtensionSessionManagerTest, RespectModifiesVideoPipeline) { | 153 TEST_F(HostExtensionSessionManagerTest, RespectModifiesVideoPipeline) { |
| 144 HostExtensionSessionManager extension_manager(extensions_, | 154 HostExtensionSessionManager extension_manager(extensions_, |
| 145 &client_session_control_); | 155 &client_session_control_); |
| 146 | 156 |
| 147 // Set up the second extension to request to modify the video pipeline. | 157 // Set up the second extension to request to modify the video pipeline. |
| 148 extension2_.set_steal_video_capturer(true); | 158 extension2_.set_steal_video_capturer(true); |
| 149 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); | 159 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); |
| 150 | 160 |
| 151 extension_manager.OnCreateVideoCapturer( | 161 scoped_ptr<webrtc::DesktopCapturer> dummy_capturer; |
| 152 scoped_ptr<webrtc::DesktopCapturer>()); | 162 extension_manager.OnCreateVideoCapturer(&dummy_capturer); |
| 153 extension_manager.OnCreateVideoEncoder(scoped_ptr<VideoEncoder>()); | 163 scoped_ptr<VideoEncoder> dummy_encoder; |
| 164 extension_manager.OnCreateVideoEncoder(&dummy_encoder); |
| 154 | 165 |
| 155 EXPECT_FALSE(extension1_.has_wrapped_video_encoder()); | 166 EXPECT_FALSE(extension1_.has_wrapped_video_encoder()); |
| 156 EXPECT_FALSE(extension1_.has_wrapped_video_capturer()); | 167 EXPECT_FALSE(extension1_.has_wrapped_video_capturer()); |
| 157 EXPECT_TRUE(extension2_.has_wrapped_video_encoder()); | 168 EXPECT_TRUE(extension2_.has_wrapped_video_encoder()); |
| 158 EXPECT_TRUE(extension2_.has_wrapped_video_capturer()); | 169 EXPECT_TRUE(extension2_.has_wrapped_video_capturer()); |
| 159 EXPECT_FALSE(extension3_.was_instantiated()); | 170 EXPECT_FALSE(extension3_.was_instantiated()); |
| 160 } | 171 } |
| 161 | 172 |
| 162 // Verifies that if an extension reports that they modify the video pipeline | 173 // Verifies that if an extension reports that it modifies the video pipeline |
| 163 // then ResetVideoPipeline() is called on the ClientSessionControl interface. | 174 // then ResetVideoPipeline() is called on the ClientSessionControl interface. |
| 164 TEST_F(HostExtensionSessionManagerTest, CallsResetVideoPipeline) { | 175 TEST_F(HostExtensionSessionManagerTest, CallsResetVideoPipeline) { |
| 165 HostExtensionSessionManager extension_manager(extensions_, | 176 HostExtensionSessionManager extension_manager(extensions_, |
| 166 &client_session_control_); | 177 &client_session_control_); |
| 167 | 178 |
| 168 EXPECT_CALL(client_session_control_, ResetVideoPipeline()); | 179 EXPECT_CALL(client_session_control_, ResetVideoPipeline()); |
| 169 | 180 |
| 170 // Set up only the first extension to request to modify the video pipeline. | 181 // Set up only the first extension to request to modify the video pipeline. |
| 171 extension1_.set_steal_video_capturer(true); | 182 extension1_.set_steal_video_capturer(true); |
| 172 | 183 |
| 173 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); | 184 extension_manager.OnNegotiatedCapabilities(&client_stub_, "cap1"); |
| 174 } | 185 } |
| 175 | 186 |
| 176 | 187 |
| 177 } // namespace remoting | 188 } // namespace remoting |
| OLD | NEW |