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

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

Issue 2130133004: Tracking text selection on the browser side in OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added an interactive ui test 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void VerifyChange() { 199 void VerifyChange() {
200 if (expected_view_ == tester()->GetUpdatedView()) 200 if (expected_view_ == tester()->GetUpdatedView())
201 OnSuccess(); 201 OnSuccess();
202 } 202 }
203 203
204 const content::RenderWidgetHostView* const expected_view_; 204 const content::RenderWidgetHostView* const expected_view_;
205 205
206 DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver); 206 DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver);
207 }; 207 };
208 208
209 // This class observes the |expected_view| for a change in the text selection
210 // that has a selection length of |expected_length|.
211 class ViewTextSelectionObserver : public TextInputManagerObserverBase {
212 public:
213 ViewTextSelectionObserver(content::WebContents* web_contents,
214 content::RenderWidgetHostView* expected_view,
215 size_t expected_selection_length)
216 : TextInputManagerObserverBase(web_contents),
217 expected_view_(expected_view),
218 expected_selection_length_(expected_selection_length) {
219 tester()->SetOnTextSelectionChangedCallback(base::Bind(
220 &ViewTextSelectionObserver::VerifyChange, base::Unretained(this)));
221 }
222
223 private:
224 void VerifyChange() {
225 if (expected_view_ == tester()->GetUpdatedView()) {
226 size_t selection_length;
227 if (tester()->GetCurrentTextSelectionLength(&selection_length) &&
228 expected_selection_length_ == selection_length)
229 OnSuccess();
230 }
231 }
232
233 const content::RenderWidgetHostView* const expected_view_;
234 const size_t expected_selection_length_;
235
236 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver);
237 };
238
209 } // namespace 239 } // namespace
210 240
211 // Main class for all TextInputState and IME related tests. 241 // Main class for all TextInputState and IME related tests.
212 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { 242 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
213 public: 243 public:
214 SitePerProcessTextInputManagerTest() {} 244 SitePerProcessTextInputManagerTest() {}
215 ~SitePerProcessTextInputManagerTest() override {} 245 ~SitePerProcessTextInputManagerTest() override {}
216 246
217 void SetUpCommandLine(base::CommandLine* command_line) override { 247 void SetUpCommandLine(base::CommandLine* command_line) override {
218 content::IsolateAllSitesForTesting(command_line); 248 content::IsolateAllSitesForTesting(command_line);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); 538 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view);
509 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), 539 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'),
510 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); 540 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false);
511 bounds_observer.Wait(); 541 bounds_observer.Wait();
512 }; 542 };
513 543
514 for (auto view : views) 544 for (auto view : views)
515 send_tab_insert_text_wait_for_bounds_change(view); 545 send_tab_insert_text_wait_for_bounds_change(view);
516 } 546 }
517 547
548 // This test creates a page with multiple child frames and adds an <input> to
549 // each frame. Then, sequentially, each <input> is focused by sending a tab key.
550 // After focusing each input, the whole text is automatically selected and a
551 // ViewHostMsg_SelectionChanged IPC sent back to the browser. This test verifies
552 // that the browser tracks the text selection from all frames.
553 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
554 TrackTextSelectionForAllFrames) {
555 // TODO(ekaramad): Since IME related methods in WebFrameWidgetImpl are not
556 // implemented yet, this test does not work on child frames. Add child frames
557 // to this test when IME methods in WebFramgeWidgetImpl are implemented
558 // (https://crbug.com/626746).
559 CreateIframePage("a()");
560 std::vector<content::RenderFrameHost*> frames{GetFrame(IndexVector{})};
561 std::vector<content::RenderWidgetHostView*> views;
562 for (auto frame : frames)
563 views.push_back(frame->GetView());
564 std::vector<std::string> input_text{"abc"};
565 for (size_t i = 0; i < frames.size(); ++i)
566 AddInputFieldToFrame(frames[i], "text", input_text[i], false);
567
568 content::WebContents* web_contents = active_contents();
569
570 auto send_tab_and_wait_for_selection_change = [&web_contents](
571 content::RenderFrameHost* frame, size_t expected_length) {
572 ViewTextSelectionObserver text_selection_observer(
573 web_contents, frame->GetView(), expected_length);
574 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
575 ui::VKEY_TAB, false, false, false, false);
576 text_selection_observer.Wait();
577 };
578
579 for (size_t i = 0; i < frames.size(); ++i)
580 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size());
581 }
582
518 // TODO(ekaramad): The following tests are specifically written for Aura and are 583 // TODO(ekaramad): The following tests are specifically written for Aura and are
519 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 584 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
520 // (crbug.com/602723). 585 // (crbug.com/602723).
521 586
522 // Observes current input method for state changes. 587 // Observes current input method for state changes.
523 class InputMethodObserverBase { 588 class InputMethodObserverBase {
524 public: 589 public:
525 explicit InputMethodObserverBase(content::WebContents* web_contents) 590 explicit InputMethodObserverBase(content::WebContents* web_contents)
526 : success_(false), 591 : success_(false),
527 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { 592 test_observer_(content::TestInputMethodObserver::Create(web_contents)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 EXPECT_FALSE(send_and_check_show_ime()); 682 EXPECT_FALSE(send_and_check_show_ime());
618 683
619 // Set |TextInputState.show_ime_if_needed|. Expect IME. 684 // Set |TextInputState.show_ime_if_needed|. Expect IME.
620 sender.SetShowImeIfNeeded(true); 685 sender.SetShowImeIfNeeded(true);
621 EXPECT_TRUE(send_and_check_show_ime()); 686 EXPECT_TRUE(send_and_check_show_ime());
622 687
623 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 688 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
624 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 689 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
625 EXPECT_FALSE(send_and_check_show_ime()); 690 EXPECT_FALSE(send_and_check_show_ime());
626 } 691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698