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

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

Issue 879253002: MacViews: Convert Cocoa action messages into editing commands for text fields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150127-MacViews-SendTextfieldToWindow-BORING-FILE-MOVES
Patch Set: Use VKEY_DELETE Created 5 years, 10 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/cocoa/bridged_content_view.mm ('k') | ui/views/test/event_generator_delegate_mac.mm » ('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/base/clipboard/clipboard.h" 15 #include "ui/base/clipboard/clipboard.h"
16 #include "ui/base/clipboard/scoped_clipboard_writer.h" 16 #include "ui/base/clipboard/scoped_clipboard_writer.h"
17 #include "ui/base/dragdrop/drag_drop_types.h" 17 #include "ui/base/dragdrop/drag_drop_types.h"
18 #include "ui/base/ime/text_input_client.h" 18 #include "ui/base/ime/text_input_client.h"
19 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/ui_base_switches.h" 20 #include "ui/base/ui_base_switches.h"
21 #include "ui/base/ui_base_switches_util.h" 21 #include "ui/base/ui_base_switches_util.h"
22 #include "ui/events/event.h" 22 #include "ui/events/event.h"
23 #include "ui/events/keycodes/keyboard_codes.h" 23 #include "ui/events/keycodes/keyboard_codes.h"
24 #include "ui/events/test/event_generator.h"
24 #include "ui/gfx/render_text.h" 25 #include "ui/gfx/render_text.h"
25 #include "ui/strings/grit/ui_strings.h" 26 #include "ui/strings/grit/ui_strings.h"
26 #include "ui/views/controls/textfield/textfield_controller.h" 27 #include "ui/views/controls/textfield/textfield_controller.h"
27 #include "ui/views/controls/textfield/textfield_model.h" 28 #include "ui/views/controls/textfield/textfield_model.h"
28 #include "ui/views/controls/textfield/textfield_test_api.h" 29 #include "ui/views/controls/textfield/textfield_test_api.h"
29 #include "ui/views/focus/focus_manager.h" 30 #include "ui/views/focus/focus_manager.h"
30 #include "ui/views/ime/mock_input_method.h" 31 #include "ui/views/ime/mock_input_method.h"
31 #include "ui/views/test/test_views_delegate.h" 32 #include "ui/views/test/test_views_delegate.h"
32 #include "ui/views/test/views_test_base.h" 33 #include "ui/views/test/views_test_base.h"
33 #include "ui/views/test/widget_test.h" 34 #include "ui/views/test/widget_test.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 196
196 void InitTextfield() { 197 void InitTextfield() {
197 InitTextfields(1); 198 InitTextfields(1);
198 } 199 }
199 200
200 void InitTextfields(int count) { 201 void InitTextfields(int count) {
201 ASSERT_FALSE(textfield_); 202 ASSERT_FALSE(textfield_);
202 textfield_ = new TestTextfield(); 203 textfield_ = new TestTextfield();
203 textfield_->set_controller(this); 204 textfield_->set_controller(this);
204 widget_ = new Widget(); 205 widget_ = new Widget();
205 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 206
207 // The widget type must be an activatable type, and we don't want to worry
208 // about the non-client view, which leaves just TYPE_WINDOW_FRAMELESS.
209 Widget::InitParams params =
210 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
211
206 params.bounds = gfx::Rect(100, 100, 100, 100); 212 params.bounds = gfx::Rect(100, 100, 100, 100);
207 widget_->Init(params); 213 widget_->Init(params);
208 View* container = new View(); 214 View* container = new View();
209 widget_->SetContentsView(container); 215 widget_->SetContentsView(container);
210 container->AddChildView(textfield_); 216 container->AddChildView(textfield_);
211 textfield_->SetBoundsRect(params.bounds); 217 textfield_->SetBoundsRect(params.bounds);
212 textfield_->set_id(1); 218 textfield_->set_id(1);
213 test_api_.reset(new TextfieldTestApi(textfield_)); 219 test_api_.reset(new TextfieldTestApi(textfield_));
214 220
215 for (int i = 1; i < count; i++) { 221 for (int i = 1; i < count; i++) {
216 Textfield* textfield = new Textfield(); 222 Textfield* textfield = new Textfield();
217 container->AddChildView(textfield); 223 container->AddChildView(textfield);
218 textfield->set_id(i + 1); 224 textfield->set_id(i + 1);
219 } 225 }
220 226
221 model_ = test_api_->model(); 227 model_ = test_api_->model();
222 model_->ClearEditHistory(); 228 model_->ClearEditHistory();
223 229
224 input_method_ = new MockInputMethod(); 230 input_method_ = new MockInputMethod();
225 widget_->ReplaceInputMethod(input_method_); 231 widget_->ReplaceInputMethod(input_method_);
226 232
227 // Activate the widget and focus the textfield for input handling. 233 // Since the window type is activatable, showing the widget will also
228 widget_->Activate(); 234 // activate it. Calling Activate directly is insufficient, since that does
235 // not also _focus_ an aura::Window (i.e. using the FocusClient). Both the
236 // widget and the textfield must have focus to properly handle input.
237 widget_->Show();
229 textfield_->RequestFocus(); 238 textfield_->RequestFocus();
230 239
231 // On Mac, activation is asynchronous since desktop widgets are used. We 240 // On Mac, activation is asynchronous since desktop widgets are used. We
232 // don't want parallel tests to steal active status either, so fake it. 241 // don't want parallel tests to steal active status either, so fake it.
233 #if defined(OS_MACOSX) && !defined(USE_AURA) 242 #if defined(OS_MACOSX) && !defined(USE_AURA)
234 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways(); 243 fake_activation_ = test::WidgetTest::FakeWidgetIsActiveAlways();
235 #endif 244 #endif
245
246 event_generator_.reset(
247 new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow()));
236 } 248 }
237 249
238 ui::MenuModel* GetContextMenuModel() { 250 ui::MenuModel* GetContextMenuModel() {
239 test_api_->UpdateContextMenu(); 251 test_api_->UpdateContextMenu();
240 return test_api_->context_menu_contents(); 252 return test_api_->context_menu_contents();
241 } 253 }
242 254
255 // True if native Mac keystrokes should be used (to avoid ifdef litter).
256 bool TestingNativeMac() {
257 #if defined(OS_MACOSX)
258 return true;
259 #else
260 return false;
261 #endif
262 }
263
243 protected: 264 protected:
244 void SendKeyEvent(ui::KeyboardCode key_code, 265 void SendKeyEvent(ui::KeyboardCode key_code,
245 bool alt, 266 bool alt,
246 bool shift, 267 bool shift,
247 bool control, 268 bool control_or_command,
248 bool caps_lock) { 269 bool caps_lock) {
249 int flags = (alt ? ui::EF_ALT_DOWN : 0) | 270 bool control = control_or_command;
250 (shift ? ui::EF_SHIFT_DOWN : 0) | 271 bool command = false;
272
273 // By default, swap control and command for native events on Mac. This
274 // handles most cases.
275 if (TestingNativeMac())
276 std::swap(control, command);
277
278 int flags = (alt ? ui::EF_ALT_DOWN : 0) | (shift ? ui::EF_SHIFT_DOWN : 0) |
251 (control ? ui::EF_CONTROL_DOWN : 0) | 279 (control ? ui::EF_CONTROL_DOWN : 0) |
280 (command ? ui::EF_COMMAND_DOWN : 0) |
252 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0); 281 (caps_lock ? ui::EF_CAPS_LOCK_DOWN : 0);
253 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, flags); 282
254 input_method_->DispatchKeyEvent(event); 283 event_generator_->PressKey(key_code, flags);
255 } 284 }
256 285
257 void SendKeyEvent(ui::KeyboardCode key_code, bool shift, bool control) { 286 void SendKeyEvent(ui::KeyboardCode key_code,
258 SendKeyEvent(key_code, false, shift, control, false); 287 bool shift,
288 bool control_or_command) {
289 SendKeyEvent(key_code, false, shift, control_or_command, false);
259 } 290 }
260 291
261 void SendKeyEvent(ui::KeyboardCode key_code) { 292 void SendKeyEvent(ui::KeyboardCode key_code) {
262 SendKeyEvent(key_code, false, false); 293 SendKeyEvent(key_code, false, false);
263 } 294 }
264 295
265 void SendKeyEvent(base::char16 ch) { 296 void SendKeyEvent(base::char16 ch) {
266 if (ch < 0x80) { 297 if (ch < 0x80) {
267 ui::KeyboardCode code = 298 ui::KeyboardCode code =
268 ch == ' ' ? ui::VKEY_SPACE : 299 ch == ' ' ? ui::VKEY_SPACE :
269 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); 300 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a');
270 SendKeyEvent(code); 301 SendKeyEvent(code);
271 } else { 302 } else {
303 // For unicode characters, assume they come from IME rather than the
304 // keyboard. So they are dispatched directly to the input method.
272 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE); 305 ui::KeyEvent event(ch, ui::VKEY_UNKNOWN, ui::EF_NONE);
273 input_method_->DispatchKeyEvent(event); 306 input_method_->DispatchKeyEvent(event);
274 } 307 }
275 } 308 }
276 309
310 // Sends a platform-specific move (and select) to start of line.
311 void SendHomeEvent(bool shift) {
312 if (TestingNativeMac()) {
313 // Use Cmd+Left on native Mac. An RTL-agnostic "end" doesn't have a
314 // default key-binding on Mac.
315 SendKeyEvent(ui::VKEY_LEFT, shift /* shift */, true /* command */);
316 return;
317 }
318 SendKeyEvent(ui::VKEY_HOME, shift /* shift */, false /* control */);
319 }
320
321 // Sends a platform-specific move (and select) to end of line.
322 void SendEndEvent(bool shift) {
323 if (TestingNativeMac()) {
324 SendKeyEvent(ui::VKEY_RIGHT, shift, true); // Cmd+Right.
325 return;
326 }
327 SendKeyEvent(ui::VKEY_END, shift, false);
328 }
329
330 // Sends {delete, move, select} word {forward, backward}.
331 void SendWordEvent(ui::KeyboardCode key, bool shift) {
332 bool alt = false;
333 bool control = true;
334 bool caps = false;
335 if (TestingNativeMac()) {
336 // Use Alt+Left/Right/Backspace on native Mac.
337 alt = true;
338 control = false;
339 }
340 SendKeyEvent(key, alt, shift, control, caps);
341 }
342
277 View* GetFocusedView() { 343 View* GetFocusedView() {
278 return widget_->GetFocusManager()->GetFocusedView(); 344 return widget_->GetFocusManager()->GetFocusedView();
279 } 345 }
280 346
281 int GetCursorPositionX(int cursor_pos) { 347 int GetCursorPositionX(int cursor_pos) {
282 return test_api_->GetRenderText()->GetCursorBounds( 348 return test_api_->GetRenderText()->GetCursorBounds(
283 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); 349 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x();
284 } 350 }
285 351
286 // Get the current cursor bounds. 352 // Get the current cursor bounds.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 416
351 // Indicates how many times OnBeforeUserAction() is called. 417 // Indicates how many times OnBeforeUserAction() is called.
352 int on_before_user_action_; 418 int on_before_user_action_;
353 419
354 // Indicates how many times OnAfterUserAction() is called. 420 // Indicates how many times OnAfterUserAction() is called.
355 int on_after_user_action_; 421 int on_after_user_action_;
356 422
357 private: 423 private:
358 ui::ClipboardType copied_to_clipboard_; 424 ui::ClipboardType copied_to_clipboard_;
359 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_; 425 scoped_ptr<test::WidgetTest::FakeActivation> fake_activation_;
426 scoped_ptr<ui::test::EventGenerator> event_generator_;
360 427
361 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); 428 DISALLOW_COPY_AND_ASSIGN(TextfieldTest);
362 }; 429 };
363 430
364 TEST_F(TextfieldTest, ModelChangesTest) { 431 TEST_F(TextfieldTest, ModelChangesTest) {
365 InitTextfield(); 432 InitTextfield();
366 433
367 // TextfieldController::ContentsChanged() shouldn't be called when changing 434 // TextfieldController::ContentsChanged() shouldn't be called when changing
368 // text programmatically. 435 // text programmatically.
369 last_contents_.clear(); 436 last_contents_.clear();
(...skipping 25 matching lines...) Expand all
395 SendKeyEvent(ui::VKEY_1, false, false, false, false); 462 SendKeyEvent(ui::VKEY_1, false, false, false, false);
396 SendKeyEvent(ui::VKEY_1, false, true, false, true); 463 SendKeyEvent(ui::VKEY_1, false, true, false, true);
397 SendKeyEvent(ui::VKEY_1, false, false, false, true); 464 SendKeyEvent(ui::VKEY_1, false, false, false, true);
398 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); 465 EXPECT_STR_EQ("TexT!1!1", textfield_->text());
399 } 466 }
400 467
401 TEST_F(TextfieldTest, ControlAndSelectTest) { 468 TEST_F(TextfieldTest, ControlAndSelectTest) {
402 // Insert a test string in a textfield. 469 // Insert a test string in a textfield.
403 InitTextfield(); 470 InitTextfield();
404 textfield_->SetText(ASCIIToUTF16("one two three")); 471 textfield_->SetText(ASCIIToUTF16("one two three"));
405 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); 472 SendHomeEvent(false);
406 SendKeyEvent(ui::VKEY_RIGHT, true, false); 473 SendKeyEvent(ui::VKEY_RIGHT, true, false);
407 SendKeyEvent(ui::VKEY_RIGHT, true, false); 474 SendKeyEvent(ui::VKEY_RIGHT, true, false);
408 SendKeyEvent(ui::VKEY_RIGHT, true, false); 475 SendKeyEvent(ui::VKEY_RIGHT, true, false);
409 476
410 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); 477 EXPECT_STR_EQ("one", textfield_->GetSelectedText());
411 478
412 // Test word select. 479 // Test word select.
413 SendKeyEvent(ui::VKEY_RIGHT, true, true); 480 SendWordEvent(ui::VKEY_RIGHT, true);
414 EXPECT_STR_EQ("one two", textfield_->GetSelectedText()); 481 EXPECT_STR_EQ("one two", textfield_->GetSelectedText());
415 SendKeyEvent(ui::VKEY_RIGHT, true, true); 482 SendWordEvent(ui::VKEY_RIGHT, true);
416 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText()); 483 EXPECT_STR_EQ("one two three", textfield_->GetSelectedText());
417 SendKeyEvent(ui::VKEY_LEFT, true, true); 484 SendWordEvent(ui::VKEY_LEFT, true);
418 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText()); 485 EXPECT_STR_EQ("one two ", textfield_->GetSelectedText());
419 SendKeyEvent(ui::VKEY_LEFT, true, true); 486 SendWordEvent(ui::VKEY_LEFT, true);
420 EXPECT_STR_EQ("one ", textfield_->GetSelectedText()); 487 EXPECT_STR_EQ("one ", textfield_->GetSelectedText());
421 488
422 // Replace the selected text. 489 // Replace the selected text.
423 SendKeyEvent(ui::VKEY_Z, true, false); 490 SendKeyEvent(ui::VKEY_Z, true, false);
424 SendKeyEvent(ui::VKEY_E, true, false); 491 SendKeyEvent(ui::VKEY_E, true, false);
425 SendKeyEvent(ui::VKEY_R, true, false); 492 SendKeyEvent(ui::VKEY_R, true, false);
426 SendKeyEvent(ui::VKEY_O, true, false); 493 SendKeyEvent(ui::VKEY_O, true, false);
427 SendKeyEvent(ui::VKEY_SPACE, false, false); 494 SendKeyEvent(ui::VKEY_SPACE, false, false);
428 EXPECT_STR_EQ("ZERO two three", textfield_->text()); 495 EXPECT_STR_EQ("ZERO two three", textfield_->text());
429 496
430 SendKeyEvent(ui::VKEY_END, true, false); 497 SendEndEvent(true);
431 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); 498 EXPECT_STR_EQ("two three", textfield_->GetSelectedText());
432 SendKeyEvent(ui::VKEY_HOME, true, false); 499 SendHomeEvent(true);
433 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); 500 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText());
434 } 501 }
435 502
436 TEST_F(TextfieldTest, InsertionDeletionTest) { 503 TEST_F(TextfieldTest, InsertionDeletionTest) {
437 // Insert a test string in a textfield. 504 // Insert a test string in a textfield.
438 InitTextfield(); 505 InitTextfield();
439 for (size_t i = 0; i < 10; i++) 506 for (size_t i = 0; i < 10; i++)
440 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); 507 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i));
441 EXPECT_STR_EQ("abcdefghij", textfield_->text()); 508 EXPECT_STR_EQ("abcdefghij", textfield_->text());
442 509
443 // Test the delete and backspace keys. 510 // Test the delete and backspace keys.
444 textfield_->SelectRange(gfx::Range(5)); 511 textfield_->SelectRange(gfx::Range(5));
445 for (int i = 0; i < 3; i++) 512 for (int i = 0; i < 3; i++)
446 SendKeyEvent(ui::VKEY_BACK); 513 SendKeyEvent(ui::VKEY_BACK);
447 EXPECT_STR_EQ("abfghij", textfield_->text()); 514 EXPECT_STR_EQ("abfghij", textfield_->text());
448 for (int i = 0; i < 3; i++) 515 for (int i = 0; i < 3; i++)
449 SendKeyEvent(ui::VKEY_DELETE); 516 SendKeyEvent(ui::VKEY_DELETE);
450 EXPECT_STR_EQ("abij", textfield_->text()); 517 EXPECT_STR_EQ("abij", textfield_->text());
451 518
452 // Select all and replace with "k". 519 // Select all and replace with "k".
453 textfield_->SelectAll(false); 520 textfield_->SelectAll(false);
454 SendKeyEvent(ui::VKEY_K); 521 SendKeyEvent(ui::VKEY_K);
455 EXPECT_STR_EQ("k", textfield_->text()); 522 EXPECT_STR_EQ("k", textfield_->text());
456 523
457 // Delete the previous word from cursor. 524 // Delete the previous word from cursor.
525 bool shift = false;
458 textfield_->SetText(ASCIIToUTF16("one two three four")); 526 textfield_->SetText(ASCIIToUTF16("one two three four"));
459 SendKeyEvent(ui::VKEY_END); 527 SendEndEvent(shift);
460 SendKeyEvent(ui::VKEY_BACK, false, false, true, false); 528 SendWordEvent(ui::VKEY_BACK, shift);
461 EXPECT_STR_EQ("one two three ", textfield_->text()); 529 EXPECT_STR_EQ("one two three ", textfield_->text());
462 530
463 // Delete to a line break on Linux and ChromeOS, to a word break on Windows. 531 // Delete to a line break on Linux and ChromeOS, to a word break on Windows
464 SendKeyEvent(ui::VKEY_LEFT, false, false, true, false); 532 // and Mac.
465 SendKeyEvent(ui::VKEY_BACK, false, true, true, false); 533 SendWordEvent(ui::VKEY_LEFT, shift);
534 shift = true;
535 SendWordEvent(ui::VKEY_BACK, shift);
466 #if defined(OS_LINUX) 536 #if defined(OS_LINUX)
467 EXPECT_STR_EQ("three ", textfield_->text()); 537 EXPECT_STR_EQ("three ", textfield_->text());
468 #else 538 #else
469 EXPECT_STR_EQ("one three ", textfield_->text()); 539 EXPECT_STR_EQ("one three ", textfield_->text());
470 #endif 540 #endif
471 541
472 // Delete the next word from cursor. 542 // Delete the next word from cursor.
473 textfield_->SetText(ASCIIToUTF16("one two three four")); 543 textfield_->SetText(ASCIIToUTF16("one two three four"));
474 SendKeyEvent(ui::VKEY_HOME); 544 shift = false;
475 SendKeyEvent(ui::VKEY_DELETE, false, false, true, false); 545 SendHomeEvent(shift);
546 SendWordEvent(ui::VKEY_DELETE, shift);
476 EXPECT_STR_EQ(" two three four", textfield_->text()); 547 EXPECT_STR_EQ(" two three four", textfield_->text());
477 548
478 // Delete to a line break on Linux and ChromeOS, to a word break on Windows. 549 // Delete to a line break on Linux and ChromeOS, to a word break on Windows
479 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); 550 // and Mac.
480 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); 551 SendWordEvent(ui::VKEY_RIGHT, shift);
552 shift = true;
553 SendWordEvent(ui::VKEY_DELETE, shift);
481 #if defined(OS_LINUX) 554 #if defined(OS_LINUX)
482 EXPECT_STR_EQ(" two", textfield_->text()); 555 EXPECT_STR_EQ(" two", textfield_->text());
483 #else 556 #else
484 EXPECT_STR_EQ(" two four", textfield_->text()); 557 EXPECT_STR_EQ(" two four", textfield_->text());
485 #endif 558 #endif
486 } 559 }
487 560
488 TEST_F(TextfieldTest, PasswordTest) { 561 TEST_F(TextfieldTest, PasswordTest) {
489 InitTextfield(); 562 InitTextfield();
490 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 563 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 x = GetCursorBounds().x(); 1498 x = GetCursorBounds().x();
1426 EXPECT_GE(1, std::abs(x - prev_x)); 1499 EXPECT_GE(1, std::abs(x - prev_x));
1427 1500
1428 SendKeyEvent(0x05E2); 1501 SendKeyEvent(0x05E2);
1429 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); 1502 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text());
1430 x = GetCursorBounds().x(); 1503 x = GetCursorBounds().x();
1431 EXPECT_GE(1, std::abs(x - prev_x)); 1504 EXPECT_GE(1, std::abs(x - prev_x));
1432 1505
1433 // Clear text. 1506 // Clear text.
1434 SendKeyEvent(ui::VKEY_A, false, true); 1507 SendKeyEvent(ui::VKEY_A, false, true);
1435 SendKeyEvent('\n'); 1508 SendKeyEvent(ui::VKEY_DELETE);
1436 1509
1437 // RTL-LTR string in LTR context. 1510 // RTL-LTR string in LTR context.
1438 SendKeyEvent(0x05E1); 1511 SendKeyEvent(0x05E1);
1439 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); 1512 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text());
1440 x = GetCursorBounds().x(); 1513 x = GetCursorBounds().x();
1441 EXPECT_EQ(GetDisplayRect().x(), x); 1514 EXPECT_EQ(GetDisplayRect().x(), x);
1442 prev_x = x; 1515 prev_x = x;
1443 1516
1444 SendKeyEvent(0x05E2); 1517 SendKeyEvent(0x05E2);
1445 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); 1518 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text()); 1552 EXPECT_EQ(WideToUTF16(L"ab\x05E1"), textfield_->text());
1480 x = GetCursorBounds().x(); 1553 x = GetCursorBounds().x();
1481 EXPECT_GT(prev_x, x); 1554 EXPECT_GT(prev_x, x);
1482 prev_x = x; 1555 prev_x = x;
1483 1556
1484 SendKeyEvent(0x05E2); 1557 SendKeyEvent(0x05E2);
1485 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text()); 1558 EXPECT_EQ(WideToUTF16(L"ab\x05E1\x5E2"), textfield_->text());
1486 x = GetCursorBounds().x(); 1559 x = GetCursorBounds().x();
1487 EXPECT_GT(prev_x, x); 1560 EXPECT_GT(prev_x, x);
1488 1561
1562 // Clear text.
1489 SendKeyEvent(ui::VKEY_A, false, true); 1563 SendKeyEvent(ui::VKEY_A, false, true);
1490 SendKeyEvent('\n'); 1564 SendKeyEvent(ui::VKEY_DELETE);
1491 1565
1492 // RTL-LTR string in RTL context. 1566 // RTL-LTR string in RTL context.
1493 SendKeyEvent(0x05E1); 1567 SendKeyEvent(0x05E1);
1494 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text()); 1568 EXPECT_EQ(WideToUTF16(L"\x05E1"), textfield_->text());
1495 x = GetCursorBounds().x(); 1569 x = GetCursorBounds().x();
1496 prev_x = x; 1570 prev_x = x;
1497 1571
1498 SendKeyEvent(0x05E2); 1572 SendKeyEvent(0x05E2);
1499 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text()); 1573 EXPECT_EQ(WideToUTF16(L"\x05E1\x05E2"), textfield_->text());
1500 x = GetCursorBounds().x(); 1574 x = GetCursorBounds().x();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 SendKeyEvent('a'); 1721 SendKeyEvent('a');
1648 SendKeyEvent(kHebrewLetterSamekh); 1722 SendKeyEvent(kHebrewLetterSamekh);
1649 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1723 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1650 1724
1651 // Test mouse pointing. 1725 // Test mouse pointing.
1652 MouseClick(GetCursorBounds(), -1); 1726 MouseClick(GetCursorBounds(), -1);
1653 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1727 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1654 1728
1655 // Clear text. 1729 // Clear text.
1656 SendKeyEvent(ui::VKEY_A, false, true); 1730 SendKeyEvent(ui::VKEY_A, false, true);
1657 SendKeyEvent('\n'); 1731 SendKeyEvent(ui::VKEY_DELETE);
1658 1732
1659 for (int i = 0; i < 500; ++i) 1733 for (int i = 0; i < 500; ++i)
1660 SendKeyEvent(kHebrewLetterSamekh); 1734 SendKeyEvent(kHebrewLetterSamekh);
1661 SendKeyEvent('a'); 1735 SendKeyEvent('a');
1662 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1736 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1663 1737
1664 MouseClick(GetCursorBounds(), -1); 1738 MouseClick(GetCursorBounds(), -1);
1665 EXPECT_EQ(501U, textfield_->GetCursorPosition()); 1739 EXPECT_EQ(501U, textfield_->GetCursorPosition());
1666 } 1740 }
1667 1741
1668 TEST_F(TextfieldTest, OverflowInRTLTest) { 1742 TEST_F(TextfieldTest, OverflowInRTLTest) {
1669 std::string locale = l10n_util::GetApplicationLocale(""); 1743 std::string locale = l10n_util::GetApplicationLocale("");
1670 base::i18n::SetICUDefaultLocale("he"); 1744 base::i18n::SetICUDefaultLocale("he");
1671 1745
1672 InitTextfield(); 1746 InitTextfield();
1673 1747
1674 base::string16 str; 1748 base::string16 str;
1675 for (int i = 0; i < 500; ++i) 1749 for (int i = 0; i < 500; ++i)
1676 SendKeyEvent('a'); 1750 SendKeyEvent('a');
1677 SendKeyEvent(kHebrewLetterSamekh); 1751 SendKeyEvent(kHebrewLetterSamekh);
1678 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1752 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1679 1753
1680 MouseClick(GetCursorBounds(), 1); 1754 MouseClick(GetCursorBounds(), 1);
1681 EXPECT_EQ(501U, textfield_->GetCursorPosition()); 1755 EXPECT_EQ(501U, textfield_->GetCursorPosition());
1682 1756
1683 // Clear text. 1757 // Clear text.
1684 SendKeyEvent(ui::VKEY_A, false, true); 1758 SendKeyEvent(ui::VKEY_A, false, true);
1685 SendKeyEvent('\n'); 1759 SendKeyEvent(ui::VKEY_DELETE);
1686 1760
1687 for (int i = 0; i < 500; ++i) 1761 for (int i = 0; i < 500; ++i)
1688 SendKeyEvent(kHebrewLetterSamekh); 1762 SendKeyEvent(kHebrewLetterSamekh);
1689 SendKeyEvent('a'); 1763 SendKeyEvent('a');
1690 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1764 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1691 1765
1692 MouseClick(GetCursorBounds(), 1); 1766 MouseClick(GetCursorBounds(), 1);
1693 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1767 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1694 1768
1695 // Reset locale. 1769 // Reset locale.
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 2183
2110 // Tap again on selection and check if touch selection handles are still 2184 // Tap again on selection and check if touch selection handles are still
2111 // present and selection is changed to a cursor at tap location. 2185 // present and selection is changed to a cursor at tap location.
2112 Tap(tap_point); 2186 Tap(tap_point);
2113 textfield_->GetSelectionRange(&range); 2187 textfield_->GetSelectionRange(&range);
2114 EXPECT_TRUE(test_api_->touch_selection_controller()); 2188 EXPECT_TRUE(test_api_->touch_selection_controller());
2115 EXPECT_EQ(tap_range, range); 2189 EXPECT_EQ(tap_range, range);
2116 } 2190 }
2117 2191
2118 } // namespace views 2192 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.mm ('k') | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698