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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp
diff --git a/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp b/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp
index d3dcde9db3349f4517cd239288001e65f74a28a8..0f8571903ed575581d74a76d5eca6b5969e3af8e 100644
--- a/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp
+++ b/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp
@@ -99,4 +99,78 @@ TEST(UserGestureIndicatorTest, ScopedNewUserGestureIndicators)
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
}
+class UsedCallback : public UserGestureUsedCallback {
+public:
+ UsedCallback() : m_usedCount(0)
+ {
+ }
+
+ void userGestureUsed() override
+ {
+ m_usedCount++;
+ }
+
+ unsigned getAndResetUsedCount()
+ {
+ unsigned curCount = m_usedCount;
+ m_usedCount = 0;
+ return curCount;
+ }
+
+private:
+ unsigned m_usedCount;
+};
+
+// Tests callback invocation.
+TEST(UserGestureIndicatorTest, Callback)
+{
+ UsedCallback cb;
+
+ {
+ UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture, &cb);
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+
+ // Untracked doesn't invoke the callback
+ EXPECT_TRUE(UserGestureIndicator::processingUserGestureUntracked());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+
+ // But processingUserGesture does
+ EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_EQ(1u, cb.getAndResetUsedCount());
+
+ // But only the first time
+ EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+ }
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+
+ {
+ UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture, &cb);
+
+ // Consume also invokes the callback
+ EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
+ EXPECT_EQ(1u, cb.getAndResetUsedCount());
+
+ // But only once
+ EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
+ EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+ }
+
+ {
+ UserGestureIndicator userGestureScope(DefinitelyNotProcessingUserGesture, &cb);
+
+ // Callback not invoked when there isn't actually a user gesture
+ EXPECT_FALSE(UserGestureIndicator::processingUserGestureUntracked());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+ }
+
+ // The callback isn't invoked outside the scope of the UGI
+ EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+ EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698