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

Unified Diff: third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp

Issue 1684023003: Add tests for UserGestureIndicator class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change header comment. Created 4 years, 10 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/blink_platform.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d3dcde9db3349f4517cd239288001e65f74a28a8
--- /dev/null
+++ b/third_party/WebKit/Source/platform/UserGestureIndicatorTest.cpp
@@ -0,0 +1,102 @@
+// 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698