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

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

Issue 1875003002: Using ui::test::EventGenerator Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Track window offset correctly - expect regressions on mac Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 21 matching lines...) Expand all
32 #include "ui/events/event_processor.h" 32 #include "ui/events/event_processor.h"
33 #include "ui/events/event_utils.h" 33 #include "ui/events/event_utils.h"
34 #include "ui/events/keycodes/keyboard_codes.h" 34 #include "ui/events/keycodes/keyboard_codes.h"
35 #include "ui/events/test/event_generator.h" 35 #include "ui/events/test/event_generator.h"
36 #include "ui/gfx/render_text.h" 36 #include "ui/gfx/render_text.h"
37 #include "ui/strings/grit/ui_strings.h" 37 #include "ui/strings/grit/ui_strings.h"
38 #include "ui/views/controls/textfield/textfield_controller.h" 38 #include "ui/views/controls/textfield/textfield_controller.h"
39 #include "ui/views/controls/textfield/textfield_model.h" 39 #include "ui/views/controls/textfield/textfield_model.h"
40 #include "ui/views/controls/textfield/textfield_test_api.h" 40 #include "ui/views/controls/textfield/textfield_test_api.h"
41 #include "ui/views/focus/focus_manager.h" 41 #include "ui/views/focus/focus_manager.h"
42 #include "ui/views/style/platform_style.h"
42 #include "ui/views/test/test_views_delegate.h" 43 #include "ui/views/test/test_views_delegate.h"
43 #include "ui/views/test/views_test_base.h" 44 #include "ui/views/test/views_test_base.h"
44 #include "ui/views/test/widget_test.h" 45 #include "ui/views/test/widget_test.h"
45 #include "ui/views/widget/widget.h" 46 #include "ui/views/widget/widget.h"
46 #include "url/gurl.h" 47 #include "url/gurl.h"
47 48
48 #if defined(OS_WIN) 49 #if defined(OS_WIN)
49 #include "base/win/windows_version.h" 50 #include "base/win/windows_version.h"
50 #endif 51 #endif
51 52
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 Widget::InitParams params = 410 Widget::InitParams params =
410 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); 411 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
411 412
412 params.bounds = gfx::Rect(100, 100, 100, 100); 413 params.bounds = gfx::Rect(100, 100, 100, 100);
413 widget_->Init(params); 414 widget_->Init(params);
414 input_method_->SetDelegate( 415 input_method_->SetDelegate(
415 test::WidgetTest::GetInputMethodDelegateForWidget(widget_)); 416 test::WidgetTest::GetInputMethodDelegateForWidget(widget_));
416 View* container = new View(); 417 View* container = new View();
417 widget_->SetContentsView(container); 418 widget_->SetContentsView(container);
418 container->AddChildView(textfield_); 419 container->AddChildView(textfield_);
419 textfield_->SetBoundsRect(params.bounds); 420 textfield_->SetBoundsRect(gfx::Rect(params.bounds.size()));
420 textfield_->set_id(1); 421 textfield_->set_id(1);
421 test_api_.reset(new TextfieldTestApi(textfield_)); 422 test_api_.reset(new TextfieldTestApi(textfield_));
422 423
423 for (int i = 1; i < count; i++) { 424 for (int i = 1; i < count; i++) {
424 Textfield* textfield = new Textfield(); 425 Textfield* textfield = new Textfield();
425 container->AddChildView(textfield); 426 container->AddChildView(textfield);
426 textfield->set_id(i + 1); 427 textfield->set_id(i + 1);
427 } 428 }
428 429
429 model_ = test_api_->model(); 430 model_ = test_api_->model();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 647
647 // For testing input method related behaviors. 648 // For testing input method related behaviors.
648 MockInputMethod* input_method_; 649 MockInputMethod* input_method_;
649 650
650 // Indicates how many times OnBeforeUserAction() is called. 651 // Indicates how many times OnBeforeUserAction() is called.
651 int on_before_user_action_; 652 int on_before_user_action_;
652 653
653 // Indicates how many times OnAfterUserAction() is called. 654 // Indicates how many times OnAfterUserAction() is called.
654 int on_after_user_action_; 655 int on_after_user_action_;
655 656
657 scoped_ptr<ui::test::EventGenerator> event_generator_;
658
656 private: 659 private:
657 ui::ClipboardType copied_to_clipboard_; 660 ui::ClipboardType copied_to_clipboard_;
658 scoped_ptr<ui::test::EventGenerator> event_generator_;
659 DISALLOW_COPY_AND_ASSIGN(TextfieldTest); 661 DISALLOW_COPY_AND_ASSIGN(TextfieldTest);
660 }; 662 };
661 663
662 TEST_F(TextfieldTest, ModelChangesTest) { 664 TEST_F(TextfieldTest, ModelChangesTest) {
663 InitTextfield(); 665 InitTextfield();
664 666
665 // TextfieldController::ContentsChanged() shouldn't be called when changing 667 // TextfieldController::ContentsChanged() shouldn't be called when changing
666 // text programmatically. 668 // text programmatically.
667 last_contents_.clear(); 669 last_contents_.clear();
668 textfield_->SetText(ASCIIToUTF16("this is")); 670 textfield_->SetText(ASCIIToUTF16("this is"));
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 // Check that releasing in the same location does not alter the selection. 1190 // Check that releasing in the same location does not alter the selection.
1189 textfield_->OnMouseReleased(release); 1191 textfield_->OnMouseReleased(release);
1190 EXPECT_EQ(text_right, textfield_->GetSelectedText()); 1192 EXPECT_EQ(text_right, textfield_->GetSelectedText());
1191 // Check that dragging from beyond the text length works too. 1193 // Check that dragging from beyond the text length works too.
1192 textfield_->OnMousePressed(click_b); 1194 textfield_->OnMousePressed(click_b);
1193 textfield_->OnMouseDragged(drag_left); 1195 textfield_->OnMouseDragged(drag_left);
1194 textfield_->OnMouseReleased(release); 1196 textfield_->OnMouseReleased(release);
1195 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); 1197 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText());
1196 } 1198 }
1197 1199
1200 // This test checks that dragging above the textfield selects to the beginning
1201 // and dragging below the textfield selects to the end, but only on platforms
1202 // where that is the expected behavior.
1203 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) {
1204 InitTextfield();
1205 textfield_->SetText(ASCIIToUTF16("hello world"));
1206 const base::string16 expected_up = base::ASCIIToUTF16(
1207 PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? "hello" : "lo");
1208 const base::string16 expected_down = base::ASCIIToUTF16(
1209 PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? " world" : " w");
1210 const int kStartX = GetCursorPositionX(5);
1211 const int kDownX = GetCursorPositionX(7);
1212 const int kUpX = GetCursorPositionX(3);
1213 const gfx::Vector2d offset =
1214 widget_->GetWindowBoundsInScreen().OffsetFromOrigin();
1215 gfx::Point start_point = gfx::Point(kStartX, 50) + offset;
1216 gfx::Point down_point = gfx::Point(kDownX, 500) + offset;
1217 gfx::Point up_point = gfx::Point(kUpX, -500) + offset;
1218
1219 event_generator_->set_current_location(start_point);
1220 event_generator_->DragMouseTo(up_point);
1221 EXPECT_EQ(expected_up, textfield_->GetSelectedText());
1222
1223 event_generator_->MoveMouseTo(start_point);
1224 event_generator_->DragMouseTo(down_point);
1225 EXPECT_EQ(expected_down, textfield_->GetSelectedText());
1226 }
1227
1198 #if defined(OS_WIN) 1228 #if defined(OS_WIN)
1199 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { 1229 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) {
1200 InitTextfield(); 1230 InitTextfield();
1201 textfield_->SetText(ASCIIToUTF16("hello world")); 1231 textfield_->SetText(ASCIIToUTF16("hello world"));
1202 1232
1203 ui::OSExchangeData data; 1233 ui::OSExchangeData data;
1204 base::string16 string(ASCIIToUTF16("string ")); 1234 base::string16 string(ASCIIToUTF16("string "));
1205 data.SetString(string); 1235 data.SetString(string);
1206 int formats = 0; 1236 int formats = 0;
1207 std::set<ui::Clipboard::FormatType> format_types; 1237 std::set<ui::Clipboard::FormatType> format_types;
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 2599
2570 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2600 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2571 ui::AXViewState state_protected; 2601 ui::AXViewState state_protected;
2572 textfield_->GetAccessibleState(&state_protected); 2602 textfield_->GetAccessibleState(&state_protected);
2573 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2603 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2574 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2604 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2575 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2605 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2576 } 2606 }
2577 2607
2578 } // namespace views 2608 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698