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..bfe1adabb1ec3fadd13101bee26ff2a0e6765d33 |
| --- /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 only a subsequent |
| +// identical event from the host. |
| +TEST(ClipboardDuplicateFilterTest, FromClientBlocksIdenticalEventToClient) { |
|
Wez
2012/05/18 18:51:52
I'll review the unit-tests after you've update the
|
| + 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_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. |
| + 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 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_client_stub(&client_stub); |
| + filter.set_host_stub(&host_stub); |
| + |
| + filter.get_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "a")); |
| + filter.get_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("text", "b")); |
| + filter.get_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| + // The client already has ("image", "b") on the clipboard, so don't send it |
| + // again. |
| + filter.get_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| + filter.get_host_filter()->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_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| + filter.get_host_filter()->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_client_filter()->InjectClipboardEvent( |
| + MakeClipboardEvent("image", "b")); |
| +} |
| + |
| +// Check what happens if no 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_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(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_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 |