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

Side by Side Diff: components/scheduler/renderer/user_model_unittest.cc

Issue 1683583002: Report user actions when gesture starts and stops in user_model. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/scheduler/renderer/user_model.h" 5 #include "components/scheduler/renderer/user_model.h"
6 6
7 #include "base/test/simple_test_tick_clock.h" 7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/test/test_simple_task_runner.h"
8 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace scheduler { 12 namespace scheduler {
12 13
13 class UserModelTest : public testing::Test { 14 class UserModelTest : public testing::Test {
14 public: 15 public:
15 UserModelTest() {} 16 UserModelTest() : mock_task_runner_(new base::TestSimpleTaskRunner()) {}
16 ~UserModelTest() override {} 17 ~UserModelTest() override {}
17 18
18 void SetUp() override { 19 void SetUp() override {
19 clock_.reset(new base::SimpleTestTickClock()); 20 clock_.reset(new base::SimpleTestTickClock());
20 clock_->Advance(base::TimeDelta::FromMicroseconds(5000)); 21 clock_->Advance(base::TimeDelta::FromMicroseconds(5000));
21 22
22 user_model_.reset(new UserModel()); 23 user_model_.reset(new UserModel(mock_task_runner_));
23 } 24 }
24 25
25 protected: 26 protected:
26 static base::TimeDelta priority_escalation_after_input_duration() { 27 static base::TimeDelta priority_escalation_after_input_duration() {
27 return base::TimeDelta::FromMilliseconds( 28 return base::TimeDelta::FromMilliseconds(
28 UserModel::kGestureEstimationLimitMillis); 29 UserModel::kGestureEstimationLimitMillis);
29 } 30 }
30 31
31 static base::TimeDelta subsequent_input_expected_after_input_duration() { 32 static base::TimeDelta subsequent_input_expected_after_input_duration() {
32 return base::TimeDelta::FromMilliseconds( 33 return base::TimeDelta::FromMilliseconds(
33 UserModel::kExpectSubsequentGestureMillis); 34 UserModel::kExpectSubsequentGestureMillis);
34 } 35 }
35 36
36 scoped_ptr<base::SimpleTestTickClock> clock_; 37 scoped_ptr<base::SimpleTestTickClock> clock_;
37 scoped_ptr<UserModel> user_model_; 38 scoped_ptr<UserModel> user_model_;
39 scoped_refptr<base::TestSimpleTaskRunner> mock_task_runner_;
38 }; 40 };
39 41
40 TEST_F(UserModelTest, TimeLeftInUserGesture_NoInput) { 42 TEST_F(UserModelTest, TimeLeftInUserGesture_NoInput) {
41 EXPECT_EQ(base::TimeDelta(), 43 EXPECT_EQ(base::TimeDelta(),
42 user_model_->TimeLeftInUserGesture(clock_->NowTicks())); 44 user_model_->TimeLeftInUserGesture(clock_->NowTicks()));
43 } 45 }
44 46
45 TEST_F(UserModelTest, TimeLeftInUserGesture_ImmediatelyAfterInput) { 47 TEST_F(UserModelTest, TimeLeftInUserGesture_ImmediatelyAfterInput) {
46 user_model_->DidStartProcessingInputEvent( 48 user_model_->DidStartProcessingInputEvent(
47 blink::WebInputEvent::Type::TouchStart, clock_->NowTicks()); 49 blink::WebInputEvent::Type::TouchStart, clock_->NowTicks());
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 base::TimeDelta delta(base::TimeDelta::FromMilliseconds( 246 base::TimeDelta delta(base::TimeDelta::FromMilliseconds(
245 UserModel::kMedianGestureDurationMillis * 2)); 247 UserModel::kMedianGestureDurationMillis * 2));
246 clock_->Advance(delta); 248 clock_->Advance(delta);
247 249
248 base::TimeDelta prediction_valid_duration; 250 base::TimeDelta prediction_valid_duration;
249 EXPECT_FALSE(user_model_->IsGestureExpectedToContinue( 251 EXPECT_FALSE(user_model_->IsGestureExpectedToContinue(
250 clock_->NowTicks(), &prediction_valid_duration)); 252 clock_->NowTicks(), &prediction_valid_duration));
251 EXPECT_EQ(base::TimeDelta(), prediction_valid_duration); 253 EXPECT_EQ(base::TimeDelta(), prediction_valid_duration);
252 } 254 }
253 255
254 } // namespace scheduler 256 } // namespace scheduler
alex clarke (OOO till 29th) 2016/02/12 16:21:50 Consider adding a simple test which uses base::Add
beaudoin 2016/03/16 20:47:39 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698