| Index: views/controls/textfield/native_textfield_views_unittest.cc
|
| diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
|
| index b571ed39e3bbb02d90d09b58e7fa87f9aca61cc2..eb060ff24052329d02bf1d42842b188c5dbe2202 100644
|
| --- a/views/controls/textfield/native_textfield_views_unittest.cc
|
| +++ b/views/controls/textfield/native_textfield_views_unittest.cc
|
| @@ -10,6 +10,7 @@
|
| #include "views/controls/textfield/textfield.h"
|
| #include "views/controls/textfield/textfield_views_model.h"
|
| #include "views/event.h"
|
| +#include "views/focus/focus_manager.h"
|
| #include "views/widget/widget.h"
|
|
|
| namespace views {
|
| @@ -55,6 +56,10 @@ class NativeTextfieldViewsTest : public ::testing::Test,
|
| }
|
|
|
| void InitTextfield(Textfield::StyleFlags style) {
|
| + InitTextfield(style, 1);
|
| + }
|
| +
|
| + void InitTextfield(Textfield::StyleFlags style, int count) {
|
| ASSERT_FALSE(textfield_);
|
| textfield_ = new Textfield(style);
|
| textfield_->SetController(this);
|
| @@ -64,13 +69,25 @@ class NativeTextfieldViewsTest : public ::testing::Test,
|
| Widget::DeleteOnDestroy,
|
| Widget::DontMirrorOriginInRTL);
|
| widget_->Init(NULL, gfx::Rect());
|
| - widget_->SetContentsView(textfield_);
|
| +
|
| + View* container = new View();
|
| + widget_->SetContentsView(container);
|
| + container->AddChildView(textfield_);
|
| textfield_view_
|
| = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper());
|
| + textfield_->SetID(1);
|
| +
|
| + for (int i = 1; i < count; i++) {
|
| + Textfield* textfield = new Textfield(style);
|
| + container->AddChildView(textfield);
|
| + textfield->SetID(i + 1);
|
| + }
|
| +
|
| DCHECK(textfield_view_);
|
| model_ = textfield_view_->model_.get();
|
| }
|
|
|
| + protected:
|
| bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code,
|
| bool shift,
|
| bool control,
|
| @@ -92,7 +109,10 @@ class NativeTextfieldViewsTest : public ::testing::Test,
|
| return SendKeyEventToTextfieldViews(key_code, false, false);
|
| }
|
|
|
| - protected:
|
| + View* GetFocusedView() {
|
| + return widget_->GetFocusManager()->GetFocusedView();
|
| + }
|
| +
|
| // We need widget to populate wrapper class.
|
| Widget* widget_;
|
|
|
| @@ -240,7 +260,7 @@ TEST_F(NativeTextfieldViewsTest, PasswordTest) {
|
| EXPECT_STR_EQ("my password", last_contents_);
|
| }
|
|
|
| -TEST_F(NativeTextfieldViewsTest, TestOnKeyPressReturnValue) {
|
| +TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) {
|
| InitTextfield(Textfield::STYLE_DEFAULT);
|
| EXPECT_TRUE(SendKeyEventToTextfieldViews(app::VKEY_A));
|
| // F24, up/down key won't be handled.
|
| @@ -299,4 +319,20 @@ TEST_F(NativeTextfieldViewsTest, CursorMovement) {
|
| EXPECT_STR_EQ("one two", last_contents_);
|
| }
|
|
|
| +TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) {
|
| + InitTextfield(Textfield::STYLE_DEFAULT, 3);
|
| + textfield_->RequestFocus();
|
| +
|
| + EXPECT_EQ(1, GetFocusedView()->GetID());
|
| + widget_->GetFocusManager()->AdvanceFocus(false);
|
| + EXPECT_EQ(2, GetFocusedView()->GetID());
|
| + widget_->GetFocusManager()->AdvanceFocus(false);
|
| + EXPECT_EQ(3, GetFocusedView()->GetID());
|
| +
|
| + widget_->GetFocusManager()->AdvanceFocus(true);
|
| + EXPECT_EQ(2, GetFocusedView()->GetID());
|
| + widget_->GetFocusManager()->AdvanceFocus(true);
|
| + EXPECT_EQ(1, GetFocusedView()->GetID());
|
| +}
|
| +
|
| } // namespace views
|
|
|