OLD | NEW |
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 <vector> |
| 6 |
5 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
6 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
8 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
11 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
12 #include "ui/base/range/range.h" | 14 #include "ui/base/range/range.h" |
13 #include "ui/gfx/render_text.h" | 15 #include "ui/gfx/render_text.h" |
14 #include "views/controls/textfield/textfield.h" | 16 #include "views/controls/textfield/textfield.h" |
15 #include "views/controls/textfield/textfield_views_model.h" | 17 #include "views/controls/textfield/textfield_views_model.h" |
16 #include "views/test/test_views_delegate.h" | 18 #include "views/test/test_views_delegate.h" |
17 #include "views/test/views_test_base.h" | 19 #include "views/test/views_test_base.h" |
18 #include "views/views_delegate.h" | 20 #include "views/views_delegate.h" |
19 | 21 |
| 22 namespace { |
| 23 |
| 24 struct WordAndCursor { |
| 25 WordAndCursor(const wchar_t* w, size_t c) |
| 26 : word(w), |
| 27 cursor(c) { |
| 28 } |
| 29 |
| 30 const wchar_t* word; |
| 31 size_t cursor; |
| 32 }; |
| 33 |
| 34 } // namespace |
| 35 |
20 namespace views { | 36 namespace views { |
21 | 37 |
22 class TextfieldViewsModelTest : public ViewsTestBase, | 38 class TextfieldViewsModelTest : public ViewsTestBase, |
23 public TextfieldViewsModel::Delegate { | 39 public TextfieldViewsModel::Delegate { |
24 public: | 40 public: |
25 TextfieldViewsModelTest() | 41 TextfieldViewsModelTest() |
26 : ViewsTestBase(), | 42 : ViewsTestBase(), |
27 composition_text_confirmed_or_cleared_(false) { | 43 composition_text_confirmed_or_cleared_(false) { |
28 } | 44 } |
29 | 45 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 model.MoveCursorLeft(gfx::LINE_BREAK, false); | 92 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
77 EXPECT_FALSE(model.Backspace()); | 93 EXPECT_FALSE(model.Backspace()); |
78 EXPECT_STR_EQ("HELLORLD", model.GetText()); | 94 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
79 // Move the cursor to the end. delete should fail. | 95 // Move the cursor to the end. delete should fail. |
80 model.MoveCursorRight(gfx::LINE_BREAK, false); | 96 model.MoveCursorRight(gfx::LINE_BREAK, false); |
81 EXPECT_FALSE(model.Delete()); | 97 EXPECT_FALSE(model.Delete()); |
82 EXPECT_STR_EQ("HELLORLD", model.GetText()); | 98 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
83 // but backspace should work. | 99 // but backspace should work. |
84 EXPECT_TRUE(model.Backspace()); | 100 EXPECT_TRUE(model.Backspace()); |
85 EXPECT_STR_EQ("HELLORL", model.GetText()); | 101 EXPECT_STR_EQ("HELLORL", model.GetText()); |
| 102 |
| 103 model.MoveCursorTo(gfx::SelectionModel(5)); |
| 104 model.ReplaceText(ASCIIToUTF16(" WOR")); |
| 105 EXPECT_STR_EQ("HELLO WORL", model.GetText()); |
| 106 } |
| 107 |
| 108 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { |
| 109 TextfieldViewsModel model(NULL); |
| 110 // Append two strings. |
| 111 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); |
| 112 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText()); |
| 113 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); |
| 114 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), |
| 115 model.GetText()); |
| 116 |
| 117 // Insert 0x05f0. |
| 118 model.MoveCursorTo(gfx::SelectionModel(1U)); |
| 119 model.InsertChar(0x05f0); |
| 120 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), |
| 121 model.GetText()); |
| 122 |
| 123 // Replace "\x05d1" with "\x05f1". |
| 124 model.ReplaceChar(0x05f1); |
| 125 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), |
| 126 model.GetText()); |
| 127 |
| 128 // Delete and backspace. |
| 129 EXPECT_EQ(3U, model.GetCursorPosition()); |
| 130 EXPECT_TRUE(model.Delete()); |
| 131 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), |
| 132 model.GetText()); |
| 133 EXPECT_TRUE(model.Backspace()); |
| 134 EXPECT_EQ(2U, model.GetCursorPosition()); |
| 135 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText()); |
| 136 } |
| 137 |
| 138 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { |
| 139 TextfieldViewsModel model(NULL); |
| 140 // Append two Hindi strings. |
| 141 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); |
| 142 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), |
| 143 model.GetText()); |
| 144 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); |
| 145 EXPECT_EQ(WideToUTF16( |
| 146 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), |
| 147 model.GetText()); |
| 148 |
| 149 // Check it is not able to place cursor in middle of a grapheme. |
| 150 // TODO(xji): temporarily disable in platform Win since the complex script |
| 151 // characters turned into empty square due to font regression. So, not able |
| 152 // to test 2 characters belong to the same grapheme. |
| 153 #if defined(OS_LINUX) |
| 154 model.MoveCursorTo(gfx::SelectionModel(1U)); |
| 155 EXPECT_EQ(0U, model.GetCursorPosition()); |
| 156 #endif |
| 157 |
| 158 model.MoveCursorTo(gfx::SelectionModel(2U)); |
| 159 EXPECT_EQ(2U, model.GetCursorPosition()); |
| 160 model.InsertChar('a'); |
| 161 EXPECT_EQ(WideToUTF16( |
| 162 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), |
| 163 model.GetText()); |
| 164 |
| 165 // ReplaceChar will replace the whole grapheme. |
| 166 model.ReplaceChar('b'); |
| 167 // TODO(xji): temporarily disable in platform Win since the complex script |
| 168 // characters turned into empty square due to font regression. So, not able |
| 169 // to test 2 characters belong to the same grapheme. |
| 170 #if defined(OS_LINUX) |
| 171 EXPECT_EQ(WideToUTF16( |
| 172 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), |
| 173 model.GetText()); |
| 174 #endif |
| 175 EXPECT_EQ(4U, model.GetCursorPosition()); |
| 176 |
| 177 // Delete should delete the whole grapheme. |
| 178 model.MoveCursorTo(gfx::SelectionModel(0U)); |
| 179 // TODO(xji): temporarily disable in platform Win since the complex script |
| 180 // characters turned into empty square due to font regression. So, not able |
| 181 // to test 2 characters belong to the same grapheme. |
| 182 #if defined(OS_LINUX) |
| 183 EXPECT_TRUE(model.Delete()); |
| 184 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), |
| 185 model.GetText()); |
| 186 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length())); |
| 187 EXPECT_TRUE(model.Backspace()); |
| 188 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), |
| 189 model.GetText()); |
| 190 #endif |
| 191 |
| 192 // Test cursor position and deletion for Hindi Virama. |
| 193 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); |
| 194 model.MoveCursorTo(gfx::SelectionModel(0)); |
| 195 EXPECT_EQ(0U, model.GetCursorPosition()); |
| 196 |
| 197 // TODO(xji): temporarily disable in platform Win since the complex script |
| 198 // characters turned into empty square due to font regression. So, not able |
| 199 // to test 2 characters belong to the same grapheme. |
| 200 #if defined(OS_LINUX) |
| 201 model.MoveCursorTo(gfx::SelectionModel(1)); |
| 202 EXPECT_EQ(0U, model.GetCursorPosition()); |
| 203 #endif |
| 204 |
| 205 model.MoveCursorTo(gfx::SelectionModel(2)); |
| 206 EXPECT_EQ(2U, model.GetCursorPosition()); |
| 207 |
| 208 model.MoveCursorTo(gfx::SelectionModel(3)); |
| 209 EXPECT_EQ(3U, model.GetCursorPosition()); |
| 210 |
| 211 model.MoveCursorTo(gfx::SelectionModel(2)); |
| 212 |
| 213 EXPECT_TRUE(model.Backspace()); |
| 214 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); |
| 215 |
| 216 // Test Delete/Backspace on Hebrew with non-spacing marks. |
| 217 // TODO(xji): temporarily disable in platform Win since the complex script |
| 218 // characters turned into empty square due to font regression. So, not able |
| 219 // to test 2 characters belong to the same grapheme. |
| 220 #if defined(OS_LINUX) |
| 221 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); |
| 222 model.MoveCursorTo(gfx::SelectionModel(0)); |
| 223 EXPECT_TRUE(model.Delete()); |
| 224 EXPECT_TRUE(model.Delete()); |
| 225 EXPECT_TRUE(model.Delete()); |
| 226 EXPECT_TRUE(model.Delete()); |
| 227 EXPECT_EQ(WideToUTF16(L""), model.GetText()); |
| 228 #endif |
| 229 |
| 230 // The first 2 characters are not strong directionality characters. |
| 231 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); |
| 232 #if defined(OS_WIN) |
| 233 model.MoveCursorRight(gfx::LINE_BREAK, false); |
| 234 #else |
| 235 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
| 236 #endif |
| 237 EXPECT_TRUE(model.Backspace()); |
| 238 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), |
| 239 model.GetText()); |
86 } | 240 } |
87 | 241 |
88 TEST_F(TextfieldViewsModelTest, EmptyString) { | 242 TEST_F(TextfieldViewsModelTest, EmptyString) { |
89 TextfieldViewsModel model(NULL); | 243 TextfieldViewsModel model(NULL); |
90 EXPECT_EQ(string16(), model.GetText()); | 244 EXPECT_EQ(string16(), model.GetText()); |
91 EXPECT_EQ(string16(), model.GetSelectedText()); | 245 EXPECT_EQ(string16(), model.GetSelectedText()); |
92 EXPECT_EQ(string16(), model.GetVisibleText()); | 246 EXPECT_EQ(string16(), model.GetVisibleText()); |
93 | 247 |
94 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | 248 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
95 EXPECT_EQ(0U, model.GetCursorPosition()); | 249 EXPECT_EQ(0U, model.GetCursorPosition()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 290 |
137 // Select all and move cursor | 291 // Select all and move cursor |
138 model.SelectAll(); | 292 model.SelectAll(); |
139 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); | 293 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); |
140 EXPECT_EQ(0U, model.GetCursorPosition()); | 294 EXPECT_EQ(0U, model.GetCursorPosition()); |
141 model.SelectAll(); | 295 model.SelectAll(); |
142 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | 296 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
143 EXPECT_EQ(5U, model.GetCursorPosition()); | 297 EXPECT_EQ(5U, model.GetCursorPosition()); |
144 } | 298 } |
145 | 299 |
| 300 TEST_F(TextfieldViewsModelTest, Selection_BidiWithNonSpacingMarks) { |
| 301 // Selection is a logical operation. And it should work with the arrow |
| 302 // keys doing visual movements, while the selection is logical between |
| 303 // the (logical) start and end points. Selection is simply defined as |
| 304 // the portion of text between the logical positions of the start and end |
| 305 // caret positions. |
| 306 TextfieldViewsModel model(NULL); |
| 307 // TODO(xji): temporarily disable in platform Win since the complex script |
| 308 // characters turned into empty square due to font regression. So, not able |
| 309 // to test 2 characters belong to the same grapheme. |
| 310 #if defined(OS_LINUX) |
| 311 model.Append(WideToUTF16( |
| 312 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def")); |
| 313 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
| 314 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
| 315 |
| 316 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 317 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); |
| 318 EXPECT_EQ(3U, model.GetCursorPosition()); |
| 319 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); |
| 320 |
| 321 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 322 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); |
| 323 EXPECT_EQ(7U, model.GetCursorPosition()); |
| 324 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"), |
| 325 model.GetSelectedText()); |
| 326 |
| 327 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 328 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); |
| 329 EXPECT_EQ(3U, model.GetCursorPosition()); |
| 330 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); |
| 331 |
| 332 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 333 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); |
| 334 EXPECT_EQ(10U, model.GetCursorPosition()); |
| 335 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"d"), |
| 336 model.GetSelectedText()); |
| 337 |
| 338 model.ClearSelection(); |
| 339 EXPECT_EQ(string16(), model.GetSelectedText()); |
| 340 model.SelectAll(); |
| 341 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"), |
| 342 model.GetSelectedText()); |
| 343 #endif |
| 344 |
| 345 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is |
| 346 // an RTL character. |
| 347 model.SetText(WideToUTF16(L"a\x05E9"L"b")); |
| 348 model.MoveCursorTo(gfx::SelectionModel(0)); |
| 349 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 350 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); |
| 351 |
| 352 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 353 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); |
| 354 |
| 355 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 356 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); |
| 357 |
| 358 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
| 359 EXPECT_EQ(3U, model.GetCursorPosition()); |
| 360 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
| 361 EXPECT_EQ(WideToUTF16(L"b"), model.GetSelectedText()); |
| 362 |
| 363 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
| 364 EXPECT_EQ(WideToUTF16(L"b"), model.GetSelectedText()); |
| 365 |
| 366 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
| 367 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); |
| 368 |
| 369 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
| 370 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 371 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 372 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
| 373 EXPECT_EQ(WideToUTF16(L"a\x05E9"), model.GetSelectedText()); |
| 374 |
| 375 model.MoveCursorRight(gfx::LINE_BREAK, false); |
| 376 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
| 377 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
| 378 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
| 379 EXPECT_EQ(WideToUTF16(L"\x05E9"L"b"), model.GetSelectedText()); |
| 380 |
| 381 model.ClearSelection(); |
| 382 EXPECT_EQ(string16(), model.GetSelectedText()); |
| 383 model.SelectAll(); |
| 384 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); |
| 385 } |
| 386 |
146 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) { | 387 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) { |
147 TextfieldViewsModel model(NULL); | 388 TextfieldViewsModel model(NULL); |
148 model.Append(ASCIIToUTF16("HELLO")); | 389 model.Append(ASCIIToUTF16("HELLO")); |
149 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | 390 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
150 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | 391 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
151 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); // select "EL" | 392 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); // select "EL" |
152 EXPECT_TRUE(model.Backspace()); | 393 EXPECT_TRUE(model.Backspace()); |
153 EXPECT_STR_EQ("HLO", model.GetText()); | 394 EXPECT_STR_EQ("HLO", model.GetText()); |
154 | 395 |
155 model.Append(ASCIIToUTF16("ILL")); | 396 model.Append(ASCIIToUTF16("ILL")); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 model.MoveCursorRight(gfx::LINE_BREAK, false); | 548 model.MoveCursorRight(gfx::LINE_BREAK, false); |
308 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 549 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
309 EXPECT_TRUE(model.Paste()); | 550 EXPECT_TRUE(model.Paste()); |
310 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 551 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
311 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 552 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
312 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); | 553 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); |
313 EXPECT_EQ(29U, model.GetCursorPosition()); | 554 EXPECT_EQ(29U, model.GetCursorPosition()); |
314 } | 555 } |
315 | 556 |
316 void SelectWordTestVerifier(TextfieldViewsModel &model, | 557 void SelectWordTestVerifier(TextfieldViewsModel &model, |
317 const std::string &expected_selected_string, size_t expected_cursor_pos) { | 558 const string16 &expected_selected_string, size_t expected_cursor_pos) { |
318 EXPECT_STR_EQ(expected_selected_string, model.GetSelectedText()); | 559 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); |
319 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); | 560 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); |
320 } | 561 } |
321 | 562 |
322 TEST_F(TextfieldViewsModelTest, SelectWordTest) { | 563 TEST_F(TextfieldViewsModelTest, SelectWordTest) { |
323 TextfieldViewsModel model(NULL); | 564 TextfieldViewsModel model(NULL); |
324 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); | 565 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); |
325 | 566 |
326 // Test when cursor is at the beginning. | 567 // Test when cursor is at the beginning. |
327 model.MoveCursorLeft(gfx::LINE_BREAK, false); | 568 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
328 model.SelectWord(); | 569 model.SelectWord(); |
329 SelectWordTestVerifier(model, " ", 2U); | 570 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U); |
330 | 571 |
331 // Test when cursor is at the beginning of a word. | 572 // Test when cursor is at the beginning of a word. |
332 gfx::SelectionModel selection(2U); | 573 gfx::SelectionModel selection(2U); |
333 model.MoveCursorTo(selection); | 574 model.MoveCursorTo(selection); |
334 model.SelectWord(); | 575 model.SelectWord(); |
335 SelectWordTestVerifier(model, "HELLO", 7U); | 576 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U); |
336 | 577 |
337 // Test when cursor is at the end of a word. | 578 // Test when cursor is at the end of a word. |
338 selection = gfx::SelectionModel(15U); | 579 selection = gfx::SelectionModel(15U); |
339 model.MoveCursorTo(selection); | 580 model.MoveCursorTo(selection); |
340 model.SelectWord(); | 581 model.SelectWord(); |
341 SelectWordTestVerifier(model, "WO", 15U); | 582 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); |
342 | 583 |
343 // Test when cursor is somewhere in a non-alph-numeric fragment. | 584 // Test when cursor is somewhere in a non-alpha-numeric fragment. |
344 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { | 585 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { |
345 selection = gfx::SelectionModel(cursor_pos); | 586 selection = gfx::SelectionModel(cursor_pos); |
346 model.MoveCursorTo(selection); | 587 model.MoveCursorTo(selection); |
347 model.SelectWord(); | 588 model.SelectWord(); |
348 SelectWordTestVerifier(model, " !! ", 13U); | 589 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U); |
349 } | 590 } |
350 | 591 |
351 // Test when cursor is somewhere in a whitespace fragment. | 592 // Test when cursor is somewhere in a whitespace fragment. |
352 selection = gfx::SelectionModel(17U); | 593 selection = gfx::SelectionModel(17U); |
353 model.MoveCursorTo(selection); | 594 model.MoveCursorTo(selection); |
354 model.SelectWord(); | 595 model.SelectWord(); |
355 SelectWordTestVerifier(model, " ", 20U); | 596 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); |
356 | 597 |
357 // Test when cursor is at the end. | 598 // Test when cursor is at the end. |
358 model.MoveCursorRight(gfx::LINE_BREAK, false); | 599 model.MoveCursorRight(gfx::LINE_BREAK, false); |
359 model.SelectWord(); | 600 model.SelectWord(); |
360 SelectWordTestVerifier(model, " ", 24U); | 601 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U); |
361 } | 602 } |
362 | 603 |
| 604 // TODO(xji): temporarily disable in platform Win since the complex script |
| 605 // characters and Chinese characters are turned into empty square due to font |
| 606 // regression. |
| 607 #if defined(OS_LINUX) |
| 608 TEST_F(TextfieldViewsModelTest, SelectWordTest_MixScripts) { |
| 609 TextfieldViewsModel model(NULL); |
| 610 std::vector<WordAndCursor> word_and_cursor; |
| 611 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); |
| 612 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); |
| 613 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5)); |
| 614 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5)); |
| 615 word_and_cursor.push_back(WordAndCursor(L" ", 3)); |
| 616 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); |
| 617 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9)); |
| 618 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9)); |
| 619 word_and_cursor.push_back(WordAndCursor(L" ", 10)); |
| 620 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12)); |
| 621 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12)); |
| 622 word_and_cursor.push_back(WordAndCursor(L"\x82B1", 13)); |
| 623 word_and_cursor.push_back(WordAndCursor(L"\x5929", 14)); |
| 624 |
| 625 // The text consists of Ascii, Hebrew, Hindi with Virama sign, and Chinese. |
| 626 model.SetText(WideToUTF16(L"a\x05d0 \x05d1\x05d2 \x0915\x094d\x0915 " |
| 627 L"\x4E2D\x56FD\x82B1\x5929")); |
| 628 for (size_t i = 0; i < word_and_cursor.size(); ++i) { |
| 629 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
| 630 for (size_t j = 0; j < i; ++j) |
| 631 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
| 632 model.SelectWord(); |
| 633 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word), |
| 634 word_and_cursor[i].cursor); |
| 635 } |
| 636 } |
| 637 #endif |
| 638 |
363 TEST_F(TextfieldViewsModelTest, RangeTest) { | 639 TEST_F(TextfieldViewsModelTest, RangeTest) { |
364 TextfieldViewsModel model(NULL); | 640 TextfieldViewsModel model(NULL); |
365 model.Append(ASCIIToUTF16("HELLO WORLD")); | 641 model.Append(ASCIIToUTF16("HELLO WORLD")); |
366 model.MoveCursorLeft(gfx::LINE_BREAK, false); | 642 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
367 ui::Range range; | 643 ui::Range range; |
368 model.GetSelectedRange(&range); | 644 model.GetSelectedRange(&range); |
369 EXPECT_TRUE(range.is_empty()); | 645 EXPECT_TRUE(range.is_empty()); |
370 EXPECT_EQ(0U, range.start()); | 646 EXPECT_EQ(0U, range.start()); |
371 EXPECT_EQ(0U, range.end()); | 647 EXPECT_EQ(0U, range.end()); |
372 | 648 |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 EXPECT_TRUE(model.Undo()); | 1411 EXPECT_TRUE(model.Undo()); |
1136 EXPECT_STR_EQ("ABCDE", model.GetText()); | 1412 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1137 EXPECT_TRUE(model.Redo()); | 1413 EXPECT_TRUE(model.Redo()); |
1138 EXPECT_STR_EQ("1234", model.GetText()); | 1414 EXPECT_STR_EQ("1234", model.GetText()); |
1139 EXPECT_FALSE(model.Redo()); | 1415 EXPECT_FALSE(model.Redo()); |
1140 | 1416 |
1141 // TODO(oshima): We need MockInputMethod to test the behavior with IME. | 1417 // TODO(oshima): We need MockInputMethod to test the behavior with IME. |
1142 } | 1418 } |
1143 | 1419 |
1144 } // namespace views | 1420 } // namespace views |
OLD | NEW |