diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 18:22:42 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-15 18:22:42 +0000 |
commit | 95bc3fcd0aefe3db1855baaa4928bd1435a342bf (patch) | |
tree | 992ce2d8be1c533f1097aae4c73507d0f19a62f9 /views/controls/textfield | |
parent | 08a367bf571caef956a817f69020e505574e031f (diff) | |
download | chromium_src-95bc3fcd0aefe3db1855baaa4928bd1435a342bf.zip chromium_src-95bc3fcd0aefe3db1855baaa4928bd1435a342bf.tar.gz chromium_src-95bc3fcd0aefe3db1855baaa4928bd1435a342bf.tar.bz2 |
Fix a cause of flakyness in NativeTextfieldViewsTest.ReadOnlyTest.
Make the test set the clipboard first before testing
that CUT doesn't set the clipboard. Without this, the
test would fail when run a second time due to existing
clipboard contents.
Also, refactor the code to add test helper methods for
getting and setting clipboard text.
BUG=none
TEST=Run NativeTextfieldViewsTest.ReadOnlyTest twice. The second time should not fail.
Review URL: http://codereview.chromium.org/8570002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110118 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/textfield')
-rw-r--r-- | views/controls/textfield/native_textfield_views_unittest.cc | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc index f3a046a..534811e 100644 --- a/views/controls/textfield/native_textfield_views_unittest.cc +++ b/views/controls/textfield/native_textfield_views_unittest.cc @@ -248,6 +248,19 @@ class NativeTextfieldViewsTest : public ViewsTestBase, } } + string16 GetClipboardText() const { + string16 text; + views::ViewsDelegate::views_delegate->GetClipboard()-> + ReadText(ui::Clipboard::BUFFER_STANDARD, &text); + return text; + } + + void SetClipboardText(const std::string& text) { + ui::ScopedClipboardWriter clipboard_writer( + views::ViewsDelegate::views_delegate->GetClipboard()); + clipboard_writer.WriteText(ASCIIToUTF16(text)); + } + View* GetFocusedView() { return widget_->GetFocusManager()->GetFocusedView(); } @@ -302,6 +315,17 @@ class NativeTextfieldViewsTest : public ViewsTestBase, return textfield_view_->GetTextInputType(); } + void VerifyTextfieldContextMenuContents(bool textfield_has_selection, + ui::MenuModel* menu_model) { + EXPECT_TRUE(menu_model->IsEnabledAt(4 /* Separator */)); + EXPECT_TRUE(menu_model->IsEnabledAt(5 /* SELECT ALL */)); + EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(0 /* CUT */)); + EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(1 /* COPY */)); + EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(3 /* DELETE */)); + string16 str(GetClipboardText()); + EXPECT_NE(str.empty(), menu_model->IsEnabledAt(2 /* PASTE */)); + } + // We need widget to populate wrapper class. Widget* widget_; @@ -649,19 +673,6 @@ TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) { EXPECT_EQ(1, GetFocusedView()->id()); } -void VerifyTextfieldContextMenuContents(bool textfield_has_selection, - ui::MenuModel* menu_model) { - EXPECT_TRUE(menu_model->IsEnabledAt(4 /* Separator */)); - EXPECT_TRUE(menu_model->IsEnabledAt(5 /* SELECT ALL */)); - EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(0 /* CUT */)); - EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(1 /* COPY */)); - EXPECT_EQ(textfield_has_selection, menu_model->IsEnabledAt(3 /* DELETE */)); - string16 str; - views::ViewsDelegate::views_delegate->GetClipboard()-> - ReadText(ui::Clipboard::BUFFER_STANDARD, &str); - EXPECT_NE(str.empty(), menu_model->IsEnabledAt(2 /* PASTE */)); -} - TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { InitTextfield(Textfield::STYLE_DEFAULT); textfield_->SetText(ASCIIToUTF16("hello world")); @@ -984,11 +995,10 @@ TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); // CUT&PASTE does not work, but COPY works + SetClipboardText("Test"); SendKeyEvent(ui::VKEY_X, false, true); EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); - string16 str; - views::ViewsDelegate::views_delegate->GetClipboard()-> - ReadText(ui::Clipboard::BUFFER_STANDARD, &str); + string16 str(GetClipboardText()); EXPECT_STR_NE(" one two three ", str); SendKeyEvent(ui::VKEY_C, false, true); |