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

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: Tweaks 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..c02e46842eb589b68ed4fd0c55c63626c6740b61 100644
--- a/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp
+++ b/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp
@@ -11,7 +11,7 @@ namespace blink {
// Checks for the initial state of UserGestureIndicator.
TEST(UserGestureIndicatorTest, InitialState)
{
- EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
+ EXPECT_FALSE(UserGestureIndicator::utilizeUserGesture());
EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_EQ(nullptr, UserGestureIndicator::currentToken());
EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
@@ -22,7 +22,7 @@ TEST(UserGestureIndicatorTest, ConstructedWithNewUserGesture)
UserGestureIndicator::clearProcessedUserGestureSinceLoad();
UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture);
- EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
@@ -34,7 +34,7 @@ TEST(UserGestureIndicatorTest, ConstructedWithUserGesture)
UserGestureIndicator::clearProcessedUserGestureSinceLoad();
UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture);
- EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
@@ -46,7 +46,7 @@ TEST(UserGestureIndicatorTest, ConstructedWithNoUserGesture)
UserGestureIndicator::clearProcessedUserGestureSinceLoad();
UserGestureIndicator userGestureScope(DefinitelyNotProcessingUserGesture);
- EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
+ EXPECT_FALSE(UserGestureIndicator::utilizeUserGesture());
EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
@@ -59,12 +59,12 @@ TEST(UserGestureIndicatorTest, DestructUserGestureIndicator)
{
UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture);
- EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
}
- EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
+ EXPECT_FALSE(UserGestureIndicator::utilizeUserGesture());
EXPECT_EQ(nullptr, UserGestureIndicator::currentToken());
EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
}
@@ -75,7 +75,7 @@ TEST(UserGestureIndicatorTest, ScopedNewUserGestureIndicators)
// Root GestureIndicator and GestureToken.
UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture);
- EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
{
@@ -83,20 +83,94 @@ TEST(UserGestureIndicatorTest, ScopedNewUserGestureIndicators)
// It should share GestureToken with the root indicator.
UserGestureIndicator innerUserGesture(DefinitelyProcessingNewUserGesture);
- EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
// Consume inner gesture.
EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
}
- EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
// Consume root gesture.
EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
- EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
+ EXPECT_FALSE(UserGestureIndicator::utilizeUserGesture());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
}
+class UsedCallback : public UserGestureUtilizedCallback {
+public:
+ UsedCallback() : m_usedCount(0)
+ {
+ }
+
+ void userGestureUtilized() 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::processingUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+
+ // But processingUserGesture does
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
+ EXPECT_EQ(1u, cb.getAndResetUsedCount());
+
+ // But only the first time
+ EXPECT_TRUE(UserGestureIndicator::utilizeUserGesture());
+ 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::utilizeUserGesture());
+ 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::processingUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+ }
+
+ // The callback isn't invoked outside the scope of the UGI
+ EXPECT_FALSE(UserGestureIndicator::utilizeUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+ EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
+ EXPECT_EQ(0u, cb.getAndResetUsedCount());
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/UserGestureIndicator.cpp ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698