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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/blink_platform.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/UserGestureIndicator.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace blink {
10
11 // Checks for the initial state of UserGestureIndicator.
12 TEST(UserGestureIndicatorTest, InitialState)
13 {
14 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
15 EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad());
16 EXPECT_EQ(nullptr, UserGestureIndicator::currentToken());
17 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
18 }
19
20 TEST(UserGestureIndicatorTest, ConstructedWithNewUserGesture)
21 {
22 UserGestureIndicator::clearProcessedUserGestureSinceLoad();
23 UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture);
24
25 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
26 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
27 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
28
29 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
30 }
31
32 TEST(UserGestureIndicatorTest, ConstructedWithUserGesture)
33 {
34 UserGestureIndicator::clearProcessedUserGestureSinceLoad();
35 UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture);
36
37 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
38 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
39 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
40
41 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
42 }
43
44 TEST(UserGestureIndicatorTest, ConstructedWithNoUserGesture)
45 {
46 UserGestureIndicator::clearProcessedUserGestureSinceLoad();
47 UserGestureIndicator userGestureScope(DefinitelyNotProcessingUserGesture);
48
49 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
50 EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad());
51 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
52
53 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
54 }
55
56 // Check that after UserGestureIndicator destruction state will be cleared.
57 TEST(UserGestureIndicatorTest, DestructUserGestureIndicator)
58 {
59 {
60 UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture);
61
62 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
63 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
64 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
65 }
66
67 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
68 EXPECT_EQ(nullptr, UserGestureIndicator::currentToken());
69 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture());
70 }
71
72 // Tests creation of scoped UserGestureIndicator objects.
73 TEST(UserGestureIndicatorTest, ScopedNewUserGestureIndicators)
74 {
75 // Root GestureIndicator and GestureToken.
76 UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture);
77
78 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
79 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad());
80 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
81 {
82 // Construct inner UserGestureIndicator.
83 // It should share GestureToken with the root indicator.
84 UserGestureIndicator innerUserGesture(DefinitelyProcessingNewUserGesture );
85
86 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
87 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
88
89 // Consume inner gesture.
90 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
91 }
92
93 EXPECT_TRUE(UserGestureIndicator::processingUserGesture());
94 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
95
96 // Consume root gesture.
97 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture());
98 EXPECT_FALSE(UserGestureIndicator::processingUserGesture());
99 EXPECT_NE(nullptr, UserGestureIndicator::currentToken());
100 }
101
102 } // namespace blink
OLDNEW
« 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