| OLD | NEW |
| 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/native_textfield_views.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/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "grit/ui_strings.h" | 20 #include "grit/ui_strings.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "ui/base/clipboard/clipboard.h" | 22 #include "ui/base/clipboard/clipboard.h" |
| 23 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 23 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 24 #include "ui/base/dragdrop/drag_drop_types.h" | 24 #include "ui/base/dragdrop/drag_drop_types.h" |
| 25 #include "ui/base/ime/text_input_client.h" | 25 #include "ui/base/ime/text_input_client.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" |
| 28 #include "ui/base/ui_base_switches_util.h" |
| 28 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
| 29 #include "ui/events/keycodes/keyboard_codes.h" | 30 #include "ui/events/keycodes/keyboard_codes.h" |
| 30 #include "ui/gfx/render_text.h" | 31 #include "ui/gfx/render_text.h" |
| 31 #include "ui/views/controls/textfield/textfield.h" | |
| 32 #include "ui/views/controls/textfield/textfield_controller.h" | 32 #include "ui/views/controls/textfield/textfield_controller.h" |
| 33 #include "ui/views/controls/textfield/textfield_views_model.h" | 33 #include "ui/views/controls/textfield/textfield_views_model.h" |
| 34 #include "ui/views/focus/focus_manager.h" | 34 #include "ui/views/focus/focus_manager.h" |
| 35 #include "ui/views/ime/mock_input_method.h" | 35 #include "ui/views/ime/mock_input_method.h" |
| 36 #include "ui/views/test/test_views_delegate.h" | 36 #include "ui/views/test/test_views_delegate.h" |
| 37 #include "ui/views/test/views_test_base.h" | 37 #include "ui/views/test/views_test_base.h" |
| 38 #include "ui/views/widget/native_widget_private.h" | 38 #include "ui/views/widget/native_widget_private.h" |
| 39 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
| 40 #include "url/gurl.h" | 40 #include "url/gurl.h" |
| 41 | 41 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); | 115 DISALLOW_COPY_AND_ASSIGN(GestureEventForTest); |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 } // namespace | 118 } // namespace |
| 119 | 119 |
| 120 namespace views { | 120 namespace views { |
| 121 | 121 |
| 122 // TODO(oshima): Move tests that are independent of TextfieldViews to | 122 class TextfieldTest : public ViewsTestBase, public TextfieldController { |
| 123 // textfield_unittests.cc once we move the test utility functions | |
| 124 // from chrome/browser/automation/ to ui/base/test/. | |
| 125 class NativeTextfieldViewsTest : public ViewsTestBase, | |
| 126 public TextfieldController { | |
| 127 public: | 123 public: |
| 128 NativeTextfieldViewsTest() | 124 TextfieldTest() |
| 129 : widget_(NULL), | 125 : widget_(NULL), |
| 130 textfield_(NULL), | 126 textfield_(NULL), |
| 131 textfield_view_(NULL), | |
| 132 model_(NULL), | 127 model_(NULL), |
| 133 input_method_(NULL), | 128 input_method_(NULL), |
| 134 on_before_user_action_(0), | 129 on_before_user_action_(0), |
| 135 on_after_user_action_(0) { | 130 on_after_user_action_(0) { |
| 136 } | 131 } |
| 137 | 132 |
| 138 // ::testing::Test: | 133 // ::testing::Test: |
| 139 virtual void SetUp() { | 134 virtual void SetUp() { |
| 140 ViewsTestBase::SetUp(); | 135 ViewsTestBase::SetUp(); |
| 141 } | 136 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ASSERT_FALSE(textfield_); | 172 ASSERT_FALSE(textfield_); |
| 178 textfield_ = new TestTextfield(style); | 173 textfield_ = new TestTextfield(style); |
| 179 textfield_->SetController(this); | 174 textfield_->SetController(this); |
| 180 widget_ = new Widget(); | 175 widget_ = new Widget(); |
| 181 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 176 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 182 params.bounds = gfx::Rect(100, 100, 100, 100); | 177 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 183 widget_->Init(params); | 178 widget_->Init(params); |
| 184 View* container = new View(); | 179 View* container = new View(); |
| 185 widget_->SetContentsView(container); | 180 widget_->SetContentsView(container); |
| 186 container->AddChildView(textfield_); | 181 container->AddChildView(textfield_); |
| 187 | 182 textfield_->SetBoundsRect(params.bounds); |
| 188 textfield_view_ = textfield_->GetTextfieldViewForTesting(); | |
| 189 DCHECK(textfield_view_); | |
| 190 textfield_view_->SetBoundsRect(params.bounds); | |
| 191 textfield_->set_id(1); | 183 textfield_->set_id(1); |
| 192 | 184 |
| 193 for (int i = 1; i < count; i++) { | 185 for (int i = 1; i < count; i++) { |
| 194 Textfield* textfield = new Textfield(style); | 186 Textfield* textfield = new Textfield(style); |
| 195 container->AddChildView(textfield); | 187 container->AddChildView(textfield); |
| 196 textfield->set_id(i + 1); | 188 textfield->set_id(i + 1); |
| 197 } | 189 } |
| 198 | 190 |
| 199 model_ = textfield_view_->model_.get(); | 191 model_ = textfield_->model_.get(); |
| 200 model_->ClearEditHistory(); | 192 model_->ClearEditHistory(); |
| 201 | 193 |
| 202 input_method_ = new MockInputMethod(); | 194 input_method_ = new MockInputMethod(); |
| 203 widget_->ReplaceInputMethod(input_method_); | 195 widget_->ReplaceInputMethod(input_method_); |
| 204 | 196 |
| 205 // Activate the widget and focus the textfield for input handling. | 197 // Activate the widget and focus the textfield for input handling. |
| 206 widget_->Activate(); | 198 widget_->Activate(); |
| 207 textfield_->RequestFocus(); | 199 textfield_->RequestFocus(); |
| 208 } | 200 } |
| 209 | 201 |
| 210 ui::MenuModel* GetContextMenuModel() { | 202 ui::MenuModel* GetContextMenuModel() { |
| 211 textfield_view_->UpdateContextMenu(); | 203 textfield_->UpdateContextMenu(); |
| 212 return textfield_view_->context_menu_contents_.get(); | 204 return textfield_->context_menu_contents_.get(); |
| 213 } | 205 } |
| 214 | 206 |
| 215 ui::TouchSelectionController* GetTouchSelectionController() { | 207 ui::TouchSelectionController* GetTouchSelectionController() { |
| 216 return textfield_view_->touch_selection_controller_.get(); | 208 return textfield_->touch_selection_controller_.get(); |
| 217 } | 209 } |
| 218 | 210 |
| 219 protected: | 211 protected: |
| 220 void SendKeyEvent(ui::KeyboardCode key_code, | 212 void SendKeyEvent(ui::KeyboardCode key_code, |
| 221 bool alt, | 213 bool alt, |
| 222 bool shift, | 214 bool shift, |
| 223 bool control, | 215 bool control, |
| 224 bool caps_lock) { | 216 bool caps_lock) { |
| 225 int flags = (alt ? ui::EF_ALT_DOWN : 0) | | 217 int flags = (alt ? ui::EF_ALT_DOWN : 0) | |
| 226 (shift ? ui::EF_SHIFT_DOWN : 0) | | 218 (shift ? ui::EF_SHIFT_DOWN : 0) | |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 ui::Clipboard::GetForCurrentThread(), | 255 ui::Clipboard::GetForCurrentThread(), |
| 264 ui::CLIPBOARD_TYPE_COPY_PASTE); | 256 ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 265 clipboard_writer.WriteText(ASCIIToUTF16(text)); | 257 clipboard_writer.WriteText(ASCIIToUTF16(text)); |
| 266 } | 258 } |
| 267 | 259 |
| 268 View* GetFocusedView() { | 260 View* GetFocusedView() { |
| 269 return widget_->GetFocusManager()->GetFocusedView(); | 261 return widget_->GetFocusManager()->GetFocusedView(); |
| 270 } | 262 } |
| 271 | 263 |
| 272 int GetCursorPositionX(int cursor_pos) { | 264 int GetCursorPositionX(int cursor_pos) { |
| 273 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 265 return textfield_->GetRenderText()->GetCursorBounds( |
| 274 return render_text->GetCursorBounds( | |
| 275 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); | 266 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); |
| 276 } | 267 } |
| 277 | 268 |
| 278 // Get the current cursor bounds. | 269 // Get the current cursor bounds. |
| 279 gfx::Rect GetCursorBounds() { | 270 gfx::Rect GetCursorBounds() { |
| 280 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 271 return textfield_->GetRenderText()->GetUpdatedCursorBounds(); |
| 281 gfx::Rect bounds = render_text->GetUpdatedCursorBounds(); | |
| 282 return bounds; | |
| 283 } | 272 } |
| 284 | 273 |
| 285 // Get the cursor bounds of |sel|. | 274 // Get the cursor bounds of |sel|. |
| 286 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) { | 275 gfx::Rect GetCursorBounds(const gfx::SelectionModel& sel) { |
| 287 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 276 return textfield_->GetRenderText()->GetCursorBounds(sel, true); |
| 288 gfx::Rect bounds = render_text->GetCursorBounds(sel, true); | |
| 289 return bounds; | |
| 290 } | 277 } |
| 291 | 278 |
| 292 gfx::Rect GetDisplayRect() { | 279 gfx::Rect GetDisplayRect() { |
| 293 return textfield_view_->GetRenderText()->display_rect(); | 280 return textfield_->GetRenderText()->display_rect(); |
| 294 } | 281 } |
| 295 | 282 |
| 296 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and | 283 // Mouse click on the point whose x-axis is |bound|'s x plus |x_offset| and |
| 297 // y-axis is in the middle of |bound|'s vertical range. | 284 // y-axis is in the middle of |bound|'s vertical range. |
| 298 void MouseClick(const gfx::Rect bound, int x_offset) { | 285 void MouseClick(const gfx::Rect bound, int x_offset) { |
| 299 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); | 286 gfx::Point point(bound.x() + x_offset, bound.y() + bound.height() / 2); |
| 300 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 287 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
| 301 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 288 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 302 textfield_view_->OnMousePressed(click); | 289 textfield_->OnMousePressed(click); |
| 303 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, | 290 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, point, point, |
| 304 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 291 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 305 textfield_view_->OnMouseReleased(release); | 292 textfield_->OnMouseReleased(release); |
| 306 } | 293 } |
| 307 | 294 |
| 308 // This is to avoid double/triple click. | 295 // This is to avoid double/triple click. |
| 309 void NonClientMouseClick() { | 296 void NonClientMouseClick() { |
| 310 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 297 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 311 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 298 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 312 ui::EF_LEFT_MOUSE_BUTTON); | 299 ui::EF_LEFT_MOUSE_BUTTON); |
| 313 textfield_view_->OnMousePressed(click); | 300 textfield_->OnMousePressed(click); |
| 314 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 301 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 315 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, | 302 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_NON_CLIENT, |
| 316 ui::EF_LEFT_MOUSE_BUTTON); | 303 ui::EF_LEFT_MOUSE_BUTTON); |
| 317 textfield_view_->OnMouseReleased(release); | 304 textfield_->OnMouseReleased(release); |
| 318 } | 305 } |
| 319 | 306 |
| 320 // Wrap for visibility in test classes. | 307 // Wrap for visibility in test classes. |
| 321 ui::TextInputType GetTextInputType() { | 308 ui::TextInputType GetTextInputType() { |
| 322 return textfield_view_->GetTextInputType(); | 309 return textfield_->GetTextInputType(); |
| 323 } | 310 } |
| 324 | 311 |
| 325 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, | 312 void VerifyTextfieldContextMenuContents(bool textfield_has_selection, |
| 326 bool can_undo, | 313 bool can_undo, |
| 327 ui::MenuModel* menu) { | 314 ui::MenuModel* menu) { |
| 328 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); | 315 EXPECT_EQ(can_undo, menu->IsEnabledAt(0 /* UNDO */)); |
| 329 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); | 316 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); |
| 330 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); | 317 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); |
| 331 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); | 318 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); |
| 332 EXPECT_NE(GetClipboardText().empty(), menu->IsEnabledAt(4 /* PASTE */)); | 319 EXPECT_NE(GetClipboardText().empty(), menu->IsEnabledAt(4 /* PASTE */)); |
| 333 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 320 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
| 334 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); | 321 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); |
| 335 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); | 322 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); |
| 336 } | 323 } |
| 337 | 324 |
| 338 // We need widget to populate wrapper class. | 325 // We need widget to populate wrapper class. |
| 339 Widget* widget_; | 326 Widget* widget_; |
| 340 | 327 |
| 341 TestTextfield* textfield_; | 328 TestTextfield* textfield_; |
| 342 NativeTextfieldViews* textfield_view_; | |
| 343 TextfieldViewsModel* model_; | 329 TextfieldViewsModel* model_; |
| 344 | 330 |
| 345 // The string from Controller::ContentsChanged callback. | 331 // The string from Controller::ContentsChanged callback. |
| 346 base::string16 last_contents_; | 332 base::string16 last_contents_; |
| 347 | 333 |
| 348 // For testing input method related behaviors. | 334 // For testing input method related behaviors. |
| 349 MockInputMethod* input_method_; | 335 MockInputMethod* input_method_; |
| 350 | 336 |
| 351 // Indicates how many times OnBeforeUserAction() is called. | 337 // Indicates how many times OnBeforeUserAction() is called. |
| 352 int on_before_user_action_; | 338 int on_before_user_action_; |
| 353 | 339 |
| 354 // Indicates how many times OnAfterUserAction() is called. | 340 // Indicates how many times OnAfterUserAction() is called. |
| 355 int on_after_user_action_; | 341 int on_after_user_action_; |
| 356 | 342 |
| 357 private: | 343 private: |
| 358 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViewsTest); | 344 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); |
| 359 }; | 345 }; |
| 360 | 346 |
| 361 TEST_F(NativeTextfieldViewsTest, ModelChangesTest) { | 347 TEST_F(TextfieldTest, ModelChangesTest) { |
| 362 InitTextfield(Textfield::STYLE_DEFAULT); | 348 InitTextfield(Textfield::STYLE_DEFAULT); |
| 363 | 349 |
| 364 // TextfieldController::ContentsChanged() shouldn't be called when changing | 350 // TextfieldController::ContentsChanged() shouldn't be called when changing |
| 365 // text programmatically. | 351 // text programmatically. |
| 366 last_contents_.clear(); | 352 last_contents_.clear(); |
| 367 textfield_->SetText(ASCIIToUTF16("this is")); | 353 textfield_->SetText(ASCIIToUTF16("this is")); |
| 368 | 354 |
| 369 EXPECT_STR_EQ("this is", model_->GetText()); | 355 EXPECT_STR_EQ("this is", model_->text()); |
| 370 EXPECT_STR_EQ("this is", textfield_->text()); | 356 EXPECT_STR_EQ("this is", textfield_->text()); |
| 371 EXPECT_TRUE(last_contents_.empty()); | 357 EXPECT_TRUE(last_contents_.empty()); |
| 372 | 358 |
| 373 textfield_->AppendText(ASCIIToUTF16(" a test")); | 359 textfield_->AppendText(ASCIIToUTF16(" a test")); |
| 374 EXPECT_STR_EQ("this is a test", model_->GetText()); | 360 EXPECT_STR_EQ("this is a test", model_->text()); |
| 375 EXPECT_STR_EQ("this is a test", textfield_->text()); | 361 EXPECT_STR_EQ("this is a test", textfield_->text()); |
| 376 EXPECT_TRUE(last_contents_.empty()); | 362 EXPECT_TRUE(last_contents_.empty()); |
| 377 | 363 |
| 378 EXPECT_EQ(base::string16(), textfield_->GetSelectedText()); | 364 EXPECT_EQ(base::string16(), textfield_->GetSelectedText()); |
| 379 textfield_->SelectAll(false); | 365 textfield_->SelectAll(false); |
| 380 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); | 366 EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText()); |
| 381 EXPECT_TRUE(last_contents_.empty()); | 367 EXPECT_TRUE(last_contents_.empty()); |
| 382 } | 368 } |
| 383 | 369 |
| 384 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) { | 370 TEST_F(TextfieldTest, ModelChangesTestLowerCase) { |
| 385 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. | 371 // Check if |model_|'s text is properly lowercased for STYLE_LOWERCASE. |
| 386 InitTextfield(Textfield::STYLE_LOWERCASE); | 372 InitTextfield(Textfield::STYLE_LOWERCASE); |
| 387 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 373 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 388 | 374 |
| 389 last_contents_.clear(); | 375 last_contents_.clear(); |
| 390 textfield_->SetText(ASCIIToUTF16("THIS IS")); | 376 textfield_->SetText(ASCIIToUTF16("THIS IS")); |
| 391 EXPECT_EQ(7U, textfield_->GetCursorPosition()); | 377 EXPECT_EQ(7U, textfield_->GetCursorPosition()); |
| 392 | 378 |
| 393 EXPECT_STR_EQ("this is", model_->GetText()); | 379 EXPECT_STR_EQ("this is", textfield_->text()); |
| 394 EXPECT_STR_EQ("THIS IS", textfield_->text()); | |
| 395 EXPECT_TRUE(last_contents_.empty()); | 380 EXPECT_TRUE(last_contents_.empty()); |
| 396 | 381 |
| 397 textfield_->AppendText(ASCIIToUTF16(" A TEST")); | 382 textfield_->AppendText(ASCIIToUTF16(" A TEST")); |
| 398 EXPECT_EQ(7U, textfield_->GetCursorPosition()); | 383 EXPECT_EQ(7U, textfield_->GetCursorPosition()); |
| 399 EXPECT_STR_EQ("this is a test", model_->GetText()); | 384 EXPECT_STR_EQ("this is a test", textfield_->text()); |
| 400 EXPECT_STR_EQ("THIS IS A TEST", textfield_->text()); | |
| 401 | 385 |
| 402 EXPECT_TRUE(last_contents_.empty()); | 386 EXPECT_TRUE(last_contents_.empty()); |
| 403 } | 387 } |
| 404 | 388 |
| 405 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseI18n) { | 389 TEST_F(TextfieldTest, ModelChangesTestLowerCaseI18n) { |
| 406 // Check if lower case conversion works for non-ASCII characters. | 390 // Check if lower case conversion works for non-ASCII characters. |
| 407 InitTextfield(Textfield::STYLE_LOWERCASE); | 391 InitTextfield(Textfield::STYLE_LOWERCASE); |
| 408 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 392 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 409 | 393 |
| 410 last_contents_.clear(); | 394 last_contents_.clear(); |
| 411 // Zenkaku Japanese "ABCabc" | 395 // Zenkaku Japanese "ABCabc" |
| 412 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43")); | 396 textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43")); |
| 413 EXPECT_EQ(6U, textfield_->GetCursorPosition()); | 397 EXPECT_EQ(6U, textfield_->GetCursorPosition()); |
| 414 // Zenkaku Japanese "abcabc" | 398 // Zenkaku Japanese "abcabc" |
| 415 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"), | 399 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"), |
| 416 model_->GetText()); | |
| 417 // Zenkaku Japanese "ABCabc" | |
| 418 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43"), | |
| 419 textfield_->text()); | 400 textfield_->text()); |
| 420 EXPECT_TRUE(last_contents_.empty()); | 401 EXPECT_TRUE(last_contents_.empty()); |
| 421 | 402 |
| 422 // Zenkaku Japanese "XYZxyz" | 403 // Zenkaku Japanese "XYZxyz" |
| 423 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A")); | 404 textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A")); |
| 424 EXPECT_EQ(6U, textfield_->GetCursorPosition()); | 405 EXPECT_EQ(6U, textfield_->GetCursorPosition()); |
| 425 // Zenkaku Japanese "abcabcxyzxyz" | 406 // Zenkaku Japanese "abcabcxyzxyz" |
| 426 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43" | 407 EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43" |
| 427 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"), | 408 L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"), |
| 428 model_->GetText()); | |
| 429 // Zenkaku Japanese "ABCabcXYZxyz" | |
| 430 EXPECT_EQ(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43" | |
| 431 L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A"), | |
| 432 textfield_->text()); | 409 textfield_->text()); |
| 433 EXPECT_TRUE(last_contents_.empty()); | 410 EXPECT_TRUE(last_contents_.empty()); |
| 434 } | 411 } |
| 435 | 412 |
| 436 TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseWithLocale) { | 413 TEST_F(TextfieldTest, ModelChangesTestLowerCaseWithLocale) { |
| 437 // Check if lower case conversion honors locale properly. | 414 // Check if lower case conversion honors locale properly. |
| 438 std::string locale = l10n_util::GetApplicationLocale(""); | 415 std::string locale = l10n_util::GetApplicationLocale(""); |
| 439 base::i18n::SetICUDefaultLocale("tr"); | 416 base::i18n::SetICUDefaultLocale("tr"); |
| 440 | 417 |
| 441 InitTextfield(Textfield::STYLE_LOWERCASE); | 418 InitTextfield(Textfield::STYLE_LOWERCASE); |
| 442 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 419 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 443 | 420 |
| 444 last_contents_.clear(); | 421 last_contents_.clear(); |
| 445 // Turkish 'I' should be converted to dotless 'i' (U+0131). | 422 // Turkish 'I' should be converted to dotless 'i' (U+0131). |
| 446 textfield_->SetText(WideToUTF16(L"I")); | 423 textfield_->SetText(WideToUTF16(L"I")); |
| 447 EXPECT_EQ(1U, textfield_->GetCursorPosition()); | 424 EXPECT_EQ(1U, textfield_->GetCursorPosition()); |
| 448 EXPECT_EQ(WideToUTF16(L"\x0131"), model_->GetText()); | 425 EXPECT_EQ(WideToUTF16(L"\x0131"), textfield_->text()); |
| 449 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); | |
| 450 EXPECT_TRUE(last_contents_.empty()); | 426 EXPECT_TRUE(last_contents_.empty()); |
| 451 | 427 |
| 452 base::i18n::SetICUDefaultLocale(locale); | 428 base::i18n::SetICUDefaultLocale(locale); |
| 453 | 429 |
| 454 // On default (en) locale, 'I' should be converted to 'i'. | 430 // On default (en) locale, 'I' should be converted to 'i'. |
| 455 textfield_->SetText(WideToUTF16(L"I")); | 431 textfield_->SetText(WideToUTF16(L"I")); |
| 456 EXPECT_EQ(1U, textfield_->GetCursorPosition()); | 432 EXPECT_EQ(1U, textfield_->GetCursorPosition()); |
| 457 EXPECT_EQ(WideToUTF16(L"i"), model_->GetText()); | 433 EXPECT_EQ(WideToUTF16(L"i"), textfield_->text()); |
| 458 EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); | |
| 459 EXPECT_TRUE(last_contents_.empty()); | 434 EXPECT_TRUE(last_contents_.empty()); |
| 460 } | 435 } |
| 461 | 436 |
| 462 TEST_F(NativeTextfieldViewsTest, KeyTest) { | 437 TEST_F(TextfieldTest, KeyTest) { |
| 463 InitTextfield(Textfield::STYLE_DEFAULT); | 438 InitTextfield(Textfield::STYLE_DEFAULT); |
| 464 // Event flags: key, alt, shift, ctrl, caps-lock. | 439 // Event flags: key, alt, shift, ctrl, caps-lock. |
| 465 SendKeyEvent(ui::VKEY_T, false, true, false, false); | 440 SendKeyEvent(ui::VKEY_T, false, true, false, false); |
| 466 SendKeyEvent(ui::VKEY_E, false, false, false, false); | 441 SendKeyEvent(ui::VKEY_E, false, false, false, false); |
| 467 SendKeyEvent(ui::VKEY_X, false, true, false, true); | 442 SendKeyEvent(ui::VKEY_X, false, true, false, true); |
| 468 SendKeyEvent(ui::VKEY_T, false, false, false, true); | 443 SendKeyEvent(ui::VKEY_T, false, false, false, true); |
| 469 SendKeyEvent(ui::VKEY_1, false, true, false, false); | 444 SendKeyEvent(ui::VKEY_1, false, true, false, false); |
| 470 SendKeyEvent(ui::VKEY_1, false, false, false, false); | 445 SendKeyEvent(ui::VKEY_1, false, false, false, false); |
| 471 SendKeyEvent(ui::VKEY_1, false, true, false, true); | 446 SendKeyEvent(ui::VKEY_1, false, true, false, true); |
| 472 SendKeyEvent(ui::VKEY_1, false, false, false, true); | 447 SendKeyEvent(ui::VKEY_1, false, false, false, true); |
| 473 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); | 448 EXPECT_STR_EQ("TexT!1!1", textfield_->text()); |
| 474 } | 449 } |
| 475 | 450 |
| 476 TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { | 451 TEST_F(TextfieldTest, ControlAndSelectTest) { |
| 477 // Insert a test string in a textfield. | 452 // Insert a test string in a textfield. |
| 478 InitTextfield(Textfield::STYLE_DEFAULT); | 453 InitTextfield(Textfield::STYLE_DEFAULT); |
| 479 textfield_->SetText(ASCIIToUTF16("one two three")); | 454 textfield_->SetText(ASCIIToUTF16("one two three")); |
| 480 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); | 455 SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); |
| 481 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 456 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 482 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 457 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 483 SendKeyEvent(ui::VKEY_RIGHT, true, false); | 458 SendKeyEvent(ui::VKEY_RIGHT, true, false); |
| 484 | 459 |
| 485 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); | 460 EXPECT_STR_EQ("one", textfield_->GetSelectedText()); |
| 486 | 461 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 501 SendKeyEvent(ui::VKEY_O, true, false); | 476 SendKeyEvent(ui::VKEY_O, true, false); |
| 502 SendKeyEvent(ui::VKEY_SPACE, false, false); | 477 SendKeyEvent(ui::VKEY_SPACE, false, false); |
| 503 EXPECT_STR_EQ("ZERO two three", textfield_->text()); | 478 EXPECT_STR_EQ("ZERO two three", textfield_->text()); |
| 504 | 479 |
| 505 SendKeyEvent(ui::VKEY_END, true, false); | 480 SendKeyEvent(ui::VKEY_END, true, false); |
| 506 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); | 481 EXPECT_STR_EQ("two three", textfield_->GetSelectedText()); |
| 507 SendKeyEvent(ui::VKEY_HOME, true, false); | 482 SendKeyEvent(ui::VKEY_HOME, true, false); |
| 508 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); | 483 EXPECT_STR_EQ("ZERO ", textfield_->GetSelectedText()); |
| 509 } | 484 } |
| 510 | 485 |
| 511 TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) { | 486 TEST_F(TextfieldTest, InsertionDeletionTest) { |
| 512 // Insert a test string in a textfield. | 487 // Insert a test string in a textfield. |
| 513 InitTextfield(Textfield::STYLE_DEFAULT); | 488 InitTextfield(Textfield::STYLE_DEFAULT); |
| 514 for (size_t i = 0; i < 10; i++) | 489 for (size_t i = 0; i < 10; i++) |
| 515 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); | 490 SendKeyEvent(static_cast<ui::KeyboardCode>(ui::VKEY_A + i)); |
| 516 EXPECT_STR_EQ("abcdefghij", textfield_->text()); | 491 EXPECT_STR_EQ("abcdefghij", textfield_->text()); |
| 517 | 492 |
| 518 // Test the delete and backspace keys. | 493 // Test the delete and backspace keys. |
| 519 textfield_->SelectRange(gfx::Range(5)); | 494 textfield_->SelectRange(gfx::Range(5)); |
| 520 for (int i = 0; i < 3; i++) | 495 for (int i = 0; i < 3; i++) |
| 521 SendKeyEvent(ui::VKEY_BACK); | 496 SendKeyEvent(ui::VKEY_BACK); |
| 522 EXPECT_STR_EQ("abfghij", textfield_->text()); | 497 EXPECT_STR_EQ("abfghij", textfield_->text()); |
| 523 for (int i = 0; i < 3; i++) | 498 for (int i = 0; i < 3; i++) |
| 524 SendKeyEvent(ui::VKEY_DELETE); | 499 SendKeyEvent(ui::VKEY_DELETE); |
| 525 EXPECT_STR_EQ("abij", textfield_->text()); | 500 EXPECT_STR_EQ("abij", textfield_->text()); |
| 526 | 501 |
| 527 // Select all and replace with "k". | 502 // Select all and replace with "k". |
| 528 textfield_->SelectAll(false); | 503 textfield_->SelectAll(false); |
| 529 SendKeyEvent(ui::VKEY_K); | 504 SendKeyEvent(ui::VKEY_K); |
| 530 EXPECT_STR_EQ("k", textfield_->text()); | 505 EXPECT_STR_EQ("k", textfield_->text()); |
| 531 | 506 |
| 532 // Delete the previous word from cursor. | 507 // Delete the previous word from cursor. |
| 533 textfield_->SetText(ASCIIToUTF16("one two three four")); | 508 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 534 SendKeyEvent(ui::VKEY_END); | 509 SendKeyEvent(ui::VKEY_END); |
| 535 SendKeyEvent(ui::VKEY_BACK, false, false, true, false); | 510 SendKeyEvent(ui::VKEY_BACK, false, false, true, false); |
| 536 EXPECT_STR_EQ("one two three ", textfield_->text()); | 511 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 537 | 512 |
| 538 // Delete text preceeding the cursor in chromeos, do nothing in windows. | 513 // Delete to a line break on Linux and ChromeOS, no-op on Windows. |
| 539 SendKeyEvent(ui::VKEY_LEFT, false, false, true, false); | 514 SendKeyEvent(ui::VKEY_LEFT, false, false, true, false); |
| 540 SendKeyEvent(ui::VKEY_BACK, false, true, true, false); | 515 SendKeyEvent(ui::VKEY_BACK, false, true, true, false); |
| 541 #if defined(OS_WIN) | 516 #if defined(OS_LINUX) |
| 517 EXPECT_STR_EQ("three ", textfield_->text()); |
| 518 #else |
| 542 EXPECT_STR_EQ("one two three ", textfield_->text()); | 519 EXPECT_STR_EQ("one two three ", textfield_->text()); |
| 543 #else | |
| 544 EXPECT_STR_EQ("three ", textfield_->text()); | |
| 545 #endif | 520 #endif |
| 546 | 521 |
| 547 // Delete the next word from cursor. | 522 // Delete the next word from cursor. |
| 548 textfield_->SetText(ASCIIToUTF16("one two three four")); | 523 textfield_->SetText(ASCIIToUTF16("one two three four")); |
| 549 SendKeyEvent(ui::VKEY_HOME); | 524 SendKeyEvent(ui::VKEY_HOME); |
| 550 SendKeyEvent(ui::VKEY_DELETE, false, false, true, false); | 525 SendKeyEvent(ui::VKEY_DELETE, false, false, true, false); |
| 551 EXPECT_STR_EQ(" two three four", textfield_->text()); | 526 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 552 | 527 |
| 553 // Delete text following the cursor in chromeos, do nothing in windows. | 528 // Delete to a line break on Linux and ChromeOS, no-op on Windows. |
| 554 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); | 529 SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); |
| 555 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); | 530 SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); |
| 556 #if defined(OS_WIN) | 531 #if defined(OS_LINUX) |
| 532 EXPECT_STR_EQ(" two", textfield_->text()); |
| 533 #else |
| 557 EXPECT_STR_EQ(" two three four", textfield_->text()); | 534 EXPECT_STR_EQ(" two three four", textfield_->text()); |
| 558 #else | |
| 559 EXPECT_STR_EQ(" two", textfield_->text()); | |
| 560 #endif | 535 #endif |
| 561 } | 536 } |
| 562 | 537 |
| 563 TEST_F(NativeTextfieldViewsTest, PasswordTest) { | 538 TEST_F(TextfieldTest, PasswordTest) { |
| 564 InitTextfield(Textfield::STYLE_OBSCURED); | 539 InitTextfield(Textfield::STYLE_OBSCURED); |
| 565 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 540 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
| 566 EXPECT_TRUE(textfield_->enabled()); | 541 EXPECT_TRUE(textfield_->enabled()); |
| 567 EXPECT_TRUE(textfield_->focusable()); | 542 EXPECT_TRUE(textfield_->focusable()); |
| 568 | 543 |
| 569 last_contents_.clear(); | 544 last_contents_.clear(); |
| 570 textfield_->SetText(ASCIIToUTF16("password")); | 545 textfield_->SetText(ASCIIToUTF16("password")); |
| 571 // Ensure text() and the callback returns the actual text instead of "*". | 546 // Ensure text() and the callback returns the actual text instead of "*". |
| 572 EXPECT_STR_EQ("password", textfield_->text()); | 547 EXPECT_STR_EQ("password", textfield_->text()); |
| 573 EXPECT_TRUE(last_contents_.empty()); | 548 EXPECT_TRUE(last_contents_.empty()); |
| 574 model_->SelectAll(false); | 549 model_->SelectAll(false); |
| 575 SetClipboardText("foo"); | 550 SetClipboardText("foo"); |
| 576 | 551 |
| 577 // Cut and copy should be disabled. | 552 // Cut and copy should be disabled. |
| 578 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | 553 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 579 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | 554 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 580 SendKeyEvent(ui::VKEY_X, false, true); | 555 SendKeyEvent(ui::VKEY_X, false, true); |
| 581 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | 556 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 582 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | 557 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 583 SendKeyEvent(ui::VKEY_C, false, true); | 558 SendKeyEvent(ui::VKEY_C, false, true); |
| 584 SendKeyEvent(ui::VKEY_INSERT, false, true); | 559 SendKeyEvent(ui::VKEY_INSERT, false, true); |
| 585 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); | 560 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); |
| 586 EXPECT_STR_EQ("password", textfield_->text()); | 561 EXPECT_STR_EQ("password", textfield_->text()); |
| 587 // [Shift]+[Delete] should just delete without copying text to the clipboard. | 562 // [Shift]+[Delete] should just delete without copying text to the clipboard. |
| 588 textfield_->SelectAll(false); | 563 textfield_->SelectAll(false); |
| 589 SendKeyEvent(ui::VKEY_DELETE, true, false); | 564 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 590 | 565 |
| 591 // Paste should work normally. | 566 // Paste should work normally. |
| 592 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); | 567 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 593 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); | 568 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 594 SendKeyEvent(ui::VKEY_V, false, true); | 569 SendKeyEvent(ui::VKEY_V, false, true); |
| 595 SendKeyEvent(ui::VKEY_INSERT, true, false); | 570 SendKeyEvent(ui::VKEY_INSERT, true, false); |
| 596 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); | 571 EXPECT_STR_EQ("foo", base::string16(GetClipboardText())); |
| 597 EXPECT_STR_EQ("foofoofoo", textfield_->text()); | 572 EXPECT_STR_EQ("foofoofoo", textfield_->text()); |
| 598 } | 573 } |
| 599 | 574 |
| 600 TEST_F(NativeTextfieldViewsTest, InputTypeSetsObscured) { | 575 TEST_F(TextfieldTest, InputTypeSetsObscured) { |
| 601 InitTextfield(Textfield::STYLE_DEFAULT); | 576 InitTextfield(Textfield::STYLE_DEFAULT); |
| 602 | 577 |
| 603 // Defaults to TEXT | 578 // Defaults to TEXT |
| 604 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 579 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
| 605 | 580 |
| 606 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. | 581 // Setting to TEXT_INPUT_TYPE_PASSWORD also sets obscured state of textfield. |
| 607 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 582 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 608 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 583 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
| 609 EXPECT_TRUE(textfield_->IsObscured()); | 584 EXPECT_TRUE(textfield_->IsObscured()); |
| 610 } | 585 } |
| 611 | 586 |
| 612 TEST_F(NativeTextfieldViewsTest, ObscuredSetsInputType) { | 587 TEST_F(TextfieldTest, ObscuredSetsInputType) { |
| 613 InitTextfield(Textfield::STYLE_DEFAULT); | 588 InitTextfield(Textfield::STYLE_DEFAULT); |
| 614 | 589 |
| 615 // Defaults to TEXT | 590 // Defaults to TEXT |
| 616 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 591 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
| 617 | 592 |
| 618 textfield_->SetObscured(true); | 593 textfield_->SetObscured(true); |
| 619 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); | 594 EXPECT_EQ(ui::TEXT_INPUT_TYPE_PASSWORD, GetTextInputType()); |
| 620 | 595 |
| 621 textfield_->SetObscured(false); | 596 textfield_->SetObscured(false); |
| 622 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 597 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
| 623 } | 598 } |
| 624 | 599 |
| 625 TEST_F(NativeTextfieldViewsTest, TextInputType) { | 600 TEST_F(TextfieldTest, TextInputType) { |
| 626 InitTextfield(Textfield::STYLE_DEFAULT); | 601 InitTextfield(Textfield::STYLE_DEFAULT); |
| 627 | 602 |
| 628 // Defaults to TEXT | 603 // Defaults to TEXT |
| 629 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); | 604 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, GetTextInputType()); |
| 630 | 605 |
| 631 // And can be set. | 606 // And can be set. |
| 632 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 607 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
| 633 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 608 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); |
| 634 | 609 |
| 635 // Readonly textfields have type NONE | 610 // Readonly textfields have type NONE |
| 636 textfield_->SetReadOnly(true); | 611 textfield_->SetReadOnly(true); |
| 637 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 612 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
| 638 | 613 |
| 639 textfield_->SetReadOnly(false); | 614 textfield_->SetReadOnly(false); |
| 640 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); | 615 EXPECT_EQ(ui::TEXT_INPUT_TYPE_URL, GetTextInputType()); |
| 641 | 616 |
| 642 // As do disabled textfields | 617 // As do disabled textfields |
| 643 textfield_->SetEnabled(false); | 618 textfield_->SetEnabled(false); |
| 644 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); | 619 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, GetTextInputType()); |
| 645 } | 620 } |
| 646 | 621 |
| 647 TEST_F(NativeTextfieldViewsTest, OnKeyPressReturnValueTest) { | 622 TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { |
| 648 InitTextfield(Textfield::STYLE_DEFAULT); | 623 InitTextfield(Textfield::STYLE_DEFAULT); |
| 649 | 624 |
| 650 // Character keys will be handled by input method. | 625 // Character keys will be handled by input method. |
| 651 SendKeyEvent(ui::VKEY_A); | 626 SendKeyEvent(ui::VKEY_A); |
| 652 EXPECT_TRUE(textfield_->key_received()); | 627 EXPECT_TRUE(textfield_->key_received()); |
| 653 EXPECT_FALSE(textfield_->key_handled()); | 628 EXPECT_FALSE(textfield_->key_handled()); |
| 654 textfield_->clear(); | 629 textfield_->clear(); |
| 655 | 630 |
| 656 // Home will be handled. | 631 // Home will be handled. |
| 657 SendKeyEvent(ui::VKEY_HOME); | 632 SendKeyEvent(ui::VKEY_HOME); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 EXPECT_TRUE(textfield_->key_handled()); | 675 EXPECT_TRUE(textfield_->key_handled()); |
| 701 textfield_->clear(); | 676 textfield_->clear(); |
| 702 | 677 |
| 703 // Now left key should not be handled. | 678 // Now left key should not be handled. |
| 704 SendKeyEvent(ui::VKEY_LEFT); | 679 SendKeyEvent(ui::VKEY_LEFT); |
| 705 EXPECT_TRUE(textfield_->key_received()); | 680 EXPECT_TRUE(textfield_->key_received()); |
| 706 EXPECT_FALSE(textfield_->key_handled()); | 681 EXPECT_FALSE(textfield_->key_handled()); |
| 707 textfield_->clear(); | 682 textfield_->clear(); |
| 708 } | 683 } |
| 709 | 684 |
| 710 TEST_F(NativeTextfieldViewsTest, CursorMovement) { | 685 TEST_F(TextfieldTest, CursorMovement) { |
| 711 InitTextfield(Textfield::STYLE_DEFAULT); | 686 InitTextfield(Textfield::STYLE_DEFAULT); |
| 712 | 687 |
| 713 // Test with trailing whitespace. | 688 // Test with trailing whitespace. |
| 714 textfield_->SetText(ASCIIToUTF16("one two hre ")); | 689 textfield_->SetText(ASCIIToUTF16("one two hre ")); |
| 715 | 690 |
| 716 // Send the cursor at the end. | 691 // Send the cursor at the end. |
| 717 SendKeyEvent(ui::VKEY_END); | 692 SendKeyEvent(ui::VKEY_END); |
| 718 | 693 |
| 719 // Ctrl+Left should move the cursor just before the last word. | 694 // Ctrl+Left should move the cursor just before the last word. |
| 720 SendKeyEvent(ui::VKEY_LEFT, false, true); | 695 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 750 | 725 |
| 751 // Ctrl+Left to move the cursor to the beginning of the first word. | 726 // Ctrl+Left to move the cursor to the beginning of the first word. |
| 752 SendKeyEvent(ui::VKEY_LEFT, false, true); | 727 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 753 // Ctrl+Left again should move the cursor back to the very beginning. | 728 // Ctrl+Left again should move the cursor back to the very beginning. |
| 754 SendKeyEvent(ui::VKEY_LEFT, false, true); | 729 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 755 SendKeyEvent(ui::VKEY_DELETE); | 730 SendKeyEvent(ui::VKEY_DELETE); |
| 756 EXPECT_STR_EQ("one two", textfield_->text()); | 731 EXPECT_STR_EQ("one two", textfield_->text()); |
| 757 EXPECT_STR_EQ("one two", last_contents_); | 732 EXPECT_STR_EQ("one two", last_contents_); |
| 758 } | 733 } |
| 759 | 734 |
| 760 TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) { | 735 TEST_F(TextfieldTest, FocusTraversalTest) { |
| 761 InitTextfields(Textfield::STYLE_DEFAULT, 3); | 736 InitTextfields(Textfield::STYLE_DEFAULT, 3); |
| 762 textfield_->RequestFocus(); | 737 textfield_->RequestFocus(); |
| 763 | 738 |
| 764 EXPECT_EQ(1, GetFocusedView()->id()); | 739 EXPECT_EQ(1, GetFocusedView()->id()); |
| 765 widget_->GetFocusManager()->AdvanceFocus(false); | 740 widget_->GetFocusManager()->AdvanceFocus(false); |
| 766 EXPECT_EQ(2, GetFocusedView()->id()); | 741 EXPECT_EQ(2, GetFocusedView()->id()); |
| 767 widget_->GetFocusManager()->AdvanceFocus(false); | 742 widget_->GetFocusManager()->AdvanceFocus(false); |
| 768 EXPECT_EQ(3, GetFocusedView()->id()); | 743 EXPECT_EQ(3, GetFocusedView()->id()); |
| 769 // Cycle back to the first textfield. | 744 // Cycle back to the first textfield. |
| 770 widget_->GetFocusManager()->AdvanceFocus(false); | 745 widget_->GetFocusManager()->AdvanceFocus(false); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 782 | 757 |
| 783 // Request focus should still work. | 758 // Request focus should still work. |
| 784 textfield_->RequestFocus(); | 759 textfield_->RequestFocus(); |
| 785 EXPECT_EQ(1, GetFocusedView()->id()); | 760 EXPECT_EQ(1, GetFocusedView()->id()); |
| 786 | 761 |
| 787 // Test if clicking on textfield view sets the focus to textfield_. | 762 // Test if clicking on textfield view sets the focus to textfield_. |
| 788 widget_->GetFocusManager()->AdvanceFocus(true); | 763 widget_->GetFocusManager()->AdvanceFocus(true); |
| 789 EXPECT_EQ(3, GetFocusedView()->id()); | 764 EXPECT_EQ(3, GetFocusedView()->id()); |
| 790 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 765 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 791 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 766 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 792 textfield_view_->OnMousePressed(click); | 767 textfield_->OnMousePressed(click); |
| 793 EXPECT_EQ(1, GetFocusedView()->id()); | 768 EXPECT_EQ(1, GetFocusedView()->id()); |
| 794 } | 769 } |
| 795 | 770 |
| 796 TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) { | 771 TEST_F(TextfieldTest, ContextMenuDisplayTest) { |
| 797 InitTextfield(Textfield::STYLE_DEFAULT); | 772 InitTextfield(Textfield::STYLE_DEFAULT); |
| 798 EXPECT_TRUE(textfield_->context_menu_controller()); | 773 EXPECT_TRUE(textfield_->context_menu_controller()); |
| 799 textfield_->SetText(ASCIIToUTF16("hello world")); | 774 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 800 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); | 775 ui::Clipboard::GetForCurrentThread()->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 801 textfield_view_->ClearEditHistory(); | 776 textfield_->ClearEditHistory(); |
| 802 EXPECT_TRUE(GetContextMenuModel()); | 777 EXPECT_TRUE(GetContextMenuModel()); |
| 803 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); | 778 VerifyTextfieldContextMenuContents(false, false, GetContextMenuModel()); |
| 804 | 779 |
| 805 textfield_->SelectAll(false); | 780 textfield_->SelectAll(false); |
| 806 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); | 781 VerifyTextfieldContextMenuContents(true, false, GetContextMenuModel()); |
| 807 | 782 |
| 808 SendKeyEvent(ui::VKEY_T); | 783 SendKeyEvent(ui::VKEY_T); |
| 809 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); | 784 VerifyTextfieldContextMenuContents(false, true, GetContextMenuModel()); |
| 810 | 785 |
| 811 textfield_->SelectAll(false); | 786 textfield_->SelectAll(false); |
| 812 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 787 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
| 813 | 788 |
| 814 // Exercise the "paste enabled?" check in the verifier. | 789 // Exercise the "paste enabled?" check in the verifier. |
| 815 SetClipboardText("Test"); | 790 SetClipboardText("Test"); |
| 816 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); | 791 VerifyTextfieldContextMenuContents(true, true, GetContextMenuModel()); |
| 817 } | 792 } |
| 818 | 793 |
| 819 TEST_F(NativeTextfieldViewsTest, DoubleAndTripleClickTest) { | 794 TEST_F(TextfieldTest, DoubleAndTripleClickTest) { |
| 820 InitTextfield(Textfield::STYLE_DEFAULT); | 795 InitTextfield(Textfield::STYLE_DEFAULT); |
| 821 textfield_->SetText(ASCIIToUTF16("hello world")); | 796 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 822 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 797 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 823 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 798 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 824 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 799 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 825 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 800 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 826 ui::MouseEvent double_click( | 801 ui::MouseEvent double_click( |
| 827 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 802 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 828 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, | 803 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK, |
| 829 ui::EF_LEFT_MOUSE_BUTTON); | 804 ui::EF_LEFT_MOUSE_BUTTON); |
| 830 | 805 |
| 831 // Test for double click. | 806 // Test for double click. |
| 832 textfield_view_->OnMousePressed(click); | 807 textfield_->OnMousePressed(click); |
| 833 textfield_view_->OnMouseReleased(release); | 808 textfield_->OnMouseReleased(release); |
| 834 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | 809 EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
| 835 textfield_view_->OnMousePressed(double_click); | 810 textfield_->OnMousePressed(double_click); |
| 836 textfield_view_->OnMouseReleased(release); | 811 textfield_->OnMouseReleased(release); |
| 837 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 812 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 838 | 813 |
| 839 // Test for triple click. | 814 // Test for triple click. |
| 840 textfield_view_->OnMousePressed(click); | 815 textfield_->OnMousePressed(click); |
| 841 textfield_view_->OnMouseReleased(release); | 816 textfield_->OnMouseReleased(release); |
| 842 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); | 817 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); |
| 843 | 818 |
| 844 // Another click should reset back to double click. | 819 // Another click should reset back to double click. |
| 845 textfield_view_->OnMousePressed(click); | 820 textfield_->OnMousePressed(click); |
| 846 textfield_view_->OnMouseReleased(release); | 821 textfield_->OnMouseReleased(release); |
| 847 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 822 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 848 } | 823 } |
| 849 | 824 |
| 850 TEST_F(NativeTextfieldViewsTest, DragToSelect) { | 825 TEST_F(TextfieldTest, DragToSelect) { |
| 851 InitTextfield(Textfield::STYLE_DEFAULT); | 826 InitTextfield(Textfield::STYLE_DEFAULT); |
| 852 textfield_->SetText(ASCIIToUTF16("hello world")); | 827 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 853 const int kStart = GetCursorPositionX(5); | 828 const int kStart = GetCursorPositionX(5); |
| 854 const int kEnd = 500; | 829 const int kEnd = 500; |
| 855 gfx::Point start_point(kStart, 0); | 830 gfx::Point start_point(kStart, 0); |
| 856 gfx::Point end_point(kEnd, 0); | 831 gfx::Point end_point(kEnd, 0); |
| 857 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, | 832 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, start_point, start_point, |
| 858 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 833 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 859 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, | 834 ui::MouseEvent click_b(ui::ET_MOUSE_PRESSED, end_point, end_point, |
| 860 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 835 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 861 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), | 836 ui::MouseEvent drag_left(ui::ET_MOUSE_DRAGGED, gfx::Point(), gfx::Point(), |
| 862 ui::EF_LEFT_MOUSE_BUTTON, 0); | 837 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 863 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, | 838 ui::MouseEvent drag_right(ui::ET_MOUSE_DRAGGED, end_point, end_point, |
| 864 ui::EF_LEFT_MOUSE_BUTTON, 0); | 839 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 865 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, | 840 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, end_point, end_point, |
| 866 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 841 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 867 textfield_view_->OnMousePressed(click_a); | 842 textfield_->OnMousePressed(click_a); |
| 868 EXPECT_TRUE(textfield_->GetSelectedText().empty()); | 843 EXPECT_TRUE(textfield_->GetSelectedText().empty()); |
| 869 // Check that dragging left selects the beginning of the string. | 844 // Check that dragging left selects the beginning of the string. |
| 870 textfield_view_->OnMouseDragged(drag_left); | 845 textfield_->OnMouseDragged(drag_left); |
| 871 base::string16 text_left = textfield_->GetSelectedText(); | 846 base::string16 text_left = textfield_->GetSelectedText(); |
| 872 EXPECT_STR_EQ("hello", text_left); | 847 EXPECT_STR_EQ("hello", text_left); |
| 873 // Check that dragging right selects the rest of the string. | 848 // Check that dragging right selects the rest of the string. |
| 874 textfield_view_->OnMouseDragged(drag_right); | 849 textfield_->OnMouseDragged(drag_right); |
| 875 base::string16 text_right = textfield_->GetSelectedText(); | 850 base::string16 text_right = textfield_->GetSelectedText(); |
| 876 EXPECT_STR_EQ(" world", text_right); | 851 EXPECT_STR_EQ(" world", text_right); |
| 877 // Check that releasing in the same location does not alter the selection. | 852 // Check that releasing in the same location does not alter the selection. |
| 878 textfield_view_->OnMouseReleased(release); | 853 textfield_->OnMouseReleased(release); |
| 879 EXPECT_EQ(text_right, textfield_->GetSelectedText()); | 854 EXPECT_EQ(text_right, textfield_->GetSelectedText()); |
| 880 // Check that dragging from beyond the text length works too. | 855 // Check that dragging from beyond the text length works too. |
| 881 textfield_view_->OnMousePressed(click_b); | 856 textfield_->OnMousePressed(click_b); |
| 882 textfield_view_->OnMouseDragged(drag_left); | 857 textfield_->OnMouseDragged(drag_left); |
| 883 textfield_view_->OnMouseReleased(release); | 858 textfield_->OnMouseReleased(release); |
| 884 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); | 859 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); |
| 885 } | 860 } |
| 886 | 861 |
| 887 #if defined(OS_WIN) | 862 #if defined(OS_WIN) |
| 888 TEST_F(NativeTextfieldViewsTest, DragAndDrop_AcceptDrop) { | 863 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { |
| 889 InitTextfield(Textfield::STYLE_DEFAULT); | 864 InitTextfield(Textfield::STYLE_DEFAULT); |
| 890 textfield_->SetText(ASCIIToUTF16("hello world")); | 865 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 891 | 866 |
| 892 ui::OSExchangeData data; | 867 ui::OSExchangeData data; |
| 893 base::string16 string(ASCIIToUTF16("string ")); | 868 base::string16 string(ASCIIToUTF16("string ")); |
| 894 data.SetString(string); | 869 data.SetString(string); |
| 895 int formats = 0; | 870 int formats = 0; |
| 896 std::set<OSExchangeData::CustomFormat> custom_formats; | 871 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 897 | 872 |
| 898 // Ensure that disabled textfields do not accept drops. | 873 // Ensure that disabled textfields do not accept drops. |
| 899 textfield_->SetEnabled(false); | 874 textfield_->SetEnabled(false); |
| 900 EXPECT_FALSE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 875 EXPECT_FALSE(textfield_->GetDropFormats(&formats, &custom_formats)); |
| 901 EXPECT_EQ(0, formats); | 876 EXPECT_EQ(0, formats); |
| 902 EXPECT_TRUE(custom_formats.empty()); | 877 EXPECT_TRUE(custom_formats.empty()); |
| 903 EXPECT_FALSE(textfield_view_->CanDrop(data)); | 878 EXPECT_FALSE(textfield_->CanDrop(data)); |
| 904 textfield_->SetEnabled(true); | 879 textfield_->SetEnabled(true); |
| 905 | 880 |
| 906 // Ensure that read-only textfields do not accept drops. | 881 // Ensure that read-only textfields do not accept drops. |
| 907 textfield_->SetReadOnly(true); | 882 textfield_->SetReadOnly(true); |
| 908 EXPECT_FALSE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 883 EXPECT_FALSE(textfield_->GetDropFormats(&formats, &custom_formats)); |
| 909 EXPECT_EQ(0, formats); | 884 EXPECT_EQ(0, formats); |
| 910 EXPECT_TRUE(custom_formats.empty()); | 885 EXPECT_TRUE(custom_formats.empty()); |
| 911 EXPECT_FALSE(textfield_view_->CanDrop(data)); | 886 EXPECT_FALSE(textfield_->CanDrop(data)); |
| 912 textfield_->SetReadOnly(false); | 887 textfield_->SetReadOnly(false); |
| 913 | 888 |
| 914 // Ensure that enabled and editable textfields do accept drops. | 889 // Ensure that enabled and editable textfields do accept drops. |
| 915 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 890 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
| 916 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 891 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
| 917 EXPECT_TRUE(custom_formats.empty()); | 892 EXPECT_TRUE(custom_formats.empty()); |
| 918 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 893 EXPECT_TRUE(textfield_->CanDrop(data)); |
| 919 gfx::Point drop_point(GetCursorPositionX(6), 0); | 894 gfx::Point drop_point(GetCursorPositionX(6), 0); |
| 920 ui::DropTargetEvent drop(data, drop_point, drop_point, | 895 ui::DropTargetEvent drop(data, drop_point, drop_point, |
| 921 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE); | 896 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE); |
| 922 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE, | 897 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE, |
| 923 textfield_view_->OnDragUpdated(drop)); | 898 textfield_->OnDragUpdated(drop)); |
| 924 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_view_->OnPerformDrop(drop)); | 899 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_->OnPerformDrop(drop)); |
| 925 EXPECT_STR_EQ("hello string world", textfield_->text()); | 900 EXPECT_STR_EQ("hello string world", textfield_->text()); |
| 926 | 901 |
| 927 // Ensure that textfields do not accept non-OSExchangeData::STRING types. | 902 // Ensure that textfields do not accept non-OSExchangeData::STRING types. |
| 928 ui::OSExchangeData bad_data; | 903 ui::OSExchangeData bad_data; |
| 929 bad_data.SetFilename(base::FilePath(FILE_PATH_LITERAL("x"))); | 904 bad_data.SetFilename(base::FilePath(FILE_PATH_LITERAL("x"))); |
| 930 #if defined(OS_WIN) | 905 #if defined(OS_WIN) |
| 931 ui::OSExchangeData::CustomFormat fmt = ui::Clipboard::GetBitmapFormatType(); | 906 ui::OSExchangeData::CustomFormat fmt = ui::Clipboard::GetBitmapFormatType(); |
| 932 bad_data.SetPickledData(fmt, Pickle()); | 907 bad_data.SetPickledData(fmt, Pickle()); |
| 933 bad_data.SetFileContents(base::FilePath(L"x"), "x"); | 908 bad_data.SetFileContents(base::FilePath(L"x"), "x"); |
| 934 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org")); | 909 bad_data.SetHtml(base::string16(ASCIIToUTF16("x")), GURL("x.org")); |
| 935 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); | 910 ui::OSExchangeData::DownloadFileInfo download(base::FilePath(), NULL); |
| 936 bad_data.SetDownloadFileInfo(download); | 911 bad_data.SetDownloadFileInfo(download); |
| 937 #endif | 912 #endif |
| 938 EXPECT_FALSE(textfield_view_->CanDrop(bad_data)); | 913 EXPECT_FALSE(textfield_->CanDrop(bad_data)); |
| 939 } | 914 } |
| 940 #endif | 915 #endif |
| 941 | 916 |
| 942 TEST_F(NativeTextfieldViewsTest, DragAndDrop_InitiateDrag) { | 917 TEST_F(TextfieldTest, DragAndDrop_InitiateDrag) { |
| 943 InitTextfield(Textfield::STYLE_DEFAULT); | 918 InitTextfield(Textfield::STYLE_DEFAULT); |
| 944 textfield_->SetText(ASCIIToUTF16("hello string world")); | 919 textfield_->SetText(ASCIIToUTF16("hello string world")); |
| 945 | 920 |
| 946 // Ensure the textfield will provide selected text for drag data. | 921 // Ensure the textfield will provide selected text for drag data. |
| 947 base::string16 string; | 922 base::string16 string; |
| 948 ui::OSExchangeData data; | 923 ui::OSExchangeData data; |
| 949 const gfx::Range kStringRange(6, 12); | 924 const gfx::Range kStringRange(6, 12); |
| 950 textfield_->SelectRange(kStringRange); | 925 textfield_->SelectRange(kStringRange); |
| 951 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 926 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
| 952 textfield_view_->WriteDragDataForView(NULL, kStringPoint, &data); | 927 textfield_->WriteDragDataForView(NULL, kStringPoint, &data); |
| 953 EXPECT_TRUE(data.GetString(&string)); | 928 EXPECT_TRUE(data.GetString(&string)); |
| 954 EXPECT_EQ(textfield_->GetSelectedText(), string); | 929 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| 955 | 930 |
| 956 // Ensure that disabled textfields do not support drag operations. | 931 // Ensure that disabled textfields do not support drag operations. |
| 957 textfield_->SetEnabled(false); | 932 textfield_->SetEnabled(false); |
| 958 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 933 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 959 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 934 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 960 textfield_->SetEnabled(true); | 935 textfield_->SetEnabled(true); |
| 961 // Ensure that textfields without selections do not support drag operations. | 936 // Ensure that textfields without selections do not support drag operations. |
| 962 textfield_->ClearSelection(); | 937 textfield_->ClearSelection(); |
| 963 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 938 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 964 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 939 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 965 textfield_->SelectRange(kStringRange); | 940 textfield_->SelectRange(kStringRange); |
| 966 // Ensure that password textfields do not support drag operations. | 941 // Ensure that password textfields do not support drag operations. |
| 967 textfield_->SetObscured(true); | 942 textfield_->SetObscured(true); |
| 968 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 943 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 969 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 944 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 970 textfield_->SetObscured(false); | 945 textfield_->SetObscured(false); |
| 971 // Ensure that textfields only initiate drag operations inside the selection. | 946 // Ensure that textfields only initiate drag operations inside the selection. |
| 972 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, | 947 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, kStringPoint, kStringPoint, |
| 973 ui::EF_LEFT_MOUSE_BUTTON, | 948 ui::EF_LEFT_MOUSE_BUTTON, |
| 974 ui::EF_LEFT_MOUSE_BUTTON); | 949 ui::EF_LEFT_MOUSE_BUTTON); |
| 975 textfield_view_->OnMousePressed(press_event); | 950 textfield_->OnMousePressed(press_event); |
| 976 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, | 951 EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, |
| 977 textfield_view_->GetDragOperationsForView(NULL, gfx::Point())); | 952 textfield_->GetDragOperationsForView(NULL, gfx::Point())); |
| 978 EXPECT_FALSE(textfield_view_->CanStartDragForView(NULL, gfx::Point(), | 953 EXPECT_FALSE(textfield_->CanStartDragForView(NULL, gfx::Point(), |
| 979 gfx::Point())); | 954 gfx::Point())); |
| 980 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, | 955 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, |
| 981 textfield_view_->GetDragOperationsForView(NULL, kStringPoint)); | 956 textfield_->GetDragOperationsForView(NULL, kStringPoint)); |
| 982 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, kStringPoint, | 957 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, |
| 983 gfx::Point())); | 958 gfx::Point())); |
| 984 // Ensure that textfields support local moves. | 959 // Ensure that textfields support local moves. |
| 985 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 960 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 986 textfield_view_->GetDragOperationsForView(textfield_view_, kStringPoint)); | 961 textfield_->GetDragOperationsForView(textfield_, kStringPoint)); |
| 987 } | 962 } |
| 988 | 963 |
| 989 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheRight) { | 964 TEST_F(TextfieldTest, DragAndDrop_ToTheRight) { |
| 990 InitTextfield(Textfield::STYLE_DEFAULT); | 965 InitTextfield(Textfield::STYLE_DEFAULT); |
| 991 textfield_->SetText(ASCIIToUTF16("hello world")); | 966 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 992 | 967 |
| 993 base::string16 string; | 968 base::string16 string; |
| 994 ui::OSExchangeData data; | 969 ui::OSExchangeData data; |
| 995 int formats = 0; | 970 int formats = 0; |
| 996 int operations = 0; | 971 int operations = 0; |
| 997 std::set<OSExchangeData::CustomFormat> custom_formats; | 972 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 998 | 973 |
| 999 // Start dragging "ello". | 974 // Start dragging "ello". |
| 1000 textfield_->SelectRange(gfx::Range(1, 5)); | 975 textfield_->SelectRange(gfx::Range(1, 5)); |
| 1001 gfx::Point point(GetCursorPositionX(3), 0); | 976 gfx::Point point(GetCursorPositionX(3), 0); |
| 1002 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 977 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
| 1003 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 978 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1004 textfield_view_->OnMousePressed(click_a); | 979 textfield_->OnMousePressed(click_a); |
| 1005 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 980 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), |
| 1006 click_a.location(), gfx::Point())); | 981 gfx::Point())); |
| 1007 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 982 operations = textfield_->GetDragOperationsForView(textfield_, |
| 1008 click_a.location()); | 983 click_a.location()); |
| 1009 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 984 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 1010 operations); | 985 operations); |
| 1011 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 986 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); |
| 1012 EXPECT_TRUE(data.GetString(&string)); | 987 EXPECT_TRUE(data.GetString(&string)); |
| 1013 EXPECT_EQ(textfield_->GetSelectedText(), string); | 988 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| 1014 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 989 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
| 1015 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 990 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
| 1016 EXPECT_TRUE(custom_formats.empty()); | 991 EXPECT_TRUE(custom_formats.empty()); |
| 1017 | 992 |
| 1018 // Drop "ello" after "w". | 993 // Drop "ello" after "w". |
| 1019 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); | 994 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); |
| 1020 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 995 EXPECT_TRUE(textfield_->CanDrop(data)); |
| 1021 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); | 996 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); |
| 1022 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 997 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); |
| 1023 textfield_view_->OnDragUpdated(drop_a)); | 998 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); |
| 1024 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | |
| 1025 textfield_view_->OnPerformDrop(drop_a)); | |
| 1026 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 999 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| 1027 textfield_view_->OnDragDone(); | 1000 textfield_->OnDragDone(); |
| 1028 | 1001 |
| 1029 // Undo/Redo the drag&drop change. | 1002 // Undo/Redo the drag&drop change. |
| 1030 SendKeyEvent(ui::VKEY_Z, false, true); | 1003 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1031 EXPECT_STR_EQ("hello world", textfield_->text()); | 1004 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1032 SendKeyEvent(ui::VKEY_Z, false, true); | 1005 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1033 EXPECT_STR_EQ("", textfield_->text()); | 1006 EXPECT_STR_EQ("", textfield_->text()); |
| 1034 SendKeyEvent(ui::VKEY_Z, false, true); | 1007 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1035 EXPECT_STR_EQ("", textfield_->text()); | 1008 EXPECT_STR_EQ("", textfield_->text()); |
| 1036 SendKeyEvent(ui::VKEY_Y, false, true); | 1009 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1037 EXPECT_STR_EQ("hello world", textfield_->text()); | 1010 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1038 SendKeyEvent(ui::VKEY_Y, false, true); | 1011 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1039 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 1012 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| 1040 SendKeyEvent(ui::VKEY_Y, false, true); | 1013 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1041 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 1014 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
| 1042 } | 1015 } |
| 1043 | 1016 |
| 1044 TEST_F(NativeTextfieldViewsTest, DragAndDrop_ToTheLeft) { | 1017 TEST_F(TextfieldTest, DragAndDrop_ToTheLeft) { |
| 1045 InitTextfield(Textfield::STYLE_DEFAULT); | 1018 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1046 textfield_->SetText(ASCIIToUTF16("hello world")); | 1019 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1047 | 1020 |
| 1048 base::string16 string; | 1021 base::string16 string; |
| 1049 ui::OSExchangeData data; | 1022 ui::OSExchangeData data; |
| 1050 int formats = 0; | 1023 int formats = 0; |
| 1051 int operations = 0; | 1024 int operations = 0; |
| 1052 std::set<OSExchangeData::CustomFormat> custom_formats; | 1025 std::set<OSExchangeData::CustomFormat> custom_formats; |
| 1053 | 1026 |
| 1054 // Start dragging " worl". | 1027 // Start dragging " worl". |
| 1055 textfield_->SelectRange(gfx::Range(5, 10)); | 1028 textfield_->SelectRange(gfx::Range(5, 10)); |
| 1056 gfx::Point point(GetCursorPositionX(7), 0); | 1029 gfx::Point point(GetCursorPositionX(7), 0); |
| 1057 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, | 1030 ui::MouseEvent click_a(ui::ET_MOUSE_PRESSED, point, point, |
| 1058 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1031 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1059 textfield_view_->OnMousePressed(click_a); | 1032 textfield_->OnMousePressed(click_a); |
| 1060 EXPECT_TRUE(textfield_view_->CanStartDragForView(textfield_view_, | 1033 EXPECT_TRUE(textfield_->CanStartDragForView(textfield_, click_a.location(), |
| 1061 click_a.location(), gfx::Point())); | 1034 gfx::Point())); |
| 1062 operations = textfield_view_->GetDragOperationsForView(textfield_view_, | 1035 operations = textfield_->GetDragOperationsForView(textfield_, |
| 1063 click_a.location()); | 1036 click_a.location()); |
| 1064 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, | 1037 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE | ui::DragDropTypes::DRAG_COPY, |
| 1065 operations); | 1038 operations); |
| 1066 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 1039 textfield_->WriteDragDataForView(NULL, click_a.location(), &data); |
| 1067 EXPECT_TRUE(data.GetString(&string)); | 1040 EXPECT_TRUE(data.GetString(&string)); |
| 1068 EXPECT_EQ(textfield_->GetSelectedText(), string); | 1041 EXPECT_EQ(textfield_->GetSelectedText(), string); |
| 1069 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 1042 EXPECT_TRUE(textfield_->GetDropFormats(&formats, &custom_formats)); |
| 1070 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 1043 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
| 1071 EXPECT_TRUE(custom_formats.empty()); | 1044 EXPECT_TRUE(custom_formats.empty()); |
| 1072 | 1045 |
| 1073 // Drop " worl" after "h". | 1046 // Drop " worl" after "h". |
| 1074 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 1047 EXPECT_TRUE(textfield_->CanDrop(data)); |
| 1075 gfx::Point drop_point(GetCursorPositionX(1), 0); | 1048 gfx::Point drop_point(GetCursorPositionX(1), 0); |
| 1076 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); | 1049 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); |
| 1077 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 1050 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop_a)); |
| 1078 textfield_view_->OnDragUpdated(drop_a)); | 1051 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnPerformDrop(drop_a)); |
| 1079 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | |
| 1080 textfield_view_->OnPerformDrop(drop_a)); | |
| 1081 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1052 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 1082 textfield_view_->OnDragDone(); | 1053 textfield_->OnDragDone(); |
| 1083 | 1054 |
| 1084 // Undo/Redo the drag&drop change. | 1055 // Undo/Redo the drag&drop change. |
| 1085 SendKeyEvent(ui::VKEY_Z, false, true); | 1056 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1086 EXPECT_STR_EQ("hello world", textfield_->text()); | 1057 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1087 SendKeyEvent(ui::VKEY_Z, false, true); | 1058 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1088 EXPECT_STR_EQ("", textfield_->text()); | 1059 EXPECT_STR_EQ("", textfield_->text()); |
| 1089 SendKeyEvent(ui::VKEY_Z, false, true); | 1060 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1090 EXPECT_STR_EQ("", textfield_->text()); | 1061 EXPECT_STR_EQ("", textfield_->text()); |
| 1091 SendKeyEvent(ui::VKEY_Y, false, true); | 1062 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1092 EXPECT_STR_EQ("hello world", textfield_->text()); | 1063 EXPECT_STR_EQ("hello world", textfield_->text()); |
| 1093 SendKeyEvent(ui::VKEY_Y, false, true); | 1064 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1094 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1065 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 1095 SendKeyEvent(ui::VKEY_Y, false, true); | 1066 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1096 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1067 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
| 1097 } | 1068 } |
| 1098 | 1069 |
| 1099 TEST_F(NativeTextfieldViewsTest, DragAndDrop_Canceled) { | 1070 TEST_F(TextfieldTest, DragAndDrop_Canceled) { |
| 1100 InitTextfield(Textfield::STYLE_DEFAULT); | 1071 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1101 textfield_->SetText(ASCIIToUTF16("hello world")); | 1072 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1102 | 1073 |
| 1103 // Start dragging "worl". | 1074 // Start dragging "worl". |
| 1104 textfield_->SelectRange(gfx::Range(6, 10)); | 1075 textfield_->SelectRange(gfx::Range(6, 10)); |
| 1105 gfx::Point point(GetCursorPositionX(8), 0); | 1076 gfx::Point point(GetCursorPositionX(8), 0); |
| 1106 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 1077 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
| 1107 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1078 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1108 textfield_view_->OnMousePressed(click); | 1079 textfield_->OnMousePressed(click); |
| 1109 ui::OSExchangeData data; | 1080 ui::OSExchangeData data; |
| 1110 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); | 1081 textfield_->WriteDragDataForView(NULL, click.location(), &data); |
| 1111 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 1082 EXPECT_TRUE(textfield_->CanDrop(data)); |
| 1112 // Drag the text over somewhere valid, outside the current selection. | 1083 // Drag the text over somewhere valid, outside the current selection. |
| 1113 gfx::Point drop_point(GetCursorPositionX(2), 0); | 1084 gfx::Point drop_point(GetCursorPositionX(2), 0); |
| 1114 ui::DropTargetEvent drop(data, drop_point, drop_point, | 1085 ui::DropTargetEvent drop(data, drop_point, drop_point, |
| 1115 ui::DragDropTypes::DRAG_MOVE); | 1086 ui::DragDropTypes::DRAG_MOVE); |
| 1116 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); | 1087 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_->OnDragUpdated(drop)); |
| 1117 // "Cancel" the drag, via move and release over the selection, and OnDragDone. | 1088 // "Cancel" the drag, via move and release over the selection, and OnDragDone. |
| 1118 gfx::Point drag_point(GetCursorPositionX(9), 0); | 1089 gfx::Point drag_point(GetCursorPositionX(9), 0); |
| 1119 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, | 1090 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, |
| 1120 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1091 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1121 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, | 1092 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, |
| 1122 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1093 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1123 textfield_view_->OnMouseDragged(drag); | 1094 textfield_->OnMouseDragged(drag); |
| 1124 textfield_view_->OnMouseReleased(release); | 1095 textfield_->OnMouseReleased(release); |
| 1125 textfield_view_->OnDragDone(); | 1096 textfield_->OnDragDone(); |
| 1126 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); | 1097 EXPECT_EQ(ASCIIToUTF16("hello world"), textfield_->text()); |
| 1127 } | 1098 } |
| 1128 | 1099 |
| 1129 TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) { | 1100 TEST_F(TextfieldTest, ReadOnlyTest) { |
| 1130 InitTextfield(Textfield::STYLE_DEFAULT); | 1101 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1131 textfield_->SetText(ASCIIToUTF16("read only")); | 1102 textfield_->SetText(ASCIIToUTF16("read only")); |
| 1132 textfield_->SetReadOnly(true); | 1103 textfield_->SetReadOnly(true); |
| 1133 EXPECT_TRUE(textfield_->enabled()); | 1104 EXPECT_TRUE(textfield_->enabled()); |
| 1134 EXPECT_TRUE(textfield_->focusable()); | 1105 EXPECT_TRUE(textfield_->focusable()); |
| 1135 | 1106 |
| 1136 SendKeyEvent(ui::VKEY_HOME); | 1107 SendKeyEvent(ui::VKEY_HOME); |
| 1137 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1108 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 1138 SendKeyEvent(ui::VKEY_END); | 1109 SendKeyEvent(ui::VKEY_END); |
| 1139 EXPECT_EQ(9U, textfield_->GetCursorPosition()); | 1110 EXPECT_EQ(9U, textfield_->GetCursorPosition()); |
| 1140 | 1111 |
| 1141 SendKeyEvent(ui::VKEY_LEFT, false, false); | 1112 SendKeyEvent(ui::VKEY_LEFT, false, false); |
| 1142 EXPECT_EQ(8U, textfield_->GetCursorPosition()); | 1113 EXPECT_EQ(8U, textfield_->GetCursorPosition()); |
| 1143 SendKeyEvent(ui::VKEY_LEFT, false, true); | 1114 SendKeyEvent(ui::VKEY_LEFT, false, true); |
| 1144 EXPECT_EQ(5U, textfield_->GetCursorPosition()); | 1115 EXPECT_EQ(5U, textfield_->GetCursorPosition()); |
| 1145 SendKeyEvent(ui::VKEY_LEFT, true, true); | 1116 SendKeyEvent(ui::VKEY_LEFT, true, true); |
| 1146 EXPECT_EQ(0U, textfield_->GetCursorPosition()); | 1117 EXPECT_EQ(0U, textfield_->GetCursorPosition()); |
| 1147 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); | 1118 EXPECT_STR_EQ("read ", textfield_->GetSelectedText()); |
| 1148 textfield_->SelectAll(false); | 1119 textfield_->SelectAll(false); |
| 1149 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); | 1120 EXPECT_STR_EQ("read only", textfield_->GetSelectedText()); |
| 1150 | 1121 |
| 1151 // Cut should be disabled. | 1122 // Cut should be disabled. |
| 1152 SetClipboardText("Test"); | 1123 SetClipboardText("Test"); |
| 1153 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | 1124 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 1154 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | 1125 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 1155 SendKeyEvent(ui::VKEY_X, false, true); | 1126 SendKeyEvent(ui::VKEY_X, false, true); |
| 1156 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1127 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 1157 EXPECT_STR_EQ("Test", base::string16(GetClipboardText())); | 1128 EXPECT_STR_EQ("Test", base::string16(GetClipboardText())); |
| 1158 EXPECT_STR_EQ("read only", textfield_->text()); | 1129 EXPECT_STR_EQ("read only", textfield_->text()); |
| 1159 | 1130 |
| 1160 // Paste should be disabled. | 1131 // Paste should be disabled. |
| 1161 EXPECT_FALSE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1132 EXPECT_FALSE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 1162 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); | 1133 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 1163 SendKeyEvent(ui::VKEY_V, false, true); | 1134 SendKeyEvent(ui::VKEY_V, false, true); |
| 1164 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1135 SendKeyEvent(ui::VKEY_INSERT, true, false); |
| 1165 EXPECT_STR_EQ("read only", textfield_->text()); | 1136 EXPECT_STR_EQ("read only", textfield_->text()); |
| 1166 | 1137 |
| 1167 // Copy should work normally. | 1138 // Copy should work normally. |
| 1168 SetClipboardText("Test"); | 1139 SetClipboardText("Test"); |
| 1169 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | 1140 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1170 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | 1141 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1171 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1142 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); |
| 1172 SetClipboardText("Test"); | 1143 SetClipboardText("Test"); |
| 1173 SendKeyEvent(ui::VKEY_C, false, true); | 1144 SendKeyEvent(ui::VKEY_C, false, true); |
| 1174 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1145 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); |
| 1175 SetClipboardText("Test"); | 1146 SetClipboardText("Test"); |
| 1176 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1147 SendKeyEvent(ui::VKEY_INSERT, false, true); |
| 1177 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); | 1148 EXPECT_STR_EQ("read only", base::string16(GetClipboardText())); |
| 1178 | 1149 |
| 1179 // SetText should work even in read only mode. | 1150 // SetText should work even in read only mode. |
| 1180 textfield_->SetText(ASCIIToUTF16(" four five six ")); | 1151 textfield_->SetText(ASCIIToUTF16(" four five six ")); |
| 1181 EXPECT_STR_EQ(" four five six ", textfield_->text()); | 1152 EXPECT_STR_EQ(" four five six ", textfield_->text()); |
| 1182 | 1153 |
| 1183 textfield_->SelectAll(false); | 1154 textfield_->SelectAll(false); |
| 1184 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1155 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1185 | 1156 |
| 1186 // Text field is unmodifiable and selection shouldn't change. | 1157 // Text field is unmodifiable and selection shouldn't change. |
| 1187 SendKeyEvent(ui::VKEY_DELETE); | 1158 SendKeyEvent(ui::VKEY_DELETE); |
| 1188 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1159 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1189 SendKeyEvent(ui::VKEY_BACK); | 1160 SendKeyEvent(ui::VKEY_BACK); |
| 1190 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1161 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1191 SendKeyEvent(ui::VKEY_T); | 1162 SendKeyEvent(ui::VKEY_T); |
| 1192 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); | 1163 EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText()); |
| 1193 } | 1164 } |
| 1194 | 1165 |
| 1195 TEST_F(NativeTextfieldViewsTest, TextInputClientTest) { | 1166 TEST_F(TextfieldTest, TextInputClientTest) { |
| 1196 InitTextfield(Textfield::STYLE_DEFAULT); | 1167 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1197 ui::TextInputClient* client = textfield_->GetTextInputClient(); | 1168 ui::TextInputClient* client = textfield_->GetTextInputClient(); |
| 1198 EXPECT_TRUE(client); | 1169 EXPECT_TRUE(client); |
| 1199 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); | 1170 EXPECT_EQ(ui::TEXT_INPUT_TYPE_TEXT, client->GetTextInputType()); |
| 1200 | 1171 |
| 1201 textfield_->SetText(ASCIIToUTF16("0123456789")); | 1172 textfield_->SetText(ASCIIToUTF16("0123456789")); |
| 1202 gfx::Range range; | 1173 gfx::Range range; |
| 1203 EXPECT_TRUE(client->GetTextRange(&range)); | 1174 EXPECT_TRUE(client->GetTextRange(&range)); |
| 1204 EXPECT_EQ(0U, range.start()); | 1175 EXPECT_EQ(0U, range.start()); |
| 1205 EXPECT_EQ(10U, range.end()); | 1176 EXPECT_EQ(10U, range.end()); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1261 EXPECT_TRUE(input_method_->text_input_type_changed()); |
| 1291 EXPECT_FALSE(textfield_->GetTextInputClient()); | 1262 EXPECT_FALSE(textfield_->GetTextInputClient()); |
| 1292 | 1263 |
| 1293 textfield_->SetReadOnly(false); | 1264 textfield_->SetReadOnly(false); |
| 1294 input_method_->Clear(); | 1265 input_method_->Clear(); |
| 1295 textfield_->SetObscured(true); | 1266 textfield_->SetObscured(true); |
| 1296 EXPECT_TRUE(input_method_->text_input_type_changed()); | 1267 EXPECT_TRUE(input_method_->text_input_type_changed()); |
| 1297 EXPECT_TRUE(textfield_->GetTextInputClient()); | 1268 EXPECT_TRUE(textfield_->GetTextInputClient()); |
| 1298 } | 1269 } |
| 1299 | 1270 |
| 1300 TEST_F(NativeTextfieldViewsTest, UndoRedoTest) { | 1271 TEST_F(TextfieldTest, UndoRedoTest) { |
| 1301 InitTextfield(Textfield::STYLE_DEFAULT); | 1272 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1302 SendKeyEvent(ui::VKEY_A); | 1273 SendKeyEvent(ui::VKEY_A); |
| 1303 EXPECT_STR_EQ("a", textfield_->text()); | 1274 EXPECT_STR_EQ("a", textfield_->text()); |
| 1304 SendKeyEvent(ui::VKEY_Z, false, true); | 1275 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1305 EXPECT_STR_EQ("", textfield_->text()); | 1276 EXPECT_STR_EQ("", textfield_->text()); |
| 1306 SendKeyEvent(ui::VKEY_Z, false, true); | 1277 SendKeyEvent(ui::VKEY_Z, false, true); |
| 1307 EXPECT_STR_EQ("", textfield_->text()); | 1278 EXPECT_STR_EQ("", textfield_->text()); |
| 1308 SendKeyEvent(ui::VKEY_Y, false, true); | 1279 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1309 EXPECT_STR_EQ("a", textfield_->text()); | 1280 EXPECT_STR_EQ("a", textfield_->text()); |
| 1310 SendKeyEvent(ui::VKEY_Y, false, true); | 1281 SendKeyEvent(ui::VKEY_Y, false, true); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1385 SendKeyEvent(ui::VKEY_Y, false, true); | 1356 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1386 EXPECT_STR_EQ("ab", textfield_->text()); | 1357 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1387 SendKeyEvent(ui::VKEY_Y, false, true); | 1358 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1388 EXPECT_STR_EQ("b", textfield_->text()); | 1359 EXPECT_STR_EQ("b", textfield_->text()); |
| 1389 SendKeyEvent(ui::VKEY_Y, false, true); | 1360 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1390 EXPECT_STR_EQ("", textfield_->text()); | 1361 EXPECT_STR_EQ("", textfield_->text()); |
| 1391 SendKeyEvent(ui::VKEY_Y, false, true); | 1362 SendKeyEvent(ui::VKEY_Y, false, true); |
| 1392 EXPECT_STR_EQ("", textfield_->text()); | 1363 EXPECT_STR_EQ("", textfield_->text()); |
| 1393 } | 1364 } |
| 1394 | 1365 |
| 1395 TEST_F(NativeTextfieldViewsTest, CutCopyPaste) { | 1366 TEST_F(TextfieldTest, CutCopyPaste) { |
| 1396 InitTextfield(Textfield::STYLE_DEFAULT); | 1367 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1397 | 1368 |
| 1398 // Ensure IDS_APP_CUT cuts. | 1369 // Ensure IDS_APP_CUT cuts. |
| 1399 textfield_->SetText(ASCIIToUTF16("123")); | 1370 textfield_->SetText(ASCIIToUTF16("123")); |
| 1400 textfield_->SelectAll(false); | 1371 textfield_->SelectAll(false); |
| 1401 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_CUT)); | 1372 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_CUT)); |
| 1402 textfield_view_->ExecuteCommand(IDS_APP_CUT, 0); | 1373 textfield_->ExecuteCommand(IDS_APP_CUT, 0); |
| 1403 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1374 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); |
| 1404 EXPECT_STR_EQ("", textfield_->text()); | 1375 EXPECT_STR_EQ("", textfield_->text()); |
| 1405 | 1376 |
| 1406 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. | 1377 // Ensure [Ctrl]+[x] cuts and [Ctrl]+[Alt][x] does nothing. |
| 1407 textfield_->SetText(ASCIIToUTF16("456")); | 1378 textfield_->SetText(ASCIIToUTF16("456")); |
| 1408 textfield_->SelectAll(false); | 1379 textfield_->SelectAll(false); |
| 1409 SendKeyEvent(ui::VKEY_X, true, false, true, false); | 1380 SendKeyEvent(ui::VKEY_X, true, false, true, false); |
| 1410 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1381 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); |
| 1411 EXPECT_STR_EQ("456", textfield_->text()); | 1382 EXPECT_STR_EQ("456", textfield_->text()); |
| 1412 SendKeyEvent(ui::VKEY_X, false, true); | 1383 SendKeyEvent(ui::VKEY_X, false, true); |
| 1413 EXPECT_STR_EQ("456", base::string16(GetClipboardText())); | 1384 EXPECT_STR_EQ("456", base::string16(GetClipboardText())); |
| 1414 EXPECT_STR_EQ("", textfield_->text()); | 1385 EXPECT_STR_EQ("", textfield_->text()); |
| 1415 | 1386 |
| 1416 // Ensure [Shift]+[Delete] cuts. | 1387 // Ensure [Shift]+[Delete] cuts. |
| 1417 textfield_->SetText(ASCIIToUTF16("123")); | 1388 textfield_->SetText(ASCIIToUTF16("123")); |
| 1418 textfield_->SelectAll(false); | 1389 textfield_->SelectAll(false); |
| 1419 SendKeyEvent(ui::VKEY_DELETE, true, false); | 1390 SendKeyEvent(ui::VKEY_DELETE, true, false); |
| 1420 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); | 1391 EXPECT_STR_EQ("123", base::string16(GetClipboardText())); |
| 1421 EXPECT_STR_EQ("", textfield_->text()); | 1392 EXPECT_STR_EQ("", textfield_->text()); |
| 1422 | 1393 |
| 1423 // Ensure IDS_APP_COPY copies. | 1394 // Ensure IDS_APP_COPY copies. |
| 1424 textfield_->SetText(ASCIIToUTF16("789")); | 1395 textfield_->SetText(ASCIIToUTF16("789")); |
| 1425 textfield_->SelectAll(false); | 1396 textfield_->SelectAll(false); |
| 1426 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_COPY)); | 1397 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_COPY)); |
| 1427 textfield_view_->ExecuteCommand(IDS_APP_COPY, 0); | 1398 textfield_->ExecuteCommand(IDS_APP_COPY, 0); |
| 1428 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); | 1399 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); |
| 1429 | 1400 |
| 1430 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. | 1401 // Ensure [Ctrl]+[c] copies and [Ctrl]+[Alt][c] does nothing. |
| 1431 textfield_->SetText(ASCIIToUTF16("012")); | 1402 textfield_->SetText(ASCIIToUTF16("012")); |
| 1432 textfield_->SelectAll(false); | 1403 textfield_->SelectAll(false); |
| 1433 SendKeyEvent(ui::VKEY_C, true, false, true, false); | 1404 SendKeyEvent(ui::VKEY_C, true, false, true, false); |
| 1434 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); | 1405 EXPECT_STR_EQ("789", base::string16(GetClipboardText())); |
| 1435 SendKeyEvent(ui::VKEY_C, false, true); | 1406 SendKeyEvent(ui::VKEY_C, false, true); |
| 1436 EXPECT_STR_EQ("012", base::string16(GetClipboardText())); | 1407 EXPECT_STR_EQ("012", base::string16(GetClipboardText())); |
| 1437 | 1408 |
| 1438 // Ensure [Ctrl]+[Insert] copies. | 1409 // Ensure [Ctrl]+[Insert] copies. |
| 1439 textfield_->SetText(ASCIIToUTF16("345")); | 1410 textfield_->SetText(ASCIIToUTF16("345")); |
| 1440 textfield_->SelectAll(false); | 1411 textfield_->SelectAll(false); |
| 1441 SendKeyEvent(ui::VKEY_INSERT, false, true); | 1412 SendKeyEvent(ui::VKEY_INSERT, false, true); |
| 1442 EXPECT_STR_EQ("345", base::string16(GetClipboardText())); | 1413 EXPECT_STR_EQ("345", base::string16(GetClipboardText())); |
| 1443 EXPECT_STR_EQ("345", textfield_->text()); | 1414 EXPECT_STR_EQ("345", textfield_->text()); |
| 1444 | 1415 |
| 1445 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; | 1416 // Ensure IDS_APP_PASTE, [Ctrl]+[V], and [Shift]+[Insert] pastes; |
| 1446 // also ensure that [Ctrl]+[Alt]+[V] does nothing. | 1417 // also ensure that [Ctrl]+[Alt]+[V] does nothing. |
| 1447 SetClipboardText("abc"); | 1418 SetClipboardText("abc"); |
| 1448 textfield_->SetText(base::string16()); | 1419 textfield_->SetText(base::string16()); |
| 1449 EXPECT_TRUE(textfield_view_->IsCommandIdEnabled(IDS_APP_PASTE)); | 1420 EXPECT_TRUE(textfield_->IsCommandIdEnabled(IDS_APP_PASTE)); |
| 1450 textfield_view_->ExecuteCommand(IDS_APP_PASTE, 0); | 1421 textfield_->ExecuteCommand(IDS_APP_PASTE, 0); |
| 1451 EXPECT_STR_EQ("abc", textfield_->text()); | 1422 EXPECT_STR_EQ("abc", textfield_->text()); |
| 1452 SendKeyEvent(ui::VKEY_V, false, true); | 1423 SendKeyEvent(ui::VKEY_V, false, true); |
| 1453 EXPECT_STR_EQ("abcabc", textfield_->text()); | 1424 EXPECT_STR_EQ("abcabc", textfield_->text()); |
| 1454 SendKeyEvent(ui::VKEY_INSERT, true, false); | 1425 SendKeyEvent(ui::VKEY_INSERT, true, false); |
| 1455 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1426 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1456 SendKeyEvent(ui::VKEY_V, true, false, true, false); | 1427 SendKeyEvent(ui::VKEY_V, true, false, true, false); |
| 1457 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1428 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1458 | 1429 |
| 1459 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. | 1430 // Ensure [Ctrl]+[Shift]+[Insert] is a no-op. |
| 1460 textfield_->SelectAll(false); | 1431 textfield_->SelectAll(false); |
| 1461 SendKeyEvent(ui::VKEY_INSERT, true, true); | 1432 SendKeyEvent(ui::VKEY_INSERT, true, true); |
| 1462 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); | 1433 EXPECT_STR_EQ("abc", base::string16(GetClipboardText())); |
| 1463 EXPECT_STR_EQ("abcabcabc", textfield_->text()); | 1434 EXPECT_STR_EQ("abcabcabc", textfield_->text()); |
| 1464 } | 1435 } |
| 1465 | 1436 |
| 1466 TEST_F(NativeTextfieldViewsTest, OvertypeMode) { | 1437 TEST_F(TextfieldTest, OvertypeMode) { |
| 1467 InitTextfield(Textfield::STYLE_DEFAULT); | 1438 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1468 // Overtype mode should be disabled (no-op [Insert]). | 1439 // Overtype mode should be disabled (no-op [Insert]). |
| 1469 textfield_->SetText(ASCIIToUTF16("2")); | 1440 textfield_->SetText(ASCIIToUTF16("2")); |
| 1470 SendKeyEvent(ui::VKEY_HOME); | 1441 SendKeyEvent(ui::VKEY_HOME); |
| 1471 SendKeyEvent(ui::VKEY_INSERT); | 1442 SendKeyEvent(ui::VKEY_INSERT); |
| 1472 SendKeyEvent(ui::VKEY_1, false, false); | 1443 SendKeyEvent(ui::VKEY_1, false, false); |
| 1473 EXPECT_STR_EQ("12", textfield_->text()); | 1444 EXPECT_STR_EQ("12", textfield_->text()); |
| 1474 } | 1445 } |
| 1475 | 1446 |
| 1476 TEST_F(NativeTextfieldViewsTest, TextCursorDisplayTest) { | 1447 TEST_F(TextfieldTest, TextCursorDisplayTest) { |
| 1477 InitTextfield(Textfield::STYLE_DEFAULT); | 1448 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1478 // LTR-RTL string in LTR context. | 1449 // LTR-RTL string in LTR context. |
| 1479 SendKeyEvent('a'); | 1450 SendKeyEvent('a'); |
| 1480 EXPECT_STR_EQ("a", textfield_->text()); | 1451 EXPECT_STR_EQ("a", textfield_->text()); |
| 1481 int x = GetCursorBounds().x(); | 1452 int x = GetCursorBounds().x(); |
| 1482 int prev_x = x; | 1453 int prev_x = x; |
| 1483 | 1454 |
| 1484 SendKeyEvent('b'); | 1455 SendKeyEvent('b'); |
| 1485 EXPECT_STR_EQ("ab", textfield_->text()); | 1456 EXPECT_STR_EQ("ab", textfield_->text()); |
| 1486 x = GetCursorBounds().x(); | 1457 x = GetCursorBounds().x(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 x = GetCursorBounds().x(); | 1489 x = GetCursorBounds().x(); |
| 1519 EXPECT_LT(prev_x, x); | 1490 EXPECT_LT(prev_x, x); |
| 1520 prev_x = x; | 1491 prev_x = x; |
| 1521 | 1492 |
| 1522 SendKeyEvent('b'); | 1493 SendKeyEvent('b'); |
| 1523 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1494 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
| 1524 x = GetCursorBounds().x(); | 1495 x = GetCursorBounds().x(); |
| 1525 EXPECT_LT(prev_x, x); | 1496 EXPECT_LT(prev_x, x); |
| 1526 } | 1497 } |
| 1527 | 1498 |
| 1528 TEST_F(NativeTextfieldViewsTest, TextCursorDisplayInRTLTest) { | 1499 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { |
| 1529 std::string locale = l10n_util::GetApplicationLocale(""); | 1500 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1530 base::i18n::SetICUDefaultLocale("he"); | 1501 base::i18n::SetICUDefaultLocale("he"); |
| 1531 | 1502 |
| 1532 InitTextfield(Textfield::STYLE_DEFAULT); | 1503 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1533 // LTR-RTL string in RTL context. | 1504 // LTR-RTL string in RTL context. |
| 1534 SendKeyEvent('a'); | 1505 SendKeyEvent('a'); |
| 1535 EXPECT_STR_EQ("a", textfield_->text()); | 1506 EXPECT_STR_EQ("a", textfield_->text()); |
| 1536 int x = GetCursorBounds().x(); | 1507 int x = GetCursorBounds().x(); |
| 1537 EXPECT_EQ(GetDisplayRect().right() - 1, x); | 1508 EXPECT_EQ(GetDisplayRect().right() - 1, x); |
| 1538 int prev_x = x; | 1509 int prev_x = x; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 | 1547 |
| 1577 SendKeyEvent('b'); | 1548 SendKeyEvent('b'); |
| 1578 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1549 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
| 1579 x = GetCursorBounds().x(); | 1550 x = GetCursorBounds().x(); |
| 1580 EXPECT_EQ(prev_x, x); | 1551 EXPECT_EQ(prev_x, x); |
| 1581 | 1552 |
| 1582 // Reset locale. | 1553 // Reset locale. |
| 1583 base::i18n::SetICUDefaultLocale(locale); | 1554 base::i18n::SetICUDefaultLocale(locale); |
| 1584 } | 1555 } |
| 1585 | 1556 |
| 1586 TEST_F(NativeTextfieldViewsTest, HitInsideTextAreaTest) { | 1557 TEST_F(TextfieldTest, HitInsideTextAreaTest) { |
| 1587 InitTextfield(Textfield::STYLE_DEFAULT); | 1558 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1588 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1559 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
| 1589 std::vector<gfx::Rect> cursor_bounds; | 1560 std::vector<gfx::Rect> cursor_bounds; |
| 1590 | 1561 |
| 1591 // Save each cursor bound. | 1562 // Save each cursor bound. |
| 1592 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); | 1563 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); |
| 1593 cursor_bounds.push_back(GetCursorBounds(sel)); | 1564 cursor_bounds.push_back(GetCursorBounds(sel)); |
| 1594 | 1565 |
| 1595 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); | 1566 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); |
| 1596 gfx::Rect bound = GetCursorBounds(sel); | 1567 gfx::Rect bound = GetCursorBounds(sel); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1631 // for the test to run if using sleep(). | 1602 // for the test to run if using sleep(). |
| 1632 NonClientMouseClick(); | 1603 NonClientMouseClick(); |
| 1633 | 1604 |
| 1634 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); | 1605 MouseClick(cursor_bounds[i + 1], - (half_width / 2)); |
| 1635 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); | 1606 EXPECT_EQ(cursor_pos_expected[index++], textfield_->GetCursorPosition()); |
| 1636 | 1607 |
| 1637 NonClientMouseClick(); | 1608 NonClientMouseClick(); |
| 1638 } | 1609 } |
| 1639 } | 1610 } |
| 1640 | 1611 |
| 1641 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaTest) { | 1612 TEST_F(TextfieldTest, HitOutsideTextAreaTest) { |
| 1642 InitTextfield(Textfield::STYLE_DEFAULT); | 1613 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1643 | 1614 |
| 1644 // LTR-RTL string in LTR context. | 1615 // LTR-RTL string in LTR context. |
| 1645 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1616 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
| 1646 | 1617 |
| 1647 SendKeyEvent(ui::VKEY_HOME); | 1618 SendKeyEvent(ui::VKEY_HOME); |
| 1648 gfx::Rect bound = GetCursorBounds(); | 1619 gfx::Rect bound = GetCursorBounds(); |
| 1649 MouseClick(bound, -10); | 1620 MouseClick(bound, -10); |
| 1650 EXPECT_EQ(bound, GetCursorBounds()); | 1621 EXPECT_EQ(bound, GetCursorBounds()); |
| 1651 | 1622 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1663 bound = GetCursorBounds(); | 1634 bound = GetCursorBounds(); |
| 1664 MouseClick(bound, 10); | 1635 MouseClick(bound, 10); |
| 1665 EXPECT_EQ(bound, GetCursorBounds()); | 1636 EXPECT_EQ(bound, GetCursorBounds()); |
| 1666 | 1637 |
| 1667 SendKeyEvent(ui::VKEY_END); | 1638 SendKeyEvent(ui::VKEY_END); |
| 1668 bound = GetCursorBounds(); | 1639 bound = GetCursorBounds(); |
| 1669 MouseClick(bound, -10); | 1640 MouseClick(bound, -10); |
| 1670 EXPECT_EQ(bound, GetCursorBounds()); | 1641 EXPECT_EQ(bound, GetCursorBounds()); |
| 1671 } | 1642 } |
| 1672 | 1643 |
| 1673 TEST_F(NativeTextfieldViewsTest, HitOutsideTextAreaInRTLTest) { | 1644 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { |
| 1674 std::string locale = l10n_util::GetApplicationLocale(""); | 1645 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1675 base::i18n::SetICUDefaultLocale("he"); | 1646 base::i18n::SetICUDefaultLocale("he"); |
| 1676 | 1647 |
| 1677 InitTextfield(Textfield::STYLE_DEFAULT); | 1648 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1678 | 1649 |
| 1679 // RTL-LTR string in RTL context. | 1650 // RTL-LTR string in RTL context. |
| 1680 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); | 1651 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); |
| 1681 SendKeyEvent(ui::VKEY_HOME); | 1652 SendKeyEvent(ui::VKEY_HOME); |
| 1682 gfx::Rect bound = GetCursorBounds(); | 1653 gfx::Rect bound = GetCursorBounds(); |
| 1683 MouseClick(bound, 10); | 1654 MouseClick(bound, 10); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1699 | 1670 |
| 1700 SendKeyEvent(ui::VKEY_END); | 1671 SendKeyEvent(ui::VKEY_END); |
| 1701 bound = GetCursorBounds(); | 1672 bound = GetCursorBounds(); |
| 1702 MouseClick(bound, 10); | 1673 MouseClick(bound, 10); |
| 1703 EXPECT_EQ(bound, GetCursorBounds()); | 1674 EXPECT_EQ(bound, GetCursorBounds()); |
| 1704 | 1675 |
| 1705 // Reset locale. | 1676 // Reset locale. |
| 1706 base::i18n::SetICUDefaultLocale(locale); | 1677 base::i18n::SetICUDefaultLocale(locale); |
| 1707 } | 1678 } |
| 1708 | 1679 |
| 1709 TEST_F(NativeTextfieldViewsTest, OverflowTest) { | 1680 TEST_F(TextfieldTest, OverflowTest) { |
| 1710 InitTextfield(Textfield::STYLE_DEFAULT); | 1681 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1711 | 1682 |
| 1712 base::string16 str; | 1683 base::string16 str; |
| 1713 for (int i = 0; i < 500; ++i) | 1684 for (int i = 0; i < 500; ++i) |
| 1714 SendKeyEvent('a'); | 1685 SendKeyEvent('a'); |
| 1715 SendKeyEvent(kHebrewLetterSamekh); | 1686 SendKeyEvent(kHebrewLetterSamekh); |
| 1716 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1687 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| 1717 | 1688 |
| 1718 // Test mouse pointing. | 1689 // Test mouse pointing. |
| 1719 MouseClick(GetCursorBounds(), -1); | 1690 MouseClick(GetCursorBounds(), -1); |
| 1720 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1691 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1721 | 1692 |
| 1722 // Clear text. | 1693 // Clear text. |
| 1723 SendKeyEvent(ui::VKEY_A, false, true); | 1694 SendKeyEvent(ui::VKEY_A, false, true); |
| 1724 SendKeyEvent('\n'); | 1695 SendKeyEvent('\n'); |
| 1725 | 1696 |
| 1726 for (int i = 0; i < 500; ++i) | 1697 for (int i = 0; i < 500; ++i) |
| 1727 SendKeyEvent(kHebrewLetterSamekh); | 1698 SendKeyEvent(kHebrewLetterSamekh); |
| 1728 SendKeyEvent('a'); | 1699 SendKeyEvent('a'); |
| 1729 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1700 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| 1730 | 1701 |
| 1731 MouseClick(GetCursorBounds(), -1); | 1702 MouseClick(GetCursorBounds(), -1); |
| 1732 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 1703 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
| 1733 } | 1704 } |
| 1734 | 1705 |
| 1735 TEST_F(NativeTextfieldViewsTest, OverflowInRTLTest) { | 1706 TEST_F(TextfieldTest, OverflowInRTLTest) { |
| 1736 std::string locale = l10n_util::GetApplicationLocale(""); | 1707 std::string locale = l10n_util::GetApplicationLocale(""); |
| 1737 base::i18n::SetICUDefaultLocale("he"); | 1708 base::i18n::SetICUDefaultLocale("he"); |
| 1738 | 1709 |
| 1739 InitTextfield(Textfield::STYLE_DEFAULT); | 1710 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1740 | 1711 |
| 1741 base::string16 str; | 1712 base::string16 str; |
| 1742 for (int i = 0; i < 500; ++i) | 1713 for (int i = 0; i < 500; ++i) |
| 1743 SendKeyEvent('a'); | 1714 SendKeyEvent('a'); |
| 1744 SendKeyEvent(kHebrewLetterSamekh); | 1715 SendKeyEvent(kHebrewLetterSamekh); |
| 1745 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1716 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1756 SendKeyEvent('a'); | 1727 SendKeyEvent('a'); |
| 1757 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 1728 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
| 1758 | 1729 |
| 1759 MouseClick(GetCursorBounds(), 1); | 1730 MouseClick(GetCursorBounds(), 1); |
| 1760 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1731 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
| 1761 | 1732 |
| 1762 // Reset locale. | 1733 // Reset locale. |
| 1763 base::i18n::SetICUDefaultLocale(locale); | 1734 base::i18n::SetICUDefaultLocale(locale); |
| 1764 } | 1735 } |
| 1765 | 1736 |
| 1766 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBoundsTest) { | 1737 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { |
| 1767 InitTextfield(Textfield::STYLE_DEFAULT); | 1738 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1768 | 1739 |
| 1769 base::string16 str; | 1740 base::string16 str; |
| 1770 const uint32 char_count = 10UL; | 1741 const uint32 char_count = 10UL; |
| 1771 ui::CompositionText composition; | 1742 ui::CompositionText composition; |
| 1772 composition.text = UTF8ToUTF16("0123456789"); | 1743 composition.text = UTF8ToUTF16("0123456789"); |
| 1773 ui::TextInputClient* client = textfield_->GetTextInputClient(); | 1744 ui::TextInputClient* client = textfield_->GetTextInputClient(); |
| 1774 | 1745 |
| 1775 // Return false if there is no composition text. | 1746 // Return false if there is no composition text. |
| 1776 gfx::Rect rect; | 1747 gfx::Rect rect; |
| 1777 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); | 1748 EXPECT_FALSE(client->GetCompositionCharacterBounds(0, &rect)); |
| 1778 | 1749 |
| 1779 // Get each character boundary by cursor. | 1750 // Get each character boundary by cursor. |
| 1780 gfx::Rect char_rect_in_screen_coord[char_count]; | 1751 gfx::Rect char_rect_in_screen_coord[char_count]; |
| 1781 gfx::Rect prev_cursor = GetCursorBounds(); | 1752 gfx::Rect prev_cursor = GetCursorBounds(); |
| 1782 for (uint32 i = 0; i < char_count; ++i) { | 1753 for (uint32 i = 0; i < char_count; ++i) { |
| 1783 composition.selection = gfx::Range(0, i+1); | 1754 composition.selection = gfx::Range(0, i+1); |
| 1784 client->SetCompositionText(composition); | 1755 client->SetCompositionText(composition); |
| 1785 EXPECT_TRUE(client->HasCompositionText()) << " i=" << i; | 1756 EXPECT_TRUE(client->HasCompositionText()) << " i=" << i; |
| 1786 gfx::Rect cursor_bounds = GetCursorBounds(); | 1757 gfx::Rect cursor_bounds = GetCursorBounds(); |
| 1787 gfx::Point top_left(prev_cursor.x(), prev_cursor.y()); | 1758 gfx::Point top_left(prev_cursor.x(), prev_cursor.y()); |
| 1788 gfx::Point bottom_right(cursor_bounds.x(), prev_cursor.bottom()); | 1759 gfx::Point bottom_right(cursor_bounds.x(), prev_cursor.bottom()); |
| 1789 views::View::ConvertPointToScreen(textfield_view_, &top_left); | 1760 views::View::ConvertPointToScreen(textfield_, &top_left); |
| 1790 views::View::ConvertPointToScreen(textfield_view_, &bottom_right); | 1761 views::View::ConvertPointToScreen(textfield_, &bottom_right); |
| 1791 char_rect_in_screen_coord[i].set_origin(top_left); | 1762 char_rect_in_screen_coord[i].set_origin(top_left); |
| 1792 char_rect_in_screen_coord[i].set_width(bottom_right.x() - top_left.x()); | 1763 char_rect_in_screen_coord[i].set_width(bottom_right.x() - top_left.x()); |
| 1793 char_rect_in_screen_coord[i].set_height(bottom_right.y() - top_left.y()); | 1764 char_rect_in_screen_coord[i].set_height(bottom_right.y() - top_left.y()); |
| 1794 prev_cursor = cursor_bounds; | 1765 prev_cursor = cursor_bounds; |
| 1795 } | 1766 } |
| 1796 | 1767 |
| 1797 for (uint32 i = 0; i < char_count; ++i) { | 1768 for (uint32 i = 0; i < char_count; ++i) { |
| 1798 gfx::Rect actual_rect; | 1769 gfx::Rect actual_rect; |
| 1799 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &actual_rect)) | 1770 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &actual_rect)) |
| 1800 << " i=" << i; | 1771 << " i=" << i; |
| 1801 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i; | 1772 EXPECT_EQ(char_rect_in_screen_coord[i], actual_rect) << " i=" << i; |
| 1802 } | 1773 } |
| 1803 | 1774 |
| 1804 // Return false if the index is out of range. | 1775 // Return false if the index is out of range. |
| 1805 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); | 1776 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); |
| 1806 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); | 1777 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); |
| 1807 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); | 1778 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); |
| 1808 } | 1779 } |
| 1809 | 1780 |
| 1810 TEST_F(NativeTextfieldViewsTest, GetCompositionCharacterBounds_ComplexText) { | 1781 TEST_F(TextfieldTest, GetCompositionCharacterBounds_ComplexText) { |
| 1811 InitTextfield(Textfield::STYLE_DEFAULT); | 1782 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1812 | 1783 |
| 1813 const base::char16 kUtf16Chars[] = { | 1784 const base::char16 kUtf16Chars[] = { |
| 1814 // U+0020 SPACE | 1785 // U+0020 SPACE |
| 1815 0x0020, | 1786 0x0020, |
| 1816 // U+1F408 (CAT) as surrogate pair | 1787 // U+1F408 (CAT) as surrogate pair |
| 1817 0xd83d, 0xdc08, | 1788 0xd83d, 0xdc08, |
| 1818 // U+5642 as Ideographic Variation Sequences | 1789 // U+5642 as Ideographic Variation Sequences |
| 1819 0x5642, 0xDB40, 0xDD00, | 1790 0x5642, 0xDB40, 0xDD00, |
| 1820 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences | 1791 // U+260E (BLACK TELEPHONE) as Emoji Variation Sequences |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1837 | 1808 |
| 1838 // Here we might expect the following results but it actually depends on how | 1809 // Here we might expect the following results but it actually depends on how |
| 1839 // Uniscribe or HarfBuzz treats them with given font. | 1810 // Uniscribe or HarfBuzz treats them with given font. |
| 1840 // - rects[1] == rects[2] | 1811 // - rects[1] == rects[2] |
| 1841 // - rects[3] == rects[4] == rects[5] | 1812 // - rects[3] == rects[4] == rects[5] |
| 1842 // - rects[6] == rects[7] | 1813 // - rects[6] == rects[7] |
| 1843 } | 1814 } |
| 1844 | 1815 |
| 1845 // The word we select by double clicking should remain selected regardless of | 1816 // The word we select by double clicking should remain selected regardless of |
| 1846 // where we drag the mouse afterwards without releasing the left button. | 1817 // where we drag the mouse afterwards without releasing the left button. |
| 1847 TEST_F(NativeTextfieldViewsTest, KeepInitiallySelectedWord) { | 1818 TEST_F(TextfieldTest, KeepInitiallySelectedWord) { |
| 1848 InitTextfield(Textfield::STYLE_DEFAULT); | 1819 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1849 | 1820 |
| 1850 textfield_->SetText(ASCIIToUTF16("abc def ghi")); | 1821 textfield_->SetText(ASCIIToUTF16("abc def ghi")); |
| 1851 | 1822 |
| 1852 textfield_->SelectRange(gfx::Range(5, 5)); | 1823 textfield_->SelectRange(gfx::Range(5, 5)); |
| 1853 const gfx::Rect middle_cursor = GetCursorBounds(); | 1824 const gfx::Rect middle_cursor = GetCursorBounds(); |
| 1854 textfield_->SelectRange(gfx::Range(0, 0)); | 1825 textfield_->SelectRange(gfx::Range(0, 0)); |
| 1855 const gfx::Point beginning = GetCursorBounds().origin(); | 1826 const gfx::Point beginning = GetCursorBounds().origin(); |
| 1856 | 1827 |
| 1857 // Double click, but do not release the left button. | 1828 // Double click, but do not release the left button. |
| 1858 MouseClick(middle_cursor, 0); | 1829 MouseClick(middle_cursor, 0); |
| 1859 const gfx::Point middle(middle_cursor.x(), | 1830 const gfx::Point middle(middle_cursor.x(), |
| 1860 middle_cursor.y() + middle_cursor.height() / 2); | 1831 middle_cursor.y() + middle_cursor.height() / 2); |
| 1861 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, | 1832 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, middle, middle, |
| 1862 ui::EF_LEFT_MOUSE_BUTTON, | 1833 ui::EF_LEFT_MOUSE_BUTTON, |
| 1863 ui::EF_LEFT_MOUSE_BUTTON); | 1834 ui::EF_LEFT_MOUSE_BUTTON); |
| 1864 textfield_view_->OnMousePressed(press_event); | 1835 textfield_->OnMousePressed(press_event); |
| 1865 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); | 1836 EXPECT_EQ(gfx::Range(4, 7), textfield_->GetSelectedRange()); |
| 1866 | 1837 |
| 1867 // Drag the mouse to the beginning of the textfield. | 1838 // Drag the mouse to the beginning of the textfield. |
| 1868 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, | 1839 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, beginning, beginning, |
| 1869 ui::EF_LEFT_MOUSE_BUTTON, 0); | 1840 ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1870 textfield_view_->OnMouseDragged(drag_event); | 1841 textfield_->OnMouseDragged(drag_event); |
| 1871 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); | 1842 EXPECT_EQ(gfx::Range(7, 0), textfield_->GetSelectedRange()); |
| 1872 } | 1843 } |
| 1873 | 1844 |
| 1874 // Touch selection and draggin currently only works for chromeos. | 1845 // Touch selection and dragging currently only works for chromeos. |
| 1875 #if defined(OS_CHROMEOS) | 1846 #if defined(OS_CHROMEOS) |
| 1876 TEST_F(NativeTextfieldViewsTest, TouchSelectionAndDraggingTest) { | 1847 TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { |
| 1877 InitTextfield(Textfield::STYLE_DEFAULT); | 1848 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1878 textfield_->SetText(ASCIIToUTF16("hello world")); | 1849 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1879 EXPECT_FALSE(GetTouchSelectionController()); | 1850 EXPECT_FALSE(GetTouchSelectionController()); |
| 1880 const int eventX = GetCursorPositionX(2); | 1851 const int x = GetCursorPositionX(2); |
| 1881 const int eventY = 0; | 1852 GestureEventForTest tap(ui::ET_GESTURE_TAP, x, 0, 1.0f, 0.0f); |
| 1853 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, x, 0, 0.0f, 0.0f); |
| 1854 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, x, 0, 0.0f, 0.0f); |
| 1882 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 1855 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| 1883 | 1856 |
| 1884 // Tapping on the textfield should turn on the TouchSelectionController. | 1857 // Tapping on the textfield should turn on the TouchSelectionController. |
| 1885 GestureEventForTest tap(ui::ET_GESTURE_TAP, eventX, eventY, 1.0f, 0.0f); | 1858 textfield_->OnGestureEvent(&tap); |
| 1886 textfield_view_->OnGestureEvent(&tap); | |
| 1887 EXPECT_TRUE(GetTouchSelectionController()); | 1859 EXPECT_TRUE(GetTouchSelectionController()); |
| 1888 | 1860 |
| 1889 // Un-focusing the textfield should reset the TouchSelectionController | 1861 // Un-focusing the textfield should reset the TouchSelectionController |
| 1890 textfield_view_->GetFocusManager()->ClearFocus(); | 1862 textfield_->GetFocusManager()->ClearFocus(); |
| 1891 EXPECT_FALSE(GetTouchSelectionController()); | 1863 EXPECT_FALSE(GetTouchSelectionController()); |
| 1892 | 1864 |
| 1893 // With touch editing enabled, long press should not show context menu. | 1865 // With touch editing enabled, long press should not show context menu. |
| 1894 // Instead, select word and invoke TouchSelectionController. | 1866 // Instead, select word and invoke TouchSelectionController. |
| 1895 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, eventX, eventY, 0.0f, | 1867 textfield_->OnGestureEvent(&tap_down); |
| 1896 0.0f); | 1868 textfield_->OnGestureEvent(&long_press); |
| 1897 textfield_view_->OnGestureEvent(&tap_down); | |
| 1898 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, | |
| 1899 0.0f, 0.0f); | |
| 1900 textfield_view_->OnGestureEvent(&long_press); | |
| 1901 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1869 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 1902 EXPECT_TRUE(GetTouchSelectionController()); | 1870 EXPECT_TRUE(GetTouchSelectionController()); |
| 1903 | 1871 |
| 1904 // Long pressing again in the selecting region should not do anything since | 1872 // With touch drag drop enabled, long pressing in the selected region should |
| 1905 // touch drag drop is not yet enabled. | 1873 // start a drag and remove TouchSelectionController. |
| 1906 textfield_view_->OnGestureEvent(&tap_down); | 1874 ASSERT_TRUE(switches::IsTouchDragDropEnabled()); |
| 1907 textfield_view_->OnGestureEvent(&long_press); | 1875 textfield_->OnGestureEvent(&tap_down); |
| 1876 textfield_->OnGestureEvent(&long_press); |
| 1877 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 1878 EXPECT_FALSE(GetTouchSelectionController()); |
| 1879 |
| 1880 // After disabling touch drag drop, long pressing again in the selection |
| 1881 // region should not do anything. |
| 1882 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1883 switches::kDisableTouchDragDrop); |
| 1884 ASSERT_FALSE(switches::IsTouchDragDropEnabled()); |
| 1885 textfield_->OnGestureEvent(&tap_down); |
| 1886 textfield_->OnGestureEvent(&long_press); |
| 1908 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1887 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 1909 EXPECT_TRUE(GetTouchSelectionController()); | 1888 EXPECT_TRUE(GetTouchSelectionController()); |
| 1910 EXPECT_TRUE(long_press.handled()); | 1889 EXPECT_TRUE(long_press.handled()); |
| 1911 | |
| 1912 // After enabling touch drag drop, long pressing in the selected region should | |
| 1913 // start a drag and remove TouchSelectionController. | |
| 1914 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1915 switches::kEnableTouchDragDrop); | |
| 1916 textfield_view_->OnGestureEvent(&tap_down); | |
| 1917 | |
| 1918 // Create a new long press event since the previous one is not marked handled. | |
| 1919 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, | |
| 1920 0.0f, 0.0f); | |
| 1921 textfield_view_->OnGestureEvent(&long_press2); | |
| 1922 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | |
| 1923 EXPECT_FALSE(GetTouchSelectionController()); | |
| 1924 } | 1890 } |
| 1925 | 1891 |
| 1926 TEST_F(NativeTextfieldViewsTest, TouchScrubbingSelection) { | 1892 TEST_F(TextfieldTest, TouchScrubbingSelection) { |
| 1927 InitTextfield(Textfield::STYLE_DEFAULT); | 1893 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1928 textfield_->SetText(ASCIIToUTF16("hello world")); | 1894 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1929 EXPECT_FALSE(GetTouchSelectionController()); | 1895 EXPECT_FALSE(GetTouchSelectionController()); |
| 1930 | 1896 |
| 1931 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 1897 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| 1932 | 1898 |
| 1933 // Simulate touch-scrubbing. | 1899 // Simulate touch-scrubbing. |
| 1934 int scrubbing_start = GetCursorPositionX(1); | 1900 int scrubbing_start = GetCursorPositionX(1); |
| 1935 int scrubbing_end = GetCursorPositionX(6); | 1901 int scrubbing_end = GetCursorPositionX(6); |
| 1936 | 1902 |
| 1937 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, | 1903 GestureEventForTest tap_down(ui::ET_GESTURE_TAP_DOWN, scrubbing_start, 0, |
| 1938 0.0f, 0.0f); | 1904 0.0f, 0.0f); |
| 1939 textfield_view_->OnGestureEvent(&tap_down); | 1905 textfield_->OnGestureEvent(&tap_down); |
| 1940 | 1906 |
| 1941 GestureEventForTest tap_cancel(ui::ET_GESTURE_TAP_CANCEL, scrubbing_start, 0, | 1907 GestureEventForTest tap_cancel(ui::ET_GESTURE_TAP_CANCEL, scrubbing_start, 0, |
| 1942 0.0f, 0.0f); | 1908 0.0f, 0.0f); |
| 1943 textfield_view_->OnGestureEvent(&tap_cancel); | 1909 textfield_->OnGestureEvent(&tap_cancel); |
| 1944 | 1910 |
| 1945 GestureEventForTest scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, scrubbing_start, | 1911 GestureEventForTest scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, scrubbing_start, |
| 1946 0, 0.0f, 0.0f); | 1912 0, 0.0f, 0.0f); |
| 1947 textfield_view_->OnGestureEvent(&scroll_begin); | 1913 textfield_->OnGestureEvent(&scroll_begin); |
| 1948 | 1914 |
| 1949 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, scrubbing_end, | 1915 GestureEventForTest scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, scrubbing_end, |
| 1950 0, scrubbing_end - scrubbing_start, 0.0f); | 1916 0, scrubbing_end - scrubbing_start, 0.0f); |
| 1951 textfield_view_->OnGestureEvent(&scroll_update); | 1917 textfield_->OnGestureEvent(&scroll_update); |
| 1952 | 1918 |
| 1953 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, scrubbing_end, 0, | 1919 GestureEventForTest scroll_end(ui::ET_GESTURE_SCROLL_END, scrubbing_end, 0, |
| 1954 0.0f, 0.0f); | 1920 0.0f, 0.0f); |
| 1955 textfield_view_->OnGestureEvent(&scroll_end); | 1921 textfield_->OnGestureEvent(&scroll_end); |
| 1956 | 1922 |
| 1957 GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f); | 1923 GestureEventForTest end(ui::ET_GESTURE_END, scrubbing_end, 0, 0.0f, 0.0f); |
| 1958 textfield_view_->OnGestureEvent(&end); | 1924 textfield_->OnGestureEvent(&end); |
| 1959 | 1925 |
| 1960 // In the end, part of text should have been selected and handles should have | 1926 // In the end, part of text should have been selected and handles should have |
| 1961 // appeared. | 1927 // appeared. |
| 1962 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); | 1928 EXPECT_STR_EQ("ello ", textfield_->GetSelectedText()); |
| 1963 EXPECT_TRUE(GetTouchSelectionController()); | 1929 EXPECT_TRUE(GetTouchSelectionController()); |
| 1964 } | 1930 } |
| 1965 #endif | 1931 #endif |
| 1966 | 1932 |
| 1967 // Long_Press gesture in NativeTextfieldViews can initiate a drag and drop now. | 1933 // Long_Press gesture in Textfield can initiate a drag and drop now. |
| 1968 TEST_F(NativeTextfieldViewsTest, TestLongPressInitiatesDragDrop) { | 1934 TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { |
| 1969 InitTextfield(Textfield::STYLE_DEFAULT); | 1935 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1970 textfield_->SetText(ASCIIToUTF16("Hello string world")); | 1936 textfield_->SetText(ASCIIToUTF16("Hello string world")); |
| 1971 | 1937 |
| 1972 // Ensure the textfield will provide selected text for drag data. | 1938 // Ensure the textfield will provide selected text for drag data. |
| 1973 textfield_->SelectRange(gfx::Range(6, 12)); | 1939 textfield_->SelectRange(gfx::Range(6, 12)); |
| 1974 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); | 1940 const gfx::Point kStringPoint(GetCursorPositionX(9), 0); |
| 1975 | 1941 |
| 1976 // Enable touch-drag-drop to make long press effective. | 1942 // Enable touch-drag-drop to make long press effective. |
| 1977 CommandLine::ForCurrentProcess()->AppendSwitch( | 1943 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1978 switches::kEnableTouchDragDrop); | 1944 switches::kEnableTouchDragDrop); |
| 1979 | 1945 |
| 1980 // Create a long press event in the selected region should start a drag. | 1946 // Create a long press event in the selected region should start a drag. |
| 1981 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), | 1947 GestureEventForTest long_press(ui::ET_GESTURE_LONG_PRESS, kStringPoint.x(), |
| 1982 kStringPoint.y(), 0.0f, 0.0f); | 1948 kStringPoint.y(), 0.0f, 0.0f); |
| 1983 textfield_view_->OnGestureEvent(&long_press); | 1949 textfield_->OnGestureEvent(&long_press); |
| 1984 EXPECT_TRUE(textfield_view_->CanStartDragForView(NULL, | 1950 EXPECT_TRUE(textfield_->CanStartDragForView(NULL, kStringPoint, |
| 1985 kStringPoint, kStringPoint)); | 1951 kStringPoint)); |
| 1986 } | 1952 } |
| 1987 | 1953 |
| 1988 TEST_F(NativeTextfieldViewsTest, GetTextfieldBaseline_FontFallbackTest) { | 1954 TEST_F(TextfieldTest, GetTextfieldBaseline_FontFallbackTest) { |
| 1989 InitTextfield(Textfield::STYLE_DEFAULT); | 1955 InitTextfield(Textfield::STYLE_DEFAULT); |
| 1990 textfield_->SetText(UTF8ToUTF16("abc")); | 1956 textfield_->SetText(UTF8ToUTF16("abc")); |
| 1991 const int old_baseline = textfield_->GetBaseline(); | 1957 const int old_baseline = textfield_->GetBaseline(); |
| 1992 | 1958 |
| 1993 // Set text which may fall back to a font which has taller baseline than | 1959 // Set text which may fall back to a font which has taller baseline than |
| 1994 // the default font. | 1960 // the default font. |
| 1995 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); | 1961 textfield_->SetText(UTF8ToUTF16("\xE0\xB9\x91")); |
| 1996 const int new_baseline = textfield_->GetBaseline(); | 1962 const int new_baseline = textfield_->GetBaseline(); |
| 1997 | 1963 |
| 1998 // Regardless of the text, the baseline must be the same. | 1964 // Regardless of the text, the baseline must be the same. |
| 1999 EXPECT_EQ(new_baseline, old_baseline); | 1965 EXPECT_EQ(new_baseline, old_baseline); |
| 2000 } | 1966 } |
| 2001 | 1967 |
| 2002 } // namespace views | 1968 } // namespace views |
| OLD | NEW |