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 5 #include "remoting/protocol/clipboard_filter.h" 6 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" 11 12 using ::testing::_; 13 14 namespace remoting { 15 namespace protocol { 16 17 MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") { 18 return arg.mime_type() == mime_type && arg.data() == data; 19 } 20 21 static ClipboardEvent MakeClipboardEvent(const std::string& mime_type, 22 const std::string& data) { 23 ClipboardEvent event; 24 event.set_mime_type(mime_type); 25 event.set_data(data); 26 return event; 27 } 28 29 // Verify that the filter passes events on correctly to a configured stub. 30 TEST(ClipboardFilterTest, EventsPassThroughFilter) { 31 MockClipboardStub clipboard_stub; 32 ClipboardFilter clipboard_filter(&clipboard_stub); 33 34 EXPECT_CALL(clipboard_stub, 35 InjectClipboardEvent(EqualsClipboardEvent("text", "foo"))); 36 37 clipboard_filter.InjectClipboardEvent(MakeClipboardEvent("text","foo")); 38 } 39 40 // Verify that the filter ignores events if disabled. 41 TEST(ClipboardFilterTest, IgnoreEventsIfDisabled) { 42 MockClipboardStub clipboard_stub; 43 ClipboardFilter clipboard_filter(&clipboard_stub); 44 45 clipboard_filter.set_enabled(false); 46 47 EXPECT_CALL(clipboard_stub, InjectClipboardEvent(_)).Times(0); 48 49 clipboard_filter.InjectClipboardEvent(MakeClipboardEvent("text","foo")); 50 } 51 52 // Verify that the filter ignores events if not configured. 53 TEST(ClipboardFilterTest, IgnoreEventsIfNotConfigured) { 54 ClipboardFilter clipboard_filter; 55 56 clipboard_filter.InjectClipboardEvent(MakeClipboardEvent("text","foo")); 57 } 58 59 } // namespace protocol 60 } // namespace remoting 61