Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLSelectElementTest.cpp

Issue 2151763002: SELECT element: Fix a DCHECK failure in optionToBeShown(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SELECT element: Fix a DCHECK failure in optionToBeShown(). Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/HTMLSelectElement.h" 5 #include "core/html/HTMLSelectElement.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/html/HTMLDocument.h" 8 #include "core/html/HTMLDocument.h"
9 #include "core/html/HTMLFormElement.h" 9 #include "core/html/HTMLFormElement.h"
10 #include "core/html/forms/FormController.h" 10 #include "core/html/forms/FormController.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 TEST_F(HTMLSelectElementTest, RestoreUnmatchedFormControlState)
106 {
107 // We had a bug that selectedOption() and m_lastOnChangeOption were
108 // mismatched in optionToBeShown(). It happened when
109 // restoreFormControlState() couldn't find matched OPTIONs.
110 // crbug.com/627833.
111
112 document().documentElement()->setInnerHTML("<select id='sel'>"
113 "<option selected>Default</option>"
114 "<option id='2'>222</option>"
115 "</select>", ASSERT_NO_EXCEPTION);
116 document().view()->updateAllLifecyclePhases();
117 Element* element = document().getElementById("sel");
118 HTMLFormControlElementWithState* select = toHTMLSelectElement(element);
119 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2") );
120
121 toHTMLSelectElement(element)->setSelectedIndex(1);
122 // Save the current state.
123 FormControlState selectState = select->saveFormControlState();
124 EXPECT_EQ(2U, selectState.valueSize());
125
126 // Reset the status.
127 select->reset();
128 ASSERT_FALSE(opt2->selected());
129 element->removeChild(opt2);
130
131 // Restore
132 select->restoreFormControlState(selectState);
133 EXPECT_EQ(-1, toHTMLSelectElement(element)->selectedIndex());
134 EXPECT_EQ(nullptr, toHTMLSelectElement(element)->optionToBeShown());
135 }
136
105 TEST_F(HTMLSelectElementTest, ElementRectRelativeToViewport) 137 TEST_F(HTMLSelectElementTest, ElementRectRelativeToViewport)
106 { 138 {
107 document().documentElement()->setInnerHTML("<select style='position:fixed; t op:12.3px; height:24px; -webkit-appearance:none;'><option>o1</select>", ASSERT_N O_EXCEPTION); 139 document().documentElement()->setInnerHTML("<select style='position:fixed; t op:12.3px; height:24px; -webkit-appearance:none;'><option>o1</select>", ASSERT_N O_EXCEPTION);
108 document().view()->updateAllLifecyclePhases(); 140 document().view()->updateAllLifecyclePhases();
109 HTMLSelectElement* select = toHTMLSelectElement(document().body()->firstChil d()); 141 HTMLSelectElement* select = toHTMLSelectElement(document().body()->firstChil d());
110 ASSERT(select); 142 ASSERT(select);
111 IntRect bounds = select->elementRectRelativeToViewport(); 143 IntRect bounds = select->elementRectRelativeToViewport();
112 EXPECT_EQ(24, bounds.height()); 144 EXPECT_EQ(24, bounds.height());
113 } 145 }
114 146
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 TEST_F(HTMLSelectElementTest, SetRecalcListItemsByOptgroupRemoval) 376 TEST_F(HTMLSelectElementTest, SetRecalcListItemsByOptgroupRemoval)
345 { 377 {
346 document().documentElement()->setInnerHTML("<select><optgroup><option>sub1</ option><option>sub2</option></optgroup></select>", ASSERT_NO_EXCEPTION); 378 document().documentElement()->setInnerHTML("<select><optgroup><option>sub1</ option><option>sub2</option></optgroup></select>", ASSERT_NO_EXCEPTION);
347 document().view()->updateAllLifecyclePhases(); 379 document().view()->updateAllLifecyclePhases();
348 HTMLSelectElement* select = toHTMLSelectElement(document().body()->firstChil d()); 380 HTMLSelectElement* select = toHTMLSelectElement(document().body()->firstChil d());
349 select->setInnerHTML("", ASSERT_NO_EXCEPTION); 381 select->setInnerHTML("", ASSERT_NO_EXCEPTION);
350 // PASS if setInnerHTML didn't have a check failure. 382 // PASS if setInnerHTML didn't have a check failure.
351 } 383 }
352 384
353 } // namespace blink 385 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698