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/HTMLTextFormControlElement.h" 7 8 #include "core/frame/FrameView.h" 9 #include "core/html/HTMLDocument.h" 10 #include "core/testing/DummyPageHolder.h" 11 #include "wtf/OwnPtr.h" 12 #include <gtest/gtest.h> 13 14 using namespace WebCore; 15 16 namespace { 17 18 class HTMLTextFormControlElementTest : public ::testing::Test { 19 protected: 20 virtual void SetUp() OVERRIDE; 21 22 HTMLTextFormControlElement& textControl() const { return *m_textControl; } 23 24 private: 25 OwnPtr<DummyPageHolder> m_dummyPageHolder; 26 27 RefPtrWillBePersistent<HTMLTextFormControlElement> m_textControl; 28 }; 29 30 void HTMLTextFormControlElementTest::SetUp() 31 { 32 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); 33 HTMLDocument& document = toHTMLDocument(m_dummyPageHolder->document()); 34 document.documentElement()->setInnerHTML("<body><textarea id=textarea></textarea></body>", ASSERT_NO_EXCEPTION); 35 document.view()->updateLayoutAndStyleIfNeededRecursive(); 36 m_textControl = toHTMLTextFormControlElement(document.getElementById("textarea")); 37 m_textControl->focus(); 38 } 39 40 TEST_F(HTMLTextFormControlElementTest, SetSelectionRange) 41 { 42 EXPECT_EQ(0, textControl().selectionStart()); 43 EXPECT_EQ(0, textControl().selectionEnd()); 44 45 textControl().setInnerEditorValue("Hello, text form."); 46 EXPECT_EQ(0, textControl().selectionStart()); 47 EXPECT_EQ(0, textControl().selectionEnd()); 48 49 textControl().setSelectionRange(1, 3); 50 EXPECT_EQ(1, textControl().selectionStart()); 51 EXPECT_EQ(3, textControl().selectionEnd()); 52 } 53 54 } 55