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

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 10693160: Add and specify Views::Textfield::SelectAll |reversed| flag, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove redundant comments. Created 8 years, 5 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
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/views/controls/message_box_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 SelectionModel start_edge = 720 SelectionModel start_edge =
721 render_text->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT); 721 render_text->EdgeSelectionModel(ltr ? CURSOR_LEFT : CURSOR_RIGHT);
722 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD)); 722 EXPECT_EQ(start_edge, SelectionModel(0, CURSOR_BACKWARD));
723 723
724 SelectionModel end_edge = 724 SelectionModel end_edge =
725 render_text->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT); 725 render_text->EdgeSelectionModel(ltr ? CURSOR_RIGHT : CURSOR_LEFT);
726 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD)); 726 EXPECT_EQ(end_edge, SelectionModel(cases[i].text.length(), CURSOR_FORWARD));
727 } 727 }
728 } 728 }
729 729
730 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) { 730 TEST_F(RenderTextTest, SelectAll) {
731 const wchar_t* const cases[] = {
732 L"abc",
733 L"a"L"\x5d0\x5d1",
734 L"a"L"\x5d1"L"b",
735 L"\x5d0\x5d1\x5d2",
736 L"\x5d0\x5d1"L"a",
737 L"\x5d0"L"a"L"\x5d1",
738 };
739
740 // Ensure that SelectAll respects the |reversed| argument regardless of
741 // application locale and text content directionality.
742 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
743 const SelectionModel expected_reversed(ui::Range(3, 0), CURSOR_FORWARD);
744 const SelectionModel expected_forwards(ui::Range(0, 3), CURSOR_BACKWARD);
745 const bool was_rtl = base::i18n::IsRTL();
746
747 for (size_t i = 0; i < 2; ++i) {
748 SetRTL(!base::i18n::IsRTL());
749 for (size_t j = 0; j < ARRAYSIZE_UNSAFE(cases); j++) {
750 render_text->SetText(WideToUTF16(cases[j]));
751 render_text->SelectAll(false);
752 EXPECT_EQ(render_text->selection_model(), expected_forwards);
753 render_text->SelectAll(true);
754 EXPECT_EQ(render_text->selection_model(), expected_reversed);
755 }
756 }
757
758 EXPECT_EQ(was_rtl, base::i18n::IsRTL());
759 }
760
761 TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
731 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); 762 scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
732 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 763 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
733 // Left arrow on select ranging (6, 4). 764 // Left arrow on select ranging (6, 4).
734 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 765 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
735 EXPECT_EQ(ui::Range(6), render_text->selection()); 766 EXPECT_EQ(ui::Range(6), render_text->selection());
736 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 767 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
737 EXPECT_EQ(ui::Range(4), render_text->selection()); 768 EXPECT_EQ(ui::Range(4), render_text->selection());
738 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 769 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
739 EXPECT_EQ(ui::Range(5), render_text->selection()); 770 EXPECT_EQ(ui::Range(5), render_text->selection());
740 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); 771 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 render_text->SetDisplayRect(Rect(width + 10, 1)); 1261 render_text->SetDisplayRect(Rect(width + 10, 1));
1231 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1262 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1232 render_text->GetUpdatedCursorBounds().x()); 1263 render_text->GetUpdatedCursorBounds().x());
1233 1264
1234 // Reset the application default text direction to LTR. 1265 // Reset the application default text direction to LTR.
1235 SetRTL(was_rtl); 1266 SetRTL(was_rtl);
1236 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); 1267 EXPECT_EQ(was_rtl, base::i18n::IsRTL());
1237 } 1268 }
1238 1269
1239 } // namespace gfx 1270 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | ui/views/controls/message_box_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698