OLD | NEW |
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/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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 model.ClearSelection(); | 341 model.ClearSelection(); |
342 model.MoveCursorToEnd(false); | 342 model.MoveCursorToEnd(false); |
343 model.MoveCursorToPreviousWord(true); | 343 model.MoveCursorToPreviousWord(true); |
344 EXPECT_TRUE(model.Paste()); | 344 EXPECT_TRUE(model.Paste()); |
345 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 345 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
346 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 346 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
347 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text()); | 347 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.text()); |
348 EXPECT_EQ(29U, model.cursor_pos()); | 348 EXPECT_EQ(29U, model.cursor_pos()); |
349 } | 349 } |
350 | 350 |
| 351 void SelectWordTestVerifier(TextfieldViewsModel &model, |
| 352 const std::string &expected_selected_string, size_t expected_cursor_pos) { |
| 353 EXPECT_STR_EQ(expected_selected_string, model.GetSelectedText()); |
| 354 EXPECT_EQ(expected_cursor_pos, model.cursor_pos()); |
| 355 } |
| 356 |
| 357 TEST(TextfieldViewsModelTest, SelectWordTest) { |
| 358 TextfieldViewsModel model; |
| 359 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); |
| 360 |
| 361 // Test when cursor is at the beginning. |
| 362 model.MoveCursorToStart(false); |
| 363 model.SelectWord(); |
| 364 SelectWordTestVerifier(model, " ", 2U); |
| 365 |
| 366 // Test when cursor is at the beginning of a word. |
| 367 model.MoveCursorTo(2U, false); |
| 368 model.SelectWord(); |
| 369 SelectWordTestVerifier(model, "HELLO", 7U); |
| 370 |
| 371 // Test when cursor is at the end of a word. |
| 372 model.MoveCursorTo(15U, false); |
| 373 model.SelectWord(); |
| 374 SelectWordTestVerifier(model, "WO", 15U); |
| 375 |
| 376 // Test when cursor is somewhere in a non-alph-numeric fragment. |
| 377 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { |
| 378 model.MoveCursorTo(cursor_pos, false); |
| 379 model.SelectWord(); |
| 380 SelectWordTestVerifier(model, " !! ", 13U); |
| 381 } |
| 382 |
| 383 // Test when cursor is somewhere in a whitespace fragment. |
| 384 model.MoveCursorTo(17U, false); |
| 385 model.SelectWord(); |
| 386 SelectWordTestVerifier(model, " ", 20U); |
| 387 |
| 388 // Test when cursor is at the end. |
| 389 model.MoveCursorToEnd(false); |
| 390 model.SelectWord(); |
| 391 SelectWordTestVerifier(model, " ", 24U); |
| 392 } |
| 393 |
351 } // namespace views | 394 } // namespace views |
OLD | NEW |