Chromium Code Reviews| 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 bool IsTrackingTripleClick() { | |
| 108 return textfield_view_->tracking_triple_click_; | |
| 109 } | |
| 110 | |
| 111 bool IsTrackingDoubleClick() { | |
| 112 return textfield_view_->tracking_double_click_; | |
| 113 } | |
| 114 | |
| 107 protected: | 115 protected: |
| 108 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, | 116 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, |
| 109 bool shift, | 117 bool shift, |
| 110 bool control, | 118 bool control, |
| 111 bool capslock) { | 119 bool capslock) { |
| 112 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | | 120 int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) | |
| 113 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | | 121 (control ? KeyEvent::EF_CONTROL_DOWN : 0) | |
| 114 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); | 122 (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0); |
| 115 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); | 123 KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0); |
| 116 return textfield_->OnKeyPressed(event); | 124 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(); | 429 views::ViewsDelegate::views_delegate = test_views_delegate.get(); |
| 422 InitTextfield(Textfield::STYLE_DEFAULT); | 430 InitTextfield(Textfield::STYLE_DEFAULT); |
| 423 textfield_->SetText(ASCIIToUTF16("hello world")); | 431 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 424 EXPECT_TRUE(GetContextMenu()); | 432 EXPECT_TRUE(GetContextMenu()); |
| 425 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model()); | 433 VerifyTextfieldContextMenuContents(false, GetContextMenu()->model()); |
| 426 | 434 |
| 427 textfield_->SelectAll(); | 435 textfield_->SelectAll(); |
| 428 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model()); | 436 VerifyTextfieldContextMenuContents(true, GetContextMenu()->model()); |
| 429 } | 437 } |
| 430 | 438 |
| 439 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { | |
| 440 InitTextfield(Textfield::STYLE_DEFAULT); | |
| 441 textfield_->SetText(ASCIIToUTF16("hello world")); | |
| 442 MouseEvent me(MouseEvent::ET_MOUSE_PRESSED, 0, 0, Event::EF_LEFT_BUTTON_DOWN); | |
| 443 EXPECT_FALSE(IsTrackingDoubleClick()); | |
| 444 EXPECT_FALSE(IsTrackingTripleClick()); | |
| 445 | |
| 446 // Test for double click. | |
| 447 textfield_view_->OnMousePressed(me); | |
| 448 EXPECT_STR_EQ("", textfield_->GetSelectedText()); | |
| 449 EXPECT_TRUE(IsTrackingDoubleClick()); | |
| 450 EXPECT_FALSE(IsTrackingTripleClick()); | |
| 451 textfield_view_->OnMousePressed(me); | |
| 452 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | |
| 453 EXPECT_FALSE(IsTrackingDoubleClick()); | |
| 454 EXPECT_TRUE(IsTrackingTripleClick()); | |
| 455 | |
| 456 // Test for triple click. | |
| 457 textfield_view_->OnMousePressed(me); | |
| 458 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); | |
| 459 EXPECT_FALSE(IsTrackingDoubleClick()); | |
| 460 EXPECT_FALSE(IsTrackingTripleClick()); | |
|
oshima
2011/01/25 19:31:59
We should test one more time to see if it's going
varunjain
2011/01/25 20:10:40
Done.
| |
| 461 } | |
| 462 | |
| 431 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 463 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { |
| 432 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate()); | 464 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate()); |
| 433 AutoReset<views::ViewsDelegate*> auto_reset( | 465 AutoReset<views::ViewsDelegate*> auto_reset( |
| 434 &views::ViewsDelegate::views_delegate, test_views_delegate.get()); | 466 &views::ViewsDelegate::views_delegate, test_views_delegate.get()); |
| 435 | 467 |
| 436 InitTextfield(Textfield::STYLE_DEFAULT); | 468 InitTextfield(Textfield::STYLE_DEFAULT); |
| 437 textfield_->SetText(ASCIIToUTF16(" one two three ")); | 469 textfield_->SetText(ASCIIToUTF16(" one two three ")); |
| 438 textfield_->SetReadOnly(true); | 470 textfield_->SetReadOnly(true); |
| 439 SendKeyEventToTextfieldViews(ui::VKEY_HOME); | 471 SendKeyEventToTextfieldViews(ui::VKEY_HOME); |
| 440 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 472 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. | 515 // Text field is unmodifiable and selection shouldn't change. |
| 484 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); | 516 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); |
| 485 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 517 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 486 SendKeyEventToTextfieldViews(ui::VKEY_BACK); | 518 SendKeyEventToTextfieldViews(ui::VKEY_BACK); |
| 487 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 519 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 488 SendKeyEventToTextfieldViews(ui::VKEY_T); | 520 SendKeyEventToTextfieldViews(ui::VKEY_T); |
| 489 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 521 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 490 } | 522 } |
| 491 | 523 |
| 492 } // namespace views | 524 } // namespace views |
| OLD | NEW |