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

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

Issue 24012002: Move Range code to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: d Created 7 years, 3 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 | 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } 505 }
506 506
507 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { 507 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) {
508 // Insert a test string in a textfield. 508 // Insert a test string in a textfield.
509 InitTextfield(Textfield::STYLE_DEFAULT); 509 InitTextfield(Textfield::STYLE_DEFAULT);
510 for (size_t i = 0; i < 10; i++) 510 for (size_t i = 0; i < 10; i++)
511 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); 511 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i));
512 EXPECT_STR_EQ("abcdefghij", textfield_->text()); 512 EXPECT_STR_EQ("abcdefghij", textfield_->text());
513 513
514 // Test the delete and backspace keys. 514 // Test the delete and backspace keys.
515 textfield_->SelectRange(ui::Range(5)); 515 textfield_->SelectRange(gfx::Range(5));
516 for (int i = 0; i < 3; i++) 516 for (int i = 0; i < 3; i++)
517 SendKeyEvent(ui::VKEY_BACK); 517 SendKeyEvent(ui::VKEY_BACK);
518 EXPECT_STR_EQ("abfghij", textfield_->text()); 518 EXPECT_STR_EQ("abfghij", textfield_->text());
519 for (int i = 0; i < 3; i++) 519 for (int i = 0; i < 3; i++)
520 SendKeyEvent(ui::VKEY_DELETE); 520 SendKeyEvent(ui::VKEY_DELETE);
521 EXPECT_STR_EQ("abij", textfield_->text()); 521 EXPECT_STR_EQ("abij", textfield_->text());
522 522
523 // Select all and replace with "k". 523 // Select all and replace with "k".
524 textfield_->SelectAll(false); 524 textfield_->SelectAll(false);
525 SendKeyEvent(ui::VKEY_K); 525 SendKeyEvent(ui::VKEY_K);
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 } 933 }
934 #endif 934 #endif
935 935
936 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { 936 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) {
937 InitTextfield(Textfield::STYLE_DEFAULT); 937 InitTextfield(Textfield::STYLE_DEFAULT);
938 textfield_->SetText(ASCIIToUTF16("hello string world")); 938 textfield_->SetText(ASCIIToUTF16("hello string world"));
939 939
940 // Ensure the textfield will provide selected text for drag data. 940 // Ensure the textfield will provide selected text for drag data.
941 string16 string; 941 string16 string;
942 ui::OSExchangeData data; 942 ui::OSExchangeData data;
943 const ui::Range kStringRange(6, 12); 943 const gfx::Range kStringRange(6, 12);
944 textfield_->SelectRange(kStringRange); 944 textfield_->SelectRange(kStringRange);
945 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 945 const gfx::Point kStringPoint(GetCursorPositionX(9), 0);
946 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); 946 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data);
947 EXPECT_TRUE(data.GetString(&string)); 947 EXPECT_TRUE(data.GetString(&string));
948 EXPECT_EQ(textfield_->GetSelectedText(), string); 948 EXPECT_EQ(textfield_->GetSelectedText(), string);
949 949
950 // Ensure that disabled textfields do not support drag operations. 950 // Ensure that disabled textfields do not support drag operations.
951 textfield_->SetEnabled(false); 951 textfield_->SetEnabled(false);
952 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, 952 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE,
953 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); 953 textfield_view_->GetDragOperationsForView(NULL, kStringPoint));
(...skipping 29 matching lines...) Expand all
983 InitTextfield(Textfield::STYLE_DEFAULT); 983 InitTextfield(Textfield::STYLE_DEFAULT);
984 textfield_->SetText(ASCIIToUTF16("hello world")); 984 textfield_->SetText(ASCIIToUTF16("hello world"));
985 985
986 string16 string; 986 string16 string;
987 ui::OSExchangeData data; 987 ui::OSExchangeData data;
988 int formats = 0; 988 int formats = 0;
989 int operations = 0; 989 int operations = 0;
990 std::set<OSExchangeData::CustomFormat> custom_formats; 990 std::set<OSExchangeData::CustomFormat> custom_formats;
991 991
992 // Start dragging "ello". 992 // Start dragging "ello".
993 textfield_->SelectRange(ui::Range(1, 5)); 993 textfield_->SelectRange(gfx::Range(1, 5));
994 gfx::Point point(GetCursorPositionX(3), 0); 994 gfx::Point point(GetCursorPositionX(3), 0);
995 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 995 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
996 ui::EF_LEFT_MOUSE_BUTTON); 996 ui::EF_LEFT_MOUSE_BUTTON);
997 textfield_view_->OnMousePressed(click_a); 997 textfield_view_->OnMousePressed(click_a);
998 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, 998 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_,
999 click_a.location(), gfx::Point())); 999 click_a.location(), gfx::Point()));
1000 operations = textfield_view_->GetDragOperationsForView(textfield_view_, 1000 operations = textfield_view_->GetDragOperationsForView(textfield_view_,
1001 click_a.location()); 1001 click_a.location());
1002 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1002 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1003 operations); 1003 operations);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 InitTextfield(Textfield::STYLE_DEFAULT); 1038 InitTextfield(Textfield::STYLE_DEFAULT);
1039 textfield_->SetText(ASCIIToUTF16("hello world")); 1039 textfield_->SetText(ASCIIToUTF16("hello world"));
1040 1040
1041 string16 string; 1041 string16 string;
1042 ui::OSExchangeData data; 1042 ui::OSExchangeData data;
1043 int formats = 0; 1043 int formats = 0;
1044 int operations = 0; 1044 int operations = 0;
1045 std::set<OSExchangeData::CustomFormat> custom_formats; 1045 std::set<OSExchangeData::CustomFormat> custom_formats;
1046 1046
1047 // Start dragging " worl". 1047 // Start dragging " worl".
1048 textfield_->SelectRange(ui::Range(5, 10)); 1048 textfield_->SelectRange(gfx::Range(5, 10));
1049 gfx::Point point(GetCursorPositionX(7), 0); 1049 gfx::Point point(GetCursorPositionX(7), 0);
1050 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, 1050 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point,
1051 ui::EF_LEFT_MOUSE_BUTTON); 1051 ui::EF_LEFT_MOUSE_BUTTON);
1052 textfield_view_->OnMousePressed(click_a); 1052 textfield_view_->OnMousePressed(click_a);
1053 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, 1053 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_,
1054 click_a.location(), gfx::Point())); 1054 click_a.location(), gfx::Point()));
1055 operations = textfield_view_->GetDragOperationsForView(textfield_view_, 1055 operations = textfield_view_->GetDragOperationsForView(textfield_view_,
1056 click_a.location()); 1056 click_a.location());
1057 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, 1057 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY,
1058 operations); 1058 operations);
(...skipping 28 matching lines...) Expand all
1087 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1087 EXPECT_STR_EQ("h worlellod", textfield_->text());
1088 SendKeyEvent(ui::VKEY_Y, false, true); 1088 SendKeyEvent(ui::VKEY_Y, false, true);
1089 EXPECT_STR_EQ("h worlellod", textfield_->text()); 1089 EXPECT_STR_EQ("h worlellod", textfield_->text());
1090 } 1090 }
1091 1091
1092 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { 1092 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) {
1093 InitTextfield(Textfield::STYLE_DEFAULT); 1093 InitTextfield(Textfield::STYLE_DEFAULT);
1094 textfield_->SetText(ASCIIToUTF16("hello world")); 1094 textfield_->SetText(ASCIIToUTF16("hello world"));
1095 1095
1096 // Start dragging "worl". 1096 // Start dragging "worl".
1097 textfield_->SelectRange(ui::Range(6, 10)); 1097 textfield_->SelectRange(gfx::Range(6, 10));
1098 gfx::Point point(GetCursorPositionX(8), 0); 1098 gfx::Point point(GetCursorPositionX(8), 0);
1099 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, 1099 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point,
1100 ui::EF_LEFT_MOUSE_BUTTON); 1100 ui::EF_LEFT_MOUSE_BUTTON);
1101 textfield_view_->OnMousePressed(click); 1101 textfield_view_->OnMousePressed(click);
1102 ui::OSExchangeData data; 1102 ui::OSExchangeData data;
1103 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); 1103 textfield_view_->WriteDragDataForView(NULL, click.location(), &data);
1104 EXPECT_TRUE(textfield_view_->CanDrop(data)); 1104 EXPECT_TRUE(textfield_view_->CanDrop(data));
1105 // Drag the text over somewhere valid, outside the current selection. 1105 // Drag the text over somewhere valid, outside the current selection.
1106 gfx::Point drop_point(GetCursorPositionX(2), 0); 1106 gfx::Point drop_point(GetCursorPositionX(2), 0);
1107 ui::DropTargetEvent drop(data, drop_point, drop_point, 1107 ui::DropTargetEvent drop(data, drop_point, drop_point,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); 1185 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
1186 } 1186 }
1187 1187
1188 TEST_F(NativeTextfieldViewsTest, TextInputClientTest) { 1188 TEST_F(NativeTextfieldViewsTest, TextInputClientTest) {
1189 InitTextfield(Textfield::STYLE_DEFAULT); 1189 InitTextfield(Textfield::STYLE_DEFAULT);
1190 ui::TextInputClient* client = textfield_->GetTextInputClient(); 1190 ui::TextInputClient* client = textfield_->GetTextInputClient();
1191 EXPECT_TRUE(client); 1191 EXPECT_TRUE(client);
1192 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); 1192 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType());
1193 1193
1194 textfield_->SetText(ASCIIToUTF16("0123456789")); 1194 textfield_->SetText(ASCIIToUTF16("0123456789"));
1195 ui::Range range; 1195 gfx::Range range;
1196 EXPECT_TRUE(client->GetTextRange(&range)); 1196 EXPECT_TRUE(client->GetTextRange(&range));
1197 EXPECT_EQ(0U, range.start()); 1197 EXPECT_EQ(0U, range.start());
1198 EXPECT_EQ(10U, range.end()); 1198 EXPECT_EQ(10U, range.end());
1199 1199
1200 EXPECT_TRUE(client->SetSelectionRange(ui::Range(1, 4))); 1200 EXPECT_TRUE(client->SetSelectionRange(gfx::Range(1, 4)));
1201 EXPECT_TRUE(client->GetSelectionRange(&range)); 1201 EXPECT_TRUE(client->GetSelectionRange(&range));
1202 EXPECT_EQ(ui::Range(1, 4), range); 1202 EXPECT_EQ(gfx::Range(1, 4), range);
1203 1203
1204 // This code can't be compiled because of a bug in base::Callback. 1204 // This code can't be compiled because of a bug in base::Callback.
1205 #if 0 1205 #if 0
1206 GetTextHelper helper; 1206 GetTextHelper helper;
1207 base::Callback<void(string16)> callback = 1207 base::Callback<void(string16)> callback =
1208 base::Bind(&GetTextHelper::set_text, base::Unretained(&helper)); 1208 base::Bind(&GetTextHelper::set_text, base::Unretained(&helper));
1209 1209
1210 EXPECT_TRUE(client->GetTextFromRange(range, callback)); 1210 EXPECT_TRUE(client->GetTextFromRange(range, callback));
1211 EXPECT_STR_EQ("123", helper.text()); 1211 EXPECT_STR_EQ("123", helper.text());
1212 #endif 1212 #endif
1213 1213
1214 EXPECT_TRUE(client->DeleteRange(range)); 1214 EXPECT_TRUE(client->DeleteRange(range));
1215 EXPECT_STR_EQ("0456789", textfield_->text()); 1215 EXPECT_STR_EQ("0456789", textfield_->text());
1216 1216
1217 ui::CompositionText composition; 1217 ui::CompositionText composition;
1218 composition.text = UTF8ToUTF16("321"); 1218 composition.text = UTF8ToUTF16("321");
1219 // Set composition through input method. 1219 // Set composition through input method.
1220 input_method_->Clear(); 1220 input_method_->Clear();
1221 input_method_->SetCompositionTextForNextKey(composition); 1221 input_method_->SetCompositionTextForNextKey(composition);
1222 textfield_->clear(); 1222 textfield_->clear();
1223 1223
1224 on_before_user_action_ = on_after_user_action_ = 0; 1224 on_before_user_action_ = on_after_user_action_ = 0;
1225 SendKeyEvent(ui::VKEY_A); 1225 SendKeyEvent(ui::VKEY_A);
1226 EXPECT_TRUE(textfield_->key_received()); 1226 EXPECT_TRUE(textfield_->key_received());
1227 EXPECT_FALSE(textfield_->key_handled()); 1227 EXPECT_FALSE(textfield_->key_handled());
1228 EXPECT_TRUE(client->HasCompositionText()); 1228 EXPECT_TRUE(client->HasCompositionText());
1229 EXPECT_TRUE(client->GetCompositionTextRange(&range)); 1229 EXPECT_TRUE(client->GetCompositionTextRange(&range));
1230 EXPECT_STR_EQ("0321456789", textfield_->text()); 1230 EXPECT_STR_EQ("0321456789", textfield_->text());
1231 EXPECT_EQ(ui::Range(1, 4), range); 1231 EXPECT_EQ(gfx::Range(1, 4), range);
1232 EXPECT_EQ(2, on_before_user_action_); 1232 EXPECT_EQ(2, on_before_user_action_);
1233 EXPECT_EQ(2, on_after_user_action_); 1233 EXPECT_EQ(2, on_after_user_action_);
1234 1234
1235 input_method_->SetResultTextForNextKey(UTF8ToUTF16("123")); 1235 input_method_->SetResultTextForNextKey(UTF8ToUTF16("123"));
1236 on_before_user_action_ = on_after_user_action_ = 0; 1236 on_before_user_action_ = on_after_user_action_ = 0;
1237 textfield_->clear(); 1237 textfield_->clear();
1238 SendKeyEvent(ui::VKEY_A); 1238 SendKeyEvent(ui::VKEY_A);
1239 EXPECT_TRUE(textfield_->key_received()); 1239 EXPECT_TRUE(textfield_->key_received());
1240 EXPECT_FALSE(textfield_->key_handled()); 1240 EXPECT_FALSE(textfield_->key_handled());
1241 EXPECT_FALSE(client->HasCompositionText()); 1241 EXPECT_FALSE(client->HasCompositionText());
(...skipping 16 matching lines...) Expand all
1258 EXPECT_TRUE(input_method_->cancel_composition_called()); 1258 EXPECT_TRUE(input_method_->cancel_composition_called());
1259 EXPECT_TRUE(textfield_->key_received()); 1259 EXPECT_TRUE(textfield_->key_received());
1260 EXPECT_TRUE(textfield_->key_handled()); 1260 EXPECT_TRUE(textfield_->key_handled());
1261 EXPECT_STR_EQ("0123321456789", textfield_->text()); 1261 EXPECT_STR_EQ("0123321456789", textfield_->text());
1262 EXPECT_EQ(8U, textfield_->GetCursorPosition()); 1262 EXPECT_EQ(8U, textfield_->GetCursorPosition());
1263 EXPECT_EQ(1, on_before_user_action_); 1263 EXPECT_EQ(1, on_before_user_action_);
1264 EXPECT_EQ(1, on_after_user_action_); 1264 EXPECT_EQ(1, on_after_user_action_);
1265 1265
1266 textfield_->clear(); 1266 textfield_->clear();
1267 textfield_->SetText(ASCIIToUTF16("0123456789")); 1267 textfield_->SetText(ASCIIToUTF16("0123456789"));
1268 EXPECT_TRUE(client->SetSelectionRange(ui::Range(5, 5))); 1268 EXPECT_TRUE(client->SetSelectionRange(gfx::Range(5, 5)));
1269 client->ExtendSelectionAndDelete(4, 2); 1269 client->ExtendSelectionAndDelete(4, 2);
1270 EXPECT_STR_EQ("0789", textfield_->text()); 1270 EXPECT_STR_EQ("0789", textfield_->text());
1271 1271
1272 // On{Before,After}UserAction should be called by whatever user action 1272 // On{Before,After}UserAction should be called by whatever user action
1273 // triggers clearing or setting a selection if appropriate. 1273 // triggers clearing or setting a selection if appropriate.
1274 on_before_user_action_ = on_after_user_action_ = 0; 1274 on_before_user_action_ = on_after_user_action_ = 0;
1275 textfield_->clear(); 1275 textfield_->clear();
1276 textfield_->ClearSelection(); 1276 textfield_->ClearSelection();
1277 textfield_->SelectAll(false); 1277 textfield_->SelectAll(false);
1278 EXPECT_EQ(0, on_before_user_action_); 1278 EXPECT_EQ(0, on_before_user_action_);
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 ui::TextInputClient* client = textfield_->GetTextInputClient(); 1766 ui::TextInputClient* client = textfield_->GetTextInputClient();
1767 1767
1768 // Return false if there is no composition text. 1768 // Return false if there is no composition text.
1769 gfx::Rect rect; 1769 gfx::Rect rect;
1770 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); 1770 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect));
1771 1771
1772 // Get each character boundary by cursor. 1772 // Get each character boundary by cursor.
1773 gfx::Rect char_rect_in_screen_coord[char_count]; 1773 gfx::Rect char_rect_in_screen_coord[char_count];
1774 gfx::Rect prev_cursor = GetCursorBounds(); 1774 gfx::Rect prev_cursor = GetCursorBounds();
1775 for (uint32 i = 0; i < char_count; ++i) { 1775 for (uint32 i = 0; i < char_count; ++i) {
1776 composition.selection = ui::Range(0, i+1); 1776 composition.selection = gfx::Range(0, i+1);
1777 client->SetCompositionText(composition); 1777 client->SetCompositionText(composition);
1778 EXPECT_TRUE(client->HasCompositionText()) << " i=" << i; 1778 EXPECT_TRUE(client->HasCompositionText()) << " i=" << i;
1779 gfx::Rect cursor_bounds = GetCursorBounds(); 1779 gfx::Rect cursor_bounds = GetCursorBounds();
1780 gfx::Point top_left(prev_cursor.x(), prev_cursor.y()); 1780 gfx::Point top_left(prev_cursor.x(), prev_cursor.y());
1781 gfx::Point bottom_right(cursor_bounds.x(), prev_cursor.bottom()); 1781 gfx::Point bottom_right(cursor_bounds.x(), prev_cursor.bottom());
1782 views::View::ConvertPointToScreen(textfield_view_, &top_left); 1782 views::View::ConvertPointToScreen(textfield_view_, &top_left);
1783 views::View::ConvertPointToScreen(textfield_view_, &bottom_right); 1783 views::View::ConvertPointToScreen(textfield_view_, &bottom_right);
1784 char_rect_in_screen_coord[i].set_origin(top_left); 1784 char_rect_in_screen_coord[i].set_origin(top_left);
1785 char_rect_in_screen_coord[i].set_width(bottom_right.x() - top_left.x()); 1785 char_rect_in_screen_coord[i].set_width(bottom_right.x() - top_left.x());
1786 char_rect_in_screen_coord[i].set_height(bottom_right.y() - top_left.y()); 1786 char_rect_in_screen_coord[i].set_height(bottom_right.y() - top_left.y());
(...skipping 13 matching lines...) Expand all
1800 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); 1800 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect));
1801 } 1801 }
1802 1802
1803 // The word we select by double clicking should remain selected regardless of 1803 // The word we select by double clicking should remain selected regardless of
1804 // where we drag the mouse afterwards without releasing the left button. 1804 // where we drag the mouse afterwards without releasing the left button.
1805 TEST_F(NativeTextfieldViewsTest, KeepInitiallySelectedWord) { 1805 TEST_F(NativeTextfieldViewsTest, KeepInitiallySelectedWord) {
1806 InitTextfield(Textfield::STYLE_DEFAULT); 1806 InitTextfield(Textfield::STYLE_DEFAULT);
1807 1807
1808 textfield_->SetText(ASCIIToUTF16("abc def ghi")); 1808 textfield_->SetText(ASCIIToUTF16("abc def ghi"));
1809 1809
1810 textfield_->SelectRange(ui::Range(5, 5)); 1810 textfield_->SelectRange(gfx::Range(5, 5));
1811 const gfx::Rect middle_cursor = GetCursorBounds(); 1811 const gfx::Rect middle_cursor = GetCursorBounds();
1812 textfield_->SelectRange(ui::Range(0, 0)); 1812 textfield_->SelectRange(gfx::Range(0, 0));
1813 const gfx::Point beginning = GetCursorBounds().origin(); 1813 const gfx::Point beginning = GetCursorBounds().origin();
1814 1814
1815 // Double click, but do not release the left button. 1815 // Double click, but do not release the left button.
1816 MouseClick(middle_cursor, 0); 1816 MouseClick(middle_cursor, 0);
1817 const gfx::Point middle(middle_cursor.x(), 1817 const gfx::Point middle(middle_cursor.x(),
1818 middle_cursor.y() + middle_cursor.height() / 2); 1818 middle_cursor.y() + middle_cursor.height() / 2);
1819 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, 1819 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle,
1820 ui::EF_LEFT_MOUSE_BUTTON); 1820 ui::EF_LEFT_MOUSE_BUTTON);
1821 textfield_view_->OnMousePressed(press_event); 1821 textfield_view_->OnMousePressed(press_event);
1822 EXPECT_EQ(ui::Range(4, 7), textfield_->GetSelectedRange()); 1822 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange());
1823 1823
1824 // Drag the mouse to the beginning of the textfield. 1824 // Drag the mouse to the beginning of the textfield.
1825 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, 1825 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning,
1826 ui::EF_LEFT_MOUSE_BUTTON); 1826 ui::EF_LEFT_MOUSE_BUTTON);
1827 textfield_view_->OnMouseDragged(drag_event); 1827 textfield_view_->OnMouseDragged(drag_event);
1828 EXPECT_EQ(ui::Range(7, 0), textfield_->GetSelectedRange()); 1828 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange());
1829 } 1829 }
1830 1830
1831 // Touch selection and draggin currently only works for chromeos. 1831 // Touch selection and draggin currently only works for chromeos.
1832 #if defined(OS_CHROMEOS) 1832 #if defined(OS_CHROMEOS)
1833 TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { 1833 TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) {
1834 InitTextfield(Textfield::STYLE_DEFAULT); 1834 InitTextfield(Textfield::STYLE_DEFAULT);
1835 textfield_->SetText(ASCIIToUTF16("hello world")); 1835 textfield_->SetText(ASCIIToUTF16("hello world"));
1836 EXPECT_FALSE(GetTouchSelectionController()); 1836 EXPECT_FALSE(GetTouchSelectionController());
1837 const int eventX = GetCursorPositionX(2); 1837 const int eventX = GetCursorPositionX(2);
1838 const int eventY = 0; 1838 const int eventY = 0;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 EXPECT_FALSE(GetTouchSelectionController()); 1879 EXPECT_FALSE(GetTouchSelectionController());
1880 } 1880 }
1881 #endif 1881 #endif
1882 1882
1883 // Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now. 1883 // Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now.
1884 TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) { 1884 TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) {
1885 InitTextfield(Textfield::STYLE_DEFAULT); 1885 InitTextfield(Textfield::STYLE_DEFAULT);
1886 textfield_->SetText(ASCIIToUTF16("Hello string world")); 1886 textfield_->SetText(ASCIIToUTF16("Hello string world"));
1887 1887
1888 // Ensure the textfield will provide selected text for drag data. 1888 // Ensure the textfield will provide selected text for drag data.
1889 textfield_->SelectRange(ui::Range(6, 12)); 1889 textfield_->SelectRange(gfx::Range(6, 12));
1890 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); 1890 const gfx::Point kStringPoint(GetCursorPositionX(9), 0);
1891 1891
1892 // Enable touch-drag-drop to make long press effective. 1892 // Enable touch-drag-drop to make long press effective.
1893 CommandLine::ForCurrentProcess()->AppendSwitch( 1893 CommandLine::ForCurrentProcess()->AppendSwitch(
1894 switches::kEnableTouchDragDrop); 1894 switches::kEnableTouchDragDrop);
1895 1895
1896 // Create a long press event in the selected region should start a drag. 1896 // Create a long press event in the selected region should start a drag.
1897 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, 1897 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS,
1898 kStringPoint.x(), kStringPoint.y(), 0); 1898 kStringPoint.x(), kStringPoint.y(), 0);
1899 textfield_view_->OnGestureEvent(&long_press); 1899 textfield_view_->OnGestureEvent(&long_press);
(...skipping 16 matching lines...) Expand all
1916 1916
1917 // Set text which may fall back to a font which has taller baseline than 1917 // Set text which may fall back to a font which has taller baseline than
1918 // the default font. |new_baseline| will be greater than |old_baseline|. 1918 // the default font. |new_baseline| will be greater than |old_baseline|.
1919 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); 1919 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91"));
1920 const int new_baseline = textfield_->GetBaseline(); 1920 const int new_baseline = textfield_->GetBaseline();
1921 1921
1922 EXPECT_GT(new_baseline, old_baseline); 1922 EXPECT_GT(new_baseline, old_baseline);
1923 } 1923 }
1924 1924
1925 } // namespace views 1925 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/native_textfield_views.cc ('k') | ui/views/controls/textfield/native_textfield_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698