| 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 2cbd7de6968816093c99d8ba205784367265cfe5..5aaabe3aee6e37f34391c743ba85abc7542c3736 100644
|
| --- a/ui/views/controls/textfield/textfield_unittest.cc
|
| +++ b/ui/views/controls/textfield/textfield_unittest.cc
|
| @@ -85,9 +85,41 @@ class TestTextfield : public views::Textfield {
|
| bool OnKeyReleased(const ui::KeyEvent& e) override {
|
| key_received_ = true;
|
| key_handled_ = views::Textfield::OnKeyReleased(e);
|
| + EXPECT_FALSE(key_handled_); // Textfield doesn't override OnKeyReleased.
|
| return key_handled_;
|
| }
|
|
|
| + // On Mac, characters are inserted directly rather than attempting to get a
|
| + // unicode character from the ui::KeyEvent (which isn't always possible).
|
| + // Also, editing commands are translated from AppKit "action messages", which
|
| + // conform to custom keybindings a user may have. For these, count them as
|
| + // both received and handled. If a Mac key event does not map to a character
|
| + // or editing command, it falls back to OnKeyPressed(), which will be logged
|
| + // above as received, but not handled.
|
| +
|
| + // ui::TextInputClient overrides:
|
| + void InsertChar(base::char16 ch, int flags) override {
|
| + views::Textfield::InsertChar(ch, flags);
|
| +#if defined(OS_MACOSX)
|
| + key_received_ = true;
|
| +#endif
|
| + }
|
| +
|
| + void ExecuteEditingCommand(int command_id) override {
|
| + views::Textfield::ExecuteEditingCommand(command_id);
|
| +#if defined(OS_MACOSX)
|
| + key_received_ = true;
|
| + key_handled_ = true;
|
| +#endif
|
| + }
|
| +
|
| + bool HandleAsKeyEventOnly(const ui::KeyEvent& key_event) override {
|
| +#if defined(OS_MACOSX)
|
| + key_received_ = true;
|
| +#endif
|
| + return views::Textfield::HandleAsKeyEventOnly(key_event);
|
| + }
|
| +
|
| bool key_handled() const { return key_handled_; }
|
| bool key_received() const { return key_received_; }
|
|
|
| @@ -182,6 +214,17 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
|
| last_contents_ = new_contents;
|
| }
|
|
|
| + // views::TextfieldController:
|
| + bool HandleKeyEvent(views::Textfield* sender,
|
| + const ui::KeyEvent& key_event) override {
|
| + if (!input_method_->HasMockComposition())
|
| + return false;
|
| +
|
| + input_method_->InsertMockComposition();
|
| + input_method_->ClearMockComposition();
|
| + return true;
|
| + }
|
| +
|
| void OnBeforeUserAction(Textfield* sender) override {
|
| ++on_before_user_action_;
|
| }
|
| @@ -340,6 +383,40 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
|
| SendKeyEvent(key, alt, shift, control, caps);
|
| }
|
|
|
| + // Sends Shift+Delete if supported, otherwise Cmd+X again.
|
| + void SendAlternateCut() {
|
| + if (TestingNativeMac())
|
| + SendKeyEvent(ui::VKEY_X, false, true);
|
| + else
|
| + SendKeyEvent(ui::VKEY_DELETE, true, false);
|
| + }
|
| +
|
| + // Sends Ctrl+Insert if supported, otherwise Cmd+C again.
|
| + void SendAlternateCopy() {
|
| + if (TestingNativeMac())
|
| + SendKeyEvent(ui::VKEY_C, false, true);
|
| + else
|
| + SendKeyEvent(ui::VKEY_INSERT, false, true);
|
| + }
|
| +
|
| + // Sends Shift+Insert if supported, otherwise Cmd+V again.
|
| + void SendAlternatePaste() {
|
| + if (TestingNativeMac())
|
| + SendKeyEvent(ui::VKEY_V, false, true);
|
| + else
|
| + SendKeyEvent(ui::VKEY_INSERT, true, false);
|
| + }
|
| +
|
| + // Most platforms support Ctrl+Y as an alternative to Ctrl+Shift+Z, but on Mac
|
| + // that is bound to "Show full history", so is not mapped as an editing
|
| + // command. So, on Mac, send Cmd+Shift+Z.
|
| + void SendAlternateRedo() {
|
| + if (TestingNativeMac())
|
| + SendKeyEvent(ui::VKEY_Z, true, true);
|
| + else
|
| + SendKeyEvent(ui::VKEY_Y, false, true);
|
| + }
|
| +
|
| View* GetFocusedView() {
|
| return widget_->GetFocusManager()->GetFocusedView();
|
| }
|
| @@ -580,7 +657,7 @@ TEST_F(TextfieldTest, PasswordTest) {
|
| EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_COPY));
|
| textfield_->ExecuteCommand(IDS_APP_COPY, 0);
|
| SendKeyEvent(ui::VKEY_C, false, true);
|
| - SendKeyEvent(ui::VKEY_INSERT, false, true);
|
| + SendAlternateCopy();
|
| EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
| EXPECT_STR_EQ("password", textfield_->text());
|
| // [Shift]+[Delete] should just delete without copying text to the clipboard.
|
| @@ -591,7 +668,7 @@ TEST_F(TextfieldTest, PasswordTest) {
|
| EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE));
|
| textfield_->ExecuteCommand(IDS_APP_PASTE, 0);
|
| SendKeyEvent(ui::VKEY_V, false, true);
|
| - SendKeyEvent(ui::VKEY_INSERT, true, false);
|
| + SendAlternatePaste();
|
| EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
| EXPECT_STR_EQ("foofoofoo", textfield_->text());
|
| }
|
| @@ -643,19 +720,26 @@ TEST_F(TextfieldTest, OnKeyPress) {
|
| EXPECT_TRUE(textfield_->key_handled());
|
| textfield_->clear();
|
|
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + bool shift = false;
|
| + SendHomeEvent(shift);
|
| EXPECT_TRUE(textfield_->key_received());
|
| EXPECT_TRUE(textfield_->key_handled());
|
| textfield_->clear();
|
|
|
| - SendKeyEvent(ui::VKEY_END);
|
| + SendEndEvent(shift);
|
| EXPECT_TRUE(textfield_->key_received());
|
| EXPECT_TRUE(textfield_->key_handled());
|
| textfield_->clear();
|
|
|
| - // F24, up/down key won't be handled.
|
| - SendKeyEvent(ui::VKEY_F24);
|
| + // F20, up/down key won't be handled.
|
| + SendKeyEvent(ui::VKEY_F20);
|
| +#if defined(OS_MACOSX)
|
| + // On Mac, key combinations that don't map to editing commands are forwarded
|
| + // on to the next responder, usually ending up at the window, which will beep.
|
| + EXPECT_FALSE(textfield_->key_received());
|
| +#else
|
| EXPECT_TRUE(textfield_->key_received());
|
| +#endif
|
| EXPECT_FALSE(textfield_->key_handled());
|
| textfield_->clear();
|
|
|
| @@ -727,19 +811,20 @@ TEST_F(TextfieldTest, CursorMovement) {
|
| SendKeyEvent(ui::VKEY_END);
|
|
|
| // Ctrl+Left should move the cursor just before the last word.
|
| - SendKeyEvent(ui::VKEY_LEFT, false, true);
|
| + bool shift = false;
|
| + SendWordEvent(ui::VKEY_LEFT, shift);
|
| SendKeyEvent(ui::VKEY_T);
|
| EXPECT_STR_EQ("one two thre ", textfield_->text());
|
| EXPECT_STR_EQ("one two thre ", last_contents_);
|
|
|
| // Ctrl+Right should move the cursor to the end of the last word.
|
| - SendKeyEvent(ui::VKEY_RIGHT, false, true);
|
| + SendWordEvent(ui::VKEY_RIGHT, shift);
|
| SendKeyEvent(ui::VKEY_E);
|
| EXPECT_STR_EQ("one two three ", textfield_->text());
|
| EXPECT_STR_EQ("one two three ", last_contents_);
|
|
|
| // Ctrl+Right again should move the cursor to the end.
|
| - SendKeyEvent(ui::VKEY_RIGHT, false, true);
|
| + SendWordEvent(ui::VKEY_RIGHT, shift);
|
| SendKeyEvent(ui::VKEY_BACK);
|
| EXPECT_STR_EQ("one two three", textfield_->text());
|
| EXPECT_STR_EQ("one two three", last_contents_);
|
| @@ -748,20 +833,20 @@ TEST_F(TextfieldTest, CursorMovement) {
|
| textfield_->SetText(ASCIIToUTF16(" ne two"));
|
|
|
| // Send the cursor at the beginning.
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + SendHomeEvent(shift);
|
|
|
| // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the
|
| // first word.
|
| - SendKeyEvent(ui::VKEY_RIGHT, false, true);
|
| - SendKeyEvent(ui::VKEY_LEFT, false, true);
|
| + SendWordEvent(ui::VKEY_RIGHT, shift);
|
| + SendWordEvent(ui::VKEY_LEFT, shift);
|
| SendKeyEvent(ui::VKEY_O);
|
| EXPECT_STR_EQ(" one two", textfield_->text());
|
| EXPECT_STR_EQ(" one two", last_contents_);
|
|
|
| // Ctrl+Left to move the cursor to the beginning of the first word.
|
| - SendKeyEvent(ui::VKEY_LEFT, false, true);
|
| + SendWordEvent(ui::VKEY_LEFT, shift);
|
| // Ctrl+Left again should move the cursor back to the very beginning.
|
| - SendKeyEvent(ui::VKEY_LEFT, false, true);
|
| + SendWordEvent(ui::VKEY_LEFT, shift);
|
| SendKeyEvent(ui::VKEY_DELETE);
|
| EXPECT_STR_EQ("one two", textfield_->text());
|
| EXPECT_STR_EQ("one two", last_contents_);
|
| @@ -1039,11 +1124,11 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
|
| EXPECT_STR_EQ("", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("hello world", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("h welloorld", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("h welloorld", textfield_->text());
|
| }
|
|
|
| @@ -1092,11 +1177,11 @@ TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) {
|
| EXPECT_STR_EQ("", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("hello world", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("h worlellod", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("h worlellod", textfield_->text());
|
| }
|
|
|
| @@ -1137,16 +1222,18 @@ TEST_F(TextfieldTest, ReadOnlyTest) {
|
| EXPECT_TRUE(textfield_->enabled());
|
| EXPECT_TRUE(textfield_->IsFocusable());
|
|
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + bool shift = false;
|
| + SendHomeEvent(shift);
|
| EXPECT_EQ(0U, textfield_->GetCursorPosition());
|
| - SendKeyEvent(ui::VKEY_END);
|
| + SendEndEvent(shift);
|
| EXPECT_EQ(9U, textfield_->GetCursorPosition());
|
|
|
| - SendKeyEvent(ui::VKEY_LEFT, false, false);
|
| + SendKeyEvent(ui::VKEY_LEFT, shift, false);
|
| EXPECT_EQ(8U, textfield_->GetCursorPosition());
|
| - SendKeyEvent(ui::VKEY_LEFT, false, true);
|
| + SendWordEvent(ui::VKEY_LEFT, shift);
|
| EXPECT_EQ(5U, textfield_->GetCursorPosition());
|
| - SendKeyEvent(ui::VKEY_LEFT, true, true);
|
| + shift = true;
|
| + SendWordEvent(ui::VKEY_LEFT, shift);
|
| EXPECT_EQ(0U, textfield_->GetCursorPosition());
|
| EXPECT_STR_EQ("read ", textfield_->GetSelectedText());
|
| textfield_->SelectAll(false);
|
| @@ -1157,7 +1244,7 @@ TEST_F(TextfieldTest, ReadOnlyTest) {
|
| EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT));
|
| textfield_->ExecuteCommand(IDS_APP_CUT, 0);
|
| SendKeyEvent(ui::VKEY_X, false, true);
|
| - SendKeyEvent(ui::VKEY_DELETE, true, false);
|
| + SendAlternateCut();
|
| EXPECT_STR_EQ("Test", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
| EXPECT_STR_EQ("read only", textfield_->text());
|
|
|
| @@ -1165,7 +1252,7 @@ TEST_F(TextfieldTest, ReadOnlyTest) {
|
| EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE));
|
| textfield_->ExecuteCommand(IDS_APP_PASTE, 0);
|
| SendKeyEvent(ui::VKEY_V, false, true);
|
| - SendKeyEvent(ui::VKEY_INSERT, true, false);
|
| + SendAlternatePaste();
|
| EXPECT_STR_EQ("read only", textfield_->text());
|
|
|
| // Copy should work normally.
|
| @@ -1177,7 +1264,7 @@ TEST_F(TextfieldTest, ReadOnlyTest) {
|
| SendKeyEvent(ui::VKEY_C, false, true);
|
| EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
| SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test");
|
| - SendKeyEvent(ui::VKEY_INSERT, false, true);
|
| + SendAlternateCopy();
|
| EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
|
|
| // SetText should work even in read only mode.
|
| @@ -1227,7 +1314,7 @@ TEST_F(TextfieldTest, TextInputClientTest) {
|
| textfield_->clear();
|
|
|
| on_before_user_action_ = on_after_user_action_ = 0;
|
| - SendKeyEvent(ui::VKEY_A);
|
| + SendKeyEvent(ui::VKEY_RETURN);
|
| EXPECT_TRUE(textfield_->key_received());
|
| EXPECT_FALSE(textfield_->key_handled());
|
| EXPECT_TRUE(client->HasCompositionText());
|
| @@ -1240,7 +1327,7 @@ TEST_F(TextfieldTest, TextInputClientTest) {
|
| input_method_->SetResultTextForNextKey(UTF8ToUTF16("123"));
|
| on_before_user_action_ = on_after_user_action_ = 0;
|
| textfield_->clear();
|
| - SendKeyEvent(ui::VKEY_A);
|
| + SendKeyEvent(ui::VKEY_RETURN);
|
| EXPECT_TRUE(textfield_->key_received());
|
| EXPECT_FALSE(textfield_->key_handled());
|
| EXPECT_FALSE(client->HasCompositionText());
|
| @@ -1252,7 +1339,7 @@ TEST_F(TextfieldTest, TextInputClientTest) {
|
| input_method_->Clear();
|
| input_method_->SetCompositionTextForNextKey(composition);
|
| textfield_->clear();
|
| - SendKeyEvent(ui::VKEY_A);
|
| + SendKeyEvent(ui::VKEY_RETURN);
|
| EXPECT_TRUE(client->HasCompositionText());
|
| EXPECT_STR_EQ("0123321456789", textfield_->text());
|
|
|
| @@ -1284,11 +1371,20 @@ TEST_F(TextfieldTest, TextInputClientTest) {
|
| EXPECT_EQ(0, on_after_user_action_);
|
|
|
| input_method_->Clear();
|
| +
|
| + // Changing the Textfield to readonly shouldn't change the input client, since
|
| + // it's still required for selections and clipboard copy.
|
| + ui::TextInputClient* text_input_client = textfield_->GetTextInputClient();
|
| + EXPECT_TRUE(text_input_client);
|
| + EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
|
| textfield_->SetReadOnly(true);
|
| EXPECT_TRUE(input_method_->text_input_type_changed());
|
| - EXPECT_FALSE(textfield_->GetTextInputClient());
|
| + EXPECT_EQ(text_input_client, textfield_->GetTextInputClient());
|
| + EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
|
|
|
| textfield_->SetReadOnly(false);
|
| + EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
|
| +
|
| input_method_->Clear();
|
| textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
|
| EXPECT_TRUE(input_method_->text_input_type_changed());
|
| @@ -1303,9 +1399,9 @@ TEST_F(TextfieldTest, UndoRedoTest) {
|
| EXPECT_STR_EQ("", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("a", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("a", textfield_->text());
|
|
|
| // AppendText
|
| @@ -1314,7 +1410,7 @@ TEST_F(TextfieldTest, UndoRedoTest) {
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("a", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
|
|
| // SetText
|
| @@ -1326,9 +1422,9 @@ TEST_F(TextfieldTest, UndoRedoTest) {
|
| EXPECT_STR_EQ("abc", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("abc", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("abc", textfield_->text());
|
| textfield_->SetText(ASCIIToUTF16("123"));
|
| textfield_->SetText(ASCIIToUTF16("123"));
|
| @@ -1345,11 +1441,11 @@ TEST_F(TextfieldTest, UndoRedoTest) {
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("a", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("123", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("1234", textfield_->text());
|
|
|
| // Undoing to the same text shouldn't call ContentsChanged.
|
| @@ -1361,13 +1457,14 @@ TEST_F(TextfieldTest, UndoRedoTest) {
|
| EXPECT_STR_EQ("abc", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("1234", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("abc", textfield_->text());
|
|
|
| // Delete/Backspace
|
| SendKeyEvent(ui::VKEY_BACK);
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + bool shift = false;
|
| + SendHomeEvent(shift);
|
| SendKeyEvent(ui::VKEY_DELETE);
|
| EXPECT_STR_EQ("b", textfield_->text());
|
| SendKeyEvent(ui::VKEY_A, false, true);
|
| @@ -1379,13 +1476,13 @@ TEST_F(TextfieldTest, UndoRedoTest) {
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
| SendKeyEvent(ui::VKEY_Z, false, true);
|
| EXPECT_STR_EQ("abc", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("ab", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("b", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_Y, false, true);
|
| + SendAlternateRedo();
|
| EXPECT_STR_EQ("", textfield_->text());
|
| }
|
|
|
| @@ -1416,7 +1513,7 @@ TEST_F(TextfieldTest, CutCopyPaste) {
|
| // Ensure [Shift]+[Delete] cuts.
|
| textfield_->SetText(ASCIIToUTF16("123"));
|
| textfield_->SelectAll(false);
|
| - SendKeyEvent(ui::VKEY_DELETE, true, false);
|
| + SendAlternateCut();
|
| EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
| EXPECT_STR_EQ("", textfield_->text());
|
| EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard());
|
| @@ -1442,7 +1539,7 @@ TEST_F(TextfieldTest, CutCopyPaste) {
|
| // Ensure [Ctrl]+[Insert] copies.
|
| textfield_->SetText(ASCIIToUTF16("345"));
|
| textfield_->SelectAll(false);
|
| - SendKeyEvent(ui::VKEY_INSERT, false, true);
|
| + SendAlternateCopy();
|
| EXPECT_STR_EQ("345", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE));
|
| EXPECT_STR_EQ("345", textfield_->text());
|
| EXPECT_EQ(ui::CLIPBOARD_TYPE_COPY_PASTE, GetAndResetCopiedToClipboard());
|
| @@ -1456,7 +1553,7 @@ TEST_F(TextfieldTest, CutCopyPaste) {
|
| EXPECT_STR_EQ("abc", textfield_->text());
|
| SendKeyEvent(ui::VKEY_V, false, true);
|
| EXPECT_STR_EQ("abcabc", textfield_->text());
|
| - SendKeyEvent(ui::VKEY_INSERT, true, false);
|
| + SendAlternatePaste();
|
| EXPECT_STR_EQ("abcabcabc", textfield_->text());
|
| SendKeyEvent(ui::VKEY_V, true, false, true, false);
|
| EXPECT_STR_EQ("abcabcabc", textfield_->text());
|
| @@ -1473,7 +1570,11 @@ TEST_F(TextfieldTest, OvertypeMode) {
|
| InitTextfield();
|
| // Overtype mode should be disabled (no-op [Insert]).
|
| textfield_->SetText(ASCIIToUTF16("2"));
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + bool shift = false;
|
| + SendHomeEvent(shift);
|
| + // Note: On Mac, there is no insert key. Insert sends kVK_Help. Currently,
|
| + // since there is no overtype on toolkit-views, the behavior happens to match.
|
| + // However, there's no enable-overtype equivalent key combination on OSX.
|
| SendKeyEvent(ui::VKEY_INSERT);
|
| SendKeyEvent(ui::VKEY_1, false, false);
|
| EXPECT_STR_EQ("12", textfield_->text());
|
| @@ -1651,12 +1752,13 @@ TEST_F(TextfieldTest, HitOutsideTextAreaTest) {
|
| // LTR-RTL string in LTR context.
|
| textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2"));
|
|
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + bool shift = false;
|
| + SendHomeEvent(shift);
|
| gfx::Rect bound = GetCursorBounds();
|
| MouseClick(bound, -10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
|
|
| - SendKeyEvent(ui::VKEY_END);
|
| + SendEndEvent(shift);
|
| bound = GetCursorBounds();
|
| MouseClick(bound, 10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
| @@ -1666,12 +1768,12 @@ TEST_F(TextfieldTest, HitOutsideTextAreaTest) {
|
| // RTL-LTR string in LTR context.
|
| textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab"));
|
|
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + SendHomeEvent(shift);
|
| bound = GetCursorBounds();
|
| MouseClick(bound, 10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
|
|
| - SendKeyEvent(ui::VKEY_END);
|
| + SendEndEvent(shift);
|
| bound = GetCursorBounds();
|
| MouseClick(bound, -10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
| @@ -1685,12 +1787,13 @@ TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) {
|
|
|
| // RTL-LTR string in RTL context.
|
| textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab"));
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + bool shift = false;
|
| + SendHomeEvent(shift);
|
| gfx::Rect bound = GetCursorBounds();
|
| MouseClick(bound, 10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
|
|
| - SendKeyEvent(ui::VKEY_END);
|
| + SendEndEvent(shift);
|
| bound = GetCursorBounds();
|
| MouseClick(bound, -10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
| @@ -1699,12 +1802,12 @@ TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) {
|
|
|
| // LTR-RTL string in RTL context.
|
| textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2"));
|
| - SendKeyEvent(ui::VKEY_HOME);
|
| + SendHomeEvent(shift);
|
| bound = GetCursorBounds();
|
| MouseClick(bound, -10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
|
|
| - SendKeyEvent(ui::VKEY_END);
|
| + SendEndEvent(shift);
|
| bound = GetCursorBounds();
|
| MouseClick(bound, 10);
|
| EXPECT_EQ(bound, GetCursorBounds());
|
| @@ -2040,7 +2143,7 @@ TEST_F(TextfieldTest, DestroyingTextfieldFromOnKeyEvent) {
|
| EXPECT_TRUE(controller.target());
|
|
|
| // Send a key to trigger OnKeyEvent().
|
| - SendKeyEvent('X');
|
| + SendKeyEvent(ui::VKEY_RETURN);
|
|
|
| EXPECT_FALSE(controller.target());
|
| }
|
| @@ -2157,7 +2260,14 @@ TEST_F(TextfieldTouchSelectionTest, TouchSelectionInUnfocusableTextfield) {
|
| textfield_->SetFocusable(true);
|
| }
|
|
|
| -TEST_F(TextfieldTouchSelectionTest, TapOnSelection) {
|
| +// No touch on desktop Mac. Tracked in http://crbug.com/445520.
|
| +#if defined(OS_MACOSX) && !defined(USE_AURA)
|
| +#define MAYBE_TapOnSelection DISABLED_TapOnSelection
|
| +#else
|
| +#define MAYBE_TapOnSelection TapOnSelection
|
| +#endif
|
| +
|
| +TEST_F(TextfieldTouchSelectionTest, MAYBE_TapOnSelection) {
|
| InitTextfield();
|
| textfield_->SetText(ASCIIToUTF16("hello world"));
|
| gfx::Range sel_range(2, 7);
|
|
|