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/page/FocusController.h" | 5 #include "core/page/FocusController.h" |
6 | 6 |
7 #include "core/dom/shadow/ShadowRootInit.h" | 7 #include "core/dom/shadow/ShadowRootInit.h" |
8 #include "core/html/HTMLElement.h" | 8 #include "core/html/HTMLElement.h" |
9 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include <memory> |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 class FocusControllerTest : public testing::Test { | 15 class FocusControllerTest : public testing::Test { |
15 public: | 16 public: |
16 Document& document() const { return m_pageHolder->document(); } | 17 Document& document() const { return m_pageHolder->document(); } |
17 FocusController& focusController() const { return document().page()->focusCo
ntroller(); } | 18 FocusController& focusController() const { return document().page()->focusCo
ntroller(); } |
18 | 19 |
19 private: | 20 private: |
20 void SetUp() override { m_pageHolder = DummyPageHolder::create(); } | 21 void SetUp() override { m_pageHolder = DummyPageHolder::create(); } |
21 | 22 |
22 OwnPtr<DummyPageHolder> m_pageHolder; | 23 std::unique_ptr<DummyPageHolder> m_pageHolder; |
23 }; | 24 }; |
24 | 25 |
25 TEST_F(FocusControllerTest, SetInitialFocus) | 26 TEST_F(FocusControllerTest, SetInitialFocus) |
26 { | 27 { |
27 document().body()->setInnerHTML("<input><textarea>", ASSERT_NO_EXCEPTION); | 28 document().body()->setInnerHTML("<input><textarea>", ASSERT_NO_EXCEPTION); |
28 Element* input = toElement(document().body()->firstChild()); | 29 Element* input = toElement(document().body()->firstChild()); |
29 // Set sequential focus navigation point before the initial focus. | 30 // Set sequential focus navigation point before the initial focus. |
30 input->focus(); | 31 input->focus(); |
31 input->blur(); | 32 input->blur(); |
32 focusController().setInitialFocus(WebFocusTypeForward); | 33 focusController().setInitialFocus(WebFocusTypeForward); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 host->attachShadow(ScriptState::forMainWorld(document().frame()), init, ASSE
RT_NO_EXCEPTION); | 72 host->attachShadow(ScriptState::forMainWorld(document().frame()), init, ASSE
RT_NO_EXCEPTION); |
72 | 73 |
73 // Set sequential focus navigation point at text node. | 74 // Set sequential focus navigation point at text node. |
74 document().setSequentialFocusNavigationStartingPoint(text); | 75 document().setSequentialFocusNavigationStartingPoint(text); |
75 | 76 |
76 focusController().advanceFocus(WebFocusTypeBackward); | 77 focusController().advanceFocus(WebFocusTypeBackward); |
77 EXPECT_EQ(target, document().focusedElement()) << "This should not hit asser
tion and finish properly."; | 78 EXPECT_EQ(target, document().focusedElement()) << "This should not hit asser
tion and finish properly."; |
78 } | 79 } |
79 | 80 |
80 } // namespace blink | 81 } // namespace blink |
OLD | NEW |