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/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 19 matching lines...) Expand all Loading... | |
| 30 #include "ui/base/ime/text_input_client.h" | 30 #include "ui/base/ime/text_input_client.h" |
| 31 #include "ui/base/ime/text_input_mode.h" | 31 #include "ui/base/ime/text_input_mode.h" |
| 32 #include "ui/base/ime/text_input_type.h" | 32 #include "ui/base/ime/text_input_type.h" |
| 33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 34 | 34 |
| 35 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 35 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 36 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | 36 #include "ui/base/ime/linux/text_edit_command_auralinux.h" |
| 37 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 37 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 // TODO(ekaramad): The following tests should be active on all platforms. After | |
| 41 // fixing https://crbug.com/578168, this test file should be built for android | |
| 42 // as well and most of the following tests should be enabled for all platforms | |
| 43 //(https://crbug.com/602723). | |
| 44 | |
| 45 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
| 46 // TextInputManager and IME Tests | 41 // TextInputManager and IME Tests |
| 47 // | 42 // |
| 48 // The following tests verify the correctness of TextInputState tracking on the | 43 // The following tests verify the correctness of TextInputState tracking on the |
| 49 // browser side. They also make sure the IME logic works correctly. The baseline | 44 // browser side. They also make sure the IME logic works correctly. The baseline |
| 50 // for comparison is the default functionality in the non-OOPIF case (i.e., the | 45 // for comparison is the default functionality in the non-OOPIF case (i.e., the |
| 51 // legacy implementation in RWHV's other than RWHVCF). | 46 // legacy implementation in RWHV's other than RWHVCF). |
| 52 // These tests live outside content/ because they rely on being part of the | 47 // These tests live outside content/ because they rely on being part of the |
| 53 // interactive UI test framework (to avoid flakiness). | 48 // interactive UI test framework (to avoid flakiness). |
| 54 | 49 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, | 565 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| 571 ui::VKEY_TAB, false, false, false, false); | 566 ui::VKEY_TAB, false, false, false, false); |
| 572 set_state_observer.Wait(); | 567 set_state_observer.Wait(); |
| 573 | 568 |
| 574 TextInputManagerTypeObserver reset_state_observer(active_contents(), | 569 TextInputManagerTypeObserver reset_state_observer(active_contents(), |
| 575 ui::TEXT_INPUT_TYPE_NONE); | 570 ui::TEXT_INPUT_TYPE_NONE); |
| 576 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 571 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 577 reset_state_observer.Wait(); | 572 reset_state_observer.Wait(); |
| 578 } | 573 } |
| 579 | 574 |
| 575 // The following test verifies that when the active widget changes value, it is | |
| 576 // always from nullptr to non-null or vice versa. | |
| 577 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 578 ResetTextInputStateOnActiveWidgetChange) { | |
| 579 CreateIframePage("a(b,c(a,b),d)"); | |
| 580 std::vector<content::RenderFrameHost*> frames{ | |
| 581 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 582 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 583 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 584 std::vector<content::RenderWidgetHostView*> views; | |
| 585 for (auto frame : frames) | |
| 586 views.push_back(frame->GetView()); | |
| 587 std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"}; | |
| 588 for (size_t i = 0; i < frames.size(); ++i) | |
| 589 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
| 590 | |
| 591 content::WebContents* web_contents = active_contents(); | |
| 592 | |
| 593 auto send_tab_and_wait_for_value = | |
| 594 [&web_contents](const std::string& expected_value) { | |
| 595 TextInputManagerValueObserver observer(web_contents, expected_value); | |
| 596 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 597 ui::VKEY_TAB, false, false, false, false); | |
| 598 observer.Wait(); | |
| 599 }; | |
| 600 | |
| 601 // Record all active view changes. | |
| 602 RecordActiveViewsObserver recorder(web_contents); | |
| 603 for (auto value : values) | |
| 604 send_tab_and_wait_for_value(value); | |
| 605 | |
| 606 // We have covered a total of 6 views, so there should at least be 11 entries | |
| 607 // recorded (at least one null between two views). | |
| 608 size_t record_count = recorder.active_views()->size(); | |
| 609 EXPECT_GT(record_count, 10U); | |
| 610 | |
| 611 // Verify we do not have subsequent nullptr or non-nullptrs. | |
| 612 for (size_t i = 0; i < record_count - 1U; ++i) { | |
| 613 const content::RenderWidgetHostView* current = | |
| 614 recorder.active_views()->at(i); | |
| 615 const content::RenderWidgetHostView* next = | |
| 616 recorder.active_views()->at(i + 1U); | |
| 617 EXPECT_TRUE((current != nullptr && next == nullptr) || | |
| 618 (current == nullptr && next != nullptr)); | |
| 619 } | |
| 620 } | |
| 621 | |
| 622 // TODO(ekaramad): Some of the following tests should be active on Android as | |
| 623 // well. Enable them when the corresponding feature is implemented for Android | |
| 624 // (https://crbug.com/602723). | |
| 625 #if !defined(OS_ANDROID) | |
| 580 // This test creates a page with multiple child frames and adds an <input> to | 626 // This test creates a page with multiple child frames and adds an <input> to |
| 581 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 627 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 582 // Then, after |TextInputState.type| for a view is changed to text, the test | 628 // Then, after |TextInputState.type| for a view is changed to text, the test |
| 583 // sends a set composition IPC to the active widget and waits until the widget | 629 // sends a set composition IPC to the active widget and waits until the widget |
| 584 // updates its composition range. | 630 // updates its composition range. |
| 585 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 631 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 586 TrackCompositionRangeForAllFrames) { | 632 TrackCompositionRangeForAllFrames) { |
| 587 CreateIframePage("a(b,c(a,b),d)"); | 633 CreateIframePage("a(b,c(a,b),d)"); |
| 588 std::vector<content::RenderFrameHost*> frames{ | 634 std::vector<content::RenderFrameHost*> frames{ |
| 589 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | 635 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 for (size_t i = 0; i < views.size(); ++i) { | 741 for (size_t i = 0; i < views.size(); ++i) { |
| 696 // First focus the <input>. | 742 // First focus the <input>. |
| 697 send_tab_and_wait_for_value(values[i]); | 743 send_tab_and_wait_for_value(values[i]); |
| 698 | 744 |
| 699 // Send a sequence of |count| 'E' keys and wait until the view receives a | 745 // Send a sequence of |count| 'E' keys and wait until the view receives a |
| 700 // selection change update for a text of the corresponding size, |count|. | 746 // selection change update for a text of the corresponding size, |count|. |
| 701 send_keys_select_all_wait_for_selection_change(views[i], count++); | 747 send_keys_select_all_wait_for_selection_change(views[i], count++); |
| 702 } | 748 } |
| 703 } | 749 } |
| 704 | 750 |
| 705 // The following test verifies that when the active widget changes value, it is | |
| 706 // always from nullptr to non-null or vice versa. | |
| 707 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | |
| 708 ResetTextInputStateOnActiveWidgetChange) { | |
| 709 CreateIframePage("a(b,c(a,b),d)"); | |
| 710 std::vector<content::RenderFrameHost*> frames{ | |
| 711 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), | |
| 712 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), | |
| 713 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; | |
| 714 std::vector<content::RenderWidgetHostView*> views; | |
| 715 for (auto frame : frames) | |
| 716 views.push_back(frame->GetView()); | |
| 717 std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"}; | |
| 718 for (size_t i = 0; i < frames.size(); ++i) | |
| 719 AddInputFieldToFrame(frames[i], "text", values[i], true); | |
| 720 | |
| 721 content::WebContents* web_contents = active_contents(); | |
| 722 | |
| 723 auto send_tab_and_wait_for_value = | |
| 724 [&web_contents](const std::string& expected_value) { | |
| 725 TextInputManagerValueObserver observer(web_contents, expected_value); | |
| 726 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | |
| 727 ui::VKEY_TAB, false, false, false, false); | |
| 728 observer.Wait(); | |
| 729 }; | |
| 730 | |
| 731 // Record all active view changes. | |
| 732 RecordActiveViewsObserver recorder(web_contents); | |
| 733 for (auto value : values) | |
| 734 send_tab_and_wait_for_value(value); | |
| 735 | |
| 736 // We have covered a total of 6 views, so there should at least be 11 entries | |
| 737 // recorded (at least one null between two views). | |
| 738 size_t record_count = recorder.active_views()->size(); | |
| 739 EXPECT_GT(record_count, 10U); | |
| 740 | |
| 741 // Verify we do not have subsequent nullptr or non-nullptrs. | |
| 742 for (size_t i = 0; i < record_count - 1U; ++i) { | |
| 743 const content::RenderWidgetHostView* current = | |
| 744 recorder.active_views()->at(i); | |
| 745 const content::RenderWidgetHostView* next = | |
| 746 recorder.active_views()->at(i + 1U); | |
| 747 EXPECT_TRUE((current != nullptr && next == nullptr) || | |
| 748 (current == nullptr && next != nullptr)); | |
| 749 } | |
| 750 } | |
| 751 | 751 |
| 752 // TODO(ekaramad): The following tests are specifically written for Aura and are | 752 // TODO(ekaramad): The following tests are specifically written for Aura and are |
| 753 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | 753 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus |
| 754 // (crbug.com/602723). | 754 // (crbug.com/602723). |
| 755 | |
| 756 #if defined(USE_AURA) | 755 #if defined(USE_AURA) |
| 757 // ----------------------------------------------------------------------------- | 756 // ----------------------------------------------------------------------------- |
| 758 // Input Method Observer Tests | 757 // Input Method Observer Tests |
| 759 // | 758 // |
| 760 // The following tests will make use of the InputMethodObserver to verify that | 759 // The following tests will make use of the InputMethodObserver to verify that |
| 761 // OOPIF pages interact properly with the InputMethod through the tab's view. | 760 // OOPIF pages interact properly with the InputMethod through the tab's view. |
| 762 | 761 |
| 763 // TODO(ekaramad): We only have coverage for some aura tests as the whole idea | 762 // TODO(ekaramad): We only have coverage for some aura tests as the whole idea |
| 764 // of ui::TextInputClient/ui::InputMethod/ui::InputMethodObserver seems to be | 763 // of ui::TextInputClient/ui::InputMethod/ui::InputMethodObserver seems to be |
| 765 // only fit to aura (specifically, OS_CHROMEOS). Can we add more tests here for | 764 // 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... | |
| 1122 WindowCountObserver(current_window_count).WaitForLimitOrMore(); | 1121 WindowCountObserver(current_window_count).WaitForLimitOrMore(); |
| 1123 // Test ends here. The rest is cleanup. | 1122 // Test ends here. The rest is cleanup. |
| 1124 | 1123 |
| 1125 // Closing this WebContents while we still hold on to our TestBrowserClient. | 1124 // Closing this WebContents while we still hold on to our TestBrowserClient. |
| 1126 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( | 1125 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( |
| 1127 1, TabStripModel::CLOSE_USER_GESTURE)); | 1126 1, TabStripModel::CLOSE_USER_GESTURE)); |
| 1128 | 1127 |
| 1129 // For the cleanup of the original WebContents in tab index 0. | 1128 // For the cleanup of the original WebContents in tab index 0. |
| 1130 content::SetBrowserClientForTesting(old_browser_client); | 1129 content::SetBrowserClientForTesting(old_browser_client); |
| 1131 } | 1130 } |
| 1132 #endif | 1131 #endif |
|
Charlie Reis
2016/11/02 22:23:13
nit: Can you add a comment here about which ifdef
EhsanK
2016/11/18 19:55:59
Done.
| |
| 1132 #endif // !defined(OS_ANDROID) | |
| OLD | NEW |