Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
|
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.
| |
| 2 * Copyright (C) 2016 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "platform/UserGestureIndicator.h" | |
| 32 | |
| 33 #include "testing/gtest/include/gtest/gtest.h" | |
| 34 | |
| 35 namespace blink { | |
| 36 | |
| 37 // Checks for the initial state of UserGestureIndicator. | |
| 38 TEST(UserGestureIndicatorTest, InitialState) | |
| 39 { | |
| 40 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | |
| 41 EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad()); | |
| 42 EXPECT_EQ(nullptr, UserGestureIndicator::currentToken()); | |
| 43 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture()); | |
| 44 } | |
| 45 | |
| 46 TEST(UserGestureIndicatorTest, ConstructedWithNewUserGesture) | |
| 47 { | |
| 48 UserGestureIndicator::clearProcessedUserGestureSinceLoad(); | |
| 49 UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture); | |
| 50 | |
| 51 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); | |
| 52 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad()); | |
| 53 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 54 | |
| 55 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture()); | |
| 56 } | |
| 57 | |
| 58 TEST(UserGestureIndicatorTest, ConstructedWithUserGesture) | |
| 59 { | |
| 60 UserGestureIndicator::clearProcessedUserGestureSinceLoad(); | |
| 61 UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture); | |
| 62 | |
| 63 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); | |
| 64 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad()); | |
| 65 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 66 | |
| 67 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture()); | |
| 68 } | |
| 69 | |
| 70 TEST(UserGestureIndicatorTest, ConstructedWithNoUserGesture) | |
| 71 { | |
| 72 UserGestureIndicator::clearProcessedUserGestureSinceLoad(); | |
| 73 UserGestureIndicator userGestureScope(DefinitelyNotProcessingUserGesture); | |
| 74 | |
| 75 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | |
| 76 EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad()); | |
| 77 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 78 | |
| 79 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture()); | |
| 80 } | |
| 81 | |
| 82 // Check that after UserGestureIndicator destruction state will be cleared. | |
| 83 TEST(UserGestureIndicatorTest, DestructUserGestureIndicator) | |
| 84 { | |
| 85 { | |
| 86 UserGestureIndicator userGestureScope(DefinitelyProcessingUserGesture); | |
| 87 | |
| 88 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); | |
| 89 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad()); | |
| 90 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 91 } | |
| 92 | |
| 93 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | |
| 94 EXPECT_EQ(nullptr, UserGestureIndicator::currentToken()); | |
| 95 EXPECT_FALSE(UserGestureIndicator::consumeUserGesture()); | |
| 96 } | |
| 97 | |
| 98 // Tests creation of scoped UserGestureIndicator objects. | |
| 99 TEST(UserGestureIndicatorTest, ScopedNewUserGestureIndicators) | |
| 100 { | |
| 101 // Root GestureIndicator and GestureToken. | |
| 102 UserGestureIndicator userGestureScope(DefinitelyProcessingNewUserGesture); | |
| 103 | |
| 104 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); | |
| 105 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad()); | |
| 106 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 107 { | |
| 108 // Construct inner UserGestureIndicator. | |
| 109 // It should share GestureToken with the root indicator. | |
| 110 UserGestureIndicator innerUserGesture(DefinitelyProcessingNewUserGesture ); | |
| 111 | |
| 112 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); | |
| 113 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 114 | |
| 115 // Consume inner gesture. | |
| 116 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture()); | |
| 117 } | |
| 118 | |
| 119 EXPECT_TRUE(UserGestureIndicator::processingUserGesture()); | |
| 120 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 121 | |
| 122 // Consume root gesture. | |
| 123 EXPECT_TRUE(UserGestureIndicator::consumeUserGesture()); | |
| 124 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | |
| 125 EXPECT_NE(nullptr, UserGestureIndicator::currentToken()); | |
| 126 } | |
| 127 | |
| 128 } // namespace blink | |
| OLD | NEW |