1 // Copyright (c) 2012 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/protocol/clipboard_echo_filter.h"
7 #include "remoting/proto/event.pb.h"
8 #include "remoting/protocol/protocol_mock_objects.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
13 using ::testing::InSequence;
18 MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") {
19 return arg.mime_type() == mime_type && arg.data() == data;
22 static ClipboardEvent MakeClipboardEvent(const std::string& mime_type,
23 const std::string& data) {
25 event.set_mime_type(mime_type);
30 // Check that the filter only filters out events identical to the latest
31 // clipboard item from the client.
32 TEST(ClipboardEchoFilterTest, FromClientBlocksIdenticalEventToClient) {
33 MockClipboardStub client_stub;
34 MockClipboardStub host_stub;
38 EXPECT_CALL(host_stub,
39 InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
40 EXPECT_CALL(host_stub,
41 InjectClipboardEvent(EqualsClipboardEvent("text", "b")));
42 EXPECT_CALL(client_stub,
43 InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
44 EXPECT_CALL(host_stub,
45 InjectClipboardEvent(EqualsClipboardEvent("image", "a")));
46 EXPECT_CALL(client_stub,
47 InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
50 ClipboardEchoFilter filter;
51 filter.set_client_stub(&client_stub);
52 filter.set_host_stub(&host_stub);
54 filter.host_filter()->InjectClipboardEvent(
55 MakeClipboardEvent("text", "a"));
56 // The client has sent ("text", "a") to the host, so make sure the filter
57 // will stop the host echoing that item back to the client.
58 filter.client_filter()->InjectClipboardEvent(
59 MakeClipboardEvent("text", "a"));
60 filter.host_filter()->InjectClipboardEvent(
61 MakeClipboardEvent("text", "b"));
62 filter.client_filter()->InjectClipboardEvent(
63 MakeClipboardEvent("text", "a"));
64 filter.host_filter()->InjectClipboardEvent(
65 MakeClipboardEvent("image", "a"));
66 filter.client_filter()->InjectClipboardEvent(
67 MakeClipboardEvent("text", "a"));
70 // Check that the filter will drop events sent to the host, if there is no host
71 // stub, whether or not there is a client stub.
72 TEST(ClipboardEchoFilterTest, NoHostStub) {
73 MockClipboardStub client_stub;
74 MockClipboardStub host_stub;
76 EXPECT_CALL(host_stub,
77 InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
79 ClipboardEchoFilter filter;
80 ClipboardEvent event = MakeClipboardEvent("text", "a");
81 filter.host_filter()->InjectClipboardEvent(event);
83 filter.set_client_stub(&client_stub);
84 filter.host_filter()->InjectClipboardEvent(event);
86 filter.set_host_stub(&host_stub);
87 filter.host_filter()->InjectClipboardEvent(event);
90 // Check that the filter will drop events sent to the client, if there is no
91 // client stub, whether or not there is a host stub.
92 TEST(ClipboardEchoFilter, NoClientStub) {
93 MockClipboardStub client_stub;
94 MockClipboardStub host_stub;
96 EXPECT_CALL(client_stub,
97 InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
99 ClipboardEchoFilter filter;
100 ClipboardEvent event = MakeClipboardEvent("text", "a");
101 filter.client_filter()->InjectClipboardEvent(event);
103 filter.set_host_stub(&host_stub);
104 filter.client_filter()->InjectClipboardEvent(event);
106 filter.set_client_stub(&client_stub);
107 filter.client_filter()->InjectClipboardEvent(event);
110 } // namespace protocol
111 } // namespace remoting