| Index: ui/views/controls/textfield/textfield_unittest.cc
|
| diff --git a/ui/views/controls/textfield/textfield_unittest.cc b/ui/views/controls/textfield/textfield_unittest.cc
|
| index c7ffba28830a90374a22a9c721a1639bc83291b2..be3f3bbe52c579aa1d0d581d3122f88ff92e81d4 100644
|
| --- a/ui/views/controls/textfield/textfield_unittest.cc
|
| +++ b/ui/views/controls/textfield/textfield_unittest.cc
|
| @@ -12,10 +12,12 @@
|
| #include <vector>
|
|
|
| #include "base/command_line.h"
|
| +#include "base/format_macros.h"
|
| #include "base/i18n/rtl.h"
|
| #include "base/macros.h"
|
| #include "base/pickle.h"
|
| #include "base/strings/string16.h"
|
| +#include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "build/build_config.h"
|
| #include "ui/accessibility/ax_view_state.h"
|
| @@ -867,6 +869,33 @@ TEST_F(TextfieldTest, InsertionDeletionTest) {
|
| #endif
|
| }
|
|
|
| +// Test that deletion operations behave correctly with an active selection.
|
| +TEST_F(TextfieldTest, DeletionWithSelection) {
|
| + struct {
|
| + ui::KeyboardCode key;
|
| + bool shift;
|
| + } cases[] = {
|
| + {ui::VKEY_BACK, false},
|
| + {ui::VKEY_BACK, true},
|
| + {ui::VKEY_DELETE, false},
|
| + {ui::VKEY_DELETE, true},
|
| + };
|
| +
|
| + InitTextfield();
|
| + // [Ctrl] ([Alt] on Mac) + [Delete]/[Backspace] should delete the active
|
| + // selection, regardless of [Shift].
|
| + for (size_t i = 0; i < arraysize(cases); ++i) {
|
| + SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i));
|
| + textfield_->SetText(ASCIIToUTF16("one two three"));
|
| + textfield_->SelectRange(gfx::Range(2, 6));
|
| + // Make selection as - on|e tw|o three.
|
| + SendWordEvent(cases[i].key, cases[i].shift);
|
| + // Verify state is on|o three.
|
| + EXPECT_STR_EQ("ono three", textfield_->text());
|
| + EXPECT_EQ(gfx::Range(2), textfield_->GetSelectedRange());
|
| + }
|
| +}
|
| +
|
| TEST_F(TextfieldTest, PasswordTest) {
|
| InitTextfield();
|
| textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
|
| @@ -1806,6 +1835,17 @@ TEST_F(TextfieldTest, CutCopyPaste) {
|
| EXPECT_STR_EQ("", textfield_->text());
|
| EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard());
|
|
|
| + // Reset clipboard text.
|
| + SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "");
|
| +
|
| + // Ensure [Shift]+[Delete] is a no-op in case there is no selection.
|
| + textfield_->SetText(ASCIIToUTF16("123"));
|
| + textfield_->SelectRange(gfx::Range(0));
|
| + SendAlternateCut();
|
| + EXPECT_STR_EQ("", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
| + EXPECT_STR_EQ("123", textfield_->text());
|
| + EXPECT_EQ(ui::CLIPBOARD_TYPE_LAST, GetAndResetCopiedToClipboard());
|
| +
|
| // Ensure IDS_APP_COPY copies.
|
| textfield_->SetText(ASCIIToUTF16("789"));
|
| textfield_->SelectAll(false);
|
|
|