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

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: Fixed an Error 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 explicit 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 for (size_t i = 0; i < frames.size(); ++i) 323 for (size_t i = 0; i < frames.size(); ++i)
303 AddInputFieldToFrame(frames[i], "text", values[i], true); 324 AddInputFieldToFrame(frames[i], "text", values[i], true);
304 325
305 // Tab into both inputs and make sure we correctly receive their 326 // Tab into both inputs and make sure we correctly receive their
306 // TextInputState. For the second tab two IPCs arrive: one from the first 327 // TextInputState. For the second tab two IPCs arrive: one from the first
307 // frame to set the state to none, and another one from the second frame to 328 // frame to set the state to none, and another one from the second frame to
308 // set it to TEXT. To avoid the race between them, we shall also observe the 329 // set it to TEXT. To avoid the race between them, we shall also observe the
309 // first frame setting its state to NONE after the second tab. 330 // first frame setting its state to NONE after the second tab.
310 ViewTextInputTypeObserver view_type_observer( 331 ViewTextInputTypeObserver view_type_observer(
311 active_contents(), frames[0]->GetView(), ui::TEXT_INPUT_TYPE_NONE); 332 active_contents(), frames[0]->GetView(), ui::TEXT_INPUT_TYPE_NONE);
333 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.
312 334
313 for (size_t i = 0; i < frames.size(); ++i) { 335 for (size_t i = 0; i < frames.size(); ++i) {
314 TextInputManagerValueObserver observer(active_contents(), values[i]); 336 TextInputManagerValueObserver observer(active_contents(), values[i]);
315 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, 337 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB,
316 ui::VKEY_TAB, false, false, false, false); 338 ui::VKEY_TAB, false, false, false, false);
317 observer.Wait(); 339 observer.Wait();
340 LOG(INFO) << "Value observed";
318 } 341 }
319 342
320 // Make sure that the first view has set its TextInputState.type to NONE. 343 // Make sure that the first view has set its TextInputState.type to NONE.
321 view_type_observer.Wait(); 344 view_type_observer.Wait();
322 345 LOG(INFO) << "View type observed";
323 // Verify that we are tracking the TextInputState from the first frame. 346 // Verify that we are tracking the TextInputState from the first frame.
324 content::RenderWidgetHostView* first_view = frames[0]->GetView(); 347 content::RenderWidgetHostView* first_view = frames[0]->GetView();
325 ui::TextInputType first_view_type; 348 ui::TextInputType first_view_type;
326 EXPECT_TRUE(content::GetTextInputTypeForView(active_contents(), first_view, 349 EXPECT_TRUE(content::GetTextInputTypeForView(active_contents(), first_view,
327 &first_view_type)); 350 &first_view_type));
328 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, first_view_type); 351 EXPECT_EQ(ui::TEXT_INPUT_TYPE_NONE, first_view_type);
329 352
330 size_t registered_views_count = 353 size_t registered_views_count =
331 content::GetRegisteredViewsCountFromTextInputManager(active_contents()); 354 content::GetRegisteredViewsCountFromTextInputManager(active_contents());
332 355
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, 472 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB,
450 ui::VKEY_TAB, false, false, false, false); 473 ui::VKEY_TAB, false, false, false, false);
451 set_state_observer.Wait(); 474 set_state_observer.Wait();
452 475
453 TextInputManagerTypeObserver reset_state_observer(active_contents(), 476 TextInputManagerTypeObserver reset_state_observer(active_contents(),
454 ui::TEXT_INPUT_TYPE_NONE); 477 ui::TEXT_INPUT_TYPE_NONE);
455 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 478 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
456 reset_state_observer.Wait(); 479 reset_state_observer.Wait();
457 } 480 }
458 481
482 // This test creates a page with multiple child frames and adds an <input> to
483 // each frame. Then, sequentially, each <input> is focused by sending a tab key.
484 // Then, after |TextInputState.type| for a view is changed to text, another key
485 // is pressed (a character) and then the test verifies that TextInputManager
486 // receives the corresponding update on the change in selection bounds on the
487 // browser side.
488 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
489 TrackSelectionBoundsForChildFrames) {
490 CreateIframePage("a(b,c(a,b),d)");
491 std::vector<content::RenderFrameHost*> frames{
492 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
493 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
494 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
495 std::vector<content::RenderWidgetHostView*> views;
496 for (auto frame : frames)
497 views.push_back(frame->GetView());
498 for (size_t i = 0; i < frames.size(); ++i)
499 AddInputFieldToFrame(frames[i], "text", "", true);
500
501 content::WebContents* web_contents = active_contents();
502
503 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents](
504 content::RenderWidgetHostView* view) {
505 ViewTextInputTypeObserver type_observer(web_contents, view,
506 ui::TEXT_INPUT_TYPE_TEXT);
507 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
508 ui::VKEY_TAB, false, false, false, false);
509 type_observer.Wait();
510 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view);
511 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'),
512 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false);
513 bounds_observer.Wait();
514 };
515
516 for (auto view : views)
517 send_tab_insert_text_wait_for_bounds_change(view);
518 }
519
459 // TODO(ekaramad): The following tests are specifically written for Aura and are 520 // TODO(ekaramad): The following tests are specifically written for Aura and are
460 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 521 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
461 // (crbug.com/602723). 522 // (crbug.com/602723).
462 523
463 // Observes current input method for state changes. 524 // Observes current input method for state changes.
464 class InputMethodObserverBase { 525 class InputMethodObserverBase {
465 public: 526 public:
466 explicit InputMethodObserverBase(content::WebContents* web_contents) 527 explicit InputMethodObserverBase(content::WebContents* web_contents)
467 : success_(false), 528 : success_(false),
468 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { 529 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()); 619 EXPECT_FALSE(send_and_check_show_ime());
559 620
560 // Set |TextInputState.show_ime_if_needed|. Expect IME. 621 // Set |TextInputState.show_ime_if_needed|. Expect IME.
561 sender.SetShowImeIfNeeded(true); 622 sender.SetShowImeIfNeeded(true);
562 EXPECT_TRUE(send_and_check_show_ime()); 623 EXPECT_TRUE(send_and_check_show_ime());
563 624
564 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 625 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
565 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 626 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
566 EXPECT_FALSE(send_and_check_show_ime()); 627 EXPECT_FALSE(send_and_check_show_ime());
567 } 628 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698