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