| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/combobox/combobox.h" | 5 #include "ui/views/controls/combobox/combobox.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "ui/base/ime/input_method.h" | 12 #include "ui/base/ime/input_method.h" |
| 13 #include "ui/base/ime/text_input_client.h" | 13 #include "ui/base/ime/text_input_client.h" |
| 14 #include "ui/base/models/combobox_model.h" | 14 #include "ui/base/models/combobox_model.h" |
| 15 #include "ui/base/models/menu_model.h" | 15 #include "ui/base/models/menu_model.h" |
| 16 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 17 #include "ui/events/event_constants.h" | 17 #include "ui/events/event_constants.h" |
| 18 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
| 19 #include "ui/events/keycodes/dom/dom_code.h" | 19 #include "ui/events/keycodes/dom/dom_code.h" |
| 20 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
| 21 #include "ui/events/test/event_generator.h" | 21 #include "ui/events/test/event_generator.h" |
| 22 #include "ui/views/controls/combobox/combobox_listener.h" | 22 #include "ui/views/controls/combobox/combobox_listener.h" |
| 23 #include "ui/views/style/platform_style.h" |
| 23 #include "ui/views/test/combobox_test_api.h" | 24 #include "ui/views/test/combobox_test_api.h" |
| 24 #include "ui/views/test/views_test_base.h" | 25 #include "ui/views/test/views_test_base.h" |
| 25 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 26 | 27 |
| 27 using base::ASCIIToUTF16; | 28 using base::ASCIIToUTF16; |
| 28 | 29 |
| 29 namespace views { | 30 namespace views { |
| 30 | 31 |
| 31 using test::ComboboxTestApi; | 32 using test::ComboboxTestApi; |
| 32 | 33 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 219 |
| 219 combobox_->RequestFocus(); | 220 combobox_->RequestFocus(); |
| 220 combobox_->SizeToPreferredSize(); | 221 combobox_->SizeToPreferredSize(); |
| 221 | 222 |
| 222 event_generator_ = | 223 event_generator_ = |
| 223 base::MakeUnique<ui::test::EventGenerator>(widget_->GetNativeWindow()); | 224 base::MakeUnique<ui::test::EventGenerator>(widget_->GetNativeWindow()); |
| 224 event_generator_->set_target(ui::test::EventGenerator::Target::WINDOW); | 225 event_generator_->set_target(ui::test::EventGenerator::Target::WINDOW); |
| 225 } | 226 } |
| 226 | 227 |
| 227 protected: | 228 protected: |
| 228 void PressKey(ui::KeyboardCode key_code) { | 229 void PressKey(ui::KeyboardCode key_code, ui::EventFlags flags = ui::EF_NONE) { |
| 229 event_generator_->PressKey(key_code, ui::EF_NONE); | 230 event_generator_->PressKey(key_code, flags); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void ReleaseKey(ui::KeyboardCode key_code) { | 233 void ReleaseKey(ui::KeyboardCode key_code, |
| 233 event_generator_->ReleaseKey(key_code, ui::EF_NONE); | 234 ui::EventFlags flags = ui::EF_NONE) { |
| 235 event_generator_->ReleaseKey(key_code, flags); |
| 234 } | 236 } |
| 235 | 237 |
| 236 View* GetFocusedView() { | 238 View* GetFocusedView() { |
| 237 return widget_->GetFocusManager()->GetFocusedView(); | 239 return widget_->GetFocusManager()->GetFocusedView(); |
| 238 } | 240 } |
| 239 | 241 |
| 240 void PerformMousePress(const gfx::Point& point) { | 242 void PerformMousePress(const gfx::Point& point) { |
| 241 ui::MouseEvent pressed_event = ui::MouseEvent( | 243 ui::MouseEvent pressed_event = ui::MouseEvent( |
| 242 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), | 244 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
| 243 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 245 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 268 | 270 |
| 269 // The current menu show count. | 271 // The current menu show count. |
| 270 int menu_show_count_ = 0; | 272 int menu_show_count_ = 0; |
| 271 | 273 |
| 272 std::unique_ptr<ui::test::EventGenerator> event_generator_; | 274 std::unique_ptr<ui::test::EventGenerator> event_generator_; |
| 273 | 275 |
| 274 private: | 276 private: |
| 275 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); | 277 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); |
| 276 }; | 278 }; |
| 277 | 279 |
| 278 TEST_F(ComboboxTest, KeyTest) { | 280 #if defined(OS_MACOSX) |
| 281 // Tests whether the various Mac specific keyboard shortcuts invoke the dropdown |
| 282 // menu or not. |
| 283 TEST_F(ComboboxTest, KeyTestMac) { |
| 279 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 284 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 280 PressKey(ui::VKEY_END); | 285 PressKey(ui::VKEY_END); |
| 281 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); | 286 EXPECT_EQ(0, combobox_->selected_index()); |
| 287 EXPECT_EQ(1, menu_show_count_); |
| 288 |
| 282 PressKey(ui::VKEY_HOME); | 289 PressKey(ui::VKEY_HOME); |
| 283 EXPECT_EQ(combobox_->selected_index(), 0); | 290 EXPECT_EQ(0, combobox_->selected_index()); |
| 291 EXPECT_EQ(2, menu_show_count_); |
| 292 |
| 293 PressKey(ui::VKEY_UP, ui::EF_COMMAND_DOWN); |
| 294 EXPECT_EQ(0, combobox_->selected_index()); |
| 295 EXPECT_EQ(3, menu_show_count_); |
| 296 |
| 297 PressKey(ui::VKEY_DOWN, ui::EF_COMMAND_DOWN); |
| 298 EXPECT_EQ(0, combobox_->selected_index()); |
| 299 EXPECT_EQ(4, menu_show_count_); |
| 300 |
| 284 PressKey(ui::VKEY_DOWN); | 301 PressKey(ui::VKEY_DOWN); |
| 285 PressKey(ui::VKEY_DOWN); | 302 EXPECT_EQ(0, combobox_->selected_index()); |
| 286 EXPECT_EQ(combobox_->selected_index(), 2); | 303 EXPECT_EQ(5, menu_show_count_); |
| 304 |
| 287 PressKey(ui::VKEY_RIGHT); | 305 PressKey(ui::VKEY_RIGHT); |
| 288 EXPECT_EQ(combobox_->selected_index(), 2); | 306 EXPECT_EQ(0, combobox_->selected_index()); |
| 307 EXPECT_EQ(5, menu_show_count_); |
| 308 |
| 289 PressKey(ui::VKEY_LEFT); | 309 PressKey(ui::VKEY_LEFT); |
| 290 EXPECT_EQ(combobox_->selected_index(), 2); | 310 EXPECT_EQ(0, combobox_->selected_index()); |
| 311 EXPECT_EQ(5, menu_show_count_); |
| 312 |
| 291 PressKey(ui::VKEY_UP); | 313 PressKey(ui::VKEY_UP); |
| 292 EXPECT_EQ(combobox_->selected_index(), 1); | 314 EXPECT_EQ(0, combobox_->selected_index()); |
| 315 EXPECT_EQ(6, menu_show_count_); |
| 316 |
| 293 PressKey(ui::VKEY_PRIOR); | 317 PressKey(ui::VKEY_PRIOR); |
| 294 EXPECT_EQ(combobox_->selected_index(), 0); | 318 EXPECT_EQ(0, combobox_->selected_index()); |
| 319 EXPECT_EQ(6, menu_show_count_); |
| 320 |
| 295 PressKey(ui::VKEY_NEXT); | 321 PressKey(ui::VKEY_NEXT); |
| 296 EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); | 322 EXPECT_EQ(0, combobox_->selected_index()); |
| 323 EXPECT_EQ(6, menu_show_count_); |
| 297 } | 324 } |
| 325 #endif |
| 298 | 326 |
| 299 // Check that if a combobox is disabled before it has a native wrapper, then the | 327 // Check that if a combobox is disabled before it has a native wrapper, then the |
| 300 // native wrapper inherits the disabled state when it gets created. | 328 // native wrapper inherits the disabled state when it gets created. |
| 301 TEST_F(ComboboxTest, DisabilityTest) { | 329 TEST_F(ComboboxTest, DisabilityTest) { |
| 302 model_.reset(new TestComboboxModel()); | 330 model_.reset(new TestComboboxModel()); |
| 303 | 331 |
| 304 ASSERT_FALSE(combobox_); | 332 ASSERT_FALSE(combobox_); |
| 305 combobox_ = new TestCombobox(model_.get(), Combobox::STYLE_NORMAL); | 333 combobox_ = new TestCombobox(model_.get(), Combobox::STYLE_NORMAL); |
| 306 combobox_->SetEnabled(false); | 334 combobox_->SetEnabled(false); |
| 307 | 335 |
| 308 widget_ = new Widget; | 336 widget_ = new Widget; |
| 309 Widget::InitParams params = | 337 Widget::InitParams params = |
| 310 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 338 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 311 params.bounds = gfx::Rect(100, 100, 100, 100); | 339 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 312 widget_->Init(params); | 340 widget_->Init(params); |
| 313 View* container = new View(); | 341 View* container = new View(); |
| 314 widget_->SetContentsView(container); | 342 widget_->SetContentsView(container); |
| 315 container->AddChildView(combobox_); | 343 container->AddChildView(combobox_); |
| 316 EXPECT_FALSE(combobox_->enabled()); | 344 EXPECT_FALSE(combobox_->enabled()); |
| 317 } | 345 } |
| 318 | 346 |
| 347 // On Mac, key events can't change the currently selected index directly for a |
| 348 // combobox. |
| 349 #if !defined(OS_MACOSX) |
| 350 |
| 351 // Tests the behavior of various keyboard shortcuts on the currently selected |
| 352 // index. |
| 353 TEST_F(ComboboxTest, KeyTest) { |
| 354 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 355 PressKey(ui::VKEY_END); |
| 356 EXPECT_EQ(model_->GetItemCount(), combobox_->selected_index() + 1); |
| 357 PressKey(ui::VKEY_HOME); |
| 358 EXPECT_EQ(0, combobox_->selected_index()); |
| 359 PressKey(ui::VKEY_DOWN); |
| 360 PressKey(ui::VKEY_DOWN); |
| 361 EXPECT_EQ(2, combobox_->selected_index()); |
| 362 PressKey(ui::VKEY_RIGHT); |
| 363 EXPECT_EQ(2, combobox_->selected_index()); |
| 364 PressKey(ui::VKEY_LEFT); |
| 365 EXPECT_EQ(2, combobox_->selected_index()); |
| 366 PressKey(ui::VKEY_UP); |
| 367 EXPECT_EQ(1, combobox_->selected_index()); |
| 368 PressKey(ui::VKEY_PRIOR); |
| 369 EXPECT_EQ(0, combobox_->selected_index()); |
| 370 PressKey(ui::VKEY_NEXT); |
| 371 EXPECT_EQ(model_->GetItemCount() - 1, combobox_->selected_index()); |
| 372 } |
| 373 |
| 319 // Verifies that we don't select a separator line in combobox when navigating | 374 // Verifies that we don't select a separator line in combobox when navigating |
| 320 // through keyboard. | 375 // through keyboard. |
| 321 TEST_F(ComboboxTest, SkipSeparatorSimple) { | 376 TEST_F(ComboboxTest, SkipSeparatorSimple) { |
| 322 std::set<int> separators; | 377 std::set<int> separators; |
| 323 separators.insert(2); | 378 separators.insert(2); |
| 324 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 379 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 325 EXPECT_EQ(0, combobox_->selected_index()); | 380 EXPECT_EQ(0, combobox_->selected_index()); |
| 326 PressKey(ui::VKEY_DOWN); | 381 PressKey(ui::VKEY_DOWN); |
| 327 EXPECT_EQ(1, combobox_->selected_index()); | 382 EXPECT_EQ(1, combobox_->selected_index()); |
| 328 PressKey(ui::VKEY_DOWN); | 383 PressKey(ui::VKEY_DOWN); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 EXPECT_EQ(5, combobox_->selected_index()); | 484 EXPECT_EQ(5, combobox_->selected_index()); |
| 430 PressKey(ui::VKEY_HOME); | 485 PressKey(ui::VKEY_HOME); |
| 431 EXPECT_EQ(0, combobox_->selected_index()); | 486 EXPECT_EQ(0, combobox_->selected_index()); |
| 432 PressKey(ui::VKEY_NEXT); | 487 PressKey(ui::VKEY_NEXT); |
| 433 EXPECT_EQ(6, combobox_->selected_index()); | 488 EXPECT_EQ(6, combobox_->selected_index()); |
| 434 PressKey(ui::VKEY_PRIOR); | 489 PressKey(ui::VKEY_PRIOR); |
| 435 EXPECT_EQ(0, combobox_->selected_index()); | 490 EXPECT_EQ(0, combobox_->selected_index()); |
| 436 PressKey(ui::VKEY_END); | 491 PressKey(ui::VKEY_END); |
| 437 EXPECT_EQ(6, combobox_->selected_index()); | 492 EXPECT_EQ(6, combobox_->selected_index()); |
| 438 } | 493 } |
| 494 #endif // !OS_MACOSX |
| 439 | 495 |
| 440 TEST_F(ComboboxTest, GetTextForRowTest) { | 496 TEST_F(ComboboxTest, GetTextForRowTest) { |
| 441 std::set<int> separators; | 497 std::set<int> separators; |
| 442 separators.insert(0); | 498 separators.insert(0); |
| 443 separators.insert(1); | 499 separators.insert(1); |
| 444 separators.insert(9); | 500 separators.insert(9); |
| 445 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 501 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 446 for (int i = 0; i < combobox_->GetRowCount(); ++i) { | 502 for (int i = 0; i < combobox_->GetRowCount(); ++i) { |
| 447 if (separators.count(i) != 0) { | 503 if (separators.count(i) != 0) { |
| 448 EXPECT_TRUE(combobox_->GetTextForRow(i).empty()) << i; | 504 EXPECT_TRUE(combobox_->GetTextForRow(i).empty()) << i; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 595 } |
| 540 | 596 |
| 541 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { | 597 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
| 542 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 598 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 543 | 599 |
| 544 TestComboboxListener listener; | 600 TestComboboxListener listener; |
| 545 combobox_->set_listener(&listener); | 601 combobox_->set_listener(&listener); |
| 546 | 602 |
| 547 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. | 603 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. |
| 548 PressKey(ui::VKEY_RETURN); | 604 PressKey(ui::VKEY_RETURN); |
| 549 EXPECT_EQ(1, menu_show_count_); | 605 EXPECT_EQ(PlatformStyle::kReturnClicksFocusedControl ? 1 : 0, |
| 606 menu_show_count_); |
| 550 EXPECT_FALSE(listener.on_perform_action_called()); | 607 EXPECT_FALSE(listener.on_perform_action_called()); |
| 551 } | 608 } |
| 552 | 609 |
| 553 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { | 610 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { |
| 554 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 611 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 555 | 612 |
| 556 TestComboboxListener listener; | 613 TestComboboxListener listener; |
| 557 combobox_->set_listener(&listener); | 614 combobox_->set_listener(&listener); |
| 558 | 615 |
| 559 // With STYLE_ACTION, the click event is notified and the menu is not shown. | 616 // With STYLE_ACTION, the click event is notified and the menu is not shown. |
| 560 PressKey(ui::VKEY_RETURN); | 617 PressKey(ui::VKEY_RETURN); |
| 561 EXPECT_EQ(0, menu_show_count_); | 618 EXPECT_EQ(0, menu_show_count_); |
| 562 EXPECT_TRUE(listener.on_perform_action_called()); | 619 |
| 563 EXPECT_EQ(0, listener.perform_action_index()); | 620 if (PlatformStyle::kReturnClicksFocusedControl) { |
| 621 EXPECT_TRUE(listener.on_perform_action_called()); |
| 622 EXPECT_EQ(0, listener.perform_action_index()); |
| 623 } else { |
| 624 EXPECT_FALSE(listener.on_perform_action_called()); |
| 625 EXPECT_EQ(-1, listener.perform_action_index()); |
| 626 } |
| 564 } | 627 } |
| 565 | 628 |
| 566 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { | 629 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { |
| 567 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 630 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 568 | 631 |
| 569 TestComboboxListener listener; | 632 TestComboboxListener listener; |
| 570 combobox_->set_listener(&listener); | 633 combobox_->set_listener(&listener); |
| 571 | 634 |
| 572 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. | 635 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. |
| 573 PressKey(ui::VKEY_SPACE); | 636 PressKey(ui::VKEY_SPACE); |
| 574 EXPECT_EQ(1, menu_show_count_); | 637 EXPECT_EQ(1, menu_show_count_); |
| 575 EXPECT_FALSE(listener.on_perform_action_called()); | 638 EXPECT_FALSE(listener.on_perform_action_called()); |
| 576 | 639 |
| 577 ReleaseKey(ui::VKEY_SPACE); | 640 ReleaseKey(ui::VKEY_SPACE); |
| 578 EXPECT_EQ(1, menu_show_count_); | 641 EXPECT_EQ(1, menu_show_count_); |
| 579 EXPECT_FALSE(listener.on_perform_action_called()); | 642 EXPECT_FALSE(listener.on_perform_action_called()); |
| 580 } | 643 } |
| 581 | 644 |
| 582 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { | 645 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { |
| 583 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 646 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 584 | 647 |
| 585 TestComboboxListener listener; | 648 TestComboboxListener listener; |
| 586 combobox_->set_listener(&listener); | 649 combobox_->set_listener(&listener); |
| 587 | 650 |
| 588 // With STYLE_ACTION, the click event is notified after releasing and the menu | 651 // With STYLE_ACTION, the click event is notified after releasing and the menu |
| 589 // is not shown. | 652 // is not shown. On Mac, the menu should be shown. |
| 590 PressKey(ui::VKEY_SPACE); | 653 PressKey(ui::VKEY_SPACE); |
| 654 #if defined(OS_MACOSX) |
| 655 EXPECT_EQ(1, menu_show_count_); |
| 656 #else |
| 591 EXPECT_EQ(0, menu_show_count_); | 657 EXPECT_EQ(0, menu_show_count_); |
| 658 #endif |
| 592 EXPECT_FALSE(listener.on_perform_action_called()); | 659 EXPECT_FALSE(listener.on_perform_action_called()); |
| 660 EXPECT_EQ(-1, listener.perform_action_index()); |
| 593 | 661 |
| 594 ReleaseKey(ui::VKEY_SPACE); | 662 ReleaseKey(ui::VKEY_SPACE); |
| 663 #if defined(OS_MACOSX) |
| 664 EXPECT_EQ(1, menu_show_count_); |
| 665 EXPECT_FALSE(listener.on_perform_action_called()); |
| 666 EXPECT_EQ(-1, listener.perform_action_index()); |
| 667 #else |
| 595 EXPECT_EQ(0, menu_show_count_); | 668 EXPECT_EQ(0, menu_show_count_); |
| 596 EXPECT_TRUE(listener.on_perform_action_called()); | 669 EXPECT_TRUE(listener.on_perform_action_called()); |
| 597 EXPECT_EQ(0, listener.perform_action_index()); | 670 EXPECT_EQ(0, listener.perform_action_index()); |
| 671 #endif |
| 598 } | 672 } |
| 599 | 673 |
| 600 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { | 674 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { |
| 601 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 675 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 602 | 676 |
| 603 TestComboboxListener listener; | 677 TestComboboxListener listener; |
| 604 combobox_->set_listener(&listener); | 678 combobox_->set_listener(&listener); |
| 605 | 679 |
| 606 combobox_->Layout(); | 680 combobox_->Layout(); |
| 607 | 681 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 631 PerformMouseRelease(left_point); | 705 PerformMouseRelease(left_point); |
| 632 | 706 |
| 633 EXPECT_EQ(1, menu_show_count_); // Unchanged. | 707 EXPECT_EQ(1, menu_show_count_); // Unchanged. |
| 634 EXPECT_EQ(0, listener.perform_action_index()); | 708 EXPECT_EQ(0, listener.perform_action_index()); |
| 635 } | 709 } |
| 636 | 710 |
| 637 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { | 711 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { |
| 638 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 712 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 639 | 713 |
| 640 EXPECT_TRUE(combobox_->OnKeyPressed( | 714 EXPECT_TRUE(combobox_->OnKeyPressed( |
| 641 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); | 715 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); |
| 642 EXPECT_EQ(1, menu_show_count_); | 716 EXPECT_EQ(1, menu_show_count_); |
| 643 EXPECT_TRUE(combobox_->OnKeyPressed( | 717 |
| 644 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); | 718 ui::KeyEvent return_press(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE); |
| 645 EXPECT_EQ(2, menu_show_count_); | 719 if (PlatformStyle::kReturnClicksFocusedControl) { |
| 720 EXPECT_TRUE(combobox_->OnKeyPressed(return_press)); |
| 721 EXPECT_EQ(2, menu_show_count_); |
| 722 } else { |
| 723 EXPECT_FALSE(combobox_->OnKeyPressed(return_press)); |
| 724 EXPECT_EQ(1, menu_show_count_); |
| 725 } |
| 646 } | 726 } |
| 647 | 727 |
| 648 TEST_F(ComboboxTest, ConsumingKeyPressEventsActionStyle) { | 728 TEST_F(ComboboxTest, ConsumingKeyPressEventsActionStyle) { |
| 649 // When the combobox's style is STYLE_ACTION, pressing events of a space key | 729 // When the combobox's style is STYLE_ACTION, pressing events of a space key |
| 650 // or an enter key will be consumed and the menu is not shown. | 730 // or an enter key will be consumed and the menu is not shown. However, on |
| 731 // Mac, space will show the menu. |
| 651 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 732 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 652 | 733 |
| 653 EXPECT_TRUE(combobox_->OnKeyPressed( | 734 EXPECT_EQ(PlatformStyle::kReturnClicksFocusedControl, |
| 654 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); | 735 combobox_->OnKeyPressed(ui::KeyEvent( |
| 736 ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); |
| 655 EXPECT_EQ(0, menu_show_count_); | 737 EXPECT_EQ(0, menu_show_count_); |
| 738 |
| 656 EXPECT_TRUE(combobox_->OnKeyPressed( | 739 EXPECT_TRUE(combobox_->OnKeyPressed( |
| 657 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); | 740 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); |
| 741 #if defined(OS_MACOSX) |
| 742 EXPECT_EQ(1, menu_show_count_); |
| 743 #else |
| 658 EXPECT_EQ(0, menu_show_count_); | 744 EXPECT_EQ(0, menu_show_count_); |
| 745 #endif |
| 659 } | 746 } |
| 660 | 747 |
| 661 TEST_F(ComboboxTest, ContentWidth) { | 748 TEST_F(ComboboxTest, ContentWidth) { |
| 662 std::vector<std::string> values; | 749 std::vector<std::string> values; |
| 663 VectorComboboxModel model(&values); | 750 VectorComboboxModel model(&values); |
| 664 TestCombobox combobox(&model, Combobox::STYLE_NORMAL); | 751 TestCombobox combobox(&model, Combobox::STYLE_NORMAL); |
| 665 TestCombobox action_combobox(&model, Combobox::STYLE_ACTION); | 752 TestCombobox action_combobox(&model, Combobox::STYLE_ACTION); |
| 666 ComboboxTestApi test_api(&combobox); | 753 ComboboxTestApi test_api(&combobox); |
| 667 ComboboxTestApi action_test_api(&action_combobox); | 754 ComboboxTestApi action_test_api(&action_combobox); |
| 668 | 755 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); | 916 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
| 830 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 917 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
| 831 | 918 |
| 832 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 919 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
| 833 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 920 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
| 834 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 921 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
| 835 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 922 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
| 836 } | 923 } |
| 837 | 924 |
| 838 } // namespace views | 925 } // namespace views |
| OLD | NEW |