| 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 #include <memory> |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 TEST(HTMLInputElementTest, create) | 17 TEST(HTMLInputElementTest, create) |
| 17 { | 18 { |
| 18 Document* document = Document::create(); | 19 Document* document = Document::create(); |
| 19 HTMLInputElement* input = HTMLInputElement::create(*document, nullptr, /* cr
eatedByParser */ false); | 20 HTMLInputElement* input = HTMLInputElement::create(*document, nullptr, /* cr
eatedByParser */ false); |
| 20 EXPECT_NE(nullptr, input->userAgentShadowRoot()); | 21 EXPECT_NE(nullptr, input->userAgentShadowRoot()); |
| 21 | 22 |
| 22 input = HTMLInputElement::create(*document, nullptr, /* createdByParser */ t
rue); | 23 input = HTMLInputElement::create(*document, nullptr, /* createdByParser */ t
rue); |
| 23 EXPECT_EQ(nullptr, input->userAgentShadowRoot()); | 24 EXPECT_EQ(nullptr, input->userAgentShadowRoot()); |
| 24 input->parserSetAttributes(Vector<Attribute>()); | 25 input->parserSetAttributes(Vector<Attribute>()); |
| 25 EXPECT_NE(nullptr, input->userAgentShadowRoot()); | 26 EXPECT_NE(nullptr, input->userAgentShadowRoot()); |
| 26 } | 27 } |
| 27 | 28 |
| 28 TEST(HTMLInputElementTest, NoAssertWhenMovedInNewDocument) | 29 TEST(HTMLInputElementTest, NoAssertWhenMovedInNewDocument) |
| 29 { | 30 { |
| 30 Document* documentWithoutFrame = Document::create(); | 31 Document* documentWithoutFrame = Document::create(); |
| 31 EXPECT_EQ(nullptr, documentWithoutFrame->frameHost()); | 32 EXPECT_EQ(nullptr, documentWithoutFrame->frameHost()); |
| 32 HTMLHtmlElement* html = HTMLHtmlElement::create(*documentWithoutFrame); | 33 HTMLHtmlElement* html = HTMLHtmlElement::create(*documentWithoutFrame); |
| 33 html->appendChild(HTMLBodyElement::create(*documentWithoutFrame)); | 34 html->appendChild(HTMLBodyElement::create(*documentWithoutFrame)); |
| 34 | 35 |
| 35 // Create an input element with type "range" inside a document without frame
. | 36 // Create an input element with type "range" inside a document without frame
. |
| 36 toHTMLBodyElement(html->firstChild())->setInnerHTML("<input type='range' />"
, ASSERT_NO_EXCEPTION); | 37 toHTMLBodyElement(html->firstChild())->setInnerHTML("<input type='range' />"
, ASSERT_NO_EXCEPTION); |
| 37 documentWithoutFrame->appendChild(html); | 38 documentWithoutFrame->appendChild(html); |
| 38 | 39 |
| 39 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(); | 40 std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(); |
| 40 auto& document = pageHolder->document(); | 41 auto& document = pageHolder->document(); |
| 41 EXPECT_NE(nullptr, document.frameHost()); | 42 EXPECT_NE(nullptr, document.frameHost()); |
| 42 | 43 |
| 43 // Put the input element inside a document with frame. | 44 // Put the input element inside a document with frame. |
| 44 document.body()->appendChild(documentWithoutFrame->body()->firstChild()); | 45 document.body()->appendChild(documentWithoutFrame->body()->firstChild()); |
| 45 | 46 |
| 46 // Remove the input element and all refs to it so it gets deleted before the
document. | 47 // 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. | 48 // The assert in |EventHandlerRegistry::updateEventHandlerTargets()| should
not be triggered. |
| 48 document.body()->removeChild(document.body()->firstChild()); | 49 document.body()->removeChild(document.body()->firstChild()); |
| 49 } | 50 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 77 HTMLInputElement* input = HTMLInputElement::create(*document, nullptr, false
); | 78 HTMLInputElement* input = HTMLInputElement::create(*document, nullptr, false
); |
| 78 input->setAttribute(HTMLNames::typeAttr, "image"); | 79 input->setAttribute(HTMLNames::typeAttr, "image"); |
| 79 input->ensureFallbackContent(); | 80 input->ensureFallbackContent(); |
| 80 // Make sure ensurePrimaryContent() recreates UA shadow tree, and updating | 81 // Make sure ensurePrimaryContent() recreates UA shadow tree, and updating |
| 81 // |value| doesn't crash. | 82 // |value| doesn't crash. |
| 82 input->ensurePrimaryContent(); | 83 input->ensurePrimaryContent(); |
| 83 input->setAttribute(HTMLNames::valueAttr, "aaa"); | 84 input->setAttribute(HTMLNames::valueAttr, "aaa"); |
| 84 } | 85 } |
| 85 | 86 |
| 86 } // namespace blink | 87 } // namespace blink |
| OLD | NEW |