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

Unified Diff: chrome/browser/page_load_metrics/user_input_tracker_unittest.cc

Issue 2569273002: Add constructors to WebInputEvents and setters so we can work at cleaning up these public structs. (Closed)
Patch Set: Rebase Created 3 years, 12 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
Index: chrome/browser/page_load_metrics/user_input_tracker_unittest.cc
diff --git a/chrome/browser/page_load_metrics/user_input_tracker_unittest.cc b/chrome/browser/page_load_metrics/user_input_tracker_unittest.cc
index 8602f19e24f9853fcd8e6db24a877eb5fcb011f8..751eb2a273f80e5b2c3936d9aab3e91429c5e928 100644
--- a/chrome/browser/page_load_metrics/user_input_tracker_unittest.cc
+++ b/chrome/browser/page_load_metrics/user_input_tracker_unittest.cc
@@ -22,10 +22,13 @@ double ToMonotonicallyIncreasingSeconds(base::TimeTicks t) {
class FakeInputEvent : public blink::WebInputEvent {
public:
- FakeInputEvent() : WebInputEvent(sizeof(FakeInputEvent)) {
- timeStampSeconds = ToMonotonicallyIncreasingSeconds(base::TimeTicks::Now());
- type = blink::WebInputEvent::Char;
- }
+ FakeInputEvent(blink::WebInputEvent::Type type = blink::WebInputEvent::Char,
Lei Zhang 2017/02/24 08:43:23 I'm personally biased again default arguments. You
+ int modifiers = blink::WebInputEvent::NoModifiers)
+ : WebInputEvent(
+ sizeof(FakeInputEvent),
+ type,
+ modifiers,
+ ToMonotonicallyIncreasingSeconds(base::TimeTicks::Now())) {}
base::TimeTicks GetTimeStamp() {
return UserInputTracker::GetEventTime(*this);
@@ -74,8 +77,8 @@ TEST_F(UserInputTrackerTest, MultipleEvents) {
// Make sure that the two events are monotonically increasing, and that both
// are in the past.
- e1.timeStampSeconds = ToMonotonicallyIncreasingSeconds(
- e2.GetTimeStamp() - base::TimeDelta::FromMilliseconds(100));
+ e1.setTimeStampSeconds(ToMonotonicallyIncreasingSeconds(
+ e2.GetTimeStamp() - base::TimeDelta::FromMilliseconds(100)));
base::TimeTicks after =
e2.GetTimeStampRounded() + base::TimeDelta::FromMicroseconds(1);
@@ -131,8 +134,8 @@ TEST_F(UserInputTrackerTest, IgnoreEventsOlderThanConsumed) {
// Make sure that the two events are monotonically increasing, and that both
// are in the past.
- e1.timeStampSeconds = ToMonotonicallyIncreasingSeconds(
- e2.GetTimeStamp() - base::TimeDelta::FromMilliseconds(100));
+ e1.setTimeStampSeconds(ToMonotonicallyIncreasingSeconds(
+ e2.GetTimeStamp() - base::TimeDelta::FromMilliseconds(100)));
base::TimeTicks after =
e2.GetTimeStampRounded() + base::TimeDelta::FromMicroseconds(1);
@@ -164,9 +167,9 @@ TEST_F(UserInputTrackerTest, ExcludeOldEvents) {
FakeInputEvent e1;
FakeInputEvent e2;
// make sure e1 is too old to be considered.
- e1.timeStampSeconds = ToMonotonicallyIncreasingSeconds(
+ e1.setTimeStampSeconds(ToMonotonicallyIncreasingSeconds(
e2.GetTimeStamp() -
- base::TimeDelta::FromMilliseconds(kTooOldMilliseconds));
+ base::TimeDelta::FromMilliseconds(kTooOldMilliseconds)));
tracker.OnInputEvent(e1);
tracker.OnInputEvent(e2);
@@ -198,16 +201,17 @@ TEST_F(UserInputTrackerTest, RateLimit) {
// kTooManyEntries milliseconds in the past, and then synthesize one event for
// each of kTooManyEntries after this start point. This guarantees that all
// events are in the past.
- e.timeStampSeconds = ToMonotonicallyIncreasingSeconds(
+ e.setTimeStampSeconds(ToMonotonicallyIncreasingSeconds(
e.GetTimeStamp() -
- base::TimeDelta::FromMilliseconds(kTooManyEntries * 2));
+ base::TimeDelta::FromMilliseconds(kTooManyEntries * 2)));
// Insert more than kMaxEntries entries. The rate limiting logic should
// prevent more than kMaxEntries entries from actually being inserted. A
// DCHECK in OnInputEvent verifies that we don't exceed the expected capacity.
for (size_t i = 0; i < kTooManyEntries; ++i) {
tracker.OnInputEvent(e);
- e.timeStampSeconds += base::TimeDelta::FromMilliseconds(1).InSecondsF();
+ e.setTimeStampSeconds(e.timeStampSeconds +
+ base::TimeDelta::FromMilliseconds(1).InSecondsF());
}
// Do a basic sanity check to make sure we can find events in the tracker.
@@ -217,8 +221,7 @@ TEST_F(UserInputTrackerTest, RateLimit) {
TEST_F(UserInputTrackerTest, IgnoredEventType) {
UserInputTracker tracker;
- FakeInputEvent e;
- e.type = blink::WebInputEvent::MouseMove;
+ FakeInputEvent e(blink::WebInputEvent::MouseMove);
tracker.OnInputEvent(e);
EXPECT_EQ(base::TimeTicks(), tracker.FindMostRecentUserInputEventBefore(
e.GetTimeStampRounded() +
@@ -227,8 +230,8 @@ TEST_F(UserInputTrackerTest, IgnoredEventType) {
TEST_F(UserInputTrackerTest, IgnoreRepeatEvents) {
UserInputTracker tracker;
- FakeInputEvent e;
- e.modifiers |= blink::WebInputEvent::IsAutoRepeat;
+ FakeInputEvent e(blink::WebInputEvent::Char,
+ blink::WebInputEvent::IsAutoRepeat);
tracker.OnInputEvent(e);
EXPECT_EQ(base::TimeTicks(), tracker.FindMostRecentUserInputEventBefore(
e.GetTimeStampRounded() +

Powered by Google App Engine
This is Rietveld 408576698