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/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" | 9 #include "ui/base/clipboard/clipboard.h" |
10 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 10 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 DCHECK(textfield_view_); | 98 DCHECK(textfield_view_); |
99 model_ = textfield_view_->model_.get(); | 99 model_ = textfield_view_->model_.get(); |
100 } | 100 } |
101 | 101 |
102 views::Menu2* GetContextMenu() { | 102 views::Menu2* GetContextMenu() { |
103 textfield_view_->InitContextMenuIfRequired(); | 103 textfield_view_->InitContextMenuIfRequired(); |
104 return textfield_view_->context_menu_menu_.get(); | 104 return textfield_view_->context_menu_menu_.get(); |
105 } | 105 } |
106 | 106 |
| 107 NativeTextfieldViews::ClickState GetClickState() { |
| 108 return textfield_view_->click_state_; |
| 109 } |
| 110 |
107 protected: | 111 protected: |
108 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, | 112 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, |
109 bool shift, | 113 bool shift, |
110 bool control, | 114 bool control, |
111 bool capslock) { | 115 bool capslock) { |
112 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | | 116 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | |
113 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | | 117 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | |
114 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); | 118 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); |
115 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); | 119 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); |
116 return textfield_->OnKeyPressed(event); | 120 return textfield_->OnKeyPressed(event); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 views::ViewsDelegate::views_delegate = test_views_delegate.get(); | 425 views::ViewsDelegate::views_delegate = test_views_delegate.get(); |
422 InitTextfield(Textfield::STYLE_DEFAULT); | 426 InitTextfield(Textfield::STYLE_DEFAULT); |
423 textfield_->SetText(ASCIIToUTF16("hello world")); | 427 textfield_->SetText(ASCIIToUTF16("hello world")); |
424 EXPECT_TRUE(GetContextMenu()); | 428 EXPECT_TRUE(GetContextMenu()); |
425 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model()); | 429 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model()); |
426 | 430 |
427 textfield_->SelectAll(); | 431 textfield_->SelectAll(); |
428 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model()); | 432 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model()); |
429 } | 433 } |
430 | 434 |
| 435 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { |
| 436 InitTextfield(Textfield::STYLE_DEFAULT); |
| 437 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 438 MouseEvent me(MouseEvent::ET_MOUSE_PRESSED, 0, 0, Event::EF_LEFT_BUTTON_DOWN); |
| 439 EXPECT_EQ(NativeTextfieldViews::NONE, GetClickState()); |
| 440 |
| 441 // Test for double click. |
| 442 textfield_view_->OnMousePressed(me); |
| 443 EXPECT_STR_EQ("", textfield_->GetSelectedText()); |
| 444 EXPECT_EQ(NativeTextfieldViews::TRACKING_DOUBLE_CLICK, GetClickState()); |
| 445 textfield_view_->OnMousePressed(me); |
| 446 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 447 EXPECT_EQ(NativeTextfieldViews::TRACKING_TRIPLE_CLICK, GetClickState()); |
| 448 |
| 449 // Test for triple click. |
| 450 textfield_view_->OnMousePressed(me); |
| 451 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); |
| 452 EXPECT_EQ(NativeTextfieldViews::NONE, GetClickState()); |
| 453 |
| 454 // Another click should reset back to single click. |
| 455 textfield_view_->OnMousePressed(me); |
| 456 EXPECT_STR_EQ("", textfield_->GetSelectedText()); |
| 457 EXPECT_EQ(NativeTextfieldViews::TRACKING_DOUBLE_CLICK, GetClickState()); |
| 458 } |
| 459 |
431 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 460 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { |
432 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate()); | 461 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate()); |
433 AutoReset<views::ViewsDelegate*> auto_reset( | 462 AutoReset<views::ViewsDelegate*> auto_reset( |
434 &views::ViewsDelegate::views_delegate, test_views_delegate.get()); | 463 &views::ViewsDelegate::views_delegate, test_views_delegate.get()); |
435 | 464 |
436 InitTextfield(Textfield::STYLE_DEFAULT); | 465 InitTextfield(Textfield::STYLE_DEFAULT); |
437 textfield_->SetText(ASCIIToUTF16(" one two three ")); | 466 textfield_->SetText(ASCIIToUTF16(" one two three ")); |
438 textfield_->SetReadOnly(true); | 467 textfield_->SetReadOnly(true); |
439 SendKeyEventToTextfieldViews(ui::VKEY_HOME); | 468 SendKeyEventToTextfieldViews(ui::VKEY_HOME); |
440 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 469 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // Text field is unmodifiable and selection shouldn't change. | 512 // Text field is unmodifiable and selection shouldn't change. |
484 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); | 513 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); |
485 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 514 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
486 SendKeyEventToTextfieldViews(ui::VKEY_BACK); | 515 SendKeyEventToTextfieldViews(ui::VKEY_BACK); |
487 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 516 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
488 SendKeyEventToTextfieldViews(ui::VKEY_T); | 517 SendKeyEventToTextfieldViews(ui::VKEY_T); |
489 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 518 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
490 } | 519 } |
491 | 520 |
492 } // namespace views | 521 } // namespace views |
OLD | NEW |