| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/ui/public/interfaces/cursor/cursor_struct_traits.h" | 5 #include "services/ui/public/interfaces/cursor/cursor_struct_traits.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/common/common_custom_types_struct_traits.h" | 8 #include "mojo/common/common_custom_types_struct_traits.h" |
| 9 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
| 10 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" | 10 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 bitmap.eraseColor(SK_ColorRED); | 41 bitmap.eraseColor(SK_ColorRED); |
| 42 } | 42 } |
| 43 return frames; | 43 return frames; |
| 44 } | 44 } |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 // Tests numeric cursor ids. | 48 // Tests numeric cursor ids. |
| 49 TEST_F(CursorStructTraitsTest, TestBuiltIn) { | 49 TEST_F(CursorStructTraitsTest, TestBuiltIn) { |
| 50 for (int i = 0; i < 43; ++i) { | 50 for (int i = 0; i < 43; ++i) { |
| 51 ui::CursorData input(i); | 51 ui::CursorType type = static_cast<ui::CursorType>(i); |
| 52 ui::CursorData input(type); |
| 52 | 53 |
| 53 ui::CursorData output; | 54 ui::CursorData output; |
| 54 ASSERT_TRUE(EchoCursorData(input, &output)); | 55 ASSERT_TRUE(EchoCursorData(input, &output)); |
| 55 EXPECT_TRUE(output.IsType(i)); | 56 EXPECT_TRUE(output.IsType(type)); |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 | 59 |
| 59 // Test that we copy cursor bitmaps and metadata across the wire. | 60 // Test that we copy cursor bitmaps and metadata across the wire. |
| 60 TEST_F(CursorStructTraitsTest, TestBitmapCursor) { | 61 TEST_F(CursorStructTraitsTest, TestBitmapCursor) { |
| 61 const base::TimeDelta kFrameDelay = base::TimeDelta::FromMilliseconds(15); | 62 const base::TimeDelta kFrameDelay = base::TimeDelta::FromMilliseconds(15); |
| 62 const gfx::Point kHotspot = gfx::Point(5, 2); | 63 const gfx::Point kHotspot = gfx::Point(5, 2); |
| 63 const float kScale = 2.0f; | 64 const float kScale = 2.0f; |
| 64 | 65 |
| 65 ui::CursorData input(kHotspot, CreateTestCursorFrames(gfx::Size(10, 10), 3), | 66 ui::CursorData input(kHotspot, CreateTestCursorFrames(gfx::Size(10, 10), 3), |
| 66 kScale, kFrameDelay); | 67 kScale, kFrameDelay); |
| 67 | 68 |
| 68 ui::CursorData output; | 69 ui::CursorData output; |
| 69 ASSERT_TRUE(EchoCursorData(input, &output)); | 70 ASSERT_TRUE(EchoCursorData(input, &output)); |
| 70 | 71 |
| 71 EXPECT_EQ(kCursorCustom, output.cursor_type()); | 72 EXPECT_EQ(CursorType::kCustom, output.cursor_type()); |
| 72 EXPECT_EQ(kScale, output.scale_factor()); | 73 EXPECT_EQ(kScale, output.scale_factor()); |
| 73 EXPECT_EQ(kFrameDelay, output.frame_delay()); | 74 EXPECT_EQ(kFrameDelay, output.frame_delay()); |
| 74 EXPECT_EQ(kHotspot, output.hotspot_in_pixels()); | 75 EXPECT_EQ(kHotspot, output.hotspot_in_pixels()); |
| 75 | 76 |
| 76 // Even if the pixel data is logically the same, expect that it has different | 77 // Even if the pixel data is logically the same, expect that it has different |
| 77 // generation ids. | 78 // generation ids. |
| 78 EXPECT_FALSE(output.IsSameAs(input)); | 79 EXPECT_FALSE(output.IsSameAs(input)); |
| 79 | 80 |
| 80 // Make a copy of output. It should be the same as output. | 81 // Make a copy of output. It should be the same as output. |
| 81 ui::CursorData copy = output; | 82 ui::CursorData copy = output; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 for (int x = 0; x < input.cursor_frames()[f].width(); ++x) { | 93 for (int x = 0; x < input.cursor_frames()[f].width(); ++x) { |
| 93 for (int y = 0; y < input.cursor_frames()[f].height(); ++y) { | 94 for (int y = 0; y < input.cursor_frames()[f].height(); ++y) { |
| 94 EXPECT_EQ(input.cursor_frames()[f].getColor(x, y), | 95 EXPECT_EQ(input.cursor_frames()[f].getColor(x, y), |
| 95 output.cursor_frames()[f].getColor(x, y)); | 96 output.cursor_frames()[f].getColor(x, y)); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace ui | 102 } // namespace ui |
| OLD | NEW |