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" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/content_browser_test_utils.h" | 18 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
| 20 #include "content/public/test/text_input_test_utils.h" | 20 #include "content/public/test/text_input_test_utils.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 23 #include "ui/base/ime/composition_underline.h" | 23 #include "ui/base/ime/composition_underline.h" |
| 24 #include "ui/base/ime/text_input_client.h" | 24 #include "ui/base/ime/text_input_client.h" |
| 25 #include "ui/base/ime/text_input_mode.h" | 25 #include "ui/base/ime/text_input_mode.h" |
| 26 #include "ui/base/ime/text_input_type.h" | 26 #include "ui/base/ime/text_input_type.h" |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 | 28 |
| 29 // TODO(ekaramad): The following tests are only active on aura platforms. After | 29 // TODO(ekaramad): The following tests should be active on all platforms. After |
| 30 // fixing crbug.com/578168 for all platforms, the following tests should be | 30 // fixing https://crbug.com/578168, this test file should be built for android |
| 31 // activated for other platforms, e.g., Mac and Android (crbug.com/602723). | 31 // as well and most of the following tests should be enabled for all platforms |
| 32 //(https://crbug.com/602723). | |
| 32 | 33 |
| 33 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
| 34 // TextInputManager and IME Tests | 35 // TextInputManager and IME Tests |
| 35 // | 36 // |
| 36 // The following tests verify the correctness of TextInputState tracking on the | 37 // The following tests verify the correctness of TextInputState tracking on the |
| 37 // browser side. They also make sure the IME logic works correctly. The baseline | 38 // browser side. They also make sure the IME logic works correctly. The baseline |
| 38 // for comparison is the default functionality in the non-OOPIF case (i.e., the | 39 // for comparison is the default functionality in the non-OOPIF case (i.e., the |
| 39 // legacy implementation in RWHV's other than RWHVCF). | 40 // legacy implementation in RWHV's other than RWHVCF). |
| 40 // These tests live outside content/ because they rely on being part of the | 41 // These tests live outside content/ because they rely on being part of the |
| 41 // interactive UI test framework (to avoid flakiness). | 42 // interactive UI test framework (to avoid flakiness). |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 EXPECT_TRUE(ExecuteScript( | 513 EXPECT_TRUE(ExecuteScript( |
| 513 main_frame, "document.querySelector('iframe').src = 'about:blank'")); | 514 main_frame, "document.querySelector('iframe').src = 'about:blank'")); |
| 514 child_reset_state_observer.Wait(); | 515 child_reset_state_observer.Wait(); |
| 515 } | 516 } |
| 516 | 517 |
| 517 // This test creates a blank page and adds an <input> to it. Then, the <input> | 518 // This test creates a blank page and adds an <input> to it. Then, the <input> |
| 518 // is focused and the test verfies that the |TextInputState.type| is set to | 519 // is focused and the test verfies that the |TextInputState.type| is set to |
| 519 // ui::TEXT_INPUT_TYPE_TEXT. Next, the browser is navigated away and the test | 520 // ui::TEXT_INPUT_TYPE_TEXT. Next, the browser is navigated away and the test |
| 520 // verifies that |TextInputState.type| resets to ui::TEXT_INPUT_TYPE_NONE. | 521 // verifies that |TextInputState.type| resets to ui::TEXT_INPUT_TYPE_NONE. |
| 521 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 522 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 522 ResetStateAfterBrowserNavigation) { | 523 ResetStateAfterBrowserNavigation) { |
|
Charlie Reis
2016/07/27 16:14:18
Ok, glad to see the tests here and above are runni
EhsanK
2016/07/27 16:46:32
Yes, and these should also run on Android when we
| |
| 523 CreateIframePage("a()"); | 524 CreateIframePage("a()"); |
| 524 content::RenderFrameHost* main_frame = GetFrame(IndexVector{}); | 525 content::RenderFrameHost* main_frame = GetFrame(IndexVector{}); |
| 525 AddInputFieldToFrame(main_frame, "text", "", false); | 526 AddInputFieldToFrame(main_frame, "text", "", false); |
| 526 | 527 |
| 527 TextInputManagerTypeObserver set_state_observer(active_contents(), | 528 TextInputManagerTypeObserver set_state_observer(active_contents(), |
| 528 ui::TEXT_INPUT_TYPE_TEXT); | 529 ui::TEXT_INPUT_TYPE_TEXT); |
| 529 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, | 530 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| 530 ui::VKEY_TAB, false, false, false, false); | 531 ui::VKEY_TAB, false, false, false, false); |
| 531 set_state_observer.Wait(); | 532 set_state_observer.Wait(); |
| 532 | 533 |
| 533 TextInputManagerTypeObserver reset_state_observer(active_contents(), | 534 TextInputManagerTypeObserver reset_state_observer(active_contents(), |
| 534 ui::TEXT_INPUT_TYPE_NONE); | 535 ui::TEXT_INPUT_TYPE_NONE); |
| 535 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 536 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 536 reset_state_observer.Wait(); | 537 reset_state_observer.Wait(); |
| 537 } | 538 } |
| 538 | 539 |
| 540 // TODO(ekaramad): Enable the following tests on other platforms when the | |
| 541 // corresponding feature is implemented (http://crbug.com/578168). | |
| 542 #if defined(USE_AURA) | |
|
EhsanK
2016/07/27 16:46:32
I guess all of the following will eventually be ac
| |
| 539 // This test creates a page with multiple child frames and adds an <input> to | 543 // This test creates a page with multiple child frames and adds an <input> to |
| 540 // each frame. Then, sequentially, each <input> is focused by sending a tab key. | 544 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 541 // Then, after |TextInputState.type| for a view is changed to text, another key | 545 // Then, after |TextInputState.type| for a view is changed to text, another key |
| 542 // is pressed (a character) and then the test verifies that TextInputManager | 546 // is pressed (a character) and then the test verifies that TextInputManager |
| 543 // receives the corresponding update on the change in selection bounds on the | 547 // receives the corresponding update on the change in selection bounds on the |
| 544 // browser side. | 548 // browser side. |
| 545 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 549 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 546 TrackSelectionBoundsForAllFrames) { | 550 TrackSelectionBoundsForAllFrames) { |
| 547 CreateIframePage("a(b,c(a,b),d)"); | 551 CreateIframePage("a(b,c(a,b),d)"); |
| 548 std::vector<content::RenderFrameHost*> frames{ | 552 std::vector<content::RenderFrameHost*> frames{ |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 ViewTextSelectionObserver text_selection_observer( | 643 ViewTextSelectionObserver text_selection_observer( |
| 640 web_contents, frame->GetView(), expected_length); | 644 web_contents, frame->GetView(), expected_length); |
| 641 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | 645 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, |
| 642 ui::VKEY_TAB, false, false, false, false); | 646 ui::VKEY_TAB, false, false, false, false); |
| 643 text_selection_observer.Wait(); | 647 text_selection_observer.Wait(); |
| 644 }; | 648 }; |
| 645 | 649 |
| 646 for (size_t i = 0; i < frames.size(); ++i) | 650 for (size_t i = 0; i < frames.size(); ++i) |
| 647 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size()); | 651 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size()); |
| 648 } | 652 } |
| 653 #endif // USE_AURA | |
| 649 | 654 |
| 650 // TODO(ekaramad): The following tests are specifically written for Aura and are | 655 // TODO(ekaramad): The following tests are specifically written for Aura and are |
| 651 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | 656 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus |
| 652 // (crbug.com/602723). | 657 // (crbug.com/602723). |
|
Charlie Reis
2016/07/27 16:14:18
This part confuses me a bit. Is there a meaningfu
EhsanK
2016/07/27 16:46:32
Sorry for the confusion. The block above is Aura o
| |
| 653 | 658 |
| 659 #if defined(USE_AURA) | |
| 654 // Observes current input method for state changes. | 660 // Observes current input method for state changes. |
| 655 class InputMethodObserverBase { | 661 class InputMethodObserverBase { |
| 656 public: | 662 public: |
| 657 explicit InputMethodObserverBase(content::WebContents* web_contents) | 663 explicit InputMethodObserverBase(content::WebContents* web_contents) |
| 658 : success_(false), | 664 : success_(false), |
| 659 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { | 665 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { |
| 660 } | 666 } |
| 661 | 667 |
| 662 void Wait() { | 668 void Wait() { |
| 663 if (success_) | 669 if (success_) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 private: | 708 private: |
| 703 DISALLOW_COPY_AND_ASSIGN(InputMethodObserverForShowIme); | 709 DISALLOW_COPY_AND_ASSIGN(InputMethodObserverForShowIme); |
| 704 }; | 710 }; |
| 705 | 711 |
| 706 // This test verifies that the IME for Aura is shown if and only if the current | 712 // This test verifies that the IME for Aura is shown if and only if the current |
| 707 // client's |TextInputState.type| is not ui::TEXT_INPUT_TYPE_NONE and the flag | 713 // client's |TextInputState.type| is not ui::TEXT_INPUT_TYPE_NONE and the flag |
| 708 // |TextInputState.show_ime_if_needed| is true. This should happen even when | 714 // |TextInputState.show_ime_if_needed| is true. This should happen even when |
| 709 // the TextInputState has not changed (according to the platform), e.g., in | 715 // the TextInputState has not changed (according to the platform), e.g., in |
| 710 // aura when receiving two consecutive updates with same |TextInputState.type|. | 716 // aura when receiving two consecutive updates with same |TextInputState.type|. |
| 711 // TODO(ekaramad): This test is actually a unit test not necessarily an OOPIF | 717 // TODO(ekaramad): This test is actually a unit test not necessarily an OOPIF |
| 712 // test. We should move it to somewhere more relevant. | 718 // test. We should move it to somewhere more relevant. |
|
EhsanK
2016/07/27 16:46:31
I might remove this test and put it with other uni
| |
| 713 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, | 719 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 714 CorrectlyShowImeIfNeeded) { | 720 CorrectlyShowImeIfNeeded) { |
| 715 // We only need the <iframe> page to create RWHV. | 721 // We only need the <iframe> page to create RWHV. |
| 716 CreateIframePage("a()"); | 722 CreateIframePage("a()"); |
| 717 content::RenderFrameHost* main_frame = GetFrame(IndexVector{}); | 723 content::RenderFrameHost* main_frame = GetFrame(IndexVector{}); |
| 718 content::RenderWidgetHostView* view = main_frame->GetView(); | 724 content::RenderWidgetHostView* view = main_frame->GetView(); |
| 719 content::WebContents* web_contents = active_contents(); | 725 content::WebContents* web_contents = active_contents(); |
| 720 | 726 |
| 721 content::TextInputStateSender sender(view); | 727 content::TextInputStateSender sender(view); |
| 722 | 728 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 749 EXPECT_FALSE(send_and_check_show_ime()); | 755 EXPECT_FALSE(send_and_check_show_ime()); |
| 750 | 756 |
| 751 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 757 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
| 752 sender.SetShowImeIfNeeded(true); | 758 sender.SetShowImeIfNeeded(true); |
| 753 EXPECT_TRUE(send_and_check_show_ime()); | 759 EXPECT_TRUE(send_and_check_show_ime()); |
| 754 | 760 |
| 755 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 761 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
| 756 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 762 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
| 757 EXPECT_FALSE(send_and_check_show_ime()); | 763 EXPECT_FALSE(send_and_check_show_ime()); |
| 758 } | 764 } |
| 765 #endif | |
| OLD | NEW |