OLD | NEW |
---|---|
(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' id='0'>111</option>" | |
42 "<option value='222'>222</option>" | |
43 "<option value='111' selected id='2'>!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 HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0") ); | |
49 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2") ); | |
50 | |
51 // Save the select element state, and then restore again. | |
52 // Test passes if the restored state is not changed. | |
tkent
2014/09/09 23:55:23
This is not acceptable.
Please use another Documen
spartha
2014/09/10 06:33:33
Done. I now clear the existing selection and then
| |
53 EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex()); | |
54 EXPECT_FALSE(opt0->selected()); | |
55 EXPECT_TRUE(opt2->selected()); | |
56 FormControlState selectState = select->saveFormControlState(); | |
57 ASSERT_EQ(2U, selectState.valueSize()); | |
58 | |
59 select->restoreFormControlState(selectState); | |
60 EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex()); | |
61 EXPECT_FALSE(opt0->selected()); | |
62 EXPECT_TRUE(opt2->selected()); | |
63 } | |
64 | |
65 TEST_F(HTMLSelectElementTest, SaveRestoreSelectMultipleFormControlState) | |
66 { | |
67 document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id ='sel' multiple>" | |
68 "<option value='111' id='0'>111</option>" | |
69 "<option value='222'>222</option>" | |
70 "<option value='111' selected id='2'>!666</option>" | |
71 "<option value='999' selected id='3'>999</option></select>"), ASSERT_NO_ EXCEPTION); | |
72 document().view()->updateLayoutAndStyleIfNeededRecursive(); | |
73 HTMLFormControlElementWithState* select = toHTMLSelectElement(document().get ElementById("sel")); | |
74 | |
75 HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0") ); | |
76 HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2") ); | |
77 HTMLOptionElement* opt3 = toHTMLOptionElement(document().getElementById("3") ); | |
78 | |
79 // Save the select element state, and then restore again. | |
80 // Test passes if the selected options are not changed. | |
81 EXPECT_FALSE(opt0->selected()); | |
82 EXPECT_TRUE(opt2->selected()); | |
83 EXPECT_TRUE(opt3->selected()); | |
84 FormControlState selectState = select->saveFormControlState(); | |
85 ASSERT_EQ(4U, selectState.valueSize()); | |
86 | |
87 select->restoreFormControlState(selectState); | |
88 EXPECT_FALSE(opt0->selected()); | |
89 EXPECT_TRUE(opt2->selected()); | |
90 EXPECT_TRUE(opt3->selected()); | |
91 } | |
92 | |
93 } // namespace blink | |
OLD | NEW |