OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 widget_ = new Widget; | 160 widget_ = new Widget; |
161 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 161 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
162 params.bounds = gfx::Rect(100, 100, 100, 100); | 162 params.bounds = gfx::Rect(100, 100, 100, 100); |
163 widget_->Init(params); | 163 widget_->Init(params); |
164 View* container = new View(); | 164 View* container = new View(); |
165 widget_->SetContentsView(container); | 165 widget_->SetContentsView(container); |
166 container->AddChildView(textfield_); | 166 container->AddChildView(textfield_); |
167 | 167 |
168 textfield_view_ | 168 textfield_view_ |
169 = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper()); | 169 = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper()); |
170 textfield_->SetID(1); | 170 textfield_->set_id(1); |
171 | 171 |
172 for (int i = 1; i < count; i++) { | 172 for (int i = 1; i < count; i++) { |
173 Textfield* textfield = new Textfield(style); | 173 Textfield* textfield = new Textfield(style); |
174 container->AddChildView(textfield); | 174 container->AddChildView(textfield); |
175 textfield->SetID(i + 1); | 175 textfield->set_id(i + 1); |
176 } | 176 } |
177 | 177 |
178 DCHECK(textfield_view_); | 178 DCHECK(textfield_view_); |
179 model_ = textfield_view_->model_.get(); | 179 model_ = textfield_view_->model_.get(); |
180 model_->ClearEditHistory(); | 180 model_->ClearEditHistory(); |
181 | 181 |
182 input_method_ = new MockInputMethod(); | 182 input_method_ = new MockInputMethod(); |
183 widget_->native_widget()->ReplaceInputMethod(input_method_); | 183 widget_->native_widget()->ReplaceInputMethod(input_method_); |
184 | 184 |
185 // Assumes the Widget is always focused. | 185 // Assumes the Widget is always focused. |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 SendKeyEvent(ui::VKEY_LEFT, false, true); | 483 SendKeyEvent(ui::VKEY_LEFT, false, true); |
484 SendKeyEvent(ui::VKEY_DELETE); | 484 SendKeyEvent(ui::VKEY_DELETE); |
485 EXPECT_STR_EQ("one two", textfield_->text()); | 485 EXPECT_STR_EQ("one two", textfield_->text()); |
486 EXPECT_STR_EQ("one two", last_contents_); | 486 EXPECT_STR_EQ("one two", last_contents_); |
487 } | 487 } |
488 | 488 |
489 TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) { | 489 TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) { |
490 InitTextfields(Textfield::STYLE_DEFAULT, 3); | 490 InitTextfields(Textfield::STYLE_DEFAULT, 3); |
491 textfield_->RequestFocus(); | 491 textfield_->RequestFocus(); |
492 | 492 |
493 EXPECT_EQ(1, GetFocusedView()->GetID()); | 493 EXPECT_EQ(1, GetFocusedView()->id()); |
494 widget_->GetFocusManager()->AdvanceFocus(false); | 494 widget_->GetFocusManager()->AdvanceFocus(false); |
495 EXPECT_EQ(2, GetFocusedView()->GetID()); | 495 EXPECT_EQ(2, GetFocusedView()->id()); |
496 widget_->GetFocusManager()->AdvanceFocus(false); | 496 widget_->GetFocusManager()->AdvanceFocus(false); |
497 EXPECT_EQ(3, GetFocusedView()->GetID()); | 497 EXPECT_EQ(3, GetFocusedView()->id()); |
498 // Cycle back to the first textfield. | 498 // Cycle back to the first textfield. |
499 widget_->GetFocusManager()->AdvanceFocus(false); | 499 widget_->GetFocusManager()->AdvanceFocus(false); |
500 EXPECT_EQ(1, GetFocusedView()->GetID()); | 500 EXPECT_EQ(1, GetFocusedView()->id()); |
501 | 501 |
502 widget_->GetFocusManager()->AdvanceFocus(true); | 502 widget_->GetFocusManager()->AdvanceFocus(true); |
503 EXPECT_EQ(3, GetFocusedView()->GetID()); | 503 EXPECT_EQ(3, GetFocusedView()->id()); |
504 widget_->GetFocusManager()->AdvanceFocus(true); | 504 widget_->GetFocusManager()->AdvanceFocus(true); |
505 EXPECT_EQ(2, GetFocusedView()->GetID()); | 505 EXPECT_EQ(2, GetFocusedView()->id()); |
506 widget_->GetFocusManager()->AdvanceFocus(true); | 506 widget_->GetFocusManager()->AdvanceFocus(true); |
507 EXPECT_EQ(1, GetFocusedView()->GetID()); | 507 EXPECT_EQ(1, GetFocusedView()->id()); |
508 // Cycle back to the last textfield. | 508 // Cycle back to the last textfield. |
509 widget_->GetFocusManager()->AdvanceFocus(true); | 509 widget_->GetFocusManager()->AdvanceFocus(true); |
510 EXPECT_EQ(3, GetFocusedView()->GetID()); | 510 EXPECT_EQ(3, GetFocusedView()->id()); |
511 | 511 |
512 // Request focus should still work. | 512 // Request focus should still work. |
513 textfield_->RequestFocus(); | 513 textfield_->RequestFocus(); |
514 EXPECT_EQ(1, GetFocusedView()->GetID()); | 514 EXPECT_EQ(1, GetFocusedView()->id()); |
515 | 515 |
516 // Test if clicking on textfield view sets the focus to textfield_. | 516 // Test if clicking on textfield view sets the focus to textfield_. |
517 widget_->GetFocusManager()->AdvanceFocus(true); | 517 widget_->GetFocusManager()->AdvanceFocus(true); |
518 EXPECT_EQ(3, GetFocusedView()->GetID()); | 518 EXPECT_EQ(3, GetFocusedView()->id()); |
519 MouseEvent click(ui::ET_MOUSE_PRESSED, 0, 0, ui::EF_LEFT_BUTTON_DOWN); | 519 MouseEvent click(ui::ET_MOUSE_PRESSED, 0, 0, ui::EF_LEFT_BUTTON_DOWN); |
520 textfield_view_->OnMousePressed(click); | 520 textfield_view_->OnMousePressed(click); |
521 EXPECT_EQ(1, GetFocusedView()->GetID()); | 521 EXPECT_EQ(1, GetFocusedView()->id()); |
522 } | 522 } |
523 | 523 |
524 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 524 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
525 ui::MenuModel* menu_model) { | 525 ui::MenuModel* menu_model) { |
526 EXPECT_TRUE(menu_model->IsEnabledAt(4 /* Separator */)); | 526 EXPECT_TRUE(menu_model->IsEnabledAt(4 /* Separator */)); |
527 EXPECT_TRUE(menu_model->IsEnabledAt(5 /* SELECT ALL */)); | 527 EXPECT_TRUE(menu_model->IsEnabledAt(5 /* SELECT ALL */)); |
528 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(0 /* CUT */)); | 528 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(0 /* CUT */)); |
529 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(1 /* COPY */)); | 529 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(1 /* COPY */)); |
530 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(3 /* DELETE */)); | 530 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(3 /* DELETE */)); |
531 string16 str; | 531 string16 str; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 EXPECT_STR_EQ("a23", textfield_->text()); | 1074 EXPECT_STR_EQ("a23", textfield_->text()); |
1075 SendKeyEvent(ui::VKEY_B); | 1075 SendKeyEvent(ui::VKEY_B); |
1076 EXPECT_STR_EQ("ab3", textfield_->text()); | 1076 EXPECT_STR_EQ("ab3", textfield_->text()); |
1077 SendKeyEvent(ui::VKEY_Z, false, true); | 1077 SendKeyEvent(ui::VKEY_Z, false, true); |
1078 EXPECT_STR_EQ("123", textfield_->text()); | 1078 EXPECT_STR_EQ("123", textfield_->text()); |
1079 SendKeyEvent(ui::VKEY_Y, false, true); | 1079 SendKeyEvent(ui::VKEY_Y, false, true); |
1080 EXPECT_STR_EQ("ab3", textfield_->text()); | 1080 EXPECT_STR_EQ("ab3", textfield_->text()); |
1081 } | 1081 } |
1082 | 1082 |
1083 } // namespace views | 1083 } // namespace views |
OLD | NEW |