| OLD | NEW |
| 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.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 GestureEventForTest(ui::EventType type, int x, int y, float delta_x, | 102 GestureEventForTest(ui::EventType type, int x, int y, float delta_x, |
| 103 float delta_y) | 103 float delta_y) |
| 104 : GestureEvent(type, x, y, 0, base::TimeDelta(), | 104 : GestureEvent(type, x, y, 0, base::TimeDelta(), |
| 105 ui::GestureEventDetails(type, delta_x, delta_y), 0) { | 105 ui::GestureEventDetails(type, delta_x, delta_y), 0) { |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); | 109 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 base::string16 GetClipboardText(ui::ClipboardType type) { |
| 113 base::string16 text; |
| 114 ui::Clipboard::GetForCurrentThread()->ReadText(type, &text); |
| 115 return text; |
| 116 } |
| 117 |
| 118 void SetClipboardText(ui::ClipboardType type, const std::string& text) { |
| 119 ui::ScopedClipboardWriter(ui::Clipboard::GetForCurrentThread(), type) |
| 120 .WriteText(ASCIIToUTF16(text)); |
| 121 } |
| 122 |
| 112 } // namespace | 123 } // namespace |
| 113 | 124 |
| 114 namespace views { | 125 namespace views { |
| 115 | 126 |
| 116 class TextfieldTest : public ViewsTestBase, public TextfieldController { | 127 class TextfieldTest : public ViewsTestBase, public TextfieldController { |
| 117 public: | 128 public: |
| 118 TextfieldTest() | 129 TextfieldTest() |
| 119 : widget_(NULL), | 130 : widget_(NULL), |
| 120 textfield_(NULL), | 131 textfield_(NULL), |
| 121 model_(NULL), | 132 model_(NULL), |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 ch == ' ' ? ui::VKEY_SPACE : | 241 ch == ' ' ? ui::VKEY_SPACE : |
| 231 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); | 242 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); |
| 232 SendKeyEvent(code); | 243 SendKeyEvent(code); |
| 233 } else { | 244 } else { |
| 234 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); | 245 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); |
| 235 event.set_character(ch); | 246 event.set_character(ch); |
| 236 input_method_->DispatchKeyEvent(event); | 247 input_method_->DispatchKeyEvent(event); |
| 237 } | 248 } |
| 238 } | 249 } |
| 239 | 250 |
| 240 base::string16 GetClipboardText() const { | |
| 241 base::string16 text; | |
| 242 ui::Clipboard::GetForCurrentThread()-> | |
| 243 ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &text); | |
| 244 return text; | |
| 245 } | |
| 246 | |
| 247 void SetClipboardText(const std::string& text) { | |
| 248 ui::ScopedClipboardWriter clipboard_writer( | |
| 249 ui::Clipboard::GetForCurrentThread(), | |
| 250 ui::CLIPBOARD_TYPE_COPY_PASTE); | |
| 251 clipboard_writer.WriteText(ASCIIToUTF16(text)); | |
| 252 } | |
| 253 | |
| 254 View* GetFocusedView() { | 251 View* GetFocusedView() { |
| 255 return widget_->GetFocusManager()->GetFocusedView(); | 252 return widget_->GetFocusManager()->GetFocusedView(); |
| 256 } | 253 } |
| 257 | 254 |
| 258 int GetCursorPositionX(int cursor_pos) { | 255 int GetCursorPositionX(int cursor_pos) { |
| 259 return textfield_->GetRenderText()->GetCursorBounds( | 256 return textfield_->GetRenderText()->GetCursorBounds( |
| 260 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); | 257 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); |
| 261 } | 258 } |
| 262 | 259 |
| 263 // Get the current cursor bounds. | 260 // Get the current cursor bounds. |
| 264 gfx::Rect GetCursorBounds() { | 261 gfx::Rect GetCursorBounds() { |
| 265 return textfield_->GetRenderText()->GetUpdatedCursorBounds(); | 262 return textfield_->GetRenderText()->GetUpdatedCursorBounds(); |
| 266 } | 263 } |
| 267 | 264 |
| 268 // Get the cursor bounds of |sel|. | 265 // Get the cursor bounds of |sel|. |
| 269 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) { | 266 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) { |
| 270 return textfield_->GetRenderText()->GetCursorBounds(sel, true); | 267 return textfield_->GetRenderText()->GetCursorBounds(sel, true); |
| 271 } | 268 } |
| 272 | 269 |
| 273 gfx::Rect GetDisplayRect() { | 270 gfx::Rect GetDisplayRect() { |
| 274 return textfield_->GetRenderText()->display_rect(); | 271 return textfield_->GetRenderText()->display_rect(); |
| 275 } | 272 } |
| 276 | 273 |
| 277 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and | 274 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and |
| 278 // y-axis is in the middle of |bound|'s vertical range. | 275 // y-axis is in the middle of |bound|'s vertical range. |
| 279 void MouseClick(const gfx::Rect bound, int x_offset) { | 276 void MouseClick(const gfx::Rect bound, int x_offset) { |
| 280 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); | 277 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); |
| 281 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 278 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
| 282 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 279 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 283 textfield_->OnMousePressed(click); | 280 textfield_->OnMousePressed(click); |
| 284 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, | 281 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, |
| 285 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 282 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 286 textfield_->OnMouseReleased(release); | 283 textfield_->OnMouseReleased(release); |
| 287 } | 284 } |
| 288 | 285 |
| 289 // This is to avoid double/triple click. | 286 // This is to avoid double/triple click. |
| 290 void NonClientMouseClick() { | 287 void NonClientMouseClick() { |
| 291 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 288 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 292 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 289 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 293 ui::EF_LEFT_MOUSE_BUTTON); | 290 ui::EF_LEFT_MOUSE_BUTTON); |
| 294 textfield_->OnMousePressed(click); | 291 textfield_->OnMousePressed(click); |
| 295 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 292 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 296 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 293 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 297 ui::EF_LEFT_MOUSE_BUTTON); | 294 ui::EF_LEFT_MOUSE_BUTTON); |
| 298 textfield_->OnMouseReleased(release); | 295 textfield_->OnMouseReleased(release); |
| 299 } | 296 } |
| 300 | 297 |
| 301 // Wrap for visibility in test classes. | |
| 302 ui::TextInputType GetTextInputType() { | |
| 303 return textfield_->GetTextInputType(); | |
| 304 } | |
| 305 | |
| 306 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 298 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
| 307 bool can_undo, | 299 bool can_undo, |
| 308 ui::MenuModel* menu) { | 300 ui::MenuModel* menu) { |
| 309 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); | 301 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); |
| 310 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); | 302 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); |
| 311 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); | 303 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); |
| 312 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); | 304 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); |
| 313 EXPECT_NE(GetClipboardText().empty(), menu->IsEnabledAt(4 /* PASTE */)); | 305 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), |
| 306 menu->IsEnabledAt(4 /* PASTE */)); |
| 314 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 307 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
| 315 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); | 308 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); |
| 316 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); | 309 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); |
| 317 } | 310 } |
| 318 | 311 |
| 319 // We need widget to populate wrapper class. | 312 // We need widget to populate wrapper class. |
| 320 Widget* widget_; | 313 Widget* widget_; |
| 321 | 314 |
| 322 TestTextfield* textfield_; | 315 TestTextfield* textfield_; |
| 323 TextfieldModel* model_; | 316 TextfieldModel* model_; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 #if defined(OS_LINUX) | 451 #if defined(OS_LINUX) |
| 459 EXPECT_STR_EQ(" two", textfield_->text()); | 452 EXPECT_STR_EQ(" two", textfield_->text()); |
| 460 #else | 453 #else |
| 461 EXPECT_STR_EQ(" two three four", textfield_->text()); | 454 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 462 #endif | 455 #endif |
| 463 } | 456 } |
| 464 | 457 |
| 465 TEST_F(TextfieldTest, PasswordTest) { | 458 TEST_F(TextfieldTest, PasswordTest) { |
| 466 InitTextfield(); | 459 InitTextfield(); |
| 467 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 460 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 468 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 461 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 469 EXPECT_TRUE(textfield_->enabled()); | 462 EXPECT_TRUE(textfield_->enabled()); |
| 470 EXPECT_TRUE(textfield_->IsFocusable()); | 463 EXPECT_TRUE(textfield_->IsFocusable()); |
| 471 | 464 |
| 472 last_contents_.clear(); | 465 last_contents_.clear(); |
| 473 textfield_->SetText(ASCIIToUTF16("password")); | 466 textfield_->SetText(ASCIIToUTF16("password")); |
| 474 // Ensure text() and the callback returns the actual text instead of "*". | 467 // Ensure text() and the callback returns the actual text instead of "*". |
| 475 EXPECT_STR_EQ("password", textfield_->text()); | 468 EXPECT_STR_EQ("password", textfield_->text()); |
| 476 EXPECT_TRUE(last_contents_.empty()); | 469 EXPECT_TRUE(last_contents_.empty()); |
| 477 model_->SelectAll(false); | 470 model_->SelectAll(false); |
| 478 SetClipboardText("foo"); | 471 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); |
| 479 | 472 |
| 480 // Cut and copy should be disabled. | 473 // Cut and copy should be disabled. |
| 481 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 474 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 482 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 475 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 483 SendKeyEvent(ui::VKEY_X, false, true); | 476 SendKeyEvent(ui::VKEY_X, false, true); |
| 484 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 477 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 485 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 478 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 486 SendKeyEvent(ui::VKEY_C, false, true); | 479 SendKeyEvent(ui::VKEY_C, false, true); |
| 487 SendKeyEvent(ui::VKEY_INSERT, false, true); | 480 SendKeyEvent(ui::VKEY_INSERT, false, true); |
| 488 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); | 481 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 489 EXPECT_STR_EQ("password", textfield_->text()); | 482 EXPECT_STR_EQ("password", textfield_->text()); |
| 490 // [Shift]+[Delete] should just delete without copying text to the clipboard. | 483 // [Shift]+[Delete] should just delete without copying text to the clipboard. |
| 491 textfield_->SelectAll(false); | 484 textfield_->SelectAll(false); |
| 492 SendKeyEvent(ui::VKEY_DELETE, true, false); | 485 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 493 | 486 |
| 494 // Paste should work normally. | 487 // Paste should work normally. |
| 495 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 488 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 496 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 489 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 497 SendKeyEvent(ui::VKEY_V, false, true); | 490 SendKeyEvent(ui::VKEY_V, false, true); |
| 498 SendKeyEvent(ui::VKEY_INSERT, true, false); | 491 SendKeyEvent(ui::VKEY_INSERT, true, false); |
| 499 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); | 492 EXPECT_STR_EQ("foo", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 500 EXPECT_STR_EQ("foofoofoo", textfield_->text()); | 493 EXPECT_STR_EQ("foofoofoo", textfield_->text()); |
| 501 } | 494 } |
| 502 | 495 |
| 503 TEST_F(TextfieldTest, TextInputType) { | 496 TEST_F(TextfieldTest, TextInputType) { |
| 504 InitTextfield(); | 497 InitTextfield(); |
| 505 | 498 |
| 506 // Defaults to TEXT | 499 // Defaults to TEXT |
| 507 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 500 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, textfield_->GetTextInputType()); |
| 508 | 501 |
| 509 // And can be set. | 502 // And can be set. |
| 510 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 503 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
| 511 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 504 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, textfield_->GetTextInputType()); |
| 512 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 505 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 513 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 506 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 514 | 507 |
| 515 // Readonly textfields have type NONE | 508 // Readonly textfields have type NONE |
| 516 textfield_->SetReadOnly(true); | 509 textfield_->SetReadOnly(true); |
| 517 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 510 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, textfield_->GetTextInputType()); |
| 518 | 511 |
| 519 textfield_->SetReadOnly(false); | 512 textfield_->SetReadOnly(false); |
| 520 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 513 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 521 | 514 |
| 522 // As do disabled textfields | 515 // As do disabled textfields |
| 523 textfield_->SetEnabled(false); | 516 textfield_->SetEnabled(false); |
| 524 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 517 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, textfield_->GetTextInputType()); |
| 525 | 518 |
| 526 textfield_->SetEnabled(true); | 519 textfield_->SetEnabled(true); |
| 527 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 520 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, textfield_->GetTextInputType()); |
| 528 } | 521 } |
| 529 | 522 |
| 530 TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { | 523 TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { |
| 531 InitTextfield(); | 524 InitTextfield(); |
| 532 | 525 |
| 533 // Character keys will be handled by input method. | 526 // Character keys will be handled by input method. |
| 534 SendKeyEvent(ui::VKEY_A); | 527 SendKeyEvent(ui::VKEY_A); |
| 535 EXPECT_TRUE(textfield_->key_received()); | 528 EXPECT_TRUE(textfield_->key_received()); |
| 536 EXPECT_FALSE(textfield_->key_handled()); | 529 EXPECT_FALSE(textfield_->key_handled()); |
| 537 textfield_->clear(); | 530 textfield_->clear(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 widget_->GetFocusManager()->AdvanceFocus(true); | 653 widget_->GetFocusManager()->AdvanceFocus(true); |
| 661 EXPECT_EQ(1, GetFocusedView()->id()); | 654 EXPECT_EQ(1, GetFocusedView()->id()); |
| 662 // Cycle back to the last textfield. | 655 // Cycle back to the last textfield. |
| 663 widget_->GetFocusManager()->AdvanceFocus(true); | 656 widget_->GetFocusManager()->AdvanceFocus(true); |
| 664 EXPECT_EQ(3, GetFocusedView()->id()); | 657 EXPECT_EQ(3, GetFocusedView()->id()); |
| 665 | 658 |
| 666 // Request focus should still work. | 659 // Request focus should still work. |
| 667 textfield_->RequestFocus(); | 660 textfield_->RequestFocus(); |
| 668 EXPECT_EQ(1, GetFocusedView()->id()); | 661 EXPECT_EQ(1, GetFocusedView()->id()); |
| 669 | 662 |
| 670 // Test if clicking on textfield view sets the focus to textfield_. | 663 // Test if clicking on textfield view sets the focus. |
| 671 widget_->GetFocusManager()->AdvanceFocus(true); | 664 widget_->GetFocusManager()->AdvanceFocus(true); |
| 672 EXPECT_EQ(3, GetFocusedView()->id()); | 665 EXPECT_EQ(3, GetFocusedView()->id()); |
| 673 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 666 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 674 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 667 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 675 textfield_->OnMousePressed(click); | 668 textfield_->OnMousePressed(click); |
| 676 EXPECT_EQ(1, GetFocusedView()->id()); | 669 EXPECT_EQ(1, GetFocusedView()->id()); |
| 677 } | 670 } |
| 678 | 671 |
| 679 TEST_F(TextfieldTest, ContextMenuDisplayTest) { | 672 TEST_F(TextfieldTest, ContextMenuDisplayTest) { |
| 680 InitTextfield(); | 673 InitTextfield(); |
| 681 EXPECT_TRUE(textfield_->context_menu_controller()); | 674 EXPECT_TRUE(textfield_->context_menu_controller()); |
| 682 textfield_->SetText(ASCIIToUTF16("hello world")); | 675 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 683 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); | 676 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 684 textfield_->ClearEditHistory(); | 677 textfield_->ClearEditHistory(); |
| 685 EXPECT_TRUE(GetContextMenuModel()); | 678 EXPECT_TRUE(GetContextMenuModel()); |
| 686 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); | 679 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); |
| 687 | 680 |
| 688 textfield_->SelectAll(false); | 681 textfield_->SelectAll(false); |
| 689 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); | 682 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); |
| 690 | 683 |
| 691 SendKeyEvent(ui::VKEY_T); | 684 SendKeyEvent(ui::VKEY_T); |
| 692 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); | 685 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); |
| 693 | 686 |
| 694 textfield_->SelectAll(false); | 687 textfield_->SelectAll(false); |
| 695 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 688 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
| 696 | 689 |
| 697 // Exercise the "paste enabled?" check in the verifier. | 690 // Exercise the "paste enabled?" check in the verifier. |
| 698 SetClipboardText("Test"); | 691 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 699 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 692 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
| 700 } | 693 } |
| 701 | 694 |
| 702 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { | 695 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { |
| 703 InitTextfield(); | 696 InitTextfield(); |
| 704 textfield_->SetText(ASCIIToUTF16("hello world")); | 697 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 705 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 698 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 706 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 699 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 707 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 700 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 708 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 701 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | 1012 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
| 1020 SendKeyEvent(ui::VKEY_LEFT, false, true); | 1013 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 1021 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | 1014 EXPECT_EQ(5U, textfield_->GetCursorPosition()); |
| 1022 SendKeyEvent(ui::VKEY_LEFT, true, true); | 1015 SendKeyEvent(ui::VKEY_LEFT, true, true); |
| 1023 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1016 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 1024 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); | 1017 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); |
| 1025 textfield_->SelectAll(false); | 1018 textfield_->SelectAll(false); |
| 1026 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); | 1019 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); |
| 1027 | 1020 |
| 1028 // Cut should be disabled. | 1021 // Cut should be disabled. |
| 1029 SetClipboardText("Test"); | 1022 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1030 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 1023 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 1031 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 1024 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 1032 SendKeyEvent(ui::VKEY_X, false, true); | 1025 SendKeyEvent(ui::VKEY_X, false, true); |
| 1033 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1026 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 1034 EXPECT_STR_EQ("Test", base::string16(GetClipboardText())); | 1027 EXPECT_STR_EQ("Test", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1035 EXPECT_STR_EQ("read only", textfield_->text()); | 1028 EXPECT_STR_EQ("read only", textfield_->text()); |
| 1036 | 1029 |
| 1037 // Paste should be disabled. | 1030 // Paste should be disabled. |
| 1038 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1031 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 1039 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 1032 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 1040 SendKeyEvent(ui::VKEY_V, false, true); | 1033 SendKeyEvent(ui::VKEY_V, false, true); |
| 1041 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1034 SendKeyEvent(ui::VKEY_INSERT, true, false); |
| 1042 EXPECT_STR_EQ("read only", textfield_->text()); | 1035 EXPECT_STR_EQ("read only", textfield_->text()); |
| 1043 | 1036 |
| 1044 // Copy should work normally. | 1037 // Copy should work normally. |
| 1045 SetClipboardText("Test"); | 1038 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1046 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 1039 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1047 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 1040 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1048 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1041 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1049 SetClipboardText("Test"); | 1042 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1050 SendKeyEvent(ui::VKEY_C, false, true); | 1043 SendKeyEvent(ui::VKEY_C, false, true); |
| 1051 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1044 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1052 SetClipboardText("Test"); | 1045 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); |
| 1053 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1046 SendKeyEvent(ui::VKEY_INSERT, false, true); |
| 1054 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1047 EXPECT_STR_EQ("read only", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1055 | 1048 |
| 1056 // SetText should work even in read only mode. | 1049 // SetText should work even in read only mode. |
| 1057 textfield_->SetText(ASCIIToUTF16(" four five six ")); | 1050 textfield_->SetText(ASCIIToUTF16(" four five six ")); |
| 1058 EXPECT_STR_EQ(" four five six ", textfield_->text()); | 1051 EXPECT_STR_EQ(" four five six ", textfield_->text()); |
| 1059 | 1052 |
| 1060 textfield_->SelectAll(false); | 1053 textfield_->SelectAll(false); |
| 1061 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1054 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1062 | 1055 |
| 1063 // Text field is unmodifiable and selection shouldn't change. | 1056 // Text field is unmodifiable and selection shouldn't change. |
| 1064 SendKeyEvent(ui::VKEY_DELETE); | 1057 SendKeyEvent(ui::VKEY_DELETE); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 } | 1262 } |
| 1270 | 1263 |
| 1271 TEST_F(TextfieldTest, CutCopyPaste) { | 1264 TEST_F(TextfieldTest, CutCopyPaste) { |
| 1272 InitTextfield(); | 1265 InitTextfield(); |
| 1273 | 1266 |
| 1274 // Ensure IDS_APP_CUT cuts. | 1267 // Ensure IDS_APP_CUT cuts. |
| 1275 textfield_->SetText(ASCIIToUTF16("123")); | 1268 textfield_->SetText(ASCIIToUTF16("123")); |
| 1276 textfield_->SelectAll(false); | 1269 textfield_->SelectAll(false); |
| 1277 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); | 1270 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 1278 textfield_->ExecuteCommand(IDS_APP_CUT, 0); | 1271 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 1279 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1272 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1280 EXPECT_STR_EQ("", textfield_->text()); | 1273 EXPECT_STR_EQ("", textfield_->text()); |
| 1281 | 1274 |
| 1282 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. | 1275 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. |
| 1283 textfield_->SetText(ASCIIToUTF16("456")); | 1276 textfield_->SetText(ASCIIToUTF16("456")); |
| 1284 textfield_->SelectAll(false); | 1277 textfield_->SelectAll(false); |
| 1285 SendKeyEvent(ui::VKEY_X, true, false, true, false); | 1278 SendKeyEvent(ui::VKEY_X, true, false, true, false); |
| 1286 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1279 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1287 EXPECT_STR_EQ("456", textfield_->text()); | 1280 EXPECT_STR_EQ("456", textfield_->text()); |
| 1288 SendKeyEvent(ui::VKEY_X, false, true); | 1281 SendKeyEvent(ui::VKEY_X, false, true); |
| 1289 EXPECT_STR_EQ("456", base::string16(GetClipboardText())); | 1282 EXPECT_STR_EQ("456", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1290 EXPECT_STR_EQ("", textfield_->text()); | 1283 EXPECT_STR_EQ("", textfield_->text()); |
| 1291 | 1284 |
| 1292 // Ensure [Shift]+[Delete] cuts. | 1285 // Ensure [Shift]+[Delete] cuts. |
| 1293 textfield_->SetText(ASCIIToUTF16("123")); | 1286 textfield_->SetText(ASCIIToUTF16("123")); |
| 1294 textfield_->SelectAll(false); | 1287 textfield_->SelectAll(false); |
| 1295 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1288 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 1296 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1289 EXPECT_STR_EQ("123", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1297 EXPECT_STR_EQ("", textfield_->text()); | 1290 EXPECT_STR_EQ("", textfield_->text()); |
| 1298 | 1291 |
| 1299 // Ensure IDS_APP_COPY copies. | 1292 // Ensure IDS_APP_COPY copies. |
| 1300 textfield_->SetText(ASCIIToUTF16("789")); | 1293 textfield_->SetText(ASCIIToUTF16("789")); |
| 1301 textfield_->SelectAll(false); | 1294 textfield_->SelectAll(false); |
| 1302 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); | 1295 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1303 textfield_->ExecuteCommand(IDS_APP_COPY, 0); | 1296 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1304 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); | 1297 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1305 | 1298 |
| 1306 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | 1299 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. |
| 1307 textfield_->SetText(ASCIIToUTF16("012")); | 1300 textfield_->SetText(ASCIIToUTF16("012")); |
| 1308 textfield_->SelectAll(false); | 1301 textfield_->SelectAll(false); |
| 1309 SendKeyEvent(ui::VKEY_C, true, false, true, false); | 1302 SendKeyEvent(ui::VKEY_C, true, false, true, false); |
| 1310 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); | 1303 EXPECT_STR_EQ("789", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1311 SendKeyEvent(ui::VKEY_C, false, true); | 1304 SendKeyEvent(ui::VKEY_C, false, true); |
| 1312 EXPECT_STR_EQ("012", base::string16(GetClipboardText())); | 1305 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1313 | 1306 |
| 1314 // Ensure [Ctrl]+[Insert] copies. | 1307 // Ensure [Ctrl]+[Insert] copies. |
| 1315 textfield_->SetText(ASCIIToUTF16("345")); | 1308 textfield_->SetText(ASCIIToUTF16("345")); |
| 1316 textfield_->SelectAll(false); | 1309 textfield_->SelectAll(false); |
| 1317 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1310 SendKeyEvent(ui::VKEY_INSERT, false, true); |
| 1318 EXPECT_STR_EQ("345", base::string16(GetClipboardText())); | 1311 EXPECT_STR_EQ("345", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1319 EXPECT_STR_EQ("345", textfield_->text()); | 1312 EXPECT_STR_EQ("345", textfield_->text()); |
| 1320 | 1313 |
| 1321 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; | 1314 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; |
| 1322 // also ensure that [Ctrl]+[Alt]+[V] does nothing. | 1315 // also ensure that [Ctrl]+[Alt]+[V] does nothing. |
| 1323 SetClipboardText("abc"); | 1316 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "abc"); |
| 1324 textfield_->SetText(base::string16()); | 1317 textfield_->SetText(base::string16()); |
| 1325 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1318 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 1326 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); | 1319 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 1327 EXPECT_STR_EQ("abc", textfield_->text()); | 1320 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1328 SendKeyEvent(ui::VKEY_V, false, true); | 1321 SendKeyEvent(ui::VKEY_V, false, true); |
| 1329 EXPECT_STR_EQ("abcabc", textfield_->text()); | 1322 EXPECT_STR_EQ("abcabc", textfield_->text()); |
| 1330 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1323 SendKeyEvent(ui::VKEY_INSERT, true, false); |
| 1331 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1324 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1332 SendKeyEvent(ui::VKEY_V, true, false, true, false); | 1325 SendKeyEvent(ui::VKEY_V, true, false, true, false); |
| 1333 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1326 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1334 | 1327 |
| 1335 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. | 1328 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. |
| 1336 textfield_->SelectAll(false); | 1329 textfield_->SelectAll(false); |
| 1337 SendKeyEvent(ui::VKEY_INSERT, true, true); | 1330 SendKeyEvent(ui::VKEY_INSERT, true, true); |
| 1338 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); | 1331 EXPECT_STR_EQ("abc", GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 1339 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1332 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1340 } | 1333 } |
| 1341 | 1334 |
| 1342 TEST_F(TextfieldTest, OvertypeMode) { | 1335 TEST_F(TextfieldTest, OvertypeMode) { |
| 1343 InitTextfield(); | 1336 InitTextfield(); |
| 1344 // Overtype mode should be disabled (no-op [Insert]). | 1337 // Overtype mode should be disabled (no-op [Insert]). |
| 1345 textfield_->SetText(ASCIIToUTF16("2")); | 1338 textfield_->SetText(ASCIIToUTF16("2")); |
| 1346 SendKeyEvent(ui::VKEY_HOME); | 1339 SendKeyEvent(ui::VKEY_HOME); |
| 1347 SendKeyEvent(ui::VKEY_INSERT); | 1340 SendKeyEvent(ui::VKEY_INSERT); |
| 1348 SendKeyEvent(ui::VKEY_1, false, false); | 1341 SendKeyEvent(ui::VKEY_1, false, false); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1740 textfield_->OnMousePressed(press_event); | 1733 textfield_->OnMousePressed(press_event); |
| 1741 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); | 1734 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); |
| 1742 | 1735 |
| 1743 // Drag the mouse to the beginning of the textfield. | 1736 // Drag the mouse to the beginning of the textfield. |
| 1744 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, | 1737 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, |
| 1745 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1738 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1746 textfield_->OnMouseDragged(drag_event); | 1739 textfield_->OnMouseDragged(drag_event); |
| 1747 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); | 1740 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); |
| 1748 } | 1741 } |
| 1749 | 1742 |
| 1743 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1744 TEST_F(TextfieldTest, SelectionClipboard) { |
| 1745 InitTextfield(); |
| 1746 textfield_->SetText(ASCIIToUTF16("0123")); |
| 1747 gfx::Point point_1(GetCursorPositionX(1), 0); |
| 1748 gfx::Point point_2(GetCursorPositionX(2), 0); |
| 1749 gfx::Point point_3(GetCursorPositionX(3), 0); |
| 1750 gfx::Point point_4(GetCursorPositionX(4), 0); |
| 1751 |
| 1752 // Text selected by the mouse should be placed on the selection clipboard. |
| 1753 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, |
| 1754 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1755 textfield_->OnMousePressed(press); |
| 1756 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3, |
| 1757 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1758 textfield_->OnMouseDragged(drag); |
| 1759 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point_3, point_3, |
| 1760 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1761 textfield_->OnMouseReleased(release); |
| 1762 EXPECT_EQ(gfx::Range(1, 3), textfield_->GetSelectedRange()); |
| 1763 EXPECT_STR_EQ("12", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1764 |
| 1765 // Select-all should update the selection clipboard. |
| 1766 SendKeyEvent(ui::VKEY_A, false, true); |
| 1767 EXPECT_EQ(gfx::Range(0, 4), textfield_->GetSelectedRange()); |
| 1768 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1769 |
| 1770 // Shift-click selection modifications should update the clipboard. |
| 1771 NonClientMouseClick(); |
| 1772 ui::MouseEvent press_2(ui::ET_MOUSE_PRESSED, point_2, point_2, |
| 1773 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1774 press_2.set_flags(press_2.flags() | ui::EF_SHIFT_DOWN); |
| 1775 textfield_->OnMousePressed(press_2); |
| 1776 ui::MouseEvent release_2(ui::ET_MOUSE_RELEASED, point_2, point_2, |
| 1777 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1778 textfield_->OnMouseReleased(release_2); |
| 1779 EXPECT_EQ(gfx::Range(0, 2), textfield_->GetSelectedRange()); |
| 1780 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1781 |
| 1782 // Shift-Left/Right should update the selection clipboard. |
| 1783 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 1784 EXPECT_STR_EQ("012", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1785 SendKeyEvent(ui::VKEY_LEFT, true, false); |
| 1786 EXPECT_STR_EQ("01", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1787 SendKeyEvent(ui::VKEY_RIGHT, true, true); |
| 1788 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1789 |
| 1790 // Moving the cursor without a selection should not change the clipboard. |
| 1791 SendKeyEvent(ui::VKEY_LEFT, false, false); |
| 1792 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange()); |
| 1793 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1794 |
| 1795 // Middle clicking should paste at the mouse (not cursor) location. |
| 1796 ui::MouseEvent middle(ui::ET_MOUSE_PRESSED, point_4, point_4, |
| 1797 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON); |
| 1798 textfield_->OnMousePressed(middle); |
| 1799 EXPECT_STR_EQ("01230123", textfield_->text()); |
| 1800 EXPECT_EQ(gfx::Range(0, 0), textfield_->GetSelectedRange()); |
| 1801 EXPECT_STR_EQ("0123", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1802 |
| 1803 // Middle click pasting should adjust trailing cursors. |
| 1804 textfield_->SelectRange(gfx::Range(5, 5)); |
| 1805 textfield_->OnMousePressed(middle); |
| 1806 EXPECT_STR_EQ("012301230123", textfield_->text()); |
| 1807 EXPECT_EQ(gfx::Range(9, 9), textfield_->GetSelectedRange()); |
| 1808 |
| 1809 // Middle click pasting should adjust trailing selections. |
| 1810 textfield_->SelectRange(gfx::Range(7, 9)); |
| 1811 textfield_->OnMousePressed(middle); |
| 1812 EXPECT_STR_EQ("0123012301230123", textfield_->text()); |
| 1813 EXPECT_EQ(gfx::Range(11, 13), textfield_->GetSelectedRange()); |
| 1814 |
| 1815 // Middle clicking in the selection should clear the clipboard and selection. |
| 1816 textfield_->SelectRange(gfx::Range(2, 6)); |
| 1817 textfield_->OnMousePressed(middle); |
| 1818 EXPECT_STR_EQ("0123012301230123", textfield_->text()); |
| 1819 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); |
| 1820 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); |
| 1821 |
| 1822 // Double and triple clicking should update the clipboard contents. |
| 1823 textfield_->SetText(ASCIIToUTF16("ab cd ef")); |
| 1824 gfx::Point word(GetCursorPositionX(4), 0); |
| 1825 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, |
| 1826 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1827 textfield_->OnMousePressed(press_word); |
| 1828 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, |
| 1829 ui::EF_LEFT_MOUSE_BUTTON, |
| 1830 ui::EF_LEFT_MOUSE_BUTTON); |
| 1831 textfield_->OnMouseReleased(release_word); |
| 1832 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word, |
| 1833 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
| 1834 ui::EF_LEFT_MOUSE_BUTTON); |
| 1835 textfield_->OnMousePressed(double_click); |
| 1836 textfield_->OnMouseReleased(release_word); |
| 1837 EXPECT_EQ(gfx::Range(3, 5), textfield_->GetSelectedRange()); |
| 1838 EXPECT_STR_EQ("cd", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1839 textfield_->OnMousePressed(press_word); |
| 1840 textfield_->OnMouseReleased(release_word); |
| 1841 EXPECT_EQ(gfx::Range(0, 8), textfield_->GetSelectedRange()); |
| 1842 EXPECT_STR_EQ("ab cd ef", GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION)); |
| 1843 } |
| 1844 #endif |
| 1845 |
| 1750 // Touch selection and dragging currently only works for chromeos. | 1846 // Touch selection and dragging currently only works for chromeos. |
| 1751 #if defined(OS_CHROMEOS) | 1847 #if defined(OS_CHROMEOS) |
| 1752 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { | 1848 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { |
| 1753 InitTextfield(); | 1849 InitTextfield(); |
| 1754 textfield_->SetText(ASCIIToUTF16("hello world")); | 1850 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1755 EXPECT_FALSE(GetTouchSelectionController()); | 1851 EXPECT_FALSE(GetTouchSelectionController()); |
| 1756 const int x = GetCursorPositionX(2); | 1852 const int x = GetCursorPositionX(2); |
| 1757 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); | 1853 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); |
| 1758 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); | 1854 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); |
| 1759 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); | 1855 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1864 // Set text which may fall back to a font which has taller baseline than | 1960 // Set text which may fall back to a font which has taller baseline than |
| 1865 // the default font. | 1961 // the default font. |
| 1866 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); | 1962 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); |
| 1867 const int new_baseline = textfield_->GetBaseline(); | 1963 const int new_baseline = textfield_->GetBaseline(); |
| 1868 | 1964 |
| 1869 // Regardless of the text, the baseline must be the same. | 1965 // Regardless of the text, the baseline must be the same. |
| 1870 EXPECT_EQ(new_baseline, old_baseline); | 1966 EXPECT_EQ(new_baseline, old_baseline); |
| 1871 } | 1967 } |
| 1872 | 1968 |
| 1873 } // namespace views | 1969 } // namespace views |
| OLD | NEW |