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

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