Commit 7d4dd395 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Cleanup of blink::LayoutTextControlTest

- Introduce helper functions to share common code
- Use TextControlElement instead of HTMLInputElement
  This will help testing LayoutTextControlMultiLine.
- Fix camelCase variable names

This CL has no behavior changes.

Bug: 1040826
Change-Id: I4287125d4531151573d839363d182ee2d8d1409e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2483741Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818371}
parent 5bc2dfed
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "third_party/blink/renderer/core/layout/layout_text_control.h" #include "third_party/blink/renderer/core/layout/layout_text_control.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h" #include "third_party/blink/renderer/core/html/forms/text_control_element.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h" #include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
namespace blink { namespace blink {
...@@ -14,14 +14,33 @@ namespace { ...@@ -14,14 +14,33 @@ namespace {
class LayoutTextControlTest : public RenderingTest { class LayoutTextControlTest : public RenderingTest {
protected: protected:
HTMLInputElement* GetHTMLInputElementById(const char* id) { TextControlElement* GetTextControlElementById(const char* id) {
return To<HTMLInputElement>(GetDocument().getElementById(id)); return To<TextControlElement>(GetDocument().getElementById(id));
} }
// Return the LayoutText from inside an HTMLInputElement's user agent shadow // Return the LayoutText from inside a text control's user agent shadow tree.
// tree. LayoutText* GetInnerLayoutText(TextControlElement* control) {
LayoutText* GetInnerLayoutText(HTMLInputElement* input) {
return ToLayoutText( return ToLayoutText(
input->InnerEditorElement()->GetLayoutObject()->SlowFirstChild()); control->InnerEditorElement()->GetLayoutObject()->SlowFirstChild());
}
// Focus on |control|, select 1-3 characters, get the first LayoutText, and
// check if selection invalidation state is clean.
LayoutText* SetupLayoutTextWithCleanSelection(TextControlElement* control) {
control->focus();
control->SetSelectionRange(1, 3);
UpdateAllLifecyclePhasesForTest();
auto* selected_text = GetInnerLayoutText(control);
EXPECT_FALSE(selected_text->ShouldInvalidateSelection());
return selected_text;
}
void CheckSelectionInvalidationChanges(const LayoutText& selected_text) {
GetDocument().View()->UpdateLifecycleToLayoutClean(
DocumentUpdateReason::kTest);
EXPECT_TRUE(selected_text.ShouldInvalidateSelection());
UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(selected_text.ShouldInvalidateSelection());
} }
}; };
...@@ -35,21 +54,11 @@ TEST_F(LayoutTextControlTest, ...@@ -35,21 +54,11 @@ TEST_F(LayoutTextControlTest,
<input id="input" type="text" value="AAAAAAAAAAAA"> <input id="input" type="text" value="AAAAAAAAAAAA">
)HTML"); )HTML");
auto* inputElement = GetHTMLInputElementById("input"); auto* text_control = GetTextControlElementById("input");
inputElement->focus(); auto* selected_text = SetupLayoutTextWithCleanSelection(text_control);
inputElement->SetSelectionRange(1, 3);
UpdateAllLifecyclePhasesForTest();
auto* selectedText = GetInnerLayoutText(inputElement);
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
inputElement->setAttribute(html_names::kClassAttr, "pseudoSelection"); text_control->setAttribute(html_names::kClassAttr, "pseudoSelection");
GetDocument().View()->UpdateLifecycleToLayoutClean( CheckSelectionInvalidationChanges(*selected_text);
DocumentUpdateReason::kTest);
EXPECT_TRUE(selectedText->ShouldInvalidateSelection());
UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
} }
TEST_F(LayoutTextControlTest, TEST_F(LayoutTextControlTest,
...@@ -61,21 +70,11 @@ TEST_F(LayoutTextControlTest, ...@@ -61,21 +70,11 @@ TEST_F(LayoutTextControlTest,
<input id="input" type="text" value="AAAAAAAAAAAA"> <input id="input" type="text" value="AAAAAAAAAAAA">
)HTML"); )HTML");
auto* inputElement = GetHTMLInputElementById("input"); auto* text_control = GetTextControlElementById("input");
inputElement->focus(); auto* selected_text = SetupLayoutTextWithCleanSelection(text_control);
inputElement->SetSelectionRange(1, 3);
UpdateAllLifecyclePhasesForTest();
auto* selectedText = GetInnerLayoutText(inputElement);
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
inputElement->setAttribute(html_names::kClassAttr, "pseudoSelection");
GetDocument().View()->UpdateLifecycleToLayoutClean(
DocumentUpdateReason::kTest);
EXPECT_TRUE(selectedText->ShouldInvalidateSelection());
UpdateAllLifecyclePhasesForTest(); text_control->setAttribute(html_names::kClassAttr, "pseudoSelection");
EXPECT_FALSE(selectedText->ShouldInvalidateSelection()); CheckSelectionInvalidationChanges(*selected_text);
} }
TEST_F(LayoutTextControlTest, TEST_F(LayoutTextControlTest,
...@@ -87,21 +86,11 @@ TEST_F(LayoutTextControlTest, ...@@ -87,21 +86,11 @@ TEST_F(LayoutTextControlTest,
<input id="input" type="text" class="pseudoSelection" value="AAAAAAAAAAAA"> <input id="input" type="text" class="pseudoSelection" value="AAAAAAAAAAAA">
)HTML"); )HTML");
auto* inputElement = GetHTMLInputElementById("input"); auto* text_control = GetTextControlElementById("input");
inputElement->focus(); auto* selected_text = SetupLayoutTextWithCleanSelection(text_control);
inputElement->SetSelectionRange(1, 3);
UpdateAllLifecyclePhasesForTest();
auto* selectedText = GetInnerLayoutText(inputElement);
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
inputElement->removeAttribute(html_names::kClassAttr);
GetDocument().View()->UpdateLifecycleToLayoutClean(
DocumentUpdateReason::kTest);
EXPECT_TRUE(selectedText->ShouldInvalidateSelection());
UpdateAllLifecyclePhasesForTest(); text_control->removeAttribute(html_names::kClassAttr);
EXPECT_FALSE(selectedText->ShouldInvalidateSelection()); CheckSelectionInvalidationChanges(*selected_text);
} }
TEST_F(LayoutTextControlTest, HitTestSearchInput) { TEST_F(LayoutTextControlTest, HitTestSearchInput) {
...@@ -110,7 +99,7 @@ TEST_F(LayoutTextControlTest, HitTestSearchInput) { ...@@ -110,7 +99,7 @@ TEST_F(LayoutTextControlTest, HitTestSearchInput) {
style="border-width: 20px; font-size: 30px; padding: 0"> style="border-width: 20px; font-size: 30px; padding: 0">
)HTML"); )HTML");
auto* input = GetHTMLInputElementById("input"); auto* input = GetTextControlElementById("input");
HitTestResult result; HitTestResult result;
HitTestLocation location(PhysicalOffset(40, 30)); HitTestLocation location(PhysicalOffset(40, 30));
EXPECT_TRUE(input->GetLayoutObject()->HitTestAllPhases(result, location, EXPECT_TRUE(input->GetLayoutObject()->HitTestAllPhases(result, location,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment