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

Side by Side Diff: third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp

Issue 1799253002: Stricter user gestures for touch - measure and warn (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "platform/UserGestureIndicator.h" 5 #include "platform/UserGestureIndicator.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); 93 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
94 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); 94 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
95 95
96 // Consume root gesture. 96 // Consume root gesture.
97 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture()); 97 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
98 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); 98 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
99 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); 99 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
100 } 100 }
101 101
102 class UsedCallback : public UserGestureUsedCallback {
103 public:
104 UsedCallback() : m_usedCount(0)
105 {
106 }
107
108 void userGestureUsed() override
109 {
110 m_usedCount++;
111 }
112
113 unsigned getAndResetUsedCount()
114 {
115 unsigned curCount = m_usedCount;
116 m_usedCount = 0;
117 return curCount;
118 }
119
120 private:
121 unsigned m_usedCount;
122 };
123
124 // Tests callback invocation.
125 TEST(UserGestureIndicatorTest, Callback)
126 {
127 UsedCallback cb;
128
129 {
130 UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture, & cb);
131 EXPECT_EQ(0u, cb.getAndResetUsedCount());
132
133 // Untracked doesn't invoke the callback
134 EXPECT_TRUE(UserGestureIndicator::processingUserGestureUntracked());
135 EXPECT_EQ(0u, cb.getAndResetUsedCount());
136
137 // But processingUserGesture does
138 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
139 EXPECT_EQ(1u, cb.getAndResetUsedCount());
140
141 // But only the first time
142 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
143 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
144 EXPECT_EQ(0u, cb.getAndResetUsedCount());
145 }
146 EXPECT_EQ(0u, cb.getAndResetUsedCount());
147
148 {
149 UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture, & cb);
150
151 // Consume also invokes the callback
152 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
153 EXPECT_EQ(1u, cb.getAndResetUsedCount());
154
155 // But only once
156 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
157 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
158 EXPECT_EQ(0u, cb.getAndResetUsedCount());
159 }
160
161 {
162 UserGestureIndicator userGestureScope(DefinitelyNotProcessingUserGesture , &cb);
163
164 // Callback not invoked when there isn't actually a user gesture
165 EXPECT_FALSE(UserGestureIndicator::processingUserGestureUntracked());
166 EXPECT_EQ(0u, cb.getAndResetUsedCount());
167 }
168
169 // The callback isn't invoked outside the scope of the UGI
170 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
171 EXPECT_EQ(0u, cb.getAndResetUsedCount());
172 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
173 EXPECT_EQ(0u, cb.getAndResetUsedCount());
174 }
175
102 } // namespace blink 176 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698