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

Side by Side Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 2541313002: RenderTextHarfBuzz: Add support for multi line text selection. (Closed)
Patch Set: -- Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 591
592 View* GetFocusedView() { 592 View* GetFocusedView() {
593 return widget_->GetFocusManager()->GetFocusedView(); 593 return widget_->GetFocusManager()->GetFocusedView();
594 } 594 }
595 595
596 int GetCursorPositionX(int cursor_pos) { 596 int GetCursorPositionX(int cursor_pos) {
597 return test_api_->GetRenderText()->GetCursorBounds( 597 return test_api_->GetRenderText()->GetCursorBounds(
598 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); 598 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x();
599 } 599 }
600 600
601 int GetCursorYForTesting() {
602 return test_api_->GetRenderText()->GetLineOffset(0).y() + 1;
603 }
604
601 // Get the current cursor bounds. 605 // Get the current cursor bounds.
602 gfx::Rect GetCursorBounds() { 606 gfx::Rect GetCursorBounds() {
603 return test_api_->GetRenderText()->GetUpdatedCursorBounds(); 607 return test_api_->GetRenderText()->GetUpdatedCursorBounds();
604 } 608 }
605 609
606 // Get the cursor bounds of |sel|. 610 // Get the cursor bounds of |sel|.
607 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) { 611 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) {
608 return test_api_->GetRenderText()->GetCursorBounds(sel, true); 612 return test_api_->GetRenderText()->GetCursorBounds(sel, true);
609 } 613 }
610 614
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 widget_->GetFocusManager()->AdvanceFocus(true); 1383 widget_->GetFocusManager()->AdvanceFocus(true);
1380 EXPECT_EQ(3, GetFocusedView()->id()); 1384 EXPECT_EQ(3, GetFocusedView()->id());
1381 1385
1382 // Request focus should still work. 1386 // Request focus should still work.
1383 textfield_->RequestFocus(); 1387 textfield_->RequestFocus();
1384 EXPECT_EQ(1, GetFocusedView()->id()); 1388 EXPECT_EQ(1, GetFocusedView()->id());
1385 1389
1386 // Test if clicking on textfield view sets the focus. 1390 // Test if clicking on textfield view sets the focus.
1387 widget_->GetFocusManager()->AdvanceFocus(true); 1391 widget_->GetFocusManager()->AdvanceFocus(true);
1388 EXPECT_EQ(3, GetFocusedView()->id()); 1392 EXPECT_EQ(3, GetFocusedView()->id());
1389 MoveMouseTo(gfx::Point()); 1393 MoveMouseTo(gfx::Point(0, GetCursorYForTesting()));
1390 ClickLeftMouseButton(); 1394 ClickLeftMouseButton();
1391 EXPECT_EQ(1, GetFocusedView()->id()); 1395 EXPECT_EQ(1, GetFocusedView()->id());
1392 1396
1393 // Tab/Shift+Tab should also cycle focus, not insert a tab character. 1397 // Tab/Shift+Tab should also cycle focus, not insert a tab character.
1394 SendKeyEvent(ui::VKEY_TAB, false, false); 1398 SendKeyEvent(ui::VKEY_TAB, false, false);
1395 EXPECT_EQ(2, GetFocusedView()->id()); 1399 EXPECT_EQ(2, GetFocusedView()->id());
1396 SendKeyEvent(ui::VKEY_TAB, false, false); 1400 SendKeyEvent(ui::VKEY_TAB, false, false);
1397 EXPECT_EQ(3, GetFocusedView()->id()); 1401 EXPECT_EQ(3, GetFocusedView()->id());
1398 // Cycle back to the first textfield. 1402 // Cycle back to the first textfield.
1399 SendKeyEvent(ui::VKEY_TAB, false, false); 1403 SendKeyEvent(ui::VKEY_TAB, false, false);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 // Exercise the "paste enabled?" check in the verifier. 1435 // Exercise the "paste enabled?" check in the verifier.
1432 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); 1436 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test");
1433 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1437 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1434 } 1438 }
1435 1439
1436 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { 1440 TEST_F(TextfieldTest, DoubleAndTripleClickTest) {
1437 InitTextfield(); 1441 InitTextfield();
1438 textfield_->SetText(ASCIIToUTF16("hello world")); 1442 textfield_->SetText(ASCIIToUTF16("hello world"));
1439 1443
1440 // Test for double click. 1444 // Test for double click.
1441 MoveMouseTo(gfx::Point()); 1445 MoveMouseTo(gfx::Point(0, GetCursorYForTesting()));
1442 ClickLeftMouseButton(); 1446 ClickLeftMouseButton();
1443 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1447 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1444 ClickLeftMouseButton(ui::EF_IS_DOUBLE_CLICK); 1448 ClickLeftMouseButton(ui::EF_IS_DOUBLE_CLICK);
1445 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1449 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1446 1450
1447 // Test for triple click. 1451 // Test for triple click.
1448 ClickLeftMouseButton(); 1452 ClickLeftMouseButton();
1449 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); 1453 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText());
1450 1454
1451 // Another click should reset back to double click. 1455 // Another click should reset back to double click.
1452 ClickLeftMouseButton(); 1456 ClickLeftMouseButton();
1453 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1457 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1454 } 1458 }
1455 1459
1456 TEST_F(TextfieldTest, DragToSelect) { 1460 TEST_F(TextfieldTest, DragToSelect) {
1457 InitTextfield(); 1461 InitTextfield();
1458 textfield_->SetText(ASCIIToUTF16("hello world")); 1462 textfield_->SetText(ASCIIToUTF16("hello world"));
1459 const int kStart = GetCursorPositionX(5); 1463 const int kStart = GetCursorPositionX(5);
1460 const int kEnd = 500; 1464 const int kEnd = 500;
1461 gfx::Point start_point(kStart, 0); 1465 const int cursor_y = GetCursorYForTesting();
1462 gfx::Point end_point(kEnd, 0); 1466 gfx::Point start_point(kStart, cursor_y);
1467 gfx::Point end_point(kEnd, cursor_y);
1463 1468
1464 MoveMouseTo(start_point); 1469 MoveMouseTo(start_point);
1465 PressLeftMouseButton(); 1470 PressLeftMouseButton();
1466 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1471 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1467 1472
1468 // Check that dragging left selects the beginning of the string. 1473 // Check that dragging left selects the beginning of the string.
1469 DragMouseTo(gfx::Point()); 1474 DragMouseTo(gfx::Point(0, cursor_y));
1470 base::string16 text_left = textfield_->GetSelectedText(); 1475 base::string16 text_left = textfield_->GetSelectedText();
1471 EXPECT_STR_EQ("hello", text_left); 1476 EXPECT_STR_EQ("hello", text_left);
1472 1477
1473 // Check that dragging right selects the rest of the string. 1478 // Check that dragging right selects the rest of the string.
1474 DragMouseTo(end_point); 1479 DragMouseTo(end_point);
1475 base::string16 text_right = textfield_->GetSelectedText(); 1480 base::string16 text_right = textfield_->GetSelectedText();
1476 EXPECT_STR_EQ(" world", text_right); 1481 EXPECT_STR_EQ(" world", text_right);
1477 1482
1478 // Check that releasing in the same location does not alter the selection. 1483 // Check that releasing in the same location does not alter the selection.
1479 ReleaseLeftMouseButton(); 1484 ReleaseLeftMouseButton();
1480 EXPECT_EQ(text_right, textfield_->GetSelectedText()); 1485 EXPECT_EQ(text_right, textfield_->GetSelectedText());
1481 1486
1482 // Check that dragging from beyond the text length works too. 1487 // Check that dragging from beyond the text length works too.
1483 MoveMouseTo(end_point); 1488 MoveMouseTo(end_point);
1484 PressLeftMouseButton(); 1489 PressLeftMouseButton();
1485 DragMouseTo(gfx::Point()); 1490 DragMouseTo(gfx::Point(0, cursor_y));
1486 ReleaseLeftMouseButton(); 1491 ReleaseLeftMouseButton();
1487 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); 1492 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText());
1488 } 1493 }
1489 1494
1490 // This test checks that dragging above the textfield selects to the beginning 1495 // This test checks that dragging above the textfield selects to the beginning
1491 // and dragging below the textfield selects to the end, but only on platforms 1496 // and dragging below the textfield selects to the end, but only on platforms
1492 // where that is the expected behavior. 1497 // where that is the expected behavior.
1493 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) { 1498 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) {
1499 // Todo add RTL case.
1494 InitTextfield(); 1500 InitTextfield();
1495 textfield_->SetText(ASCIIToUTF16("hello world")); 1501 textfield_->SetText(ASCIIToUTF16("hello world"));
1496 const base::string16 expected_up = base::ASCIIToUTF16( 1502 const base::string16 expected_up = base::ASCIIToUTF16(
1497 PlatformStyle::kTextDragVerticallyDragsToEnd ? "hello" : "lo"); 1503 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? "hello" : "lo");
1498 const base::string16 expected_down = base::ASCIIToUTF16( 1504 const base::string16 expected_down = base::ASCIIToUTF16(
1499 PlatformStyle::kTextDragVerticallyDragsToEnd ? " world" : " w"); 1505 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? " world" : " w");
1500 const int kStartX = GetCursorPositionX(5); 1506 const int kStartX = GetCursorPositionX(5);
1501 const int kDownX = GetCursorPositionX(7); 1507 const int kDownX = GetCursorPositionX(7);
1502 const int kUpX = GetCursorPositionX(3); 1508 const int kUpX = GetCursorPositionX(3);
1503 gfx::Point start_point(kStartX, 0); 1509 gfx::Point start_point(kStartX, GetCursorYForTesting());
1504 gfx::Point down_point(kDownX, 500); 1510 gfx::Point down_point(kDownX, 500);
1505 gfx::Point up_point(kUpX, -500); 1511 gfx::Point up_point(kUpX, -500);
1506 1512
1507 MoveMouseTo(start_point); 1513 MoveMouseTo(start_point);
1508 PressLeftMouseButton(); 1514 PressLeftMouseButton();
1509 DragMouseTo(up_point); 1515 DragMouseTo(up_point);
1510 ReleaseLeftMouseButton(); 1516 ReleaseLeftMouseButton();
1511 EXPECT_EQ(textfield_->GetSelectedText(), expected_up); 1517 EXPECT_EQ(textfield_->GetSelectedText(), expected_up);
1512 1518
1513 // Click at |up_point|. This is important because drags do not count as clicks 1519 // Click at |up_point|. This is important because drags do not count as clicks
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 1585
1580 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { 1586 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) {
1581 InitTextfield(); 1587 InitTextfield();
1582 textfield_->SetText(ASCIIToUTF16("hello string world")); 1588 textfield_->SetText(ASCIIToUTF16("hello string world"));
1583 1589
1584 // Ensure the textfield will provide selected text for drag data. 1590 // Ensure the textfield will provide selected text for drag data.
1585 base::string16 string; 1591 base::string16 string;
1586 ui::OSExchangeData data; 1592 ui::OSExchangeData data;
1587 const gfx::Range kStringRange(6, 12); 1593 const gfx::Range kStringRange(6, 12);
1588 textfield_->SelectRange(kStringRange); 1594 textfield_->SelectRange(kStringRange);
1589 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 1595 const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting());
1590 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); 1596 textfield_->WriteDragDataForView(NULL, kStringPoint, &data);
1591 EXPECT_TRUE(data.GetString(&string)); 1597 EXPECT_TRUE(data.GetString(&string));
1592 EXPECT_EQ(textfield_->GetSelectedText(), string); 1598 EXPECT_EQ(textfield_->GetSelectedText(), string);
1593 1599
1594 // Ensure that disabled textfields do not support drag operations. 1600 // Ensure that disabled textfields do not support drag operations.
1595 textfield_->SetEnabled(false); 1601 textfield_->SetEnabled(false);
1596 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1602 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1597 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1603 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1598 textfield_->SetEnabled(true); 1604 textfield_->SetEnabled(true);
1599 // Ensure that textfields without selections do not support drag operations. 1605 // Ensure that textfields without selections do not support drag operations.
(...skipping 18 matching lines...) Expand all
1618 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 1624 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
1619 gfx::Point())); 1625 gfx::Point()));
1620 // Ensure that textfields support local moves. 1626 // Ensure that textfields support local moves.
1621 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1627 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1622 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); 1628 textfield_->GetDragOperationsForView(textfield_, kStringPoint));
1623 } 1629 }
1624 1630
1625 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { 1631 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
1626 InitTextfield(); 1632 InitTextfield();
1627 textfield_->SetText(ASCIIToUTF16("hello world")); 1633 textfield_->SetText(ASCIIToUTF16("hello world"));
1634 const int cursor_y = GetCursorYForTesting();
1628 1635
1629 base::string16 string; 1636 base::string16 string;
1630 ui::OSExchangeData data; 1637 ui::OSExchangeData data;
1631 int formats = 0; 1638 int formats = 0;
1632 int operations = 0; 1639 int operations = 0;
1633 std::set<ui::Clipboard::FormatType> format_types; 1640 std::set<ui::Clipboard::FormatType> format_types;
1634 1641
1635 // Start dragging "ello". 1642 // Start dragging "ello".
1636 textfield_->SelectRange(gfx::Range(1, 5)); 1643 textfield_->SelectRange(gfx::Range(1, 5));
1637 gfx::Point point(GetCursorPositionX(3), 0); 1644 gfx::Point point(GetCursorPositionX(3), cursor_y);
1638 MoveMouseTo(point); 1645 MoveMouseTo(point);
1639 PressLeftMouseButton(); 1646 PressLeftMouseButton();
1640 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, point)); 1647 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, point));
1641 operations = textfield_->GetDragOperationsForView(textfield_, point); 1648 operations = textfield_->GetDragOperationsForView(textfield_, point);
1642 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1649 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1643 operations); 1650 operations);
1644 textfield_->WriteDragDataForView(nullptr, point, &data); 1651 textfield_->WriteDragDataForView(nullptr, point, &data);
1645 EXPECT_TRUE(data.GetString(&string)); 1652 EXPECT_TRUE(data.GetString(&string));
1646 EXPECT_EQ(textfield_->GetSelectedText(), string); 1653 EXPECT_EQ(textfield_->GetSelectedText(), string);
1647 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1654 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1648 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1655 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1649 EXPECT_TRUE(format_types.empty()); 1656 EXPECT_TRUE(format_types.empty());
1650 1657
1651 // Drop "ello" after "w". 1658 // Drop "ello" after "w".
1652 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); 1659 const gfx::Point kDropPoint(GetCursorPositionX(7), cursor_y);
1653 EXPECT_TRUE(textfield_->CanDrop(data)); 1660 EXPECT_TRUE(textfield_->CanDrop(data));
1654 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); 1661 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations);
1655 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1662 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1656 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1663 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1657 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1664 EXPECT_STR_EQ("h welloorld", textfield_->text());
1658 textfield_->OnDragDone(); 1665 textfield_->OnDragDone();
1659 1666
1660 // Undo/Redo the drag&drop change. 1667 // Undo/Redo the drag&drop change.
1661 SendKeyEvent(ui::VKEY_Z, false, true); 1668 SendKeyEvent(ui::VKEY_Z, false, true);
1662 EXPECT_STR_EQ("hello world", textfield_->text()); 1669 EXPECT_STR_EQ("hello world", textfield_->text());
1663 SendKeyEvent(ui::VKEY_Z, false, true); 1670 SendKeyEvent(ui::VKEY_Z, false, true);
1664 EXPECT_STR_EQ("", textfield_->text()); 1671 EXPECT_STR_EQ("", textfield_->text());
1665 SendKeyEvent(ui::VKEY_Z, false, true); 1672 SendKeyEvent(ui::VKEY_Z, false, true);
1666 EXPECT_STR_EQ("", textfield_->text()); 1673 EXPECT_STR_EQ("", textfield_->text());
1667 SendKeyEvent(ui::VKEY_Z, true, true); 1674 SendKeyEvent(ui::VKEY_Z, true, true);
1668 EXPECT_STR_EQ("hello world", textfield_->text()); 1675 EXPECT_STR_EQ("hello world", textfield_->text());
1669 SendKeyEvent(ui::VKEY_Z, true, true); 1676 SendKeyEvent(ui::VKEY_Z, true, true);
1670 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1677 EXPECT_STR_EQ("h welloorld", textfield_->text());
1671 SendKeyEvent(ui::VKEY_Z, true, true); 1678 SendKeyEvent(ui::VKEY_Z, true, true);
1672 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1679 EXPECT_STR_EQ("h welloorld", textfield_->text());
1673 } 1680 }
1674 1681
1675 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { 1682 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) {
1676 InitTextfield(); 1683 InitTextfield();
1677 textfield_->SetText(ASCIIToUTF16("hello world")); 1684 textfield_->SetText(ASCIIToUTF16("hello world"));
1685 const int cursor_y = GetCursorYForTesting();
1678 1686
1679 base::string16 string; 1687 base::string16 string;
1680 ui::OSExchangeData data; 1688 ui::OSExchangeData data;
1681 int formats = 0; 1689 int formats = 0;
1682 int operations = 0; 1690 int operations = 0;
1683 std::set<ui::Clipboard::FormatType> format_types; 1691 std::set<ui::Clipboard::FormatType> format_types;
1684 1692
1685 // Start dragging " worl". 1693 // Start dragging " worl".
1686 textfield_->SelectRange(gfx::Range(5, 10)); 1694 textfield_->SelectRange(gfx::Range(5, 10));
1687 gfx::Point point(GetCursorPositionX(7), 0); 1695 gfx::Point point(GetCursorPositionX(7), cursor_y);
1688 MoveMouseTo(point); 1696 MoveMouseTo(point);
1689 PressLeftMouseButton(); 1697 PressLeftMouseButton();
1690 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point())); 1698 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point()));
1691 operations = textfield_->GetDragOperationsForView(textfield_, point); 1699 operations = textfield_->GetDragOperationsForView(textfield_, point);
1692 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1700 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1693 operations); 1701 operations);
1694 textfield_->WriteDragDataForView(nullptr, point, &data); 1702 textfield_->WriteDragDataForView(nullptr, point, &data);
1695 EXPECT_TRUE(data.GetString(&string)); 1703 EXPECT_TRUE(data.GetString(&string));
1696 EXPECT_EQ(textfield_->GetSelectedText(), string); 1704 EXPECT_EQ(textfield_->GetSelectedText(), string);
1697 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1705 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1698 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1706 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1699 EXPECT_TRUE(format_types.empty()); 1707 EXPECT_TRUE(format_types.empty());
1700 1708
1701 // Drop " worl" after "h". 1709 // Drop " worl" after "h".
1702 EXPECT_TRUE(textfield_->CanDrop(data)); 1710 EXPECT_TRUE(textfield_->CanDrop(data));
1703 gfx::Point drop_point(GetCursorPositionX(1), 0); 1711 gfx::Point drop_point(GetCursorPositionX(1), cursor_y);
1704 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); 1712 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations);
1705 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1713 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1706 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1714 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1707 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1715 EXPECT_STR_EQ("h worlellod", textfield_->text());
1708 textfield_->OnDragDone(); 1716 textfield_->OnDragDone();
1709 1717
1710 // Undo/Redo the drag&drop change. 1718 // Undo/Redo the drag&drop change.
1711 SendKeyEvent(ui::VKEY_Z, false, true); 1719 SendKeyEvent(ui::VKEY_Z, false, true);
1712 EXPECT_STR_EQ("hello world", textfield_->text()); 1720 EXPECT_STR_EQ("hello world", textfield_->text());
1713 SendKeyEvent(ui::VKEY_Z, false, true); 1721 SendKeyEvent(ui::VKEY_Z, false, true);
1714 EXPECT_STR_EQ("", textfield_->text()); 1722 EXPECT_STR_EQ("", textfield_->text());
1715 SendKeyEvent(ui::VKEY_Z, false, true); 1723 SendKeyEvent(ui::VKEY_Z, false, true);
1716 EXPECT_STR_EQ("", textfield_->text()); 1724 EXPECT_STR_EQ("", textfield_->text());
1717 SendKeyEvent(ui::VKEY_Z, true, true); 1725 SendKeyEvent(ui::VKEY_Z, true, true);
1718 EXPECT_STR_EQ("hello world", textfield_->text()); 1726 EXPECT_STR_EQ("hello world", textfield_->text());
1719 SendKeyEvent(ui::VKEY_Z, true, true); 1727 SendKeyEvent(ui::VKEY_Z, true, true);
1720 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1728 EXPECT_STR_EQ("h worlellod", textfield_->text());
1721 SendKeyEvent(ui::VKEY_Z, true, true); 1729 SendKeyEvent(ui::VKEY_Z, true, true);
1722 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1730 EXPECT_STR_EQ("h worlellod", textfield_->text());
1723 } 1731 }
1724 1732
1725 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1733 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1726 InitTextfield(); 1734 InitTextfield();
1727 textfield_->SetText(ASCIIToUTF16("hello world")); 1735 textfield_->SetText(ASCIIToUTF16("hello world"));
1736 const int cursor_y = GetCursorYForTesting();
1728 1737
1729 // Start dragging "worl". 1738 // Start dragging "worl".
1730 textfield_->SelectRange(gfx::Range(6, 10)); 1739 textfield_->SelectRange(gfx::Range(6, 10));
1731 gfx::Point point(GetCursorPositionX(8), 0); 1740 gfx::Point point(GetCursorPositionX(8), cursor_y);
1732 MoveMouseTo(point); 1741 MoveMouseTo(point);
1733 PressLeftMouseButton(); 1742 PressLeftMouseButton();
1734 ui::OSExchangeData data; 1743 ui::OSExchangeData data;
1735 textfield_->WriteDragDataForView(nullptr, point, &data); 1744 textfield_->WriteDragDataForView(nullptr, point, &data);
1736 EXPECT_TRUE(textfield_->CanDrop(data)); 1745 EXPECT_TRUE(textfield_->CanDrop(data));
1737 // Drag the text over somewhere valid, outside the current selection. 1746 // Drag the text over somewhere valid, outside the current selection.
1738 gfx::Point drop_point(GetCursorPositionX(2), 0); 1747 gfx::Point drop_point(GetCursorPositionX(2), cursor_y);
1739 ui::DropTargetEvent drop(data, drop_point, drop_point, 1748 ui::DropTargetEvent drop(data, drop_point, drop_point,
1740 ui::DragDropTypes::DRAG_MOVE); 1749 ui::DragDropTypes::DRAG_MOVE);
1741 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); 1750 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop));
1742 // "Cancel" the drag, via move and release over the selection, and OnDragDone. 1751 // "Cancel" the drag, via move and release over the selection, and OnDragDone.
1743 gfx::Point drag_point(GetCursorPositionX(9), 0); 1752 gfx::Point drag_point(GetCursorPositionX(9), cursor_y);
1744 DragMouseTo(drag_point); 1753 DragMouseTo(drag_point);
1745 ReleaseLeftMouseButton(); 1754 ReleaseLeftMouseButton();
1746 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); 1755 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text());
1747 } 1756 }
1748 1757
1749 TEST_F(TextfieldTest, ReadOnlyTest) { 1758 TEST_F(TextfieldTest, ReadOnlyTest) {
1750 InitTextfield(); 1759 InitTextfield();
1751 textfield_->SetText(ASCIIToUTF16("read only")); 1760 textfield_->SetText(ASCIIToUTF16("read only"));
1752 textfield_->SetReadOnly(true); 1761 textfield_->SetReadOnly(true);
1753 EXPECT_TRUE(textfield_->enabled()); 1762 EXPECT_TRUE(textfield_->enabled());
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 2605
2597 // Drag the mouse to the beginning of the textfield. 2606 // Drag the mouse to the beginning of the textfield.
2598 DragMouseTo(beginning); 2607 DragMouseTo(beginning);
2599 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 2608 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
2600 } 2609 }
2601 2610
2602 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 2611 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2603 TEST_F(TextfieldTest, SelectionClipboard) { 2612 TEST_F(TextfieldTest, SelectionClipboard) {
2604 InitTextfield(); 2613 InitTextfield();
2605 textfield_->SetText(ASCIIToUTF16("0123")); 2614 textfield_->SetText(ASCIIToUTF16("0123"));
2606 gfx::Point point_1(GetCursorPositionX(1), 0); 2615 const int cursor_y = GetCursorYForTesting();
2607 gfx::Point point_2(GetCursorPositionX(2), 0); 2616 gfx::Point point_1(GetCursorPositionX(1), cursor_y);
2608 gfx::Point point_3(GetCursorPositionX(3), 0); 2617 gfx::Point point_2(GetCursorPositionX(2), cursor_y);
2609 gfx::Point point_4(GetCursorPositionX(4), 0); 2618 gfx::Point point_3(GetCursorPositionX(3), cursor_y);
2619 gfx::Point point_4(GetCursorPositionX(4), cursor_y);
2610 2620
2611 // Text selected by the mouse should be placed on the selection clipboard. 2621 // Text selected by the mouse should be placed on the selection clipboard.
2612 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, 2622 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1,
2613 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2623 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2614 ui::EF_LEFT_MOUSE_BUTTON); 2624 ui::EF_LEFT_MOUSE_BUTTON);
2615 textfield_->OnMousePressed(press); 2625 textfield_->OnMousePressed(press);
2616 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3, 2626 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3,
2617 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2627 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2618 ui::EF_LEFT_MOUSE_BUTTON); 2628 ui::EF_LEFT_MOUSE_BUTTON);
2619 textfield_->OnMouseDragged(drag); 2629 textfield_->OnMouseDragged(drag);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2697 // Middle clicking in the selection should clear the clipboard and selection. 2707 // Middle clicking in the selection should clear the clipboard and selection.
2698 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); 2708 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo");
2699 textfield_->SelectRange(gfx::Range(2, 6)); 2709 textfield_->SelectRange(gfx::Range(2, 6));
2700 textfield_->OnMousePressed(middle); 2710 textfield_->OnMousePressed(middle);
2701 EXPECT_STR_EQ("012301230123", textfield_->text()); 2711 EXPECT_STR_EQ("012301230123", textfield_->text());
2702 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); 2712 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange());
2703 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); 2713 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
2704 2714
2705 // Double and triple clicking should update the clipboard contents. 2715 // Double and triple clicking should update the clipboard contents.
2706 textfield_->SetText(ASCIIToUTF16("ab cd ef")); 2716 textfield_->SetText(ASCIIToUTF16("ab cd ef"));
2707 gfx::Point word(GetCursorPositionX(4), 0); 2717 gfx::Point word(GetCursorPositionX(4), cursor_y);
2708 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, 2718 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word,
2709 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2719 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2710 ui::EF_LEFT_MOUSE_BUTTON); 2720 ui::EF_LEFT_MOUSE_BUTTON);
2711 textfield_->OnMousePressed(press_word); 2721 textfield_->OnMousePressed(press_word);
2712 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, 2722 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word,
2713 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2723 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2714 ui::EF_LEFT_MOUSE_BUTTON); 2724 ui::EF_LEFT_MOUSE_BUTTON);
2715 textfield_->OnMouseReleased(release_word); 2725 textfield_->OnMouseReleased(release_word);
2716 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word, 2726 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word,
2717 ui::EventTimeForNow(), 2727 ui::EventTimeForNow(),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 } 2792 }
2783 #endif 2793 #endif
2784 2794
2785 // Long_Press gesture in Textfield can initiate a drag and drop now. 2795 // Long_Press gesture in Textfield can initiate a drag and drop now.
2786 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { 2796 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) {
2787 InitTextfield(); 2797 InitTextfield();
2788 textfield_->SetText(ASCIIToUTF16("Hello string world")); 2798 textfield_->SetText(ASCIIToUTF16("Hello string world"));
2789 2799
2790 // Ensure the textfield will provide selected text for drag data. 2800 // Ensure the textfield will provide selected text for drag data.
2791 textfield_->SelectRange(gfx::Range(6, 12)); 2801 textfield_->SelectRange(gfx::Range(6, 12));
2792 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 2802 const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting());
2793 2803
2794 // Enable touch-drag-drop to make long press effective. 2804 // Enable touch-drag-drop to make long press effective.
2795 base::CommandLine::ForCurrentProcess()->AppendSwitch( 2805 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2796 switches::kEnableTouchDragDrop); 2806 switches::kEnableTouchDragDrop);
2797 2807
2798 // Create a long press event in the selected region should start a drag. 2808 // Create a long press event in the selected region should start a drag.
2799 GestureEventForTest long_press( 2809 GestureEventForTest long_press(
2800 kStringPoint.x(), 2810 kStringPoint.x(),
2801 kStringPoint.y(), 2811 kStringPoint.y(),
2802 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); 2812 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 ui::AXNodeData node_data_protected; 3013 ui::AXNodeData node_data_protected;
3004 node_data_protected.state = 0; 3014 node_data_protected.state = 0;
3005 textfield_->GetAccessibleNodeData(&node_data_protected); 3015 textfield_->GetAccessibleNodeData(&node_data_protected);
3006 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); 3016 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role);
3007 EXPECT_EQ(ASCIIToUTF16("********"), 3017 EXPECT_EQ(ASCIIToUTF16("********"),
3008 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); 3018 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE));
3009 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 3019 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
3010 } 3020 }
3011 3021
3012 } // namespace views 3022 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698