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

Side by Side Diff: third_party/WebKit/Source/core/html/TextControlElementTest.cpp

Issue 2716793002: Simplify TextControlElementTest.SetSelectionRangeDoesNotCaluseLayout (Closed)
Patch Set: update Created 3 years, 9 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 | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/html/TextControlElement.h" 5 #include "core/html/TextControlElement.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/editing/FrameSelection.h" 9 #include "core/editing/FrameSelection.h"
10 #include "core/frame/FrameView.h" 10 #include "core/frame/FrameView.h"
11 #include "core/html/HTMLInputElement.h" 11 #include "core/html/HTMLInputElement.h"
12 #include "core/html/HTMLTextAreaElement.h" 12 #include "core/html/HTMLTextAreaElement.h"
13 #include "core/loader/EmptyClients.h" 13 #include "core/loader/EmptyClients.h"
14 #include "core/testing/DummyPageHolder.h" 14 #include "core/testing/DummyPageHolder.h"
15 #include "platform/testing/UnitTestHelpers.h" 15 #include "platform/testing/UnitTestHelpers.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "wtf/PtrUtil.h" 17 #include "wtf/PtrUtil.h"
18 18
19 namespace blink { 19 namespace blink {
20 20
21 class TextControlElementTest : public ::testing::Test { 21 class TextControlElementTest : public ::testing::Test {
22 protected: 22 protected:
23 void SetUp() override; 23 void SetUp() override;
24 24
25 DummyPageHolder& page() const { return *m_dummyPageHolder; } 25 DummyPageHolder& page() const { return *m_dummyPageHolder; }
26 Document& document() const { return *m_document; } 26 Document& document() const { return *m_document; }
27 TextControlElement& textControl() const { return *m_textControl; } 27 TextControlElement& textControl() const { return *m_textControl; }
28 HTMLInputElement& input() const { return *m_input; } 28 HTMLInputElement& input() const { return *m_input; }
29 29
30 int layoutCount() const { return page().frameView().layoutCount(); }
31 void forceLayoutFlag();
32
33 private: 30 private:
34 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 31 std::unique_ptr<DummyPageHolder> m_dummyPageHolder;
35 32
36 Persistent<Document> m_document; 33 Persistent<Document> m_document;
37 Persistent<TextControlElement> m_textControl; 34 Persistent<TextControlElement> m_textControl;
38 Persistent<HTMLInputElement> m_input; 35 Persistent<HTMLInputElement> m_input;
39 }; 36 };
40 37
41 void TextControlElementTest::SetUp() { 38 void TextControlElementTest::SetUp() {
42 Page::PageClients pageClients; 39 Page::PageClients pageClients;
43 fillWithEmptyClients(pageClients); 40 fillWithEmptyClients(pageClients);
44 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients); 41 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients);
45 42
46 m_document = &m_dummyPageHolder->document(); 43 m_document = &m_dummyPageHolder->document();
47 m_document->documentElement()->setInnerHTML( 44 m_document->documentElement()->setInnerHTML(
48 "<body><textarea id=textarea></textarea><input id=input /></body>"); 45 "<body><textarea id=textarea></textarea><input id=input /></body>");
49 m_document->view()->updateAllLifecyclePhases(); 46 m_document->view()->updateAllLifecyclePhases();
50 m_textControl = toTextControlElement(m_document->getElementById("textarea")); 47 m_textControl = toTextControlElement(m_document->getElementById("textarea"));
51 m_textControl->focus(); 48 m_textControl->focus();
52 m_input = toHTMLInputElement(m_document->getElementById("input")); 49 m_input = toHTMLInputElement(m_document->getElementById("input"));
53 } 50 }
54 51
55 void TextControlElementTest::forceLayoutFlag() {
56 FrameView& frameView = page().frameView();
57 IntRect frameRect = frameView.frameRect();
58 frameRect.setWidth(frameRect.width() + 1);
59 frameRect.setHeight(frameRect.height() + 1);
60 page().frameView().setFrameRect(frameRect);
61 document().updateStyleAndLayoutIgnorePendingStylesheets();
62 }
63
64 TEST_F(TextControlElementTest, SetSelectionRange) { 52 TEST_F(TextControlElementTest, SetSelectionRange) {
65 EXPECT_EQ(0u, textControl().selectionStart()); 53 EXPECT_EQ(0u, textControl().selectionStart());
66 EXPECT_EQ(0u, textControl().selectionEnd()); 54 EXPECT_EQ(0u, textControl().selectionEnd());
67 55
68 textControl().setInnerEditorValue("Hello, text form."); 56 textControl().setInnerEditorValue("Hello, text form.");
69 EXPECT_EQ(0u, textControl().selectionStart()); 57 EXPECT_EQ(0u, textControl().selectionStart());
70 EXPECT_EQ(0u, textControl().selectionEnd()); 58 EXPECT_EQ(0u, textControl().selectionEnd());
71 59
72 textControl().setSelectionRange(1, 3); 60 textControl().setSelectionRange(1, 3);
73 EXPECT_EQ(1u, textControl().selectionStart()); 61 EXPECT_EQ(1u, textControl().selectionStart());
74 EXPECT_EQ(3u, textControl().selectionEnd()); 62 EXPECT_EQ(3u, textControl().selectionEnd());
75 } 63 }
76 64
77 TEST_F(TextControlElementTest, SetSelectionRangeDoesNotCauseLayout) { 65 TEST_F(TextControlElementTest, SetSelectionRangeDoesNotCauseLayout) {
78 input().focus(); 66 input().focus();
79 input().setValue("Hello, input form."); 67 input().setValue("Hello, input form.");
80 input().setSelectionRange(1, 1); 68 input().setSelectionRange(1, 1);
81 FrameSelection& frameSelection = document().frame()->selection();
82 forceLayoutFlag();
83 LayoutRect oldCaretRect(frameSelection.absoluteCaretBounds());
84 EXPECT_FALSE(oldCaretRect.isEmpty());
85 int startLayoutCount = layoutCount();
86 input().setSelectionRange(1, 1);
87 EXPECT_EQ(startLayoutCount, layoutCount());
88 LayoutRect newCaretRect(frameSelection.absoluteCaretBounds());
89 EXPECT_EQ(oldCaretRect, newCaretRect);
90 69
91 forceLayoutFlag(); 70 // Force layout if document().updateStyleAndLayoutIgnorePendingStylesheets()
92 oldCaretRect = LayoutRect(frameSelection.absoluteCaretBounds()); 71 // is called.
93 EXPECT_FALSE(oldCaretRect.isEmpty()); 72 document().body()->appendChild(document().createTextNode("foo"));
94 startLayoutCount = layoutCount(); 73 {
95 input().setSelectionRange(2, 2); 74 EXPECT_TRUE(document().needsLayoutTreeUpdate());
96 EXPECT_EQ(startLayoutCount, layoutCount()); 75 DocumentLifecycle::DisallowTransitionScope disallowTransition(
yosin_UTC9 2017/02/24 07:36:36 DocumentLifecycle::DisallowTransitionScope does no
yoichio 2017/02/28 02:11:39 What do you mean? This test is built as both debug
yosin_UTC9 2017/02/28 02:23:05 I mean rather than detecting test failure by DCHEC
yoichio 2017/02/28 04:11:56 Done.
97 newCaretRect = LayoutRect(frameSelection.absoluteCaretBounds()); 76 document().lifecycle());
98 EXPECT_NE(oldCaretRect, newCaretRect); 77 input().setSelectionRange(2, 2);
78 }
99 } 79 }
100 80
101 TEST_F(TextControlElementTest, IndexForPosition) { 81 TEST_F(TextControlElementTest, IndexForPosition) {
102 HTMLInputElement* input = 82 HTMLInputElement* input =
103 toHTMLInputElement(document().getElementById("input")); 83 toHTMLInputElement(document().getElementById("input"));
104 input->setValue("Hello"); 84 input->setValue("Hello");
105 HTMLElement* innerEditor = input->innerEditorElement(); 85 HTMLElement* innerEditor = input->innerEditorElement();
106 EXPECT_EQ(5u, TextControlElement::indexForPosition( 86 EXPECT_EQ(5u, TextControlElement::indexForPosition(
107 innerEditor, 87 innerEditor,
108 Position(innerEditor, PositionAnchorType::AfterAnchor))); 88 Position(innerEditor, PositionAnchorType::AfterAnchor)));
109 } 89 }
110 90
111 } // namespace blink 91 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698