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

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

Issue 1177503003: Remove the 2-level input method system & InputMethodBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/controls/tree/tree_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/pickle.h" 12 #include "base/pickle.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "ui/accessibility/ax_view_state.h" 15 #include "ui/accessibility/ax_view_state.h"
16 #include "ui/base/clipboard/clipboard.h" 16 #include "ui/base/clipboard/clipboard.h"
17 #include "ui/base/clipboard/scoped_clipboard_writer.h" 17 #include "ui/base/clipboard/scoped_clipboard_writer.h"
18 #include "ui/base/dragdrop/drag_drop_types.h" 18 #include "ui/base/dragdrop/drag_drop_types.h"
19 #include "ui/base/ime/input_method_base.h"
20 #include "ui/base/ime/input_method_delegate.h"
21 #include "ui/base/ime/input_method_factory.h"
19 #include "ui/base/ime/text_input_client.h" 22 #include "ui/base/ime/text_input_client.h"
20 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/ui_base_switches.h" 24 #include "ui/base/ui_base_switches.h"
22 #include "ui/base/ui_base_switches_util.h" 25 #include "ui/base/ui_base_switches_util.h"
23 #include "ui/events/event.h" 26 #include "ui/events/event.h"
27 #include "ui/events/event_processor.h"
24 #include "ui/events/event_utils.h" 28 #include "ui/events/event_utils.h"
25 #include "ui/events/keycodes/keyboard_codes.h" 29 #include "ui/events/keycodes/keyboard_codes.h"
26 #include "ui/events/test/event_generator.h" 30 #include "ui/events/test/event_generator.h"
27 #include "ui/gfx/render_text.h" 31 #include "ui/gfx/render_text.h"
28 #include "ui/strings/grit/ui_strings.h" 32 #include "ui/strings/grit/ui_strings.h"
29 #include "ui/views/controls/textfield/textfield_controller.h" 33 #include "ui/views/controls/textfield/textfield_controller.h"
30 #include "ui/views/controls/textfield/textfield_model.h" 34 #include "ui/views/controls/textfield/textfield_model.h"
31 #include "ui/views/controls/textfield/textfield_test_api.h" 35 #include "ui/views/controls/textfield/textfield_test_api.h"
32 #include "ui/views/focus/focus_manager.h" 36 #include "ui/views/focus/focus_manager.h"
33 #include "ui/views/ime/mock_input_method.h"
34 #include "ui/views/test/test_views_delegate.h" 37 #include "ui/views/test/test_views_delegate.h"
35 #include "ui/views/test/views_test_base.h" 38 #include "ui/views/test/views_test_base.h"
36 #include "ui/views/test/widget_test.h" 39 #include "ui/views/test/widget_test.h"
37 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
38 #include "url/gurl.h" 41 #include "url/gurl.h"
39 42
40 #if defined(OS_WIN) 43 #if defined(OS_WIN)
41 #include "base/win/windows_version.h" 44 #include "base/win/windows_version.h"
42 #endif 45 #endif
43 46
44 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 47 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
45 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" 48 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
46 #endif 49 #endif
47 50
48 #if defined(USE_X11) 51 #if defined(USE_X11)
49 #include "ui/events/event_utils.h" 52 #include "ui/events/event_utils.h"
50 #endif 53 #endif
51 54
52 using base::ASCIIToUTF16; 55 using base::ASCIIToUTF16;
53 using base::UTF8ToUTF16; 56 using base::UTF8ToUTF16;
54 using base::WideToUTF16; 57 using base::WideToUTF16;
55 58
56 #define EXPECT_STR_EQ(ascii, utf16) EXPECT_EQ(ASCIIToUTF16(ascii), utf16) 59 #define EXPECT_STR_EQ(ascii, utf16) EXPECT_EQ(ASCIIToUTF16(ascii), utf16)
57 60
58 namespace { 61 namespace {
59 62
60 const base::char16 kHebrewLetterSamekh = 0x05E1; 63 const base::char16 kHebrewLetterSamekh = 0x05E1;
61 64
65 class MockInputMethod : public ui::InputMethodBase {
66 public:
67 MockInputMethod();
68 ~MockInputMethod() override;
69
70 // Overridden from InputMethod:
71 bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
72 NativeEventResult* result) override;
73 bool DispatchKeyEvent(const ui::KeyEvent& key) override;
74 void OnTextInputTypeChanged(const ui::TextInputClient* client) override;
75 void OnCaretBoundsChanged(const ui::TextInputClient* client) override {}
76 void CancelComposition(const ui::TextInputClient* client) override;
77 void OnInputLocaleChanged() override {}
78 std::string GetInputLocale() override;
79 bool IsActive() override;
80 bool IsCandidatePopupOpen() const override;
81 void ShowImeIfNeeded() override {}
82
83 bool untranslated_ime_message_called() const {
84 return untranslated_ime_message_called_;
85 }
86 bool text_input_type_changed() const { return text_input_type_changed_; }
87 bool cancel_composition_called() const { return cancel_composition_called_; }
88
89 // Clears all internal states and result.
90 void Clear();
91
92 void SetCompositionTextForNextKey(const ui::CompositionText& composition);
93 void SetResultTextForNextKey(const base::string16& result);
94
95 private:
96 // Overridden from InputMethodBase.
97 void OnWillChangeFocusedClient(ui::TextInputClient* focused_before,
98 ui::TextInputClient* focused) override;
99
100 // Clears boolean states defined below.
101 void ClearStates();
102
103 // Whether a mock composition or result is scheduled for the next key event.
104 bool HasComposition();
105
106 // Clears only composition information and result text.
107 void ClearComposition();
108
109 // Composition information for the next key event. It'll be cleared
110 // automatically after dispatching the next key event.
111 ui::CompositionText composition_;
112
113 // Result text for the next key event. It'll be cleared automatically after
114 // dispatching the next key event.
115 base::string16 result_text_;
116
117 // Record call state of corresponding methods. They will be set to false
118 // automatically before dispatching a key event.
119 bool untranslated_ime_message_called_;
120 bool text_input_type_changed_;
121 bool cancel_composition_called_;
122
123 DISALLOW_COPY_AND_ASSIGN(MockInputMethod);
124 };
125
126 MockInputMethod::MockInputMethod()
127 : untranslated_ime_message_called_(false),
128 text_input_type_changed_(false),
129 cancel_composition_called_(false) {
130 }
131
132 MockInputMethod::~MockInputMethod() {
133 }
134
135 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event,
136 NativeEventResult* result) {
137 if (result)
138 *result = NativeEventResult();
139 return false;
140 }
141
142 bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& key) {
143 // Checks whether the key event is from EventGenerator on Windows which will
144 // generate key event for WM_CHAR.
145 // The MockInputMethod will insert char on WM_KEYDOWN so ignore WM_CHAR here.
146 if (key.is_char() && key.HasNativeEvent())
147 return true;
148
149 bool handled = !IsTextInputTypeNone() && HasComposition();
150 ClearStates();
151 if (handled) {
152 DCHECK(!key.is_char());
153 ui::KeyEvent mock_key(ui::ET_KEY_PRESSED, ui::VKEY_PROCESSKEY, key.flags());
154 DispatchKeyEventPostIME(mock_key);
155 } else {
156 DispatchKeyEventPostIME(key);
157 }
158
159 ui::TextInputClient* client = GetTextInputClient();
160 if (client) {
161 if (handled) {
162 if (result_text_.length())
163 client->InsertText(result_text_);
164 if (composition_.text.length())
165 client->SetCompositionText(composition_);
166 else
167 client->ClearCompositionText();
168 } else if (key.type() == ui::ET_KEY_PRESSED) {
169 base::char16 ch = key.GetCharacter();
170 if (ch)
171 client->InsertChar(ch, key.flags());
172 }
173 }
174
175 ClearComposition();
176 return true;
177 }
178
179 void MockInputMethod::OnTextInputTypeChanged(
180 const ui::TextInputClient* client) {
181 if (IsTextInputClientFocused(client))
182 text_input_type_changed_ = true;
183 InputMethodBase::OnTextInputTypeChanged(client);
184 }
185
186 void MockInputMethod::CancelComposition(const ui::TextInputClient* client) {
187 if (IsTextInputClientFocused(client)) {
188 cancel_composition_called_ = true;
189 ClearComposition();
190 }
191 }
192
193 std::string MockInputMethod::GetInputLocale() {
194 return "en-US";
195 }
196
197 bool MockInputMethod::IsActive() {
198 return true;
199 }
200
201 bool MockInputMethod::IsCandidatePopupOpen() const {
202 return false;
203 }
204
205 void MockInputMethod::OnWillChangeFocusedClient(
206 ui::TextInputClient* focused_before,
207 ui::TextInputClient* focused) {
208 ui::TextInputClient* client = GetTextInputClient();
209 if (client && client->HasCompositionText())
210 client->ConfirmCompositionText();
211 ClearComposition();
212 }
213
214 void MockInputMethod::Clear() {
215 ClearStates();
216 ClearComposition();
217 }
218
219 void MockInputMethod::SetCompositionTextForNextKey(
220 const ui::CompositionText& composition) {
221 composition_ = composition;
222 }
223
224 void MockInputMethod::SetResultTextForNextKey(const base::string16& result) {
225 result_text_ = result;
226 }
227
228 void MockInputMethod::ClearStates() {
229 untranslated_ime_message_called_ = false;
230 text_input_type_changed_ = false;
231 cancel_composition_called_ = false;
232 }
233
234 bool MockInputMethod::HasComposition() {
235 return composition_.text.length() || result_text_.length();
236 }
237
238 void MockInputMethod::ClearComposition() {
239 composition_.Clear();
240 result_text_.clear();
241 }
242
62 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults. 243 // A Textfield wrapper to intercept OnKey[Pressed|Released]() ressults.
63 class TestTextfield : public views::Textfield { 244 class TestTextfield : public views::Textfield {
64 public: 245 public:
65 TestTextfield() 246 TestTextfield()
66 : Textfield(), 247 : Textfield(),
67 key_handled_(false), 248 key_handled_(false),
68 key_received_(false), 249 key_received_(false),
69 weak_ptr_factory_(this) {} 250 weak_ptr_factory_(this) {}
70 251
71 bool OnKeyPressed(const ui::KeyEvent& e) override { 252 bool OnKeyPressed(const ui::KeyEvent& e) override {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 explicit TextfieldDestroyerController(views::Textfield* target) 313 explicit TextfieldDestroyerController(views::Textfield* target)
133 : target_(target) { 314 : target_(target) {
134 target_->set_controller(this); 315 target_->set_controller(this);
135 } 316 }
136 317
137 views::Textfield* target() { return target_.get(); } 318 views::Textfield* target() { return target_.get(); }
138 319
139 // views::TextfieldController: 320 // views::TextfieldController:
140 bool HandleKeyEvent(views::Textfield* sender, 321 bool HandleKeyEvent(views::Textfield* sender,
141 const ui::KeyEvent& key_event) override { 322 const ui::KeyEvent& key_event) override {
323 target_->OnBlur();
142 target_.reset(); 324 target_.reset();
143 return false; 325 return false;
144 } 326 }
145 327
146 private: 328 private:
147 scoped_ptr<views::Textfield> target_; 329 scoped_ptr<views::Textfield> target_;
148 }; 330 };
149 331
150 base::string16 GetClipboardText(ui::ClipboardType type) { 332 base::string16 GetClipboardText(ui::ClipboardType type) {
151 base::string16 text; 333 base::string16 text;
(...skipping 12 matching lines...) Expand all
164 class TextfieldTest : public ViewsTestBase, public TextfieldController { 346 class TextfieldTest : public ViewsTestBase, public TextfieldController {
165 public: 347 public:
166 TextfieldTest() 348 TextfieldTest()
167 : widget_(NULL), 349 : widget_(NULL),
168 textfield_(NULL), 350 textfield_(NULL),
169 model_(NULL), 351 model_(NULL),
170 input_method_(NULL), 352 input_method_(NULL),
171 on_before_user_action_(0), 353 on_before_user_action_(0),
172 on_after_user_action_(0), 354 on_after_user_action_(0),
173 copied_to_clipboard_(ui::CLIPBOARD_TYPE_LAST) { 355 copied_to_clipboard_(ui::CLIPBOARD_TYPE_LAST) {
356 input_method_ = new MockInputMethod();
357 ui::SetUpInputMethodForTesting(input_method_);
174 } 358 }
175 359
176 // ::testing::Test: 360 // ::testing::Test:
177 void TearDown() override { 361 void TearDown() override {
178 if (widget_) 362 if (widget_)
179 widget_->Close(); 363 widget_->Close();
180 ViewsTestBase::TearDown(); 364 ViewsTestBase::TearDown();
181 } 365 }
182 366
183 ui::ClipboardType GetAndResetCopiedToClipboard() { 367 ui::ClipboardType GetAndResetCopiedToClipboard() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 textfield_->set_controller(this); 401 textfield_->set_controller(this);
218 widget_ = new Widget(); 402 widget_ = new Widget();
219 403
220 // The widget type must be an activatable type, and we don't want to worry 404 // The widget type must be an activatable type, and we don't want to worry
221 // about the non-client view, which leaves just TYPE_WINDOW_FRAMELESS. 405 // about the non-client view, which leaves just TYPE_WINDOW_FRAMELESS.
222 Widget::InitParams params = 406 Widget::InitParams params =
223 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 407 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
224 408
225 params.bounds = gfx::Rect(100, 100, 100, 100); 409 params.bounds = gfx::Rect(100, 100, 100, 100);
226 widget_->Init(params); 410 widget_->Init(params);
411 input_method_->SetDelegate(
412 test::WidgetTest::GetInputMethodDelegateForWidget(widget_));
227 View* container = new View(); 413 View* container = new View();
228 widget_->SetContentsView(container); 414 widget_->SetContentsView(container);
229 container->AddChildView(textfield_); 415 container->AddChildView(textfield_);
230 textfield_->SetBoundsRect(params.bounds); 416 textfield_->SetBoundsRect(params.bounds);
231 textfield_->set_id(1); 417 textfield_->set_id(1);
232 test_api_.reset(new TextfieldTestApi(textfield_)); 418 test_api_.reset(new TextfieldTestApi(textfield_));
233 419
234 for (int i = 1; i < count; i++) { 420 for (int i = 1; i < count; i++) {
235 Textfield* textfield = new Textfield(); 421 Textfield* textfield = new Textfield();
236 container->AddChildView(textfield); 422 container->AddChildView(textfield);
237 textfield->set_id(i + 1); 423 textfield->set_id(i + 1);
238 } 424 }
239 425
240 model_ = test_api_->model(); 426 model_ = test_api_->model();
241 model_->ClearEditHistory(); 427 model_->ClearEditHistory();
242 428
243 input_method_ = new MockInputMethod();
244 widget_->ReplaceInputMethod(input_method_);
245
246 // Since the window type is activatable, showing the widget will also 429 // Since the window type is activatable, showing the widget will also
247 // activate it. Calling Activate directly is insufficient, since that does 430 // activate it. Calling Activate directly is insufficient, since that does
248 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the 431 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the
249 // widget and the textfield must have focus to properly handle input. 432 // widget and the textfield must have focus to properly handle input.
250 widget_->Show(); 433 widget_->Show();
251 textfield_->RequestFocus(); 434 textfield_->RequestFocus();
252 435
253 // On Mac, activation is asynchronous since desktop widgets are used. We 436 // On Mac, activation is asynchronous since desktop widgets are used. We
254 // don't want parallel tests to steal active status either, so fake it. 437 // don't want parallel tests to steal active status either, so fake it.
255 #if defined(OS_MACOSX) && !defined(USE_AURA) 438 #if defined(OS_MACOSX) && !defined(USE_AURA)
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 SendKeyEvent(ui::VKEY_DELETE); 1459 SendKeyEvent(ui::VKEY_DELETE);
1277 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1460 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1278 SendKeyEvent(ui::VKEY_BACK); 1461 SendKeyEvent(ui::VKEY_BACK);
1279 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1462 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1280 SendKeyEvent(ui::VKEY_T); 1463 SendKeyEvent(ui::VKEY_T);
1281 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1464 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1282 } 1465 }
1283 1466
1284 TEST_F(TextfieldTest, TextInputClientTest) { 1467 TEST_F(TextfieldTest, TextInputClientTest) {
1285 InitTextfield(); 1468 InitTextfield();
1286 ui::TextInputClient* client = textfield_->GetTextInputClient(); 1469 ui::TextInputClient* client = textfield_;
1287 EXPECT_TRUE(client); 1470 EXPECT_TRUE(client);
1288 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); 1471 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType());
1289 1472
1290 textfield_->SetText(ASCIIToUTF16("0123456789")); 1473 textfield_->SetText(ASCIIToUTF16("0123456789"));
1291 gfx::Range range; 1474 gfx::Range range;
1292 EXPECT_TRUE(client->GetTextRange(&range)); 1475 EXPECT_TRUE(client->GetTextRange(&range));
1293 EXPECT_EQ(0U, range.start()); 1476 EXPECT_EQ(0U, range.start());
1294 EXPECT_EQ(10U, range.end()); 1477 EXPECT_EQ(10U, range.end());
1295 1478
1296 EXPECT_TRUE(client->SetSelectionRange(gfx::Range(1, 4))); 1479 EXPECT_TRUE(client->SetSelectionRange(gfx::Range(1, 4)));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 textfield_->clear(); 1556 textfield_->clear();
1374 textfield_->ClearSelection(); 1557 textfield_->ClearSelection();
1375 textfield_->SelectAll(false); 1558 textfield_->SelectAll(false);
1376 EXPECT_EQ(0, on_before_user_action_); 1559 EXPECT_EQ(0, on_before_user_action_);
1377 EXPECT_EQ(0, on_after_user_action_); 1560 EXPECT_EQ(0, on_after_user_action_);
1378 1561
1379 input_method_->Clear(); 1562 input_method_->Clear();
1380 1563
1381 // Changing the Textfield to readonly shouldn't change the input client, since 1564 // Changing the Textfield to readonly shouldn't change the input client, since
1382 // it's still required for selections and clipboard copy. 1565 // it's still required for selections and clipboard copy.
1383 ui::TextInputClient* text_input_client = textfield_->GetTextInputClient(); 1566 ui::TextInputClient* text_input_client = textfield_;
1384 EXPECT_TRUE(text_input_client); 1567 EXPECT_TRUE(text_input_client);
1385 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType()); 1568 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
1386 textfield_->SetReadOnly(true); 1569 textfield_->SetReadOnly(true);
1387 EXPECT_TRUE(input_method_->text_input_type_changed()); 1570 EXPECT_TRUE(input_method_->text_input_type_changed());
1388 EXPECT_EQ(text_input_client, textfield_->GetTextInputClient());
1389 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType()); 1571 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
1390 1572
1391 input_method_->Clear(); 1573 input_method_->Clear();
1392 textfield_->SetReadOnly(false); 1574 textfield_->SetReadOnly(false);
1393 EXPECT_TRUE(input_method_->text_input_type_changed()); 1575 EXPECT_TRUE(input_method_->text_input_type_changed());
1394 EXPECT_EQ(text_input_client, textfield_->GetTextInputClient());
1395 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType()); 1576 EXPECT_NE(ui::TEXT_INPUT_TYPE_NONE, text_input_client->GetTextInputType());
1396 1577
1397 input_method_->Clear(); 1578 input_method_->Clear();
1398 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 1579 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
1399 EXPECT_TRUE(input_method_->text_input_type_changed()); 1580 EXPECT_TRUE(input_method_->text_input_type_changed());
1400 EXPECT_TRUE(textfield_->GetTextInputClient());
1401 } 1581 }
1402 1582
1403 TEST_F(TextfieldTest, UndoRedoTest) { 1583 TEST_F(TextfieldTest, UndoRedoTest) {
1404 InitTextfield(); 1584 InitTextfield();
1405 SendKeyEvent(ui::VKEY_A); 1585 SendKeyEvent(ui::VKEY_A);
1406 EXPECT_STR_EQ("a", textfield_->text()); 1586 EXPECT_STR_EQ("a", textfield_->text());
1407 SendKeyEvent(ui::VKEY_Z, false, true); 1587 SendKeyEvent(ui::VKEY_Z, false, true);
1408 EXPECT_STR_EQ("", textfield_->text()); 1588 EXPECT_STR_EQ("", textfield_->text());
1409 SendKeyEvent(ui::VKEY_Z, false, true); 1589 SendKeyEvent(ui::VKEY_Z, false, true);
1410 EXPECT_STR_EQ("", textfield_->text()); 1590 EXPECT_STR_EQ("", textfield_->text());
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 2081
1902 // Reset locale. 2082 // Reset locale.
1903 base::i18n::SetICUDefaultLocale(locale); 2083 base::i18n::SetICUDefaultLocale(locale);
1904 } 2084 }
1905 2085
1906 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { 2086 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) {
1907 InitTextfield(); 2087 InitTextfield();
1908 ui::CompositionText composition; 2088 ui::CompositionText composition;
1909 composition.text = UTF8ToUTF16("abc123"); 2089 composition.text = UTF8ToUTF16("abc123");
1910 const uint32 char_count = static_cast<uint32>(composition.text.length()); 2090 const uint32 char_count = static_cast<uint32>(composition.text.length());
1911 ui::TextInputClient* client = textfield_->GetTextInputClient(); 2091 ui::TextInputClient* client = textfield_;
1912 2092
1913 // Compare the composition character bounds with surrounding cursor bounds. 2093 // Compare the composition character bounds with surrounding cursor bounds.
1914 for (uint32 i = 0; i < char_count; ++i) { 2094 for (uint32 i = 0; i < char_count; ++i) {
1915 composition.selection = gfx::Range(i); 2095 composition.selection = gfx::Range(i);
1916 client->SetCompositionText(composition); 2096 client->SetCompositionText(composition);
1917 gfx::Point cursor_origin = GetCursorBounds().origin(); 2097 gfx::Point cursor_origin = GetCursorBounds().origin();
1918 views::View::ConvertPointToScreen(textfield_, &cursor_origin); 2098 views::View::ConvertPointToScreen(textfield_, &cursor_origin);
1919 2099
1920 composition.selection = gfx::Range(i + 1); 2100 composition.selection = gfx::Range(i + 1);
1921 client->SetCompositionText(composition); 2101 client->SetCompositionText(composition);
(...skipping 25 matching lines...) Expand all
1947 0x5642, 0xDB40, 0xDD00, 2127 0x5642, 0xDB40, 0xDD00,
1948 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences 2128 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences
1949 0x260E, 0xFE0F, 2129 0x260E, 0xFE0F,
1950 // U+0020 SPACE 2130 // U+0020 SPACE
1951 0x0020, 2131 0x0020,
1952 }; 2132 };
1953 const size_t kUtf16CharsCount = arraysize(kUtf16Chars); 2133 const size_t kUtf16CharsCount = arraysize(kUtf16Chars);
1954 2134
1955 ui::CompositionText composition; 2135 ui::CompositionText composition;
1956 composition.text.assign(kUtf16Chars, kUtf16Chars + kUtf16CharsCount); 2136 composition.text.assign(kUtf16Chars, kUtf16Chars + kUtf16CharsCount);
1957 ui::TextInputClient* client = textfield_->GetTextInputClient(); 2137 ui::TextInputClient* client = textfield_;
1958 client->SetCompositionText(composition); 2138 client->SetCompositionText(composition);
1959 2139
1960 // Make sure GetCompositionCharacterBounds never fails for index. 2140 // Make sure GetCompositionCharacterBounds never fails for index.
1961 gfx::Rect rects[kUtf16CharsCount]; 2141 gfx::Rect rects[kUtf16CharsCount];
1962 gfx::Rect prev_cursor = GetCursorBounds(); 2142 gfx::Rect prev_cursor = GetCursorBounds();
1963 for (uint32 i = 0; i < kUtf16CharsCount; ++i) 2143 for (uint32 i = 0; i < kUtf16CharsCount; ++i)
1964 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &rects[i])); 2144 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &rects[i]));
1965 2145
1966 // Here we might expect the following results but it actually depends on how 2146 // Here we might expect the following results but it actually depends on how
1967 // Uniscribe or HarfBuzz treats them with given font. 2147 // Uniscribe or HarfBuzz treats them with given font.
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 2538
2359 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2539 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2360 ui::AXViewState state_protected; 2540 ui::AXViewState state_protected;
2361 textfield_->GetAccessibleState(&state_protected); 2541 textfield_->GetAccessibleState(&state_protected);
2362 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2542 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2363 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2543 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2364 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2544 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2365 } 2545 }
2366 2546
2367 } // namespace views 2547 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/controls/tree/tree_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698