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

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: code style fixes 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
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('k') | views/test/test_views_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/message_loop.h"
6 #include "base/scoped_ptr.h"
5 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/base/clipboard/clipboard.h"
10 #include "ui/base/clipboard/scoped_clipboard_writer.h"
7 #include "views/controls/textfield/textfield_views_model.h" 11 #include "views/controls/textfield/textfield_views_model.h"
12 #include "views/test/test_views_delegate.h"
13 #include "views/views_delegate.h"
8 14
9 namespace views { 15 namespace views {
10 16
11 #define EXPECT_STR_EQ(ascii, utf16) \ 17 #define EXPECT_STR_EQ(ascii, utf16) \
12 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) 18 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16))
13 19
14 TEST(TextfieldViewsModelTest, EditString) { 20 TEST(TextfieldViewsModelTest, EditString) {
15 TextfieldViewsModel model; 21 TextfieldViewsModel model;
16 // append two strings 22 // append two strings
17 model.Append(ASCIIToUTF16("HILL")); 23 model.Append(ASCIIToUTF16("HILL"));
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 model.MoveCursorToEnd(false); 281 model.MoveCursorToEnd(false);
276 EXPECT_EQ(7U, model.cursor_pos()); 282 EXPECT_EQ(7U, model.cursor_pos());
277 283
278 model.SetText(ASCIIToUTF16("BYE")); 284 model.SetText(ASCIIToUTF16("BYE"));
279 EXPECT_EQ(3U, model.cursor_pos()); 285 EXPECT_EQ(3U, model.cursor_pos());
280 EXPECT_EQ(string16(), model.GetSelectedText()); 286 EXPECT_EQ(string16(), model.GetSelectedText());
281 model.SetText(ASCIIToUTF16("")); 287 model.SetText(ASCIIToUTF16(""));
282 EXPECT_EQ(0U, model.cursor_pos()); 288 EXPECT_EQ(0U, model.cursor_pos());
283 } 289 }
284 290
291 TEST(TextfieldViewsModelTest, Clipboard) {
292 views::ViewsDelegate::views_delegate = new TestViewsDelegate();
293 ui::Clipboard* clipboard
294 = views::ViewsDelegate::views_delegate->GetClipboard();
295 string16 initial_clipboard_text;
296 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &initial_clipboard_text);
297 string16 clipboard_text;
298 TextfieldViewsModel model;
299 model.Append(ASCIIToUTF16("HELLO WORLD"));
300 model.MoveCursorToEnd(false);
301
302 // Test for cut: Empty selection.
303 EXPECT_FALSE(model.Cut());
304 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
305 EXPECT_STR_EQ(UTF16ToUTF8(initial_clipboard_text), clipboard_text);
306 EXPECT_STR_EQ("HELLO WORLD", model.text());
307 EXPECT_EQ(11U, model.cursor_pos());
308
309 // Test for cut: Non-empty selection.
310 model.MoveCursorToPreviousWord(true);
311 EXPECT_TRUE(model.Cut());
312 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
313 EXPECT_STR_EQ("WORLD", clipboard_text);
314 EXPECT_STR_EQ("HELLO ", model.text());
315 EXPECT_EQ(6U, model.cursor_pos());
316
317 // Test for copy: Empty selection.
318 model.Copy();
319 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
320 EXPECT_STR_EQ("WORLD", clipboard_text);
321 EXPECT_STR_EQ("HELLO ", model.text());
322 EXPECT_EQ(6U, model.cursor_pos());
323
324 // Test for copy: Non-empty selection.
325 model.Append(ASCIIToUTF16("HELLO WORLD"));
326 model.SelectAll();
327 model.Copy();
328 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
329 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
330 EXPECT_STR_EQ("HELLO HELLO WORLD", model.text());
331 EXPECT_EQ(0U, model.cursor_pos());
332
333 // Test for paste.
334 model.ClearSelection();
335 model.MoveCursorToEnd(false);
336 model.MoveCursorToPreviousWord(true);
337 EXPECT_TRUE(model.Paste());
338 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
339 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
340 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text());
341 EXPECT_EQ(29U, model.cursor_pos());
342 }
343
285 } // namespace views 344 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('k') | views/test/test_views_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698