| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/html/HTMLSelectElement.h" | 6 #include "core/html/HTMLSelectElement.h" |
| 7 | 7 |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/html/HTMLDocument.h" | 9 #include "core/html/HTMLDocument.h" |
| 10 #include "core/html/forms/FormController.h" | 10 #include "core/html/forms/FormController.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 m_document->setCharset("utf-8"); | 35 m_document->setCharset("utf-8"); |
| 36 } | 36 } |
| 37 | 37 |
| 38 TEST_F(HTMLSelectElementTest, SaveRestoreSelectSingleFormControlState) | 38 TEST_F(HTMLSelectElementTest, SaveRestoreSelectSingleFormControlState) |
| 39 { | 39 { |
| 40 document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id
='sel'>" | 40 document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id
='sel'>" |
| 41 "<option value='111' id='0'>111</option>" | 41 "<option value='111' id='0'>111</option>" |
| 42 "<option value='222'>222</option>" | 42 "<option value='222'>222</option>" |
| 43 "<option value='111' selected id='2'>!666</option>" | 43 "<option value='111' selected id='2'>!666</option>" |
| 44 "<option value='999'>999</option></select>"), ASSERT_NO_EXCEPTION); | 44 "<option value='999'>999</option></select>"), ASSERT_NO_EXCEPTION); |
| 45 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 45 document().view()->updateLayoutAndStyleForPainting(); |
| 46 Element* element = document().getElementById("sel"); | 46 Element* element = document().getElementById("sel"); |
| 47 HTMLFormControlElementWithState* select = toHTMLSelectElement(element); | 47 HTMLFormControlElementWithState* select = toHTMLSelectElement(element); |
| 48 HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0")
); | 48 HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0")
); |
| 49 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2")
); | 49 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2")
); |
| 50 | 50 |
| 51 // Save the select element state, and then restore again. | 51 // Save the select element state, and then restore again. |
| 52 // Test passes if the restored state is not changed. | 52 // Test passes if the restored state is not changed. |
| 53 EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex()); | 53 EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex()); |
| 54 EXPECT_FALSE(opt0->selected()); | 54 EXPECT_FALSE(opt0->selected()); |
| 55 EXPECT_TRUE(opt2->selected()); | 55 EXPECT_TRUE(opt2->selected()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 EXPECT_TRUE(opt2->selected()); | 67 EXPECT_TRUE(opt2->selected()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(HTMLSelectElementTest, SaveRestoreSelectMultipleFormControlState) | 70 TEST_F(HTMLSelectElementTest, SaveRestoreSelectMultipleFormControlState) |
| 71 { | 71 { |
| 72 document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id
='sel' multiple>" | 72 document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id
='sel' multiple>" |
| 73 "<option value='111' id='0'>111</option>" | 73 "<option value='111' id='0'>111</option>" |
| 74 "<option value='222'>222</option>" | 74 "<option value='222'>222</option>" |
| 75 "<option value='111' selected id='2'>!666</option>" | 75 "<option value='111' selected id='2'>!666</option>" |
| 76 "<option value='999' selected id='3'>999</option></select>"), ASSERT_NO_
EXCEPTION); | 76 "<option value='999' selected id='3'>999</option></select>"), ASSERT_NO_
EXCEPTION); |
| 77 document().view()->updateLayoutAndStyleIfNeededRecursive(); | 77 document().view()->updateLayoutAndStyleForPainting(); |
| 78 HTMLFormControlElementWithState* select = toHTMLSelectElement(document().get
ElementById("sel")); | 78 HTMLFormControlElementWithState* select = toHTMLSelectElement(document().get
ElementById("sel")); |
| 79 | 79 |
| 80 HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0")
); | 80 HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0")
); |
| 81 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2")
); | 81 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2")
); |
| 82 HTMLOptionElement* opt3 = toHTMLOptionElement(document().getElementById("3")
); | 82 HTMLOptionElement* opt3 = toHTMLOptionElement(document().getElementById("3")
); |
| 83 | 83 |
| 84 // Save the select element state, and then restore again. | 84 // Save the select element state, and then restore again. |
| 85 // Test passes if the selected options are not changed. | 85 // Test passes if the selected options are not changed. |
| 86 EXPECT_FALSE(opt0->selected()); | 86 EXPECT_FALSE(opt0->selected()); |
| 87 EXPECT_TRUE(opt2->selected()); | 87 EXPECT_TRUE(opt2->selected()); |
| 88 EXPECT_TRUE(opt3->selected()); | 88 EXPECT_TRUE(opt3->selected()); |
| 89 FormControlState selectState = select->saveFormControlState(); | 89 FormControlState selectState = select->saveFormControlState(); |
| 90 EXPECT_EQ(4U, selectState.valueSize()); | 90 EXPECT_EQ(4U, selectState.valueSize()); |
| 91 | 91 |
| 92 // Clear the selected state, to be restored by restoreFormControlState. | 92 // Clear the selected state, to be restored by restoreFormControlState. |
| 93 opt2->setSelected(false); | 93 opt2->setSelected(false); |
| 94 opt3->setSelected(false); | 94 opt3->setSelected(false); |
| 95 ASSERT_FALSE(opt2->selected()); | 95 ASSERT_FALSE(opt2->selected()); |
| 96 ASSERT_FALSE(opt3->selected()); | 96 ASSERT_FALSE(opt3->selected()); |
| 97 | 97 |
| 98 // Restore | 98 // Restore |
| 99 select->restoreFormControlState(selectState); | 99 select->restoreFormControlState(selectState); |
| 100 EXPECT_FALSE(opt0->selected()); | 100 EXPECT_FALSE(opt0->selected()); |
| 101 EXPECT_TRUE(opt2->selected()); | 101 EXPECT_TRUE(opt2->selected()); |
| 102 EXPECT_TRUE(opt3->selected()); | 102 EXPECT_TRUE(opt3->selected()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |