OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/ui/ws/cursor_location_manager.h" |
| 6 |
| 7 #include "base/atomicops.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/geometry/point.h" |
| 10 |
| 11 namespace ui { |
| 12 namespace ws { |
| 13 namespace test { |
| 14 namespace { |
| 15 |
| 16 gfx::Point Atomic32ToPoint(base::subtle::Atomic32 atomic) { |
| 17 return gfx::Point(static_cast<int16_t>(atomic >> 16), |
| 18 static_cast<int16_t>(atomic & 0xFFFF)); |
| 19 } |
| 20 |
| 21 } // namespace |
| 22 |
| 23 TEST(CursorLocationManagerTest, PositiveCoordinates) { |
| 24 const gfx::Point point(100, 150); |
| 25 |
| 26 CursorLocationManager cursor_location_manager; |
| 27 cursor_location_manager.OnMouseCursorLocationChanged(point); |
| 28 |
| 29 base::subtle::Atomic32* cursor_location_memory = nullptr; |
| 30 mojo::ScopedSharedBufferHandle handle = |
| 31 cursor_location_manager.GetCursorLocationMemory(); |
| 32 mojo::ScopedSharedBufferMapping cursor_location_mapping = |
| 33 handle->Map(sizeof(base::subtle::Atomic32)); |
| 34 ASSERT_TRUE(cursor_location_mapping); |
| 35 cursor_location_memory = |
| 36 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); |
| 37 |
| 38 base::subtle::Atomic32 location = |
| 39 base::subtle::NoBarrier_Load(cursor_location_memory); |
| 40 EXPECT_EQ(point, Atomic32ToPoint(location)); |
| 41 } |
| 42 |
| 43 TEST(CursorLocationManagerTest, NegativeCoordinates) { |
| 44 const gfx::Point point(-10, -11); |
| 45 |
| 46 CursorLocationManager cursor_location_manager; |
| 47 cursor_location_manager.OnMouseCursorLocationChanged(point); |
| 48 |
| 49 base::subtle::Atomic32* cursor_location_memory = nullptr; |
| 50 mojo::ScopedSharedBufferHandle handle = |
| 51 cursor_location_manager.GetCursorLocationMemory(); |
| 52 mojo::ScopedSharedBufferMapping cursor_location_mapping = |
| 53 handle->Map(sizeof(base::subtle::Atomic32)); |
| 54 ASSERT_TRUE(cursor_location_mapping); |
| 55 cursor_location_memory = |
| 56 reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get()); |
| 57 |
| 58 base::subtle::Atomic32 location = |
| 59 base::subtle::NoBarrier_Load(cursor_location_memory); |
| 60 EXPECT_EQ(point, Atomic32ToPoint(location)); |
| 61 } |
| 62 |
| 63 } // namespace test |
| 64 } // namespace ws |
| 65 } // namespace ui |
OLD | NEW |