| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 // Test for triple click. | 1456 // Test for triple click. |
| 1457 ClickLeftMouseButton(); | 1457 ClickLeftMouseButton(); |
| 1458 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); | 1458 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); |
| 1459 | 1459 |
| 1460 // Another click should reset back to double click. | 1460 // Another click should reset back to double click. |
| 1461 ClickLeftMouseButton(); | 1461 ClickLeftMouseButton(); |
| 1462 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1462 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 1463 } | 1463 } |
| 1464 | 1464 |
| 1465 // Tests text selection behavior on a right click. | 1465 // Tests text selection behavior on a right click. |
| 1466 TEST_F(TextfieldTest, SelectWordOnRightClick) { | 1466 TEST_F(TextfieldTest, SelectionOnRightClick) { |
| 1467 InitTextfield(); | 1467 InitTextfield(); |
| 1468 textfield_->SetText(ASCIIToUTF16("hello world")); | 1468 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1469 | 1469 |
| 1470 // Verify right clicking within the selection does not alter the selection. | 1470 // Verify right clicking within the selection does not alter the selection. |
| 1471 textfield_->SelectRange(gfx::Range(1, 5)); | 1471 textfield_->SelectRange(gfx::Range(1, 5)); |
| 1472 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); | 1472 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); |
| 1473 const int cursor_y = GetCursorYForTesting(); | 1473 const int cursor_y = GetCursorYForTesting(); |
| 1474 MoveMouseTo(gfx::Point(GetCursorPositionX(3), cursor_y)); | 1474 MoveMouseTo(gfx::Point(GetCursorPositionX(3), cursor_y)); |
| 1475 ClickRightMouseButton(); | 1475 ClickRightMouseButton(); |
| 1476 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); | 1476 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); |
| 1477 | 1477 |
| 1478 // Verify right clicking outside the selection, selects the word under the | 1478 // Verify right clicking outside the selection, selects the word under the |
| 1479 // cursor on platforms where this is expected. | 1479 // cursor on platforms where this is expected. |
| 1480 MoveMouseTo(gfx::Point(GetCursorPositionX(8), cursor_y)); | 1480 MoveMouseTo(gfx::Point(GetCursorPositionX(8), cursor_y)); |
| 1481 const char* expected_right_click = | 1481 const char* expected_right_click_word = |
| 1482 PlatformStyle::kSelectWordOnRightClick ? "world" : "ello"; | 1482 PlatformStyle::kSelectWordOnRightClick ? "world" : "ello"; |
| 1483 ClickRightMouseButton(); | 1483 ClickRightMouseButton(); |
| 1484 EXPECT_STR_EQ(expected_right_click, textfield_->GetSelectedText()); | 1484 EXPECT_STR_EQ(expected_right_click_word, textfield_->GetSelectedText()); |
| 1485 |
| 1486 // Verify right clicking inside an unfocused textfield selects all the text on |
| 1487 // platforms where this is expected. Else the older selection is retained. |
| 1488 widget_->GetFocusManager()->ClearFocus(); |
| 1489 EXPECT_FALSE(textfield_->HasFocus()); |
| 1490 MoveMouseTo(gfx::Point(GetCursorPositionX(0), cursor_y)); |
| 1491 ClickRightMouseButton(); |
| 1492 EXPECT_TRUE(textfield_->HasFocus()); |
| 1493 const char* expected_right_click_unfocused = |
| 1494 PlatformStyle::kSelectAllOnRightClickWhenUnfocused |
| 1495 ? "hello world" |
| 1496 : expected_right_click_word; |
| 1497 EXPECT_STR_EQ(expected_right_click_unfocused, textfield_->GetSelectedText()); |
| 1485 } | 1498 } |
| 1486 | 1499 |
| 1487 TEST_F(TextfieldTest, DragToSelect) { | 1500 TEST_F(TextfieldTest, DragToSelect) { |
| 1488 InitTextfield(); | 1501 InitTextfield(); |
| 1489 textfield_->SetText(ASCIIToUTF16("hello world")); | 1502 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1490 const int kStart = GetCursorPositionX(5); | 1503 const int kStart = GetCursorPositionX(5); |
| 1491 const int kEnd = 500; | 1504 const int kEnd = 500; |
| 1492 const int cursor_y = GetCursorYForTesting(); | 1505 const int cursor_y = GetCursorYForTesting(); |
| 1493 gfx::Point start_point(kStart, cursor_y); | 1506 gfx::Point start_point(kStart, cursor_y); |
| 1494 gfx::Point end_point(kEnd, cursor_y); | 1507 gfx::Point end_point(kEnd, cursor_y); |
| (...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3039 ui::AXNodeData node_data_protected; | 3052 ui::AXNodeData node_data_protected; |
| 3040 node_data_protected.state = 0; | 3053 node_data_protected.state = 0; |
| 3041 textfield_->GetAccessibleNodeData(&node_data_protected); | 3054 textfield_->GetAccessibleNodeData(&node_data_protected); |
| 3042 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); | 3055 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); |
| 3043 EXPECT_EQ(ASCIIToUTF16("********"), | 3056 EXPECT_EQ(ASCIIToUTF16("********"), |
| 3044 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); | 3057 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); |
| 3045 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 3058 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 3046 } | 3059 } |
| 3047 | 3060 |
| 3048 } // namespace views | 3061 } // namespace views |
| OLD | NEW |