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

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

Issue 2541313002: RenderTextHarfBuzz: Add support for multi line text selection. (Closed)
Patch Set: FindCursorPosition now returns valid grapheme boundaries. crbug.com/673986 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) {
1494 InitTextfield(); 1499 InitTextfield();
1495 textfield_->SetText(ASCIIToUTF16("hello world")); 1500 textfield_->SetText(ASCIIToUTF16("hello world"));
1496 const base::string16 expected_up = base::ASCIIToUTF16( 1501 const base::string16 expected_up = base::ASCIIToUTF16(
1497 PlatformStyle::kTextDragVerticallyDragsToEnd ? "hello" : "lo"); 1502 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? "hello" : "lo");
1498 const base::string16 expected_down = base::ASCIIToUTF16( 1503 const base::string16 expected_down = base::ASCIIToUTF16(
1499 PlatformStyle::kTextDragVerticallyDragsToEnd ? " world" : " w"); 1504 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? " world" : " w");
1500 const int kStartX = GetCursorPositionX(5); 1505 const int kStartX = GetCursorPositionX(5);
1501 const int kDownX = GetCursorPositionX(7); 1506 const int kDownX = GetCursorPositionX(7);
1502 const int kUpX = GetCursorPositionX(3); 1507 const int kUpX = GetCursorPositionX(3);
1503 gfx::Point start_point(kStartX, 0); 1508 gfx::Point start_point(kStartX, GetCursorYForTesting());
1504 gfx::Point down_point(kDownX, 500); 1509 gfx::Point down_point(kDownX, 500);
1505 gfx::Point up_point(kUpX, -500); 1510 gfx::Point up_point(kUpX, -500);
1506 1511
1507 MoveMouseTo(start_point); 1512 MoveMouseTo(start_point);
1508 PressLeftMouseButton(); 1513 PressLeftMouseButton();
1509 DragMouseTo(up_point); 1514 DragMouseTo(up_point);
1510 ReleaseLeftMouseButton(); 1515 ReleaseLeftMouseButton();
1511 EXPECT_EQ(textfield_->GetSelectedText(), expected_up); 1516 EXPECT_EQ(textfield_->GetSelectedText(), expected_up);
1512 1517
1513 // Click at |up_point|. This is important because drags do not count as clicks 1518 // 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 1584
1580 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { 1585 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) {
1581 InitTextfield(); 1586 InitTextfield();
1582 textfield_->SetText(ASCIIToUTF16("hello string world")); 1587 textfield_->SetText(ASCIIToUTF16("hello string world"));
1583 1588
1584 // Ensure the textfield will provide selected text for drag data. 1589 // Ensure the textfield will provide selected text for drag data.
1585 base::string16 string; 1590 base::string16 string;
1586 ui::OSExchangeData data; 1591 ui::OSExchangeData data;
1587 const gfx::Range kStringRange(6, 12); 1592 const gfx::Range kStringRange(6, 12);
1588 textfield_->SelectRange(kStringRange); 1593 textfield_->SelectRange(kStringRange);
1589 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 1594 const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting());
1590 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); 1595 textfield_->WriteDragDataForView(NULL, kStringPoint, &data);
1591 EXPECT_TRUE(data.GetString(&string)); 1596 EXPECT_TRUE(data.GetString(&string));
1592 EXPECT_EQ(textfield_->GetSelectedText(), string); 1597 EXPECT_EQ(textfield_->GetSelectedText(), string);
1593 1598
1594 // Ensure that disabled textfields do not support drag operations. 1599 // Ensure that disabled textfields do not support drag operations.
1595 textfield_->SetEnabled(false); 1600 textfield_->SetEnabled(false);
1596 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1601 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1597 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1602 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1598 textfield_->SetEnabled(true); 1603 textfield_->SetEnabled(true);
1599 // Ensure that textfields without selections do not support drag operations. 1604 // Ensure that textfields without selections do not support drag operations.
(...skipping 18 matching lines...) Expand all
1618 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 1623 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
1619 gfx::Point())); 1624 gfx::Point()));
1620 // Ensure that textfields support local moves. 1625 // Ensure that textfields support local moves.
1621 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1626 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1622 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); 1627 textfield_->GetDragOperationsForView(textfield_, kStringPoint));
1623 } 1628 }
1624 1629
1625 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { 1630 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
1626 InitTextfield(); 1631 InitTextfield();
1627 textfield_->SetText(ASCIIToUTF16("hello world")); 1632 textfield_->SetText(ASCIIToUTF16("hello world"));
1633 const int cursor_y = GetCursorYForTesting();
1628 1634
1629 base::string16 string; 1635 base::string16 string;
1630 ui::OSExchangeData data; 1636 ui::OSExchangeData data;
1631 int formats = 0; 1637 int formats = 0;
1632 int operations = 0; 1638 int operations = 0;
1633 std::set<ui::Clipboard::FormatType> format_types; 1639 std::set<ui::Clipboard::FormatType> format_types;
1634 1640
1635 // Start dragging "ello". 1641 // Start dragging "ello".
1636 textfield_->SelectRange(gfx::Range(1, 5)); 1642 textfield_->SelectRange(gfx::Range(1, 5));
1637 gfx::Point point(GetCursorPositionX(3), 0); 1643 gfx::Point point(GetCursorPositionX(3), cursor_y);
1638 MoveMouseTo(point); 1644 MoveMouseTo(point);
1639 PressLeftMouseButton(); 1645 PressLeftMouseButton();
1640 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, point)); 1646 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, point));
1641 operations = textfield_->GetDragOperationsForView(textfield_, point); 1647 operations = textfield_->GetDragOperationsForView(textfield_, point);
1642 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1648 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1643 operations); 1649 operations);
1644 textfield_->WriteDragDataForView(nullptr, point, &data); 1650 textfield_->WriteDragDataForView(nullptr, point, &data);
1645 EXPECT_TRUE(data.GetString(&string)); 1651 EXPECT_TRUE(data.GetString(&string));
1646 EXPECT_EQ(textfield_->GetSelectedText(), string); 1652 EXPECT_EQ(textfield_->GetSelectedText(), string);
1647 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1653 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1648 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1654 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1649 EXPECT_TRUE(format_types.empty()); 1655 EXPECT_TRUE(format_types.empty());
1650 1656
1651 // Drop "ello" after "w". 1657 // Drop "ello" after "w".
1652 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); 1658 const gfx::Point kDropPoint(GetCursorPositionX(7), cursor_y);
1653 EXPECT_TRUE(textfield_->CanDrop(data)); 1659 EXPECT_TRUE(textfield_->CanDrop(data));
1654 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); 1660 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations);
1655 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1661 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1656 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1662 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1657 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1663 EXPECT_STR_EQ("h welloorld", textfield_->text());
1658 textfield_->OnDragDone(); 1664 textfield_->OnDragDone();
1659 1665
1660 // Undo/Redo the drag&drop change. 1666 // Undo/Redo the drag&drop change.
1661 SendKeyEvent(ui::VKEY_Z, false, true); 1667 SendKeyEvent(ui::VKEY_Z, false, true);
1662 EXPECT_STR_EQ("hello world", textfield_->text()); 1668 EXPECT_STR_EQ("hello world", textfield_->text());
1663 SendKeyEvent(ui::VKEY_Z, false, true); 1669 SendKeyEvent(ui::VKEY_Z, false, true);
1664 EXPECT_STR_EQ("", textfield_->text()); 1670 EXPECT_STR_EQ("", textfield_->text());
1665 SendKeyEvent(ui::VKEY_Z, false, true); 1671 SendKeyEvent(ui::VKEY_Z, false, true);
1666 EXPECT_STR_EQ("", textfield_->text()); 1672 EXPECT_STR_EQ("", textfield_->text());
1667 SendKeyEvent(ui::VKEY_Z, true, true); 1673 SendKeyEvent(ui::VKEY_Z, true, true);
1668 EXPECT_STR_EQ("hello world", textfield_->text()); 1674 EXPECT_STR_EQ("hello world", textfield_->text());
1669 SendKeyEvent(ui::VKEY_Z, true, true); 1675 SendKeyEvent(ui::VKEY_Z, true, true);
1670 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1676 EXPECT_STR_EQ("h welloorld", textfield_->text());
1671 SendKeyEvent(ui::VKEY_Z, true, true); 1677 SendKeyEvent(ui::VKEY_Z, true, true);
1672 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1678 EXPECT_STR_EQ("h welloorld", textfield_->text());
1673 } 1679 }
1674 1680
1675 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { 1681 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) {
1676 InitTextfield(); 1682 InitTextfield();
1677 textfield_->SetText(ASCIIToUTF16("hello world")); 1683 textfield_->SetText(ASCIIToUTF16("hello world"));
1684 const int cursor_y = GetCursorYForTesting();
1678 1685
1679 base::string16 string; 1686 base::string16 string;
1680 ui::OSExchangeData data; 1687 ui::OSExchangeData data;
1681 int formats = 0; 1688 int formats = 0;
1682 int operations = 0; 1689 int operations = 0;
1683 std::set<ui::Clipboard::FormatType> format_types; 1690 std::set<ui::Clipboard::FormatType> format_types;
1684 1691
1685 // Start dragging " worl". 1692 // Start dragging " worl".
1686 textfield_->SelectRange(gfx::Range(5, 10)); 1693 textfield_->SelectRange(gfx::Range(5, 10));
1687 gfx::Point point(GetCursorPositionX(7), 0); 1694 gfx::Point point(GetCursorPositionX(7), cursor_y);
1688 MoveMouseTo(point); 1695 MoveMouseTo(point);
1689 PressLeftMouseButton(); 1696 PressLeftMouseButton();
1690 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point())); 1697 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point()));
1691 operations = textfield_->GetDragOperationsForView(textfield_, point); 1698 operations = textfield_->GetDragOperationsForView(textfield_, point);
1692 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1699 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1693 operations); 1700 operations);
1694 textfield_->WriteDragDataForView(nullptr, point, &data); 1701 textfield_->WriteDragDataForView(nullptr, point, &data);
1695 EXPECT_TRUE(data.GetString(&string)); 1702 EXPECT_TRUE(data.GetString(&string));
1696 EXPECT_EQ(textfield_->GetSelectedText(), string); 1703 EXPECT_EQ(textfield_->GetSelectedText(), string);
1697 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1704 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1698 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1705 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1699 EXPECT_TRUE(format_types.empty()); 1706 EXPECT_TRUE(format_types.empty());
1700 1707
1701 // Drop " worl" after "h". 1708 // Drop " worl" after "h".
1702 EXPECT_TRUE(textfield_->CanDrop(data)); 1709 EXPECT_TRUE(textfield_->CanDrop(data));
1703 gfx::Point drop_point(GetCursorPositionX(1), 0); 1710 gfx::Point drop_point(GetCursorPositionX(1), cursor_y);
1704 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); 1711 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations);
1705 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1712 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1706 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1713 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1707 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1714 EXPECT_STR_EQ("h worlellod", textfield_->text());
1708 textfield_->OnDragDone(); 1715 textfield_->OnDragDone();
1709 1716
1710 // Undo/Redo the drag&drop change. 1717 // Undo/Redo the drag&drop change.
1711 SendKeyEvent(ui::VKEY_Z, false, true); 1718 SendKeyEvent(ui::VKEY_Z, false, true);
1712 EXPECT_STR_EQ("hello world", textfield_->text()); 1719 EXPECT_STR_EQ("hello world", textfield_->text());
1713 SendKeyEvent(ui::VKEY_Z, false, true); 1720 SendKeyEvent(ui::VKEY_Z, false, true);
1714 EXPECT_STR_EQ("", textfield_->text()); 1721 EXPECT_STR_EQ("", textfield_->text());
1715 SendKeyEvent(ui::VKEY_Z, false, true); 1722 SendKeyEvent(ui::VKEY_Z, false, true);
1716 EXPECT_STR_EQ("", textfield_->text()); 1723 EXPECT_STR_EQ("", textfield_->text());
1717 SendKeyEvent(ui::VKEY_Z, true, true); 1724 SendKeyEvent(ui::VKEY_Z, true, true);
1718 EXPECT_STR_EQ("hello world", textfield_->text()); 1725 EXPECT_STR_EQ("hello world", textfield_->text());
1719 SendKeyEvent(ui::VKEY_Z, true, true); 1726 SendKeyEvent(ui::VKEY_Z, true, true);
1720 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1727 EXPECT_STR_EQ("h worlellod", textfield_->text());
1721 SendKeyEvent(ui::VKEY_Z, true, true); 1728 SendKeyEvent(ui::VKEY_Z, true, true);
1722 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1729 EXPECT_STR_EQ("h worlellod", textfield_->text());
1723 } 1730 }
1724 1731
1725 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1732 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1726 InitTextfield(); 1733 InitTextfield();
1727 textfield_->SetText(ASCIIToUTF16("hello world")); 1734 textfield_->SetText(ASCIIToUTF16("hello world"));
1735 const int cursor_y = GetCursorYForTesting();
1728 1736
1729 // Start dragging "worl". 1737 // Start dragging "worl".
1730 textfield_->SelectRange(gfx::Range(6, 10)); 1738 textfield_->SelectRange(gfx::Range(6, 10));
1731 gfx::Point point(GetCursorPositionX(8), 0); 1739 gfx::Point point(GetCursorPositionX(8), cursor_y);
1732 MoveMouseTo(point); 1740 MoveMouseTo(point);
1733 PressLeftMouseButton(); 1741 PressLeftMouseButton();
1734 ui::OSExchangeData data; 1742 ui::OSExchangeData data;
1735 textfield_->WriteDragDataForView(nullptr, point, &data); 1743 textfield_->WriteDragDataForView(nullptr, point, &data);
1736 EXPECT_TRUE(textfield_->CanDrop(data)); 1744 EXPECT_TRUE(textfield_->CanDrop(data));
1737 // Drag the text over somewhere valid, outside the current selection. 1745 // Drag the text over somewhere valid, outside the current selection.
1738 gfx::Point drop_point(GetCursorPositionX(2), 0); 1746 gfx::Point drop_point(GetCursorPositionX(2), cursor_y);
1739 ui::DropTargetEvent drop(data, drop_point, drop_point, 1747 ui::DropTargetEvent drop(data, drop_point, drop_point,
1740 ui::DragDropTypes::DRAG_MOVE); 1748 ui::DragDropTypes::DRAG_MOVE);
1741 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); 1749 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop));
1742 // "Cancel" the drag, via move and release over the selection, and OnDragDone. 1750 // "Cancel" the drag, via move and release over the selection, and OnDragDone.
1743 gfx::Point drag_point(GetCursorPositionX(9), 0); 1751 gfx::Point drag_point(GetCursorPositionX(9), cursor_y);
1744 DragMouseTo(drag_point); 1752 DragMouseTo(drag_point);
1745 ReleaseLeftMouseButton(); 1753 ReleaseLeftMouseButton();
1746 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); 1754 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text());
1747 } 1755 }
1748 1756
1749 TEST_F(TextfieldTest, ReadOnlyTest) { 1757 TEST_F(TextfieldTest, ReadOnlyTest) {
1750 InitTextfield(); 1758 InitTextfield();
1751 textfield_->SetText(ASCIIToUTF16("read only")); 1759 textfield_->SetText(ASCIIToUTF16("read only"));
1752 textfield_->SetReadOnly(true); 1760 textfield_->SetReadOnly(true);
1753 EXPECT_TRUE(textfield_->enabled()); 1761 EXPECT_TRUE(textfield_->enabled());
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 2604
2597 // Drag the mouse to the beginning of the textfield. 2605 // Drag the mouse to the beginning of the textfield.
2598 DragMouseTo(beginning); 2606 DragMouseTo(beginning);
2599 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 2607 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
2600 } 2608 }
2601 2609
2602 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 2610 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2603 TEST_F(TextfieldTest, SelectionClipboard) { 2611 TEST_F(TextfieldTest, SelectionClipboard) {
2604 InitTextfield(); 2612 InitTextfield();
2605 textfield_->SetText(ASCIIToUTF16("0123")); 2613 textfield_->SetText(ASCIIToUTF16("0123"));
2606 gfx::Point point_1(GetCursorPositionX(1), 0); 2614 const int cursor_y = GetCursorYForTesting();
2607 gfx::Point point_2(GetCursorPositionX(2), 0); 2615 gfx::Point point_1(GetCursorPositionX(1), cursor_y);
2608 gfx::Point point_3(GetCursorPositionX(3), 0); 2616 gfx::Point point_2(GetCursorPositionX(2), cursor_y);
2609 gfx::Point point_4(GetCursorPositionX(4), 0); 2617 gfx::Point point_3(GetCursorPositionX(3), cursor_y);
2618 gfx::Point point_4(GetCursorPositionX(4), cursor_y);
2610 2619
2611 // Text selected by the mouse should be placed on the selection clipboard. 2620 // Text selected by the mouse should be placed on the selection clipboard.
2612 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, 2621 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1,
2613 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2622 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2614 ui::EF_LEFT_MOUSE_BUTTON); 2623 ui::EF_LEFT_MOUSE_BUTTON);
2615 textfield_->OnMousePressed(press); 2624 textfield_->OnMousePressed(press);
2616 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3, 2625 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3,
2617 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2626 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2618 ui::EF_LEFT_MOUSE_BUTTON); 2627 ui::EF_LEFT_MOUSE_BUTTON);
2619 textfield_->OnMouseDragged(drag); 2628 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. 2706 // Middle clicking in the selection should clear the clipboard and selection.
2698 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); 2707 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo");
2699 textfield_->SelectRange(gfx::Range(2, 6)); 2708 textfield_->SelectRange(gfx::Range(2, 6));
2700 textfield_->OnMousePressed(middle); 2709 textfield_->OnMousePressed(middle);
2701 EXPECT_STR_EQ("012301230123", textfield_->text()); 2710 EXPECT_STR_EQ("012301230123", textfield_->text());
2702 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); 2711 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange());
2703 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); 2712 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
2704 2713
2705 // Double and triple clicking should update the clipboard contents. 2714 // Double and triple clicking should update the clipboard contents.
2706 textfield_->SetText(ASCIIToUTF16("ab cd ef")); 2715 textfield_->SetText(ASCIIToUTF16("ab cd ef"));
2707 gfx::Point word(GetCursorPositionX(4), 0); 2716 gfx::Point word(GetCursorPositionX(4), cursor_y);
2708 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, 2717 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word,
2709 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2718 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2710 ui::EF_LEFT_MOUSE_BUTTON); 2719 ui::EF_LEFT_MOUSE_BUTTON);
2711 textfield_->OnMousePressed(press_word); 2720 textfield_->OnMousePressed(press_word);
2712 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, 2721 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word,
2713 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2722 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2714 ui::EF_LEFT_MOUSE_BUTTON); 2723 ui::EF_LEFT_MOUSE_BUTTON);
2715 textfield_->OnMouseReleased(release_word); 2724 textfield_->OnMouseReleased(release_word);
2716 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word, 2725 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word,
2717 ui::EventTimeForNow(), 2726 ui::EventTimeForNow(),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 } 2791 }
2783 #endif 2792 #endif
2784 2793
2785 // Long_Press gesture in Textfield can initiate a drag and drop now. 2794 // Long_Press gesture in Textfield can initiate a drag and drop now.
2786 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { 2795 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) {
2787 InitTextfield(); 2796 InitTextfield();
2788 textfield_->SetText(ASCIIToUTF16("Hello string world")); 2797 textfield_->SetText(ASCIIToUTF16("Hello string world"));
2789 2798
2790 // Ensure the textfield will provide selected text for drag data. 2799 // Ensure the textfield will provide selected text for drag data.
2791 textfield_->SelectRange(gfx::Range(6, 12)); 2800 textfield_->SelectRange(gfx::Range(6, 12));
2792 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 2801 const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting());
2793 2802
2794 // Enable touch-drag-drop to make long press effective. 2803 // Enable touch-drag-drop to make long press effective.
2795 base::CommandLine::ForCurrentProcess()->AppendSwitch( 2804 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2796 switches::kEnableTouchDragDrop); 2805 switches::kEnableTouchDragDrop);
2797 2806
2798 // Create a long press event in the selected region should start a drag. 2807 // Create a long press event in the selected region should start a drag.
2799 GestureEventForTest long_press( 2808 GestureEventForTest long_press(
2800 kStringPoint.x(), 2809 kStringPoint.x(),
2801 kStringPoint.y(), 2810 kStringPoint.y(),
2802 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); 2811 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; 3012 ui::AXNodeData node_data_protected;
3004 node_data_protected.state = 0; 3013 node_data_protected.state = 0;
3005 textfield_->GetAccessibleNodeData(&node_data_protected); 3014 textfield_->GetAccessibleNodeData(&node_data_protected);
3006 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); 3015 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role);
3007 EXPECT_EQ(ASCIIToUTF16("********"), 3016 EXPECT_EQ(ASCIIToUTF16("********"),
3008 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); 3017 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE));
3009 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 3018 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
3010 } 3019 }
3011 3020
3012 } // namespace views 3021 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698