Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: services/ui/ws/cursor_location_manager_unittest.cc

Issue 2696963003: Split cursor location from UserDisplayManager. (Closed)
Patch Set: Fix nits. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/ws/cursor_location_manager.cc ('k') | services/ui/ws/display_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/ws/cursor_location_manager_unittest.cc
diff --git a/services/ui/ws/cursor_location_manager_unittest.cc b/services/ui/ws/cursor_location_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e93485c403345c39e72457632bf81f484675c22c
--- /dev/null
+++ b/services/ui/ws/cursor_location_manager_unittest.cc
@@ -0,0 +1,65 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/ui/ws/cursor_location_manager.h"
+
+#include "base/atomicops.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/geometry/point.h"
+
+namespace ui {
+namespace ws {
+namespace test {
+namespace {
+
+gfx::Point Atomic32ToPoint(base::subtle::Atomic32 atomic) {
+ return gfx::Point(static_cast<int16_t>(atomic >> 16),
+ static_cast<int16_t>(atomic & 0xFFFF));
+}
+
+} // namespace
+
+TEST(CursorLocationManagerTest, PositiveCoordinates) {
+ const gfx::Point point(100, 150);
+
+ CursorLocationManager cursor_location_manager;
+ cursor_location_manager.OnMouseCursorLocationChanged(point);
+
+ base::subtle::Atomic32* cursor_location_memory = nullptr;
+ mojo::ScopedSharedBufferHandle handle =
+ cursor_location_manager.GetCursorLocationMemory();
+ mojo::ScopedSharedBufferMapping cursor_location_mapping =
+ handle->Map(sizeof(base::subtle::Atomic32));
+ ASSERT_TRUE(cursor_location_mapping);
+ cursor_location_memory =
+ reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get());
+
+ base::subtle::Atomic32 location =
+ base::subtle::NoBarrier_Load(cursor_location_memory);
+ EXPECT_EQ(point, Atomic32ToPoint(location));
+}
+
+TEST(CursorLocationManagerTest, NegativeCoordinates) {
+ const gfx::Point point(-10, -11);
+
+ CursorLocationManager cursor_location_manager;
+ cursor_location_manager.OnMouseCursorLocationChanged(point);
+
+ base::subtle::Atomic32* cursor_location_memory = nullptr;
+ mojo::ScopedSharedBufferHandle handle =
+ cursor_location_manager.GetCursorLocationMemory();
+ mojo::ScopedSharedBufferMapping cursor_location_mapping =
+ handle->Map(sizeof(base::subtle::Atomic32));
+ ASSERT_TRUE(cursor_location_mapping);
+ cursor_location_memory =
+ reinterpret_cast<base::subtle::Atomic32*>(cursor_location_mapping.get());
+
+ base::subtle::Atomic32 location =
+ base::subtle::NoBarrier_Load(cursor_location_memory);
+ EXPECT_EQ(point, Atomic32ToPoint(location));
+}
+
+} // namespace test
+} // namespace ws
+} // namespace ui
« no previous file with comments | « services/ui/ws/cursor_location_manager.cc ('k') | services/ui/ws/display_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698