| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/base/clipboard/clipboard.h" | 9 #include "ui/base/clipboard/clipboard.h" |
| 10 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 10 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 11 #include "ui/base/keycodes/keyboard_codes.h" | 11 #include "ui/base/keycodes/keyboard_codes.h" |
| 12 #include "views/controls/menu/menu_2.h" | 12 #include "views/controls/menu/menu_2.h" |
| 13 #include "views/controls/textfield/native_textfield_views.h" | 13 #include "views/controls/textfield/native_textfield_views.h" |
| 14 #include "views/controls/textfield/textfield.h" | 14 #include "views/controls/textfield/textfield.h" |
| 15 #include "views/controls/textfield/textfield_controller.h" |
| 15 #include "views/controls/textfield/textfield_views_model.h" | 16 #include "views/controls/textfield/textfield_views_model.h" |
| 16 #include "views/events/event.h" | 17 #include "views/events/event.h" |
| 17 #include "views/focus/focus_manager.h" | 18 #include "views/focus/focus_manager.h" |
| 18 #include "views/test/test_views_delegate.h" | 19 #include "views/test/test_views_delegate.h" |
| 19 #include "views/test/views_test_base.h" | 20 #include "views/test/views_test_base.h" |
| 21 #include "views/views_delegate.h" |
| 20 #include "views/widget/widget.h" | 22 #include "views/widget/widget.h" |
| 21 #include "views/views_delegate.h" | |
| 22 | 23 |
| 23 namespace views { | 24 namespace views { |
| 24 | 25 |
| 25 // Convert to Wide so that the printed string will be readable when | 26 // Convert to Wide so that the printed string will be readable when |
| 26 // check fails. | 27 // check fails. |
| 27 #define EXPECT_STR_EQ(ascii, utf16) \ | 28 #define EXPECT_STR_EQ(ascii, utf16) \ |
| 28 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 29 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
| 29 #define EXPECT_STR_NE(ascii, utf16) \ | 30 #define EXPECT_STR_NE(ascii, utf16) \ |
| 30 EXPECT_NE(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 31 EXPECT_NE(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
| 31 | 32 |
| 32 // TODO(oshima): Move tests that are independent of TextfieldViews to | 33 // TODO(oshima): Move tests that are independent of TextfieldViews to |
| 33 // textfield_unittests.cc once we move the test utility functions | 34 // textfield_unittests.cc once we move the test utility functions |
| 34 // from chrome/browser/automation/ to app/test/. | 35 // from chrome/browser/automation/ to app/test/. |
| 35 class NativeTextfieldViewsTest : public ViewsTestBase, | 36 class NativeTextfieldViewsTest : public ViewsTestBase, |
| 36 public Textfield::Controller { | 37 public TextfieldController { |
| 37 public: | 38 public: |
| 38 NativeTextfieldViewsTest() | 39 NativeTextfieldViewsTest() |
| 39 : widget_(NULL), | 40 : widget_(NULL), |
| 40 textfield_(NULL), | 41 textfield_(NULL), |
| 41 textfield_view_(NULL), | 42 textfield_view_(NULL), |
| 42 model_(NULL) { | 43 model_(NULL) { |
| 43 } | 44 } |
| 44 | 45 |
| 45 // ::testing::Test overrides. | 46 // ::testing::Test: |
| 46 virtual void SetUp() { | 47 virtual void SetUp() { |
| 47 NativeTextfieldViews::SetEnableTextfieldViews(true); | 48 NativeTextfieldViews::SetEnableTextfieldViews(true); |
| 48 } | 49 } |
| 49 | 50 |
| 50 virtual void TearDown() { | 51 virtual void TearDown() { |
| 51 NativeTextfieldViews::SetEnableTextfieldViews(false); | 52 NativeTextfieldViews::SetEnableTextfieldViews(false); |
| 52 if (widget_) | 53 if (widget_) |
| 53 widget_->Close(); | 54 widget_->Close(); |
| 54 ViewsTestBase::TearDown(); | 55 ViewsTestBase::TearDown(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 // Textfield::Controller implementation: | 58 // TextfieldController: |
| 58 virtual void ContentsChanged(Textfield* sender, | 59 virtual void ContentsChanged(Textfield* sender, |
| 59 const string16& new_contents){ | 60 const string16& new_contents){ |
| 60 last_contents_ = new_contents; | 61 last_contents_ = new_contents; |
| 61 } | 62 } |
| 62 | 63 |
| 63 virtual bool HandleKeyEvent(Textfield* sender, | 64 virtual bool HandleKeyEvent(Textfield* sender, |
| 64 const KeyEvent& key_event) { | 65 const KeyEvent& key_event) { |
| 65 | 66 |
| 66 // TODO(oshima): figure out how to test the keystroke. | 67 // TODO(oshima): figure out how to test the keystroke. |
| 67 return false; | 68 return false; |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 // Text field is unmodifiable and selection shouldn't change. | 513 // Text field is unmodifiable and selection shouldn't change. |
| 513 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); | 514 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); |
| 514 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 515 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 515 SendKeyEventToTextfieldViews(ui::VKEY_BACK); | 516 SendKeyEventToTextfieldViews(ui::VKEY_BACK); |
| 516 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 517 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 517 SendKeyEventToTextfieldViews(ui::VKEY_T); | 518 SendKeyEventToTextfieldViews(ui::VKEY_T); |
| 518 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 519 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 519 } | 520 } |
| 520 | 521 |
| 521 } // namespace views | 522 } // namespace views |
| OLD | NEW |