| 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 20 matching lines...) Expand all Loading... |
| 31 #include "ui/base/ime/text_input_client.h" | 31 #include "ui/base/ime/text_input_client.h" |
| 32 #include "ui/base/ime/text_input_mode.h" | 32 #include "ui/base/ime/text_input_mode.h" |
| 33 #include "ui/base/ime/text_input_type.h" | 33 #include "ui/base/ime/text_input_type.h" |
| 34 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 35 | 35 |
| 36 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 36 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 37 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | 37 #include "ui/base/ime/linux/text_edit_command_auralinux.h" |
| 38 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 38 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 // TODO(ekaramad): The following tests should be active on all platforms. After | |
| 42 // fixing https://crbug.com/578168, this test file should be built for android | |
| 43 // as well and most of the following tests should be enabled for all platforms | |
| 44 //(https://crbug.com/602723). | |
| 45 | |
| 46 /////////////////////////////////////////////////////////////////////////////// | 41 /////////////////////////////////////////////////////////////////////////////// |
| 47 // TextInputManager and IME Tests | 42 // TextInputManager and IME Tests |
| 48 // | 43 // |
| 49 // The following tests verify the correctness of TextInputState tracking on the | 44 // The following tests verify the correctness of TextInputState tracking on the |
| 50 // browser side. They also make sure the IME logic works correctly. The baseline | 45 // browser side. They also make sure the IME logic works correctly. The baseline |
| 51 // for comparison is the default functionality in the non-OOPIF case (i.e., the | 46 // for comparison is the default functionality in the non-OOPIF case (i.e., the |
| 52 // legacy implementation in RWHV's other than RWHVCF). | 47 // legacy implementation in RWHV's other than RWHVCF). |
| 53 // These tests live outside content/ because they rely on being part of the | 48 // These tests live outside content/ because they rely on being part of the |
| 54 // interactive UI test framework (to avoid flakiness). | 49 // interactive UI test framework (to avoid flakiness). |
| 55 | 50 |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, | 631 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| 637 ui::VKEY_TAB, false, false, false, false); | 632 ui::VKEY_TAB, false, false, false, false); |
| 638 set_state_observer.Wait(); | 633 set_state_observer.Wait(); |
| 639 | 634 |
| 640 TextInputManagerTypeObserver reset_state_observer(active_contents(), | 635 TextInputManagerTypeObserver reset_state_observer(active_contents(), |
| 641 ui::TEXT_INPUT_TYPE_NONE); | 636 ui::TEXT_INPUT_TYPE_NONE); |
| 642 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 637 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 643 reset_state_observer.Wait(); | 638 reset_state_observer.Wait(); |
| 644 } | 639 } |
| 645 | 640 |
| 641 // The following test verifies that when the active widget changes value, it is |
| 642 // always from nullptr to non-null or vice versa. |
| 643 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 644 ResetTextInputStateOnActiveWidgetChange) { |
| 645 CreateIframePage("a(b,c(a,b),d)"); |
| 646 std::vector<content::RenderFrameHost*> frames{ |
| 647 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| 648 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), |
| 649 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; |
| 650 std::vector<content::RenderWidgetHostView*> views; |
| 651 for (auto frame : frames) |
| 652 views.push_back(frame->GetView()); |
| 653 std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"}; |
| 654 for (size_t i = 0; i < frames.size(); ++i) |
| 655 AddInputFieldToFrame(frames[i], "text", values[i], true); |
| 656 |
| 657 content::WebContents* web_contents = active_contents(); |
| 658 |
| 659 auto send_tab_and_wait_for_value = |
| 660 [&web_contents](const std::string& expected_value) { |
| 661 TextInputManagerValueObserver observer(web_contents, expected_value); |
| 662 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, |
| 663 ui::VKEY_TAB, false, false, false, false); |
| 664 observer.Wait(); |
| 665 }; |
| 666 |
| 667 // Record all active view changes. |
| 668 RecordActiveViewsObserver recorder(web_contents); |
| 669 for (auto value : values) |
| 670 send_tab_and_wait_for_value(value); |
| 671 |
| 672 // We have covered a total of 6 views, so there should at least be 11 entries |
| 673 // recorded (at least one null between two views). |
| 674 size_t record_count = recorder.active_views()->size(); |
| 675 EXPECT_GT(record_count, 10U); |
| 676 |
| 677 // Verify we do not have subsequent nullptr or non-nullptrs. |
| 678 for (size_t i = 0; i < record_count - 1U; ++i) { |
| 679 const content::RenderWidgetHostView* current = |
| 680 recorder.active_views()->at(i); |
| 681 const content::RenderWidgetHostView* next = |
| 682 recorder.active_views()->at(i + 1U); |
| 683 EXPECT_TRUE((current != nullptr && next == nullptr) || |
| 684 (current == nullptr && next != nullptr)); |
| 685 } |
| 686 } |
| 687 |
| 688 // TODO(ekaramad): Some of the following tests should be active on Android as |
| 689 // well. Enable them when the corresponding feature is implemented for Android |
| 690 // (https://crbug.com/602723). |
| 691 #if !defined(OS_ANDROID) |
| 646 // This test creates a page with multiple child frames and adds an <input> to | 692 // 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. | 693 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 648 // Then, after |TextInputState.type| for a view is changed to text, the test | 694 // Then, after |TextInputState.type| for a view is changed to text, the test |
| 649 // sends a set composition IPC to the active widget and waits until the widget | 695 // sends a set composition IPC to the active widget and waits until the widget |
| 650 // updates its composition range. | 696 // updates its composition range. |
| 651 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 697 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 652 TrackCompositionRangeForAllFrames) { | 698 TrackCompositionRangeForAllFrames) { |
| 653 CreateIframePage("a(b,c(a,b),d)"); | 699 CreateIframePage("a(b,c(a,b),d)"); |
| 654 std::vector<content::RenderFrameHost*> frames{ | 700 std::vector<content::RenderFrameHost*> frames{ |
| 655 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | 701 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 content::RenderFrameHost* frame = frames[i / 2]; | 840 content::RenderFrameHost* frame = frames[i / 2]; |
| 795 FocusFormField(frame, values[i]); | 841 FocusFormField(frame, values[i]); |
| 796 FormFieldDataVerifier verifier(values[i], placeholders[i]); | 842 FormFieldDataVerifier verifier(values[i], placeholders[i]); |
| 797 content::FormFieldDataCallback callback = | 843 content::FormFieldDataCallback callback = |
| 798 base::Bind(&FormFieldDataVerifier::Verify, base::Unretained(&verifier)); | 844 base::Bind(&FormFieldDataVerifier::Verify, base::Unretained(&verifier)); |
| 799 frame->RequestFocusedFormFieldData(callback); | 845 frame->RequestFocusedFormFieldData(callback); |
| 800 verifier.Wait(); | 846 verifier.Wait(); |
| 801 } | 847 } |
| 802 } | 848 } |
| 803 | 849 |
| 804 // The following test verifies that when the active widget changes value, it is | |
| 805 // always from nullptr to non-null or vice versa. | |
| 806 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 807 ResetTextInputStateOnActiveWidgetChange) { | |
| 808 CreateIframePage("a(b,c(a,b),d)"); | |
| 809 std::vector<content::RenderFrameHost*> frames{ | |
| 810 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 811 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 812 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 813 std::vector<content::RenderWidgetHostView*> views; | |
| 814 for (auto frame : frames) | |
| 815 views.push_back(frame->GetView()); | |
| 816 std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"}; | |
| 817 for (size_t i = 0; i < frames.size(); ++i) | |
| 818 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
| 819 | |
| 820 content::WebContents* web_contents = active_contents(); | |
| 821 | |
| 822 auto send_tab_and_wait_for_value = | |
| 823 [&web_contents](const std::string& expected_value) { | |
| 824 TextInputManagerValueObserver observer(web_contents, expected_value); | |
| 825 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 826 ui::VKEY_TAB, false, false, false, false); | |
| 827 observer.Wait(); | |
| 828 }; | |
| 829 | |
| 830 // Record all active view changes. | |
| 831 RecordActiveViewsObserver recorder(web_contents); | |
| 832 for (auto value : values) | |
| 833 send_tab_and_wait_for_value(value); | |
| 834 | |
| 835 // We have covered a total of 6 views, so there should at least be 11 entries | |
| 836 // recorded (at least one null between two views). | |
| 837 size_t record_count = recorder.active_views()->size(); | |
| 838 EXPECT_GT(record_count, 10U); | |
| 839 | |
| 840 // Verify we do not have subsequent nullptr or non-nullptrs. | |
| 841 for (size_t i = 0; i < record_count - 1U; ++i) { | |
| 842 const content::RenderWidgetHostView* current = | |
| 843 recorder.active_views()->at(i); | |
| 844 const content::RenderWidgetHostView* next = | |
| 845 recorder.active_views()->at(i + 1U); | |
| 846 EXPECT_TRUE((current != nullptr && next == nullptr) || | |
| 847 (current == nullptr && next != nullptr)); | |
| 848 } | |
| 849 } | |
| 850 | 850 |
| 851 // TODO(ekaramad): The following tests are specifically written for Aura and are | 851 // TODO(ekaramad): The following tests are specifically written for Aura and are |
| 852 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | 852 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus |
| 853 // (crbug.com/602723). | 853 // (crbug.com/602723). |
| 854 | |
| 855 #if defined(USE_AURA) | 854 #if defined(USE_AURA) |
| 856 // ----------------------------------------------------------------------------- | 855 // ----------------------------------------------------------------------------- |
| 857 // Input Method Observer Tests | 856 // Input Method Observer Tests |
| 858 // | 857 // |
| 859 // The following tests will make use of the InputMethodObserver to verify that | 858 // The following tests will make use of the InputMethodObserver to verify that |
| 860 // OOPIF pages interact properly with the InputMethod through the tab's view. | 859 // OOPIF pages interact properly with the InputMethod through the tab's view. |
| 861 | 860 |
| 862 // TODO(ekaramad): We only have coverage for some aura tests as the whole idea | 861 // TODO(ekaramad): We only have coverage for some aura tests as the whole idea |
| 863 // of ui::TextInputClient/ui::InputMethod/ui::InputMethodObserver seems to be | 862 // of ui::TextInputClient/ui::InputMethod/ui::InputMethodObserver seems to be |
| 864 // only fit to aura (specifically, OS_CHROMEOS). Can we add more tests here for | 863 // only fit to aura (specifically, OS_CHROMEOS). Can we add more tests here for |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 WindowCountObserver(current_window_count).WaitForLimitOrMore(); | 1220 WindowCountObserver(current_window_count).WaitForLimitOrMore(); |
| 1222 // Test ends here. The rest is cleanup. | 1221 // Test ends here. The rest is cleanup. |
| 1223 | 1222 |
| 1224 // Closing this WebContents while we still hold on to our TestBrowserClient. | 1223 // Closing this WebContents while we still hold on to our TestBrowserClient. |
| 1225 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( | 1224 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( |
| 1226 1, TabStripModel::CLOSE_USER_GESTURE)); | 1225 1, TabStripModel::CLOSE_USER_GESTURE)); |
| 1227 | 1226 |
| 1228 // For the cleanup of the original WebContents in tab index 0. | 1227 // For the cleanup of the original WebContents in tab index 0. |
| 1229 content::SetBrowserClientForTesting(old_browser_client); | 1228 content::SetBrowserClientForTesting(old_browser_client); |
| 1230 } | 1229 } |
| 1231 #endif | 1230 #endif // defined(MAC_OSX) |
| 1231 #endif // !defined(OS_ANDROID) |
| OLD | NEW |