Index: views/controls/textfield/textfield_views_model_unittest.cc |
diff --git a/views/controls/textfield/textfield_views_model_unittest.cc b/views/controls/textfield/textfield_views_model_unittest.cc |
index fa09efa745fda63c7676143574b4f0622d282434..72ac6be3bac1ed3e8fee9911f2436ba68d93f5c8 100644 |
--- a/views/controls/textfield/textfield_views_model_unittest.cc |
+++ b/views/controls/textfield/textfield_views_model_unittest.cc |
@@ -2,12 +2,39 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "app/clipboard/clipboard.h" |
+#include "base/message_loop.h" |
+#include "base/scoped_ptr.h" |
#include "base/utf_string_conversions.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "views/controls/textfield/textfield_views_model.h" |
+#include "views/views_delegate.h" |
namespace views { |
+class SimpleViewsDelegate : public views::ViewsDelegate { |
+ public: |
+ SimpleViewsDelegate() { clipboard_.reset(new Clipboard()); } |
+ virtual Clipboard* GetClipboard() const { return clipboard_.get(); } |
+ virtual void SaveWindowPlacement(const std::wstring& window_name, |
+ const gfx::Rect& bounds, bool maximized) {} |
+ virtual bool GetSavedWindowBounds(const std::wstring& window_name, |
+ gfx::Rect* bounds) const { return false; } |
+ virtual bool GetSavedMaximizedState(const std::wstring& window_name, |
+ bool* maximized) const { return false; } |
+ virtual void NotifyAccessibilityEvent( |
+ views::View* view, AccessibilityTypes::Event event_type) {} |
+#if defined(OS_WIN) |
+ virtual HICON GetDefaultWindowIcon() const { return 0; } |
+#endif |
+ virtual void AddRef() {} |
+ virtual void ReleaseRef() { MessageLoopForUI::current()->Quit(); } |
+ |
+ private: |
+ scoped_ptr<Clipboard> clipboard_; |
+ DISALLOW_COPY_AND_ASSIGN(SimpleViewsDelegate); |
+}; |
oshima
2011/01/04 22:36:49
Looks like there are several ViewsDelegate impl fo
varunjain
2011/01/05 16:19:31
Done.
|
+ |
#define EXPECT_STR_EQ(ascii, utf16) \ |
EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
@@ -282,4 +309,40 @@ TEST(TextfieldViewsModelTest, SetText) { |
EXPECT_EQ(0U, model.cursor_pos()); |
} |
+TEST(TextfieldViewsModelTest, Clipboard) { |
+ views::ViewsDelegate::views_delegate = new SimpleViewsDelegate(); |
+ Clipboard* clipboard = views::ViewsDelegate::views_delegate->GetClipboard(); |
+ string16 clipboard_text; |
+ TextfieldViewsModel model; |
+ |
+ // Test for cut. |
+ model.Append(ASCIIToUTF16("HELLO WORLD")); |
+ model.MoveCursorToEnd(false); |
+ model.MoveCursorToPreviousWord(true); |
+ EXPECT_TRUE(model.HandleClipboardEvents(app::VKEY_X)); |
+ clipboard->ReadText(Clipboard::BUFFER_STANDARD, &clipboard_text); |
+ EXPECT_STR_EQ("WORLD", clipboard_text); |
+ EXPECT_STR_EQ("HELLO ", model.text()); |
+ EXPECT_EQ(6U, model.cursor_pos()); |
+ |
+ // Test for copy. |
+ model.Append(ASCIIToUTF16("HELLO WORLD")); |
+ model.SelectAll(); |
+ EXPECT_FALSE(model.HandleClipboardEvents(app::VKEY_C)); |
+ clipboard->ReadText(Clipboard::BUFFER_STANDARD, &clipboard_text); |
+ EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
+ EXPECT_STR_EQ("HELLO HELLO WORLD", model.text()); |
+ EXPECT_EQ(0U, model.cursor_pos()); |
oshima
2011/01/04 22:36:49
can you add test case for cut© with no selecti
varunjain
2011/01/05 16:19:31
Done.
|
+ |
+ // Test for paste. |
+ model.ClearSelection(); |
+ model.MoveCursorToEnd(false); |
+ model.MoveCursorToPreviousWord(true); |
+ EXPECT_TRUE(model.HandleClipboardEvents(app::VKEY_V)); |
+ clipboard->ReadText(Clipboard::BUFFER_STANDARD, &clipboard_text); |
+ EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
+ EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text()); |
+ EXPECT_EQ(29U, model.cursor_pos()); |
+} |
+ |
} // namespace views |