Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: views/controls/textfield/textfield_views_model_unittest.cc

Issue 6004010: Implement clipboard features in views textfield. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/clipboard/clipboard.h"
6 #include "base/message_loop.h"
7 #include "base/scoped_ptr.h"
5 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
7 #include "views/controls/textfield/textfield_views_model.h" 10 #include "views/controls/textfield/textfield_views_model.h"
11 #include "views/views_delegate.h"
8 12
9 namespace views { 13 namespace views {
10 14
15 class SimpleViewsDelegate : public views::ViewsDelegate {
16 public:
17 SimpleViewsDelegate() { clipboard_.reset(new Clipboard()); }
18 virtual Clipboard* GetClipboard() const { return clipboard_.get(); }
19 virtual void SaveWindowPlacement(const std::wstring& window_name,
20 const gfx::Rect& bounds, bool maximized) {}
21 virtual bool GetSavedWindowBounds(const std::wstring& window_name,
22 gfx::Rect* bounds) const { return false; }
23 virtual bool GetSavedMaximizedState(const std::wstring& window_name,
24 bool* maximized) const { return false; }
25 virtual void NotifyAccessibilityEvent(
26 views::View* view, AccessibilityTypes::Event event_type) {}
27 #if defined(OS_WIN)
28 virtual HICON GetDefaultWindowIcon() const { return 0; }
29 #endif
30 virtual void AddRef() {}
31 virtual void ReleaseRef() { MessageLoopForUI::current()->Quit(); }
32
33 private:
34 scoped_ptr<Clipboard> clipboard_;
35 DISALLOW_COPY_AND_ASSIGN(SimpleViewsDelegate);
36 };
oshima 2011/01/04 22:36:49 Looks like there are several ViewsDelegate impl fo
varunjain 2011/01/05 16:19:31 Done.
37
11 #define EXPECT_STR_EQ(ascii, utf16) \ 38 #define EXPECT_STR_EQ(ascii, utf16) \
12 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) 39 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16))
13 40
14 TEST(TextfieldViewsModelTest, EditString) { 41 TEST(TextfieldViewsModelTest, EditString) {
15 TextfieldViewsModel model; 42 TextfieldViewsModel model;
16 // append two strings 43 // append two strings
17 model.Append(ASCIIToUTF16("HILL")); 44 model.Append(ASCIIToUTF16("HILL"));
18 EXPECT_STR_EQ("HILL", model.text()); 45 EXPECT_STR_EQ("HILL", model.text());
19 model.Append(ASCIIToUTF16("WORLD")); 46 model.Append(ASCIIToUTF16("WORLD"));
20 EXPECT_STR_EQ("HILLWORLD", model.text()); 47 EXPECT_STR_EQ("HILLWORLD", model.text());
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 model.MoveCursorToEnd(false); 302 model.MoveCursorToEnd(false);
276 EXPECT_EQ(7U, model.cursor_pos()); 303 EXPECT_EQ(7U, model.cursor_pos());
277 304
278 model.SetText(ASCIIToUTF16("BYE")); 305 model.SetText(ASCIIToUTF16("BYE"));
279 EXPECT_EQ(3U, model.cursor_pos()); 306 EXPECT_EQ(3U, model.cursor_pos());
280 EXPECT_EQ(string16(), model.GetSelectedText()); 307 EXPECT_EQ(string16(), model.GetSelectedText());
281 model.SetText(ASCIIToUTF16("")); 308 model.SetText(ASCIIToUTF16(""));
282 EXPECT_EQ(0U, model.cursor_pos()); 309 EXPECT_EQ(0U, model.cursor_pos());
283 } 310 }
284 311
312 TEST(TextfieldViewsModelTest, Clipboard) {
313 views::ViewsDelegate::views_delegate = new SimpleViewsDelegate();
314 Clipboard* clipboard = views::ViewsDelegate::views_delegate->GetClipboard();
315 string16 clipboard_text;
316 TextfieldViewsModel model;
317
318 // Test for cut.
319 model.Append(ASCIIToUTF16("HELLO WORLD"));
320 model.MoveCursorToEnd(false);
321 model.MoveCursorToPreviousWord(true);
322 EXPECT_TRUE(model.HandleClipboardEvents(app::VKEY_X));
323 clipboard->ReadText(Clipboard::BUFFER_STANDARD, &clipboard_text);
324 EXPECT_STR_EQ("WORLD", clipboard_text);
325 EXPECT_STR_EQ("HELLO ", model.text());
326 EXPECT_EQ(6U, model.cursor_pos());
327
328 // Test for copy.
329 model.Append(ASCIIToUTF16("HELLO WORLD"));
330 model.SelectAll();
331 EXPECT_FALSE(model.HandleClipboardEvents(app::VKEY_C));
332 clipboard->ReadText(Clipboard::BUFFER_STANDARD, &clipboard_text);
333 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
334 EXPECT_STR_EQ("HELLO HELLO WORLD", model.text());
335 EXPECT_EQ(0U, model.cursor_pos());
oshima 2011/01/04 22:36:49 can you add test case for cut&copy with no selecti
varunjain 2011/01/05 16:19:31 Done.
336
337 // Test for paste.
338 model.ClearSelection();
339 model.MoveCursorToEnd(false);
340 model.MoveCursorToPreviousWord(true);
341 EXPECT_TRUE(model.HandleClipboardEvents(app::VKEY_V));
342 clipboard->ReadText(Clipboard::BUFFER_STANDARD, &clipboard_text);
343 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
344 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text());
345 EXPECT_EQ(29U, model.cursor_pos());
346 }
347
285 } // namespace views 348 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698