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

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

Issue 8575020: Improve RenderTextWin font fallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Disabling more under XP. Created 9 years 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 | « ui/gfx/render_text_win.cc ('k') | no next file » | 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 <vector> 5 #include <vector>
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/clipboard/clipboard.h" 13 #include "ui/base/clipboard/clipboard.h"
14 #include "ui/base/clipboard/scoped_clipboard_writer.h" 14 #include "ui/base/clipboard/scoped_clipboard_writer.h"
15 #include "ui/base/range/range.h" 15 #include "ui/base/range/range.h"
16 #include "ui/gfx/render_text.h" 16 #include "ui/gfx/render_text.h"
17 #include "ui/views/controls/textfield/textfield.h" 17 #include "ui/views/controls/textfield/textfield.h"
18 #include "ui/views/controls/textfield/textfield_views_model.h" 18 #include "ui/views/controls/textfield/textfield_views_model.h"
19 #include "ui/views/test/test_views_delegate.h" 19 #include "ui/views/test/test_views_delegate.h"
20 #include "ui/views/test/views_test_base.h" 20 #include "ui/views/test/views_test_base.h"
21 #include "ui/views/views_delegate.h" 21 #include "ui/views/views_delegate.h"
22 22
23 #if defined(OS_WIN)
24 #include "base/win/windows_version.h"
25 #endif
26
23 namespace { 27 namespace {
24 28
25 struct WordAndCursor { 29 struct WordAndCursor {
26 WordAndCursor(const wchar_t* w, size_t c) 30 WordAndCursor(const wchar_t* w, size_t c)
27 : word(w), 31 : word(w),
28 cursor(c) { 32 cursor(c) {
29 } 33 }
30 34
31 const wchar_t* word; 35 const wchar_t* word;
32 size_t cursor; 36 size_t cursor;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 EXPECT_EQ(3U, model.GetCursorPosition()); 134 EXPECT_EQ(3U, model.GetCursorPosition());
131 EXPECT_TRUE(model.Delete()); 135 EXPECT_TRUE(model.Delete());
132 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), 136 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"),
133 model.GetText()); 137 model.GetText());
134 EXPECT_TRUE(model.Backspace()); 138 EXPECT_TRUE(model.Backspace());
135 EXPECT_EQ(2U, model.GetCursorPosition()); 139 EXPECT_EQ(2U, model.GetCursorPosition());
136 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText()); 140 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText());
137 } 141 }
138 142
139 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { 143 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) {
144 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
145 // font support for some scripts - http://crbug.com/106450
146 bool on_windows_xp = false;
147 #if defined(OS_WIN)
148 on_windows_xp = base::win::GetVersion() < base::win::VERSION_VISTA;
149 #endif
150
140 TextfieldViewsModel model(NULL); 151 TextfieldViewsModel model(NULL);
152
141 // Append two Hindi strings. 153 // Append two Hindi strings.
142 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); 154 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"));
143 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), 155 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"),
144 model.GetText()); 156 model.GetText());
145 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); 157 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d"));
146 EXPECT_EQ(WideToUTF16( 158 EXPECT_EQ(WideToUTF16(
147 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), 159 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"),
148 model.GetText()); 160 model.GetText());
149 161
150 // Check it is not able to place cursor in middle of a grapheme. 162 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
151 // TODO(xji): temporarily disable in platform Win since the complex script 163 // font support for some scripts - http://crbug.com/106450
152 // characters turned into empty square due to font regression. So, not able 164 if (!on_windows_xp) {
153 // to test 2 characters belong to the same grapheme. 165 // Check it is not able to place cursor in middle of a grapheme.
166 model.MoveCursorTo(gfx::SelectionModel(1U));
167 EXPECT_EQ(0U, model.GetCursorPosition());
168
169 model.MoveCursorTo(gfx::SelectionModel(2U));
170 EXPECT_EQ(2U, model.GetCursorPosition());
171 model.InsertChar('a');
172 EXPECT_EQ(WideToUTF16(
173 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"),
174 model.GetText());
175
176 // ReplaceChar will replace the whole grapheme.
177 model.ReplaceChar('b');
178 // TODO(xji): temporarily disable in platform Win since the complex script
179 // characters turned into empty square due to font regression. So, not able
180 // to test 2 characters belong to the same grapheme.
154 #if defined(OS_LINUX) 181 #if defined(OS_LINUX)
155 model.MoveCursorTo(gfx::SelectionModel(1U)); 182 EXPECT_EQ(WideToUTF16(
156 EXPECT_EQ(0U, model.GetCursorPosition()); 183 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"),
184 model.GetText());
157 #endif 185 #endif
158 186 EXPECT_EQ(4U, model.GetCursorPosition());
159 model.MoveCursorTo(gfx::SelectionModel(2U)); 187 }
160 EXPECT_EQ(2U, model.GetCursorPosition());
161 model.InsertChar('a');
162 EXPECT_EQ(WideToUTF16(
163 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"),
164 model.GetText());
165
166 // ReplaceChar will replace the whole grapheme.
167 model.ReplaceChar('b');
168 // TODO(xji): temporarily disable in platform Win since the complex script
169 // characters turned into empty square due to font regression. So, not able
170 // to test 2 characters belong to the same grapheme.
171 #if defined(OS_LINUX)
172 EXPECT_EQ(WideToUTF16(
173 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"),
174 model.GetText());
175 #endif
176 EXPECT_EQ(4U, model.GetCursorPosition());
177 188
178 // Delete should delete the whole grapheme. 189 // Delete should delete the whole grapheme.
179 model.MoveCursorTo(gfx::SelectionModel(0U)); 190 model.MoveCursorTo(gfx::SelectionModel(0U));
180 // TODO(xji): temporarily disable in platform Win since the complex script 191 // TODO(xji): temporarily disable in platform Win since the complex script
181 // characters turned into empty square due to font regression. So, not able 192 // characters turned into empty square due to font regression. So, not able
182 // to test 2 characters belong to the same grapheme. 193 // to test 2 characters belong to the same grapheme.
183 #if defined(OS_LINUX) 194 #if defined(OS_LINUX)
184 EXPECT_TRUE(model.Delete()); 195 EXPECT_TRUE(model.Delete());
185 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), 196 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"),
186 model.GetText()); 197 model.GetText());
187 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length())); 198 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length()));
199 EXPECT_EQ(model.GetText().length(), model.GetCursorPosition());
188 EXPECT_TRUE(model.Backspace()); 200 EXPECT_TRUE(model.Backspace());
189 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), 201 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"),
190 model.GetText()); 202 model.GetText());
191 #endif 203 #endif
192 204
193 // Test cursor position and deletion for Hindi Virama. 205 // Test cursor position and deletion for Hindi Virama.
194 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); 206 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E"));
195 model.MoveCursorTo(gfx::SelectionModel(0)); 207 model.MoveCursorTo(gfx::SelectionModel(0));
196 EXPECT_EQ(0U, model.GetCursorPosition()); 208 EXPECT_EQ(0U, model.GetCursorPosition());
197 209
198 // TODO(xji): temporarily disable in platform Win since the complex script 210 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
199 // characters turned into empty square due to font regression. So, not able 211 // font support for some scripts - http://crbug.com/106450
200 // to test 2 characters belong to the same grapheme. 212 if (!on_windows_xp) {
201 #if defined(OS_LINUX) 213 model.MoveCursorTo(gfx::SelectionModel(1));
202 model.MoveCursorTo(gfx::SelectionModel(1)); 214 EXPECT_EQ(0U, model.GetCursorPosition());
203 EXPECT_EQ(0U, model.GetCursorPosition()); 215 model.MoveCursorTo(gfx::SelectionModel(3));
216 EXPECT_EQ(3U, model.GetCursorPosition());
217 }
218
219 // TODO(asvitkine): Temporarily disable the following check on Windows. It
220 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme.
221 #if !defined(OS_WIN)
222 model.MoveCursorTo(gfx::SelectionModel(2));
223 EXPECT_EQ(2U, model.GetCursorPosition());
224 EXPECT_TRUE(model.Backspace());
225 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText());
204 #endif 226 #endif
205 227
206 model.MoveCursorTo(gfx::SelectionModel(2));
207 EXPECT_EQ(2U, model.GetCursorPosition());
208
209 model.MoveCursorTo(gfx::SelectionModel(3));
210 EXPECT_EQ(3U, model.GetCursorPosition());
211
212 model.MoveCursorTo(gfx::SelectionModel(2));
213
214 EXPECT_TRUE(model.Backspace());
215 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText());
216
217 // Test Delete/Backspace on Hebrew with non-spacing marks.
218 // TODO(xji): temporarily disable in platform Win since the complex script
219 // characters turned into empty square due to font regression. So, not able
220 // to test 2 characters belong to the same grapheme.
221 #if defined(OS_LINUX)
222 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); 228 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9"));
223 model.MoveCursorTo(gfx::SelectionModel(0)); 229 model.MoveCursorTo(gfx::SelectionModel(0));
224 EXPECT_TRUE(model.Delete()); 230 EXPECT_TRUE(model.Delete());
225 EXPECT_TRUE(model.Delete()); 231 EXPECT_TRUE(model.Delete());
226 EXPECT_TRUE(model.Delete()); 232 EXPECT_TRUE(model.Delete());
227 EXPECT_TRUE(model.Delete()); 233 EXPECT_TRUE(model.Delete());
228 EXPECT_EQ(WideToUTF16(L""), model.GetText()); 234 EXPECT_EQ(WideToUTF16(L""), model.GetText());
229 #endif
230 235
231 // The first 2 characters are not strong directionality characters. 236 // The first 2 characters are not strong directionality characters.
232 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); 237 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC"));
233 #if defined(OS_WIN) 238 #if defined(OS_WIN)
234 model.MoveCursorRight(gfx::LINE_BREAK, false); 239 model.MoveCursorRight(gfx::LINE_BREAK, false);
235 #else 240 #else
236 model.MoveCursorLeft(gfx::LINE_BREAK, false); 241 model.MoveCursorLeft(gfx::LINE_BREAK, false);
237 #endif 242 #endif
238 EXPECT_TRUE(model.Backspace()); 243 EXPECT_TRUE(model.Backspace());
239 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), 244 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"),
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 model.ClearSelection(); 559 model.ClearSelection();
555 model.MoveCursorRight(gfx::LINE_BREAK, false); 560 model.MoveCursorRight(gfx::LINE_BREAK, false);
556 model.MoveCursorLeft(gfx::WORD_BREAK, true); 561 model.MoveCursorLeft(gfx::WORD_BREAK, true);
557 EXPECT_TRUE(model.Paste()); 562 EXPECT_TRUE(model.Paste());
558 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); 563 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
559 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); 564 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
560 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); 565 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText());
561 EXPECT_EQ(29U, model.GetCursorPosition()); 566 EXPECT_EQ(29U, model.GetCursorPosition());
562 } 567 }
563 568
564 void SelectWordTestVerifier(TextfieldViewsModel &model, 569 static void SelectWordTestVerifier(const TextfieldViewsModel& model,
565 const string16 &expected_selected_string, size_t expected_cursor_pos) { 570 const string16 &expected_selected_string, size_t expected_cursor_pos) {
566 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); 571 EXPECT_EQ(expected_selected_string, model.GetSelectedText());
567 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); 572 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition());
568 } 573 }
569 574
570 TEST_F(TextfieldViewsModelTest, SelectWordTest) { 575 TEST_F(TextfieldViewsModelTest, SelectWordTest) {
571 TextfieldViewsModel model(NULL); 576 TextfieldViewsModel model(NULL);
572 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); 577 model.Append(ASCIIToUTF16(" HELLO !! WO RLD "));
573 578
574 // Test when cursor is at the beginning. 579 // Test when cursor is at the beginning.
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 EXPECT_TRUE(model.Undo()); 1549 EXPECT_TRUE(model.Undo());
1545 EXPECT_STR_EQ("ABCDE", model.GetText()); 1550 EXPECT_STR_EQ("ABCDE", model.GetText());
1546 EXPECT_TRUE(model.Redo()); 1551 EXPECT_TRUE(model.Redo());
1547 EXPECT_STR_EQ("1234", model.GetText()); 1552 EXPECT_STR_EQ("1234", model.GetText());
1548 EXPECT_FALSE(model.Redo()); 1553 EXPECT_FALSE(model.Redo());
1549 1554
1550 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1555 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1551 } 1556 }
1552 1557
1553 } // namespace views 1558 } // namespace views
OLDNEW
« no previous file with comments | « ui/gfx/render_text_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698