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