| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 textfield_(NULL), | 110 textfield_(NULL), |
| 111 textfield_view_(NULL), | 111 textfield_view_(NULL), |
| 112 model_(NULL), | 112 model_(NULL), |
| 113 input_method_(NULL), | 113 input_method_(NULL), |
| 114 on_before_user_action_(0), | 114 on_before_user_action_(0), |
| 115 on_after_user_action_(0) { | 115 on_after_user_action_(0) { |
| 116 } | 116 } |
| 117 | 117 |
| 118 // ::testing::Test: | 118 // ::testing::Test: |
| 119 virtual void SetUp() { | 119 virtual void SetUp() { |
| 120 ViewsTestBase::SetUp(); |
| 120 Widget::SetPureViews(true); | 121 Widget::SetPureViews(true); |
| 121 } | 122 } |
| 122 | 123 |
| 123 virtual void TearDown() { | 124 virtual void TearDown() { |
| 124 Widget::SetPureViews(false); | |
| 125 if (widget_) | 125 if (widget_) |
| 126 widget_->Close(); | 126 widget_->Close(); |
| 127 Widget::SetPureViews(false); |
| 127 ViewsTestBase::TearDown(); | 128 ViewsTestBase::TearDown(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // TextfieldController: | 131 // TextfieldController: |
| 131 virtual void ContentsChanged(Textfield* sender, | 132 virtual void ContentsChanged(Textfield* sender, |
| 132 const string16& new_contents) { | 133 const string16& new_contents) { |
| 133 ASSERT_NE(last_contents_, new_contents); | 134 ASSERT_NE(last_contents_, new_contents); |
| 134 last_contents_ = new_contents; | 135 last_contents_ = new_contents; |
| 135 } | 136 } |
| 136 | 137 |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 ui::OSExchangeData::DownloadFileInfo download(FilePath(), NULL); | 651 ui::OSExchangeData::DownloadFileInfo download(FilePath(), NULL); |
| 651 bad_data.SetDownloadFileInfo(download); | 652 bad_data.SetDownloadFileInfo(download); |
| 652 #else | 653 #else |
| 653 // Skip OSExchangeDataProviderWin::SetURL, which also sets CF_TEXT / STRING. | 654 // Skip OSExchangeDataProviderWin::SetURL, which also sets CF_TEXT / STRING. |
| 654 bad_data.SetURL(GURL("x.org"), string16(ASCIIToUTF16("x"))); | 655 bad_data.SetURL(GURL("x.org"), string16(ASCIIToUTF16("x"))); |
| 655 bad_data.SetPickledData(GDK_SELECTION_PRIMARY, Pickle()); | 656 bad_data.SetPickledData(GDK_SELECTION_PRIMARY, Pickle()); |
| 656 #endif | 657 #endif |
| 657 EXPECT_FALSE(textfield_view_->CanDrop(bad_data)); | 658 EXPECT_FALSE(textfield_view_->CanDrop(bad_data)); |
| 658 } | 659 } |
| 659 | 660 |
| 661 #if !defined(TOUCH_UI) |
| 660 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { | 662 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { |
| 661 InitTextfield(Textfield::STYLE_DEFAULT); | 663 InitTextfield(Textfield::STYLE_DEFAULT); |
| 662 textfield_->SetText(ASCIIToUTF16("hello string world")); | 664 textfield_->SetText(ASCIIToUTF16("hello string world")); |
| 663 | 665 |
| 664 // Ensure the textfield will provide selected text for drag data. | 666 // Ensure the textfield will provide selected text for drag data. |
| 665 string16 string; | 667 string16 string; |
| 666 ui::OSExchangeData data; | 668 ui::OSExchangeData data; |
| 667 const ui::Range kStringRange(6, 12); | 669 const ui::Range kStringRange(6, 12); |
| 668 textfield_->SelectRange(kStringRange); | 670 textfield_->SelectRange(kStringRange); |
| 669 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 671 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 // "Cancel" the drag, via move and release over the selection, and OnDragDone. | 823 // "Cancel" the drag, via move and release over the selection, and OnDragDone. |
| 822 MouseEvent drag(ui::ET_MOUSE_DRAGGED, GetCursorPositionX(9), 0, | 824 MouseEvent drag(ui::ET_MOUSE_DRAGGED, GetCursorPositionX(9), 0, |
| 823 ui::EF_LEFT_BUTTON_DOWN); | 825 ui::EF_LEFT_BUTTON_DOWN); |
| 824 MouseEvent release(ui::ET_MOUSE_RELEASED, GetCursorPositionX(9), 0, | 826 MouseEvent release(ui::ET_MOUSE_RELEASED, GetCursorPositionX(9), 0, |
| 825 ui::EF_LEFT_BUTTON_DOWN); | 827 ui::EF_LEFT_BUTTON_DOWN); |
| 826 textfield_view_->OnMouseDragged(drag); | 828 textfield_view_->OnMouseDragged(drag); |
| 827 textfield_view_->OnMouseReleased(release); | 829 textfield_view_->OnMouseReleased(release); |
| 828 textfield_view_->OnDragDone(); | 830 textfield_view_->OnDragDone(); |
| 829 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 831 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
| 830 } | 832 } |
| 833 #endif |
| 831 | 834 |
| 832 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 835 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { |
| 833 InitTextfield(Textfield::STYLE_DEFAULT); | 836 InitTextfield(Textfield::STYLE_DEFAULT); |
| 834 textfield_->SetText(ASCIIToUTF16(" one two three ")); | 837 textfield_->SetText(ASCIIToUTF16(" one two three ")); |
| 835 textfield_->SetReadOnly(true); | 838 textfield_->SetReadOnly(true); |
| 836 SendKeyEvent(ui::VKEY_HOME); | 839 SendKeyEvent(ui::VKEY_HOME); |
| 837 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 840 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 838 | 841 |
| 839 SendKeyEvent(ui::VKEY_END); | 842 SendKeyEvent(ui::VKEY_END); |
| 840 EXPECT_EQ(15U, textfield_->GetCursorPosition()); | 843 EXPECT_EQ(15U, textfield_->GetCursorPosition()); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 EXPECT_STR_EQ("a23", textfield_->text()); | 1081 EXPECT_STR_EQ("a23", textfield_->text()); |
| 1079 SendKeyEvent(ui::VKEY_B); | 1082 SendKeyEvent(ui::VKEY_B); |
| 1080 EXPECT_STR_EQ("ab3", textfield_->text()); | 1083 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1081 SendKeyEvent(ui::VKEY_Z, false, true); | 1084 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1082 EXPECT_STR_EQ("123", textfield_->text()); | 1085 EXPECT_STR_EQ("123", textfield_->text()); |
| 1083 SendKeyEvent(ui::VKEY_Y, false, true); | 1086 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1084 EXPECT_STR_EQ("ab3", textfield_->text()); | 1087 EXPECT_STR_EQ("ab3", textfield_->text()); |
| 1085 } | 1088 } |
| 1086 | 1089 |
| 1087 } // namespace views | 1090 } // namespace views |
| OLD | NEW |