Chromium Code Reviews| Index: chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc |
| diff --git a/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc b/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc |
| index 35e9c65e9a42d329cf15962b56c3b85127294559..2b58efcaec19fd64f41d8c16e64d823a33223451 100644 |
| --- a/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc |
| +++ b/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc |
| @@ -98,8 +98,7 @@ class TextInputManagerValueObserver : public TextInputManagerObserverBase { |
| } |
| private: |
| - void VerifyValue(content::TextInputManagerTester* text_input_manager_tester) { |
| - ASSERT_EQ(tester(), text_input_manager_tester); |
| + void VerifyValue() { |
| std::string value; |
| if (tester()->GetTextInputValue(&value) && expected_value_ == value) |
| OnSuccess(); |
| @@ -122,8 +121,7 @@ class TextInputManagerTypeObserver : public TextInputManagerObserverBase { |
| } |
| private: |
| - void VerifyType(content::TextInputManagerTester* text_input_manager_tester) { |
| - ASSERT_EQ(tester(), text_input_manager_tester); |
| + void VerifyType() { |
| ui::TextInputType type = |
| tester()->GetTextInputType(&type) ? type : ui::TEXT_INPUT_TYPE_NONE; |
| if (expected_type_ == type) |
| @@ -145,9 +143,7 @@ class TextInputManagerChangeObserver : public TextInputManagerObserverBase { |
| } |
| private: |
| - void VerifyChange( |
| - content::TextInputManagerTester* text_input_manager_tester) { |
| - ASSERT_EQ(tester(), text_input_manager_tester); |
| + void VerifyChange() { |
| if (tester()->IsTextInputStateChanged()) |
| OnSuccess(); |
| } |
| @@ -170,7 +166,7 @@ class ViewTextInputTypeObserver : public TextInputManagerObserverBase { |
| } |
| private: |
| - void VerifyType(content::TextInputManagerTester* tester) { |
| + void VerifyType() { |
| ui::TextInputType type; |
| if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) |
| return; |
| @@ -185,6 +181,31 @@ class ViewTextInputTypeObserver : public TextInputManagerObserverBase { |
| DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver); |
| }; |
| +// This class observes the |expected_view| for the first change in its |
| +// selection bounds. |
| +class ViewSelectionBoundsChangedObserver : public TextInputManagerObserverBase { |
| + public: |
| + explicit ViewSelectionBoundsChangedObserver( |
| + content::WebContents* web_contents, |
| + content::RenderWidgetHostView* expected_view) |
| + : TextInputManagerObserverBase(web_contents), |
| + expected_view_(expected_view) { |
| + tester()->SetOnSelectionBoundsChangedCallback( |
| + base::Bind(&ViewSelectionBoundsChangedObserver::VerifyChange, |
| + base::Unretained(this))); |
| + } |
| + |
| + private: |
| + void VerifyChange() { |
| + if (expected_view_ == tester()->GetUpdatedView()) |
| + OnSuccess(); |
| + } |
| + |
| + const content::RenderWidgetHostView* const expected_view_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver); |
| +}; |
| + |
| } // namespace |
| // Main class for all TextInputState and IME related tests. |
| @@ -309,17 +330,19 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| // first frame setting its state to NONE after the second tab. |
| ViewTextInputTypeObserver view_type_observer( |
| active_contents(), frames[0]->GetView(), ui::TEXT_INPUT_TYPE_NONE); |
| + LOG(INFO) << "View type created"; |
|
Charlie Reis
2016/06/30 20:27:21
Did you mean to leave these in?
EhsanK
2016/06/30 21:01:15
No sorry for these. I will remove them all.
|
| for (size_t i = 0; i < frames.size(); ++i) { |
| TextInputManagerValueObserver observer(active_contents(), values[i]); |
| SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, |
| ui::VKEY_TAB, false, false, false, false); |
| observer.Wait(); |
| + LOG(INFO) << "Value observed"; |
| } |
| // Make sure that the first view has set its TextInputState.type to NONE. |
| view_type_observer.Wait(); |
| - |
| + LOG(INFO) << "View type observed"; |
| // Verify that we are tracking the TextInputState from the first frame. |
| content::RenderWidgetHostView* first_view = frames[0]->GetView(); |
| ui::TextInputType first_view_type; |
| @@ -456,6 +479,44 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| reset_state_observer.Wait(); |
| } |
| +// This test creates a page with multiple child frames and adds an <input> to |
| +// each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| +// Then, after |TextInputState.type| for a view is changed to text, another key |
| +// is pressed (a character) and then the test verifies that TextInputManager |
| +// receives the corresponding update on the change in selection bounds on the |
| +// browser side. |
| +IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| + TrackSelectionBoundsForChildFrames) { |
| + CreateIframePage("a(b,c(a,b),d)"); |
| + std::vector<content::RenderFrameHost*> frames{ |
| + GetFrame(IndexVector{}), GetFrame(IndexVector{0}), |
| + GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), |
| + GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; |
| + std::vector<content::RenderWidgetHostView*> views; |
| + for (auto frame : frames) |
| + views.push_back(frame->GetView()); |
| + for (size_t i = 0; i < frames.size(); ++i) |
| + AddInputFieldToFrame(frames[i], "text", "", true); |
| + |
| + content::WebContents* web_contents = active_contents(); |
| + |
| + auto send_tab_insert_text_wait_for_bounds_change = [&web_contents]( |
| + content::RenderWidgetHostView* view) { |
| + ViewTextInputTypeObserver type_observer(web_contents, view, |
| + ui::TEXT_INPUT_TYPE_TEXT); |
| + SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, |
| + ui::VKEY_TAB, false, false, false, false); |
| + type_observer.Wait(); |
| + ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); |
| + SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), |
| + ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); |
| + bounds_observer.Wait(); |
| + }; |
| + |
| + for (auto view : views) |
| + send_tab_insert_text_wait_for_bounds_change(view); |
| +} |
| + |
| // TODO(ekaramad): The following tests are specifically written for Aura and are |
| // based on InputMethodObserver. Write similar tests for Mac/Android/Mus |
| // (crbug.com/602723). |