OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 | 136 |
137 virtual void TearDown() { | 137 virtual void TearDown() { |
138 if (widget_) | 138 if (widget_) |
139 widget_->Close(); | 139 widget_->Close(); |
140 ViewsTestBase::TearDown(); | 140 ViewsTestBase::TearDown(); |
141 } | 141 } |
142 | 142 |
143 // TextfieldController: | 143 // TextfieldController: |
144 virtual void ContentsChanged(Textfield* sender, | 144 virtual void ContentsChanged(Textfield* sender, |
145 const string16& new_contents) OVERRIDE { | 145 const string16& new_contents) OVERRIDE { |
146 ASSERT_NE(last_contents_, new_contents); | 146 // Paste calls TextfieldController::ContentsChanged() explicitly even if the |
147 // paste action did not change the content. See http://crbug.com/79002 | |
148 // ASSERT_NE(last_contents_, new_contents); | |
oshima
2013/05/23 17:52:58
Instead of leaving dead code, just explain last_co
msw
2013/05/23 19:08:13
Done.
| |
147 last_contents_ = new_contents; | 149 last_contents_ = new_contents; |
148 } | 150 } |
149 | 151 |
150 virtual bool HandleKeyEvent(Textfield* sender, | 152 virtual bool HandleKeyEvent(Textfield* sender, |
151 const ui::KeyEvent& key_event) OVERRIDE { | 153 const ui::KeyEvent& key_event) OVERRIDE { |
152 // TODO(oshima): figure out how to test the keystroke. | 154 // TODO(oshima): figure out how to test the keystroke. |
153 return false; | 155 return false; |
154 } | 156 } |
155 | 157 |
156 virtual void OnBeforeUserAction(Textfield* sender) OVERRIDE { | 158 virtual void OnBeforeUserAction(Textfield* sender) OVERRIDE { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 textfield_view_->UpdateContextMenu(); | 210 textfield_view_->UpdateContextMenu(); |
209 return textfield_view_->context_menu_contents_.get(); | 211 return textfield_view_->context_menu_contents_.get(); |
210 } | 212 } |
211 | 213 |
212 ui::TouchSelectionController* GetTouchSelectionController() { | 214 ui::TouchSelectionController* GetTouchSelectionController() { |
213 return textfield_view_->touch_selection_controller_.get(); | 215 return textfield_view_->touch_selection_controller_.get(); |
214 } | 216 } |
215 | 217 |
216 protected: | 218 protected: |
217 void SendKeyEvent(ui::KeyboardCode key_code, | 219 void SendKeyEvent(ui::KeyboardCode key_code, |
220 bool alt, | |
218 bool shift, | 221 bool shift, |
219 bool control, | 222 bool control, |
220 bool caps_lock) { | 223 bool caps_lock) { |
221 int flags = (shift ? ui::EF_SHIFT_DOWN : 0) | | 224 int flags = (alt ? ui::EF_ALT_DOWN : 0) | |
222 (control ? ui::EF_CONTROL_DOWN : 0) | | 225 (shift ? ui::EF_SHIFT_DOWN : 0) | |
223 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); | 226 (control ? ui::EF_CONTROL_DOWN : 0) | |
227 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); | |
224 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags, false); | 228 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags, false); |
225 input_method_->DispatchKeyEvent(event); | 229 input_method_->DispatchKeyEvent(event); |
226 } | 230 } |
227 | 231 |
228 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { | 232 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { |
229 SendKeyEvent(key_code, shift, control, false); | 233 SendKeyEvent(key_code, false, shift, control, false); |
230 } | 234 } |
231 | 235 |
232 void SendKeyEvent(ui::KeyboardCode key_code) { | 236 void SendKeyEvent(ui::KeyboardCode key_code) { |
233 SendKeyEvent(key_code, false, false); | 237 SendKeyEvent(key_code, false, false); |
234 } | 238 } |
235 | 239 |
236 void SendKeyEvent(char16 ch) { | 240 void SendKeyEvent(char16 ch) { |
237 if (ch < 0x80) { | 241 if (ch < 0x80) { |
238 ui::KeyboardCode code = | 242 ui::KeyboardCode code = |
239 ch == ' ' ? ui::VKEY_SPACE : | 243 ch == ' ' ? ui::VKEY_SPACE : |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 // On default (en) locale, 'I' should be converted to 'i'. | 449 // On default (en) locale, 'I' should be converted to 'i'. |
446 textfield_->SetText(WideToUTF16(L"I")); | 450 textfield_->SetText(WideToUTF16(L"I")); |
447 EXPECT_EQ(1U, textfield_->GetCursorPosition()); | 451 EXPECT_EQ(1U, textfield_->GetCursorPosition()); |
448 EXPECT_EQ(WideToUTF16(L"i"), model_->GetText()); | 452 EXPECT_EQ(WideToUTF16(L"i"), model_->GetText()); |
449 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); | 453 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); |
450 EXPECT_TRUE(last_contents_.empty()); | 454 EXPECT_TRUE(last_contents_.empty()); |
451 } | 455 } |
452 | 456 |
453 TEST_F(NativeTextfieldViewsTest, KeyTest) { | 457 TEST_F(NativeTextfieldViewsTest, KeyTest) { |
454 InitTextfield(Textfield::STYLE_DEFAULT); | 458 InitTextfield(Textfield::STYLE_DEFAULT); |
455 SendKeyEvent(ui::VKEY_C, true, false); | 459 // Event flags: key, alt, shift, ctrl, caps-lock. |
456 EXPECT_STR_EQ("C", textfield_->text()); | 460 SendKeyEvent(ui::VKEY_T, false, true, false, false); |
457 EXPECT_STR_EQ("C", last_contents_); | 461 SendKeyEvent(ui::VKEY_E, false, false, false, false); |
458 last_contents_.clear(); | 462 SendKeyEvent(ui::VKEY_X, false, true, false, true); |
459 | 463 SendKeyEvent(ui::VKEY_T, false, false, false, true); |
460 SendKeyEvent(ui::VKEY_R, false, false); | 464 SendKeyEvent(ui::VKEY_1, false, true, false, false); |
461 EXPECT_STR_EQ("Cr", textfield_->text()); | 465 SendKeyEvent(ui::VKEY_1, false, false, false, false); |
462 EXPECT_STR_EQ("Cr", last_contents_); | 466 SendKeyEvent(ui::VKEY_1, false, true, false, true); |
463 | 467 SendKeyEvent(ui::VKEY_1, false, false, false, true); |
464 textfield_->SetText(string16()); | 468 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); |
465 SendKeyEvent(ui::VKEY_C, true, false, true); | |
466 SendKeyEvent(ui::VKEY_C, false, false, true); | |
467 SendKeyEvent(ui::VKEY_1, false, false, true); | |
468 SendKeyEvent(ui::VKEY_1, true, false, true); | |
469 SendKeyEvent(ui::VKEY_1, true, false, false); | |
470 EXPECT_STR_EQ("cC1!!", textfield_->text()); | |
471 EXPECT_STR_EQ("cC1!!", last_contents_); | |
472 } | 469 } |
473 | 470 |
474 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { | 471 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { |
475 // Insert a test string in a textfield. | 472 // Insert a test string in a textfield. |
476 InitTextfield(Textfield::STYLE_DEFAULT); | 473 InitTextfield(Textfield::STYLE_DEFAULT); |
477 textfield_->SetText(ASCIIToUTF16("one two three")); | 474 textfield_->SetText(ASCIIToUTF16("one two three")); |
478 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); | 475 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); |
479 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 476 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
480 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 477 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
481 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 478 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 EXPECT_STR_EQ("this is ", textfield_->text()); | 535 EXPECT_STR_EQ("this is ", textfield_->text()); |
539 | 536 |
540 // Select all and replace with "k". | 537 // Select all and replace with "k". |
541 textfield_->SelectAll(false); | 538 textfield_->SelectAll(false); |
542 SendKeyEvent(ui::VKEY_K); | 539 SendKeyEvent(ui::VKEY_K); |
543 EXPECT_STR_EQ("k", textfield_->text()); | 540 EXPECT_STR_EQ("k", textfield_->text()); |
544 | 541 |
545 // Delete the previous word from cursor. | 542 // Delete the previous word from cursor. |
546 textfield_->SetText(ASCIIToUTF16("one two three four")); | 543 textfield_->SetText(ASCIIToUTF16("one two three four")); |
547 SendKeyEvent(ui::VKEY_END); | 544 SendKeyEvent(ui::VKEY_END); |
548 SendKeyEvent(ui::VKEY_BACK, false, true, false); | 545 SendKeyEvent(ui::VKEY_BACK, false, false, true, false); |
549 EXPECT_STR_EQ("one two three ", textfield_->text()); | 546 EXPECT_STR_EQ("one two three ", textfield_->text()); |
550 | 547 |
551 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing | 548 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing |
552 // in windows. | 549 // in windows. |
553 SendKeyEvent(ui::VKEY_LEFT, false, true, false); | 550 SendKeyEvent(ui::VKEY_LEFT, false, false, true, false); |
554 SendKeyEvent(ui::VKEY_BACK, true, true, false); | 551 SendKeyEvent(ui::VKEY_BACK, false, true, true, false); |
555 #if defined(OS_WIN) | 552 #if defined(OS_WIN) |
556 EXPECT_STR_EQ("one two three ", textfield_->text()); | 553 EXPECT_STR_EQ("one two three ", textfield_->text()); |
557 #else | 554 #else |
558 EXPECT_STR_EQ("three ", textfield_->text()); | 555 EXPECT_STR_EQ("three ", textfield_->text()); |
559 #endif | 556 #endif |
560 | 557 |
561 // Delete the next word from cursor. | 558 // Delete the next word from cursor. |
562 textfield_->SetText(ASCIIToUTF16("one two three four")); | 559 textfield_->SetText(ASCIIToUTF16("one two three four")); |
563 SendKeyEvent(ui::VKEY_HOME); | 560 SendKeyEvent(ui::VKEY_HOME); |
564 SendKeyEvent(ui::VKEY_DELETE, false, true, false); | 561 SendKeyEvent(ui::VKEY_DELETE, false, false, true, false); |
565 EXPECT_STR_EQ(" two three four", textfield_->text()); | 562 EXPECT_STR_EQ(" two three four", textfield_->text()); |
566 | 563 |
567 // Delete upto the end of the buffer from cursor in chromeos, do nothing | 564 // Delete upto the end of the buffer from cursor in chromeos, do nothing |
568 // in windows. | 565 // in windows. |
569 SendKeyEvent(ui::VKEY_RIGHT, false, true, false); | 566 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); |
570 SendKeyEvent(ui::VKEY_DELETE, true, true, false); | 567 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); |
571 #if defined(OS_WIN) | 568 #if defined(OS_WIN) |
572 EXPECT_STR_EQ(" two three four", textfield_->text()); | 569 EXPECT_STR_EQ(" two three four", textfield_->text()); |
573 #else | 570 #else |
574 EXPECT_STR_EQ(" two", textfield_->text()); | 571 EXPECT_STR_EQ(" two", textfield_->text()); |
575 #endif | 572 #endif |
576 } | 573 } |
577 | 574 |
578 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 575 TEST_F(NativeTextfieldViewsTest, PasswordTest) { |
579 InitTextfield(Textfield::STYLE_OBSCURED); | 576 InitTextfield(Textfield::STYLE_OBSCURED); |
580 | |
581 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 577 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
578 EXPECT_TRUE(textfield_->enabled()); | |
579 EXPECT_TRUE(textfield_->focusable()); | |
582 | 580 |
583 last_contents_.clear(); | 581 last_contents_.clear(); |
584 textfield_->SetText(ASCIIToUTF16("my password")); | 582 textfield_->SetText(ASCIIToUTF16("password")); |
585 // Just to make sure the text() and callback returns | 583 // Ensure text() and the callback returns the actual text instead of "*". |
586 // the actual text instead of "*". | 584 EXPECT_STR_EQ("password", textfield_->text()); |
587 EXPECT_STR_EQ("my password", textfield_->text()); | |
588 EXPECT_TRUE(last_contents_.empty()); | 585 EXPECT_TRUE(last_contents_.empty()); |
586 model_->SelectAll(false); | |
587 SetClipboardText("foo"); | |
589 | 588 |
590 // Cut and copy should be disabled in the context menu. | 589 // Cut and copy should be disabled. |
591 model_->SelectAll(false); | 590 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); |
592 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_CUT)); | 591 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); |
593 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_COPY)); | 592 SendKeyEvent(ui::VKEY_X, false, true); |
593 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | |
594 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | |
595 SendKeyEvent(ui::VKEY_C, false, true); | |
596 SendKeyEvent(ui::VKEY_INSERT, false, true); | |
597 EXPECT_STR_EQ("foo", string16(GetClipboardText())); | |
598 EXPECT_STR_EQ("password", textfield_->text()); | |
594 | 599 |
595 // Cut and copy keyboard shortcuts and menu commands should do nothing. | 600 // Paste should work normally. |
596 SetClipboardText("foo"); | 601 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); |
597 SendKeyEvent(ui::VKEY_C, false, true); | 602 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); |
598 SendKeyEvent(ui::VKEY_X, false, true); | 603 SendKeyEvent(ui::VKEY_V, false, true); |
599 ExecuteCommand(IDS_APP_COPY, 0); | 604 SendKeyEvent(ui::VKEY_INSERT, true, false); |
600 ExecuteCommand(IDS_APP_CUT, 0); | |
601 EXPECT_STR_EQ("foo", string16(GetClipboardText())); | 605 EXPECT_STR_EQ("foo", string16(GetClipboardText())); |
602 EXPECT_STR_EQ("my password", textfield_->text()); | 606 EXPECT_STR_EQ("foofoofoo", textfield_->text()); |
603 } | 607 } |
604 | 608 |
605 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { | 609 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { |
606 InitTextfield(Textfield::STYLE_DEFAULT); | 610 InitTextfield(Textfield::STYLE_DEFAULT); |
607 | 611 |
608 // Defaults to TEXT | 612 // Defaults to TEXT |
609 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 613 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
610 | 614 |
611 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. | 615 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. |
612 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 616 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1139 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, | 1143 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, |
1140 ui::EF_LEFT_MOUSE_BUTTON); | 1144 ui::EF_LEFT_MOUSE_BUTTON); |
1141 textfield_view_->OnMouseDragged(drag); | 1145 textfield_view_->OnMouseDragged(drag); |
1142 textfield_view_->OnMouseReleased(release); | 1146 textfield_view_->OnMouseReleased(release); |
1143 textfield_view_->OnDragDone(); | 1147 textfield_view_->OnDragDone(); |
1144 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 1148 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
1145 } | 1149 } |
1146 | 1150 |
1147 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 1151 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { |
1148 InitTextfield(Textfield::STYLE_DEFAULT); | 1152 InitTextfield(Textfield::STYLE_DEFAULT); |
1149 textfield_->SetText(ASCIIToUTF16(" one two three ")); | 1153 textfield_->SetText(ASCIIToUTF16("read only")); |
1150 textfield_->SetReadOnly(true); | 1154 textfield_->SetReadOnly(true); |
1155 EXPECT_TRUE(textfield_->enabled()); | |
1156 EXPECT_TRUE(textfield_->focusable()); | |
1157 | |
1151 SendKeyEvent(ui::VKEY_HOME); | 1158 SendKeyEvent(ui::VKEY_HOME); |
1152 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1159 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
1153 | |
1154 SendKeyEvent(ui::VKEY_END); | 1160 SendKeyEvent(ui::VKEY_END); |
1155 EXPECT_EQ(15U, textfield_->GetCursorPosition()); | 1161 EXPECT_EQ(9U, textfield_->GetCursorPosition()); |
1156 | 1162 |
1157 SendKeyEvent(ui::VKEY_LEFT, false, false); | 1163 SendKeyEvent(ui::VKEY_LEFT, false, false); |
1158 EXPECT_EQ(14U, textfield_->GetCursorPosition()); | 1164 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
1165 SendKeyEvent(ui::VKEY_LEFT, false, true); | |
1166 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | |
1167 SendKeyEvent(ui::VKEY_LEFT, true, true); | |
1168 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | |
1169 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); | |
1170 textfield_->SelectAll(false); | |
1171 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); | |
1159 | 1172 |
1160 SendKeyEvent(ui::VKEY_LEFT, false, true); | 1173 // Cut should be disabled. |
1161 EXPECT_EQ(9U, textfield_->GetCursorPosition()); | 1174 SetClipboardText("Test"); |
1175 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | |
1176 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | |
1177 SendKeyEvent(ui::VKEY_X, false, true); | |
1178 EXPECT_STR_EQ("Test", string16(GetClipboardText())); | |
1179 EXPECT_STR_EQ("read only", textfield_->text()); | |
1162 | 1180 |
1163 SendKeyEvent(ui::VKEY_LEFT, true, true); | 1181 // Paste should be disabled. |
1164 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | 1182 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); |
1165 EXPECT_STR_EQ("two ", textfield_->GetSelectedText()); | 1183 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); |
1184 SendKeyEvent(ui::VKEY_V, false, true); | |
1185 SendKeyEvent(ui::VKEY_INSERT, true, false); | |
1186 EXPECT_STR_EQ("read only", textfield_->text()); | |
1166 | 1187 |
1167 textfield_->SelectAll(false); | 1188 // Copy should work normally. |
1168 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); | |
1169 | |
1170 // CUT&PASTE does not work, but COPY works | |
1171 SetClipboardText("Test"); | 1189 SetClipboardText("Test"); |
1172 SendKeyEvent(ui::VKEY_X, false, true); | 1190 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); |
1173 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); | 1191 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); |
1174 string16 str(GetClipboardText()); | 1192 EXPECT_STR_EQ("read only", string16(GetClipboardText())); |
1175 EXPECT_STR_NE(" one two three ", str); | 1193 SetClipboardText("Test"); |
1176 | |
1177 SendKeyEvent(ui::VKEY_C, false, true); | 1194 SendKeyEvent(ui::VKEY_C, false, true); |
1178 ui::Clipboard::GetForCurrentThread()-> | 1195 EXPECT_STR_EQ("read only", string16(GetClipboardText())); |
1179 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); | 1196 SetClipboardText("Test"); |
1180 EXPECT_STR_EQ(" one two three ", str); | 1197 SendKeyEvent(ui::VKEY_INSERT, false, true); |
1198 EXPECT_STR_EQ("read only", string16(GetClipboardText())); | |
1181 | 1199 |
1182 // SetText should work even in read only mode. | 1200 // SetText should work even in read only mode. |
1183 textfield_->SetText(ASCIIToUTF16(" four five six ")); | 1201 textfield_->SetText(ASCIIToUTF16(" four five six ")); |
1184 EXPECT_STR_EQ(" four five six ", textfield_->text()); | 1202 EXPECT_STR_EQ(" four five six ", textfield_->text()); |
1185 | 1203 |
1186 // Paste shouldn't work. | |
1187 SendKeyEvent(ui::VKEY_V, false, true); | |
1188 EXPECT_STR_EQ(" four five six ", textfield_->text()); | |
1189 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | |
1190 | |
1191 textfield_->SelectAll(false); | 1204 textfield_->SelectAll(false); |
1192 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1205 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1193 | 1206 |
1194 // Text field is unmodifiable and selection shouldn't change. | 1207 // Text field is unmodifiable and selection shouldn't change. |
1195 SendKeyEvent(ui::VKEY_DELETE); | 1208 SendKeyEvent(ui::VKEY_DELETE); |
1196 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1209 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1197 SendKeyEvent(ui::VKEY_BACK); | 1210 SendKeyEvent(ui::VKEY_BACK); |
1198 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1211 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
1199 SendKeyEvent(ui::VKEY_T); | 1212 SendKeyEvent(ui::VKEY_T); |
1200 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1213 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1393 SendKeyEvent(ui::VKEY_Y, false, true); | 1406 SendKeyEvent(ui::VKEY_Y, false, true); |
1394 EXPECT_STR_EQ("ab", textfield_->text()); | 1407 EXPECT_STR_EQ("ab", textfield_->text()); |
1395 SendKeyEvent(ui::VKEY_Y, false, true); | 1408 SendKeyEvent(ui::VKEY_Y, false, true); |
1396 EXPECT_STR_EQ("b", textfield_->text()); | 1409 EXPECT_STR_EQ("b", textfield_->text()); |
1397 SendKeyEvent(ui::VKEY_Y, false, true); | 1410 SendKeyEvent(ui::VKEY_Y, false, true); |
1398 EXPECT_STR_EQ("", textfield_->text()); | 1411 EXPECT_STR_EQ("", textfield_->text()); |
1399 SendKeyEvent(ui::VKEY_Y, false, true); | 1412 SendKeyEvent(ui::VKEY_Y, false, true); |
1400 EXPECT_STR_EQ("", textfield_->text()); | 1413 EXPECT_STR_EQ("", textfield_->text()); |
1401 } | 1414 } |
1402 | 1415 |
1403 TEST_F(NativeTextfieldViewsTest, CopyPasteShortcuts) { | 1416 TEST_F(NativeTextfieldViewsTest, CutCopyPaste) { |
1404 InitTextfield(Textfield::STYLE_DEFAULT); | 1417 InitTextfield(Textfield::STYLE_DEFAULT); |
1405 // Ensure [Ctrl]+[c] copies and [Ctrl]+[v] pastes. | 1418 |
1406 textfield_->SetText(ASCIIToUTF16("abc")); | 1419 // Ensure IDS_APP_CUT cuts. |
1420 textfield_->SetText(ASCIIToUTF16("123")); | |
1407 textfield_->SelectAll(false); | 1421 textfield_->SelectAll(false); |
1422 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | |
1423 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | |
1424 EXPECT_STR_EQ("123", string16(GetClipboardText())); | |
1425 EXPECT_STR_EQ("", textfield_->text()); | |
1426 | |
1427 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. | |
1428 textfield_->SetText(ASCIIToUTF16("456")); | |
1429 textfield_->SelectAll(false); | |
1430 SendKeyEvent(ui::VKEY_X, true, false, true, false); | |
1431 EXPECT_STR_EQ("123", string16(GetClipboardText())); | |
1432 EXPECT_STR_EQ("456", textfield_->text()); | |
1433 SendKeyEvent(ui::VKEY_X, false, true); | |
1434 EXPECT_STR_EQ("456", string16(GetClipboardText())); | |
1435 EXPECT_STR_EQ("", textfield_->text()); | |
1436 | |
1437 // Ensure IDS_APP_COPY copies. | |
1438 textfield_->SetText(ASCIIToUTF16("789")); | |
1439 textfield_->SelectAll(false); | |
1440 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | |
1441 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | |
1442 EXPECT_STR_EQ("789", string16(GetClipboardText())); | |
1443 | |
1444 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | |
1445 textfield_->SetText(ASCIIToUTF16("012")); | |
1446 textfield_->SelectAll(false); | |
1447 SendKeyEvent(ui::VKEY_C, true, false, true, false); | |
1448 EXPECT_STR_EQ("789", string16(GetClipboardText())); | |
1408 SendKeyEvent(ui::VKEY_C, false, true); | 1449 SendKeyEvent(ui::VKEY_C, false, true); |
1409 EXPECT_STR_EQ("abc", string16(GetClipboardText())); | 1450 EXPECT_STR_EQ("012", string16(GetClipboardText())); |
1410 SendKeyEvent(ui::VKEY_HOME); | 1451 |
1452 // Ensure [Ctrl]+[Insert] copies. | |
1453 textfield_->SetText(ASCIIToUTF16("345")); | |
1454 textfield_->SelectAll(false); | |
1455 SendKeyEvent(ui::VKEY_INSERT, false, true); | |
1456 EXPECT_STR_EQ("345", string16(GetClipboardText())); | |
1457 EXPECT_STR_EQ("345", textfield_->text()); | |
1458 | |
1459 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; | |
1460 // also ensure that [Ctrl]+[Alt]+[V] does nothing. | |
1461 SetClipboardText("abc"); | |
1462 textfield_->SetText(string16()); | |
1463 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); | |
1464 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); | |
1465 EXPECT_STR_EQ("abc", textfield_->text()); | |
1411 SendKeyEvent(ui::VKEY_V, false, true); | 1466 SendKeyEvent(ui::VKEY_V, false, true); |
1412 EXPECT_STR_EQ("abcabc", textfield_->text()); | 1467 EXPECT_STR_EQ("abcabc", textfield_->text()); |
1468 SendKeyEvent(ui::VKEY_INSERT, true, false); | |
1469 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | |
1470 SendKeyEvent(ui::VKEY_V, true, false, true, false); | |
1471 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | |
1413 | 1472 |
1414 // Ensure [Ctrl]+[Insert] copies and [Shift]+[Insert] pastes. | |
1415 textfield_->SetText(ASCIIToUTF16("123")); | |
1416 textfield_->SelectAll(false); | |
1417 SendKeyEvent(ui::VKEY_INSERT, false, true); | |
1418 EXPECT_STR_EQ("123", string16(GetClipboardText())); | |
1419 SendKeyEvent(ui::VKEY_HOME); | |
1420 SendKeyEvent(ui::VKEY_INSERT, true, false); | |
1421 EXPECT_STR_EQ("123123", textfield_->text()); | |
1422 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. | 1473 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. |
1423 textfield_->SelectAll(false); | 1474 textfield_->SelectAll(false); |
1424 SendKeyEvent(ui::VKEY_INSERT, true, true); | 1475 SendKeyEvent(ui::VKEY_INSERT, true, true); |
1425 EXPECT_STR_EQ("123", string16(GetClipboardText())); | 1476 EXPECT_STR_EQ("abc", string16(GetClipboardText())); |
1426 EXPECT_STR_EQ("123123", textfield_->text()); | 1477 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
1427 } | 1478 } |
1428 | 1479 |
1429 TEST_F(NativeTextfieldViewsTest, OvertypeMode) { | 1480 TEST_F(NativeTextfieldViewsTest, OvertypeMode) { |
1430 InitTextfield(Textfield::STYLE_DEFAULT); | 1481 InitTextfield(Textfield::STYLE_DEFAULT); |
1431 // Overtype mode should be disabled (no-op [Insert]). | 1482 // Overtype mode should be disabled (no-op [Insert]). |
1432 textfield_->SetText(ASCIIToUTF16("2")); | 1483 textfield_->SetText(ASCIIToUTF16("2")); |
1433 SendKeyEvent(ui::VKEY_HOME); | 1484 SendKeyEvent(ui::VKEY_HOME); |
1434 SendKeyEvent(ui::VKEY_INSERT); | 1485 SendKeyEvent(ui::VKEY_INSERT); |
1435 SendKeyEvent(ui::VKEY_1, false, false); | 1486 SendKeyEvent(ui::VKEY_1, false, false); |
1436 EXPECT_STR_EQ("12", textfield_->text()); | 1487 EXPECT_STR_EQ("12", textfield_->text()); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1870 textfield_view_->OnGestureEvent(&tap_down); | 1921 textfield_view_->OnGestureEvent(&tap_down); |
1871 // Create a new long press event since the previous one is not marked handled. | 1922 // Create a new long press event since the previous one is not marked handled. |
1872 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0); | 1923 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0); |
1873 textfield_view_->OnGestureEvent(&long_press2); | 1924 textfield_view_->OnGestureEvent(&long_press2); |
1874 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1925 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
1875 EXPECT_FALSE(GetTouchSelectionController()); | 1926 EXPECT_FALSE(GetTouchSelectionController()); |
1876 } | 1927 } |
1877 #endif | 1928 #endif |
1878 | 1929 |
1879 } // namespace views | 1930 } // namespace views |
OLD | NEW |