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

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

Issue 1999773002: views::Textfield: Implement transpose editing command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/views/controls/textfield/textfield_model.h" 5 #include "ui/views/controls/textfield/textfield_model.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 1582
1583 // Test 7 1583 // Test 7
1584 // Clipboard text with lots of spaces between words should have all spaces 1584 // Clipboard text with lots of spaces between words should have all spaces
1585 // replaced with a single space. 1585 // replaced with a single space.
1586 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE) 1586 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE)
1587 .WriteText(base::ASCIIToUTF16("FOO BAR")); 1587 .WriteText(base::ASCIIToUTF16("FOO BAR"));
1588 EXPECT_TRUE(model.Paste()); 1588 EXPECT_TRUE(model.Paste());
1589 EXPECT_STR_EQ("FOO BAR", model.text()); 1589 EXPECT_STR_EQ("FOO BAR", model.text());
1590 } 1590 }
1591 1591
1592 TEST_F(TextfieldModelTest, Transpose) {
1593 const base::string16 ltr = base::ASCIIToUTF16("12");
1594 const base::string16 rtl = base::WideToUTF16(L"\x0634\x0632");
1595 const base::string16 ltr_transposed = base::ASCIIToUTF16("21");
1596 const base::string16 rtl_transposed = base::WideToUTF16(L"\x0632\x0634");
1597
1598 // This is a string with an 'a' between two emojis.
1599 const base::string16 surrogate_pairs({0xD83D, 0xDE07, 'a', 0xD83D, 0xDE0E});
1600 const base::string16 test_strings[] = {ltr, rtl, surrogate_pairs};
1601
1602 struct TestCase {
1603 gfx::Range range;
1604 base::string16 expected_text;
1605 gfx::Range expected_selection;
1606 };
1607
1608 std::vector<TestCase> ltr_tests = {
1609 {gfx::Range(0), ltr, gfx::Range(0)},
1610 {gfx::Range(1), ltr_transposed, gfx::Range(2)},
1611 {gfx::Range(2), ltr_transposed, gfx::Range(2)},
1612 {gfx::Range(0, 2), ltr, gfx::Range(0, 2)}};
1613
1614 std::vector<TestCase> rtl_tests = {
1615 {gfx::Range(0), rtl, gfx::Range(0)},
1616 {gfx::Range(1), rtl_transposed, gfx::Range(2)},
1617 {gfx::Range(2), rtl_transposed, gfx::Range(2)},
1618 {gfx::Range(0, 1), rtl, gfx::Range(0, 1)}};
1619
1620 // Only test at valid grapheme boundaries.
1621 std::vector<TestCase> surrogate_pairs_test = {
1622 {gfx::Range(0), surrogate_pairs, gfx::Range(0)},
1623 {gfx::Range(2), base::string16({'a', 0xD83D, 0xDE07, 0xD83D, 0xDE0E}),
1624 gfx::Range(3)},
1625 {gfx::Range(3), base::string16({0xD83D, 0xDE07, 0xD83D, 0xDE0E, 'a'}),
1626 gfx::Range(5)},
1627 {gfx::Range(5), base::string16({0xD83D, 0xDE07, 0xD83D, 0xDE0E, 'a'}),
1628 gfx::Range(5)},
1629 {gfx::Range(3, 5), surrogate_pairs, gfx::Range(3, 5)}};
1630
1631 std::vector<std::vector<TestCase>> all_tests = {ltr_tests, rtl_tests,
1632 surrogate_pairs_test};
1633
1634 TextfieldModel model(nullptr);
1635
1636 EXPECT_EQ(all_tests.size(), arraysize(test_strings));
1637
1638 for (size_t i = 0; i < arraysize(test_strings); i++) {
1639 for (size_t j = 0; j < all_tests[i].size(); j++) {
1640 SCOPED_TRACE(testing::Message() << "Testing case " << i << ", " << j
1641 << " with string " << test_strings[i]);
1642
1643 const TestCase& test_case = all_tests[i][j];
1644
1645 model.SetText(test_strings[i]);
1646 model.SelectRange(test_case.range);
1647 EXPECT_EQ(test_case.range, model.render_text()->selection());
1648 model.Transpose();
1649
1650 EXPECT_EQ(test_case.expected_text, model.text());
1651 EXPECT_EQ(test_case.expected_selection, model.render_text()->selection());
1652 }
1653 }
1654 }
1655
1592 } // namespace views 1656 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield_model.cc ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698