OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2016 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "public/web/WebUserGestureToken.h" | 31 #include "wtf/text/TextCodec.h" |
32 | 32 |
33 #include "platform/UserGestureIndicator.h" | |
34 #include "public/web/WebScopedUserGesture.h" | |
35 #include "public/web/WebUserGestureIndicator.h" | |
36 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
37 | 34 |
38 namespace blink { | 35 namespace WTF { |
39 | 36 |
40 TEST(WebUserGestureTokenTest, Basic) | 37 namespace { |
41 { | |
42 WebUserGestureToken token; | |
43 EXPECT_FALSE(token.hasGestures()); | |
44 UserGestureIndicator::clearProcessedUserGestureSinceLoad(); | |
45 EXPECT_FALSE(UserGestureIndicator::processedUserGestureSinceLoad()); | |
46 | 38 |
| 39 TEST(TextCodec, QuestionMarkEncoding) |
47 { | 40 { |
48 WebScopedUserGesture indicator(token); | 41 UnencodableReplacementArray replacement; |
49 EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture()); | 42 int size = TextCodec::getUnencodableReplacement(0xE003, |
| 43 QuestionMarksForUnencodables, |
| 44 replacement); |
| 45 EXPECT_EQ(size, 1); |
| 46 EXPECT_EQ(replacement[0], '?'); |
| 47 EXPECT_EQ(replacement[1], 0); |
50 } | 48 } |
51 | 49 |
| 50 TEST(TextCodec, HTMLEntityEncoding) |
52 { | 51 { |
53 UserGestureIndicator indicator(DefinitelyProcessingNewUserGesture); | 52 UnencodableReplacementArray replacement; |
54 EXPECT_TRUE(WebUserGestureIndicator::isProcessingUserGesture()); | 53 int size = TextCodec::getUnencodableReplacement(0xE003, |
55 token = WebUserGestureIndicator::currentUserGestureToken(); | 54 EntitiesForUnencodables, |
56 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad()); | 55 replacement); |
| 56 EXPECT_EQ(size, 8); |
| 57 EXPECT_EQ(std::string(replacement), ""); |
| 58 EXPECT_EQ(replacement[8], 0); |
57 } | 59 } |
58 | 60 |
59 EXPECT_TRUE(token.hasGestures()); | 61 TEST(TextCodec, URLEntityEncoding) |
60 EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture()); | |
61 | |
62 { | 62 { |
63 WebScopedUserGesture indicator(token); | 63 UnencodableReplacementArray replacement; |
64 EXPECT_TRUE(WebUserGestureIndicator::isProcessingUserGesture()); | 64 int size = TextCodec::getUnencodableReplacement( |
65 WebUserGestureIndicator::consumeUserGesture(); | 65 0xE003, |
66 EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture()); | 66 URLEncodedEntitiesForUnencodables, |
| 67 replacement); |
| 68 EXPECT_EQ(size, 14); |
| 69 EXPECT_EQ(std::string(replacement), "%26%2357347%3B"); |
| 70 EXPECT_EQ(replacement[14], 0); |
67 } | 71 } |
68 | 72 |
69 EXPECT_FALSE(token.hasGestures()); | 73 TEST(TextCodec, CSSEntityEncoding) |
70 | |
71 { | 74 { |
72 WebScopedUserGesture indicator(token); | 75 UnencodableReplacementArray replacement; |
73 EXPECT_FALSE(WebUserGestureIndicator::isProcessingUserGesture()); | 76 int size = TextCodec::getUnencodableReplacement( |
| 77 0xE003, |
| 78 CSSEncodedEntitiesForUnencodables, |
| 79 replacement); |
| 80 EXPECT_EQ(size, 6); |
| 81 EXPECT_EQ(std::string(replacement), "\\e003 "); |
| 82 EXPECT_EQ(replacement[6], 0); |
74 } | 83 } |
75 | 84 |
76 EXPECT_TRUE(UserGestureIndicator::processedUserGestureSinceLoad()); | 85 } // anonymous namespace |
77 } | 86 } // namespace WTF |
78 | |
79 } // namespace blink | |
OLD | NEW |