| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/laser/laser_pointer_points.h" | 5 #include "ash/laser/laser_pointer_points.h" |
| 6 #include "ash/laser/laser_pointer_points_test_api.h" | 6 #include "ash/laser/laser_pointer_points_test_api.h" |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "ui/events/test/event_generator.h" | 8 #include "ui/events/test/event_generator.h" |
| 9 | 9 |
| 10 namespace ash { | 10 namespace ash { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); | 26 DISALLOW_COPY_AND_ASSIGN(LaserPointerPointsTest); |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 // Tests that the laser pointers internal collection handles receiving points | 31 // Tests that the laser pointers internal collection handles receiving points |
| 32 // and that the functions are returning the expected output. | 32 // and that the functions are returning the expected output. |
| 33 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { | 33 TEST_F(LaserPointerPointsTest, LaserPointerInternalCollection) { |
| 34 EXPECT_TRUE(points_.IsEmpty()); | 34 EXPECT_TRUE(points_.IsEmpty()); |
| 35 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); | 35 EXPECT_EQ(gfx::Rect(), points_.GetBoundingBox()); |
| 36 const gfx::Point left(1, 1); | 36 const gfx::PointF left(1, 1); |
| 37 const gfx::Point bottom(1, 9); | 37 const gfx::PointF bottom(1, 9); |
| 38 const gfx::Point top_right(30, 0); | 38 const gfx::PointF top_right(30, 0); |
| 39 const gfx::Point last(2, 2); | 39 const gfx::PointF last(2, 2); |
| 40 points_.AddPoint(left); | 40 points_.AddPoint(left); |
| 41 EXPECT_EQ(gfx::Rect(1, 1, 0, 0), points_.GetBoundingBox()); | 41 EXPECT_EQ(gfx::Rect(1, 1, 0, 0), points_.GetBoundingBox()); |
| 42 | 42 |
| 43 // Should be the new bottom of the bounding box. | 43 // Should be the new bottom of the bounding box. |
| 44 points_.AddPoint(bottom); | 44 points_.AddPoint(bottom); |
| 45 EXPECT_EQ(gfx::Rect(1, 1, 0, bottom.y() - 1), points_.GetBoundingBox()); | 45 EXPECT_EQ(gfx::Rect(1, 1, 0, bottom.y() - 1), points_.GetBoundingBox()); |
| 46 | 46 |
| 47 // Should be the new top and right of the bounding box. | 47 // Should be the new top and right of the bounding box. |
| 48 points_.AddPoint(top_right); | 48 points_.AddPoint(top_right); |
| 49 EXPECT_EQ(3, points_.GetNumberOfPoints()); | 49 EXPECT_EQ(3, points_.GetNumberOfPoints()); |
| 50 EXPECT_FALSE(points_.IsEmpty()); | 50 EXPECT_FALSE(points_.IsEmpty()); |
| 51 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(), | 51 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(), |
| 52 bottom.y() - top_right.y()), | 52 bottom.y() - top_right.y()), |
| 53 points_.GetBoundingBox()); | 53 points_.GetBoundingBox()); |
| 54 | 54 |
| 55 // Should not expand bounding box. | 55 // Should not expand bounding box. |
| 56 points_.AddPoint(last); | 56 points_.AddPoint(last); |
| 57 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(), | 57 EXPECT_EQ(gfx::Rect(left.x(), top_right.y(), top_right.x() - left.x(), |
| 58 bottom.y() - top_right.y()), | 58 bottom.y() - top_right.y()), |
| 59 points_.GetBoundingBox()); | 59 points_.GetBoundingBox()); |
| 60 | 60 |
| 61 // Points should be sorted in the order they are added. | 61 // Points should be sorted in the order they are added. |
| 62 EXPECT_EQ(left, points_.GetOldest().location); | 62 EXPECT_EQ(left, points_.GetOldest().location); |
| 63 EXPECT_EQ(last, points_.GetNewest().location); | 63 EXPECT_EQ(last, points_.GetNewest().location); |
| 64 | 64 |
| 65 // Add a new point which will expand the bounding box. | 65 // Add a new point which will expand the bounding box. |
| 66 gfx::Point new_left_bottom(0, 40); | 66 gfx::PointF new_left_bottom(0, 40); |
| 67 points_.AddPoint(new_left_bottom); | 67 points_.AddPoint(new_left_bottom); |
| 68 EXPECT_EQ(5, points_.GetNumberOfPoints()); | 68 EXPECT_EQ(5, points_.GetNumberOfPoints()); |
| 69 EXPECT_EQ(gfx::Rect(new_left_bottom.x(), top_right.y(), | 69 EXPECT_EQ(gfx::Rect(new_left_bottom.x(), top_right.y(), |
| 70 top_right.x() - new_left_bottom.x(), | 70 top_right.x() - new_left_bottom.x(), |
| 71 new_left_bottom.y() - top_right.y()), | 71 new_left_bottom.y() - top_right.y()), |
| 72 points_.GetBoundingBox()); | 72 points_.GetBoundingBox()); |
| 73 | 73 |
| 74 // Verify clearing works. | 74 // Verify clearing works. |
| 75 points_.Clear(); | 75 points_.Clear(); |
| 76 EXPECT_TRUE(points_.IsEmpty()); | 76 EXPECT_TRUE(points_.IsEmpty()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age); | 111 EXPECT_FLOAT_EQ(0.4, points_test_api_.GetPointAtIndex(1).age); |
| 112 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age); | 112 EXPECT_FLOAT_EQ(0.2, points_test_api_.GetPointAtIndex(2).age); |
| 113 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age); | 113 EXPECT_FLOAT_EQ(0.0, points_test_api_.GetPointAtIndex(3).age); |
| 114 | 114 |
| 115 // Verify adding 1 point three seconds later will remove 2 points which are | 115 // Verify adding 1 point three seconds later will remove 2 points which are |
| 116 // older than 5 seconds. | 116 // older than 5 seconds. |
| 117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); | 117 points_test_api_.MoveForwardInTime(base::TimeDelta::FromSeconds(3)); |
| 118 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); | 118 EXPECT_EQ(3, points_test_api_.GetNumberOfPoints()); |
| 119 } | 119 } |
| 120 } // namespace ash | 120 } // namespace ash |
| OLD | NEW |