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

Unified Diff: remoting/protocol/clipboard_echo_filter_unittest.cc

Issue 10399052: [Chromoting] Add a filter that will stop the host sending unnecessary clipboard events to the clien… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/protocol/clipboard_echo_filter.cc ('k') | remoting/protocol/host_control_dispatcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/clipboard_echo_filter_unittest.cc
diff --git a/remoting/protocol/clipboard_echo_filter_unittest.cc b/remoting/protocol/clipboard_echo_filter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..25f5de101d645b5142a9318a922468f31670a037
--- /dev/null
+++ b/remoting/protocol/clipboard_echo_filter_unittest.cc
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/protocol/clipboard_echo_filter.h"
+
+#include "remoting/proto/event.pb.h"
+#include "remoting/protocol/protocol_mock_objects.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+using ::testing::InSequence;
+
+namespace remoting {
+namespace protocol {
+
+MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") {
+ return arg.mime_type() == mime_type && arg.data() == data;
+}
+
+static ClipboardEvent MakeClipboardEvent(const std::string& mime_type,
+ const std::string& data) {
+ ClipboardEvent event;
+ event.set_mime_type(mime_type);
+ event.set_data(data);
+ return event;
+}
+
+// Check that the filter only filters out events identical to the latest
+// clipboard item from the client.
+TEST(ClipboardEchoFilterTest, FromClientBlocksIdenticalEventToClient) {
+ MockClipboardStub client_stub;
+ MockClipboardStub host_stub;
+
+ {
+ InSequence s;
+ EXPECT_CALL(host_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
+ EXPECT_CALL(host_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("text", "b")));
+ EXPECT_CALL(client_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
+ EXPECT_CALL(host_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("image", "a")));
+ EXPECT_CALL(client_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
+ }
+
+ ClipboardEchoFilter filter;
+ filter.set_client_stub(&client_stub);
+ filter.set_host_stub(&host_stub);
+
+ filter.host_filter()->InjectClipboardEvent(
+ MakeClipboardEvent("text", "a"));
+ // The client has sent ("text", "a") to the host, so make sure the filter
+ // will stop the host echoing that item back to the client.
+ filter.client_filter()->InjectClipboardEvent(
+ MakeClipboardEvent("text", "a"));
+ filter.host_filter()->InjectClipboardEvent(
+ MakeClipboardEvent("text", "b"));
+ filter.client_filter()->InjectClipboardEvent(
+ MakeClipboardEvent("text", "a"));
+ filter.host_filter()->InjectClipboardEvent(
+ MakeClipboardEvent("image", "a"));
+ filter.client_filter()->InjectClipboardEvent(
+ MakeClipboardEvent("text", "a"));
+}
+
+// Check that the filter will drop events sent to the host, if there is no host
+// stub, whether or not there is a client stub.
+TEST(ClipboardEchoFilterTest, NoHostStub) {
+ MockClipboardStub client_stub;
+ MockClipboardStub host_stub;
+
+ EXPECT_CALL(host_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
+
+ ClipboardEchoFilter filter;
+ ClipboardEvent event = MakeClipboardEvent("text", "a");
+ filter.host_filter()->InjectClipboardEvent(event);
+
+ filter.set_client_stub(&client_stub);
+ filter.host_filter()->InjectClipboardEvent(event);
+
+ filter.set_host_stub(&host_stub);
+ filter.host_filter()->InjectClipboardEvent(event);
+}
+
+// Check that the filter will drop events sent to the client, if there is no
+// client stub, whether or not there is a host stub.
+TEST(ClipboardEchoFilter, NoClientStub) {
+ MockClipboardStub client_stub;
+ MockClipboardStub host_stub;
+
+ EXPECT_CALL(client_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
+
+ ClipboardEchoFilter filter;
+ ClipboardEvent event = MakeClipboardEvent("text", "a");
+ filter.client_filter()->InjectClipboardEvent(event);
+
+ filter.set_host_stub(&host_stub);
+ filter.client_filter()->InjectClipboardEvent(event);
+
+ filter.set_client_stub(&client_stub);
+ filter.client_filter()->InjectClipboardEvent(event);
+}
+
+} // namespace protocol
+} // namespace remoting
« no previous file with comments | « remoting/protocol/clipboard_echo_filter.cc ('k') | remoting/protocol/host_control_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698