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