OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 EXPECT_STR_EQ("this is a test", model_->GetText()); | 352 EXPECT_STR_EQ("this is a test", model_->GetText()); |
353 EXPECT_STR_EQ("this is a test", textfield_->text()); | 353 EXPECT_STR_EQ("this is a test", textfield_->text()); |
354 EXPECT_TRUE(last_contents_.empty()); | 354 EXPECT_TRUE(last_contents_.empty()); |
355 | 355 |
356 EXPECT_EQ(string16(), textfield_->GetSelectedText()); | 356 EXPECT_EQ(string16(), textfield_->GetSelectedText()); |
357 textfield_->SelectAll(); | 357 textfield_->SelectAll(); |
358 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 358 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
359 EXPECT_TRUE(last_contents_.empty()); | 359 EXPECT_TRUE(last_contents_.empty()); |
360 } | 360 } |
361 | 361 |
| 362 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) { |
| 363 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. |
| 364 InitTextfield(Textfield::STYLE_LOWERCASE); |
| 365 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 366 |
| 367 last_contents_.clear(); |
| 368 textfield_->SetText(ASCIIToUTF16("THIS IS")); |
| 369 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 370 |
| 371 EXPECT_STR_EQ("this is", model_->GetText()); |
| 372 EXPECT_STR_EQ("THIS IS", textfield_->text()); |
| 373 EXPECT_TRUE(last_contents_.empty()); |
| 374 |
| 375 textfield_->AppendText(ASCIIToUTF16(" A TEST")); |
| 376 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 377 EXPECT_STR_EQ("this is a test", model_->GetText()); |
| 378 EXPECT_STR_EQ("THIS IS A TEST", textfield_->text()); |
| 379 |
| 380 EXPECT_TRUE(last_contents_.empty()); |
| 381 } |
| 382 |
| 383 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseI18n) { |
| 384 // Check if lower case conversion works for non-ASCII characters. |
| 385 InitTextfield(Textfield::STYLE_LOWERCASE); |
| 386 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 387 |
| 388 last_contents_.clear(); |
| 389 // Zenkaku Japanese "ABCabc" |
| 390 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43")); |
| 391 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 392 // Zenkaku Japanese "abcabc" |
| 393 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"), |
| 394 model_->GetText()); |
| 395 // Zenkaku Japanese "ABCabc" |
| 396 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"), |
| 397 textfield_->text()); |
| 398 EXPECT_TRUE(last_contents_.empty()); |
| 399 |
| 400 // Zenkaku Japanese "XYZxyz" |
| 401 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A")); |
| 402 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 403 // Zenkaku Japanese "abcabcxyzxyz" |
| 404 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43" |
| 405 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"), |
| 406 model_->GetText()); |
| 407 // Zenkaku Japanese "ABCabcXYZxyz" |
| 408 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43" |
| 409 L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A"), |
| 410 textfield_->text()); |
| 411 EXPECT_TRUE(last_contents_.empty()); |
| 412 } |
| 413 |
| 414 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseWithLocale) { |
| 415 // Check if lower case conversion honors locale properly. |
| 416 std::string locale = l10n_util::GetApplicationLocale(""); |
| 417 base::i18n::SetICUDefaultLocale("tr"); |
| 418 |
| 419 InitTextfield(Textfield::STYLE_LOWERCASE); |
| 420 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 421 |
| 422 last_contents_.clear(); |
| 423 // Turkish 'I' should be converted to dotless 'i' (U+0131). |
| 424 textfield_->SetText(WideToUTF16(L"I")); |
| 425 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 426 EXPECT_EQ(WideToUTF16(L"\x0131"), model_->GetText()); |
| 427 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); |
| 428 EXPECT_TRUE(last_contents_.empty()); |
| 429 |
| 430 base::i18n::SetICUDefaultLocale(locale); |
| 431 |
| 432 // On default (en) locale, 'I' should be converted to 'i'. |
| 433 textfield_->SetText(WideToUTF16(L"I")); |
| 434 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 435 EXPECT_EQ(WideToUTF16(L"i"), model_->GetText()); |
| 436 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); |
| 437 EXPECT_TRUE(last_contents_.empty()); |
| 438 } |
| 439 |
362 TEST_F(NativeTextfieldViewsTest, KeyTest) { | 440 TEST_F(NativeTextfieldViewsTest, KeyTest) { |
363 InitTextfield(Textfield::STYLE_DEFAULT); | 441 InitTextfield(Textfield::STYLE_DEFAULT); |
364 SendKeyEvent(ui::VKEY_C, true, false); | 442 SendKeyEvent(ui::VKEY_C, true, false); |
365 EXPECT_STR_EQ("C", textfield_->text()); | 443 EXPECT_STR_EQ("C", textfield_->text()); |
366 EXPECT_STR_EQ("C", last_contents_); | 444 EXPECT_STR_EQ("C", last_contents_); |
367 last_contents_.clear(); | 445 last_contents_.clear(); |
368 | 446 |
369 SendKeyEvent(ui::VKEY_R, false, false); | 447 SendKeyEvent(ui::VKEY_R, false, false); |
370 EXPECT_STR_EQ("Cr", textfield_->text()); | 448 EXPECT_STR_EQ("Cr", textfield_->text()); |
371 EXPECT_STR_EQ("Cr", last_contents_); | 449 EXPECT_STR_EQ("Cr", last_contents_); |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 #else | 1652 #else |
1575 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1653 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1576 #endif | 1654 #endif |
1577 #endif // !defined(OS_WIN) | 1655 #endif // !defined(OS_WIN) |
1578 | 1656 |
1579 // Reset locale. | 1657 // Reset locale. |
1580 base::i18n::SetICUDefaultLocale(locale); | 1658 base::i18n::SetICUDefaultLocale(locale); |
1581 } | 1659 } |
1582 | 1660 |
1583 } // namespace views | 1661 } // namespace views |
OLD | NEW |