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

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

Issue 2132633002: Tracking composition range on the browser side (Aura) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing 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 "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/render_frame_host.h" 13 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/browser_test_utils.h" 16 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "content/public/test/text_input_test_utils.h" 19 #include "content/public/test/text_input_test_utils.h"
19 #include "net/dns/mock_host_resolver.h" 20 #include "net/dns/mock_host_resolver.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
22 #include "ui/base/ime/composition_underline.h"
21 #include "ui/base/ime/text_input_client.h" 23 #include "ui/base/ime/text_input_client.h"
22 #include "ui/base/ime/text_input_mode.h" 24 #include "ui/base/ime/text_input_mode.h"
23 #include "ui/base/ime/text_input_type.h" 25 #include "ui/base/ime/text_input_type.h"
24 #include "url/gurl.h" 26 #include "url/gurl.h"
25 27
26 // TODO(ekaramad): The following tests are only active on aura platforms. After 28 // TODO(ekaramad): The following tests are only active on aura platforms. After
27 // fixing crbug.com/578168 for all platforms, the following tests should be 29 // fixing crbug.com/578168 for all platforms, the following tests should be
28 // activated for other platforms, e.g., Mac and Android (crbug.com/602723). 30 // activated for other platforms, e.g., Mac and Android (crbug.com/602723).
29 31
30 /////////////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////////////
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void VerifyChange() { 201 void VerifyChange() {
200 if (expected_view_ == tester()->GetUpdatedView()) 202 if (expected_view_ == tester()->GetUpdatedView())
201 OnSuccess(); 203 OnSuccess();
202 } 204 }
203 205
204 const content::RenderWidgetHostView* const expected_view_; 206 const content::RenderWidgetHostView* const expected_view_;
205 207
206 DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver); 208 DISALLOW_COPY_AND_ASSIGN(ViewSelectionBoundsChangedObserver);
207 }; 209 };
208 210
211 // This class observes the |expected_view| for the first change in its
212 // composition range information.
213 class ViewCompositionRangeChangedObserver
214 : public TextInputManagerObserverBase {
215 public:
216 ViewCompositionRangeChangedObserver(
217 content::WebContents* web_contents,
218 content::RenderWidgetHostView* expected_view)
219 : TextInputManagerObserverBase(web_contents),
220 expected_view_(expected_view) {
221 tester()->SetOnImeCompositionRangeChangedCallback(
222 base::Bind(&ViewCompositionRangeChangedObserver::VerifyChange,
223 base::Unretained(this)));
224 }
225
226 private:
227 void VerifyChange() {
228 if (expected_view_ == tester()->GetUpdatedView())
229 OnSuccess();
230 }
231
232 const content::RenderWidgetHostView* const expected_view_;
233
234 DISALLOW_COPY_AND_ASSIGN(ViewCompositionRangeChangedObserver);
235 };
236
209 } // namespace 237 } // namespace
210 238
211 // Main class for all TextInputState and IME related tests. 239 // Main class for all TextInputState and IME related tests.
212 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { 240 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
213 public: 241 public:
214 SitePerProcessTextInputManagerTest() {} 242 SitePerProcessTextInputManagerTest() {}
215 ~SitePerProcessTextInputManagerTest() override {} 243 ~SitePerProcessTextInputManagerTest() override {}
216 244
217 void SetUpCommandLine(base::CommandLine* command_line) override { 245 void SetUpCommandLine(base::CommandLine* command_line) override {
218 content::IsolateAllSitesForTesting(command_line); 246 content::IsolateAllSitesForTesting(command_line);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 reset_state_observer.Wait(); 505 reset_state_observer.Wait();
478 } 506 }
479 507
480 // This test creates a page with multiple child frames and adds an <input> to 508 // 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. 509 // 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 510 // 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 511 // is pressed (a character) and then the test verifies that TextInputManager
484 // receives the corresponding update on the change in selection bounds on the 512 // receives the corresponding update on the change in selection bounds on the
485 // browser side. 513 // browser side.
486 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, 514 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
487 TrackSelectionBoundsForChildFrames) { 515 TrackSelectionBoundsForAllFrames) {
488 CreateIframePage("a(b,c(a,b),d)"); 516 CreateIframePage("a(b,c(a,b),d)");
489 std::vector<content::RenderFrameHost*> frames{ 517 std::vector<content::RenderFrameHost*> frames{
490 GetFrame(IndexVector{}), GetFrame(IndexVector{0}), 518 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
491 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}), 519 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
492 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})}; 520 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
493 std::vector<content::RenderWidgetHostView*> views; 521 std::vector<content::RenderWidgetHostView*> views;
494 for (auto frame : frames) 522 for (auto frame : frames)
495 views.push_back(frame->GetView()); 523 views.push_back(frame->GetView());
496 for (size_t i = 0; i < frames.size(); ++i) 524 for (size_t i = 0; i < frames.size(); ++i)
497 AddInputFieldToFrame(frames[i], "text", "", true); 525 AddInputFieldToFrame(frames[i], "text", "", true);
(...skipping 10 matching lines...) Expand all
508 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view); 536 ViewSelectionBoundsChangedObserver bounds_observer(web_contents, view);
509 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'), 537 SimulateKeyPress(web_contents, ui::DomKey::FromCharacter('E'),
510 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false); 538 ui::DomCode::US_E, ui::VKEY_E, false, false, false, false);
511 bounds_observer.Wait(); 539 bounds_observer.Wait();
512 }; 540 };
513 541
514 for (auto view : views) 542 for (auto view : views)
515 send_tab_insert_text_wait_for_bounds_change(view); 543 send_tab_insert_text_wait_for_bounds_change(view);
516 } 544 }
517 545
546 // This test creates a page with multiple child frames and adds an <input> to
547 // each frame. Then, sequentially, each <input> is focused by sending a tab key.
548 // Then, after |TextInputState.type| for a view is changed to text, the test
549 // sends a set composition IPC to the active widget and waits until the widget
550 // updates its composition range.
551 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
552 TrackCompositionRangeForAllFrames) {
553 // TODO(ekaramd): After IME methods are implemented for WebFrameWidgetImpl,
554 // change the page so that it contains child frames as well
555 // (crbug.com/626746).
556 CreateIframePage("a()");
557 std::vector<content::RenderFrameHost*> frames{GetFrame(IndexVector{})};
558 std::vector<content::RenderWidgetHostView*> views;
559 for (auto frame : frames)
560 views.push_back(frame->GetView());
561 for (size_t i = 0; i < frames.size(); ++i)
562 AddInputFieldToFrame(frames[i], "text", "", true);
563
564 content::WebContents* web_contents = active_contents();
565
566 ui::CompositionText composition;
567 composition.text = base::ASCIIToUTF16("text");
568 composition.underlines = {ui::CompositionUnderline()};
569 composition.selection = gfx::Range();
570 auto send_tab_set_composition_wait_for_bounds_change =
571 [&web_contents, &composition](content::RenderWidgetHostView* view) {
572 ViewTextInputTypeObserver type_observer(web_contents, view,
573 ui::TEXT_INPUT_TYPE_TEXT);
574 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
575 ui::VKEY_TAB, false, false, false, false);
576 type_observer.Wait();
577 ViewCompositionRangeChangedObserver range_observer(web_contents, view);
578 content::SetCompositionTextForFocusedTextInputClient(web_contents,
579 composition);
580 range_observer.Wait();
581 };
582
583 for (auto view : views)
584 send_tab_set_composition_wait_for_bounds_change(view);
585 }
586
518 // TODO(ekaramad): The following tests are specifically written for Aura and are 587 // TODO(ekaramad): The following tests are specifically written for Aura and are
519 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 588 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
520 // (crbug.com/602723). 589 // (crbug.com/602723).
521 590
522 // Observes current input method for state changes. 591 // Observes current input method for state changes.
523 class InputMethodObserverBase { 592 class InputMethodObserverBase {
524 public: 593 public:
525 explicit InputMethodObserverBase(content::WebContents* web_contents) 594 explicit InputMethodObserverBase(content::WebContents* web_contents)
526 : success_(false), 595 : success_(false),
527 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { 596 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()); 686 EXPECT_FALSE(send_and_check_show_ime());
618 687
619 // Set |TextInputState.show_ime_if_needed|. Expect IME. 688 // Set |TextInputState.show_ime_if_needed|. Expect IME.
620 sender.SetShowImeIfNeeded(true); 689 sender.SetShowImeIfNeeded(true);
621 EXPECT_TRUE(send_and_check_show_ime()); 690 EXPECT_TRUE(send_and_check_show_ime());
622 691
623 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 692 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
624 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 693 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
625 EXPECT_FALSE(send_and_check_show_ime()); 694 EXPECT_FALSE(send_and_check_show_ime());
626 } 695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698