| 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
|
|
|