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

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

Issue 9358049: Implement STYLE_LOWERCASE style for Aura NativeTextfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add MaybeLowerCase(), test descriptions and cursor position assertion. Created 8 years, 8 months 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
OLDNEW
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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 EXPECT_STR_EQ("this is a test", model_->GetText()); 354 EXPECT_STR_EQ("this is a test", model_->GetText());
355 EXPECT_STR_EQ("this is a test", textfield_->text()); 355 EXPECT_STR_EQ("this is a test", textfield_->text());
356 EXPECT_TRUE(last_contents_.empty()); 356 EXPECT_TRUE(last_contents_.empty());
357 357
358 EXPECT_EQ(string16(), textfield_->GetSelectedText()); 358 EXPECT_EQ(string16(), textfield_->GetSelectedText());
359 textfield_->SelectAll(); 359 textfield_->SelectAll();
360 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); 360 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText());
361 EXPECT_TRUE(last_contents_.empty()); 361 EXPECT_TRUE(last_contents_.empty());
362 } 362 }
363 363
364 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) {
365 // Check if |model_|'s text is properly lowercased when STYLE_LOWERCASE is
msw 2012/04/12 16:15:29 optional one-line comment nit: // Check if |model_
kochi 2012/04/13 09:44:09 Done.
366 // specified.
367 InitTextfield(Textfield::STYLE_LOWERCASE);
368 EXPECT_EQ(0U, textfield_->GetCursorPosition());
369
370 last_contents_.clear();
371 textfield_->SetText(ASCIIToUTF16("THIS IS"));
372 EXPECT_EQ(0U, textfield_->GetCursorPosition());
373
374 EXPECT_STR_EQ("this is", model_->GetText());
375 EXPECT_STR_EQ("THIS IS", textfield_->text());
376 EXPECT_TRUE(last_contents_.empty());
377
378 textfield_->AppendText(ASCIIToUTF16(" A TEST"));
379 EXPECT_EQ(0U, textfield_->GetCursorPosition());
380 EXPECT_STR_EQ("this is a test", model_->GetText());
381 EXPECT_STR_EQ("THIS IS A TEST", textfield_->text());
382
383 EXPECT_TRUE(last_contents_.empty());
384 }
385
386 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseI18n) {
387 // Check if lower case conversion works for non-ASCII characters.
388 InitTextfield(Textfield::STYLE_LOWERCASE);
389 EXPECT_EQ(0U, textfield_->GetCursorPosition());
390
391 last_contents_.clear();
392 // Zenkaku Japanese "ABCabc"
393 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"));
394 EXPECT_EQ(0U, textfield_->GetCursorPosition());
395 // Zenkaku Japanese "abcabc"
396 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"),
397 model_->GetText());
398 // Zenkaku Japanese "ABCabc"
399 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"),
400 textfield_->text());
401 EXPECT_TRUE(last_contents_.empty());
402
403 // Zenkaku Japanese "XYZxyz"
404 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A"));
405 EXPECT_EQ(0U, textfield_->GetCursorPosition());
406 // Zenkaku Japanese "abcabcxyzxyz"
407 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"
408 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"),
409 model_->GetText());
410 // Zenkaku Japanese "ABCabcXYZxyz"
411 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"
412 L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A"),
413 textfield_->text());
414 EXPECT_TRUE(last_contents_.empty());
415 }
416
417 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseWithLocale) {
418 // Check if lower case conversion honors locale properly.
419 std::string locale = l10n_util::GetApplicationLocale("");
420 base::i18n::SetICUDefaultLocale("tr");
421
422 InitTextfield(Textfield::STYLE_LOWERCASE);
423 EXPECT_EQ(0U, textfield_->GetCursorPosition());
424
425 last_contents_.clear();
426 // Turkish 'I' should be converted to dotless 'i' (U+0131).
427 textfield_->SetText(WideToUTF16(L"I"));
428 EXPECT_EQ(0U, textfield_->GetCursorPosition());
429 EXPECT_EQ(WideToUTF16(L"\x0131"), model_->GetText());
430 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text());
431 EXPECT_TRUE(last_contents_.empty());
432
433 base::i18n::SetICUDefaultLocale(locale);
434
435 // On default (en) locale, 'I' should be converted to 'i'.
436 textfield_->SetText(WideToUTF16(L"I"));
437 EXPECT_EQ(0U, textfield_->GetCursorPosition());
438 EXPECT_EQ(WideToUTF16(L"i"), model_->GetText());
439 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text());
440 EXPECT_TRUE(last_contents_.empty());
441 }
442
364 TEST_F(NativeTextfieldViewsTest, KeyTest) { 443 TEST_F(NativeTextfieldViewsTest, KeyTest) {
365 InitTextfield(Textfield::STYLE_DEFAULT); 444 InitTextfield(Textfield::STYLE_DEFAULT);
366 SendKeyEvent(ui::VKEY_C, true, false); 445 SendKeyEvent(ui::VKEY_C, true, false);
367 EXPECT_STR_EQ("C", textfield_->text()); 446 EXPECT_STR_EQ("C", textfield_->text());
368 EXPECT_STR_EQ("C", last_contents_); 447 EXPECT_STR_EQ("C", last_contents_);
369 last_contents_.clear(); 448 last_contents_.clear();
370 449
371 SendKeyEvent(ui::VKEY_R, false, false); 450 SendKeyEvent(ui::VKEY_R, false, false);
372 EXPECT_STR_EQ("Cr", textfield_->text()); 451 EXPECT_STR_EQ("Cr", textfield_->text());
373 EXPECT_STR_EQ("Cr", last_contents_); 452 EXPECT_STR_EQ("Cr", last_contents_);
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 #else 1655 #else
1577 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1656 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1578 #endif 1657 #endif
1579 #endif // !defined(OS_WIN) 1658 #endif // !defined(OS_WIN)
1580 1659
1581 // Reset locale. 1660 // Reset locale.
1582 base::i18n::SetICUDefaultLocale(locale); 1661 base::i18n::SetICUDefaultLocale(locale);
1583 } 1662 }
1584 1663
1585 } // namespace views 1664 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698