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