| OLD | NEW |
| 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/HTMLInputElement.h" | 5 #include "core/html/HTMLInputElement.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/html/HTMLBodyElement.h" | 8 #include "core/html/HTMLBodyElement.h" |
| 9 #include "core/html/HTMLFormElement.h" | 9 #include "core/html/HTMLFormElement.h" |
| 10 #include "core/html/HTMLHtmlElement.h" | 10 #include "core/html/HTMLHtmlElement.h" |
| 11 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 TEST(HTMLInputElementTest, create) | 16 TEST(HTMLInputElementTest, create) |
| 17 { | 17 { |
| 18 const RefPtrWillBeRawPtr<Document> document = Document::create(); | 18 const RawPtr<Document> document = Document::create(); |
| 19 RefPtrWillBeRawPtr<HTMLInputElement> input = HTMLInputElement::create(*docum
ent, nullptr, /* createdByParser */ false); | 19 RawPtr<HTMLInputElement> input = HTMLInputElement::create(*document, nullptr
, /* createdByParser */ false); |
| 20 EXPECT_NE(nullptr, input->userAgentShadowRoot()); | 20 EXPECT_NE(nullptr, input->userAgentShadowRoot()); |
| 21 | 21 |
| 22 input = HTMLInputElement::create(*document, nullptr, /* createdByParser */ t
rue); | 22 input = HTMLInputElement::create(*document, nullptr, /* createdByParser */ t
rue); |
| 23 EXPECT_EQ(nullptr, input->userAgentShadowRoot()); | 23 EXPECT_EQ(nullptr, input->userAgentShadowRoot()); |
| 24 input->parserSetAttributes(Vector<Attribute>()); | 24 input->parserSetAttributes(Vector<Attribute>()); |
| 25 EXPECT_NE(nullptr, input->userAgentShadowRoot()); | 25 EXPECT_NE(nullptr, input->userAgentShadowRoot()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 TEST(HTMLInputElementTest, NoAssertWhenMovedInNewDocument) | 28 TEST(HTMLInputElementTest, NoAssertWhenMovedInNewDocument) |
| 29 { | 29 { |
| 30 const RefPtrWillBeRawPtr<Document> documentWithoutFrame = Document::create()
; | 30 const RawPtr<Document> documentWithoutFrame = Document::create(); |
| 31 EXPECT_EQ(nullptr, documentWithoutFrame->frameHost()); | 31 EXPECT_EQ(nullptr, documentWithoutFrame->frameHost()); |
| 32 RefPtrWillBeRawPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*document
WithoutFrame); | 32 RawPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*documentWithoutFrame
); |
| 33 html->appendChild(HTMLBodyElement::create(*documentWithoutFrame)); | 33 html->appendChild(HTMLBodyElement::create(*documentWithoutFrame)); |
| 34 | 34 |
| 35 // Create an input element with type "range" inside a document without frame
. | 35 // Create an input element with type "range" inside a document without frame
. |
| 36 toHTMLBodyElement(html->firstChild())->setInnerHTML("<input type='range' />"
, ASSERT_NO_EXCEPTION); | 36 toHTMLBodyElement(html->firstChild())->setInnerHTML("<input type='range' />"
, ASSERT_NO_EXCEPTION); |
| 37 documentWithoutFrame->appendChild(html.release()); | 37 documentWithoutFrame->appendChild(html.release()); |
| 38 | 38 |
| 39 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(); | 39 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(); |
| 40 auto& document = pageHolder->document(); | 40 auto& document = pageHolder->document(); |
| 41 EXPECT_NE(nullptr, document.frameHost()); | 41 EXPECT_NE(nullptr, document.frameHost()); |
| 42 | 42 |
| 43 // Put the input element inside a document with frame. | 43 // Put the input element inside a document with frame. |
| 44 document.body()->appendChild(documentWithoutFrame->body()->firstChild()); | 44 document.body()->appendChild(documentWithoutFrame->body()->firstChild()); |
| 45 | 45 |
| 46 // Remove the input element and all refs to it so it gets deleted before the
document. | 46 // Remove the input element and all refs to it so it gets deleted before the
document. |
| 47 // The assert in |EventHandlerRegistry::updateEventHandlerTargets()| should
not be triggered. | 47 // The assert in |EventHandlerRegistry::updateEventHandlerTargets()| should
not be triggered. |
| 48 document.body()->removeChild(document.body()->firstChild()); | 48 document.body()->removeChild(document.body()->firstChild()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST(HTMLInputElementTest, DefaultToolTip) | 51 TEST(HTMLInputElementTest, DefaultToolTip) |
| 52 { | 52 { |
| 53 RefPtrWillBeRawPtr<Document> document = Document::create(); | 53 RawPtr<Document> document = Document::create(); |
| 54 RefPtrWillBeRawPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*document
); | 54 RawPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(*document); |
| 55 html->appendChild(HTMLBodyElement::create(*document)); | 55 html->appendChild(HTMLBodyElement::create(*document)); |
| 56 RefPtrWillBeRawPtr<HTMLInputElement> inputWithoutForm = HTMLInputElement::cr
eate(*document, nullptr, false); | 56 RawPtr<HTMLInputElement> inputWithoutForm = HTMLInputElement::create(*docume
nt, nullptr, false); |
| 57 inputWithoutForm->setBooleanAttribute(HTMLNames::requiredAttr, true); | 57 inputWithoutForm->setBooleanAttribute(HTMLNames::requiredAttr, true); |
| 58 toHTMLBodyElement(html->firstChild())->appendChild(inputWithoutForm.get()); | 58 toHTMLBodyElement(html->firstChild())->appendChild(inputWithoutForm.get()); |
| 59 document->appendChild(html.release()); | 59 document->appendChild(html.release()); |
| 60 EXPECT_EQ("<<ValidationValueMissing>>", inputWithoutForm->defaultToolTip()); | 60 EXPECT_EQ("<<ValidationValueMissing>>", inputWithoutForm->defaultToolTip()); |
| 61 | 61 |
| 62 RefPtrWillBeRawPtr<HTMLFormElement> form = HTMLFormElement::create(*document
); | 62 RawPtr<HTMLFormElement> form = HTMLFormElement::create(*document); |
| 63 document->body()->appendChild(form.get()); | 63 document->body()->appendChild(form.get()); |
| 64 RefPtrWillBeRawPtr<HTMLInputElement> inputWithForm = HTMLInputElement::creat
e(*document, nullptr, false); | 64 RawPtr<HTMLInputElement> inputWithForm = HTMLInputElement::create(*document,
nullptr, false); |
| 65 inputWithForm->setBooleanAttribute(HTMLNames::requiredAttr, true); | 65 inputWithForm->setBooleanAttribute(HTMLNames::requiredAttr, true); |
| 66 form->appendChild(inputWithForm.get()); | 66 form->appendChild(inputWithForm.get()); |
| 67 EXPECT_EQ("<<ValidationValueMissing>>", inputWithForm->defaultToolTip()); | 67 EXPECT_EQ("<<ValidationValueMissing>>", inputWithForm->defaultToolTip()); |
| 68 | 68 |
| 69 form->setBooleanAttribute(HTMLNames::novalidateAttr, true); | 69 form->setBooleanAttribute(HTMLNames::novalidateAttr, true); |
| 70 EXPECT_EQ(String(), inputWithForm->defaultToolTip()); | 70 EXPECT_EQ(String(), inputWithForm->defaultToolTip()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // crbug.com/589838 | 73 // crbug.com/589838 |
| 74 TEST(HTMLInputElementTest, ImageTypeCrash) | 74 TEST(HTMLInputElementTest, ImageTypeCrash) |
| 75 { | 75 { |
| 76 RefPtrWillBeRawPtr<Document> document = Document::create(); | 76 RawPtr<Document> document = Document::create(); |
| 77 RefPtrWillBeRawPtr<HTMLInputElement> input = HTMLInputElement::create(*docum
ent, nullptr, false); | 77 RawPtr<HTMLInputElement> input = HTMLInputElement::create(*document, nullptr
, false); |
| 78 input->setAttribute(HTMLNames::typeAttr, "image"); | 78 input->setAttribute(HTMLNames::typeAttr, "image"); |
| 79 input->ensureFallbackContent(); | 79 input->ensureFallbackContent(); |
| 80 // Make sure ensurePrimaryContent() recreates UA shadow tree, and updating | 80 // Make sure ensurePrimaryContent() recreates UA shadow tree, and updating |
| 81 // |value| doesn't crash. | 81 // |value| doesn't crash. |
| 82 input->ensurePrimaryContent(); | 82 input->ensurePrimaryContent(); |
| 83 input->setAttribute(HTMLNames::valueAttr, "aaa"); | 83 input->setAttribute(HTMLNames::valueAttr, "aaa"); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace blink | 86 } // namespace blink |
| OLD | NEW |