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

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: Change MaybeLowerCase() to GetTextForDisplay() 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 for STYLE_LOWERCASE.
366 InitTextfield(Textfield::STYLE_LOWERCASE);
367 EXPECT_EQ(0U, textfield_->GetCursorPosition());
msw 2012/04/13 18:13:25 Why do these test check the cursor position at all
kochi 2012/04/16 04:54:18 That's for addressing sky's review comment "Also,
368
369 last_contents_.clear();
370 textfield_->SetText(ASCIIToUTF16("THIS IS"));
371 EXPECT_EQ(0U, textfield_->GetCursorPosition());
372
373 EXPECT_STR_EQ("this is", model_->GetText());
374 EXPECT_STR_EQ("THIS IS", textfield_->text());
375 EXPECT_TRUE(last_contents_.empty());
376
377 textfield_->AppendText(ASCIIToUTF16(" A TEST"));
378 EXPECT_EQ(0U, textfield_->GetCursorPosition());
379 EXPECT_STR_EQ("this is a test", model_->GetText());
380 EXPECT_STR_EQ("THIS IS A TEST", textfield_->text());
381
382 EXPECT_TRUE(last_contents_.empty());
383 }
384
385 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseI18n) {
386 // Check if lower case conversion works for non-ASCII characters.
387 InitTextfield(Textfield::STYLE_LOWERCASE);
388 EXPECT_EQ(0U, textfield_->GetCursorPosition());
389
390 last_contents_.clear();
391 // Zenkaku Japanese "ABCabc"
392 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"));
393 EXPECT_EQ(0U, textfield_->GetCursorPosition());
394 // Zenkaku Japanese "abcabc"
395 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"),
396 model_->GetText());
397 // Zenkaku Japanese "ABCabc"
398 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"),
399 textfield_->text());
400 EXPECT_TRUE(last_contents_.empty());
401
402 // Zenkaku Japanese "XYZxyz"
403 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A"));
404 EXPECT_EQ(0U, textfield_->GetCursorPosition());
405 // Zenkaku Japanese "abcabcxyzxyz"
406 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"
407 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"),
408 model_->GetText());
409 // Zenkaku Japanese "ABCabcXYZxyz"
410 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"
411 L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A"),
412 textfield_->text());
413 EXPECT_TRUE(last_contents_.empty());
414 }
415
416 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseWithLocale) {
417 // Check if lower case conversion honors locale properly.
418 std::string locale = l10n_util::GetApplicationLocale("");
419 base::i18n::SetICUDefaultLocale("tr");
420
421 InitTextfield(Textfield::STYLE_LOWERCASE);
422 EXPECT_EQ(0U, textfield_->GetCursorPosition());
423
424 last_contents_.clear();
425 // Turkish 'I' should be converted to dotless 'i' (U+0131).
426 textfield_->SetText(WideToUTF16(L"I"));
427 EXPECT_EQ(0U, textfield_->GetCursorPosition());
428 EXPECT_EQ(WideToUTF16(L"\x0131"), model_->GetText());
429 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text());
430 EXPECT_TRUE(last_contents_.empty());
431
432 base::i18n::SetICUDefaultLocale(locale);
433
434 // On default (en) locale, 'I' should be converted to 'i'.
435 textfield_->SetText(WideToUTF16(L"I"));
436 EXPECT_EQ(0U, textfield_->GetCursorPosition());
437 EXPECT_EQ(WideToUTF16(L"i"), model_->GetText());
438 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text());
439 EXPECT_TRUE(last_contents_.empty());
440 }
441
364 TEST_F(NativeTextfieldViewsTest, KeyTest) { 442 TEST_F(NativeTextfieldViewsTest, KeyTest) {
365 InitTextfield(Textfield::STYLE_DEFAULT); 443 InitTextfield(Textfield::STYLE_DEFAULT);
366 SendKeyEvent(ui::VKEY_C, true, false); 444 SendKeyEvent(ui::VKEY_C, true, false);
367 EXPECT_STR_EQ("C", textfield_->text()); 445 EXPECT_STR_EQ("C", textfield_->text());
368 EXPECT_STR_EQ("C", last_contents_); 446 EXPECT_STR_EQ("C", last_contents_);
369 last_contents_.clear(); 447 last_contents_.clear();
370 448
371 SendKeyEvent(ui::VKEY_R, false, false); 449 SendKeyEvent(ui::VKEY_R, false, false);
372 EXPECT_STR_EQ("Cr", textfield_->text()); 450 EXPECT_STR_EQ("Cr", textfield_->text());
373 EXPECT_STR_EQ("Cr", last_contents_); 451 EXPECT_STR_EQ("Cr", last_contents_);
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 #else 1654 #else
1577 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1655 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1578 #endif 1656 #endif
1579 #endif // !defined(OS_WIN) 1657 #endif // !defined(OS_WIN)
1580 1658
1581 // Reset locale. 1659 // Reset locale.
1582 base::i18n::SetICUDefaultLocale(locale); 1660 base::i18n::SetICUDefaultLocale(locale);
1583 } 1661 }
1584 1662
1585 } // namespace views 1663 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698