OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/DocumentUserGestureToken.h" | 5 #include "core/dom/DocumentUserGestureToken.h" |
6 | 6 |
7 #include "core/testing/DummyPageHolder.h" | 7 #include "core/testing/DummyPageHolder.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 TEST(DocumentUserGestureTokenTest, DocumentUserGestureState) { | 12 class DocumentUserGestureTokenTest : public ::testing::Test { |
13 std::unique_ptr<DummyPageHolder> dummyPageHolder = | 13 public: |
14 DummyPageHolder::create(IntSize(800, 600)); | 14 void SetUp() override { |
15 Document& document = dummyPageHolder->document(); | 15 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
16 ASSERT_FALSE(document.hasReceivedUserGesture()); | 16 ASSERT_FALSE(document().hasReceivedUserGesture()); |
| 17 } |
17 | 18 |
| 19 Document& document() const { return m_dummyPageHolder->document(); } |
| 20 |
| 21 private: |
| 22 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 23 }; |
| 24 |
| 25 TEST_F(DocumentUserGestureTokenTest, NoGesture) { |
18 // A nullptr Document* will not set user gesture state. | 26 // A nullptr Document* will not set user gesture state. |
19 DocumentUserGestureToken::create(nullptr); | 27 DocumentUserGestureToken::create(nullptr); |
20 EXPECT_FALSE(document.hasReceivedUserGesture()); | 28 EXPECT_FALSE(document().hasReceivedUserGesture()); |
| 29 } |
21 | 30 |
| 31 TEST_F(DocumentUserGestureTokenTest, PossiblyExisting) { |
22 // A non-null Document* will set state, but a subsequent nullptr Document* | 32 // A non-null Document* will set state, but a subsequent nullptr Document* |
23 // token will not override it. | 33 // token will not override it. |
24 DocumentUserGestureToken::create(&document); | 34 DocumentUserGestureToken::create(&document()); |
25 EXPECT_TRUE(document.hasReceivedUserGesture()); | 35 EXPECT_TRUE(document().hasReceivedUserGesture()); |
26 DocumentUserGestureToken::create(nullptr); | 36 DocumentUserGestureToken::create(nullptr); |
27 EXPECT_TRUE(document.hasReceivedUserGesture()); | 37 EXPECT_TRUE(document().hasReceivedUserGesture()); |
28 document.clearHasReceivedUserGesture(); | 38 } |
29 ASSERT_FALSE(document.hasReceivedUserGesture()); | |
30 | 39 |
| 40 TEST_F(DocumentUserGestureTokenTest, NewGesture) { |
31 // UserGestureToken::Status doesn't impact Document gesture state. | 41 // UserGestureToken::Status doesn't impact Document gesture state. |
32 DocumentUserGestureToken::create(&document, UserGestureToken::NewGesture); | 42 DocumentUserGestureToken::create(&document(), UserGestureToken::NewGesture); |
33 EXPECT_TRUE(document.hasReceivedUserGesture()); | 43 EXPECT_TRUE(document().hasReceivedUserGesture()); |
34 } | 44 } |
35 | 45 |
36 } // namespace blink | 46 } // namespace blink |
OLD | NEW |