Chromium Code Reviews| 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..35e70b186173b6a391cb5292e758b7ff3fde7683 |
| --- /dev/null |
| +++ b/remoting/protocol/clipboard_echo_filter_unittest.cc |
| @@ -0,0 +1,109 @@ |
| +// 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 a clipboard event to the host filters out only a subsequent |
| +// identical event from the host. |
|
Wez
2012/05/21 22:33:15
nit: Suggest "... the host only filters out events
simonmorris
2012/05/21 23:01:33
Done.
|
| +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.get_host_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + // We know the client has ("text", "a") on its clipboard, so don't send it |
| + // the same item. |
|
Wez
2012/05/21 22:33:15
nit: This reads as documentation of what we're doi
simonmorris
2012/05/21 23:01:33
Done.
|
| + filter.get_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + filter.get_host_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "b")); |
| + filter.get_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + filter.get_host_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "a")); |
| + filter.get_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| +} |
| + |
| +// Check what happens if no host stub is set. |
|
Wez
2012/05/21 22:33:15
Can you update this description to indicate the ex
simonmorris
2012/05/21 23:01:33
Done.
|
| +TEST(ClipboardEchoFilterTest, NoToHost) { |
| + MockClipboardStub client_stub; |
| + MockClipboardStub host_stub; |
| + |
| + EXPECT_CALL(host_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("text", "a"))); |
| + |
| + ClipboardEchoFilter filter; |
| + ClipboardEvent event = MakeClipboardEvent("text", "a"); |
| + filter.get_host_filter()->InjectClipboardEvent(event); |
| + |
| + filter.set_client_stub(&client_stub); |
| + filter.get_host_filter()->InjectClipboardEvent(event); |
| + |
| + filter.set_host_stub(&host_stub); |
| + filter.get_host_filter()->InjectClipboardEvent(event); |
| +} |
| + |
| +// Check what happens if no client stub is set. |
| +TEST(ClipboardEchoFilter, NoToClient) { |
| + MockClipboardStub client_stub; |
| + MockClipboardStub host_stub; |
| + |
| + EXPECT_CALL(client_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("text", "a"))); |
| + |
| + ClipboardEchoFilter filter; |
| + ClipboardEvent event = MakeClipboardEvent("text", "a"); |
| + filter.get_client_filter()->InjectClipboardEvent(event); |
| + |
| + filter.set_host_stub(&host_stub); |
| + filter.get_client_filter()->InjectClipboardEvent(event); |
| + |
| + filter.set_client_stub(&client_stub); |
| + filter.get_client_filter()->InjectClipboardEvent(event); |
| +} |
| + |
| +} // namespace protocol |
| +} // namespace remoting |