Commit a6b2a874 authored by iceman's avatar iceman Committed by Commit bot

Add tests for UserGestureIndicator class.

BUG=
TEST=blink_platform_unittests --gtest_filter="UserGestureIndicatorTest*"

Review URL: https://codereview.chromium.org/1684023003

Cr-Commit-Position: refs/heads/master@{#374639}
parent 44a0f0ff
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "platform/UserGestureIndicator.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
// Checks for the initial state of UserGestureIndicator.
TEST(UserGestureIndicatorTest, InitialState)
{
EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_EQ(nullptr, UserGestureIndicator::currentToken());
EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
}
TEST(UserGestureIndicatorTest, ConstructedWithNewUserGesture)
{
UserGestureIndicator::clearProcessedUserGestureSinceLoad();
UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture);
EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
}
TEST(UserGestureIndicatorTest, ConstructedWithUserGesture)
{
UserGestureIndicator::clearProcessedUserGestureSinceLoad();
UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture);
EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
}
TEST(UserGestureIndicatorTest, ConstructedWithNoUserGesture)
{
UserGestureIndicator::clearProcessedUserGestureSinceLoad();
UserGestureIndicator userGestureScope(DefinitelyNotProcessingUserGesture);
EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
}
// Check that after UserGestureIndicator destruction state will be cleared.
TEST(UserGestureIndicatorTest, DestructUserGestureIndicator)
{
{
UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture);
EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
}
EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
EXPECT_EQ(nullptr, UserGestureIndicator::currentToken());
EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
}
// Tests creation of scoped UserGestureIndicator objects.
TEST(UserGestureIndicatorTest, ScopedNewUserGestureIndicators)
{
// Root GestureIndicator and GestureToken.
UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture);
EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
{
// Construct inner UserGestureIndicator.
// It should share GestureToken with the root indicator.
UserGestureIndicator innerUserGesture(DefinitelyProcessingNewUserGesture);
EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
// Consume inner gesture.
EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
}
EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
// Consume root gesture.
EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
}
} // namespace blink
...@@ -1007,6 +1007,7 @@ ...@@ -1007,6 +1007,7 @@
'SharedBufferTest.cpp', 'SharedBufferTest.cpp',
'TimerTest.cpp', 'TimerTest.cpp',
'TracedValueTest.cpp', 'TracedValueTest.cpp',
'UserGestureIndicatorTest.cpp',
'UUIDTest.cpp', 'UUIDTest.cpp',
'WebScreenInfoTest.cpp', 'WebScreenInfoTest.cpp',
'WebVectorTest.cpp', 'WebVectorTest.cpp',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment