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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 | 595 |
| 596 ViewCompositionRangeChangedObserver range_observer(web_contents, view); | 596 ViewCompositionRangeChangedObserver range_observer(web_contents, view); |
| 597 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); | 597 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); |
| 598 range_observer.Wait(); | 598 range_observer.Wait(); |
| 599 }; | 599 }; |
| 600 | 600 |
| 601 for (auto* view : views) | 601 for (auto* view : views) |
| 602 send_tab_set_composition_wait_for_bounds_change(view); | 602 send_tab_set_composition_wait_for_bounds_change(view); |
| 603 } | 603 } |
| 604 | 604 |
| 605 // TODO(ekaramad): Enable the following tests on other platforms when the | |
| 606 // corresponding feature is implemented (http://crbug.com/578168). | |
| 607 #if defined(USE_AURA) | |
| 608 // This test creates a page with multiple child frames and adds an <input> to | |
| 609 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | |
| 610 // Then, after |TextInputState.type| for a view is changed to text, another key | |
| 611 // is pressed (a character) and then the test verifies that TextInputManager | |
| 612 // receives the corresponding update on the change in selection bounds on the | |
| 613 // browser side. | |
| 614 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 615 TrackSelectionBoundsForAllFrames) { | |
| 616 CreateIframePage("a(b,c(a,b),d)"); | |
| 617 std::vector<content::RenderFrameHost*> frames{ | |
| 618 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 619 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 620 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 621 std::vector<content::RenderWidgetHostView*> views; | |
| 622 for (auto* frame : frames) | |
| 623 views.push_back(frame->GetView()); | |
| 624 for (size_t i = 0; i < frames.size(); ++i) | |
| 625 AddInputFieldToFrame(frames[i], "text", "", true); | |
| 626 | |
| 627 content::WebContents* web_contents = active_contents(); | |
| 628 | |
| 629 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents]( | |
| 630 content::RenderWidgetHostView* view) { | |
|
EhsanK
2016/08/17 21:36:00
This test is just copied over (actually not copied
| |
| 631 ViewTextInputTypeObserver type_observer(web_contents, view, | |
| 632 ui::TEXT_INPUT_TYPE_TEXT); | |
| 633 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 634 ui::VKEY_TAB, false, false, false, false); | |
| 635 type_observer.Wait(); | |
| 636 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); | |
| 637 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | |
| 638 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); | |
| 639 bounds_observer.Wait(); | |
| 640 }; | |
| 641 | |
| 642 for (auto* view : views) | |
| 643 send_tab_insert_text_wait_for_bounds_change(view); | |
| 644 } | |
| 645 | |
| 646 // This test creates a page with multiple child frames and adds an <input> to | 605 // This test creates a page with multiple child frames and adds an <input> to |
| 647 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 606 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 648 // After focusing each input, a sequence of key presses (character 'E') are sent | 607 // After focusing each input, a sequence of key presses (character 'E') are sent |
| 649 // to the focused widget and then the whole text is selected using Ctrl+A. The | 608 // to the focused widget. The test then verifies that the selection length |
| 650 // test then verifies that the selection length equals the length of the | 609 // equals the length of the sequence of 'E's. |
| 651 // sequence of 'E's. | |
| 652 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 610 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 653 TrackTextSelectionForAllFrames) { | 611 TrackTextSelectionForAllFrames) { |
| 654 CreateIframePage("a(b,c(a,b),d)"); | 612 CreateIframePage("a(b,c(a,b),d)"); |
| 655 std::vector<content::RenderFrameHost*> frames{ | 613 std::vector<content::RenderFrameHost*> frames{ |
| 656 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | 614 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| 657 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | 615 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), |
| 658 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | 616 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; |
| 659 std::vector<std::string> values{"main", "b", "c", "ca", "cb", "d"}; | 617 std::vector<std::string> values{"main", "b", "c", "ca", "cb", "d"}; |
| 660 std::vector<content::RenderWidgetHostView*> views; | 618 std::vector<content::RenderWidgetHostView*> views; |
| 661 for (auto* frame : frames) | 619 for (auto* frame : frames) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 673 }; | 631 }; |
| 674 | 632 |
| 675 auto send_keys_select_all_wait_for_selection_change = [&web_contents]( | 633 auto send_keys_select_all_wait_for_selection_change = [&web_contents]( |
| 676 content::RenderWidgetHostView* view, size_t count) { | 634 content::RenderWidgetHostView* view, size_t count) { |
| 677 ViewTextSelectionObserver observer(web_contents, view, count); | 635 ViewTextSelectionObserver observer(web_contents, view, count); |
| 678 for (size_t i = 0; i < count; ++i) { | 636 for (size_t i = 0; i < count; ++i) { |
| 679 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | 637 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), |
| 680 ui::DomCode::US_E, ui::VKEY_E, false, false, false, | 638 ui::DomCode::US_E, ui::VKEY_E, false, false, false, |
| 681 false); | 639 false); |
| 682 } | 640 } |
| 683 // Send Ctrl+A to select the whole text. | |
| 684 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('a'), | |
| 685 ui::DomCode::US_A, ui::VKEY_A, true, false, false, false); | |
|
EhsanK
2016/08/17 21:36:00
This was removed since it was not needed nor corre
| |
| 686 observer.Wait(); | 641 observer.Wait(); |
| 687 }; | 642 }; |
| 688 | 643 |
| 689 size_t count = 2; | 644 size_t count = 2; |
| 690 for (size_t i = 0; i < views.size(); ++i) { | 645 for (size_t i = 0; i < views.size(); ++i) { |
| 691 // First focus the <input>. | 646 // First focus the <input>. |
| 692 send_tab_and_wait_for_value(values[i]); | 647 send_tab_and_wait_for_value(values[i]); |
| 693 | 648 |
| 694 // Send a sequence of |count| 'E' keys and wait until the view receives a | 649 // Send a sequence of |count| 'E' keys and wait until the view receives a |
| 695 // selection change update for a text of the corresponding size, |count|. | 650 // selection change update for a text of the corresponding size, |count|. |
| 696 send_keys_select_all_wait_for_selection_change(views[i], count++); | 651 send_keys_select_all_wait_for_selection_change(views[i], count++); |
| 697 } | 652 } |
| 698 } | 653 } |
| 699 | 654 |
| 655 // TODO(ekaramad): Enable the following tests on other platforms when the | |
|
sky
2016/08/17 20:42:52
Is there a compelling reason to move the test here
EhsanK
2016/08/17 21:36:00
Sorry for the ugly diff. Hmmm...actually, the inte
sky
2016/08/17 23:32:47
Any chance you could add ifdefs instead? Again, it
EhsanK
2016/08/18 14:43:29
Done (assuming that I understood the suggestion co
| |
| 656 // corresponding feature is implemented (http://crbug.com/578168). | |
| 657 #if defined(USE_AURA) | |
| 658 // This test creates a page with multiple child frames and adds an <input> to | |
| 659 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | |
| 660 // Then, after |TextInputState.type| for a view is changed to text, another key | |
| 661 // is pressed (a character) and then the test verifies that TextInputManager | |
| 662 // receives the corresponding update on the change in selection bounds on the | |
| 663 // browser side. | |
| 664 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 665 TrackSelectionBoundsForAllFrames) { | |
| 666 CreateIframePage("a(b,c(a,b),d)"); | |
| 667 std::vector<content::RenderFrameHost*> frames{ | |
| 668 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 669 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 670 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 671 std::vector<content::RenderWidgetHostView*> views; | |
| 672 for (auto* frame : frames) | |
| 673 views.push_back(frame->GetView()); | |
| 674 for (size_t i = 0; i < frames.size(); ++i) | |
| 675 AddInputFieldToFrame(frames[i], "text", "", true); | |
| 676 | |
| 677 content::WebContents* web_contents = active_contents(); | |
| 678 | |
| 679 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents]( | |
| 680 content::RenderWidgetHostView* view) { | |
| 681 ViewTextInputTypeObserver type_observer(web_contents, view, | |
| 682 ui::TEXT_INPUT_TYPE_TEXT); | |
| 683 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 684 ui::VKEY_TAB, false, false, false, false); | |
| 685 type_observer.Wait(); | |
| 686 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); | |
| 687 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | |
| 688 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); | |
| 689 bounds_observer.Wait(); | |
| 690 }; | |
| 691 | |
| 692 for (auto* view : views) | |
| 693 send_tab_insert_text_wait_for_bounds_change(view); | |
| 694 } | |
| 695 | |
| 700 // The following test verifies that when the active widget changes value, it is | 696 // The following test verifies that when the active widget changes value, it is |
| 701 // always from nullptr to non-null or vice versa. | 697 // always from nullptr to non-null or vice versa. |
| 702 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 698 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 703 ResetTextInputStateOnActiveWidgetChange) { | 699 ResetTextInputStateOnActiveWidgetChange) { |
| 704 CreateIframePage("a(b,c(a,b),d)"); | 700 CreateIframePage("a(b,c(a,b),d)"); |
| 705 std::vector<content::RenderFrameHost*> frames{ | 701 std::vector<content::RenderFrameHost*> frames{ |
| 706 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | 702 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| 707 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | 703 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), |
| 708 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | 704 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; |
| 709 std::vector<content::RenderWidgetHostView*> views; | 705 std::vector<content::RenderWidgetHostView*> views; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 | 854 |
| 859 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 855 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 860 sender.SetShowImeIfNeeded(true); | 856 sender.SetShowImeIfNeeded(true); |
| 861 EXPECT_TRUE(send_and_check_show_ime()); | 857 EXPECT_TRUE(send_and_check_show_ime()); |
| 862 | 858 |
| 863 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 859 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 864 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 860 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 865 EXPECT_FALSE(send_and_check_show_ime()); | 861 EXPECT_FALSE(send_and_check_show_ime()); |
| 866 } | 862 } |
| 867 #endif // USE_AURA | 863 #endif // USE_AURA |
| OLD | NEW |