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

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 Compile Errors 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 ui::TextInputType expected_type) 159 ui::TextInputType expected_type)
160 : TextInputManagerObserverBase(web_contents), 160 : TextInputManagerObserverBase(web_contents),
161 web_contents_(web_contents), 161 web_contents_(web_contents),
162 view_(rwhv), 162 view_(rwhv),
163 expected_type_(expected_type) { 163 expected_type_(expected_type) {
164 tester()->SetUpdateTextInputStateCalledCallback(base::Bind( 164 tester()->SetUpdateTextInputStateCalledCallback(base::Bind(
165 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this))); 165 &ViewTextInputTypeObserver::VerifyType, base::Unretained(this)));
166 } 166 }
167 167
168 private: 168 private:
169 void VerifyType(content::TextInputManagerTester* tester) { 169 void VerifyType(content::TextInputManagerTester* text_input_manager_tester) {
170 ui::TextInputType type; 170 ui::TextInputType type;
171 if (!content::GetTextInputTypeForView(web_contents_, view_, &type)) 171 if (!content::GetTextInputTypeForView(web_contents_, view_, &type))
172 return; 172 return;
173 if (expected_type_ == type) 173 if (expected_type_ == type)
174 OnSuccess(); 174 OnSuccess();
175 } 175 }
176 176
177 content::WebContents* web_contents_; 177 content::WebContents* web_contents_;
178 content::RenderWidgetHostView* view_; 178 content::RenderWidgetHostView* view_;
179 const ui::TextInputType expected_type_; 179 const ui::TextInputType expected_type_;
180 180
181 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver); 181 DISALLOW_COPY_AND_ASSIGN(ViewTextInputTypeObserver);
182 }; 182 };
183 183
184 // This class observers the |expected_view| for the first change in its
kenrb 2016/06/28 19:15:23 nit: /s/observers/observes
EhsanK 2016/06/29 17:09:58 Done.
185 // selection bounds.
186 class ViewsSelectionBoundsChangedObserver
187 : public TextInputManagerObserverBase {
188 public:
189 explicit ViewsSelectionBoundsChangedObserver(
190 content::WebContents* web_contents,
191 content::RenderWidgetHostView* expected_view)
192 : TextInputManagerObserverBase(web_contents),
193 expected_view_(expected_view) {
194 tester()->SetOnSelectionBoundsChangedCallback(
195 base::Bind(&ViewsSelectionBoundsChangedObserver::VerifyChange,
196 base::Unretained(this)));
197 }
198
199 private:
200 void VerifyChange(
201 content::TextInputManagerTester* text_input_manager_tester) {
202 if (expected_view_ == tester()->GetUpdatedView())
203 OnSuccess();
204 }
205
206 const content::RenderWidgetHostView* const expected_view_;
207
208 DISALLOW_COPY_AND_ASSIGN(ViewsSelectionBoundsChangedObserver);
209 };
210
184 } // namespace 211 } // namespace
185 212
186 // Main class for all TextInputState and IME related tests. 213 // Main class for all TextInputState and IME related tests.
187 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { 214 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
188 public: 215 public:
189 SitePerProcessTextInputManagerTest() {} 216 SitePerProcessTextInputManagerTest() {}
190 ~SitePerProcessTextInputManagerTest() override {} 217 ~SitePerProcessTextInputManagerTest() override {}
191 218
192 void SetUpCommandLine(base::CommandLine* command_line) override { 219 void SetUpCommandLine(base::CommandLine* command_line) override {
193 content::IsolateAllSitesForTesting(command_line); 220 content::IsolateAllSitesForTesting(command_line);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB, 466 SimulateKeyPress(active_contents(), ui::DomKey::TAB, ui::DomCode::TAB,
440 ui::VKEY_TAB, false, false, false, false); 467 ui::VKEY_TAB, false, false, false, false);
441 set_state_observer.Wait(); 468 set_state_observer.Wait();
442 469
443 TextInputManagerTypeObserver reset_state_observer(active_contents(), 470 TextInputManagerTypeObserver reset_state_observer(active_contents(),
444 ui::TEXT_INPUT_TYPE_NONE); 471 ui::TEXT_INPUT_TYPE_NONE);
445 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 472 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
446 reset_state_observer.Wait(); 473 reset_state_observer.Wait();
447 } 474 }
448 475
476 // This test creates a page with multiple child frames and adds an <input> to
477 // each frame. Then, sequentially, each <input> is focused by sending a tab key.
478 // Then, after |TextInputState.type| for a view is changed to text, another key
479 // is pressed (a character) and then the test verifies that TextInputManager
480 // receives the corresponding update on the change in selection bounds on the
481 // browser side.
482 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
483 TrackSelectionBoundsForChildFrames) {
484 CreateIframePage("a(b,c(a,b),d)");
485 std::vector<content::RenderFrameHost*> frames{
486 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
487 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
488 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
489 std::vector<content::RenderWidgetHostView*> views;
490 for (auto frame : frames)
491 views.push_back(frame->GetView());
492 for (size_t i = 0; i < frames.size(); ++i)
493 AddInputFieldToFrame(frames[i], "text", "", true);
494
495 content::WebContents* web_contents = active_contents();
496
497 auto send_tab_insert_text_wait_for_bounds_change = [&web_contents](
498 content::RenderWidgetHostView* view) {
499 ViewTextInputTypeObserver type_observer(web_contents, view,
500 ui::TEXT_INPUT_TYPE_TEXT);
501 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
502 ui::VKEY_TAB, false, false, false, false);
503 type_observer.Wait();
504 ViewsSelectionBoundsChangedObserver bounds_observer(web_contents, view);
505 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'),
506 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false);
507 bounds_observer.Wait();
508 };
509
510 for (auto view : views)
511 send_tab_insert_text_wait_for_bounds_change(view);
512 }
513
449 // TODO(ekaramad): The following tests are specifically written for Aura and are 514 // TODO(ekaramad): The following tests are specifically written for Aura and are
450 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 515 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
451 // (crbug.com/602723). 516 // (crbug.com/602723).
452 517
453 // Observes current input method for state changes. 518 // Observes current input method for state changes.
454 class InputMethodObserverBase { 519 class InputMethodObserverBase {
455 public: 520 public:
456 explicit InputMethodObserverBase(content::WebContents* web_contents) 521 explicit InputMethodObserverBase(content::WebContents* web_contents)
457 : success_(false), 522 : success_(false),
458 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { 523 test_observer_(content::TestInputMethodObserver::Create(web_contents)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 EXPECT_FALSE(send_and_check_show_ime()); 613 EXPECT_FALSE(send_and_check_show_ime());
549 614
550 // Set |TextInputState.show_ime_if_needed|. Expect IME. 615 // Set |TextInputState.show_ime_if_needed|. Expect IME.
551 sender.SetShowImeIfNeeded(true); 616 sender.SetShowImeIfNeeded(true);
552 EXPECT_TRUE(send_and_check_show_ime()); 617 EXPECT_TRUE(send_and_check_show_ime());
553 618
554 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 619 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
555 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 620 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
556 EXPECT_FALSE(send_and_check_show_ime()); 621 EXPECT_FALSE(send_and_check_show_ime());
557 } 622 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698