| 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 <memory> |
| 7 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/events/KeyboardEvent.h" |
| 10 #include "core/events/KeyboardEventInit.h" |
| 8 #include "core/frame/FrameHost.h" | 11 #include "core/frame/FrameHost.h" |
| 9 #include "core/frame/FrameView.h" | 12 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/VisualViewport.h" | 13 #include "core/frame/VisualViewport.h" |
| 11 #include "core/html/HTMLBodyElement.h" | 14 #include "core/html/HTMLBodyElement.h" |
| 12 #include "core/html/HTMLFormElement.h" | 15 #include "core/html/HTMLFormElement.h" |
| 13 #include "core/html/HTMLHtmlElement.h" | 16 #include "core/html/HTMLHtmlElement.h" |
| 14 #include "core/html/HTMLOptionElement.h" | 17 #include "core/html/HTMLOptionElement.h" |
| 15 #include "core/html/forms/DateTimeChooser.h" | 18 #include "core/html/forms/DateTimeChooser.h" |
| 16 #include "core/testing/DummyPageHolder.h" | 19 #include "core/testing/DummyPageHolder.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include <memory> | |
| 19 | 21 |
| 20 namespace blink { | 22 namespace blink { |
| 21 | 23 |
| 22 class HTMLInputElementTest : public testing::Test { | 24 class HTMLInputElementTest : public testing::Test { |
| 23 protected: | 25 protected: |
| 24 Document& document() { return m_pageHolder->document(); } | 26 Document& document() { return m_pageHolder->document(); } |
| 25 HTMLInputElement& testElement() { | 27 HTMLInputElement& testElement() { |
| 26 Element* element = document().getElementById("test"); | 28 Element* element = document().getElementById("test"); |
| 27 DCHECK(element); | 29 DCHECK(element); |
| 28 return toHTMLInputElement(*element); | 30 return toHTMLInputElement(*element); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 TEST_F(HTMLInputElementTest, ImageTypeCrash) { | 143 TEST_F(HTMLInputElementTest, ImageTypeCrash) { |
| 142 HTMLInputElement* input = HTMLInputElement::create(document(), false); | 144 HTMLInputElement* input = HTMLInputElement::create(document(), false); |
| 143 input->setAttribute(HTMLNames::typeAttr, "image"); | 145 input->setAttribute(HTMLNames::typeAttr, "image"); |
| 144 input->ensureFallbackContent(); | 146 input->ensureFallbackContent(); |
| 145 // Make sure ensurePrimaryContent() recreates UA shadow tree, and updating | 147 // Make sure ensurePrimaryContent() recreates UA shadow tree, and updating |
| 146 // |value| doesn't crash. | 148 // |value| doesn't crash. |
| 147 input->ensurePrimaryContent(); | 149 input->ensurePrimaryContent(); |
| 148 input->setAttribute(HTMLNames::valueAttr, "aaa"); | 150 input->setAttribute(HTMLNames::valueAttr, "aaa"); |
| 149 } | 151 } |
| 150 | 152 |
| 153 TEST_F(HTMLInputElementTest, RadioKeyDownDCHECKFailure) { |
| 154 // crbug.com/697286 |
| 155 document().body()->setInnerHTML( |
| 156 "<input type=radio name=g><input type=radio name=g>"); |
| 157 HTMLInputElement& radio1 = |
| 158 toHTMLInputElement(*document().body()->firstChild()); |
| 159 HTMLInputElement& radio2 = toHTMLInputElement(*radio1.nextSibling()); |
| 160 radio1.focus(); |
| 161 // Make layout-dirty. |
| 162 radio2.setAttribute(HTMLNames::styleAttr, "position:fixed"); |
| 163 KeyboardEventInit init; |
| 164 init.setKey("ArrowRight"); |
| 165 radio1.defaultEventHandler(new KeyboardEvent("keydown", init)); |
| 166 EXPECT_EQ(document().activeElement(), &radio2); |
| 167 } |
| 168 |
| 151 TEST_F(HTMLInputElementTest, DateTimeChooserSizeParamRespectsScale) { | 169 TEST_F(HTMLInputElementTest, DateTimeChooserSizeParamRespectsScale) { |
| 152 document().view()->frame().page()->visualViewport().setScale(2.f); | 170 document().view()->frame().page()->visualViewport().setScale(2.f); |
| 153 document().body()->setInnerHTML( | 171 document().body()->setInnerHTML( |
| 154 "<input type='date' style='width:200px;height:50px' />"); | 172 "<input type='date' style='width:200px;height:50px' />"); |
| 155 document().view()->updateAllLifecyclePhases(); | 173 document().view()->updateAllLifecyclePhases(); |
| 156 HTMLInputElement* input = toHTMLInputElement(document().body()->firstChild()); | 174 HTMLInputElement* input = toHTMLInputElement(document().body()->firstChild()); |
| 157 | 175 |
| 158 DateTimeChooserParameters params; | 176 DateTimeChooserParameters params; |
| 159 bool success = input->setupDateTimeChooserParameters(params); | 177 bool success = input->setupDateTimeChooserParameters(params); |
| 160 EXPECT_TRUE(success); | 178 EXPECT_TRUE(success); |
| 161 EXPECT_EQ("date", params.type); | 179 EXPECT_EQ("date", params.type); |
| 162 EXPECT_EQ(IntRect(16, 16, 400, 100), params.anchorRectInScreen); | 180 EXPECT_EQ(IntRect(16, 16, 400, 100), params.anchorRectInScreen); |
| 163 } | 181 } |
| 164 | 182 |
| 165 } // namespace blink | 183 } // namespace blink |
| OLD | NEW |