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

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

Issue 2541313002: RenderTextHarfBuzz: Add support for multi line text selection. (Closed)
Patch Set: Fix test. Created 3 years, 12 months 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
« no previous file with comments | « ui/views/controls/label_unittest.cc ('k') | ui/views/examples/label_example.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 widget_->GetFocusManager()->AdvanceFocus(true); 1388 widget_->GetFocusManager()->AdvanceFocus(true);
1385 EXPECT_EQ(3, GetFocusedView()->id()); 1389 EXPECT_EQ(3, GetFocusedView()->id());
1386 1390
1387 // Request focus should still work. 1391 // Request focus should still work.
1388 textfield_->RequestFocus(); 1392 textfield_->RequestFocus();
1389 EXPECT_EQ(1, GetFocusedView()->id()); 1393 EXPECT_EQ(1, GetFocusedView()->id());
1390 1394
1391 // Test if clicking on textfield view sets the focus. 1395 // Test if clicking on textfield view sets the focus.
1392 widget_->GetFocusManager()->AdvanceFocus(true); 1396 widget_->GetFocusManager()->AdvanceFocus(true);
1393 EXPECT_EQ(3, GetFocusedView()->id()); 1397 EXPECT_EQ(3, GetFocusedView()->id());
1394 MoveMouseTo(gfx::Point()); 1398 MoveMouseTo(gfx::Point(0, GetCursorYForTesting()));
1395 ClickLeftMouseButton(); 1399 ClickLeftMouseButton();
1396 EXPECT_EQ(1, GetFocusedView()->id()); 1400 EXPECT_EQ(1, GetFocusedView()->id());
1397 1401
1398 // Tab/Shift+Tab should also cycle focus, not insert a tab character. 1402 // Tab/Shift+Tab should also cycle focus, not insert a tab character.
1399 SendKeyEvent(ui::VKEY_TAB, false, false); 1403 SendKeyEvent(ui::VKEY_TAB, false, false);
1400 EXPECT_EQ(2, GetFocusedView()->id()); 1404 EXPECT_EQ(2, GetFocusedView()->id());
1401 SendKeyEvent(ui::VKEY_TAB, false, false); 1405 SendKeyEvent(ui::VKEY_TAB, false, false);
1402 EXPECT_EQ(3, GetFocusedView()->id()); 1406 EXPECT_EQ(3, GetFocusedView()->id());
1403 // Cycle back to the first textfield. 1407 // Cycle back to the first textfield.
1404 SendKeyEvent(ui::VKEY_TAB, false, false); 1408 SendKeyEvent(ui::VKEY_TAB, false, false);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 // Exercise the "paste enabled?" check in the verifier. 1440 // Exercise the "paste enabled?" check in the verifier.
1437 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test"); 1441 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "Test");
1438 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); 1442 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel());
1439 } 1443 }
1440 1444
1441 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { 1445 TEST_F(TextfieldTest, DoubleAndTripleClickTest) {
1442 InitTextfield(); 1446 InitTextfield();
1443 textfield_->SetText(ASCIIToUTF16("hello world")); 1447 textfield_->SetText(ASCIIToUTF16("hello world"));
1444 1448
1445 // Test for double click. 1449 // Test for double click.
1446 MoveMouseTo(gfx::Point()); 1450 MoveMouseTo(gfx::Point(0, GetCursorYForTesting()));
1447 ClickLeftMouseButton(); 1451 ClickLeftMouseButton();
1448 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1452 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1449 ClickLeftMouseButton(ui::EF_IS_DOUBLE_CLICK); 1453 ClickLeftMouseButton(ui::EF_IS_DOUBLE_CLICK);
1450 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1454 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1451 1455
1452 // Test for triple click. 1456 // Test for triple click.
1453 ClickLeftMouseButton(); 1457 ClickLeftMouseButton();
1454 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); 1458 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText());
1455 1459
1456 // Another click should reset back to double click. 1460 // Another click should reset back to double click.
1457 ClickLeftMouseButton(); 1461 ClickLeftMouseButton();
1458 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); 1462 EXPECT_STR_EQ("hello", textfield_->GetSelectedText());
1459 } 1463 }
1460 1464
1461 // Tests text selection behavior on a right click. 1465 // Tests text selection behavior on a right click.
1462 TEST_F(TextfieldTest, SelectWordOnRightClick) { 1466 TEST_F(TextfieldTest, SelectWordOnRightClick) {
1463 InitTextfield(); 1467 InitTextfield();
1464 textfield_->SetText(ASCIIToUTF16("hello world")); 1468 textfield_->SetText(ASCIIToUTF16("hello world"));
1465 1469
1466 // Verify right clicking within the selection does not alter the selection. 1470 // Verify right clicking within the selection does not alter the selection.
1467 textfield_->SelectRange(gfx::Range(1, 5)); 1471 textfield_->SelectRange(gfx::Range(1, 5));
1468 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); 1472 EXPECT_STR_EQ("ello", textfield_->GetSelectedText());
1469 MoveMouseTo(gfx::Point(GetCursorPositionX(3), 0)); 1473 const int cursor_y = GetCursorYForTesting();
1474 MoveMouseTo(gfx::Point(GetCursorPositionX(3), cursor_y));
1470 ClickRightMouseButton(); 1475 ClickRightMouseButton();
1471 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); 1476 EXPECT_STR_EQ("ello", textfield_->GetSelectedText());
1472 1477
1473 // Verify right clicking outside the selection, selects the word under the 1478 // Verify right clicking outside the selection, selects the word under the
1474 // cursor on platforms where this is expected. 1479 // cursor on platforms where this is expected.
1475 MoveMouseTo(gfx::Point(GetCursorPositionX(8), 0)); 1480 MoveMouseTo(gfx::Point(GetCursorPositionX(8), cursor_y));
1476 const char* expected_right_click = 1481 const char* expected_right_click =
1477 PlatformStyle::kSelectWordOnRightClick ? "world" : "ello"; 1482 PlatformStyle::kSelectWordOnRightClick ? "world" : "ello";
1478 ClickRightMouseButton(); 1483 ClickRightMouseButton();
1479 EXPECT_STR_EQ(expected_right_click, textfield_->GetSelectedText()); 1484 EXPECT_STR_EQ(expected_right_click, textfield_->GetSelectedText());
1480 } 1485 }
1481 1486
1482 TEST_F(TextfieldTest, DragToSelect) { 1487 TEST_F(TextfieldTest, DragToSelect) {
1483 InitTextfield(); 1488 InitTextfield();
1484 textfield_->SetText(ASCIIToUTF16("hello world")); 1489 textfield_->SetText(ASCIIToUTF16("hello world"));
1485 const int kStart = GetCursorPositionX(5); 1490 const int kStart = GetCursorPositionX(5);
1486 const int kEnd = 500; 1491 const int kEnd = 500;
1487 gfx::Point start_point(kStart, 0); 1492 const int cursor_y = GetCursorYForTesting();
1488 gfx::Point end_point(kEnd, 0); 1493 gfx::Point start_point(kStart, cursor_y);
1494 gfx::Point end_point(kEnd, cursor_y);
1489 1495
1490 MoveMouseTo(start_point); 1496 MoveMouseTo(start_point);
1491 PressLeftMouseButton(); 1497 PressLeftMouseButton();
1492 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 1498 EXPECT_TRUE(textfield_->GetSelectedText().empty());
1493 1499
1494 // Check that dragging left selects the beginning of the string. 1500 // Check that dragging left selects the beginning of the string.
1495 DragMouseTo(gfx::Point()); 1501 DragMouseTo(gfx::Point(0, cursor_y));
1496 base::string16 text_left = textfield_->GetSelectedText(); 1502 base::string16 text_left = textfield_->GetSelectedText();
1497 EXPECT_STR_EQ("hello", text_left); 1503 EXPECT_STR_EQ("hello", text_left);
1498 1504
1499 // Check that dragging right selects the rest of the string. 1505 // Check that dragging right selects the rest of the string.
1500 DragMouseTo(end_point); 1506 DragMouseTo(end_point);
1501 base::string16 text_right = textfield_->GetSelectedText(); 1507 base::string16 text_right = textfield_->GetSelectedText();
1502 EXPECT_STR_EQ(" world", text_right); 1508 EXPECT_STR_EQ(" world", text_right);
1503 1509
1504 // Check that releasing in the same location does not alter the selection. 1510 // Check that releasing in the same location does not alter the selection.
1505 ReleaseLeftMouseButton(); 1511 ReleaseLeftMouseButton();
1506 EXPECT_EQ(text_right, textfield_->GetSelectedText()); 1512 EXPECT_EQ(text_right, textfield_->GetSelectedText());
1507 1513
1508 // Check that dragging from beyond the text length works too. 1514 // Check that dragging from beyond the text length works too.
1509 MoveMouseTo(end_point); 1515 MoveMouseTo(end_point);
1510 PressLeftMouseButton(); 1516 PressLeftMouseButton();
1511 DragMouseTo(gfx::Point()); 1517 DragMouseTo(gfx::Point(0, cursor_y));
1512 ReleaseLeftMouseButton(); 1518 ReleaseLeftMouseButton();
1513 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); 1519 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText());
1514 } 1520 }
1515 1521
1516 // This test checks that dragging above the textfield selects to the beginning 1522 // This test checks that dragging above the textfield selects to the beginning
1517 // and dragging below the textfield selects to the end, but only on platforms 1523 // and dragging below the textfield selects to the end, but only on platforms
1518 // where that is the expected behavior. 1524 // where that is the expected behavior.
1519 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) { 1525 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) {
1520 InitTextfield(); 1526 InitTextfield();
1521 textfield_->SetText(ASCIIToUTF16("hello world")); 1527 textfield_->SetText(ASCIIToUTF16("hello world"));
1522 const base::string16 expected_up = base::ASCIIToUTF16( 1528 const base::string16 expected_up = base::ASCIIToUTF16(
1523 PlatformStyle::kTextDragVerticallyDragsToEnd ? "hello" : "lo"); 1529 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? "hello" : "lo");
1524 const base::string16 expected_down = base::ASCIIToUTF16( 1530 const base::string16 expected_down = base::ASCIIToUTF16(
1525 PlatformStyle::kTextDragVerticallyDragsToEnd ? " world" : " w"); 1531 gfx::RenderText::kDragToEndIfOutsideVerticalBounds ? " world" : " w");
1526 const int kStartX = GetCursorPositionX(5); 1532 const int kStartX = GetCursorPositionX(5);
1527 const int kDownX = GetCursorPositionX(7); 1533 const int kDownX = GetCursorPositionX(7);
1528 const int kUpX = GetCursorPositionX(3); 1534 const int kUpX = GetCursorPositionX(3);
1529 gfx::Point start_point(kStartX, 0); 1535 gfx::Point start_point(kStartX, GetCursorYForTesting());
1530 gfx::Point down_point(kDownX, 500); 1536 gfx::Point down_point(kDownX, 500);
1531 gfx::Point up_point(kUpX, -500); 1537 gfx::Point up_point(kUpX, -500);
1532 1538
1533 MoveMouseTo(start_point); 1539 MoveMouseTo(start_point);
1534 PressLeftMouseButton(); 1540 PressLeftMouseButton();
1535 DragMouseTo(up_point); 1541 DragMouseTo(up_point);
1536 ReleaseLeftMouseButton(); 1542 ReleaseLeftMouseButton();
1537 EXPECT_EQ(textfield_->GetSelectedText(), expected_up); 1543 EXPECT_EQ(textfield_->GetSelectedText(), expected_up);
1538 1544
1539 // Click at |up_point|. This is important because drags do not count as clicks 1545 // 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
1605 1611
1606 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { 1612 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) {
1607 InitTextfield(); 1613 InitTextfield();
1608 textfield_->SetText(ASCIIToUTF16("hello string world")); 1614 textfield_->SetText(ASCIIToUTF16("hello string world"));
1609 1615
1610 // Ensure the textfield will provide selected text for drag data. 1616 // Ensure the textfield will provide selected text for drag data.
1611 base::string16 string; 1617 base::string16 string;
1612 ui::OSExchangeData data; 1618 ui::OSExchangeData data;
1613 const gfx::Range kStringRange(6, 12); 1619 const gfx::Range kStringRange(6, 12);
1614 textfield_->SelectRange(kStringRange); 1620 textfield_->SelectRange(kStringRange);
1615 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 1621 const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting());
1616 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); 1622 textfield_->WriteDragDataForView(NULL, kStringPoint, &data);
1617 EXPECT_TRUE(data.GetString(&string)); 1623 EXPECT_TRUE(data.GetString(&string));
1618 EXPECT_EQ(textfield_->GetSelectedText(), string); 1624 EXPECT_EQ(textfield_->GetSelectedText(), string);
1619 1625
1620 // Ensure that disabled textfields do not support drag operations. 1626 // Ensure that disabled textfields do not support drag operations.
1621 textfield_->SetEnabled(false); 1627 textfield_->SetEnabled(false);
1622 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 1628 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
1623 textfield_->GetDragOperationsForView(NULL, kStringPoint)); 1629 textfield_->GetDragOperationsForView(NULL, kStringPoint));
1624 textfield_->SetEnabled(true); 1630 textfield_->SetEnabled(true);
1625 // Ensure that textfields without selections do not support drag operations. 1631 // Ensure that textfields without selections do not support drag operations.
(...skipping 18 matching lines...) Expand all
1644 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, 1650 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint,
1645 gfx::Point())); 1651 gfx::Point()));
1646 // Ensure that textfields support local moves. 1652 // Ensure that textfields support local moves.
1647 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1653 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1648 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); 1654 textfield_->GetDragOperationsForView(textfield_, kStringPoint));
1649 } 1655 }
1650 1656
1651 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { 1657 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) {
1652 InitTextfield(); 1658 InitTextfield();
1653 textfield_->SetText(ASCIIToUTF16("hello world")); 1659 textfield_->SetText(ASCIIToUTF16("hello world"));
1660 const int cursor_y = GetCursorYForTesting();
1654 1661
1655 base::string16 string; 1662 base::string16 string;
1656 ui::OSExchangeData data; 1663 ui::OSExchangeData data;
1657 int formats = 0; 1664 int formats = 0;
1658 int operations = 0; 1665 int operations = 0;
1659 std::set<ui::Clipboard::FormatType> format_types; 1666 std::set<ui::Clipboard::FormatType> format_types;
1660 1667
1661 // Start dragging "ello". 1668 // Start dragging "ello".
1662 textfield_->SelectRange(gfx::Range(1, 5)); 1669 textfield_->SelectRange(gfx::Range(1, 5));
1663 gfx::Point point(GetCursorPositionX(3), 0); 1670 gfx::Point point(GetCursorPositionX(3), cursor_y);
1664 MoveMouseTo(point); 1671 MoveMouseTo(point);
1665 PressLeftMouseButton(); 1672 PressLeftMouseButton();
1666 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, point)); 1673 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, point));
1667 operations = textfield_->GetDragOperationsForView(textfield_, point); 1674 operations = textfield_->GetDragOperationsForView(textfield_, point);
1668 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1675 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1669 operations); 1676 operations);
1670 textfield_->WriteDragDataForView(nullptr, point, &data); 1677 textfield_->WriteDragDataForView(nullptr, point, &data);
1671 EXPECT_TRUE(data.GetString(&string)); 1678 EXPECT_TRUE(data.GetString(&string));
1672 EXPECT_EQ(textfield_->GetSelectedText(), string); 1679 EXPECT_EQ(textfield_->GetSelectedText(), string);
1673 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1680 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1674 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1681 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1675 EXPECT_TRUE(format_types.empty()); 1682 EXPECT_TRUE(format_types.empty());
1676 1683
1677 // Drop "ello" after "w". 1684 // Drop "ello" after "w".
1678 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); 1685 const gfx::Point kDropPoint(GetCursorPositionX(7), cursor_y);
1679 EXPECT_TRUE(textfield_->CanDrop(data)); 1686 EXPECT_TRUE(textfield_->CanDrop(data));
1680 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); 1687 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations);
1681 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1688 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1682 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1689 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1683 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1690 EXPECT_STR_EQ("h welloorld", textfield_->text());
1684 textfield_->OnDragDone(); 1691 textfield_->OnDragDone();
1685 1692
1686 // Undo/Redo the drag&drop change. 1693 // Undo/Redo the drag&drop change.
1687 SendKeyEvent(ui::VKEY_Z, false, true); 1694 SendKeyEvent(ui::VKEY_Z, false, true);
1688 EXPECT_STR_EQ("hello world", textfield_->text()); 1695 EXPECT_STR_EQ("hello world", textfield_->text());
1689 SendKeyEvent(ui::VKEY_Z, false, true); 1696 SendKeyEvent(ui::VKEY_Z, false, true);
1690 EXPECT_STR_EQ("", textfield_->text()); 1697 EXPECT_STR_EQ("", textfield_->text());
1691 SendKeyEvent(ui::VKEY_Z, false, true); 1698 SendKeyEvent(ui::VKEY_Z, false, true);
1692 EXPECT_STR_EQ("", textfield_->text()); 1699 EXPECT_STR_EQ("", textfield_->text());
1693 SendKeyEvent(ui::VKEY_Z, true, true); 1700 SendKeyEvent(ui::VKEY_Z, true, true);
1694 EXPECT_STR_EQ("hello world", textfield_->text()); 1701 EXPECT_STR_EQ("hello world", textfield_->text());
1695 SendKeyEvent(ui::VKEY_Z, true, true); 1702 SendKeyEvent(ui::VKEY_Z, true, true);
1696 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1703 EXPECT_STR_EQ("h welloorld", textfield_->text());
1697 SendKeyEvent(ui::VKEY_Z, true, true); 1704 SendKeyEvent(ui::VKEY_Z, true, true);
1698 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1705 EXPECT_STR_EQ("h welloorld", textfield_->text());
1699 } 1706 }
1700 1707
1701 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { 1708 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) {
1702 InitTextfield(); 1709 InitTextfield();
1703 textfield_->SetText(ASCIIToUTF16("hello world")); 1710 textfield_->SetText(ASCIIToUTF16("hello world"));
1711 const int cursor_y = GetCursorYForTesting();
1704 1712
1705 base::string16 string; 1713 base::string16 string;
1706 ui::OSExchangeData data; 1714 ui::OSExchangeData data;
1707 int formats = 0; 1715 int formats = 0;
1708 int operations = 0; 1716 int operations = 0;
1709 std::set<ui::Clipboard::FormatType> format_types; 1717 std::set<ui::Clipboard::FormatType> format_types;
1710 1718
1711 // Start dragging " worl". 1719 // Start dragging " worl".
1712 textfield_->SelectRange(gfx::Range(5, 10)); 1720 textfield_->SelectRange(gfx::Range(5, 10));
1713 gfx::Point point(GetCursorPositionX(7), 0); 1721 gfx::Point point(GetCursorPositionX(7), cursor_y);
1714 MoveMouseTo(point); 1722 MoveMouseTo(point);
1715 PressLeftMouseButton(); 1723 PressLeftMouseButton();
1716 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point())); 1724 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, point, gfx::Point()));
1717 operations = textfield_->GetDragOperationsForView(textfield_, point); 1725 operations = textfield_->GetDragOperationsForView(textfield_, point);
1718 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1726 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1719 operations); 1727 operations);
1720 textfield_->WriteDragDataForView(nullptr, point, &data); 1728 textfield_->WriteDragDataForView(nullptr, point, &data);
1721 EXPECT_TRUE(data.GetString(&string)); 1729 EXPECT_TRUE(data.GetString(&string));
1722 EXPECT_EQ(textfield_->GetSelectedText(), string); 1730 EXPECT_EQ(textfield_->GetSelectedText(), string);
1723 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types)); 1731 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &format_types));
1724 EXPECT_EQ(ui::OSExchangeData::STRING, formats); 1732 EXPECT_EQ(ui::OSExchangeData::STRING, formats);
1725 EXPECT_TRUE(format_types.empty()); 1733 EXPECT_TRUE(format_types.empty());
1726 1734
1727 // Drop " worl" after "h". 1735 // Drop " worl" after "h".
1728 EXPECT_TRUE(textfield_->CanDrop(data)); 1736 EXPECT_TRUE(textfield_->CanDrop(data));
1729 gfx::Point drop_point(GetCursorPositionX(1), 0); 1737 gfx::Point drop_point(GetCursorPositionX(1), cursor_y);
1730 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); 1738 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations);
1731 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); 1739 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a));
1732 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); 1740 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a));
1733 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1741 EXPECT_STR_EQ("h worlellod", textfield_->text());
1734 textfield_->OnDragDone(); 1742 textfield_->OnDragDone();
1735 1743
1736 // Undo/Redo the drag&drop change. 1744 // Undo/Redo the drag&drop change.
1737 SendKeyEvent(ui::VKEY_Z, false, true); 1745 SendKeyEvent(ui::VKEY_Z, false, true);
1738 EXPECT_STR_EQ("hello world", textfield_->text()); 1746 EXPECT_STR_EQ("hello world", textfield_->text());
1739 SendKeyEvent(ui::VKEY_Z, false, true); 1747 SendKeyEvent(ui::VKEY_Z, false, true);
1740 EXPECT_STR_EQ("", textfield_->text()); 1748 EXPECT_STR_EQ("", textfield_->text());
1741 SendKeyEvent(ui::VKEY_Z, false, true); 1749 SendKeyEvent(ui::VKEY_Z, false, true);
1742 EXPECT_STR_EQ("", textfield_->text()); 1750 EXPECT_STR_EQ("", textfield_->text());
1743 SendKeyEvent(ui::VKEY_Z, true, true); 1751 SendKeyEvent(ui::VKEY_Z, true, true);
1744 EXPECT_STR_EQ("hello world", textfield_->text()); 1752 EXPECT_STR_EQ("hello world", textfield_->text());
1745 SendKeyEvent(ui::VKEY_Z, true, true); 1753 SendKeyEvent(ui::VKEY_Z, true, true);
1746 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1754 EXPECT_STR_EQ("h worlellod", textfield_->text());
1747 SendKeyEvent(ui::VKEY_Z, true, true); 1755 SendKeyEvent(ui::VKEY_Z, true, true);
1748 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1756 EXPECT_STR_EQ("h worlellod", textfield_->text());
1749 } 1757 }
1750 1758
1751 TEST_F(TextfieldTest, DragAndDrop_Canceled) { 1759 TEST_F(TextfieldTest, DragAndDrop_Canceled) {
1752 InitTextfield(); 1760 InitTextfield();
1753 textfield_->SetText(ASCIIToUTF16("hello world")); 1761 textfield_->SetText(ASCIIToUTF16("hello world"));
1762 const int cursor_y = GetCursorYForTesting();
1754 1763
1755 // Start dragging "worl". 1764 // Start dragging "worl".
1756 textfield_->SelectRange(gfx::Range(6, 10)); 1765 textfield_->SelectRange(gfx::Range(6, 10));
1757 gfx::Point point(GetCursorPositionX(8), 0); 1766 gfx::Point point(GetCursorPositionX(8), cursor_y);
1758 MoveMouseTo(point); 1767 MoveMouseTo(point);
1759 PressLeftMouseButton(); 1768 PressLeftMouseButton();
1760 ui::OSExchangeData data; 1769 ui::OSExchangeData data;
1761 textfield_->WriteDragDataForView(nullptr, point, &data); 1770 textfield_->WriteDragDataForView(nullptr, point, &data);
1762 EXPECT_TRUE(textfield_->CanDrop(data)); 1771 EXPECT_TRUE(textfield_->CanDrop(data));
1763 // Drag the text over somewhere valid, outside the current selection. 1772 // Drag the text over somewhere valid, outside the current selection.
1764 gfx::Point drop_point(GetCursorPositionX(2), 0); 1773 gfx::Point drop_point(GetCursorPositionX(2), cursor_y);
1765 ui::DropTargetEvent drop(data, drop_point, drop_point, 1774 ui::DropTargetEvent drop(data, drop_point, drop_point,
1766 ui::DragDropTypes::DRAG_MOVE); 1775 ui::DragDropTypes::DRAG_MOVE);
1767 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); 1776 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop));
1768 // "Cancel" the drag, via move and release over the selection, and OnDragDone. 1777 // "Cancel" the drag, via move and release over the selection, and OnDragDone.
1769 gfx::Point drag_point(GetCursorPositionX(9), 0); 1778 gfx::Point drag_point(GetCursorPositionX(9), cursor_y);
1770 DragMouseTo(drag_point); 1779 DragMouseTo(drag_point);
1771 ReleaseLeftMouseButton(); 1780 ReleaseLeftMouseButton();
1772 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); 1781 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text());
1773 } 1782 }
1774 1783
1775 TEST_F(TextfieldTest, ReadOnlyTest) { 1784 TEST_F(TextfieldTest, ReadOnlyTest) {
1776 InitTextfield(); 1785 InitTextfield();
1777 textfield_->SetText(ASCIIToUTF16("read only")); 1786 textfield_->SetText(ASCIIToUTF16("read only"));
1778 textfield_->SetReadOnly(true); 1787 textfield_->SetReadOnly(true);
1779 EXPECT_TRUE(textfield_->enabled()); 1788 EXPECT_TRUE(textfield_->enabled());
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2622 2631
2623 // Drag the mouse to the beginning of the textfield. 2632 // Drag the mouse to the beginning of the textfield.
2624 DragMouseTo(beginning); 2633 DragMouseTo(beginning);
2625 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); 2634 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
2626 } 2635 }
2627 2636
2628 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 2637 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2629 TEST_F(TextfieldTest, SelectionClipboard) { 2638 TEST_F(TextfieldTest, SelectionClipboard) {
2630 InitTextfield(); 2639 InitTextfield();
2631 textfield_->SetText(ASCIIToUTF16("0123")); 2640 textfield_->SetText(ASCIIToUTF16("0123"));
2632 gfx::Point point_1(GetCursorPositionX(1), 0); 2641 const int cursor_y = GetCursorYForTesting();
2633 gfx::Point point_2(GetCursorPositionX(2), 0); 2642 gfx::Point point_1(GetCursorPositionX(1), cursor_y);
2634 gfx::Point point_3(GetCursorPositionX(3), 0); 2643 gfx::Point point_2(GetCursorPositionX(2), cursor_y);
2635 gfx::Point point_4(GetCursorPositionX(4), 0); 2644 gfx::Point point_3(GetCursorPositionX(3), cursor_y);
2645 gfx::Point point_4(GetCursorPositionX(4), cursor_y);
2636 2646
2637 // Text selected by the mouse should be placed on the selection clipboard. 2647 // Text selected by the mouse should be placed on the selection clipboard.
2638 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1, 2648 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, point_1, point_1,
2639 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2649 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2640 ui::EF_LEFT_MOUSE_BUTTON); 2650 ui::EF_LEFT_MOUSE_BUTTON);
2641 textfield_->OnMousePressed(press); 2651 textfield_->OnMousePressed(press);
2642 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3, 2652 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, point_3, point_3,
2643 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2653 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2644 ui::EF_LEFT_MOUSE_BUTTON); 2654 ui::EF_LEFT_MOUSE_BUTTON);
2645 textfield_->OnMouseDragged(drag); 2655 textfield_->OnMouseDragged(drag);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2723 // Middle clicking in the selection should clear the clipboard and selection. 2733 // Middle clicking in the selection should clear the clipboard and selection.
2724 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo"); 2734 SetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE, "foo");
2725 textfield_->SelectRange(gfx::Range(2, 6)); 2735 textfield_->SelectRange(gfx::Range(2, 6));
2726 textfield_->OnMousePressed(middle); 2736 textfield_->OnMousePressed(middle);
2727 EXPECT_STR_EQ("012301230123", textfield_->text()); 2737 EXPECT_STR_EQ("012301230123", textfield_->text());
2728 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange()); 2738 EXPECT_EQ(gfx::Range(6, 6), textfield_->GetSelectedRange());
2729 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty()); 2739 EXPECT_TRUE(GetClipboardText(ui::CLIPBOARD_TYPE_SELECTION).empty());
2730 2740
2731 // Double and triple clicking should update the clipboard contents. 2741 // Double and triple clicking should update the clipboard contents.
2732 textfield_->SetText(ASCIIToUTF16("ab cd ef")); 2742 textfield_->SetText(ASCIIToUTF16("ab cd ef"));
2733 gfx::Point word(GetCursorPositionX(4), 0); 2743 gfx::Point word(GetCursorPositionX(4), cursor_y);
2734 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word, 2744 ui::MouseEvent press_word(ui::ET_MOUSE_PRESSED, word, word,
2735 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2745 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2736 ui::EF_LEFT_MOUSE_BUTTON); 2746 ui::EF_LEFT_MOUSE_BUTTON);
2737 textfield_->OnMousePressed(press_word); 2747 textfield_->OnMousePressed(press_word);
2738 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word, 2748 ui::MouseEvent release_word(ui::ET_MOUSE_RELEASED, word, word,
2739 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 2749 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
2740 ui::EF_LEFT_MOUSE_BUTTON); 2750 ui::EF_LEFT_MOUSE_BUTTON);
2741 textfield_->OnMouseReleased(release_word); 2751 textfield_->OnMouseReleased(release_word);
2742 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word, 2752 ui::MouseEvent double_click(ui::ET_MOUSE_PRESSED, word, word,
2743 ui::EventTimeForNow(), 2753 ui::EventTimeForNow(),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 } 2818 }
2809 #endif 2819 #endif
2810 2820
2811 // Long_Press gesture in Textfield can initiate a drag and drop now. 2821 // Long_Press gesture in Textfield can initiate a drag and drop now.
2812 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { 2822 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) {
2813 InitTextfield(); 2823 InitTextfield();
2814 textfield_->SetText(ASCIIToUTF16("Hello string world")); 2824 textfield_->SetText(ASCIIToUTF16("Hello string world"));
2815 2825
2816 // Ensure the textfield will provide selected text for drag data. 2826 // Ensure the textfield will provide selected text for drag data.
2817 textfield_->SelectRange(gfx::Range(6, 12)); 2827 textfield_->SelectRange(gfx::Range(6, 12));
2818 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 2828 const gfx::Point kStringPoint(GetCursorPositionX(9), GetCursorYForTesting());
2819 2829
2820 // Enable touch-drag-drop to make long press effective. 2830 // Enable touch-drag-drop to make long press effective.
2821 base::CommandLine::ForCurrentProcess()->AppendSwitch( 2831 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2822 switches::kEnableTouchDragDrop); 2832 switches::kEnableTouchDragDrop);
2823 2833
2824 // Create a long press event in the selected region should start a drag. 2834 // Create a long press event in the selected region should start a drag.
2825 GestureEventForTest long_press( 2835 GestureEventForTest long_press(
2826 kStringPoint.x(), 2836 kStringPoint.x(),
2827 kStringPoint.y(), 2837 kStringPoint.y(),
2828 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS)); 2838 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3029 ui::AXNodeData node_data_protected; 3039 ui::AXNodeData node_data_protected;
3030 node_data_protected.state = 0; 3040 node_data_protected.state = 0;
3031 textfield_->GetAccessibleNodeData(&node_data_protected); 3041 textfield_->GetAccessibleNodeData(&node_data_protected);
3032 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); 3042 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role);
3033 EXPECT_EQ(ASCIIToUTF16("********"), 3043 EXPECT_EQ(ASCIIToUTF16("********"),
3034 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); 3044 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE));
3035 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 3045 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
3036 } 3046 }
3037 3047
3038 } // namespace views 3048 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label_unittest.cc ('k') | ui/views/examples/label_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698