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