| 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/chrome_content_browser_client.h" | 9 #include "chrome/browser/chrome_content_browser_client.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 | 735 |
| 736 ViewCompositionRangeChangedObserver range_observer(web_contents, view); | 736 ViewCompositionRangeChangedObserver range_observer(web_contents, view); |
| 737 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); | 737 EXPECT_TRUE(content::RequestCompositionInfoFromActiveWidget(web_contents)); |
| 738 range_observer.Wait(); | 738 range_observer.Wait(); |
| 739 }; | 739 }; |
| 740 | 740 |
| 741 for (auto* view : views) | 741 for (auto* view : views) |
| 742 send_tab_set_composition_wait_for_bounds_change(view); | 742 send_tab_set_composition_wait_for_bounds_change(view); |
| 743 } | 743 } |
| 744 | 744 |
| 745 // TODO(ekaramad): Some of the following tests should be active on Android as | |
| 746 // well. Enable them when the corresponding feature is implemented for Android | |
| 747 // (https://crbug.com/602723). | |
| 748 #if !defined(OS_ANDROID) | |
| 749 // This test creates a page with multiple child frames and adds an <input> to | |
| 750 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | |
| 751 // Then, after |TextInputState.type| for a view is changed to text, another key | |
| 752 // is pressed (a character) and then the test verifies that TextInputManager | |
| 753 // receives the corresponding update on the change in selection bounds on the | |
| 754 // browser side. | |
| 755 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 756 TrackSelectionBoundsForAllFrames) { | |
| 757 CreateIframePage("a(b,c(a,b),d)"); | |
| 758 std::vector<content::RenderFrameHost*> frames{ | |
| 759 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 760 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 761 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 762 std::vector<content::RenderWidgetHostView*> views; | |
| 763 for (auto* frame : frames) | |
| 764 views.push_back(frame->GetView()); | |
| 765 for (size_t i = 0; i < frames.size(); ++i) | |
| 766 AddInputFieldToFrame(frames[i], "text", "", true); | |
| 767 | |
| 768 content::WebContents* web_contents = active_contents(); | |
| 769 | |
| 770 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents]( | |
| 771 content::RenderWidgetHostView* view) { | |
| 772 ViewTextInputTypeObserver type_observer(web_contents, view, | |
| 773 ui::TEXT_INPUT_TYPE_TEXT); | |
| 774 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 775 ui::VKEY_TAB, false, false, false, false); | |
| 776 type_observer.Wait(); | |
| 777 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); | |
| 778 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), | |
| 779 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); | |
| 780 bounds_observer.Wait(); | |
| 781 }; | |
| 782 | |
| 783 for (auto* view : views) | |
| 784 send_tab_insert_text_wait_for_bounds_change(view); | |
| 785 } | |
| 786 | |
| 787 // This test creates a page with multiple child frames and adds an <input> to | 745 // This test creates a page with multiple child frames and adds an <input> to |
| 788 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 746 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 789 // After focusing each input, a sequence of key presses (character 'E') are sent | 747 // After focusing each input, a sequence of key presses (character 'E') are sent |
| 790 // to the focused widget. The test then verifies that the selection length | 748 // to the focused widget. The test then verifies that the selection length |
| 791 // equals the length of the sequence of 'E's. | 749 // equals the length of the sequence of 'E's. |
| 792 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 750 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 793 TrackTextSelectionForAllFrames) { | 751 TrackTextSelectionForAllFrames) { |
| 794 CreateIframePage("a(b,c(a,b),d)"); | 752 CreateIframePage("a(b,c(a,b),d)"); |
| 795 std::vector<content::RenderFrameHost*> frames{ | 753 std::vector<content::RenderFrameHost*> frames{ |
| 796 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | 754 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 827 for (size_t i = 0; i < views.size(); ++i) { | 785 for (size_t i = 0; i < views.size(); ++i) { |
| 828 // First focus the <input>. | 786 // First focus the <input>. |
| 829 send_tab_and_wait_for_value(values[i]); | 787 send_tab_and_wait_for_value(values[i]); |
| 830 | 788 |
| 831 // Send a sequence of |count| 'E' keys and wait until the view receives a | 789 // Send a sequence of |count| 'E' keys and wait until the view receives a |
| 832 // selection change update for a text of the corresponding size, |count|. | 790 // selection change update for a text of the corresponding size, |count|. |
| 833 send_keys_select_all_wait_for_selection_change(views[i], count++); | 791 send_keys_select_all_wait_for_selection_change(views[i], count++); |
| 834 } | 792 } |
| 835 } | 793 } |
| 836 | 794 |
| 795 // TODO(ekaramad): Some of the following tests should be active on Android as |
| 796 // well. Enable them when the corresponding feature is implemented for Android |
| 797 // (https://crbug.com/602723). |
| 798 #if !defined(OS_ANDROID) |
| 799 // This test creates a page with multiple child frames and adds an <input> to |
| 800 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 801 // Then, after |TextInputState.type| for a view is changed to text, another key |
| 802 // is pressed (a character) and then the test verifies that TextInputManager |
| 803 // receives the corresponding update on the change in selection bounds on the |
| 804 // browser side. |
| 805 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 806 TrackSelectionBoundsForAllFrames) { |
| 807 CreateIframePage("a(b,c(a,b),d)"); |
| 808 std::vector<content::RenderFrameHost*> frames{ |
| 809 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| 810 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), |
| 811 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; |
| 812 std::vector<content::RenderWidgetHostView*> views; |
| 813 for (auto* frame : frames) |
| 814 views.push_back(frame->GetView()); |
| 815 for (size_t i = 0; i < frames.size(); ++i) |
| 816 AddInputFieldToFrame(frames[i], "text", "", true); |
| 817 |
| 818 content::WebContents* web_contents = active_contents(); |
| 819 |
| 820 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents]( |
| 821 content::RenderWidgetHostView* view) { |
| 822 ViewTextInputTypeObserver type_observer(web_contents, view, |
| 823 ui::TEXT_INPUT_TYPE_TEXT); |
| 824 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, |
| 825 ui::VKEY_TAB, false, false, false, false); |
| 826 type_observer.Wait(); |
| 827 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); |
| 828 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), |
| 829 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); |
| 830 bounds_observer.Wait(); |
| 831 }; |
| 832 |
| 833 for (auto* view : views) |
| 834 send_tab_insert_text_wait_for_bounds_change(view); |
| 835 } |
| 836 |
| 837 // This test creates a page with multiple child frames and adds two <input> | 837 // This test creates a page with multiple child frames and adds two <input> |
| 838 // elements to each frame. Then, sequentially, each <input> is focused through | 838 // elements to each frame. Then, sequentially, each <input> is focused through |
| 839 // javascript. For each frame, its text and placeholder attributes are queried | 839 // javascript. For each frame, its text and placeholder attributes are queried |
| 840 // through RenderFrameHost and verified against expected values. | 840 // through RenderFrameHost and verified against expected values. |
| 841 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 841 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 842 RequestFocusedFormFieldDataForMultipleIFrames) { | 842 RequestFocusedFormFieldDataForMultipleIFrames) { |
| 843 CreateIframePage("a(b, c)"); | 843 CreateIframePage("a(b, c)"); |
| 844 std::vector<content::RenderFrameHost*> frames{GetFrame(IndexVector{}), | 844 std::vector<content::RenderFrameHost*> frames{GetFrame(IndexVector{}), |
| 845 GetFrame(IndexVector{0}), | 845 GetFrame(IndexVector{0}), |
| 846 GetFrame(IndexVector{1})}; | 846 GetFrame(IndexVector{1})}; |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 | 1354 |
| 1355 // Closing this WebContents while we still hold on to our TestBrowserClient. | 1355 // Closing this WebContents while we still hold on to our TestBrowserClient. |
| 1356 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( | 1356 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( |
| 1357 1, TabStripModel::CLOSE_USER_GESTURE)); | 1357 1, TabStripModel::CLOSE_USER_GESTURE)); |
| 1358 | 1358 |
| 1359 // For the cleanup of the original WebContents in tab index 0. | 1359 // For the cleanup of the original WebContents in tab index 0. |
| 1360 content::SetBrowserClientForTesting(old_browser_client); | 1360 content::SetBrowserClientForTesting(old_browser_client); |
| 1361 } | 1361 } |
| 1362 #endif // defined(MAC_OSX) | 1362 #endif // defined(MAC_OSX) |
| 1363 #endif // !defined(OS_ANDROID) | 1363 #endif // !defined(OS_ANDROID) |
| OLD | NEW |