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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
186 input_method_->OnFocus(); | 186 input_method_->OnFocus(); |
187 | 187 |
188 textfield_->RequestFocus(); | 188 textfield_->RequestFocus(); |
189 } | 189 } |
190 | 190 |
191 views::Menu2* GetContextMenu() { | 191 ui::MenuModel* GetContextMenuModel() { |
192 textfield_view_->InitContextMenuIfRequired(); | 192 textfield_view_->UpdateContextMenu(); |
193 return textfield_view_->context_menu_menu_.get(); | 193 return textfield_view_->context_menu_contents_.get(); |
194 } | 194 } |
195 | 195 |
196 protected: | 196 protected: |
197 void SendKeyEvent(ui::KeyboardCode key_code, | 197 void SendKeyEvent(ui::KeyboardCode key_code, |
198 bool shift, | 198 bool shift, |
199 bool control, | 199 bool control, |
200 bool capslock) { | 200 bool capslock) { |
201 int flags = (shift ? ui::EF_SHIFT_DOWN : 0) | | 201 int flags = (shift ? ui::EF_SHIFT_DOWN : 0) | |
202 (control ? ui::EF_CONTROL_DOWN : 0) | | 202 (control ? ui::EF_CONTROL_DOWN : 0) | |
203 (capslock ? ui::EF_CAPS_LOCK_DOWN : 0); | 203 (capslock ? ui::EF_CAPS_LOCK_DOWN : 0); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
532 views::ViewsDelegate::views_delegate->GetClipboard()-> | 532 views::ViewsDelegate::views_delegate->GetClipboard()-> |
533 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); | 533 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); |
534 EXPECT_NE(str.empty(), menu_model->IsEnabledAt(2 /* PASTE */)); | 534 EXPECT_NE(str.empty(), menu_model->IsEnabledAt(2 /* PASTE */)); |
535 } | 535 } |
536 | 536 |
537 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { | 537 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { |
538 InitTextfield(Textfield::STYLE_DEFAULT); | 538 InitTextfield(Textfield::STYLE_DEFAULT); |
539 textfield_->SetText(ASCIIToUTF16("hello world")); | 539 textfield_->SetText(ASCIIToUTF16("hello world")); |
540 EXPECT_TRUE(GetContextMenu()); | 540 EXPECT_TRUE(GetContextMenuModel()); |
541 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model()); | 541 VerifyTextfieldContextMenuContents(false, GetContextMenuModel()); |
542 | 542 |
543 textfield_->SelectAll(); | 543 textfield_->SelectAll(); |
544 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model()); | 544 VerifyTextfieldContextMenuContents(true, GetContextMenuModel()); |
545 } | 545 } |
546 | 546 |
547 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { | 547 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { |
548 InitTextfield(Textfield::STYLE_DEFAULT); | 548 InitTextfield(Textfield::STYLE_DEFAULT); |
549 textfield_->SetText(ASCIIToUTF16("hello world")); | 549 textfield_->SetText(ASCIIToUTF16("hello world")); |
550 MouseEvent click(ui::ET_MOUSE_PRESSED, 0, 0, ui::EF_LEFT_BUTTON_DOWN); | 550 MouseEvent click(ui::ET_MOUSE_PRESSED, 0, 0, ui::EF_LEFT_BUTTON_DOWN); |
551 MouseEvent release(ui::ET_MOUSE_RELEASED, 0, 0, ui::EF_LEFT_BUTTON_DOWN); | 551 MouseEvent release(ui::ET_MOUSE_RELEASED, 0, 0, ui::EF_LEFT_BUTTON_DOWN); |
552 MouseEvent double_click(ui::ET_MOUSE_PRESSED, 0, 0, | 552 MouseEvent double_click(ui::ET_MOUSE_PRESSED, 0, 0, |
553 ui::EF_LEFT_BUTTON_DOWN | ui::EF_IS_DOUBLE_CLICK); | 553 ui::EF_LEFT_BUTTON_DOWN | ui::EF_IS_DOUBLE_CLICK); |
554 | 554 |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 EXPECT_STR_EQ("a23", textfield_->text()); | 1077 EXPECT_STR_EQ("a23", textfield_->text()); |
1078 SendKeyEvent(ui::VKEY_B); | 1078 SendKeyEvent(ui::VKEY_B); |
1079 EXPECT_STR_EQ("ab3", textfield_->text()); | 1079 EXPECT_STR_EQ("ab3", textfield_->text()); |
1080 SendKeyEvent(ui::VKEY_Z, false, true); | 1080 SendKeyEvent(ui::VKEY_Z, false, true); |
1081 EXPECT_STR_EQ("123", textfield_->text()); | 1081 EXPECT_STR_EQ("123", textfield_->text()); |
1082 SendKeyEvent(ui::VKEY_Y, false, true); | 1082 SendKeyEvent(ui::VKEY_Y, false, true); |
1083 EXPECT_STR_EQ("ab3", textfield_->text()); | 1083 EXPECT_STR_EQ("ab3", textfield_->text()); |
1084 } | 1084 } |
1085 | 1085 |
1086 } // namespace views | 1086 } // namespace views |
OLD | NEW |