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

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 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 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 model.SelectRange(test_case.range); 1646 model.SelectRange(test_case.range);
1647 EXPECT_EQ(test_case.range, model.render_text()->selection()); 1647 EXPECT_EQ(test_case.range, model.render_text()->selection());
1648 model.Transpose(); 1648 model.Transpose();
1649 1649
1650 EXPECT_EQ(test_case.expected_text, model.text()); 1650 EXPECT_EQ(test_case.expected_text, model.text());
1651 EXPECT_EQ(test_case.expected_selection, model.render_text()->selection()); 1651 EXPECT_EQ(test_case.expected_selection, model.render_text()->selection());
1652 } 1652 }
1653 } 1653 }
1654 } 1654 }
1655 1655
1656 TEST_F(TextfieldModelTest, Yank) {
1657 TextfieldModel model(nullptr);
1658 model.SetText(base::ASCIIToUTF16("abcde"));
1659 model.SelectRange(gfx::Range(1, 3));
1660
1661 // Delete selection but don't add to kill buffer.
1662 model.Delete(false);
1663 EXPECT_STR_EQ("ade", model.text());
1664
1665 // Since the kill buffer is empty, yank should cause no change.
1666 model.Yank();
1667 EXPECT_STR_EQ("ade", model.text());
1668
1669 // Delete selection and add to kill buffer.
1670 model.SelectRange(gfx::Range(0, 1));
1671 model.Delete(true);
1672 EXPECT_STR_EQ("de", model.text());
1673
1674 // Yank twice.
1675 model.Yank();
1676 model.Yank();
1677 EXPECT_STR_EQ("aade", model.text());
1678
1679 // Ensure an empty deletion does not modify the kill buffer.
1680 model.SelectRange(gfx::Range(4));
1681 model.Delete(true);
1682 model.Yank();
1683 EXPECT_STR_EQ("aadea", model.text());
1684
1685 // Backspace twice but don't add to kill buffer.
1686 model.Backspace(false);
1687 model.Backspace(false);
1688 EXPECT_STR_EQ("aad", model.text());
1689
1690 // Ensure kill buffer is not modified.
1691 model.Yank();
1692 EXPECT_STR_EQ("aada", model.text());
1693
1694 // Backspace twice, each time modifying the kill buffer.
1695 model.Backspace(true);
1696 model.Backspace(true);
1697 EXPECT_STR_EQ("aa", model.text());
1698
1699 // Ensure yanking inserts the modified kill buffer text.
1700 model.Yank();
1701 EXPECT_STR_EQ("aad", model.text());
1702 }
1703
1656 } // namespace views 1704 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698