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

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

Issue 541693003: HTMLSelectElement does not include selected index/indices while saving state (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated Created 6 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/html/HTMLSelectElement.h"
7
8 #include "core/frame/FrameView.h"
9 #include "core/html/HTMLDocument.h"
10 #include "core/html/forms/FormController.h"
11 #include "core/loader/EmptyClients.h"
12 #include "core/testing/DummyPageHolder.h"
13 #include <gtest/gtest.h>
14
15 namespace blink {
16
17 class HTMLSelectElementTest : public::testing::Test {
18 protected:
19 virtual void SetUp() OVERRIDE;
20 HTMLDocument& document() const { return *m_document; }
21
22 private:
23 OwnPtr<DummyPageHolder> m_dummyPageHolder;
24 RefPtrWillBePersistent<HTMLDocument> m_document;
25 };
26
27 void HTMLSelectElementTest::SetUp()
28 {
29 Page::PageClients pageClients;
30 fillWithEmptyClients(pageClients);
31 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients) ;
32
33 m_document = toHTMLDocument(&m_dummyPageHolder->document());
34 m_document->setMimeType("text/html");
35 m_document->setCharset("utf-8");
36 }
37
38 TEST_F(HTMLSelectElementTest, SaveRestoreSelectSingleFormControlState)
39 {
40 document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id ='sel'>"
41 "<option value='111'>111</option>"
tkent 2014/09/09 02:14:45 Indent continuous lines.
spartha 2014/09/09 11:09:56 Done.
42 "<option value='222'>222</option>"
43 "<option value='111' selected>!666</option>"
44 "<option value='999'>999</option></select>"), ASSERT_NO_EXCEPTION);
45 document().view()->updateLayoutAndStyleIfNeededRecursive();
46 Element* element = document().getElementById("sel");
47 HTMLFormControlElementWithState* select = toHTMLSelectElement(element);
48
49 // Save the select element state, and then restore again.
50 // Test passes if the restored state is not changed.
tkent 2014/09/09 02:14:45 This is a bad test. The test passes even if resto
spartha 2014/09/09 08:08:04 That is the nature of the issue that this patch tr
51 EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex());
52 FormControlState selectState = select->saveFormControlState();
53 select->restoreFormControlState(selectState);
54 EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex());
55 }
56
57 TEST_F(HTMLSelectElementTest, SaveRestoreSelectMultipleFormControlState)
58 {
59 document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id ='sel' multiple>"
60 "<option value='111' id='0'>111</option>"
61 "<option value='222'>222</option>"
62 "<option value='111' selected id='2'>!666</option>"
63 "<option value='999' selected id='3'>999</option></select>"), ASSERT_NO_EXCE PTION);
64 document().view()->updateLayoutAndStyleIfNeededRecursive();
65 HTMLFormControlElementWithState* select = toHTMLSelectElement(document().get ElementById("sel"));
66
67 HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0") );
68 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2") );
69 HTMLOptionElement* opt3 = toHTMLOptionElement(document().getElementById("3") );
70
71 // Save the select element state, and then restore again.
72 // Test passes if the selected options are not changed.
73 EXPECT_FALSE(opt0->selected());
74 EXPECT_TRUE(opt2->selected());
75 EXPECT_TRUE(opt3->selected());
76 FormControlState selectState = select->saveFormControlState();
77
78 select->restoreFormControlState(selectState);
79 EXPECT_FALSE(opt0->selected());
80 EXPECT_TRUE(opt2->selected());
81 EXPECT_TRUE(opt3->selected());
82 }
83
84 } // namespace blink
OLDNEW
« Source/core/html/HTMLSelectElement.cpp ('K') | « Source/core/html/HTMLSelectElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698