| 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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 #else | 1569 #else |
| 1555 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1570 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1556 #endif | 1571 #endif |
| 1557 #endif // !defined(OS_WIN) | 1572 #endif // !defined(OS_WIN) |
| 1558 | 1573 |
| 1559 // Reset locale. | 1574 // Reset locale. |
| 1560 base::i18n::SetICUDefaultLocale(locale); | 1575 base::i18n::SetICUDefaultLocale(locale); |
| 1561 } | 1576 } |
| 1562 | 1577 |
| 1563 } // namespace views | 1578 } // namespace views |
| OLD | NEW |