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

Side by Side Diff: chrome/browser/page_load_metrics/user_input_tracker_unittest.cc

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 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 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 "chrome/browser/page_load_metrics/user_input_tracker.h" 5 #include "chrome/browser/page_load_metrics/user_input_tracker.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/public/platform/WebInputEvent.h" 9 #include "third_party/WebKit/public/platform/WebInputEvent.h"
10 10
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // events are in the past. 203 // events are in the past.
204 e.setTimeStampSeconds(ToMonotonicallyIncreasingSeconds( 204 e.setTimeStampSeconds(ToMonotonicallyIncreasingSeconds(
205 e.GetTimeStamp() - 205 e.GetTimeStamp() -
206 base::TimeDelta::FromMilliseconds(kTooManyEntries * 2))); 206 base::TimeDelta::FromMilliseconds(kTooManyEntries * 2)));
207 207
208 // Insert more than kMaxEntries entries. The rate limiting logic should 208 // Insert more than kMaxEntries entries. The rate limiting logic should
209 // prevent more than kMaxEntries entries from actually being inserted. A 209 // prevent more than kMaxEntries entries from actually being inserted. A
210 // DCHECK in OnInputEvent verifies that we don't exceed the expected capacity. 210 // DCHECK in OnInputEvent verifies that we don't exceed the expected capacity.
211 for (size_t i = 0; i < kTooManyEntries; ++i) { 211 for (size_t i = 0; i < kTooManyEntries; ++i) {
212 tracker.OnInputEvent(e); 212 tracker.OnInputEvent(e);
213 e.setTimeStampSeconds(e.timeStampSeconds + 213 e.setTimeStampSeconds(e.timeStampSeconds() +
214 base::TimeDelta::FromMilliseconds(1).InSecondsF()); 214 base::TimeDelta::FromMilliseconds(1).InSecondsF());
215 } 215 }
216 216
217 // Do a basic sanity check to make sure we can find events in the tracker. 217 // Do a basic sanity check to make sure we can find events in the tracker.
218 EXPECT_NE(base::TimeTicks(), 218 EXPECT_NE(base::TimeTicks(),
219 tracker.FindMostRecentUserInputEventBefore(base::TimeTicks::Now())); 219 tracker.FindMostRecentUserInputEventBefore(base::TimeTicks::Now()));
220 } 220 }
221 221
222 TEST_F(UserInputTrackerTest, IgnoredEventType) { 222 TEST_F(UserInputTrackerTest, IgnoredEventType) {
223 UserInputTracker tracker; 223 UserInputTracker tracker;
224 FakeInputEvent e(blink::WebInputEvent::MouseMove); 224 FakeInputEvent e(blink::WebInputEvent::MouseMove);
225 tracker.OnInputEvent(e); 225 tracker.OnInputEvent(e);
226 EXPECT_EQ(base::TimeTicks(), tracker.FindMostRecentUserInputEventBefore( 226 EXPECT_EQ(base::TimeTicks(), tracker.FindMostRecentUserInputEventBefore(
227 e.GetTimeStampRounded() + 227 e.GetTimeStampRounded() +
228 base::TimeDelta::FromMilliseconds(1))); 228 base::TimeDelta::FromMilliseconds(1)));
229 } 229 }
230 230
231 TEST_F(UserInputTrackerTest, IgnoreRepeatEvents) { 231 TEST_F(UserInputTrackerTest, IgnoreRepeatEvents) {
232 UserInputTracker tracker; 232 UserInputTracker tracker;
233 FakeInputEvent e(blink::WebInputEvent::Char, 233 FakeInputEvent e(blink::WebInputEvent::Char,
234 blink::WebInputEvent::IsAutoRepeat); 234 blink::WebInputEvent::IsAutoRepeat);
235 tracker.OnInputEvent(e); 235 tracker.OnInputEvent(e);
236 EXPECT_EQ(base::TimeTicks(), tracker.FindMostRecentUserInputEventBefore( 236 EXPECT_EQ(base::TimeTicks(), tracker.FindMostRecentUserInputEventBefore(
237 e.GetTimeStampRounded() + 237 e.GetTimeStampRounded() +
238 base::TimeDelta::FromMilliseconds(1))); 238 base::TimeDelta::FromMilliseconds(1)));
239 } 239 }
240 240
241 } // namespace page_load_metrics 241 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698