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 2119813002: views::Textfield: Implement yank editing command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review. Created 4 years, 4 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 namespace views { 48 namespace views {
49 49
50 class TextfieldModelTest : public ViewsTestBase, 50 class TextfieldModelTest : public ViewsTestBase,
51 public TextfieldModel::Delegate { 51 public TextfieldModel::Delegate {
52 public: 52 public:
53 TextfieldModelTest() 53 TextfieldModelTest()
54 : ViewsTestBase(), 54 : ViewsTestBase(),
55 composition_text_confirmed_or_cleared_(false) { 55 composition_text_confirmed_or_cleared_(false) {
56 } 56 }
57 57
58 // ::testing::Test:
59 void TearDown() override {
60 // Clear kill buffer used for "Yank" text editing command so that no state
61 // persists between tests.
62 TextfieldModel::ClearKillBuffer();
63 ViewsTestBase::TearDown();
64 }
65
58 void OnCompositionTextConfirmedOrCleared() override { 66 void OnCompositionTextConfirmedOrCleared() override {
59 composition_text_confirmed_or_cleared_ = true; 67 composition_text_confirmed_or_cleared_ = true;
60 } 68 }
61 69
62 protected: 70 protected:
63 void ResetModel(TextfieldModel* model) const { 71 void ResetModel(TextfieldModel* model) const {
64 model->SetText(base::string16()); 72 model->SetText(base::string16());
65 model->ClearEditHistory(); 73 model->ClearEditHistory();
66 } 74 }
67 75
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 model.SelectRange(test_case.range); 1654 model.SelectRange(test_case.range);
1647 EXPECT_EQ(test_case.range, model.render_text()->selection()); 1655 EXPECT_EQ(test_case.range, model.render_text()->selection());
1648 model.Transpose(); 1656 model.Transpose();
1649 1657
1650 EXPECT_EQ(test_case.expected_text, model.text()); 1658 EXPECT_EQ(test_case.expected_text, model.text());
1651 EXPECT_EQ(test_case.expected_selection, model.render_text()->selection()); 1659 EXPECT_EQ(test_case.expected_selection, model.render_text()->selection());
1652 } 1660 }
1653 } 1661 }
1654 } 1662 }
1655 1663
1664 TEST_F(TextfieldModelTest, Yank) {
1665 TextfieldModel model(nullptr);
1666 model.SetText(base::ASCIIToUTF16("abcde"));
1667 model.SelectRange(gfx::Range(1, 3));
1668
1669 // Delete selection but don't add to kill buffer.
1670 model.Delete(false);
1671 EXPECT_STR_EQ("ade", model.text());
1672
1673 // Since the kill buffer is empty, yank should cause no change.
1674 model.Yank();
1675 EXPECT_STR_EQ("ade", model.text());
1676
1677 // Delete selection and add to kill buffer.
1678 model.SelectRange(gfx::Range(0, 1));
1679 model.Delete(true);
1680 EXPECT_STR_EQ("de", model.text());
1681
1682 // Yank twice.
1683 model.Yank();
1684 model.Yank();
1685 EXPECT_STR_EQ("aade", model.text());
1686
1687 // Ensure an empty deletion does not modify the kill buffer.
1688 model.SelectRange(gfx::Range(4));
1689 model.Delete(true);
1690 model.Yank();
1691 EXPECT_STR_EQ("aadea", model.text());
1692
1693 // Backspace twice but don't add to kill buffer.
1694 model.Backspace(false);
1695 model.Backspace(false);
1696 EXPECT_STR_EQ("aad", model.text());
1697
1698 // Ensure kill buffer is not modified.
1699 model.Yank();
1700 EXPECT_STR_EQ("aada", model.text());
1701
1702 // Backspace twice, each time modifying the kill buffer.
1703 model.Backspace(true);
1704 model.Backspace(true);
1705 EXPECT_STR_EQ("aa", model.text());
1706
1707 // Ensure yanking inserts the modified kill buffer text.
1708 model.Yank();
1709 EXPECT_STR_EQ("aad", model.text());
1710 }
1711
1656 } // namespace views 1712 } // 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