Index: third_party/WebKit/Source/core/html/HTMLInputElementTest.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLInputElementTest.cpp b/third_party/WebKit/Source/core/html/HTMLInputElementTest.cpp |
index 9dabccd19e5d16e0c23f2838cbe3ca697ad1377d..e17481e06b7f5f7a53804a9cddbc19c7229477b0 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLInputElementTest.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLInputElementTest.cpp |
@@ -11,6 +11,7 @@ |
#include "core/html/HTMLBodyElement.h" |
#include "core/html/HTMLFormElement.h" |
#include "core/html/HTMLHtmlElement.h" |
+#include "core/html/HTMLOptionElement.h" |
#include "core/html/forms/DateTimeChooser.h" |
#include "core/testing/DummyPageHolder.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -18,19 +19,73 @@ |
namespace blink { |
-TEST(HTMLInputElementTest, create) |
+class HTMLInputElementTest : public testing::Test { |
+protected: |
+ Document& document() { return m_pageHolder->document(); } |
+ HTMLInputElement& testElement() |
+ { |
+ Element* element = document().getElementById("test"); |
+ DCHECK(element); |
+ return toHTMLInputElement(*element); |
+ } |
+ |
+private: |
+ void SetUp() override |
+ { |
+ m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); |
+ } |
+ |
+ std::unique_ptr<DummyPageHolder> m_pageHolder; |
+}; |
+ |
+TEST_F(HTMLInputElementTest, FilteredDataListOptionsNoList) |
{ |
- Document* document = Document::create(); |
- HTMLInputElement* input = HTMLInputElement::create(*document, nullptr, /* createdByParser */ false); |
+ document().documentElement()->setInnerHTML("<input id=test>", ASSERT_NO_EXCEPTION); |
+ EXPECT_TRUE(testElement().filteredDataListOptions().isEmpty()); |
+ |
+ document().documentElement()->setInnerHTML("<input id=test list=dl1><datalist id=dl1></datalist>", ASSERT_NO_EXCEPTION); |
+ EXPECT_TRUE(testElement().filteredDataListOptions().isEmpty()); |
+} |
+ |
+TEST_F(HTMLInputElementTest, FilteredDataListOptionsPrefixed) |
+{ |
+ document().documentElement()->setInnerHTML( |
+ "<input id=test value=ABC list=dl2>" |
+ "<datalist id=dl2>" |
+ "<option>AbC DEF</option>" |
+ "<option>VAX</option>" |
+ "<option value=ghi>abc</option>" |
+ "</datalist>", ASSERT_NO_EXCEPTION); |
+ auto options = testElement().filteredDataListOptions(); |
+ EXPECT_EQ(1u, options.size()); |
+ EXPECT_EQ("AbC DEF", options[0]->value().utf8()); |
+} |
+ |
+TEST_F(HTMLInputElementTest, FilteredDataListOptionsForMultipleEmail) |
+{ |
+ document().documentElement()->setInnerHTML( |
+ "<input id=test value='foo@example.com, tkent' list=dl3 type=email multiple>" |
+ "<datalist id=dl3>" |
+ "<option>keishi@chromium.org</option>" |
+ "<option>tkent@chromium.org</option>" |
+ "</datalist>", ASSERT_NO_EXCEPTION); |
+ auto options = testElement().filteredDataListOptions(); |
+ EXPECT_EQ(1u, options.size()); |
+ EXPECT_EQ("tkent@chromium.org", options[0]->value().utf8()); |
+} |
+ |
+TEST_F(HTMLInputElementTest, create) |
+{ |
+ HTMLInputElement* input = HTMLInputElement::create(document(), nullptr, /* createdByParser */ false); |
EXPECT_NE(nullptr, input->userAgentShadowRoot()); |
- input = HTMLInputElement::create(*document, nullptr, /* createdByParser */ true); |
+ input = HTMLInputElement::create(document(), nullptr, /* createdByParser */ true); |
EXPECT_EQ(nullptr, input->userAgentShadowRoot()); |
input->parserSetAttributes(Vector<Attribute>()); |
EXPECT_NE(nullptr, input->userAgentShadowRoot()); |
} |
-TEST(HTMLInputElementTest, NoAssertWhenMovedInNewDocument) |
+TEST_F(HTMLInputElementTest, NoAssertWhenMovedInNewDocument) |
{ |
Document* documentWithoutFrame = Document::create(); |
EXPECT_EQ(nullptr, documentWithoutFrame->frameHost()); |
@@ -53,20 +108,16 @@ TEST(HTMLInputElementTest, NoAssertWhenMovedInNewDocument) |
document.body()->removeChild(document.body()->firstChild()); |
} |
-TEST(HTMLInputElementTest, DefaultToolTip) |
+TEST_F(HTMLInputElementTest, DefaultToolTip) |
{ |
- Document* document = Document::create(); |
- HTMLHtmlElement* html = HTMLHtmlElement::create(*document); |
- html->appendChild(HTMLBodyElement::create(*document)); |
- HTMLInputElement* inputWithoutForm = HTMLInputElement::create(*document, nullptr, false); |
+ HTMLInputElement* inputWithoutForm = HTMLInputElement::create(document(), nullptr, false); |
inputWithoutForm->setBooleanAttribute(HTMLNames::requiredAttr, true); |
- toHTMLBodyElement(html->firstChild())->appendChild(inputWithoutForm); |
- document->appendChild(html); |
+ document().body()->appendChild(inputWithoutForm); |
EXPECT_EQ("<<ValidationValueMissing>>", inputWithoutForm->defaultToolTip()); |
- HTMLFormElement* form = HTMLFormElement::create(*document); |
- document->body()->appendChild(form); |
- HTMLInputElement* inputWithForm = HTMLInputElement::create(*document, nullptr, false); |
+ HTMLFormElement* form = HTMLFormElement::create(document()); |
+ document().body()->appendChild(form); |
+ HTMLInputElement* inputWithForm = HTMLInputElement::create(document(), nullptr, false); |
inputWithForm->setBooleanAttribute(HTMLNames::requiredAttr, true); |
form->appendChild(inputWithForm); |
EXPECT_EQ("<<ValidationValueMissing>>", inputWithForm->defaultToolTip()); |
@@ -76,10 +127,9 @@ TEST(HTMLInputElementTest, DefaultToolTip) |
} |
// crbug.com/589838 |
-TEST(HTMLInputElementTest, ImageTypeCrash) |
+TEST_F(HTMLInputElementTest, ImageTypeCrash) |
{ |
- Document* document = Document::create(); |
- HTMLInputElement* input = HTMLInputElement::create(*document, nullptr, false); |
+ HTMLInputElement* input = HTMLInputElement::create(document(), nullptr, false); |
input->setAttribute(HTMLNames::typeAttr, "image"); |
input->ensureFallbackContent(); |
// Make sure ensurePrimaryContent() recreates UA shadow tree, and updating |
@@ -88,14 +138,12 @@ TEST(HTMLInputElementTest, ImageTypeCrash) |
input->setAttribute(HTMLNames::valueAttr, "aaa"); |
} |
-TEST(HTMLInputElementTest, DateTimeChooserSizeParamRespectsScale) |
+TEST_F(HTMLInputElementTest, DateTimeChooserSizeParamRespectsScale) |
{ |
- std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(); |
- Document* document = &(pageHolder->document()); |
- document->view()->frame().host()->visualViewport().setScale(2.f); |
- document->body()->setInnerHTML("<input type='date' style='width:200px;height:50px' />", ASSERT_NO_EXCEPTION); |
- document->view()->updateAllLifecyclePhases(); |
- HTMLInputElement* input = toHTMLInputElement(document->body()->firstChild()); |
+ document().view()->frame().host()->visualViewport().setScale(2.f); |
+ document().body()->setInnerHTML("<input type='date' style='width:200px;height:50px' />", ASSERT_NO_EXCEPTION); |
+ document().view()->updateAllLifecyclePhases(); |
+ HTMLInputElement* input = toHTMLInputElement(document().body()->firstChild()); |
DateTimeChooserParameters params; |
bool success = input->setupDateTimeChooserParameters(params); |