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

Side by Side Diff: third_party/WebKit/Source/core/page/FocusControllerTest.cpp

Issue 1954023002: Move asserts in FocusNavigationController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: readding assert Created 4 years, 7 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 | « third_party/WebKit/Source/core/page/FocusController.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/html/HTMLElement.h" 8 #include "core/html/HTMLElement.h"
8 #include "core/testing/DummyPageHolder.h" 9 #include "core/testing/DummyPageHolder.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 class FocusControllerTest : public testing::Test { 14 class FocusControllerTest : public testing::Test {
14 public: 15 public:
15 Document& document() const { return m_pageHolder->document(); } 16 Document& document() const { return m_pageHolder->document(); }
16 FocusController& focusController() const { return document().page()->focusCo ntroller(); } 17 FocusController& focusController() const { return document().page()->focusCo ntroller(); }
17 18
18 private: 19 private:
19 void SetUp() override { m_pageHolder = DummyPageHolder::create(); } 20 void SetUp() override { m_pageHolder = DummyPageHolder::create(); }
20 21
21 OwnPtr<DummyPageHolder> m_pageHolder; 22 OwnPtr<DummyPageHolder> m_pageHolder;
22 }; 23 };
23 24
24 TEST_F(FocusControllerTest, SetInitialFocus) 25 TEST_F(FocusControllerTest, SetInitialFocus)
25 { 26 {
26 document().body()->setInnerHTML("<input><textarea>", ASSERT_NO_EXCEPTION); 27 document().body()->setInnerHTML("<input><textarea>", ASSERT_NO_EXCEPTION);
27 Element* input = toElement(document().body()->firstChild()); 28 Element* input = toElement(document().body()->firstChild());
28 // Set sequential focus navigation point before the initial focus. 29 // Set sequential focus navigation point before the initial focus.
29 input->focus(); 30 input->focus();
30 input->blur(); 31 input->blur();
31 focusController().setInitialFocus(WebFocusTypeForward); 32 focusController().setInitialFocus(WebFocusTypeForward);
32 EXPECT_EQ(input, document().focusedElement()) << "We should ignore sequentia l focus navigation starting point in setInitialFocus()."; 33 EXPECT_EQ(input, document().focusedElement()) << "We should ignore sequentia l focus navigation starting point in setInitialFocus().";
33 } 34 }
34 35
36 TEST_F(FocusControllerTest, DoNotCrash1)
37 {
38 document().body()->setInnerHTML(
39 "<div id='host'></div>This test is for crbug.com/609012<p id='target' ta bindex='0'></p>",
40 ASSERT_NO_EXCEPTION);
41 // <div> with shadow root
42 Element* host = toElement(document().body()->firstChild());
43 ShadowRootInit init;
44 init.setMode("open");
45 host->attachShadow(ScriptState::forMainWorld(document().frame()), init, ASSE RT_NO_EXCEPTION);
46 // "This test is for crbug.com/609012"
47 Node* text = host->nextSibling();
48 // <p>
49 Element* target = toElement(text->nextSibling());
50
51 // Set sequential focus navigation point at text node.
52 document().setSequentialFocusNavigationStartingPoint(text);
53
54 focusController().advanceFocus(WebFocusTypeForward);
55 EXPECT_EQ(target, document().focusedElement()) << "This should not hit asser tion and finish properly.";
56 }
57
58 TEST_F(FocusControllerTest, DoNotCrash2)
59 {
60 document().body()->setInnerHTML(
61 "<p id='target' tabindex='0'></p>This test is for crbug.com/609012<div i d='host'></div>",
62 ASSERT_NO_EXCEPTION);
63 // <p>
64 Element* target = toElement(document().body()->firstChild());
65 // "This test is for crbug.com/609012"
66 Node* text = target->nextSibling();
67 // <div> with shadow root
68 Element* host = toElement(text->nextSibling());
69 ShadowRootInit init;
70 init.setMode("open");
71 host->attachShadow(ScriptState::forMainWorld(document().frame()), init, ASSE RT_NO_EXCEPTION);
72
73 // Set sequential focus navigation point at text node.
74 document().setSequentialFocusNavigationStartingPoint(text);
75
76 focusController().advanceFocus(WebFocusTypeBackward);
77 EXPECT_EQ(target, document().focusedElement()) << "This should not hit asser tion and finish properly.";
78 }
79
35 } // namespace blink 80 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/FocusController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698