OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/keyboard_codes.h" | 5 #include "app/keyboard_codes.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/base/clipboard/clipboard.h" | |
10 #include "views/controls/menu/menu_2.h" | |
9 #include "views/controls/textfield/native_textfield_views.h" | 11 #include "views/controls/textfield/native_textfield_views.h" |
10 #include "views/controls/textfield/textfield.h" | 12 #include "views/controls/textfield/textfield.h" |
11 #include "views/controls/textfield/textfield_views_model.h" | 13 #include "views/controls/textfield/textfield_views_model.h" |
12 #include "views/event.h" | 14 #include "views/event.h" |
13 #include "views/focus/focus_manager.h" | 15 #include "views/focus/focus_manager.h" |
16 #include "views/test/test_views_delegate.h" | |
14 #include "views/widget/widget.h" | 17 #include "views/widget/widget.h" |
18 #include "views/views_delegate.h" | |
19 | |
20 #if !defined(OS_WIN) | |
21 #if defined(TOUCH_UI) | |
22 #include "views/controls/menu/native_menu_x.h" | |
23 #else | |
24 #include "views/controls/menu/native_menu_gtk.h" | |
25 #endif | |
26 #endif | |
15 | 27 |
16 namespace views { | 28 namespace views { |
17 | 29 |
18 #define EXPECT_STR_EQ(ascii, utf16) \ | 30 #define EXPECT_STR_EQ(ascii, utf16) \ |
19 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 31 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
20 | 32 |
21 // TODO(oshima): Move tests that are independent of TextfieldViews to | 33 // TODO(oshima): Move tests that are independent of TextfieldViews to |
22 // textfield_unittests.cc once we move the test utility functions | 34 // textfield_unittests.cc once we move the test utility functions |
23 // from chrome/browser/automation/ to app/test/. | 35 // from chrome/browser/automation/ to app/test/. |
24 class NativeTextfieldViewsTest : public ::testing::Test, | 36 class NativeTextfieldViewsTest : public ::testing::Test, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 for (int i = 1; i < count; i++) { | 93 for (int i = 1; i < count; i++) { |
82 Textfield* textfield = new Textfield(style); | 94 Textfield* textfield = new Textfield(style); |
83 container->AddChildView(textfield); | 95 container->AddChildView(textfield); |
84 textfield->SetID(i + 1); | 96 textfield->SetID(i + 1); |
85 } | 97 } |
86 | 98 |
87 DCHECK(textfield_view_); | 99 DCHECK(textfield_view_); |
88 model_ = textfield_view_->model_.get(); | 100 model_ = textfield_view_->model_.get(); |
89 } | 101 } |
90 | 102 |
103 views::Menu2* GetContextMenu() { | |
104 if (!textfield_view_->context_menu_menu_.get()) | |
105 textfield_view_->CreateContextMenu(); | |
106 return textfield_view_->context_menu_menu_.get(); | |
107 } | |
108 | |
91 protected: | 109 protected: |
92 bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code, | 110 bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code, |
93 bool shift, | 111 bool shift, |
94 bool control, | 112 bool control, |
95 bool capslock) { | 113 bool capslock) { |
96 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | | 114 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | |
97 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | | 115 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | |
98 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); | 116 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); |
99 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); | 117 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); |
100 return textfield_->OnKeyPressed(event); | 118 return textfield_->OnKeyPressed(event); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 EXPECT_EQ(1, GetFocusedView()->GetID()); | 391 EXPECT_EQ(1, GetFocusedView()->GetID()); |
374 // Cycle back to the last textfield. | 392 // Cycle back to the last textfield. |
375 widget_->GetFocusManager()->AdvanceFocus(true); | 393 widget_->GetFocusManager()->AdvanceFocus(true); |
376 EXPECT_EQ(3, GetFocusedView()->GetID()); | 394 EXPECT_EQ(3, GetFocusedView()->GetID()); |
377 | 395 |
378 // Request focus should still work. | 396 // Request focus should still work. |
379 textfield_->RequestFocus(); | 397 textfield_->RequestFocus(); |
380 EXPECT_EQ(1, GetFocusedView()->GetID()); | 398 EXPECT_EQ(1, GetFocusedView()->GetID()); |
381 } | 399 } |
382 | 400 |
401 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | |
402 menus::MenuModel* menu_model) { | |
403 EXPECT_TRUE(menu_model->IsEnabledAt(4 /* Separator */)); | |
404 EXPECT_TRUE(menu_model->IsEnabledAt(5 /* SELECT ALL */)); | |
405 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(0 /* CUT */)); | |
406 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(1 /* COPY */)); | |
407 EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(3 /* DELETE */)); | |
408 string16 str; | |
409 views::ViewsDelegate::views_delegate->GetClipboard() | |
410 ->ReadText(ui::Clipboard::BUFFER_STANDARD, &str); | |
411 EXPECT_NE(str.empty(), menu_model->IsEnabledAt(2 /* PASTE */)); | |
412 } | |
413 | |
414 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { | |
415 views::ViewsDelegate::views_delegate = new TestViewsDelegate(); | |
oshima
2011/01/12 18:46:25
don't you have to delete this?
tfarina
2011/01/12 19:19:19
It seems, refer to this CL for a fix?
http://coder
varunjain
2011/01/12 19:59:05
Fixed... I cannot believe I did this again (especi
| |
416 InitTextfield(Textfield::STYLE_DEFAULT); | |
417 textfield_->SetText(ASCIIToUTF16("hello world")); | |
418 EXPECT_TRUE(GetContextMenu()); | |
419 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model()); | |
420 | |
421 textfield_->SelectAll(); | |
422 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model()); | |
423 } | |
424 | |
425 #if !defined(OS_WIN) | |
426 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { | |
oshima
2011/01/12 18:46:25
why do we need this here?
varunjain
2011/01/12 19:59:05
for touchui=1 && chromeos=1, we do not get an impl
oshima
2011/01/12 21:01:47
That sounds like general issue with touchui&chrome
varunjain
2011/01/12 21:28:11
In the general case, when touchui=1&&chromeos=1, t
| |
427 #if defined(TOUCH_UI) | |
428 return new NativeMenuX(menu); | |
429 #else | |
430 return new NativeMenuGtk(menu); | |
431 #endif | |
432 } | |
433 #endif | |
434 | |
383 } // namespace views | 435 } // namespace views |
OLD | NEW |