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

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

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

Powered by Google App Engine
This is Rietveld 408576698