Chromium Code Reviews| Index: remoting/protocol/clipboard_duplicate_filter_unittest.cc |
| diff --git a/remoting/protocol/clipboard_duplicate_filter_unittest.cc b/remoting/protocol/clipboard_duplicate_filter_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9359b7d4c0b226b981d53e9d6954f4057f017cec |
| --- /dev/null |
| +++ b/remoting/protocol/clipboard_duplicate_filter_unittest.cc |
| @@ -0,0 +1,161 @@ |
| +// 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_duplicate_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 a subsequent |
| +// identical event from the host. |
|
Wez
2012/05/16 20:51:43
This case actually tests more than that; it also t
simonmorris
2012/05/16 22:35:25
Done.
|
| +TEST(ClipboardDuplicateFilterTest, 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"))); |
| + } |
| + |
| + ClipboardDuplicateFilter filter; |
| + filter.set_to_client(&client_stub); |
| + filter.set_to_host(&host_stub); |
| + |
| + filter.get_filter_to_host()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + // We know the client has ("text", "a") on its clipboard, so don't send it |
| + // the same item. |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + filter.get_filter_to_host()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "b")); |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + filter.get_filter_to_host()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "a")); |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| +} |
| + |
| +// Check that a clipboard event to the client filters out a subsequent |
| +// identical event to the client, but that an intermediate different event to |
| +// the host lets the subsequent event get to the client. |
| +TEST(ClipboardDuplicateFilterTest, ToClientBlocksIdenticalEventToClient) { |
| + MockClipboardStub client_stub; |
| + MockClipboardStub host_stub; |
| + |
| + { |
| + InSequence s; |
| + EXPECT_CALL(client_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("text", "a"))); |
| + EXPECT_CALL(client_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("text", "b"))); |
| + EXPECT_CALL(client_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("image", "b"))); |
| + EXPECT_CALL(host_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("text", "a"))); |
| + EXPECT_CALL(client_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("image", "b"))); |
| + EXPECT_CALL(host_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("image", "b"))); |
| + } |
| + |
| + ClipboardDuplicateFilter filter; |
| + filter.set_to_client(&client_stub); |
| + filter.set_to_host(&host_stub); |
| + |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "b")); |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| + // The client already has ("image", "b") on the clipboard, so don't send it |
| + // again. |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| + filter.get_filter_to_host()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + // The next event is a duplicate of the previous event sent to the client, |
| + // but by now we know that the client has ("text", "a") on its clipboard, |
| + // so we need to send ("image", "b") again. |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| + filter.get_filter_to_host()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| + // In this case, the client still has ("image", "b") on its clipboard, so |
| + // we don't send it again. |
| + filter.get_filter_to_client()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| +} |
| + |
| +// Check what happens if no to-host stub is set. |
| +TEST(ClipboardDuplicateFilterTest, NoToHost) { |
| + MockClipboardStub client_stub; |
| + MockClipboardStub host_stub; |
| + |
| + EXPECT_CALL(host_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("text", "a"))); |
| + |
| + ClipboardDuplicateFilter filter; |
| + ClipboardEvent event = MakeClipboardEvent("text", "a"); |
| + filter.get_filter_to_host()->InjectClipboardEvent(event); |
| + |
| + filter.set_to_client(&client_stub); |
| + filter.get_filter_to_host()->InjectClipboardEvent(event); |
| + |
| + filter.set_to_host(&host_stub); |
| + filter.get_filter_to_host()->InjectClipboardEvent(event); |
| +} |
| + |
| +// Check what happens if no to-client stub is set. |
| +TEST(ClipboardDuplicateFilter, NoToClient) { |
| + MockClipboardStub client_stub; |
| + MockClipboardStub host_stub; |
| + |
| + EXPECT_CALL(client_stub, |
| + InjectClipboardEvent(EqualsClipboardEvent("text", "a"))); |
| + |
| + ClipboardDuplicateFilter filter; |
| + ClipboardEvent event = MakeClipboardEvent("text", "a"); |
| + filter.get_filter_to_client()->InjectClipboardEvent(event); |
| + |
| + filter.set_to_host(&host_stub); |
| + filter.get_filter_to_client()->InjectClipboardEvent(event); |
| + |
| + filter.set_to_client(&client_stub); |
| + filter.get_filter_to_client()->InjectClipboardEvent(event); |
| +} |
| + |
| +} // namespace protocol |
| +} // namespace remoting |