| 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" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 EXPECT_TRUE(model.Delete()); | 131 EXPECT_TRUE(model.Delete()); |
| 132 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), | 132 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), |
| 133 model.GetText()); | 133 model.GetText()); |
| 134 EXPECT_TRUE(model.Backspace()); | 134 EXPECT_TRUE(model.Backspace()); |
| 135 EXPECT_EQ(2U, model.GetCursorPosition()); | 135 EXPECT_EQ(2U, model.GetCursorPosition()); |
| 136 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText()); | 136 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { | 139 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { |
| 140 TextfieldViewsModel model(NULL); | 140 TextfieldViewsModel model(NULL); |
| 141 | |
| 142 // Append two Hindi strings. | 141 // Append two Hindi strings. |
| 143 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); | 142 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); |
| 144 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), | 143 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), |
| 145 model.GetText()); | 144 model.GetText()); |
| 146 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); | 145 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); |
| 147 EXPECT_EQ(WideToUTF16( | 146 EXPECT_EQ(WideToUTF16( |
| 148 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), | 147 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), |
| 149 model.GetText()); | 148 model.GetText()); |
| 150 | 149 |
| 151 // 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) |
| 152 model.MoveCursorTo(gfx::SelectionModel(1U)); | 155 model.MoveCursorTo(gfx::SelectionModel(1U)); |
| 153 EXPECT_EQ(0U, model.GetCursorPosition()); | 156 EXPECT_EQ(0U, model.GetCursorPosition()); |
| 157 #endif |
| 154 | 158 |
| 155 model.MoveCursorTo(gfx::SelectionModel(2U)); | 159 model.MoveCursorTo(gfx::SelectionModel(2U)); |
| 156 EXPECT_EQ(2U, model.GetCursorPosition()); | 160 EXPECT_EQ(2U, model.GetCursorPosition()); |
| 157 model.InsertChar('a'); | 161 model.InsertChar('a'); |
| 158 EXPECT_EQ(WideToUTF16( | 162 EXPECT_EQ(WideToUTF16( |
| 159 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), | 163 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), |
| 160 model.GetText()); | 164 model.GetText()); |
| 161 | 165 |
| 162 // ReplaceChar will replace the whole grapheme. | 166 // ReplaceChar will replace the whole grapheme. |
| 163 model.ReplaceChar('b'); | 167 model.ReplaceChar('b'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 174 // Delete should delete the whole grapheme. | 178 // Delete should delete the whole grapheme. |
| 175 model.MoveCursorTo(gfx::SelectionModel(0U)); | 179 model.MoveCursorTo(gfx::SelectionModel(0U)); |
| 176 // TODO(xji): temporarily disable in platform Win since the complex script | 180 // TODO(xji): temporarily disable in platform Win since the complex script |
| 177 // 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 |
| 178 // to test 2 characters belong to the same grapheme. | 182 // to test 2 characters belong to the same grapheme. |
| 179 #if defined(OS_LINUX) | 183 #if defined(OS_LINUX) |
| 180 EXPECT_TRUE(model.Delete()); | 184 EXPECT_TRUE(model.Delete()); |
| 181 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), | 185 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), |
| 182 model.GetText()); | 186 model.GetText()); |
| 183 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length())); | 187 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length())); |
| 184 EXPECT_EQ(model.GetText().length(), model.GetCursorPosition()); | |
| 185 EXPECT_TRUE(model.Backspace()); | 188 EXPECT_TRUE(model.Backspace()); |
| 186 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), | 189 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), |
| 187 model.GetText()); | 190 model.GetText()); |
| 188 #endif | 191 #endif |
| 189 | 192 |
| 190 // Test cursor position and deletion for Hindi Virama. | 193 // Test cursor position and deletion for Hindi Virama. |
| 191 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); | 194 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); |
| 192 model.MoveCursorTo(gfx::SelectionModel(0)); | 195 model.MoveCursorTo(gfx::SelectionModel(0)); |
| 193 EXPECT_EQ(0U, model.GetCursorPosition()); | 196 EXPECT_EQ(0U, model.GetCursorPosition()); |
| 194 | 197 |
| 198 // TODO(xji): temporarily disable in platform Win since the complex script |
| 199 // characters turned into empty square due to font regression. So, not able |
| 200 // to test 2 characters belong to the same grapheme. |
| 201 #if defined(OS_LINUX) |
| 195 model.MoveCursorTo(gfx::SelectionModel(1)); | 202 model.MoveCursorTo(gfx::SelectionModel(1)); |
| 196 EXPECT_EQ(0U, model.GetCursorPosition()); | 203 EXPECT_EQ(0U, model.GetCursorPosition()); |
| 204 #endif |
| 205 |
| 206 model.MoveCursorTo(gfx::SelectionModel(2)); |
| 207 EXPECT_EQ(2U, model.GetCursorPosition()); |
| 197 | 208 |
| 198 model.MoveCursorTo(gfx::SelectionModel(3)); | 209 model.MoveCursorTo(gfx::SelectionModel(3)); |
| 199 EXPECT_EQ(3U, model.GetCursorPosition()); | 210 EXPECT_EQ(3U, model.GetCursorPosition()); |
| 200 | 211 |
| 201 // TODO(asvitkine): Temporarily disable the following check on Windows. It | |
| 202 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme. | |
| 203 #if !defined(OS_WIN) | |
| 204 model.MoveCursorTo(gfx::SelectionModel(2)); | 212 model.MoveCursorTo(gfx::SelectionModel(2)); |
| 205 EXPECT_EQ(2U, model.GetCursorPosition()); | 213 |
| 206 EXPECT_TRUE(model.Backspace()); | 214 EXPECT_TRUE(model.Backspace()); |
| 207 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); | 215 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); |
| 208 #endif | |
| 209 | 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) |
| 210 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); | 222 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); |
| 211 model.MoveCursorTo(gfx::SelectionModel(0)); | 223 model.MoveCursorTo(gfx::SelectionModel(0)); |
| 212 EXPECT_TRUE(model.Delete()); | 224 EXPECT_TRUE(model.Delete()); |
| 213 EXPECT_TRUE(model.Delete()); | 225 EXPECT_TRUE(model.Delete()); |
| 214 EXPECT_TRUE(model.Delete()); | 226 EXPECT_TRUE(model.Delete()); |
| 215 EXPECT_TRUE(model.Delete()); | 227 EXPECT_TRUE(model.Delete()); |
| 216 EXPECT_EQ(WideToUTF16(L""), model.GetText()); | 228 EXPECT_EQ(WideToUTF16(L""), model.GetText()); |
| 229 #endif |
| 217 | 230 |
| 218 // The first 2 characters are not strong directionality characters. | 231 // The first 2 characters are not strong directionality characters. |
| 219 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); | 232 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); |
| 220 #if defined(OS_WIN) | 233 #if defined(OS_WIN) |
| 221 model.MoveCursorRight(gfx::LINE_BREAK, false); | 234 model.MoveCursorRight(gfx::LINE_BREAK, false); |
| 222 #else | 235 #else |
| 223 model.MoveCursorLeft(gfx::LINE_BREAK, false); | 236 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
| 224 #endif | 237 #endif |
| 225 EXPECT_TRUE(model.Backspace()); | 238 EXPECT_TRUE(model.Backspace()); |
| 226 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... |
| 541 model.ClearSelection(); | 554 model.ClearSelection(); |
| 542 model.MoveCursorRight(gfx::LINE_BREAK, false); | 555 model.MoveCursorRight(gfx::LINE_BREAK, false); |
| 543 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 556 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
| 544 EXPECT_TRUE(model.Paste()); | 557 EXPECT_TRUE(model.Paste()); |
| 545 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 558 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
| 546 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 559 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
| 547 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); | 560 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); |
| 548 EXPECT_EQ(29U, model.GetCursorPosition()); | 561 EXPECT_EQ(29U, model.GetCursorPosition()); |
| 549 } | 562 } |
| 550 | 563 |
| 551 static void SelectWordTestVerifier(const TextfieldViewsModel& model, | 564 void SelectWordTestVerifier(TextfieldViewsModel &model, |
| 552 const string16 &expected_selected_string, size_t expected_cursor_pos) { | 565 const string16 &expected_selected_string, size_t expected_cursor_pos) { |
| 553 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); | 566 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); |
| 554 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); | 567 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); |
| 555 } | 568 } |
| 556 | 569 |
| 557 TEST_F(TextfieldViewsModelTest, SelectWordTest) { | 570 TEST_F(TextfieldViewsModelTest, SelectWordTest) { |
| 558 TextfieldViewsModel model(NULL); | 571 TextfieldViewsModel model(NULL); |
| 559 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); | 572 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); |
| 560 | 573 |
| 561 // Test when cursor is at the beginning. | 574 // Test when cursor is at the beginning. |
| (...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 EXPECT_TRUE(model.Undo()); | 1527 EXPECT_TRUE(model.Undo()); |
| 1515 EXPECT_STR_EQ("ABCDE", model.GetText()); | 1528 EXPECT_STR_EQ("ABCDE", model.GetText()); |
| 1516 EXPECT_TRUE(model.Redo()); | 1529 EXPECT_TRUE(model.Redo()); |
| 1517 EXPECT_STR_EQ("1234", model.GetText()); | 1530 EXPECT_STR_EQ("1234", model.GetText()); |
| 1518 EXPECT_FALSE(model.Redo()); | 1531 EXPECT_FALSE(model.Redo()); |
| 1519 | 1532 |
| 1520 // TODO(oshima): We need MockInputMethod to test the behavior with IME. | 1533 // TODO(oshima): We need MockInputMethod to test the behavior with IME. |
| 1521 } | 1534 } |
| 1522 | 1535 |
| 1523 } // namespace views | 1536 } // namespace views |
| OLD | NEW |