clipboard_echo_filter_unittest.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.
  4. #include "remoting/protocol/clipboard_echo_filter.h"
  5. #include "remoting/proto/event.pb.h"
  6. #include "remoting/protocol/protocol_mock_objects.h"
  7. #include "remoting/protocol/test_event_matchers.h"
  8. #include "testing/gmock/include/gmock/gmock.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. using ::testing::_;
  11. using ::testing::InSequence;
  12. namespace remoting {
  13. namespace protocol {
  14. using test::EqualsClipboardEvent;
  15. static ClipboardEvent MakeClipboardEvent(const std::string& mime_type,
  16. const std::string& data) {
  17. ClipboardEvent event;
  18. event.set_mime_type(mime_type);
  19. event.set_data(data);
  20. return event;
  21. }
  22. // Check that the filter only filters out events identical to the latest
  23. // clipboard item from the client.
  24. TEST(ClipboardEchoFilterTest, FromClientBlocksIdenticalEventToClient) {
  25. MockClipboardStub client_stub;
  26. MockClipboardStub host_stub;
  27. {
  28. InSequence s;
  29. EXPECT_CALL(host_stub,
  30. InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
  31. EXPECT_CALL(host_stub,
  32. InjectClipboardEvent(EqualsClipboardEvent("text", "b")));
  33. EXPECT_CALL(client_stub,
  34. InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
  35. EXPECT_CALL(host_stub,
  36. InjectClipboardEvent(EqualsClipboardEvent("image", "a")));
  37. EXPECT_CALL(client_stub,
  38. InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
  39. }
  40. ClipboardEchoFilter filter;
  41. filter.set_client_stub(&client_stub);
  42. filter.set_host_stub(&host_stub);
  43. filter.host_filter()->InjectClipboardEvent(
  44. MakeClipboardEvent("text", "a"));
  45. // The client has sent ("text", "a") to the host, so make sure the filter
  46. // will stop the host echoing that item back to the client.
  47. filter.client_filter()->InjectClipboardEvent(
  48. MakeClipboardEvent("text", "a"));
  49. filter.host_filter()->InjectClipboardEvent(
  50. MakeClipboardEvent("text", "b"));
  51. filter.client_filter()->InjectClipboardEvent(
  52. MakeClipboardEvent("text", "a"));
  53. filter.host_filter()->InjectClipboardEvent(
  54. MakeClipboardEvent("image", "a"));
  55. filter.client_filter()->InjectClipboardEvent(
  56. MakeClipboardEvent("text", "a"));
  57. }
  58. // Check that the filter will drop events sent to the host, if there is no host
  59. // stub, whether or not there is a client stub.
  60. TEST(ClipboardEchoFilterTest, NoHostStub) {
  61. MockClipboardStub client_stub;
  62. MockClipboardStub host_stub;
  63. EXPECT_CALL(host_stub,
  64. InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
  65. ClipboardEchoFilter filter;
  66. ClipboardEvent event = MakeClipboardEvent("text", "a");
  67. filter.host_filter()->InjectClipboardEvent(event);
  68. filter.set_client_stub(&client_stub);
  69. filter.host_filter()->InjectClipboardEvent(event);
  70. filter.set_host_stub(&host_stub);
  71. filter.host_filter()->InjectClipboardEvent(event);
  72. }
  73. // Check that the filter will drop events sent to the client, if there is no
  74. // client stub, whether or not there is a host stub.
  75. TEST(ClipboardEchoFilter, NoClientStub) {
  76. MockClipboardStub client_stub;
  77. MockClipboardStub host_stub;
  78. EXPECT_CALL(client_stub,
  79. InjectClipboardEvent(EqualsClipboardEvent("text", "a")));
  80. ClipboardEchoFilter filter;
  81. ClipboardEvent event = MakeClipboardEvent("text", "a");
  82. filter.client_filter()->InjectClipboardEvent(event);
  83. filter.set_host_stub(&host_stub);
  84. filter.client_filter()->InjectClipboardEvent(event);
  85. filter.set_client_stub(&client_stub);
  86. filter.client_filter()->InjectClipboardEvent(event);
  87. }
  88. } // namespace protocol
  89. } // namespace remoting