Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, | 558 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| 559 ui::VKEY_TAB, false, false, false, false); | 559 ui::VKEY_TAB, false, false, false, false); |
| 560 set_state_observer.Wait(); | 560 set_state_observer.Wait(); |
| 561 | 561 |
| 562 TextInputManagerTypeObserver reset_state_observer(active_contents(), | 562 TextInputManagerTypeObserver reset_state_observer(active_contents(), |
| 563 ui::TEXT_INPUT_TYPE_NONE); | 563 ui::TEXT_INPUT_TYPE_NONE); |
| 564 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 564 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 565 reset_state_observer.Wait(); | 565 reset_state_observer.Wait(); |
| 566 } | 566 } |
| 567 | 567 |
| 568 // This test creates a page with multiple child frames and adds an <input> to | |
| 569 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | |
| 570 // After focusing each input, a sequence of key presses (character 'E') are sent | |
| 571 // to the focused widget and then the whole text is selected using Ctrl+A. The | |
| 572 // test then verifies that the selection length equals the length of the | |
| 573 // sequence of 'E's. | |
| 574 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 575 TrackTextSelectionForAllFrames) { | |
| 576 CreateIframePage("a(b,c(a,b),d)"); | |
| 577 std::vector<content::RenderFrameHost*> frames{ | |
| 578 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 579 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 580 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 581 std::vector<std::string> values{"main", "b", "c", "ca", "cb", "d"}; | |
| 582 std::vector<content::RenderWidgetHostView*> views; | |
| 583 for (auto* frame : frames) | |
| 584 views.push_back(frame->GetView()); | |
| 585 for (size_t i = 0; i < frames.size(); ++i) | |
| 586 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
| 587 | |
| 588 content::WebContents* web_contents = active_contents(); | |
| 589 | |
| 590 auto send_tab_and_wait_for_value = [&web_contents](const std::string& value) { | |
| 591 TextInputManagerValueObserver observer(web_contents, value); | |
| 592 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 593 ui::VKEY_TAB, false, false, false, false); | |
| 594 observer.Wait(); | |
| 595 }; | |
| 596 | |
| 597 auto send_keys_select_all_wait_for_selection_change = [&web_contents]( | |
| 598 content::RenderWidgetHostView* view, size_t count) { | |
| 599 ViewTextSelectionObserver observer(web_contents, view, count); | |
| 600 for (size_t i = 0; i < count; ++i) { | |
| 601 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | |
| 602 ui::DomCode::US_E, ui::VKEY_E, false, false, false, | |
| 603 false); | |
| 604 } | |
| 605 // Send Ctrl+A to select the whole text. | |
| 606 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('a'), | |
| 607 ui::DomCode::US_A, ui::VKEY_A, true, false, false, false); | |
|
Avi (use Gerrit)
2016/08/12 15:53:10
Why is control-A supposed to work on the Mac? On t
EhsanK
2016/08/16 13:36:44
Very good catch! You are right and I was not selec
EhsanK
2016/08/16 13:46:45
Sorry - outdated comment. The second paragraph is
| |
| 608 observer.Wait(); | |
| 609 }; | |
| 610 | |
| 611 size_t count = 2; | |
| 612 for (size_t i = 0; i < views.size(); ++i) { | |
| 613 // First focus the <input>. | |
| 614 send_tab_and_wait_for_value(values[i]); | |
| 615 | |
| 616 // Send a sequence of |count| 'E' keys and wait until the view receives a | |
| 617 // selection change update for a text of the corresponding size, |count|. | |
| 618 send_keys_select_all_wait_for_selection_change(views[i], count++); | |
| 619 } | |
| 620 } | |
| 621 | |
| 568 // TODO(ekaramad): Enable the following tests on other platforms when the | 622 // TODO(ekaramad): Enable the following tests on other platforms when the |
| 569 // corresponding feature is implemented (http://crbug.com/578168). | 623 // corresponding feature is implemented (http://crbug.com/578168). |
| 570 #if defined(USE_AURA) | 624 #if defined(USE_AURA) |
| 571 // This test creates a page with multiple child frames and adds an <input> to | 625 // This test creates a page with multiple child frames and adds an <input> to |
| 572 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 626 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 573 // Then, after |TextInputState.type| for a view is changed to text, another key | 627 // Then, after |TextInputState.type| for a view is changed to text, another key |
| 574 // is pressed (a character) and then the test verifies that TextInputManager | 628 // is pressed (a character) and then the test verifies that TextInputManager |
| 575 // receives the corresponding update on the change in selection bounds on the | 629 // receives the corresponding update on the change in selection bounds on the |
| 576 // browser side. | 630 // browser side. |
| 577 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 631 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 type_observer.Wait(); | 689 type_observer.Wait(); |
| 636 ViewCompositionRangeChangedObserver range_observer(web_contents, view); | 690 ViewCompositionRangeChangedObserver range_observer(web_contents, view); |
| 637 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); | 691 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); |
| 638 range_observer.Wait(); | 692 range_observer.Wait(); |
| 639 }; | 693 }; |
| 640 | 694 |
| 641 for (auto* view : views) | 695 for (auto* view : views) |
| 642 send_tab_set_composition_wait_for_bounds_change(view); | 696 send_tab_set_composition_wait_for_bounds_change(view); |
| 643 } | 697 } |
| 644 | 698 |
| 645 // This test creates a page with multiple child frames and adds an <input> to | |
| 646 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | |
| 647 // After focusing each input, a sequence of key presses (character 'E') are sent | |
| 648 // to the focused widget and then the whole text is selected using Ctrl+A. The | |
| 649 // test then verifies that the selection length equals the length of the | |
| 650 // sequence of 'E's. | |
| 651 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 652 TrackTextSelectionForAllFrames) { | |
| 653 CreateIframePage("a(b,c(a,b),d)"); | |
| 654 std::vector<content::RenderFrameHost*> frames{ | |
| 655 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 656 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 657 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 658 std::vector<std::string> values{"main", "b", "c", "ca", "cb", "d"}; | |
| 659 std::vector<content::RenderWidgetHostView*> views; | |
| 660 for (auto* frame : frames) | |
| 661 views.push_back(frame->GetView()); | |
| 662 for (size_t i = 0; i < frames.size(); ++i) | |
| 663 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
| 664 | |
| 665 content::WebContents* web_contents = active_contents(); | |
| 666 | |
| 667 auto send_tab_and_wait_for_value = [&web_contents](const std::string& value) { | |
| 668 TextInputManagerValueObserver observer(web_contents, value); | |
| 669 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 670 ui::VKEY_TAB, false, false, false, false); | |
| 671 observer.Wait(); | |
| 672 }; | |
| 673 | |
| 674 auto send_keys_select_all_wait_for_selection_change = [&web_contents]( | |
| 675 content::RenderWidgetHostView* view, size_t count) { | |
| 676 ViewTextSelectionObserver observer(web_contents, view, count); | |
| 677 for (size_t i = 0; i < count; ++i) { | |
| 678 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | |
| 679 ui::DomCode::US_E, ui::VKEY_E, false, false, false, | |
| 680 false); | |
| 681 } | |
| 682 // Send Ctrl+A to select the whole text. | |
| 683 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('a'), | |
| 684 ui::DomCode::US_A, ui::VKEY_A, true, false, false, false); | |
| 685 observer.Wait(); | |
| 686 }; | |
| 687 | |
| 688 size_t count = 2; | |
| 689 for (size_t i = 0; i < views.size(); ++i) { | |
| 690 // First focus the <input>. | |
| 691 send_tab_and_wait_for_value(values[i]); | |
| 692 | |
| 693 // Send a sequence of |count| 'E' keys and wait until the view receives a | |
| 694 // selection change update for a text of the corresponding size, |count|. | |
| 695 send_keys_select_all_wait_for_selection_change(views[i], count++); | |
| 696 } | |
| 697 } | |
| 698 | |
| 699 // The following test verifies that when the active widget changes value, it is | 699 // The following test verifies that when the active widget changes value, it is |
| 700 // always from nullptr to non-null or vice versa. | 700 // always from nullptr to non-null or vice versa. |
| 701 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 701 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 702 ResetTextInputStateOnActiveWidgetChange) { | 702 ResetTextInputStateOnActiveWidgetChange) { |
| 703 CreateIframePage("a(b,c(a,b),d)"); | 703 CreateIframePage("a(b,c(a,b),d)"); |
| 704 std::vector<content::RenderFrameHost*> frames{ | 704 std::vector<content::RenderFrameHost*> frames{ |
| 705 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | 705 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| 706 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | 706 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), |
| 707 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | 707 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; |
| 708 std::vector<content::RenderWidgetHostView*> views; | 708 std::vector<content::RenderWidgetHostView*> views; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 | 857 |
| 858 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 858 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 859 sender.SetShowImeIfNeeded(true); | 859 sender.SetShowImeIfNeeded(true); |
| 860 EXPECT_TRUE(send_and_check_show_ime()); | 860 EXPECT_TRUE(send_and_check_show_ime()); |
| 861 | 861 |
| 862 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 862 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 863 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 863 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 864 EXPECT_FALSE(send_and_check_show_ime()); | 864 EXPECT_FALSE(send_and_check_show_ime()); |
| 865 } | 865 } |
| 866 #endif // USE_AURA | 866 #endif // USE_AURA |
| OLD | NEW |