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/bind.h" | |
7 #include "base/bind_helpers.h" | |
8 #include "base/callback.h" | |
6 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
7 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
10 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
11 #include "ui/base/keycodes/keyboard_codes.h" | 14 #include "ui/base/keycodes/keyboard_codes.h" |
12 #include "views/controls/menu/menu_2.h" | 15 #include "views/controls/menu/menu_2.h" |
13 #include "views/controls/textfield/native_textfield_views.h" | 16 #include "views/controls/textfield/native_textfield_views.h" |
14 #include "views/controls/textfield/textfield.h" | 17 #include "views/controls/textfield/textfield.h" |
15 #include "views/controls/textfield/textfield_controller.h" | 18 #include "views/controls/textfield/textfield_controller.h" |
16 #include "views/controls/textfield/textfield_views_model.h" | 19 #include "views/controls/textfield/textfield_views_model.h" |
17 #include "views/events/event.h" | 20 #include "views/events/event.h" |
18 #include "views/focus/focus_manager.h" | 21 #include "views/focus/focus_manager.h" |
22 #include "views/ime/mock_input_method.h" | |
23 #include "views/ime/text_input_client.h" | |
19 #include "views/test/test_views_delegate.h" | 24 #include "views/test/test_views_delegate.h" |
20 #include "views/test/views_test_base.h" | 25 #include "views/test/views_test_base.h" |
21 #include "views/views_delegate.h" | 26 #include "views/views_delegate.h" |
27 #include "views/widget/native_widget.h" | |
22 #include "views/widget/widget.h" | 28 #include "views/widget/widget.h" |
23 | 29 |
30 namespace { | |
31 | |
32 // A wrapper of Textfield to intercept the result of OnKeyPressed() and | |
33 // OnKeyReleased() methods. | |
34 class TestTextfield : public views::Textfield { | |
35 public: | |
36 TestTextfield() | |
37 : key_handled_(false), | |
38 key_received_(false) { | |
39 } | |
40 | |
41 explicit TestTextfield(StyleFlags style) | |
42 : Textfield(style), | |
43 key_handled_(false), | |
44 key_received_(false) { | |
45 } | |
46 | |
47 virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE { | |
48 key_received_ = true; | |
49 key_handled_ = views::Textfield::OnKeyPressed(e); | |
50 return key_handled_; | |
51 } | |
52 | |
53 virtual bool OnKeyReleased(const views::KeyEvent& e) OVERRIDE { | |
54 key_received_ = true; | |
55 key_handled_ = views::Textfield::OnKeyReleased(e); | |
56 return key_handled_; | |
57 } | |
58 | |
59 bool key_handled() const { return key_handled_; } | |
60 bool key_received() const { return key_received_; } | |
61 | |
62 void clear() { | |
63 key_received_ = key_handled_ = false; | |
64 } | |
65 | |
66 private: | |
67 bool key_handled_; | |
68 bool key_received_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(TestTextfield); | |
71 }; | |
72 | |
73 // A helper class for use with TextInputClient::GetTextFromRange(). | |
74 class GetTextHelper { | |
75 public: | |
76 GetTextHelper() { | |
77 } | |
78 | |
79 void set_text(const string16& text) { text_ = text; } | |
80 const string16& text() const { return text_; } | |
81 | |
82 private: | |
83 string16 text_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(GetTextHelper); | |
86 }; | |
87 | |
88 } // namespace | |
89 | |
24 namespace views { | 90 namespace views { |
25 | 91 |
26 // Convert to Wide so that the printed string will be readable when | 92 // Convert to Wide so that the printed string will be readable when |
27 // check fails. | 93 // check fails. |
28 #define EXPECT_STR_EQ(ascii, utf16) \ | 94 #define EXPECT_STR_EQ(ascii, utf16) \ |
29 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 95 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
30 #define EXPECT_STR_NE(ascii, utf16) \ | 96 #define EXPECT_STR_NE(ascii, utf16) \ |
31 EXPECT_NE(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 97 EXPECT_NE(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
32 | 98 |
33 // TODO(oshima): Move tests that are independent of TextfieldViews to | 99 // TODO(oshima): Move tests that are independent of TextfieldViews to |
34 // textfield_unittests.cc once we move the test utility functions | 100 // textfield_unittests.cc once we move the test utility functions |
35 // from chrome/browser/automation/ to app/test/. | 101 // from chrome/browser/automation/ to app/test/. |
36 class NativeTextfieldViewsTest : public ViewsTestBase, | 102 class NativeTextfieldViewsTest : public ViewsTestBase, |
37 public TextfieldController { | 103 public TextfieldController { |
38 public: | 104 public: |
39 NativeTextfieldViewsTest() | 105 NativeTextfieldViewsTest() |
40 : widget_(NULL), | 106 : widget_(NULL), |
41 textfield_(NULL), | 107 textfield_(NULL), |
42 textfield_view_(NULL), | 108 textfield_view_(NULL), |
43 model_(NULL) { | 109 model_(NULL), |
110 input_method_(NULL), | |
111 on_before_user_action_(0), | |
112 on_after_user_action_(0) { | |
44 } | 113 } |
45 | 114 |
46 // ::testing::Test: | 115 // ::testing::Test: |
47 virtual void SetUp() { | 116 virtual void SetUp() { |
48 NativeTextfieldViews::SetEnableTextfieldViews(true); | 117 NativeTextfieldViews::SetEnableTextfieldViews(true); |
49 } | 118 } |
50 | 119 |
51 virtual void TearDown() { | 120 virtual void TearDown() { |
52 NativeTextfieldViews::SetEnableTextfieldViews(false); | 121 NativeTextfieldViews::SetEnableTextfieldViews(false); |
53 if (widget_) | 122 if (widget_) |
54 widget_->Close(); | 123 widget_->Close(); |
55 ViewsTestBase::TearDown(); | 124 ViewsTestBase::TearDown(); |
56 } | 125 } |
57 | 126 |
58 // TextfieldController: | 127 // TextfieldController: |
59 virtual void ContentsChanged(Textfield* sender, | 128 virtual void ContentsChanged(Textfield* sender, |
60 const string16& new_contents){ | 129 const string16& new_contents) { |
130 ASSERT_NE(last_contents_, new_contents); | |
61 last_contents_ = new_contents; | 131 last_contents_ = new_contents; |
62 } | 132 } |
63 | 133 |
64 virtual bool HandleKeyEvent(Textfield* sender, | 134 virtual bool HandleKeyEvent(Textfield* sender, |
65 const KeyEvent& key_event) { | 135 const KeyEvent& key_event) { |
66 | 136 |
67 // TODO(oshima): figure out how to test the keystroke. | 137 // TODO(oshima): figure out how to test the keystroke. |
68 return false; | 138 return false; |
69 } | 139 } |
70 | 140 |
141 virtual void OnBeforeUserAction(Textfield* sender) { | |
142 ++on_before_user_action_; | |
oshima
2011/03/25 17:31:25
FYI: it's okay to use postfix notation these days.
James Su
2011/03/25 20:53:59
I'm just used to it :)
| |
143 } | |
144 | |
145 virtual void OnAfterUserAction(Textfield* sender) { | |
146 ++on_after_user_action_; | |
147 } | |
148 | |
71 void InitTextfield(Textfield::StyleFlags style) { | 149 void InitTextfield(Textfield::StyleFlags style) { |
72 InitTextfields(style, 1); | 150 InitTextfields(style, 1); |
73 } | 151 } |
74 | 152 |
75 void InitTextfields(Textfield::StyleFlags style, int count) { | 153 void InitTextfields(Textfield::StyleFlags style, int count) { |
76 ASSERT_FALSE(textfield_); | 154 ASSERT_FALSE(textfield_); |
77 textfield_ = new Textfield(style); | 155 textfield_ = new TestTextfield(style); |
78 textfield_->SetController(this); | 156 textfield_->SetController(this); |
79 Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); | 157 Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); |
80 params.mirror_origin_in_rtl = false; | 158 params.mirror_origin_in_rtl = false; |
81 widget_ = Widget::CreatePopupWidget(params); | 159 widget_ = Widget::CreatePopupWidget(params); |
82 widget_->Init(NULL, gfx::Rect(100, 100, 100, 100)); | 160 widget_->Init(NULL, gfx::Rect(100, 100, 100, 100)); |
83 View* container = new View(); | 161 View* container = new View(); |
84 widget_->SetContentsView(container); | 162 widget_->SetContentsView(container); |
85 container->AddChildView(textfield_); | 163 container->AddChildView(textfield_); |
86 | 164 |
87 textfield_view_ | 165 textfield_view_ |
88 = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper()); | 166 = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper()); |
89 textfield_->SetID(1); | 167 textfield_->SetID(1); |
90 | 168 |
91 for (int i = 1; i < count; i++) { | 169 for (int i = 1; i < count; i++) { |
92 Textfield* textfield = new Textfield(style); | 170 Textfield* textfield = new Textfield(style); |
93 container->AddChildView(textfield); | 171 container->AddChildView(textfield); |
94 textfield->SetID(i + 1); | 172 textfield->SetID(i + 1); |
95 } | 173 } |
96 | 174 |
97 DCHECK(textfield_view_); | 175 DCHECK(textfield_view_); |
98 model_ = textfield_view_->model_.get(); | 176 model_ = textfield_view_->model_.get(); |
177 | |
178 input_method_ = new MockInputMethod(); | |
179 widget_->native_widget()->ReplaceInputMethod(input_method_); | |
180 | |
181 textfield_->RequestFocus(); | |
99 } | 182 } |
100 | 183 |
101 views::Menu2* GetContextMenu() { | 184 views::Menu2* GetContextMenu() { |
102 textfield_view_->InitContextMenuIfRequired(); | 185 textfield_view_->InitContextMenuIfRequired(); |
103 return textfield_view_->context_menu_menu_.get(); | 186 return textfield_view_->context_menu_menu_.get(); |
104 } | 187 } |
105 | 188 |
106 NativeTextfieldViews::ClickState GetClickState() { | 189 NativeTextfieldViews::ClickState GetClickState() { |
107 return textfield_view_->click_state_; | 190 return textfield_view_->click_state_; |
108 } | 191 } |
109 | 192 |
110 protected: | 193 protected: |
111 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, | 194 void SendKeyEvent(ui::KeyboardCode key_code, |
112 bool shift, | 195 bool shift, |
113 bool control, | 196 bool control, |
114 bool capslock) { | 197 bool capslock) { |
115 int flags = (shift ? ui::EF_SHIFT_DOWN : 0) | | 198 int flags = (shift ? ui::EF_SHIFT_DOWN : 0) | |
116 (control ? ui::EF_CONTROL_DOWN : 0) | | 199 (control ? ui::EF_CONTROL_DOWN : 0) | |
117 (capslock ? ui::EF_CAPS_LOCK_DOWN : 0); | 200 (capslock ? ui::EF_CAPS_LOCK_DOWN : 0); |
118 KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); | 201 KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); |
119 return textfield_->OnKeyPressed(event); | 202 input_method_->DispatchKeyEvent(event); |
120 } | 203 } |
121 | 204 |
122 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code, | 205 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { |
123 bool shift, | 206 SendKeyEvent(key_code, shift, control, false); |
124 bool control) { | |
125 return SendKeyEventToTextfieldViews(key_code, shift, control, false); | |
126 } | 207 } |
127 | 208 |
128 bool SendKeyEventToTextfieldViews(ui::KeyboardCode key_code) { | 209 void SendKeyEvent(ui::KeyboardCode key_code) { |
129 return SendKeyEventToTextfieldViews(key_code, false, false); | 210 SendKeyEvent(key_code, false, false); |
130 } | 211 } |
131 | 212 |
132 View* GetFocusedView() { | 213 View* GetFocusedView() { |
133 return widget_->GetFocusManager()->GetFocusedView(); | 214 return widget_->GetFocusManager()->GetFocusedView(); |
134 } | 215 } |
135 | 216 |
136 // We need widget to populate wrapper class. | 217 // We need widget to populate wrapper class. |
137 Widget* widget_; | 218 Widget* widget_; |
138 | 219 |
139 Textfield* textfield_; | 220 TestTextfield* textfield_; |
140 NativeTextfieldViews* textfield_view_; | 221 NativeTextfieldViews* textfield_view_; |
141 TextfieldViewsModel* model_; | 222 TextfieldViewsModel* model_; |
142 | 223 |
143 // The string from Controller::ContentsChanged callback. | 224 // The string from Controller::ContentsChanged callback. |
144 string16 last_contents_; | 225 string16 last_contents_; |
145 | 226 |
227 // For testing input method related behaviors. | |
228 MockInputMethod* input_method_; | |
229 | |
230 // Indicates how many times OnBeforeUserAction() is called. | |
231 int on_before_user_action_; | |
232 | |
233 // Indicates how many times OnAfterUserAction() is called. | |
234 int on_after_user_action_; | |
235 | |
146 private: | 236 private: |
147 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViewsTest); | 237 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViewsTest); |
148 }; | 238 }; |
149 | 239 |
150 TEST_F(NativeTextfieldViewsTest, ModelChangesTeset) { | 240 TEST_F(NativeTextfieldViewsTest, ModelChangesTest) { |
151 InitTextfield(Textfield::STYLE_DEFAULT); | 241 InitTextfield(Textfield::STYLE_DEFAULT); |
242 | |
243 // TextfieldController::ContentsChanged() shouldn't be called when changing | |
244 // text programmatically. | |
245 last_contents_.clear(); | |
152 textfield_->SetText(ASCIIToUTF16("this is")); | 246 textfield_->SetText(ASCIIToUTF16("this is")); |
153 | 247 |
154 EXPECT_STR_EQ("this is", model_->text()); | 248 EXPECT_STR_EQ("this is", model_->text()); |
155 EXPECT_STR_EQ("this is", last_contents_); | 249 EXPECT_STR_EQ("this is", textfield_->text()); |
156 last_contents_.clear(); | 250 EXPECT_EQ(string16(), last_contents_); |
157 | 251 |
158 textfield_->AppendText(ASCIIToUTF16(" a test")); | 252 textfield_->AppendText(ASCIIToUTF16(" a test")); |
159 EXPECT_STR_EQ("this is a test", model_->text()); | 253 EXPECT_STR_EQ("this is a test", model_->text()); |
160 EXPECT_STR_EQ("this is a test", last_contents_); | 254 EXPECT_STR_EQ("this is a test", textfield_->text()); |
161 last_contents_.clear(); | |
162 | |
163 // Cases where the callback should not be called. | |
164 textfield_->SetText(ASCIIToUTF16("this is a test")); | |
165 EXPECT_STR_EQ("this is a test", model_->text()); | |
166 EXPECT_EQ(string16(), last_contents_); | |
167 | |
168 textfield_->AppendText(string16()); | |
169 EXPECT_STR_EQ("this is a test", model_->text()); | |
170 EXPECT_EQ(string16(), last_contents_); | 255 EXPECT_EQ(string16(), last_contents_); |
171 | 256 |
172 EXPECT_EQ(string16(), textfield_->GetSelectedText()); | 257 EXPECT_EQ(string16(), textfield_->GetSelectedText()); |
173 textfield_->SelectAll(); | 258 textfield_->SelectAll(); |
174 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 259 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
175 EXPECT_EQ(string16(), last_contents_); | 260 EXPECT_EQ(string16(), last_contents_); |
176 } | 261 } |
177 | 262 |
178 TEST_F(NativeTextfieldViewsTest, KeyTest) { | 263 TEST_F(NativeTextfieldViewsTest, KeyTest) { |
179 InitTextfield(Textfield::STYLE_DEFAULT); | 264 InitTextfield(Textfield::STYLE_DEFAULT); |
180 SendKeyEventToTextfieldViews(ui::VKEY_C, true, false); | 265 SendKeyEvent(ui::VKEY_C, true, false); |
181 EXPECT_STR_EQ("C", textfield_->text()); | 266 EXPECT_STR_EQ("C", textfield_->text()); |
182 EXPECT_STR_EQ("C", last_contents_); | 267 EXPECT_STR_EQ("C", last_contents_); |
183 last_contents_.clear(); | 268 last_contents_.clear(); |
184 | 269 |
185 SendKeyEventToTextfieldViews(ui::VKEY_R, false, false); | 270 SendKeyEvent(ui::VKEY_R, false, false); |
186 EXPECT_STR_EQ("Cr", textfield_->text()); | 271 EXPECT_STR_EQ("Cr", textfield_->text()); |
187 EXPECT_STR_EQ("Cr", last_contents_); | 272 EXPECT_STR_EQ("Cr", last_contents_); |
188 | 273 |
189 textfield_->SetText(ASCIIToUTF16("")); | 274 textfield_->SetText(ASCIIToUTF16("")); |
190 SendKeyEventToTextfieldViews(ui::VKEY_C, true, false, true); | 275 SendKeyEvent(ui::VKEY_C, true, false, true); |
191 SendKeyEventToTextfieldViews(ui::VKEY_C, false, false, true); | 276 SendKeyEvent(ui::VKEY_C, false, false, true); |
192 SendKeyEventToTextfieldViews(ui::VKEY_1, false, false, true); | 277 SendKeyEvent(ui::VKEY_1, false, false, true); |
193 SendKeyEventToTextfieldViews(ui::VKEY_1, true, false, true); | 278 SendKeyEvent(ui::VKEY_1, true, false, true); |
194 SendKeyEventToTextfieldViews(ui::VKEY_1, true, false, false); | 279 SendKeyEvent(ui::VKEY_1, true, false, false); |
195 EXPECT_STR_EQ("cC1!!", textfield_->text()); | 280 EXPECT_STR_EQ("cC1!!", textfield_->text()); |
196 EXPECT_STR_EQ("cC1!!", last_contents_); | 281 EXPECT_STR_EQ("cC1!!", last_contents_); |
197 } | 282 } |
198 | 283 |
199 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { | 284 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { |
200 // Insert a test string in a textfield. | 285 // Insert a test string in a textfield. |
201 InitTextfield(Textfield::STYLE_DEFAULT); | 286 InitTextfield(Textfield::STYLE_DEFAULT); |
202 textfield_->SetText(ASCIIToUTF16("one two three")); | 287 textfield_->SetText(ASCIIToUTF16("one two three")); |
203 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, | 288 SendKeyEvent(ui::VKEY_RIGHT, |
204 true /* shift */, false /* control */); | 289 true /* shift */, false /* control */); |
205 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, false); | 290 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
206 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, false); | 291 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
207 | 292 |
208 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 293 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
209 | 294 |
210 // Test word select. | 295 // Test word select. |
211 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, true); | 296 SendKeyEvent(ui::VKEY_RIGHT, true, true); |
212 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); | 297 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); |
213 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, true, true); | 298 SendKeyEvent(ui::VKEY_RIGHT, true, true); |
214 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); | 299 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); |
215 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, true, true); | 300 SendKeyEvent(ui::VKEY_LEFT, true, true); |
216 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); | 301 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); |
217 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, true, true); | 302 SendKeyEvent(ui::VKEY_LEFT, true, true); |
218 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); | 303 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); |
219 | 304 |
220 // Replace the selected text. | 305 // Replace the selected text. |
221 SendKeyEventToTextfieldViews(ui::VKEY_Z, true, false); | 306 SendKeyEvent(ui::VKEY_Z, true, false); |
222 SendKeyEventToTextfieldViews(ui::VKEY_E, true, false); | 307 SendKeyEvent(ui::VKEY_E, true, false); |
223 SendKeyEventToTextfieldViews(ui::VKEY_R, true, false); | 308 SendKeyEvent(ui::VKEY_R, true, false); |
224 SendKeyEventToTextfieldViews(ui::VKEY_O, true, false); | 309 SendKeyEvent(ui::VKEY_O, true, false); |
225 SendKeyEventToTextfieldViews(ui::VKEY_SPACE, false, false); | 310 SendKeyEvent(ui::VKEY_SPACE, false, false); |
226 EXPECT_STR_EQ("ZERO two three", textfield_->text()); | 311 EXPECT_STR_EQ("ZERO two three", textfield_->text()); |
227 | 312 |
228 SendKeyEventToTextfieldViews(ui::VKEY_END, true, false); | 313 SendKeyEvent(ui::VKEY_END, true, false); |
229 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); | 314 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); |
230 SendKeyEventToTextfieldViews(ui::VKEY_HOME, true, false); | 315 SendKeyEvent(ui::VKEY_HOME, true, false); |
231 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); | 316 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); |
232 } | 317 } |
233 | 318 |
234 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { | 319 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { |
235 // Insert a test string in a textfield. | 320 // Insert a test string in a textfield. |
236 InitTextfield(Textfield::STYLE_DEFAULT); | 321 InitTextfield(Textfield::STYLE_DEFAULT); |
237 char test_str[] = "this is a test"; | 322 char test_str[] = "this is a test"; |
238 for (size_t i = 0; i < sizeof(test_str); i++) { | 323 for (size_t i = 0; i < sizeof(test_str); i++) { |
239 // This is ugly and should be replaced by a utility standard function. | 324 // This is ugly and should be replaced by a utility standard function. |
240 // See comment in NativeTextfieldViews::GetPrintableChar. | 325 // See comment in NativeTextfieldViews::GetPrintableChar. |
241 char c = test_str[i]; | 326 char c = test_str[i]; |
242 ui::KeyboardCode code = | 327 ui::KeyboardCode code = |
243 c == ' ' ? ui::VKEY_SPACE : | 328 c == ' ' ? ui::VKEY_SPACE : |
244 static_cast<ui::KeyboardCode>(ui::VKEY_A + c - 'a'); | 329 static_cast<ui::KeyboardCode>(ui::VKEY_A + c - 'a'); |
245 SendKeyEventToTextfieldViews(code); | 330 SendKeyEvent(code); |
246 } | 331 } |
247 EXPECT_STR_EQ(test_str, textfield_->text()); | 332 EXPECT_STR_EQ(test_str, textfield_->text()); |
248 | 333 |
249 // Move the cursor around. | 334 // Move the cursor around. |
250 for (int i = 0; i < 6; i++) { | 335 for (int i = 0; i < 6; i++) { |
251 SendKeyEventToTextfieldViews(ui::VKEY_LEFT); | 336 SendKeyEvent(ui::VKEY_LEFT); |
252 } | 337 } |
253 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT); | 338 SendKeyEvent(ui::VKEY_RIGHT); |
254 | 339 |
255 // Delete using backspace and check resulting string. | 340 // Delete using backspace and check resulting string. |
256 SendKeyEventToTextfieldViews(ui::VKEY_BACK); | 341 SendKeyEvent(ui::VKEY_BACK); |
257 EXPECT_STR_EQ("this is test", textfield_->text()); | 342 EXPECT_STR_EQ("this is test", textfield_->text()); |
258 | 343 |
259 // Delete using delete key and check resulting string. | 344 // Delete using delete key and check resulting string. |
260 for (int i = 0; i < 5; i++) { | 345 for (int i = 0; i < 5; i++) { |
261 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); | 346 SendKeyEvent(ui::VKEY_DELETE); |
262 } | 347 } |
263 EXPECT_STR_EQ("this is ", textfield_->text()); | 348 EXPECT_STR_EQ("this is ", textfield_->text()); |
264 | 349 |
265 // Select all and replace with "k". | 350 // Select all and replace with "k". |
266 textfield_->SelectAll(); | 351 textfield_->SelectAll(); |
267 SendKeyEventToTextfieldViews(ui::VKEY_K); | 352 SendKeyEvent(ui::VKEY_K); |
268 EXPECT_STR_EQ("k", textfield_->text()); | 353 EXPECT_STR_EQ("k", textfield_->text()); |
269 | 354 |
270 // Delete the previous word from cursor. | 355 // Delete the previous word from cursor. |
271 textfield_->SetText(ASCIIToUTF16("one two three four")); | 356 textfield_->SetText(ASCIIToUTF16("one two three four")); |
272 SendKeyEventToTextfieldViews(ui::VKEY_END); | 357 SendKeyEvent(ui::VKEY_END); |
273 SendKeyEventToTextfieldViews(ui::VKEY_BACK, false, true, false); | 358 SendKeyEvent(ui::VKEY_BACK, false, true, false); |
274 EXPECT_STR_EQ("one two three ", textfield_->text()); | 359 EXPECT_STR_EQ("one two three ", textfield_->text()); |
275 | 360 |
276 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing | 361 // Delete upto the beginning of the buffer from cursor in chromeos, do nothing |
277 // in windows. | 362 // in windows. |
278 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true, false); | 363 SendKeyEvent(ui::VKEY_LEFT, false, true, false); |
279 SendKeyEventToTextfieldViews(ui::VKEY_BACK, true, true, false); | 364 SendKeyEvent(ui::VKEY_BACK, true, true, false); |
280 #if defined(OS_WIN) | 365 #if defined(OS_WIN) |
281 EXPECT_STR_EQ("one two three ", textfield_->text()); | 366 EXPECT_STR_EQ("one two three ", textfield_->text()); |
282 #else | 367 #else |
283 EXPECT_STR_EQ("three ", textfield_->text()); | 368 EXPECT_STR_EQ("three ", textfield_->text()); |
284 #endif | 369 #endif |
285 | 370 |
286 // Delete the next word from cursor. | 371 // Delete the next word from cursor. |
287 textfield_->SetText(ASCIIToUTF16("one two three four")); | 372 textfield_->SetText(ASCIIToUTF16("one two three four")); |
288 SendKeyEventToTextfieldViews(ui::VKEY_HOME); | 373 SendKeyEvent(ui::VKEY_HOME); |
289 SendKeyEventToTextfieldViews(ui::VKEY_DELETE, false, true, false); | 374 SendKeyEvent(ui::VKEY_DELETE, false, true, false); |
290 EXPECT_STR_EQ(" two three four", textfield_->text()); | 375 EXPECT_STR_EQ(" two three four", textfield_->text()); |
291 | 376 |
292 // Delete upto the end of the buffer from cursor in chromeos, do nothing | 377 // Delete upto the end of the buffer from cursor in chromeos, do nothing |
293 // in windows. | 378 // in windows. |
294 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true, false); | 379 SendKeyEvent(ui::VKEY_RIGHT, false, true, false); |
295 SendKeyEventToTextfieldViews(ui::VKEY_DELETE, true, true, false); | 380 SendKeyEvent(ui::VKEY_DELETE, true, true, false); |
296 #if defined(OS_WIN) | 381 #if defined(OS_WIN) |
297 EXPECT_STR_EQ(" two three four", textfield_->text()); | 382 EXPECT_STR_EQ(" two three four", textfield_->text()); |
298 #else | 383 #else |
299 EXPECT_STR_EQ(" two", textfield_->text()); | 384 EXPECT_STR_EQ(" two", textfield_->text()); |
300 #endif | 385 #endif |
301 } | 386 } |
302 | 387 |
303 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 388 TEST_F(NativeTextfieldViewsTest, PasswordTest) { |
304 InitTextfield(Textfield::STYLE_PASSWORD); | 389 InitTextfield(Textfield::STYLE_PASSWORD); |
305 textfield_->SetText(ASCIIToUTF16("my password")); | 390 textfield_->SetText(ASCIIToUTF16("my password")); |
306 // Just to make sure the text() and callback returns | 391 // Just to make sure the text() and callback returns |
307 // the actual text instead of "*". | 392 // the actual text instead of "*". |
308 EXPECT_STR_EQ("my password", textfield_->text()); | 393 EXPECT_STR_EQ("my password", textfield_->text()); |
309 EXPECT_STR_EQ("my password", last_contents_); | |
310 } | 394 } |
311 | 395 |
312 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { | 396 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { |
313 InitTextfield(Textfield::STYLE_DEFAULT); | 397 InitTextfield(Textfield::STYLE_DEFAULT); |
314 EXPECT_TRUE(SendKeyEventToTextfieldViews(ui::VKEY_A)); | 398 |
399 // Character keys will be handled by input method. | |
400 SendKeyEvent(ui::VKEY_A); | |
401 EXPECT_TRUE(textfield_->key_received()); | |
402 EXPECT_FALSE(textfield_->key_handled()); | |
403 textfield_->clear(); | |
404 | |
405 // Home will be handled. | |
406 SendKeyEvent(ui::VKEY_HOME); | |
407 EXPECT_TRUE(textfield_->key_received()); | |
408 EXPECT_TRUE(textfield_->key_handled()); | |
409 textfield_->clear(); | |
410 | |
315 // F24, up/down key won't be handled. | 411 // F24, up/down key won't be handled. |
316 EXPECT_FALSE(SendKeyEventToTextfieldViews(ui::VKEY_F24)); | 412 SendKeyEvent(ui::VKEY_F24); |
317 EXPECT_FALSE(SendKeyEventToTextfieldViews(ui::VKEY_UP)); | 413 EXPECT_TRUE(textfield_->key_received()); |
318 EXPECT_FALSE(SendKeyEventToTextfieldViews(ui::VKEY_DOWN)); | 414 EXPECT_FALSE(textfield_->key_handled()); |
415 textfield_->clear(); | |
416 | |
417 SendKeyEvent(ui::VKEY_UP); | |
418 EXPECT_TRUE(textfield_->key_received()); | |
419 EXPECT_FALSE(textfield_->key_handled()); | |
420 textfield_->clear(); | |
421 | |
422 SendKeyEvent(ui::VKEY_DOWN); | |
423 EXPECT_TRUE(textfield_->key_received()); | |
424 EXPECT_FALSE(textfield_->key_handled()); | |
319 } | 425 } |
320 | 426 |
321 TEST_F(NativeTextfieldViewsTest, CursorMovement) { | 427 TEST_F(NativeTextfieldViewsTest, CursorMovement) { |
322 InitTextfield(Textfield::STYLE_DEFAULT); | 428 InitTextfield(Textfield::STYLE_DEFAULT); |
323 | 429 |
324 // Test with trailing whitespace. | 430 // Test with trailing whitespace. |
325 textfield_->SetText(ASCIIToUTF16("one two hre ")); | 431 textfield_->SetText(ASCIIToUTF16("one two hre ")); |
326 | 432 |
327 // Send the cursor at the end. | 433 // Send the cursor at the end. |
328 SendKeyEventToTextfieldViews(ui::VKEY_END); | 434 SendKeyEvent(ui::VKEY_END); |
329 | 435 |
330 // Ctrl+Left should move the cursor just before the last word. | 436 // Ctrl+Left should move the cursor just before the last word. |
331 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); | 437 SendKeyEvent(ui::VKEY_LEFT, false, true); |
332 SendKeyEventToTextfieldViews(ui::VKEY_T); | 438 SendKeyEvent(ui::VKEY_T); |
333 EXPECT_STR_EQ("one two thre ", textfield_->text()); | 439 EXPECT_STR_EQ("one two thre ", textfield_->text()); |
334 EXPECT_STR_EQ("one two thre ", last_contents_); | 440 EXPECT_STR_EQ("one two thre ", last_contents_); |
335 | 441 |
336 // Ctrl+Right should move the cursor to the end of the last word. | 442 // Ctrl+Right should move the cursor to the end of the last word. |
337 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true); | 443 SendKeyEvent(ui::VKEY_RIGHT, false, true); |
338 SendKeyEventToTextfieldViews(ui::VKEY_E); | 444 SendKeyEvent(ui::VKEY_E); |
339 EXPECT_STR_EQ("one two three ", textfield_->text()); | 445 EXPECT_STR_EQ("one two three ", textfield_->text()); |
340 EXPECT_STR_EQ("one two three ", last_contents_); | 446 EXPECT_STR_EQ("one two three ", last_contents_); |
341 | 447 |
342 // Ctrl+Right again should move the cursor to the end. | 448 // Ctrl+Right again should move the cursor to the end. |
343 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true); | 449 SendKeyEvent(ui::VKEY_RIGHT, false, true); |
344 SendKeyEventToTextfieldViews(ui::VKEY_BACK); | 450 SendKeyEvent(ui::VKEY_BACK); |
345 EXPECT_STR_EQ("one two three", textfield_->text()); | 451 EXPECT_STR_EQ("one two three", textfield_->text()); |
346 EXPECT_STR_EQ("one two three", last_contents_); | 452 EXPECT_STR_EQ("one two three", last_contents_); |
347 | 453 |
348 // Test with leading whitespace. | 454 // Test with leading whitespace. |
349 textfield_->SetText(ASCIIToUTF16(" ne two")); | 455 textfield_->SetText(ASCIIToUTF16(" ne two")); |
350 | 456 |
351 // Send the cursor at the beginning. | 457 // Send the cursor at the beginning. |
352 SendKeyEventToTextfieldViews(ui::VKEY_HOME); | 458 SendKeyEvent(ui::VKEY_HOME); |
353 | 459 |
354 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the | 460 // Ctrl+Right, then Ctrl+Left should move the cursor to the beginning of the |
355 // first word. | 461 // first word. |
356 SendKeyEventToTextfieldViews(ui::VKEY_RIGHT, false, true); | 462 SendKeyEvent(ui::VKEY_RIGHT, false, true); |
357 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); | 463 SendKeyEvent(ui::VKEY_LEFT, false, true); |
358 SendKeyEventToTextfieldViews(ui::VKEY_O); | 464 SendKeyEvent(ui::VKEY_O); |
359 EXPECT_STR_EQ(" one two", textfield_->text()); | 465 EXPECT_STR_EQ(" one two", textfield_->text()); |
360 EXPECT_STR_EQ(" one two", last_contents_); | 466 EXPECT_STR_EQ(" one two", last_contents_); |
361 | 467 |
362 // Ctrl+Left to move the cursor to the beginning of the first word. | 468 // Ctrl+Left to move the cursor to the beginning of the first word. |
363 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); | 469 SendKeyEvent(ui::VKEY_LEFT, false, true); |
364 // Ctrl+Left again should move the cursor back to the very beginning. | 470 // Ctrl+Left again should move the cursor back to the very beginning. |
365 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); | 471 SendKeyEvent(ui::VKEY_LEFT, false, true); |
366 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); | 472 SendKeyEvent(ui::VKEY_DELETE); |
367 EXPECT_STR_EQ("one two", textfield_->text()); | 473 EXPECT_STR_EQ("one two", textfield_->text()); |
368 EXPECT_STR_EQ("one two", last_contents_); | 474 EXPECT_STR_EQ("one two", last_contents_); |
369 } | 475 } |
370 | 476 |
371 #if defined(OS_WIN) | 477 TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) { |
372 // TODO(oshima): Windows' FocusManager::ClearNativeFocus() resets the | |
373 // focused view to NULL, which causes crash in this test. Figure out | |
374 // why and fix this. | |
375 #define MAYBE_FocusTraversalTest DISABLED_FocusTraversalTest | |
376 #else | |
377 #define MAYBE_FocusTraversalTest FocusTraversalTest | |
378 #endif | |
379 TEST_F(NativeTextfieldViewsTest, MAYBE_FocusTraversalTest) { | |
380 InitTextfields(Textfield::STYLE_DEFAULT, 3); | 478 InitTextfields(Textfield::STYLE_DEFAULT, 3); |
381 textfield_->RequestFocus(); | 479 textfield_->RequestFocus(); |
382 | 480 |
383 EXPECT_EQ(1, GetFocusedView()->GetID()); | 481 EXPECT_EQ(1, GetFocusedView()->GetID()); |
384 widget_->GetFocusManager()->AdvanceFocus(false); | 482 widget_->GetFocusManager()->AdvanceFocus(false); |
385 EXPECT_EQ(2, GetFocusedView()->GetID()); | 483 EXPECT_EQ(2, GetFocusedView()->GetID()); |
386 widget_->GetFocusManager()->AdvanceFocus(false); | 484 widget_->GetFocusManager()->AdvanceFocus(false); |
387 EXPECT_EQ(3, GetFocusedView()->GetID()); | 485 EXPECT_EQ(3, GetFocusedView()->GetID()); |
388 // Cycle back to the first textfield. | 486 // Cycle back to the first textfield. |
389 widget_->GetFocusManager()->AdvanceFocus(false); | 487 widget_->GetFocusManager()->AdvanceFocus(false); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 } | 555 } |
458 | 556 |
459 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 557 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { |
460 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate()); | 558 scoped_ptr<TestViewsDelegate> test_views_delegate(new TestViewsDelegate()); |
461 AutoReset<views::ViewsDelegate*> auto_reset( | 559 AutoReset<views::ViewsDelegate*> auto_reset( |
462 &views::ViewsDelegate::views_delegate, test_views_delegate.get()); | 560 &views::ViewsDelegate::views_delegate, test_views_delegate.get()); |
463 | 561 |
464 InitTextfield(Textfield::STYLE_DEFAULT); | 562 InitTextfield(Textfield::STYLE_DEFAULT); |
465 textfield_->SetText(ASCIIToUTF16(" one two three ")); | 563 textfield_->SetText(ASCIIToUTF16(" one two three ")); |
466 textfield_->SetReadOnly(true); | 564 textfield_->SetReadOnly(true); |
467 SendKeyEventToTextfieldViews(ui::VKEY_HOME); | 565 SendKeyEvent(ui::VKEY_HOME); |
468 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 566 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
469 | 567 |
470 SendKeyEventToTextfieldViews(ui::VKEY_END); | 568 SendKeyEvent(ui::VKEY_END); |
471 EXPECT_EQ(15U, textfield_->GetCursorPosition()); | 569 EXPECT_EQ(15U, textfield_->GetCursorPosition()); |
472 | 570 |
473 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, false); | 571 SendKeyEvent(ui::VKEY_LEFT, false, false); |
474 EXPECT_EQ(14U, textfield_->GetCursorPosition()); | 572 EXPECT_EQ(14U, textfield_->GetCursorPosition()); |
475 | 573 |
476 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, false, true); | 574 SendKeyEvent(ui::VKEY_LEFT, false, true); |
477 EXPECT_EQ(9U, textfield_->GetCursorPosition()); | 575 EXPECT_EQ(9U, textfield_->GetCursorPosition()); |
478 | 576 |
479 SendKeyEventToTextfieldViews(ui::VKEY_LEFT, true, true); | 577 SendKeyEvent(ui::VKEY_LEFT, true, true); |
480 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | 578 EXPECT_EQ(5U, textfield_->GetCursorPosition()); |
481 EXPECT_STR_EQ("two ", textfield_->GetSelectedText()); | 579 EXPECT_STR_EQ("two ", textfield_->GetSelectedText()); |
482 | 580 |
483 textfield_->SelectAll(); | 581 textfield_->SelectAll(); |
484 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); | 582 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); |
485 | 583 |
486 // CUT&PASTE does not work, but COPY works | 584 // CUT&PASTE does not work, but COPY works |
487 SendKeyEventToTextfieldViews(ui::VKEY_X, false, true); | 585 SendKeyEvent(ui::VKEY_X, false, true); |
488 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); | 586 EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText()); |
489 string16 str; | 587 string16 str; |
490 views::ViewsDelegate::views_delegate->GetClipboard()-> | 588 views::ViewsDelegate::views_delegate->GetClipboard()-> |
491 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); | 589 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); |
492 EXPECT_STR_NE(" one two three ", str); | 590 EXPECT_STR_NE(" one two three ", str); |
493 | 591 |
494 SendKeyEventToTextfieldViews(ui::VKEY_C, false, true); | 592 SendKeyEvent(ui::VKEY_C, false, true); |
495 views::ViewsDelegate::views_delegate->GetClipboard()-> | 593 views::ViewsDelegate::views_delegate->GetClipboard()-> |
496 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); | 594 ReadText(ui::Clipboard::BUFFER_STANDARD, &str); |
497 EXPECT_STR_EQ(" one two three ", str); | 595 EXPECT_STR_EQ(" one two three ", str); |
498 | 596 |
499 // SetText should work even in read only mode. | 597 // SetText should work even in read only mode. |
500 textfield_->SetText(ASCIIToUTF16(" four five six ")); | 598 textfield_->SetText(ASCIIToUTF16(" four five six ")); |
501 EXPECT_STR_EQ(" four five six ", textfield_->text()); | 599 EXPECT_STR_EQ(" four five six ", textfield_->text()); |
502 | 600 |
503 // Paste shouldn't work. | 601 // Paste shouldn't work. |
504 SendKeyEventToTextfieldViews(ui::VKEY_V, false, true); | 602 SendKeyEvent(ui::VKEY_V, false, true); |
505 EXPECT_STR_EQ(" four five six ", textfield_->text()); | 603 EXPECT_STR_EQ(" four five six ", textfield_->text()); |
506 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | 604 EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
507 | 605 |
508 textfield_->SelectAll(); | 606 textfield_->SelectAll(); |
509 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 607 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
510 | 608 |
511 // Text field is unmodifiable and selection shouldn't change. | 609 // Text field is unmodifiable and selection shouldn't change. |
512 SendKeyEventToTextfieldViews(ui::VKEY_DELETE); | 610 SendKeyEvent(ui::VKEY_DELETE); |
513 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 611 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
514 SendKeyEventToTextfieldViews(ui::VKEY_BACK); | 612 SendKeyEvent(ui::VKEY_BACK); |
515 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 613 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
516 SendKeyEventToTextfieldViews(ui::VKEY_T); | 614 SendKeyEvent(ui::VKEY_T); |
517 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 615 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
518 } | 616 } |
519 | 617 |
618 TEST_F(NativeTextfieldViewsTest, TextInputClientTest) { | |
619 InitTextfield(Textfield::STYLE_DEFAULT); | |
620 TextInputClient* client = textfield_->GetTextInputClient(); | |
621 EXPECT_TRUE(client); | |
622 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); | |
623 | |
624 textfield_->SetText(ASCIIToUTF16("0123456789")); | |
625 ui::Range range; | |
626 EXPECT_TRUE(client->GetTextRange(&range)); | |
627 EXPECT_EQ(0U, range.start()); | |
628 EXPECT_EQ(10U, range.end()); | |
629 | |
630 EXPECT_TRUE(client->SetSelectionRange(ui::Range(1, 4))); | |
631 EXPECT_TRUE(client->GetSelectionRange(&range)); | |
632 EXPECT_EQ(ui::Range(1,4), range); | |
633 | |
634 // This code can't be compiled because of a bug in base::Callback. | |
635 #if 0 | |
636 GetTextHelper helper; | |
637 base::Callback<void(string16)> callback = | |
638 base::Bind(&GetTextHelper::set_text, base::Unretained(&helper)); | |
639 | |
640 EXPECT_TRUE(client->GetTextFromRange(range, callback)); | |
641 EXPECT_STR_EQ("123", helper.text()); | |
642 #endif | |
643 | |
644 EXPECT_TRUE(client->DeleteRange(range)); | |
645 EXPECT_STR_EQ("0456789", textfield_->text()); | |
646 | |
647 ui::CompositionText composition; | |
648 composition.text = UTF8ToUTF16("321"); | |
649 // Set composition through input method. | |
650 input_method_->Clear(); | |
651 input_method_->SetCompositionTextForNextKey(composition); | |
652 textfield_->clear(); | |
653 | |
654 on_before_user_action_ = on_after_user_action_ = 0; | |
655 SendKeyEvent(ui::VKEY_A); | |
656 EXPECT_TRUE(textfield_->key_received()); | |
657 EXPECT_FALSE(textfield_->key_handled()); | |
658 EXPECT_TRUE(client->HasCompositionText()); | |
659 EXPECT_TRUE(client->GetCompositionTextRange(&range)); | |
660 EXPECT_STR_EQ("0321456789", textfield_->text()); | |
661 EXPECT_EQ(ui::Range(1,4), range); | |
662 EXPECT_EQ(2, on_before_user_action_); | |
663 EXPECT_EQ(2, on_after_user_action_); | |
664 | |
665 input_method_->SetResultTextForNextKey(UTF8ToUTF16("123")); | |
666 on_before_user_action_ = on_after_user_action_ = 0; | |
667 textfield_->clear(); | |
668 SendKeyEvent(ui::VKEY_A); | |
669 EXPECT_TRUE(textfield_->key_received()); | |
670 EXPECT_FALSE(textfield_->key_handled()); | |
671 EXPECT_FALSE(client->HasCompositionText()); | |
672 EXPECT_FALSE(input_method_->cancel_composition_called()); | |
673 EXPECT_STR_EQ("0123456789", textfield_->text()); | |
674 EXPECT_EQ(2, on_before_user_action_); | |
675 EXPECT_EQ(2, on_after_user_action_); | |
676 | |
677 input_method_->Clear(); | |
678 input_method_->SetCompositionTextForNextKey(composition); | |
679 textfield_->clear(); | |
680 SendKeyEvent(ui::VKEY_A); | |
681 EXPECT_TRUE(client->HasCompositionText()); | |
682 EXPECT_STR_EQ("0123321456789", textfield_->text()); | |
683 | |
684 on_before_user_action_ = on_after_user_action_ = 0; | |
685 textfield_->clear(); | |
686 SendKeyEvent(ui::VKEY_RIGHT); | |
687 EXPECT_FALSE(client->HasCompositionText()); | |
688 EXPECT_TRUE(input_method_->cancel_composition_called()); | |
689 EXPECT_TRUE(textfield_->key_received()); | |
690 EXPECT_TRUE(textfield_->key_handled()); | |
691 EXPECT_STR_EQ("0123321456789", textfield_->text()); | |
692 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | |
693 EXPECT_EQ(1, on_before_user_action_); | |
694 EXPECT_EQ(1, on_after_user_action_); | |
695 | |
696 input_method_->Clear(); | |
697 textfield_->SetReadOnly(true); | |
698 EXPECT_TRUE(input_method_->text_input_type_changed()); | |
699 EXPECT_FALSE(textfield_->GetTextInputClient()); | |
700 | |
701 textfield_->SetReadOnly(false); | |
702 input_method_->Clear(); | |
703 textfield_->SetPassword(true); | |
704 EXPECT_TRUE(input_method_->text_input_type_changed()); | |
705 EXPECT_TRUE(textfield_->GetTextInputClient()); | |
706 } | |
707 | |
708 | |
520 } // namespace views | 709 } // namespace views |
OLD | NEW |