1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/render_text.h"
#include "base/memory/scoped_ptr.h"
#include "base/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gfx {
class RenderTextTest : public testing::Test {
};
TEST_F(RenderTextTest, DefaultStyle) {
// Defaults to empty text with no styles.
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
EXPECT_TRUE(render_text->text().empty());
EXPECT_TRUE(render_text->style_ranges().empty());
// Test that the built-in default style is applied for new text.
render_text->SetText(ASCIIToUTF16("abc"));
EXPECT_EQ(1U, render_text->style_ranges().size());
StyleRange style;
EXPECT_EQ(style.font.GetFontName(),
render_text->style_ranges()[0].font.GetFontName());
EXPECT_EQ(style.foreground, render_text->style_ranges()[0].foreground);
EXPECT_EQ(ui::Range(0, 3), render_text->style_ranges()[0].range);
EXPECT_EQ(style.strike, render_text->style_ranges()[0].strike);
EXPECT_EQ(style.underline, render_text->style_ranges()[0].underline);
// Test that clearing the text also clears the styles.
render_text->SetText(string16());
EXPECT_TRUE(render_text->text().empty());
EXPECT_TRUE(render_text->style_ranges().empty());
}
TEST_F(RenderTextTest, CustomDefaultStyle) {
// Test a custom default style.
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
StyleRange color;
color.foreground = SK_ColorRED;
render_text->set_default_style(color);
render_text->SetText(ASCIIToUTF16("abc"));
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(color.foreground, render_text->style_ranges()[0].foreground);
// Test that the custom default style persists across clearing text.
render_text->SetText(string16());
EXPECT_TRUE(render_text->style_ranges().empty());
render_text->SetText(ASCIIToUTF16("abc"));
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(color.foreground, render_text->style_ranges()[0].foreground);
// Test ApplyDefaultStyle after setting a new default.
StyleRange strike;
strike.strike = true;
render_text->set_default_style(strike);
render_text->ApplyDefaultStyle();
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(true, render_text->style_ranges()[0].strike);
EXPECT_EQ(strike.foreground, render_text->style_ranges()[0].foreground);
}
TEST_F(RenderTextTest, ApplyStyleRange) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
render_text->SetText(ASCIIToUTF16("01234"));
EXPECT_EQ(1U, render_text->style_ranges().size());
// Test ApplyStyleRange (no-op on empty range).
StyleRange empty;
empty.range = ui::Range(1, 1);
render_text->ApplyStyleRange(empty);
EXPECT_EQ(1U, render_text->style_ranges().size());
// Test ApplyStyleRange (no-op on invalid range).
StyleRange invalid;
invalid.range = ui::Range::InvalidRange();
render_text->ApplyStyleRange(invalid);
EXPECT_EQ(1U, render_text->style_ranges().size());
// Apply a style with a range contained by an existing range.
StyleRange underline;
underline.underline = true;
underline.range = ui::Range(2, 3);
render_text->ApplyStyleRange(underline);
EXPECT_EQ(3U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 2), render_text->style_ranges()[0].range);
EXPECT_FALSE(render_text->style_ranges()[0].underline);
EXPECT_EQ(ui::Range(2, 3), render_text->style_ranges()[1].range);
EXPECT_TRUE(render_text->style_ranges()[1].underline);
EXPECT_EQ(ui::Range(3, 5), render_text->style_ranges()[2].range);
EXPECT_FALSE(render_text->style_ranges()[2].underline);
// Apply a style with a range equal to another range.
StyleRange color;
color.foreground = SK_ColorWHITE;
color.range = ui::Range(2, 3);
render_text->ApplyStyleRange(color);
EXPECT_EQ(3U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 2), render_text->style_ranges()[0].range);
EXPECT_NE(SK_ColorWHITE, render_text->style_ranges()[0].foreground);
EXPECT_FALSE(render_text->style_ranges()[0].underline);
EXPECT_EQ(ui::Range(2, 3), render_text->style_ranges()[1].range);
EXPECT_EQ(SK_ColorWHITE, render_text->style_ranges()[1].foreground);
EXPECT_FALSE(render_text->style_ranges()[1].underline);
EXPECT_EQ(ui::Range(3, 5), render_text->style_ranges()[2].range);
EXPECT_NE(SK_ColorWHITE, render_text->style_ranges()[2].foreground);
EXPECT_FALSE(render_text->style_ranges()[2].underline);
// Apply a style with a range containing an existing range.
// This new style also overlaps portions of neighboring ranges.
StyleRange strike;
strike.strike = true;
strike.range = ui::Range(1, 4);
render_text->ApplyStyleRange(strike);
EXPECT_EQ(3U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 1), render_text->style_ranges()[0].range);
EXPECT_FALSE(render_text->style_ranges()[0].strike);
EXPECT_EQ(ui::Range(1, 4), render_text->style_ranges()[1].range);
EXPECT_TRUE(render_text->style_ranges()[1].strike);
EXPECT_EQ(ui::Range(4, 5), render_text->style_ranges()[2].range);
EXPECT_FALSE(render_text->style_ranges()[2].strike);
// Apply a style overlapping all ranges.
StyleRange strike_underline;
strike_underline.strike = true;
strike_underline.underline = true;
strike_underline.range = ui::Range(0, render_text->text().length());
render_text->ApplyStyleRange(strike_underline);
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 5), render_text->style_ranges()[0].range);
EXPECT_TRUE(render_text->style_ranges()[0].underline);
EXPECT_TRUE(render_text->style_ranges()[0].strike);
// Apply the default style.
render_text->ApplyDefaultStyle();
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 5), render_text->style_ranges()[0].range);
EXPECT_FALSE(render_text->style_ranges()[0].underline);
EXPECT_FALSE(render_text->style_ranges()[0].strike);
}
TEST_F(RenderTextTest, StyleRangesAdjust) {
// Test that style ranges adjust to the text size.
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
render_text->SetText(ASCIIToUTF16("abcdef"));
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 6), render_text->style_ranges()[0].range);
// Test that the range is clipped to the length of shorter text.
render_text->SetText(ASCIIToUTF16("abc"));
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 3), render_text->style_ranges()[0].range);
// Test that the last range extends to the length of longer text.
StyleRange strike;
strike.strike = true;
strike.range = ui::Range(2, 3);
render_text->ApplyStyleRange(strike);
render_text->SetText(ASCIIToUTF16("abcdefghi"));
EXPECT_EQ(2U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 2), render_text->style_ranges()[0].range);
EXPECT_EQ(ui::Range(2, 9), render_text->style_ranges()[1].range);
EXPECT_TRUE(render_text->style_ranges()[1].strike);
// Test that ranges are removed if they're outside the range of shorter text.
render_text->SetText(ASCIIToUTF16("ab"));
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 2), render_text->style_ranges()[0].range);
EXPECT_FALSE(render_text->style_ranges()[0].strike);
// Test that previously removed ranges don't return.
render_text->SetText(ASCIIToUTF16("abcdef"));
EXPECT_EQ(1U, render_text->style_ranges().size());
EXPECT_EQ(ui::Range(0, 6), render_text->style_ranges()[0].range);
EXPECT_FALSE(render_text->style_ranges()[0].strike);
}
void RunMoveCursorLeftRightTest(RenderText* render_text,
const std::vector<SelectionModel>& expected,
bool move_right) {
for (int i = 0; i < static_cast<int>(expected.size()); ++i) {
SelectionModel sel = expected[i];
EXPECT_TRUE(render_text->selection_model().Equals(sel));
if (move_right)
render_text->MoveCursorRight(CHARACTER_BREAK, false);
else
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
}
SelectionModel sel = expected[expected.size() - 1];
if (move_right)
render_text->MoveCursorRight(LINE_BREAK, false);
else
render_text->MoveCursorLeft(LINE_BREAK, false);
EXPECT_TRUE(render_text->selection_model().Equals(sel));
}
TEST_F(RenderTextTest, MoveCursorLeftRightInLtr) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
// Pure LTR.
render_text->SetText(ASCIIToUTF16("abc"));
// |expected| saves the expected SelectionModel when moving cursor from left
// to right.
std::vector<SelectionModel> expected;
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
// The last element is to test the clamped line ends.
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
RunMoveCursorLeftRightTest(render_text.get(), expected, true);
expected.clear();
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
RunMoveCursorLeftRightTest(render_text.get(), expected, false);
}
TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtl) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
// LTR-RTL
render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
// The last one is the expected END position.
std::vector<SelectionModel> expected;
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(5, 5, SelectionModel::LEADING));
expected.push_back(SelectionModel(4, 4, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 3, SelectionModel::LEADING));
expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING));
expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING));
RunMoveCursorLeftRightTest(render_text.get(), expected, true);
expected.clear();
expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING));
expected.push_back(SelectionModel(4, 3, SelectionModel::TRAILING));
expected.push_back(SelectionModel(5, 4, SelectionModel::TRAILING));
expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
RunMoveCursorLeftRightTest(render_text.get(), expected, false);
}
TEST_F(RenderTextTest, MoveCursorLeftRightInLtrRtlLtr) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
// LTR-RTL-LTR.
render_text->SetText(WideToUTF16(L"a"L"\x05d1"L"b"));
std::vector<SelectionModel> expected;
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
RunMoveCursorLeftRightTest(render_text.get(), expected, true);
expected.clear();
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
RunMoveCursorLeftRightTest(render_text.get(), expected, false);
}
TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
// Pure RTL.
render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"));
render_text->MoveCursorRight(LINE_BREAK, false);
std::vector<SelectionModel> expected;
#if defined(OS_LINUX)
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
#else
expected.push_back(SelectionModel(3, 0, SelectionModel::LEADING));
#endif
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
#if defined(OS_LINUX)
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
#else
expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
// TODO(xji): expected (0, 2, TRAILING), actual (3, 0, LEADING).
// cursor moves from leftmost to rightmost.
// expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
#endif
RunMoveCursorLeftRightTest(render_text.get(), expected, false);
expected.clear();
#if defined(OS_LINUX)
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
#else
expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
#endif
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
#if defined(OS_LINUX)
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
#else
expected.push_back(SelectionModel(3, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 0, SelectionModel::LEADING));
#endif
RunMoveCursorLeftRightTest(render_text.get(), expected, true);
}
TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
// RTL-LTR
render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc"));
render_text->MoveCursorRight(LINE_BREAK, false);
std::vector<SelectionModel> expected;
#if defined(OS_LINUX)
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(5, 5, SelectionModel::LEADING));
expected.push_back(SelectionModel(4, 4, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 3, SelectionModel::LEADING));
expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING));
expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING));
#else
expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING));
expected.push_back(SelectionModel(5, 5, SelectionModel::LEADING));
expected.push_back(SelectionModel(4, 4, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 3, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
// TODO(xji): expected (0, 2, TRAILING), actual (3, 0, LEADING).
// cursor moves from leftmost to middle.
// expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
#endif
RunMoveCursorLeftRightTest(render_text.get(), expected, false);
expected.clear();
#if defined(OS_LINUX)
expected.push_back(SelectionModel(6, 3, SelectionModel::LEADING));
expected.push_back(SelectionModel(4, 3, SelectionModel::TRAILING));
expected.push_back(SelectionModel(5, 4, SelectionModel::TRAILING));
expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
#else
expected.push_back(SelectionModel(0, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(4, 3, SelectionModel::TRAILING));
expected.push_back(SelectionModel(5, 4, SelectionModel::TRAILING));
expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING));
expected.push_back(SelectionModel(6, 5, SelectionModel::TRAILING));
#endif
RunMoveCursorLeftRightTest(render_text.get(), expected, true);
}
TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
// RTL-LTR-RTL.
render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1"));
render_text->MoveCursorRight(LINE_BREAK, false);
std::vector<SelectionModel> expected;
#if defined(OS_LINUX)
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
#else
expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(1, 1, SelectionModel::LEADING));
expected.push_back(SelectionModel(1, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING));
// TODO(xji): expected (0, 0, TRAILING), actual (2, 1, LEADING).
// cursor moves from leftmost to middle.
// expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING));
#endif
RunMoveCursorLeftRightTest(render_text.get(), expected, false);
expected.clear();
#if defined(OS_LINUX)
expected.push_back(SelectionModel(3, 2, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
#else
expected.push_back(SelectionModel(0, 0, SelectionModel::TRAILING));
expected.push_back(SelectionModel(0, 0, SelectionModel::LEADING));
expected.push_back(SelectionModel(2, 1, SelectionModel::TRAILING));
expected.push_back(SelectionModel(2, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING));
expected.push_back(SelectionModel(3, 2, SelectionModel::LEADING));
#endif
RunMoveCursorLeftRightTest(render_text.get(), expected, true);
}
// TODO(xji): temporarily disable in platform Win since the complex script
// characters turned into empty square due to font regression. So, not able
// to test 2 characters belong to the same grapheme.
#if defined(OS_LINUX)
TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
render_text->SetText(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"));
EXPECT_EQ(0U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(2U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(4U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(5U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(5U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(4U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(2U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(0U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(0U, render_text->GetCursorPosition());
}
#endif
TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
// Left arrow on select ranging (6, 4).
render_text->MoveCursorRight(LINE_BREAK, false);
EXPECT_EQ(6U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(4U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(5U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(6U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, true);
EXPECT_EQ(6U, render_text->GetSelectionStart());
EXPECT_EQ(5U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, true);
EXPECT_EQ(6U, render_text->GetSelectionStart());
EXPECT_EQ(4U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, false);
EXPECT_EQ(6U, render_text->GetCursorPosition());
// Right arrow on select ranging (4, 6).
render_text->MoveCursorLeft(LINE_BREAK, false);
EXPECT_EQ(0U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(1U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(2U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(3U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(5U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(4U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, true);
EXPECT_EQ(4U, render_text->GetSelectionStart());
EXPECT_EQ(5U, render_text->GetCursorPosition());
render_text->MoveCursorLeft(CHARACTER_BREAK, true);
EXPECT_EQ(4U, render_text->GetSelectionStart());
EXPECT_EQ(6U, render_text->GetCursorPosition());
render_text->MoveCursorRight(CHARACTER_BREAK, false);
EXPECT_EQ(4U, render_text->GetCursorPosition());
}
} // namespace gfx
|