| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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/client/plugin/empty_cursor_filter.h" | |
| 6 | |
| 7 #include <ostream> | |
| 8 | |
| 9 #include "remoting/proto/control.pb.h" | |
| 10 #include "remoting/protocol/cursor_shape_stub.h" | |
| 11 #include "remoting/protocol/protocol_mock_objects.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace remoting { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Chromoting cursors are always RGBA. | |
| 20 const int kBytesPerPixel = 4; | |
| 21 | |
| 22 const int kTestCursorWidth = 100; | |
| 23 const int kTestCursorHeight = 64; | |
| 24 const int kTestCursorHotspotX = 10; | |
| 25 const int kTestCursorHotspotY = 30; | |
| 26 const int kTestCursorDataSize = | |
| 27 kTestCursorWidth * kTestCursorHeight * kBytesPerPixel; | |
| 28 | |
| 29 protocol::CursorShapeInfo CreateTransparentCursorShape() { | |
| 30 protocol::CursorShapeInfo transparent_cursor; | |
| 31 transparent_cursor.set_width(kTestCursorWidth); | |
| 32 transparent_cursor.set_height(kTestCursorHeight); | |
| 33 transparent_cursor.set_hotspot_x(kTestCursorHotspotX); | |
| 34 transparent_cursor.set_hotspot_y(kTestCursorHotspotY); | |
| 35 transparent_cursor.mutable_data()->resize(kTestCursorDataSize, 0); | |
| 36 return transparent_cursor; | |
| 37 } | |
| 38 | |
| 39 protocol::CursorShapeInfo CreateOpaqueCursorShape() { | |
| 40 protocol::CursorShapeInfo cursor = CreateTransparentCursorShape(); | |
| 41 cursor.mutable_data()->assign(kTestCursorDataSize, 0x01); | |
| 42 return cursor; | |
| 43 } | |
| 44 | |
| 45 MATCHER_P(EqualsCursorShape, cursor_shape, "") { | |
| 46 // TODO(wez): Should not assume that all fields were set. | |
| 47 return arg.data() == cursor_shape.data() && | |
| 48 arg.width() == cursor_shape.width() && | |
| 49 arg.height() == cursor_shape.height() && | |
| 50 arg.hotspot_x() == cursor_shape.hotspot_x() && | |
| 51 arg.hotspot_y() == cursor_shape.hotspot_y(); | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 namespace protocol { | |
| 57 | |
| 58 // This pretty-printer must be defined under remoting::protocol to be used. | |
| 59 ::std::ostream& operator<<(::std::ostream& os, const CursorShapeInfo& cursor) { | |
| 60 return os << "[w:" << cursor.width() << ", h:" << cursor.height() | |
| 61 << ", h.x:" << cursor.hotspot_x() << ", h.y:" << cursor.hotspot_y() | |
| 62 << ", data.size:" << cursor.data().size() << "]"; | |
| 63 } | |
| 64 | |
| 65 } // namespace protocol | |
| 66 | |
| 67 // Verify that EmptyCursorShape() generates a normalized empty cursor. | |
| 68 TEST(EmptyCursorFilterTest, EmptyCursorShape) { | |
| 69 const protocol::CursorShapeInfo& empty_cursor = EmptyCursorShape(); | |
| 70 | |
| 71 // TODO(wez): Replace these individual asserts with IsCursorShapeValid()? | |
| 72 ASSERT_TRUE(empty_cursor.has_data()); | |
| 73 ASSERT_TRUE(empty_cursor.has_width()); | |
| 74 ASSERT_TRUE(empty_cursor.has_height()); | |
| 75 ASSERT_TRUE(empty_cursor.has_hotspot_x()); | |
| 76 ASSERT_TRUE(empty_cursor.has_hotspot_y()); | |
| 77 | |
| 78 EXPECT_EQ(0, empty_cursor.width()); | |
| 79 EXPECT_EQ(0, empty_cursor.height()); | |
| 80 EXPECT_EQ(0, empty_cursor.hotspot_x()); | |
| 81 EXPECT_EQ(0, empty_cursor.hotspot_y()); | |
| 82 EXPECT_TRUE(empty_cursor.data().empty()); | |
| 83 } | |
| 84 | |
| 85 // Verify that IsCursorShapeEmpty returns true only for normalized empty | |
| 86 // cursors, not for opaque or transparent non-empty cursors. | |
| 87 TEST(EmptyCursorFilterTest, IsCursorShapeEmpty) { | |
| 88 const protocol::CursorShapeInfo& kEmptyCursor = EmptyCursorShape(); | |
| 89 EXPECT_TRUE(IsCursorShapeEmpty(kEmptyCursor)); | |
| 90 | |
| 91 const protocol::CursorShapeInfo& kOpaqueCursor = CreateOpaqueCursorShape(); | |
| 92 EXPECT_FALSE(IsCursorShapeEmpty(kOpaqueCursor)); | |
| 93 | |
| 94 const protocol::CursorShapeInfo& kTransparentCursor = | |
| 95 CreateTransparentCursorShape(); | |
| 96 EXPECT_FALSE(IsCursorShapeEmpty(kTransparentCursor)); | |
| 97 } | |
| 98 | |
| 99 // Verify that EmptyCursorFilter behaves correctly for normalized empty cursors. | |
| 100 TEST(EmptyCursorFilterTest, EmptyCursor) { | |
| 101 const protocol::CursorShapeInfo& kEmptyCursor = EmptyCursorShape(); | |
| 102 protocol::MockCursorShapeStub cursor_stub; | |
| 103 EmptyCursorFilter cursor_filter(&cursor_stub); | |
| 104 | |
| 105 EXPECT_CALL(cursor_stub, SetCursorShape(EqualsCursorShape(kEmptyCursor))); | |
| 106 | |
| 107 cursor_filter.SetCursorShape(kEmptyCursor); | |
| 108 } | |
| 109 | |
| 110 // Verify that EmptyCursorFilter turns transparent cursors into empty ones. | |
| 111 TEST(EmptyCursorFilterTest, TransparentCursor) { | |
| 112 const protocol::CursorShapeInfo& kEmptyCursor = EmptyCursorShape(); | |
| 113 protocol::MockCursorShapeStub cursor_stub; | |
| 114 EmptyCursorFilter cursor_filter(&cursor_stub); | |
| 115 | |
| 116 EXPECT_CALL(cursor_stub, SetCursorShape(EqualsCursorShape(kEmptyCursor))); | |
| 117 | |
| 118 cursor_filter.SetCursorShape(CreateTransparentCursorShape()); | |
| 119 } | |
| 120 | |
| 121 // Verify that EmptyCursorFilter leaves non-transparent cursors alone. | |
| 122 TEST(EmptyCursorFilterTest, NonTransparentCursor) { | |
| 123 const protocol::CursorShapeInfo& kOpaqueCursor = CreateOpaqueCursorShape(); | |
| 124 protocol::MockCursorShapeStub cursor_stub; | |
| 125 EmptyCursorFilter cursor_filter(&cursor_stub); | |
| 126 | |
| 127 EXPECT_CALL(cursor_stub, SetCursorShape(EqualsCursorShape(kOpaqueCursor))); | |
| 128 | |
| 129 cursor_filter.SetCursorShape(kOpaqueCursor); | |
| 130 } | |
| 131 | |
| 132 } // namespace remoting | |
| OLD | NEW |