Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc

Issue 2057803002: Tracking SelectionBounds for all RenderWidgets on the Browser Side (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing creis@'s comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h" 10 #include "chrome/test/base/in_process_browser_test.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 public: 91 public:
92 TextInputManagerValueObserver(content::WebContents* web_contents, 92 TextInputManagerValueObserver(content::WebContents* web_contents,
93 const std::string& expected_value) 93 const std::string& expected_value)
94 : TextInputManagerObserverBase(web_contents), 94 : TextInputManagerObserverBase(web_contents),
95 expected_value_(expected_value) { 95 expected_value_(expected_value) {
96 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( 96 tester()->SetUpdateTextInputStateCalledCallback(base::Bind(
97 &TextInputManagerValueObserver::VerifyValue, base::Unretained(this))); 97 &TextInputManagerValueObserver::VerifyValue, base::Unretained(this)));
98 } 98 }
99 99
100 private: 100 private:
101 void VerifyValue(content::TextInputManagerTester* text_input_manager_tester) { 101 void VerifyValue() {
102 ASSERT_EQ(tester(), text_input_manager_tester);
103 std::string value; 102 std::string value;
104 if (tester()->GetTextInputValue(&value) && expected_value_ == value) 103 if (tester()->GetTextInputValue(&value) && expected_value_ == value)
105 OnSuccess(); 104 OnSuccess();
106 } 105 }
107 106
108 const std::string expected_value_; 107 const std::string expected_value_;
109 108
110 DISALLOW_COPY_AND_ASSIGN(TextInputManagerValueObserver); 109 DISALLOW_COPY_AND_ASSIGN(TextInputManagerValueObserver);
111 }; 110 };
112 111
113 // This class observes TextInputManager for changes in |TextInputState.type|. 112 // This class observes TextInputManager for changes in |TextInputState.type|.
114 class TextInputManagerTypeObserver : public TextInputManagerObserverBase { 113 class TextInputManagerTypeObserver : public TextInputManagerObserverBase {
115 public: 114 public:
116 TextInputManagerTypeObserver(content::WebContents* web_contents, 115 TextInputManagerTypeObserver(content::WebContents* web_contents,
117 ui::TextInputType expected_type) 116 ui::TextInputType expected_type)
118 : TextInputManagerObserverBase(web_contents), 117 : TextInputManagerObserverBase(web_contents),
119 expected_type_(expected_type) { 118 expected_type_(expected_type) {
120 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( 119 tester()->SetUpdateTextInputStateCalledCallback(base::Bind(
121 &TextInputManagerTypeObserver::VerifyType, base::Unretained(this))); 120 &TextInputManagerTypeObserver::VerifyType, base::Unretained(this)));
122 } 121 }
123 122
124 private: 123 private:
125 void VerifyType(content::TextInputManagerTester* text_input_manager_tester) { 124 void VerifyType() {
126 ASSERT_EQ(tester(), text_input_manager_tester);
127 ui::TextInputType type = 125 ui::TextInputType type =
128 tester()->GetTextInputType(&type) ? type : ui::TEXT_INPUT_TYPE_NONE; 126 tester()->GetTextInputType(&type) ? type : ui::TEXT_INPUT_TYPE_NONE;
129 if (expected_type_ == type) 127 if (expected_type_ == type)
130 OnSuccess(); 128 OnSuccess();
131 } 129 }
132 130
133 const ui::TextInputType expected_type_; 131 const ui::TextInputType expected_type_;
134 132
135 DISALLOW_COPY_AND_ASSIGN(TextInputManagerTypeObserver); 133 DISALLOW_COPY_AND_ASSIGN(TextInputManagerTypeObserver);
136 }; 134 };
137 135
138 // This class observes TextInputManager for the first change in TextInputState. 136 // This class observes TextInputManager for the first change in TextInputState.
139 class TextInputManagerChangeObserver : public TextInputManagerObserverBase { 137 class TextInputManagerChangeObserver : public TextInputManagerObserverBase {
140 public: 138 public:
141 explicit TextInputManagerChangeObserver(content::WebContents* web_contents) 139 explicit TextInputManagerChangeObserver(content::WebContents* web_contents)
142 : TextInputManagerObserverBase(web_contents) { 140 : TextInputManagerObserverBase(web_contents) {
143 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( 141 tester()->SetUpdateTextInputStateCalledCallback(base::Bind(
144 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this))); 142 &TextInputManagerChangeObserver::VerifyChange, base::Unretained(this)));
145 } 143 }
146 144
147 private: 145 private:
148 void VerifyChange( 146 void VerifyChange() {
149 content::TextInputManagerTester* text_input_manager_tester) {
150 ASSERT_EQ(tester(), text_input_manager_tester);
151 if (tester()->IsTextInputStateChanged()) 147 if (tester()->IsTextInputStateChanged())
152 OnSuccess(); 148 OnSuccess();
153 } 149 }
154 150
155 DISALLOW_COPY_AND_ASSIGN(TextInputManagerChangeObserver); 151 DISALLOW_COPY_AND_ASSIGN(TextInputManagerChangeObserver);
156 }; 152 };
157 153
158 // This class observes |TextInputState.type| for a specific RWHV. 154 // This class observes |TextInputState.type| for a specific RWHV.
159 class ViewTextInputTypeObserver : public TextInputManagerObserverBase { 155 class ViewTextInputTypeObserver : public TextInputManagerObserverBase {
160 public: 156 public:
161 explicit ViewTextInputTypeObserver(content::WebContents* web_contents, 157 explicit ViewTextInputTypeObserver(content::WebContents* web_contents,
162 content::RenderWidgetHostView* rwhv, 158 content::RenderWidgetHostView* rwhv,
163 ui::TextInputType expected_type) 159 ui::TextInputType expected_type)
164 : TextInputManagerObserverBase(web_contents), 160 : TextInputManagerObserverBase(web_contents),
165 web_contents_(web_contents), 161 web_contents_(web_contents),
166 view_(rwhv), 162 view_(rwhv),
167 expected_type_(expected_type) { 163 expected_type_(expected_type) {
168 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( 164 tester()->SetUpdateTextInputStateCalledCallback(base::Bind(
169 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this))); 165 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this)));
170 } 166 }
171 167
172 private: 168 private:
173 void VerifyType(content::TextInputManagerTester* tester) { 169 void VerifyType() {
174 ui::TextInputType type; 170 ui::TextInputType type;
175 if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) 171 if (!content::GetTextInputTypeForView(web_contents_, view_, &type))
176 return; 172 return;
177 if (expected_type_ == type) 173 if (expected_type_ == type)
178 OnSuccess(); 174 OnSuccess();
179 } 175 }
180 176
181 content::WebContents* web_contents_; 177 content::WebContents* web_contents_;
182 content::RenderWidgetHostView* view_; 178 content::RenderWidgetHostView* view_;
183 const ui::TextInputType expected_type_; 179 const ui::TextInputType expected_type_;
184 180
185 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver); 181 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver);
186 }; 182 };
187 183
184 // This class observes the |expected_view| for the first change in its
185 // selection bounds.
186 class ViewSelectionBoundsChangedObserver : public TextInputManagerObserverBase {
187 public:
188 ViewSelectionBoundsChangedObserver(
189 content::WebContents* web_contents,
190 content::RenderWidgetHostView* expected_view)
191 : TextInputManagerObserverBase(web_contents),
192 expected_view_(expected_view) {
193 tester()->SetOnSelectionBoundsChangedCallback(
194 base::Bind(&ViewSelectionBoundsChangedObserver::VerifyChange,
195 base::Unretained(this)));
196 }
197
198 private:
199 void VerifyChange() {
200 if (expected_view_ == tester()->GetUpdatedView())
201 OnSuccess();
202 }
203
204 const content::RenderWidgetHostView* const expected_view_;
205
206 DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver);
207 };
208
188 } // namespace 209 } // namespace
189 210
190 // Main class for all TextInputState and IME related tests. 211 // Main class for all TextInputState and IME related tests.
191 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { 212 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
192 public: 213 public:
193 SitePerProcessTextInputManagerTest() {} 214 SitePerProcessTextInputManagerTest() {}
194 ~SitePerProcessTextInputManagerTest() override {} 215 ~SitePerProcessTextInputManagerTest() override {}
195 216
196 void SetUpCommandLine(base::CommandLine* command_line) override { 217 void SetUpCommandLine(base::CommandLine* command_line) override {
197 content::IsolateAllSitesForTesting(command_line); 218 content::IsolateAllSitesForTesting(command_line);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, 470 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB,
450 ui::VKEY_TAB, false, false, false, false); 471 ui::VKEY_TAB, false, false, false, false);
451 set_state_observer.Wait(); 472 set_state_observer.Wait();
452 473
453 TextInputManagerTypeObserver reset_state_observer(active_contents(), 474 TextInputManagerTypeObserver reset_state_observer(active_contents(),
454 ui::TEXT_INPUT_TYPE_NONE); 475 ui::TEXT_INPUT_TYPE_NONE);
455 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 476 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
456 reset_state_observer.Wait(); 477 reset_state_observer.Wait();
457 } 478 }
458 479
480 // This test creates a page with multiple child frames and adds an <input> to
481 // each frame. Then, sequentially, each <input> is focused by sending a tab key.
482 // Then, after |TextInputState.type| for a view is changed to text, another key
483 // is pressed (a character) and then the test verifies that TextInputManager
484 // receives the corresponding update on the change in selection bounds on the
485 // browser side.
486 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
487 TrackSelectionBoundsForChildFrames) {
488 CreateIframePage("a(b,c(a,b),d)");
489 std::vector<content::RenderFrameHost*> frames{
490 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
491 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
492 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
493 std::vector<content::RenderWidgetHostView*> views;
494 for (auto frame : frames)
495 views.push_back(frame->GetView());
496 for (size_t i = 0; i < frames.size(); ++i)
497 AddInputFieldToFrame(frames[i], "text", "", true);
498
499 content::WebContents* web_contents = active_contents();
500
501 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents](
502 content::RenderWidgetHostView* view) {
503 ViewTextInputTypeObserver type_observer(web_contents, view,
504 ui::TEXT_INPUT_TYPE_TEXT);
505 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
506 ui::VKEY_TAB, false, false, false, false);
507 type_observer.Wait();
508 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view);
509 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'),
510 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false);
511 bounds_observer.Wait();
512 };
513
514 for (auto view : views)
515 send_tab_insert_text_wait_for_bounds_change(view);
516 }
517
459 // TODO(ekaramad): The following tests are specifically written for Aura and are 518 // TODO(ekaramad): The following tests are specifically written for Aura and are
460 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 519 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
461 // (crbug.com/602723). 520 // (crbug.com/602723).
462 521
463 // Observes current input method for state changes. 522 // Observes current input method for state changes.
464 class InputMethodObserverBase { 523 class InputMethodObserverBase {
465 public: 524 public:
466 explicit InputMethodObserverBase(content::WebContents* web_contents) 525 explicit InputMethodObserverBase(content::WebContents* web_contents)
467 : success_(false), 526 : success_(false),
468 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { 527 test_observer_(content::TestInputMethodObserver::Create(web_contents)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 EXPECT_FALSE(send_and_check_show_ime()); 617 EXPECT_FALSE(send_and_check_show_ime());
559 618
560 // Set |TextInputState.show_ime_if_needed|. Expect IME. 619 // Set |TextInputState.show_ime_if_needed|. Expect IME.
561 sender.SetShowImeIfNeeded(true); 620 sender.SetShowImeIfNeeded(true);
562 EXPECT_TRUE(send_and_check_show_ime()); 621 EXPECT_TRUE(send_and_check_show_ime());
563 622
564 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 623 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
565 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 624 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
566 EXPECT_FALSE(send_and_check_show_ime()); 625 EXPECT_FALSE(send_and_check_show_ime());
567 } 626 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/OWNERS ('k') | content/browser/frame_host/render_widget_host_view_child_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698