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

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

Issue 117983002: Prefix string16 with base:: in ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/native_textfield_views.h" 5 #include "ui/views/controls/textfield/native_textfield_views.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 bool key_received_; 80 bool key_received_;
81 81
82 DISALLOW_COPY_AND_ASSIGN(TestTextfield); 82 DISALLOW_COPY_AND_ASSIGN(TestTextfield);
83 }; 83 };
84 84
85 // A helper class for use with ui::TextInputClient::GetTextFromRange(). 85 // A helper class for use with ui::TextInputClient::GetTextFromRange().
86 class GetTextHelper { 86 class GetTextHelper {
87 public: 87 public:
88 GetTextHelper() {} 88 GetTextHelper() {}
89 89
90 void set_text(const string16& text) { text_ = text; } 90 void set_text(const base::string16& text) { text_ = text; }
91 const string16& text() const { return text_; } 91 const base::string16& text() const { return text_; }
92 92
93 private: 93 private:
94 string16 text_; 94 base::string16 text_;
95 95
96 DISALLOW_COPY_AND_ASSIGN(GetTextHelper); 96 DISALLOW_COPY_AND_ASSIGN(GetTextHelper);
97 }; 97 };
98 98
99 // Convenience to make constructing a GestureEvent simpler. 99 // Convenience to make constructing a GestureEvent simpler.
100 class GestureEventForTest : public ui::GestureEvent { 100 class GestureEventForTest : public ui::GestureEvent {
101 public: 101 public:
102 GestureEventForTest(ui::EventType type, int x, int y, float delta_x, 102 GestureEventForTest(ui::EventType type, int x, int y, float delta_x,
103 float delta_y) 103 float delta_y)
104 : GestureEvent(type, x, y, 0, base::TimeDelta(), 104 : GestureEvent(type, x, y, 0, base::TimeDelta(),
(...skipping 30 matching lines...) Expand all
135 } 135 }
136 136
137 virtual void TearDown() { 137 virtual void TearDown() {
138 if (widget_) 138 if (widget_)
139 widget_->Close(); 139 widget_->Close();
140 ViewsTestBase::TearDown(); 140 ViewsTestBase::TearDown();
141 } 141 }
142 142
143 // TextfieldController: 143 // TextfieldController:
144 virtual void ContentsChanged(Textfield* sender, 144 virtual void ContentsChanged(Textfield* sender,
145 const string16& new_contents) OVERRIDE { 145 const base::string16& new_contents) OVERRIDE {
146 // Paste calls TextfieldController::ContentsChanged() explicitly even if the 146 // Paste calls TextfieldController::ContentsChanged() explicitly even if the
147 // paste action did not change the content. So |new_contents| may match 147 // paste action did not change the content. So |new_contents| may match
148 // |last_contents_|. For more info, see http://crbug.com/79002 148 // |last_contents_|. For more info, see http://crbug.com/79002
149 last_contents_ = new_contents; 149 last_contents_ = new_contents;
150 } 150 }
151 151
152 virtual bool HandleKeyEvent(Textfield* sender, 152 virtual bool HandleKeyEvent(Textfield* sender,
153 const ui::KeyEvent& key_event) OVERRIDE { 153 const ui::KeyEvent& key_event) OVERRIDE {
154 // TODO(oshima): figure out how to test the keystroke. 154 // TODO(oshima): figure out how to test the keystroke.
155 return false; 155 return false;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 ch == ' ' ? ui::VKEY_SPACE : 239 ch == ' ' ? ui::VKEY_SPACE :
240 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a'); 240 static_cast<ui::KeyboardCode>(ui::VKEY_A + ch - 'a');
241 SendKeyEvent(code); 241 SendKeyEvent(code);
242 } else { 242 } else {
243 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); 243 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false);
244 event.set_character(ch); 244 event.set_character(ch);
245 input_method_->DispatchKeyEvent(event); 245 input_method_->DispatchKeyEvent(event);
246 } 246 }
247 } 247 }
248 248
249 string16 GetClipboardText() const { 249 base::string16 GetClipboardText() const {
250 string16 text; 250 base::string16 text;
251 ui::Clipboard::GetForCurrentThread()-> 251 ui::Clipboard::GetForCurrentThread()->
252 ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &text); 252 ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &text);
253 return text; 253 return text;
254 } 254 }
255 255
256 void SetClipboardText(const std::string& text) { 256 void SetClipboardText(const std::string& text) {
257 ui::ScopedClipboardWriter clipboard_writer( 257 ui::ScopedClipboardWriter clipboard_writer(
258 ui::Clipboard::GetForCurrentThread(), 258 ui::Clipboard::GetForCurrentThread(),
259 ui::CLIPBOARD_TYPE_COPY_PASTE); 259 ui::CLIPBOARD_TYPE_COPY_PASTE);
260 clipboard_writer.WriteText(ASCIIToUTF16(text)); 260 clipboard_writer.WriteText(ASCIIToUTF16(text));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 331 }
332 332
333 // We need widget to populate wrapper class. 333 // We need widget to populate wrapper class.
334 Widget* widget_; 334 Widget* widget_;
335 335
336 TestTextfield* textfield_; 336 TestTextfield* textfield_;
337 NativeTextfieldViews* textfield_view_; 337 NativeTextfieldViews* textfield_view_;
338 TextfieldViewsModel* model_; 338 TextfieldViewsModel* model_;
339 339
340 // The string from Controller::ContentsChanged callback. 340 // The string from Controller::ContentsChanged callback.
341 string16 last_contents_; 341 base::string16 last_contents_;
342 342
343 // For testing input method related behaviors. 343 // For testing input method related behaviors.
344 MockInputMethod* input_method_; 344 MockInputMethod* input_method_;
345 345
346 // Indicates how many times OnBeforeUserAction() is called. 346 // Indicates how many times OnBeforeUserAction() is called.
347 int on_before_user_action_; 347 int on_before_user_action_;
348 348
349 // Indicates how many times OnAfterUserAction() is called. 349 // Indicates how many times OnAfterUserAction() is called.
350 int on_after_user_action_; 350 int on_after_user_action_;
351 351
(...skipping 11 matching lines...) Expand all
363 363
364 EXPECT_STR_EQ("this is", model_->GetText()); 364 EXPECT_STR_EQ("this is", model_->GetText());
365 EXPECT_STR_EQ("this is", textfield_->text()); 365 EXPECT_STR_EQ("this is", textfield_->text());
366 EXPECT_TRUE(last_contents_.empty()); 366 EXPECT_TRUE(last_contents_.empty());
367 367
368 textfield_->AppendText(ASCIIToUTF16(" a test")); 368 textfield_->AppendText(ASCIIToUTF16(" a test"));
369 EXPECT_STR_EQ("this is a test", model_->GetText()); 369 EXPECT_STR_EQ("this is a test", model_->GetText());
370 EXPECT_STR_EQ("this is a test", textfield_->text()); 370 EXPECT_STR_EQ("this is a test", textfield_->text());
371 EXPECT_TRUE(last_contents_.empty()); 371 EXPECT_TRUE(last_contents_.empty());
372 372
373 EXPECT_EQ(string16(), textfield_->GetSelectedText()); 373 EXPECT_EQ(base::string16(), textfield_->GetSelectedText());
374 textfield_->SelectAll(false); 374 textfield_->SelectAll(false);
375 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); 375 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText());
376 EXPECT_TRUE(last_contents_.empty()); 376 EXPECT_TRUE(last_contents_.empty());
377 } 377 }
378 378
379 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) { 379 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) {
380 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. 380 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE.
381 InitTextfield(Textfield::STYLE_LOWERCASE); 381 InitTextfield(Textfield::STYLE_LOWERCASE);
382 EXPECT_EQ(0U, textfield_->GetCursorPosition()); 382 EXPECT_EQ(0U, textfield_->GetCursorPosition());
383 383
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 SetClipboardText("foo"); 570 SetClipboardText("foo");
571 571
572 // Cut and copy should be disabled. 572 // Cut and copy should be disabled.
573 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); 573 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT));
574 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); 574 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0);
575 SendKeyEvent(ui::VKEY_X, false, true); 575 SendKeyEvent(ui::VKEY_X, false, true);
576 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); 576 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY));
577 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); 577 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0);
578 SendKeyEvent(ui::VKEY_C, false, true); 578 SendKeyEvent(ui::VKEY_C, false, true);
579 SendKeyEvent(ui::VKEY_INSERT, false, true); 579 SendKeyEvent(ui::VKEY_INSERT, false, true);
580 EXPECT_STR_EQ("foo", string16(GetClipboardText())); 580 EXPECT_STR_EQ("foo", base::string16(GetClipboardText()));
581 EXPECT_STR_EQ("password", textfield_->text()); 581 EXPECT_STR_EQ("password", textfield_->text());
582 // [Shift]+[Delete] should just delete without copying text to the clipboard. 582 // [Shift]+[Delete] should just delete without copying text to the clipboard.
583 textfield_->SelectAll(false); 583 textfield_->SelectAll(false);
584 SendKeyEvent(ui::VKEY_DELETE, true, false); 584 SendKeyEvent(ui::VKEY_DELETE, true, false);
585 585
586 // Paste should work normally. 586 // Paste should work normally.
587 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); 587 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE));
588 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); 588 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0);
589 SendKeyEvent(ui::VKEY_V, false, true); 589 SendKeyEvent(ui::VKEY_V, false, true);
590 SendKeyEvent(ui::VKEY_INSERT, true, false); 590 SendKeyEvent(ui::VKEY_INSERT, true, false);
591 EXPECT_STR_EQ("foo", string16(GetClipboardText())); 591 EXPECT_STR_EQ("foo", base::string16(GetClipboardText()));
592 EXPECT_STR_EQ("foofoofoo", textfield_->text()); 592 EXPECT_STR_EQ("foofoofoo", textfield_->text());
593 } 593 }
594 594
595 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { 595 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) {
596 InitTextfield(Textfield::STYLE_DEFAULT); 596 InitTextfield(Textfield::STYLE_DEFAULT);
597 597
598 // Defaults to TEXT 598 // Defaults to TEXT
599 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); 599 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType());
600 600
601 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. 601 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 EXPECT_TRUE(textfield_->key_received()); 664 EXPECT_TRUE(textfield_->key_received());
665 EXPECT_FALSE(textfield_->key_handled()); 665 EXPECT_FALSE(textfield_->key_handled());
666 textfield_->clear(); 666 textfield_->clear();
667 667
668 SendKeyEvent(ui::VKEY_DOWN); 668 SendKeyEvent(ui::VKEY_DOWN);
669 EXPECT_TRUE(textfield_->key_received()); 669 EXPECT_TRUE(textfield_->key_received());
670 EXPECT_FALSE(textfield_->key_handled()); 670 EXPECT_FALSE(textfield_->key_handled());
671 textfield_->clear(); 671 textfield_->clear();
672 672
673 // Empty Textfield does not handle left/right. 673 // Empty Textfield does not handle left/right.
674 textfield_->SetText(string16()); 674 textfield_->SetText(base::string16());
675 SendKeyEvent(ui::VKEY_LEFT); 675 SendKeyEvent(ui::VKEY_LEFT);
676 EXPECT_TRUE(textfield_->key_received()); 676 EXPECT_TRUE(textfield_->key_received());
677 EXPECT_FALSE(textfield_->key_handled()); 677 EXPECT_FALSE(textfield_->key_handled());
678 textfield_->clear(); 678 textfield_->clear();
679 679
680 SendKeyEvent(ui::VKEY_RIGHT); 680 SendKeyEvent(ui::VKEY_RIGHT);
681 EXPECT_TRUE(textfield_->key_received()); 681 EXPECT_TRUE(textfield_->key_received());
682 EXPECT_FALSE(textfield_->key_handled()); 682 EXPECT_FALSE(textfield_->key_handled());
683 textfield_->clear(); 683 textfield_->clear();
684 684
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), 856 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(),
857 ui::EF_LEFT_MOUSE_BUTTON, 0); 857 ui::EF_LEFT_MOUSE_BUTTON, 0);
858 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, 858 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point,
859 ui::EF_LEFT_MOUSE_BUTTON, 0); 859 ui::EF_LEFT_MOUSE_BUTTON, 0);
860 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, 860 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point,
861 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 861 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
862 textfield_view_->OnMousePressed(click_a); 862 textfield_view_->OnMousePressed(click_a);
863 EXPECT_TRUE(textfield_->GetSelectedText().empty()); 863 EXPECT_TRUE(textfield_->GetSelectedText().empty());
864 // Check that dragging left selects the beginning of the string. 864 // Check that dragging left selects the beginning of the string.
865 textfield_view_->OnMouseDragged(drag_left); 865 textfield_view_->OnMouseDragged(drag_left);
866 string16 text_left = textfield_->GetSelectedText(); 866 base::string16 text_left = textfield_->GetSelectedText();
867 EXPECT_STR_EQ("hello", text_left); 867 EXPECT_STR_EQ("hello", text_left);
868 // Check that dragging right selects the rest of the string. 868 // Check that dragging right selects the rest of the string.
869 textfield_view_->OnMouseDragged(drag_right); 869 textfield_view_->OnMouseDragged(drag_right);
870 string16 text_right = textfield_->GetSelectedText(); 870 base::string16 text_right = textfield_->GetSelectedText();
871 EXPECT_STR_EQ(" world", text_right); 871 EXPECT_STR_EQ(" world", text_right);
872 // Check that releasing in the same location does not alter the selection. 872 // Check that releasing in the same location does not alter the selection.
873 textfield_view_->OnMouseReleased(release); 873 textfield_view_->OnMouseReleased(release);
874 EXPECT_EQ(text_right, textfield_->GetSelectedText()); 874 EXPECT_EQ(text_right, textfield_->GetSelectedText());
875 // Check that dragging from beyond the text length works too. 875 // Check that dragging from beyond the text length works too.
876 textfield_view_->OnMousePressed(click_b); 876 textfield_view_->OnMousePressed(click_b);
877 textfield_view_->OnMouseDragged(drag_left); 877 textfield_view_->OnMouseDragged(drag_left);
878 textfield_view_->OnMouseReleased(release); 878 textfield_view_->OnMouseReleased(release);
879 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); 879 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText());
880 } 880 }
881 881
882 #if defined(OS_WIN) 882 #if defined(OS_WIN)
883 TEST_F(NativeTextfieldViewsTest, DragAndDrop_AcceptDrop) { 883 TEST_F(NativeTextfieldViewsTest, DragAndDrop_AcceptDrop) {
884 InitTextfield(Textfield::STYLE_DEFAULT); 884 InitTextfield(Textfield::STYLE_DEFAULT);
885 textfield_->SetText(ASCIIToUTF16("hello world")); 885 textfield_->SetText(ASCIIToUTF16("hello world"));
886 886
887 ui::OSExchangeData data; 887 ui::OSExchangeData data;
888 string16 string(ASCIIToUTF16("string ")); 888 base::string16 string(ASCIIToUTF16("string "));
889 data.SetString(string); 889 data.SetString(string);
890 int formats = 0; 890 int formats = 0;
891 std::set<OSExchangeData::CustomFormat> custom_formats; 891 std::set<OSExchangeData::CustomFormat> custom_formats;
892 892
893 // Ensure that disabled textfields do not accept drops. 893 // Ensure that disabled textfields do not accept drops.
894 textfield_->SetEnabled(false); 894 textfield_->SetEnabled(false);
895 EXPECT_FALSE(textfield_view_->GetDropFormats(&formats, &custom_formats)); 895 EXPECT_FALSE(textfield_view_->GetDropFormats(&formats, &custom_formats));
896 EXPECT_EQ(0, formats); 896 EXPECT_EQ(0, formats);
897 EXPECT_TRUE(custom_formats.empty()); 897 EXPECT_TRUE(custom_formats.empty());
898 EXPECT_FALSE(textfield_view_->CanDrop(data)); 898 EXPECT_FALSE(textfield_view_->CanDrop(data));
(...skipping 20 matching lines...) Expand all
919 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_view_->OnPerformDrop(drop)); 919 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_view_->OnPerformDrop(drop));
920 EXPECT_STR_EQ("hello string world", textfield_->text()); 920 EXPECT_STR_EQ("hello string world", textfield_->text());
921 921
922 // Ensure that textfields do not accept non-OSExchangeData::STRING types. 922 // Ensure that textfields do not accept non-OSExchangeData::STRING types.
923 ui::OSExchangeData bad_data; 923 ui::OSExchangeData bad_data;
924 bad_data.SetFilename(base::FilePath(FILE_PATH_LITERAL("x"))); 924 bad_data.SetFilename(base::FilePath(FILE_PATH_LITERAL("x")));
925 #if defined(OS_WIN) 925 #if defined(OS_WIN)
926 ui::OSExchangeData::CustomFormat fmt = ui::Clipboard::GetBitmapFormatType(); 926 ui::OSExchangeData::CustomFormat fmt = ui::Clipboard::GetBitmapFormatType();
927 bad_data.SetPickledData(fmt, Pickle()); 927 bad_data.SetPickledData(fmt, Pickle());
928 bad_data.SetFileContents(base::FilePath(L"x"), "x"); 928 bad_data.SetFileContents(base::FilePath(L"x"), "x");
929 bad_data.SetHtml(string16(ASCIIToUTF16("x")), GURL("x.org")); 929 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org"));
930 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); 930 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL);
931 bad_data.SetDownloadFileInfo(download); 931 bad_data.SetDownloadFileInfo(download);
932 #endif 932 #endif
933 EXPECT_FALSE(textfield_view_->CanDrop(bad_data)); 933 EXPECT_FALSE(textfield_view_->CanDrop(bad_data));
934 } 934 }
935 #endif 935 #endif
936 936
937 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { 937 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) {
938 InitTextfield(Textfield::STYLE_DEFAULT); 938 InitTextfield(Textfield::STYLE_DEFAULT);
939 textfield_->SetText(ASCIIToUTF16("hello string world")); 939 textfield_->SetText(ASCIIToUTF16("hello string world"));
940 940
941 // Ensure the textfield will provide selected text for drag data. 941 // Ensure the textfield will provide selected text for drag data.
942 string16 string; 942 base::string16 string;
943 ui::OSExchangeData data; 943 ui::OSExchangeData data;
944 const gfx::Range kStringRange(6, 12); 944 const gfx::Range kStringRange(6, 12);
945 textfield_->SelectRange(kStringRange); 945 textfield_->SelectRange(kStringRange);
946 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 946 const gfx::Point kStringPoint(GetCursorPositionX(9), 0);
947 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); 947 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data);
948 EXPECT_TRUE(data.GetString(&string)); 948 EXPECT_TRUE(data.GetString(&string));
949 EXPECT_EQ(textfield_->GetSelectedText(), string); 949 EXPECT_EQ(textfield_->GetSelectedText(), string);
950 950
951 // Ensure that disabled textfields do not support drag operations. 951 // Ensure that disabled textfields do not support drag operations.
952 textfield_->SetEnabled(false); 952 textfield_->SetEnabled(false);
(...skipping 25 matching lines...) Expand all
978 gfx::Point())); 978 gfx::Point()));
979 // Ensure that textfields support local moves. 979 // Ensure that textfields support local moves.
980 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 980 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
981 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint)); 981 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint));
982 } 982 }
983 983
984 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) { 984 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) {
985 InitTextfield(Textfield::STYLE_DEFAULT); 985 InitTextfield(Textfield::STYLE_DEFAULT);
986 textfield_->SetText(ASCIIToUTF16("hello world")); 986 textfield_->SetText(ASCIIToUTF16("hello world"));
987 987
988 string16 string; 988 base::string16 string;
989 ui::OSExchangeData data; 989 ui::OSExchangeData data;
990 int formats = 0; 990 int formats = 0;
991 int operations = 0; 991 int operations = 0;
992 std::set<OSExchangeData::CustomFormat> custom_formats; 992 std::set<OSExchangeData::CustomFormat> custom_formats;
993 993
994 // Start dragging "ello". 994 // Start dragging "ello".
995 textfield_->SelectRange(gfx::Range(1, 5)); 995 textfield_->SelectRange(gfx::Range(1, 5));
996 gfx::Point point(GetCursorPositionX(3), 0); 996 gfx::Point point(GetCursorPositionX(3), 0);
997 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 997 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
998 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 998 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 SendKeyEvent(ui::VKEY_Y, false, true); 1033 SendKeyEvent(ui::VKEY_Y, false, true);
1034 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1034 EXPECT_STR_EQ("h welloorld", textfield_->text());
1035 SendKeyEvent(ui::VKEY_Y, false, true); 1035 SendKeyEvent(ui::VKEY_Y, false, true);
1036 EXPECT_STR_EQ("h welloorld", textfield_->text()); 1036 EXPECT_STR_EQ("h welloorld", textfield_->text());
1037 } 1037 }
1038 1038
1039 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheLeft) { 1039 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheLeft) {
1040 InitTextfield(Textfield::STYLE_DEFAULT); 1040 InitTextfield(Textfield::STYLE_DEFAULT);
1041 textfield_->SetText(ASCIIToUTF16("hello world")); 1041 textfield_->SetText(ASCIIToUTF16("hello world"));
1042 1042
1043 string16 string; 1043 base::string16 string;
1044 ui::OSExchangeData data; 1044 ui::OSExchangeData data;
1045 int formats = 0; 1045 int formats = 0;
1046 int operations = 0; 1046 int operations = 0;
1047 std::set<OSExchangeData::CustomFormat> custom_formats; 1047 std::set<OSExchangeData::CustomFormat> custom_formats;
1048 1048
1049 // Start dragging " worl". 1049 // Start dragging " worl".
1050 textfield_->SelectRange(gfx::Range(5, 10)); 1050 textfield_->SelectRange(gfx::Range(5, 10));
1051 gfx::Point point(GetCursorPositionX(7), 0); 1051 gfx::Point point(GetCursorPositionX(7), 0);
1052 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1052 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
1053 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 1053 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); 1142 EXPECT_STR_EQ("read ", textfield_->GetSelectedText());
1143 textfield_->SelectAll(false); 1143 textfield_->SelectAll(false);
1144 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); 1144 EXPECT_STR_EQ("read only", textfield_->GetSelectedText());
1145 1145
1146 // Cut should be disabled. 1146 // Cut should be disabled.
1147 SetClipboardText("Test"); 1147 SetClipboardText("Test");
1148 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); 1148 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT));
1149 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); 1149 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0);
1150 SendKeyEvent(ui::VKEY_X, false, true); 1150 SendKeyEvent(ui::VKEY_X, false, true);
1151 SendKeyEvent(ui::VKEY_DELETE, true, false); 1151 SendKeyEvent(ui::VKEY_DELETE, true, false);
1152 EXPECT_STR_EQ("Test", string16(GetClipboardText())); 1152 EXPECT_STR_EQ("Test", base::string16(GetClipboardText()));
1153 EXPECT_STR_EQ("read only", textfield_->text()); 1153 EXPECT_STR_EQ("read only", textfield_->text());
1154 1154
1155 // Paste should be disabled. 1155 // Paste should be disabled.
1156 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); 1156 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE));
1157 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); 1157 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0);
1158 SendKeyEvent(ui::VKEY_V, false, true); 1158 SendKeyEvent(ui::VKEY_V, false, true);
1159 SendKeyEvent(ui::VKEY_INSERT, true, false); 1159 SendKeyEvent(ui::VKEY_INSERT, true, false);
1160 EXPECT_STR_EQ("read only", textfield_->text()); 1160 EXPECT_STR_EQ("read only", textfield_->text());
1161 1161
1162 // Copy should work normally. 1162 // Copy should work normally.
1163 SetClipboardText("Test"); 1163 SetClipboardText("Test");
1164 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); 1164 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY));
1165 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); 1165 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0);
1166 EXPECT_STR_EQ("read only", string16(GetClipboardText())); 1166 EXPECT_STR_EQ("read only", base::string16(GetClipboardText()));
1167 SetClipboardText("Test"); 1167 SetClipboardText("Test");
1168 SendKeyEvent(ui::VKEY_C, false, true); 1168 SendKeyEvent(ui::VKEY_C, false, true);
1169 EXPECT_STR_EQ("read only", string16(GetClipboardText())); 1169 EXPECT_STR_EQ("read only", base::string16(GetClipboardText()));
1170 SetClipboardText("Test"); 1170 SetClipboardText("Test");
1171 SendKeyEvent(ui::VKEY_INSERT, false, true); 1171 SendKeyEvent(ui::VKEY_INSERT, false, true);
1172 EXPECT_STR_EQ("read only", string16(GetClipboardText())); 1172 EXPECT_STR_EQ("read only", base::string16(GetClipboardText()));
1173 1173
1174 // SetText should work even in read only mode. 1174 // SetText should work even in read only mode.
1175 textfield_->SetText(ASCIIToUTF16(" four five six ")); 1175 textfield_->SetText(ASCIIToUTF16(" four five six "));
1176 EXPECT_STR_EQ(" four five six ", textfield_->text()); 1176 EXPECT_STR_EQ(" four five six ", textfield_->text());
1177 1177
1178 textfield_->SelectAll(false); 1178 textfield_->SelectAll(false);
1179 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1179 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1180 1180
1181 // Text field is unmodifiable and selection shouldn't change. 1181 // Text field is unmodifiable and selection shouldn't change.
1182 SendKeyEvent(ui::VKEY_DELETE); 1182 SendKeyEvent(ui::VKEY_DELETE);
(...skipping 16 matching lines...) Expand all
1199 EXPECT_EQ(0U, range.start()); 1199 EXPECT_EQ(0U, range.start());
1200 EXPECT_EQ(10U, range.end()); 1200 EXPECT_EQ(10U, range.end());
1201 1201
1202 EXPECT_TRUE(client->SetSelectionRange(gfx::Range(1, 4))); 1202 EXPECT_TRUE(client->SetSelectionRange(gfx::Range(1, 4)));
1203 EXPECT_TRUE(client->GetSelectionRange(&range)); 1203 EXPECT_TRUE(client->GetSelectionRange(&range));
1204 EXPECT_EQ(gfx::Range(1, 4), range); 1204 EXPECT_EQ(gfx::Range(1, 4), range);
1205 1205
1206 // This code can't be compiled because of a bug in base::Callback. 1206 // This code can't be compiled because of a bug in base::Callback.
1207 #if 0 1207 #if 0
1208 GetTextHelper helper; 1208 GetTextHelper helper;
1209 base::Callback<void(string16)> callback = 1209 base::Callback<void(base::string16)> callback =
1210 base::Bind(&GetTextHelper::set_text, base::Unretained(&helper)); 1210 base::Bind(&GetTextHelper::set_text, base::Unretained(&helper));
1211 1211
1212 EXPECT_TRUE(client->GetTextFromRange(range, callback)); 1212 EXPECT_TRUE(client->GetTextFromRange(range, callback));
1213 EXPECT_STR_EQ("123", helper.text()); 1213 EXPECT_STR_EQ("123", helper.text());
1214 #endif 1214 #endif
1215 1215
1216 EXPECT_TRUE(client->DeleteRange(range)); 1216 EXPECT_TRUE(client->DeleteRange(range));
1217 EXPECT_STR_EQ("0456789", textfield_->text()); 1217 EXPECT_STR_EQ("0456789", textfield_->text());
1218 1218
1219 ui::CompositionText composition; 1219 ui::CompositionText composition;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 } 1388 }
1389 1389
1390 TEST_F(NativeTextfieldViewsTest, CutCopyPaste) { 1390 TEST_F(NativeTextfieldViewsTest, CutCopyPaste) {
1391 InitTextfield(Textfield::STYLE_DEFAULT); 1391 InitTextfield(Textfield::STYLE_DEFAULT);
1392 1392
1393 // Ensure IDS_APP_CUT cuts. 1393 // Ensure IDS_APP_CUT cuts.
1394 textfield_->SetText(ASCIIToUTF16("123")); 1394 textfield_->SetText(ASCIIToUTF16("123"));
1395 textfield_->SelectAll(false); 1395 textfield_->SelectAll(false);
1396 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); 1396 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT));
1397 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); 1397 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0);
1398 EXPECT_STR_EQ("123", string16(GetClipboardText())); 1398 EXPECT_STR_EQ("123", base::string16(GetClipboardText()));
1399 EXPECT_STR_EQ("", textfield_->text()); 1399 EXPECT_STR_EQ("", textfield_->text());
1400 1400
1401 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. 1401 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing.
1402 textfield_->SetText(ASCIIToUTF16("456")); 1402 textfield_->SetText(ASCIIToUTF16("456"));
1403 textfield_->SelectAll(false); 1403 textfield_->SelectAll(false);
1404 SendKeyEvent(ui::VKEY_X, true, false, true, false); 1404 SendKeyEvent(ui::VKEY_X, true, false, true, false);
1405 EXPECT_STR_EQ("123", string16(GetClipboardText())); 1405 EXPECT_STR_EQ("123", base::string16(GetClipboardText()));
1406 EXPECT_STR_EQ("456", textfield_->text()); 1406 EXPECT_STR_EQ("456", textfield_->text());
1407 SendKeyEvent(ui::VKEY_X, false, true); 1407 SendKeyEvent(ui::VKEY_X, false, true);
1408 EXPECT_STR_EQ("456", string16(GetClipboardText())); 1408 EXPECT_STR_EQ("456", base::string16(GetClipboardText()));
1409 EXPECT_STR_EQ("", textfield_->text()); 1409 EXPECT_STR_EQ("", textfield_->text());
1410 1410
1411 // Ensure [Shift]+[Delete] cuts. 1411 // Ensure [Shift]+[Delete] cuts.
1412 textfield_->SetText(ASCIIToUTF16("123")); 1412 textfield_->SetText(ASCIIToUTF16("123"));
1413 textfield_->SelectAll(false); 1413 textfield_->SelectAll(false);
1414 SendKeyEvent(ui::VKEY_DELETE, true, false); 1414 SendKeyEvent(ui::VKEY_DELETE, true, false);
1415 EXPECT_STR_EQ("123", string16(GetClipboardText())); 1415 EXPECT_STR_EQ("123", base::string16(GetClipboardText()));
1416 EXPECT_STR_EQ("", textfield_->text()); 1416 EXPECT_STR_EQ("", textfield_->text());
1417 1417
1418 // Ensure IDS_APP_COPY copies. 1418 // Ensure IDS_APP_COPY copies.
1419 textfield_->SetText(ASCIIToUTF16("789")); 1419 textfield_->SetText(ASCIIToUTF16("789"));
1420 textfield_->SelectAll(false); 1420 textfield_->SelectAll(false);
1421 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); 1421 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY));
1422 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); 1422 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0);
1423 EXPECT_STR_EQ("789", string16(GetClipboardText())); 1423 EXPECT_STR_EQ("789", base::string16(GetClipboardText()));
1424 1424
1425 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. 1425 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing.
1426 textfield_->SetText(ASCIIToUTF16("012")); 1426 textfield_->SetText(ASCIIToUTF16("012"));
1427 textfield_->SelectAll(false); 1427 textfield_->SelectAll(false);
1428 SendKeyEvent(ui::VKEY_C, true, false, true, false); 1428 SendKeyEvent(ui::VKEY_C, true, false, true, false);
1429 EXPECT_STR_EQ("789", string16(GetClipboardText())); 1429 EXPECT_STR_EQ("789", base::string16(GetClipboardText()));
1430 SendKeyEvent(ui::VKEY_C, false, true); 1430 SendKeyEvent(ui::VKEY_C, false, true);
1431 EXPECT_STR_EQ("012", string16(GetClipboardText())); 1431 EXPECT_STR_EQ("012", base::string16(GetClipboardText()));
1432 1432
1433 // Ensure [Ctrl]+[Insert] copies. 1433 // Ensure [Ctrl]+[Insert] copies.
1434 textfield_->SetText(ASCIIToUTF16("345")); 1434 textfield_->SetText(ASCIIToUTF16("345"));
1435 textfield_->SelectAll(false); 1435 textfield_->SelectAll(false);
1436 SendKeyEvent(ui::VKEY_INSERT, false, true); 1436 SendKeyEvent(ui::VKEY_INSERT, false, true);
1437 EXPECT_STR_EQ("345", string16(GetClipboardText())); 1437 EXPECT_STR_EQ("345", base::string16(GetClipboardText()));
1438 EXPECT_STR_EQ("345", textfield_->text()); 1438 EXPECT_STR_EQ("345", textfield_->text());
1439 1439
1440 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; 1440 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes;
1441 // also ensure that [Ctrl]+[Alt]+[V] does nothing. 1441 // also ensure that [Ctrl]+[Alt]+[V] does nothing.
1442 SetClipboardText("abc"); 1442 SetClipboardText("abc");
1443 textfield_->SetText(string16()); 1443 textfield_->SetText(base::string16());
1444 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); 1444 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE));
1445 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); 1445 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0);
1446 EXPECT_STR_EQ("abc", textfield_->text()); 1446 EXPECT_STR_EQ("abc", textfield_->text());
1447 SendKeyEvent(ui::VKEY_V, false, true); 1447 SendKeyEvent(ui::VKEY_V, false, true);
1448 EXPECT_STR_EQ("abcabc", textfield_->text()); 1448 EXPECT_STR_EQ("abcabc", textfield_->text());
1449 SendKeyEvent(ui::VKEY_INSERT, true, false); 1449 SendKeyEvent(ui::VKEY_INSERT, true, false);
1450 EXPECT_STR_EQ("abcabcabc", textfield_->text()); 1450 EXPECT_STR_EQ("abcabcabc", textfield_->text());
1451 SendKeyEvent(ui::VKEY_V, true, false, true, false); 1451 SendKeyEvent(ui::VKEY_V, true, false, true, false);
1452 EXPECT_STR_EQ("abcabcabc", textfield_->text()); 1452 EXPECT_STR_EQ("abcabcabc", textfield_->text());
1453 1453
1454 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. 1454 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op.
1455 textfield_->SelectAll(false); 1455 textfield_->SelectAll(false);
1456 SendKeyEvent(ui::VKEY_INSERT, true, true); 1456 SendKeyEvent(ui::VKEY_INSERT, true, true);
1457 EXPECT_STR_EQ("abc", string16(GetClipboardText())); 1457 EXPECT_STR_EQ("abc", base::string16(GetClipboardText()));
1458 EXPECT_STR_EQ("abcabcabc", textfield_->text()); 1458 EXPECT_STR_EQ("abcabcabc", textfield_->text());
1459 } 1459 }
1460 1460
1461 TEST_F(NativeTextfieldViewsTest, OvertypeMode) { 1461 TEST_F(NativeTextfieldViewsTest, OvertypeMode) {
1462 InitTextfield(Textfield::STYLE_DEFAULT); 1462 InitTextfield(Textfield::STYLE_DEFAULT);
1463 // Overtype mode should be disabled (no-op [Insert]). 1463 // Overtype mode should be disabled (no-op [Insert]).
1464 textfield_->SetText(ASCIIToUTF16("2")); 1464 textfield_->SetText(ASCIIToUTF16("2"));
1465 SendKeyEvent(ui::VKEY_HOME); 1465 SendKeyEvent(ui::VKEY_HOME);
1466 SendKeyEvent(ui::VKEY_INSERT); 1466 SendKeyEvent(ui::VKEY_INSERT);
1467 SendKeyEvent(ui::VKEY_1, false, false); 1467 SendKeyEvent(ui::VKEY_1, false, false);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 MouseClick(bound, 10); 1697 MouseClick(bound, 10);
1698 EXPECT_EQ(bound, GetCursorBounds()); 1698 EXPECT_EQ(bound, GetCursorBounds());
1699 1699
1700 // Reset locale. 1700 // Reset locale.
1701 base::i18n::SetICUDefaultLocale(locale); 1701 base::i18n::SetICUDefaultLocale(locale);
1702 } 1702 }
1703 1703
1704 TEST_F(NativeTextfieldViewsTest, OverflowTest) { 1704 TEST_F(NativeTextfieldViewsTest, OverflowTest) {
1705 InitTextfield(Textfield::STYLE_DEFAULT); 1705 InitTextfield(Textfield::STYLE_DEFAULT);
1706 1706
1707 string16 str; 1707 base::string16 str;
1708 for (int i = 0; i < 500; ++i) 1708 for (int i = 0; i < 500; ++i)
1709 SendKeyEvent('a'); 1709 SendKeyEvent('a');
1710 SendKeyEvent(kHebrewLetterSamekh); 1710 SendKeyEvent(kHebrewLetterSamekh);
1711 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1711 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1712 1712
1713 // Test mouse pointing. 1713 // Test mouse pointing.
1714 MouseClick(GetCursorBounds(), -1); 1714 MouseClick(GetCursorBounds(), -1);
1715 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1715 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1716 1716
1717 // Clear text. 1717 // Clear text.
1718 SendKeyEvent(ui::VKEY_A, false, true); 1718 SendKeyEvent(ui::VKEY_A, false, true);
1719 SendKeyEvent('\n'); 1719 SendKeyEvent('\n');
1720 1720
1721 for (int i = 0; i < 500; ++i) 1721 for (int i = 0; i < 500; ++i)
1722 SendKeyEvent(kHebrewLetterSamekh); 1722 SendKeyEvent(kHebrewLetterSamekh);
1723 SendKeyEvent('a'); 1723 SendKeyEvent('a');
1724 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1724 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1725 1725
1726 MouseClick(GetCursorBounds(), -1); 1726 MouseClick(GetCursorBounds(), -1);
1727 EXPECT_EQ(501U, textfield_->GetCursorPosition()); 1727 EXPECT_EQ(501U, textfield_->GetCursorPosition());
1728 } 1728 }
1729 1729
1730 TEST_F(NativeTextfieldViewsTest, OverflowInRTLTest) { 1730 TEST_F(NativeTextfieldViewsTest, OverflowInRTLTest) {
1731 std::string locale = l10n_util::GetApplicationLocale(""); 1731 std::string locale = l10n_util::GetApplicationLocale("");
1732 base::i18n::SetICUDefaultLocale("he"); 1732 base::i18n::SetICUDefaultLocale("he");
1733 1733
1734 InitTextfield(Textfield::STYLE_DEFAULT); 1734 InitTextfield(Textfield::STYLE_DEFAULT);
1735 1735
1736 string16 str; 1736 base::string16 str;
1737 for (int i = 0; i < 500; ++i) 1737 for (int i = 0; i < 500; ++i)
1738 SendKeyEvent('a'); 1738 SendKeyEvent('a');
1739 SendKeyEvent(kHebrewLetterSamekh); 1739 SendKeyEvent(kHebrewLetterSamekh);
1740 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1740 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1741 1741
1742 MouseClick(GetCursorBounds(), 1); 1742 MouseClick(GetCursorBounds(), 1);
1743 EXPECT_EQ(501U, textfield_->GetCursorPosition()); 1743 EXPECT_EQ(501U, textfield_->GetCursorPosition());
1744 1744
1745 // Clear text. 1745 // Clear text.
1746 SendKeyEvent(ui::VKEY_A, false, true); 1746 SendKeyEvent(ui::VKEY_A, false, true);
1747 SendKeyEvent('\n'); 1747 SendKeyEvent('\n');
1748 1748
1749 for (int i = 0; i < 500; ++i) 1749 for (int i = 0; i < 500; ++i)
1750 SendKeyEvent(kHebrewLetterSamekh); 1750 SendKeyEvent(kHebrewLetterSamekh);
1751 SendKeyEvent('a'); 1751 SendKeyEvent('a');
1752 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); 1752 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds()));
1753 1753
1754 MouseClick(GetCursorBounds(), 1); 1754 MouseClick(GetCursorBounds(), 1);
1755 EXPECT_EQ(500U, textfield_->GetCursorPosition()); 1755 EXPECT_EQ(500U, textfield_->GetCursorPosition());
1756 1756
1757 // Reset locale. 1757 // Reset locale.
1758 base::i18n::SetICUDefaultLocale(locale); 1758 base::i18n::SetICUDefaultLocale(locale);
1759 } 1759 }
1760 1760
1761 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBoundsTest) { 1761 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBoundsTest) {
1762 InitTextfield(Textfield::STYLE_DEFAULT); 1762 InitTextfield(Textfield::STYLE_DEFAULT);
1763 1763
1764 string16 str; 1764 base::string16 str;
1765 const uint32 char_count = 10UL; 1765 const uint32 char_count = 10UL;
1766 ui::CompositionText composition; 1766 ui::CompositionText composition;
1767 composition.text = UTF8ToUTF16("0123456789"); 1767 composition.text = UTF8ToUTF16("0123456789");
1768 ui::TextInputClient* client = textfield_->GetTextInputClient(); 1768 ui::TextInputClient* client = textfield_->GetTextInputClient();
1769 1769
1770 // Return false if there is no composition text. 1770 // Return false if there is no composition text.
1771 gfx::Rect rect; 1771 gfx::Rect rect;
1772 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); 1772 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect));
1773 1773
1774 // Get each character boundary by cursor. 1774 // Get each character boundary by cursor.
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 // Set text which may fall back to a font which has taller baseline than 1988 // Set text which may fall back to a font which has taller baseline than
1989 // the default font. 1989 // the default font.
1990 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); 1990 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91"));
1991 const int new_baseline = textfield_->GetBaseline(); 1991 const int new_baseline = textfield_->GetBaseline();
1992 1992
1993 // Regardless of the text, the baseline must be the same. 1993 // Regardless of the text, the baseline must be the same.
1994 EXPECT_EQ(new_baseline, old_baseline); 1994 EXPECT_EQ(new_baseline, old_baseline);
1995 } 1995 }
1996 1996
1997 } // namespace views 1997 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.cc ('k') | ui/views/controls/textfield/native_textfield_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698