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 @@
#include "third_party/blink/renderer/core/layout/layout_text_control.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"
namespace blink {
......@@ -14,14 +14,33 @@ namespace {
class LayoutTextControlTest : public RenderingTest {
protected:
HTMLInputElement* GetHTMLInputElementById(const char* id) {
return To<HTMLInputElement>(GetDocument().getElementById(id));
TextControlElement* GetTextControlElementById(const char* id) {
return To<TextControlElement>(GetDocument().getElementById(id));
}
// Return the LayoutText from inside an HTMLInputElement's user agent shadow
// tree.
LayoutText* GetInnerLayoutText(HTMLInputElement* input) {
// Return the LayoutText from inside a text control's user agent shadow tree.
LayoutText* GetInnerLayoutText(TextControlElement* control) {
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,
<input id="input" type="text" value="AAAAAAAAAAAA">
)HTML");
auto* inputElement = GetHTMLInputElementById("input");
inputElement->focus();
inputElement->SetSelectionRange(1, 3);
UpdateAllLifecyclePhasesForTest();
auto* selectedText = GetInnerLayoutText(inputElement);
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
auto* text_control = GetTextControlElementById("input");
auto* selected_text = SetupLayoutTextWithCleanSelection(text_control);
inputElement->setAttribute(html_names::kClassAttr, "pseudoSelection");
GetDocument().View()->UpdateLifecycleToLayoutClean(
DocumentUpdateReason::kTest);
EXPECT_TRUE(selectedText->ShouldInvalidateSelection());
UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
text_control->setAttribute(html_names::kClassAttr, "pseudoSelection");
CheckSelectionInvalidationChanges(*selected_text);
}
TEST_F(LayoutTextControlTest,
......@@ -61,21 +70,11 @@ TEST_F(LayoutTextControlTest,
<input id="input" type="text" value="AAAAAAAAAAAA">
)HTML");
auto* inputElement = GetHTMLInputElementById("input");
inputElement->focus();
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());
auto* text_control = GetTextControlElementById("input");
auto* selected_text = SetupLayoutTextWithCleanSelection(text_control);
UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
text_control->setAttribute(html_names::kClassAttr, "pseudoSelection");
CheckSelectionInvalidationChanges(*selected_text);
}
TEST_F(LayoutTextControlTest,
......@@ -87,21 +86,11 @@ TEST_F(LayoutTextControlTest,
<input id="input" type="text" class="pseudoSelection" value="AAAAAAAAAAAA">
)HTML");
auto* inputElement = GetHTMLInputElementById("input");
inputElement->focus();
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());
auto* text_control = GetTextControlElementById("input");
auto* selected_text = SetupLayoutTextWithCleanSelection(text_control);
UpdateAllLifecyclePhasesForTest();
EXPECT_FALSE(selectedText->ShouldInvalidateSelection());
text_control->removeAttribute(html_names::kClassAttr);
CheckSelectionInvalidationChanges(*selected_text);
}
TEST_F(LayoutTextControlTest, HitTestSearchInput) {
......@@ -110,7 +99,7 @@ TEST_F(LayoutTextControlTest, HitTestSearchInput) {
style="border-width: 20px; font-size: 30px; padding: 0">
)HTML");
auto* input = GetHTMLInputElementById("input");
auto* input = GetTextControlElementById("input");
HitTestResult result;
HitTestLocation location(PhysicalOffset(40, 30));
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