OLD | NEW |
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 "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void VerifyChange() { | 228 void VerifyChange() { |
229 if (expected_view_ == tester()->GetUpdatedView()) | 229 if (expected_view_ == tester()->GetUpdatedView()) |
230 OnSuccess(); | 230 OnSuccess(); |
231 } | 231 } |
232 | 232 |
233 const content::RenderWidgetHostView* const expected_view_; | 233 const content::RenderWidgetHostView* const expected_view_; |
234 | 234 |
235 DISALLOW_COPY_AND_ASSIGN(ViewCompositionRangeChangedObserver); | 235 DISALLOW_COPY_AND_ASSIGN(ViewCompositionRangeChangedObserver); |
236 }; | 236 }; |
237 | 237 |
| 238 // This class observes the |expected_view| for a change in the text selection |
| 239 // that has a selection length of |expected_length|. |
| 240 class ViewTextSelectionObserver : public TextInputManagerObserverBase { |
| 241 public: |
| 242 ViewTextSelectionObserver(content::WebContents* web_contents, |
| 243 content::RenderWidgetHostView* expected_view, |
| 244 size_t expected_selection_length) |
| 245 : TextInputManagerObserverBase(web_contents), |
| 246 expected_view_(expected_view), |
| 247 expected_selection_length_(expected_selection_length) { |
| 248 tester()->SetOnTextSelectionChangedCallback(base::Bind( |
| 249 &ViewTextSelectionObserver::VerifyChange, base::Unretained(this))); |
| 250 } |
| 251 |
| 252 private: |
| 253 void VerifyChange() { |
| 254 if (expected_view_ == tester()->GetUpdatedView()) { |
| 255 size_t selection_length; |
| 256 if (tester()->GetCurrentTextSelectionLength(&selection_length) && |
| 257 expected_selection_length_ == selection_length) |
| 258 OnSuccess(); |
| 259 } |
| 260 } |
| 261 |
| 262 const content::RenderWidgetHostView* const expected_view_; |
| 263 const size_t expected_selection_length_; |
| 264 |
| 265 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); |
| 266 }; |
| 267 |
238 } // namespace | 268 } // namespace |
239 | 269 |
240 // Main class for all TextInputState and IME related tests. | 270 // Main class for all TextInputState and IME related tests. |
241 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { | 271 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { |
242 public: | 272 public: |
243 SitePerProcessTextInputManagerTest() {} | 273 SitePerProcessTextInputManagerTest() {} |
244 ~SitePerProcessTextInputManagerTest() override {} | 274 ~SitePerProcessTextInputManagerTest() override {} |
245 | 275 |
246 void SetUpCommandLine(base::CommandLine* command_line) override { | 276 void SetUpCommandLine(base::CommandLine* command_line) override { |
247 content::IsolateAllSitesForTesting(command_line); | 277 content::IsolateAllSitesForTesting(command_line); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 content::SetCompositionForRenderWidgetHost( | 605 content::SetCompositionForRenderWidgetHost( |
576 view->GetRenderWidgetHost(), base::ASCIIToUTF16("text"), | 606 view->GetRenderWidgetHost(), base::ASCIIToUTF16("text"), |
577 {ui::CompositionUnderline()}, gfx::Range::InvalidRange(), 0, 0); | 607 {ui::CompositionUnderline()}, gfx::Range::InvalidRange(), 0, 0); |
578 range_observer.Wait(); | 608 range_observer.Wait(); |
579 }; | 609 }; |
580 | 610 |
581 for (auto view : views) | 611 for (auto view : views) |
582 send_tab_set_composition_wait_for_bounds_change(view); | 612 send_tab_set_composition_wait_for_bounds_change(view); |
583 } | 613 } |
584 | 614 |
| 615 // This test creates a page with multiple child frames and adds an <input> to |
| 616 // each frame. Then, sequentially, each <input> is focused by sending a tab key. |
| 617 // After focusing each input, the whole text is automatically selected and a |
| 618 // ViewHostMsg_SelectionChanged IPC sent back to the browser. This test verifies |
| 619 // that the browser tracks the text selection from all frames. |
| 620 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest, |
| 621 TrackTextSelectionForAllFrames) { |
| 622 // TODO(ekaramad): Since IME related methods in WebFrameWidgetImpl are not |
| 623 // implemented yet, this test does not work on child frames. Add child frames |
| 624 // to this test when IME methods in WebFramgeWidgetImpl are implemented |
| 625 // (https://crbug.com/626746). |
| 626 CreateIframePage("a()"); |
| 627 std::vector<content::RenderFrameHost*> frames{GetFrame(IndexVector{})}; |
| 628 std::vector<content::RenderWidgetHostView*> views; |
| 629 for (auto frame : frames) |
| 630 views.push_back(frame->GetView()); |
| 631 std::vector<std::string> input_text{"abc"}; |
| 632 for (size_t i = 0; i < frames.size(); ++i) |
| 633 AddInputFieldToFrame(frames[i], "text", input_text[i], false); |
| 634 |
| 635 content::WebContents* web_contents = active_contents(); |
| 636 |
| 637 auto send_tab_and_wait_for_selection_change = [&web_contents]( |
| 638 content::RenderFrameHost* frame, size_t expected_length) { |
| 639 ViewTextSelectionObserver text_selection_observer( |
| 640 web_contents, frame->GetView(), expected_length); |
| 641 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, |
| 642 ui::VKEY_TAB, false, false, false, false); |
| 643 text_selection_observer.Wait(); |
| 644 }; |
| 645 |
| 646 for (size_t i = 0; i < frames.size(); ++i) |
| 647 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size()); |
| 648 } |
| 649 |
585 // TODO(ekaramad): The following tests are specifically written for Aura and are | 650 // TODO(ekaramad): The following tests are specifically written for Aura and are |
586 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus | 651 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus |
587 // (crbug.com/602723). | 652 // (crbug.com/602723). |
588 | 653 |
589 // Observes current input method for state changes. | 654 // Observes current input method for state changes. |
590 class InputMethodObserverBase { | 655 class InputMethodObserverBase { |
591 public: | 656 public: |
592 explicit InputMethodObserverBase(content::WebContents* web_contents) | 657 explicit InputMethodObserverBase(content::WebContents* web_contents) |
593 : success_(false), | 658 : success_(false), |
594 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { | 659 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 EXPECT_FALSE(send_and_check_show_ime()); | 749 EXPECT_FALSE(send_and_check_show_ime()); |
685 | 750 |
686 // Set |TextInputState.show_ime_if_needed|. Expect IME. | 751 // Set |TextInputState.show_ime_if_needed|. Expect IME. |
687 sender.SetShowImeIfNeeded(true); | 752 sender.SetShowImeIfNeeded(true); |
688 EXPECT_TRUE(send_and_check_show_ime()); | 753 EXPECT_TRUE(send_and_check_show_ime()); |
689 | 754 |
690 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. | 755 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. |
691 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); | 756 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); |
692 EXPECT_FALSE(send_and_check_show_ime()); | 757 EXPECT_FALSE(send_and_check_show_ime()); |
693 } | 758 } |
OLD | NEW |