Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..45f9b5027c136fbe8eaa30bca4fd40c2d74f2fc0 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp |
| @@ -0,0 +1,128 @@ |
| +/* |
|
tkent
2016/02/10 10:08:53
Please use the 3-line header like platform/JSONPar
Andrey Kraynov
2016/02/10 10:20:36
Done.
|
| + * Copyright (C) 2016 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#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 |