OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/pickle.h" | 13 #include "base/pickle.h" |
14 #include "base/string16.h" | 14 #include "base/string16.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "grit/ui_strings.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/base/clipboard/clipboard.h" | 19 #include "ui/base/clipboard/clipboard.h" |
19 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 20 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
20 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
21 #include "ui/base/ime/text_input_client.h" | 22 #include "ui/base/ime/text_input_client.h" |
22 #include "ui/base/keycodes/keyboard_codes.h" | 23 #include "ui/base/keycodes/keyboard_codes.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/gfx/render_text.h" | 25 #include "ui/gfx/render_text.h" |
25 #include "ui/views/controls/textfield/native_textfield_views.h" | 26 #include "ui/views/controls/textfield/native_textfield_views.h" |
26 #include "ui/views/controls/textfield/textfield.h" | 27 #include "ui/views/controls/textfield/textfield.h" |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 InitTextfield(Textfield::STYLE_OBSCURED); | 490 InitTextfield(Textfield::STYLE_OBSCURED); |
490 | 491 |
491 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 492 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
492 | 493 |
493 last_contents_.clear(); | 494 last_contents_.clear(); |
494 textfield_->SetText(ASCIIToUTF16("my password")); | 495 textfield_->SetText(ASCIIToUTF16("my password")); |
495 // Just to make sure the text() and callback returns | 496 // Just to make sure the text() and callback returns |
496 // the actual text instead of "*". | 497 // the actual text instead of "*". |
497 EXPECT_STR_EQ("my password", textfield_->text()); | 498 EXPECT_STR_EQ("my password", textfield_->text()); |
498 EXPECT_TRUE(last_contents_.empty()); | 499 EXPECT_TRUE(last_contents_.empty()); |
| 500 |
| 501 // Cut and copy should be disabled in the context menu. |
| 502 model_->SelectAll(); |
| 503 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_CUT)); |
| 504 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_COPY)); |
| 505 |
| 506 // Cut and copy keyboard shortcuts and menu commands should do nothing. |
| 507 SetClipboardText("foo"); |
| 508 SendKeyEvent(ui::VKEY_C, false, true); |
| 509 SendKeyEvent(ui::VKEY_X, false, true); |
| 510 ExecuteCommand(IDS_APP_COPY); |
| 511 ExecuteCommand(IDS_APP_CUT); |
| 512 EXPECT_STR_EQ("foo", string16(GetClipboardText())); |
| 513 EXPECT_STR_EQ("my password", textfield_->text()); |
499 } | 514 } |
500 | 515 |
501 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { | 516 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { |
502 InitTextfield(Textfield::STYLE_DEFAULT); | 517 InitTextfield(Textfield::STYLE_DEFAULT); |
503 | 518 |
504 // Defaults to TEXT | 519 // Defaults to TEXT |
505 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 520 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
506 | 521 |
507 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. | 522 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. |
508 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 523 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 // Ensure that disabled textfields do not support drag operations. | 820 // Ensure that disabled textfields do not support drag operations. |
806 textfield_->SetEnabled(false); | 821 textfield_->SetEnabled(false); |
807 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 822 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
808 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 823 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
809 textfield_->SetEnabled(true); | 824 textfield_->SetEnabled(true); |
810 // Ensure that textfields without selections do not support drag operations. | 825 // Ensure that textfields without selections do not support drag operations. |
811 textfield_->ClearSelection(); | 826 textfield_->ClearSelection(); |
812 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 827 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
813 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 828 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
814 textfield_->SelectRange(kStringRange); | 829 textfield_->SelectRange(kStringRange); |
| 830 // Ensure that password textfields do not support drag operations. |
| 831 textfield_->SetObscured(true); |
| 832 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 833 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
| 834 textfield_->SetObscured(false); |
815 // Ensure that textfields only initiate drag operations inside the selection. | 835 // Ensure that textfields only initiate drag operations inside the selection. |
816 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 836 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
817 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); | 837 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); |
818 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), | 838 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), |
819 gfx::Point())); | 839 gfx::Point())); |
820 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, | 840 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, |
821 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 841 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); |
822 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, | 842 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, |
823 gfx::Point())); | 843 gfx::Point())); |
824 // Ensure that textfields support local moves. | 844 // Ensure that textfields support local moves. |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 #else | 1575 #else |
1556 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1576 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1557 #endif | 1577 #endif |
1558 #endif // !defined(OS_WIN) | 1578 #endif // !defined(OS_WIN) |
1559 | 1579 |
1560 // Reset locale. | 1580 // Reset locale. |
1561 base::i18n::SetICUDefaultLocale(locale); | 1581 base::i18n::SetICUDefaultLocale(locale); |
1562 } | 1582 } |
1563 | 1583 |
1564 } // namespace views | 1584 } // namespace views |
OLD | NEW |