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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLSelectElementTest.cpp
diff --git a/Source/core/html/HTMLSelectElementTest.cpp b/Source/core/html/HTMLSelectElementTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..85728e6cd8f6c67da1ed057a2a59f22a5cb8805e
--- /dev/null
+++ b/Source/core/html/HTMLSelectElementTest.cpp
@@ -0,0 +1,84 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/html/HTMLSelectElement.h"
+
+#include "core/frame/FrameView.h"
+#include "core/html/HTMLDocument.h"
+#include "core/html/forms/FormController.h"
+#include "core/loader/EmptyClients.h"
+#include "core/testing/DummyPageHolder.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+
+class HTMLSelectElementTest : public::testing::Test {
+protected:
+ virtual void SetUp() OVERRIDE;
+ HTMLDocument& document() const { return *m_document; }
+
+private:
+ OwnPtr<DummyPageHolder> m_dummyPageHolder;
+ RefPtrWillBePersistent<HTMLDocument> m_document;
+};
+
+void HTMLSelectElementTest::SetUp()
+{
+ Page::PageClients pageClients;
+ fillWithEmptyClients(pageClients);
+ m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600), &pageClients);
+
+ m_document = toHTMLDocument(&m_dummyPageHolder->document());
+ m_document->setMimeType("text/html");
+ m_document->setCharset("utf-8");
+}
+
+TEST_F(HTMLSelectElementTest, SaveRestoreSelectSingleFormControlState)
+{
+ document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id='sel'>"
+ "<option value='111'>111</option>"
tkent 2014/09/09 02:14:45 Indent continuous lines.
spartha 2014/09/09 11:09:56 Done.
+ "<option value='222'>222</option>"
+ "<option value='111' selected>!666</option>"
+ "<option value='999'>999</option></select>"), ASSERT_NO_EXCEPTION);
+ document().view()->updateLayoutAndStyleIfNeededRecursive();
+ Element* element = document().getElementById("sel");
+ HTMLFormControlElementWithState* select = toHTMLSelectElement(element);
+
+ // Save the select element state, and then restore again.
+ // 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
+ EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex());
+ FormControlState selectState = select->saveFormControlState();
+ select->restoreFormControlState(selectState);
+ EXPECT_EQ(2, toHTMLSelectElement(element)->selectedIndex());
+}
+
+TEST_F(HTMLSelectElementTest, SaveRestoreSelectMultipleFormControlState)
+{
+ document().documentElement()->setInnerHTML(String("<!DOCTYPE HTML><select id='sel' multiple>"
+ "<option value='111' id='0'>111</option>"
+ "<option value='222'>222</option>"
+ "<option value='111' selected id='2'>!666</option>"
+ "<option value='999' selected id='3'>999</option></select>"), ASSERT_NO_EXCEPTION);
+ document().view()->updateLayoutAndStyleIfNeededRecursive();
+ HTMLFormControlElementWithState* select = toHTMLSelectElement(document().getElementById("sel"));
+
+ HTMLOptionElement* opt0 = toHTMLOptionElement(document().getElementById("0"));
+ HTMLOptionElement* opt2 = toHTMLOptionElement(document().getElementById("2"));
+ HTMLOptionElement* opt3 = toHTMLOptionElement(document().getElementById("3"));
+
+ // Save the select element state, and then restore again.
+ // Test passes if the selected options are not changed.
+ EXPECT_FALSE(opt0->selected());
+ EXPECT_TRUE(opt2->selected());
+ EXPECT_TRUE(opt3->selected());
+ FormControlState selectState = select->saveFormControlState();
+
+ select->restoreFormControlState(selectState);
+ EXPECT_FALSE(opt0->selected());
+ EXPECT_TRUE(opt2->selected());
+ EXPECT_TRUE(opt3->selected());
+}
+
+} // namespace blink
« 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