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

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

Issue 8747001: Reintroduce password support to NativeTextfieldViews (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments, Utf16OffsetToPointer bug Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 InitTextfield(Textfield::STYLE_OBSCURED); 489 InitTextfield(Textfield::STYLE_OBSCURED);
489 490
490 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); 491 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType());
491 492
492 last_contents_.clear(); 493 last_contents_.clear();
493 textfield_->SetText(ASCIIToUTF16("my password")); 494 textfield_->SetText(ASCIIToUTF16("my password"));
494 // Just to make sure the text() and callback returns 495 // Just to make sure the text() and callback returns
495 // the actual text instead of "*". 496 // the actual text instead of "*".
496 EXPECT_STR_EQ("my password", textfield_->text()); 497 EXPECT_STR_EQ("my password", textfield_->text());
497 EXPECT_TRUE(last_contents_.empty()); 498 EXPECT_TRUE(last_contents_.empty());
499
500 // Cut and copy should be disabled in the context menu.
501 model_->SelectAll();
502 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_CUT));
503 EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_COPY));
504
505 // Cut and copy keyboard shortcuts and menu commands should do nothing.
506 SetClipboardText("foo");
507 SendKeyEvent(ui::VKEY_C, false, true);
508 SendKeyEvent(ui::VKEY_X, false, true);
509 ExecuteCommand(IDS_APP_COPY);
510 ExecuteCommand(IDS_APP_CUT);
511 EXPECT_STR_EQ("foo", string16(GetClipboardText()));
512 EXPECT_STR_EQ("my password", textfield_->text());
498 } 513 }
499 514
500 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { 515 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) {
501 InitTextfield(Textfield::STYLE_DEFAULT); 516 InitTextfield(Textfield::STYLE_DEFAULT);
502 517
503 // Defaults to TEXT 518 // Defaults to TEXT
504 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); 519 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
505 520
506 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. 521 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield.
507 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 522 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 // Ensure that disabled textfields do not support drag operations. 819 // Ensure that disabled textfields do not support drag operations.
805 textfield_->SetEnabled(false); 820 textfield_->SetEnabled(false);
806 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 821 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
807 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); 822 textfield_view_->GetDragOperationsForView(NULL, kStringPoint));
808 textfield_->SetEnabled(true); 823 textfield_->SetEnabled(true);
809 // Ensure that textfields without selections do not support drag operations. 824 // Ensure that textfields without selections do not support drag operations.
810 textfield_->ClearSelection(); 825 textfield_->ClearSelection();
811 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 826 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
812 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); 827 textfield_view_->GetDragOperationsForView(NULL, kStringPoint));
813 textfield_->SelectRange(kStringRange); 828 textfield_->SelectRange(kStringRange);
829 // Ensure that password textfields do not support drag operations.
830 textfield_->SetObscured(true);
831 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
832 textfield_view_->GetDragOperationsForView(NULL, kStringPoint));
833 textfield_->SetObscured(false);
814 // Ensure that textfields only initiate drag operations inside the selection. 834 // Ensure that textfields only initiate drag operations inside the selection.
815 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 835 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
816 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); 836 textfield_view_->GetDragOperationsForView(NULL, gfx::Point()));
817 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), 837 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(),
818 gfx::Point())); 838 gfx::Point()));
819 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, 839 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY,
820 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); 840 textfield_view_->GetDragOperationsForView(NULL, kStringPoint));
821 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, 841 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint,
822 gfx::Point())); 842 gfx::Point()));
823 // Ensure that textfields support local moves. 843 // Ensure that textfields support local moves.
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 #else 1574 #else
1555 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1575 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1556 #endif 1576 #endif
1557 #endif // !defined(OS_WIN) 1577 #endif // !defined(OS_WIN)
1558 1578
1559 // Reset locale. 1579 // Reset locale.
1560 base::i18n::SetICUDefaultLocale(locale); 1580 base::i18n::SetICUDefaultLocale(locale);
1561 } 1581 }
1562 1582
1563 } // namespace views 1583 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698