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

Unified Diff: views/controls/textfield/native_textfield_views_unittest.cc

Issue 5988010: focus reverse traversal was not working for TextfieldViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updated comment Created 9 years, 12 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: 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..b081a8857ea52c2e4cfa2fd93cc68cc0fdebf476 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) {
Jay Civelli 2011/01/06 00:55:54 May be it should be named: InitMultipleTextfields?
oshima 2011/01/06 01:31:22 renamed to InitTextfiels (Multiple sounded a bit v
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,
@@ -79,7 +96,7 @@ class NativeTextfieldViewsTest : public ::testing::Test,
(control ? KeyEvent::EF_CONTROL_DOWN : 0) |
(capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0);
KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0);
- return textfield_view_->OnKeyPressed(event);
+ return textfield_->OnKeyPressed(event);
}
bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code,
@@ -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());
Jay Civelli 2011/01/06 00:55:54 May be you could advance focus one more time to ma
oshima 2011/01/06 01:31:22 Thank you for good suggestion. Added a few more ca
+
+ widget_->GetFocusManager()->AdvanceFocus(true);
+ EXPECT_EQ(2, GetFocusedView()->GetID());
+ widget_->GetFocusManager()->AdvanceFocus(true);
+ EXPECT_EQ(1, GetFocusedView()->GetID());
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698