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

Side by Side Diff: ui/events/gesture_detection/motion_event_generic_unittest.cc

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/events/gesture_detection/motion_event_generic.h" 8 #include "ui/events/gesture_detection/motion_event_generic.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 EXPECT_EQ(9.6f, event.GetHistoricalY(2, 0)); 84 EXPECT_EQ(9.6f, event.GetHistoricalY(2, 0));
85 EXPECT_EQ(3.f, event.GetHistoricalTouchMajor(2, 0)); 85 EXPECT_EQ(3.f, event.GetHistoricalTouchMajor(2, 0));
86 } 86 }
87 87
88 TEST(MotionEventGenericTest, Clone) { 88 TEST(MotionEventGenericTest, Clone) {
89 MotionEventGeneric event(MotionEvent::ACTION_DOWN, 89 MotionEventGeneric event(MotionEvent::ACTION_DOWN,
90 base::TimeTicks::Now(), 90 base::TimeTicks::Now(),
91 PointerProperties(8.3f, 4.7f, 2.f)); 91 PointerProperties(8.3f, 4.7f, 2.f));
92 event.set_button_state(MotionEvent::BUTTON_PRIMARY); 92 event.set_button_state(MotionEvent::BUTTON_PRIMARY);
93 93
94 scoped_ptr<MotionEvent> clone = event.Clone(); 94 std::unique_ptr<MotionEvent> clone = event.Clone();
95 ASSERT_TRUE(clone); 95 ASSERT_TRUE(clone);
96 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); 96 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId());
97 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); 97 EXPECT_EQ(test::ToString(event), test::ToString(*clone));
98 } 98 }
99 99
100 TEST(MotionEventGenericTest, CloneWithHistory) { 100 TEST(MotionEventGenericTest, CloneWithHistory) {
101 base::TimeTicks event_time = base::TimeTicks::Now(); 101 base::TimeTicks event_time = base::TimeTicks::Now();
102 base::TimeTicks historical_event_time = 102 base::TimeTicks historical_event_time =
103 event_time - base::TimeDelta::FromMilliseconds(5); 103 event_time - base::TimeDelta::FromMilliseconds(5);
104 104
105 PointerProperties pointer(8.3f, 4.7f, 10.1f); 105 PointerProperties pointer(8.3f, 4.7f, 10.1f);
106 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer); 106 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer);
107 107
108 PointerProperties historical_pointer(3.4f, -4.3f, 11.5); 108 PointerProperties historical_pointer(3.4f, -4.3f, 11.5);
109 scoped_ptr<MotionEvent> historical_event(new MotionEventGeneric( 109 std::unique_ptr<MotionEvent> historical_event(new MotionEventGeneric(
110 MotionEvent::ACTION_MOVE, historical_event_time, historical_pointer)); 110 MotionEvent::ACTION_MOVE, historical_event_time, historical_pointer));
111 111
112 event.PushHistoricalEvent(std::move(historical_event)); 112 event.PushHistoricalEvent(std::move(historical_event));
113 EXPECT_EQ(1U, event.GetHistorySize()); 113 EXPECT_EQ(1U, event.GetHistorySize());
114 114
115 scoped_ptr<MotionEvent> clone = event.Clone(); 115 std::unique_ptr<MotionEvent> clone = event.Clone();
116 ASSERT_TRUE(clone); 116 ASSERT_TRUE(clone);
117 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); 117 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId());
118 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); 118 EXPECT_EQ(test::ToString(event), test::ToString(*clone));
119 } 119 }
120 120
121 TEST(MotionEventGenericTest, Cancel) { 121 TEST(MotionEventGenericTest, Cancel) {
122 MotionEventGeneric event(MotionEvent::ACTION_UP, 122 MotionEventGeneric event(MotionEvent::ACTION_UP,
123 base::TimeTicks::Now(), 123 base::TimeTicks::Now(),
124 PointerProperties(8.7f, 4.3f, 1.f)); 124 PointerProperties(8.7f, 4.3f, 1.f));
125 event.set_button_state(MotionEvent::BUTTON_SECONDARY); 125 event.set_button_state(MotionEvent::BUTTON_SECONDARY);
126 126
127 scoped_ptr<MotionEvent> cancel = event.Cancel(); 127 std::unique_ptr<MotionEvent> cancel = event.Cancel();
128 event.set_action(MotionEvent::ACTION_CANCEL); 128 event.set_action(MotionEvent::ACTION_CANCEL);
129 ASSERT_TRUE(cancel); 129 ASSERT_TRUE(cancel);
130 EXPECT_NE(event.GetUniqueEventId(), cancel->GetUniqueEventId()); 130 EXPECT_NE(event.GetUniqueEventId(), cancel->GetUniqueEventId());
131 EXPECT_EQ(test::ToString(event), test::ToString(*cancel)); 131 EXPECT_EQ(test::ToString(event), test::ToString(*cancel));
132 } 132 }
133 133
134 TEST(MotionEventGenericTest, FindPointerIndexOfId) { 134 TEST(MotionEventGenericTest, FindPointerIndexOfId) {
135 base::TimeTicks event_time = base::TimeTicks::Now(); 135 base::TimeTicks event_time = base::TimeTicks::Now();
136 PointerProperties pointer; 136 PointerProperties pointer;
137 pointer.id = 0; 137 pointer.id = 0;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 pointer0.pressure = 25; 246 pointer0.pressure = 25;
247 pointer0.touch_minor = 30; 247 pointer0.touch_minor = 30;
248 pointer0.touch_major = 35; 248 pointer0.touch_major = 35;
249 pointer0.orientation = -1; 249 pointer0.orientation = -1;
250 250
251 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer0); 251 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer0);
252 event.PushPointer(pointer1); 252 event.PushPointer(pointer1);
253 253
254 pointer0.x += 50; 254 pointer0.x += 50;
255 pointer1.x -= 50; 255 pointer1.x -= 50;
256 scoped_ptr<MotionEventGeneric> historical_event0(new MotionEventGeneric( 256 std::unique_ptr<MotionEventGeneric> historical_event0(new MotionEventGeneric(
257 MotionEvent::ACTION_MOVE, historical_event_time0, pointer0)); 257 MotionEvent::ACTION_MOVE, historical_event_time0, pointer0));
258 historical_event0->PushPointer(pointer1); 258 historical_event0->PushPointer(pointer1);
259 259
260 pointer0.x += 100; 260 pointer0.x += 100;
261 pointer1.x -= 100; 261 pointer1.x -= 100;
262 scoped_ptr<MotionEventGeneric> historical_event1(new MotionEventGeneric( 262 std::unique_ptr<MotionEventGeneric> historical_event1(new MotionEventGeneric(
263 MotionEvent::ACTION_MOVE, historical_event_time1, pointer0)); 263 MotionEvent::ACTION_MOVE, historical_event_time1, pointer0));
264 historical_event1->PushPointer(pointer1); 264 historical_event1->PushPointer(pointer1);
265 265
266 event.PushHistoricalEvent(std::move(historical_event0)); 266 event.PushHistoricalEvent(std::move(historical_event0));
267 event.PushHistoricalEvent(std::move(historical_event1)); 267 event.PushHistoricalEvent(std::move(historical_event1));
268 ASSERT_EQ(2U, event.GetHistorySize()); 268 ASSERT_EQ(2U, event.GetHistorySize());
269 ASSERT_EQ(2U, event.GetPointerCount()); 269 ASSERT_EQ(2U, event.GetPointerCount());
270 270
271 // Do a basic smoke exercise of event stringification to ensure things don't 271 // Do a basic smoke exercise of event stringification to ensure things don't
272 // explode in the process. 272 // explode in the process.
273 std::string event_string = test::ToString(event); 273 std::string event_string = test::ToString(event);
274 EXPECT_FALSE(event_string.empty()); 274 EXPECT_FALSE(event_string.empty());
275 } 275 }
276 276
277 } // namespace ui 277 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698