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

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

Issue 6267002: Implement double/triple click functionality in views textfield. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: refactoring 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/event.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) 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/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/clipboard/clipboard.h" 10 #include "ui/base/clipboard/clipboard.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 model.ClearSelection(); 354 model.ClearSelection();
355 model.MoveCursorToEnd(false); 355 model.MoveCursorToEnd(false);
356 model.MoveCursorToPreviousWord(true); 356 model.MoveCursorToPreviousWord(true);
357 EXPECT_TRUE(model.Paste()); 357 EXPECT_TRUE(model.Paste());
358 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 358 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
359 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); 359 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
360 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text()); 360 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text());
361 EXPECT_EQ(29U, model.cursor_pos()); 361 EXPECT_EQ(29U, model.cursor_pos());
362 } 362 }
363 363
364 void SelectWordTestVerifier(TextfieldViewsModel &model,
365 const std::string &expected_selected_string, size_t expected_cursor_pos) {
366 EXPECT_STR_EQ(expected_selected_string, model.GetSelectedText());
367 EXPECT_EQ(expected_cursor_pos, model.cursor_pos());
368 }
369
370 TEST_F(TextfieldViewsModelTest, SelectWordTest) {
371 TextfieldViewsModel model;
372 model.Append(ASCIIToUTF16(" HELLO !! WO RLD "));
373
374 // Test when cursor is at the beginning.
375 model.MoveCursorToStart(false);
376 model.SelectWord();
377 SelectWordTestVerifier(model, " ", 2U);
378
379 // Test when cursor is at the beginning of a word.
380 model.MoveCursorTo(2U, false);
381 model.SelectWord();
382 SelectWordTestVerifier(model, "HELLO", 7U);
383
384 // Test when cursor is at the end of a word.
385 model.MoveCursorTo(15U, false);
386 model.SelectWord();
387 SelectWordTestVerifier(model, "WO", 15U);
388
389 // Test when cursor is somewhere in a non-alph-numeric fragment.
390 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) {
391 model.MoveCursorTo(cursor_pos, false);
392 model.SelectWord();
393 SelectWordTestVerifier(model, " !! ", 13U);
394 }
395
396 // Test when cursor is somewhere in a whitespace fragment.
397 model.MoveCursorTo(17U, false);
398 model.SelectWord();
399 SelectWordTestVerifier(model, " ", 20U);
400
401 // Test when cursor is at the end.
402 model.MoveCursorToEnd(false);
403 model.SelectWord();
404 SelectWordTestVerifier(model, " ", 24U);
405 }
406
364 TEST_F(TextfieldViewsModelTest, RangeTest) { 407 TEST_F(TextfieldViewsModelTest, RangeTest) {
365 TextfieldViewsModel model; 408 TextfieldViewsModel model;
366 model.Append(ASCIIToUTF16("HELLO WORLD")); 409 model.Append(ASCIIToUTF16("HELLO WORLD"));
367 model.MoveCursorToStart(false); 410 model.MoveCursorToStart(false);
368 TextRange range; 411 TextRange range;
369 model.GetSelectedRange(&range); 412 model.GetSelectedRange(&range);
370 EXPECT_TRUE(range.is_empty()); 413 EXPECT_TRUE(range.is_empty());
371 EXPECT_EQ(0U, range.start()); 414 EXPECT_EQ(0U, range.start());
372 EXPECT_EQ(0U, range.end()); 415 EXPECT_EQ(0U, range.end());
373 416
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 model.SelectRange(range); 507 model.SelectRange(range);
465 EXPECT_TRUE(model.GetSelectedText().empty()); 508 EXPECT_TRUE(model.GetSelectedText().empty());
466 509
467 range.SetRange(1000, 1000); 510 range.SetRange(1000, 1000);
468 EXPECT_TRUE(range.is_empty()); 511 EXPECT_TRUE(range.is_empty());
469 model.SelectRange(range); 512 model.SelectRange(range);
470 EXPECT_TRUE(model.GetSelectedText().empty()); 513 EXPECT_TRUE(model.GetSelectedText().empty());
471 } 514 }
472 515
473 } // namespace views 516 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('k') | views/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698