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

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

Issue 2171443003: In TextInputManager, reset input type to none before switching active widgets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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/renderer_host/text_input_manager.cc » ('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 "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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 OnSuccess(); 259 OnSuccess();
260 } 260 }
261 } 261 }
262 262
263 const content::RenderWidgetHostView* const expected_view_; 263 const content::RenderWidgetHostView* const expected_view_;
264 const size_t expected_selection_length_; 264 const size_t expected_selection_length_;
265 265
266 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); 266 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver);
267 }; 267 };
268 268
269 // This class monitors all the changes in TextInputState and keeps a record of
270 // the active views. There is no waiting and the recording process is
271 // continuous.
272 class RecordActiveViewsObserver {
273 public:
274 explicit RecordActiveViewsObserver(content::WebContents* web_contents)
275 : tester_(new content::TextInputManagerTester(web_contents)) {
276 tester_->SetUpdateTextInputStateCalledCallback(base::Bind(
277 &RecordActiveViewsObserver::RecordActiveView, base::Unretained(this)));
278 }
279
280 const std::vector<const content::RenderWidgetHostView*>* active_views()
281 const {
282 return &active_views_;
283 }
284
285 private:
286 void RecordActiveView() {
287 if (!tester_->IsTextInputStateChanged())
288 return;
289 active_views_.push_back(tester_->GetActiveView());
290 }
291
292 std::unique_ptr<content::TextInputManagerTester> tester_;
293 std::vector<const content::RenderWidgetHostView*> active_views_;
294
295 DISALLOW_COPY_AND_ASSIGN(RecordActiveViewsObserver);
296 };
297
269 } // namespace 298 } // namespace
270 299
271 // Main class for all TextInputState and IME related tests. 300 // Main class for all TextInputState and IME related tests.
272 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { 301 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
273 public: 302 public:
274 SitePerProcessTextInputManagerTest() {} 303 SitePerProcessTextInputManagerTest() {}
275 ~SitePerProcessTextInputManagerTest() override {} 304 ~SitePerProcessTextInputManagerTest() override {}
276 305
277 void SetUpCommandLine(base::CommandLine* command_line) override { 306 void SetUpCommandLine(base::CommandLine* command_line) override {
278 content::IsolateAllSitesForTesting(command_line); 307 content::IsolateAllSitesForTesting(command_line);
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 web_contents, frame->GetView(), expected_length); 673 web_contents, frame->GetView(), expected_length);
645 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, 674 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
646 ui::VKEY_TAB, false, false, false, false); 675 ui::VKEY_TAB, false, false, false, false);
647 text_selection_observer.Wait(); 676 text_selection_observer.Wait();
648 }; 677 };
649 678
650 for (size_t i = 0; i < frames.size(); ++i) 679 for (size_t i = 0; i < frames.size(); ++i)
651 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size()); 680 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size());
652 } 681 }
653 682
683 // The following test verifies that when the active widget changes value, it is
684 // always from nullptr to non-null or vice versa.
685 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
686 ResetTextInputStateOnActiveWidgetChange) {
687 CreateIframePage("a(b,c(a,b),d)");
688 std::vector<content::RenderFrameHost*> frames{
689 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
690 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
691 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
692 std::vector<content::RenderWidgetHostView*> views;
693 for (auto frame : frames)
694 views.push_back(frame->GetView());
695 std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"};
696 for (size_t i = 0; i < frames.size(); ++i)
697 AddInputFieldToFrame(frames[i], "text", values[i], true);
698
699 content::WebContents* web_contents = active_contents();
700
701 auto send_tab_and_wait_for_value =
702 [&web_contents](const std::string& expected_value) {
703 TextInputManagerValueObserver observer(web_contents, expected_value);
704 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
705 ui::VKEY_TAB, false, false, false, false);
706 observer.Wait();
707 };
708
709 // Record all active view changes.
710 RecordActiveViewsObserver recorder(web_contents);
711 for (auto value : values)
712 send_tab_and_wait_for_value(value);
713
714 // We have covered a total of 6 views, so there should at least be 11 entries
715 // recorded (at least one null between two views).
716 size_t record_count = recorder.active_views()->size();
717 EXPECT_GT(record_count, 10U);
718
719 // Verify we do not have subsequent nullptr or non-nullptrs.
720 for (size_t i = 0; i < record_count - 1U; ++i) {
721 const content::RenderWidgetHostView* current =
722 recorder.active_views()->at(i);
723 const content::RenderWidgetHostView* next =
724 recorder.active_views()->at(i + 1U);
725 EXPECT_TRUE((current != nullptr && next == nullptr) ||
726 (current == nullptr && next != nullptr));
727 }
728 }
729
730 // TODO(ekaramad): The following tests are specifically written for Aura and are
731 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
732 // (crbug.com/602723).
733
654 // ----------------------------------------------------------------------------- 734 // -----------------------------------------------------------------------------
655 // Input Method Observer Tests 735 // Input Method Observer Tests
656 // 736 //
657 // The following tests will make use of the InputMethodObserver to verify that 737 // The following tests will make use of the InputMethodObserver to verify that
658 // OOPIF pages interact properly with the InputMethod through the tab's view. 738 // OOPIF pages interact properly with the InputMethod through the tab's view.
659 739
660 // TODO(ekaramad): We only have coverage for some aura tests as the whole idea 740 // TODO(ekaramad): We only have coverage for some aura tests as the whole idea
661 // of ui::TextInputClient/ui::InputMethod/ui::InputMethodObserver seems to be 741 // of ui::TextInputClient/ui::InputMethod/ui::InputMethodObserver seems to be
662 // only fit to aura (specifically, OS_CHROMEOS). Can we add more tests here for 742 // only fit to aura (specifically, OS_CHROMEOS). Can we add more tests here for
663 // aura as well as other platforms (https://crbug.com/602723)? 743 // aura as well as other platforms (https://crbug.com/602723)?
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 841
762 // Set |TextInputState.show_ime_if_needed|. Expect IME. 842 // Set |TextInputState.show_ime_if_needed|. Expect IME.
763 sender.SetShowImeIfNeeded(true); 843 sender.SetShowImeIfNeeded(true);
764 EXPECT_TRUE(send_and_check_show_ime()); 844 EXPECT_TRUE(send_and_check_show_ime());
765 845
766 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 846 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
767 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 847 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
768 EXPECT_FALSE(send_and_check_show_ime()); 848 EXPECT_FALSE(send_and_check_show_ime());
769 } 849 }
770 #endif // USE_AURA 850 #endif // USE_AURA
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/text_input_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698