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

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: Fixed a typo in comment 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
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 OnSuccess(); 258 OnSuccess();
259 } 259 }
260 } 260 }
261 261
262 const content::RenderWidgetHostView* const expected_view_; 262 const content::RenderWidgetHostView* const expected_view_;
263 const size_t expected_selection_length_; 263 const size_t expected_selection_length_;
264 264
265 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver); 265 DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver);
266 }; 266 };
267 267
268 // This class monitors all the changes in TextInputState and keeps a record of
269 // the active views. There is no waiting and the recording process is
270 // continuous.
271 class RecordActiveViewsObserver {
272 public:
273 explicit RecordActiveViewsObserver(content::WebContents* web_contents)
274 : tester_(new content::TextInputManagerTester(web_contents)) {
275 tester_->SetUpdateTextInputStateCalledCallback(base::Bind(
276 &RecordActiveViewsObserver::RecordActiveView, base::Unretained(this)));
277 }
278
279 const std::vector<const content::RenderWidgetHostView*>* active_views()
280 const {
281 return &active_views_;
282 }
283
284 private:
285 void RecordActiveView() {
286 if (!tester_->IsTextInputStateChanged())
287 return;
288 active_views_.push_back(tester_->GetActiveView());
289 }
290
291 std::unique_ptr<content::TextInputManagerTester> tester_;
292 std::vector<const content::RenderWidgetHostView*> active_views_;
293
294 DISALLOW_COPY_AND_ASSIGN(RecordActiveViewsObserver);
295 };
296
268 } // namespace 297 } // namespace
269 298
270 // Main class for all TextInputState and IME related tests. 299 // Main class for all TextInputState and IME related tests.
271 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { 300 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
272 public: 301 public:
273 SitePerProcessTextInputManagerTest() {} 302 SitePerProcessTextInputManagerTest() {}
274 ~SitePerProcessTextInputManagerTest() override {} 303 ~SitePerProcessTextInputManagerTest() override {}
275 304
276 void SetUpCommandLine(base::CommandLine* command_line) override { 305 void SetUpCommandLine(base::CommandLine* command_line) override {
277 content::IsolateAllSitesForTesting(command_line); 306 content::IsolateAllSitesForTesting(command_line);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 web_contents, frame->GetView(), expected_length); 669 web_contents, frame->GetView(), expected_length);
641 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, 670 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
642 ui::VKEY_TAB, false, false, false, false); 671 ui::VKEY_TAB, false, false, false, false);
643 text_selection_observer.Wait(); 672 text_selection_observer.Wait();
644 }; 673 };
645 674
646 for (size_t i = 0; i < frames.size(); ++i) 675 for (size_t i = 0; i < frames.size(); ++i)
647 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size()); 676 send_tab_and_wait_for_selection_change(frames[i], input_text[i].size());
648 } 677 }
649 678
679 // The following test verifies that when the active widget changes value, it is
680 // always from nullptr to non-null or vice versa.
681 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
682 ResetTextInputStateOnActiveWidgetChange) {
683 CreateIframePage("a(b,c(a,b),d)");
684 std::vector<content::RenderFrameHost*> frames{
685 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
686 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
687 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
688 std::vector<content::RenderWidgetHostView*> views;
689 for (auto frame : frames)
690 views.push_back(frame->GetView());
691 std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"};
692 for (size_t i = 0; i < frames.size(); ++i)
693 AddInputFieldToFrame(frames[i], "text", values[i], true);
694
695 content::WebContents* web_contents = active_contents();
696
697 auto send_tab_and_wait_for_value =
698 [&web_contents](const std::string& expected_value) {
699 TextInputManagerValueObserver observer(web_contents, expected_value);
700 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
701 ui::VKEY_TAB, false, false, false, false);
702 observer.Wait();
703 };
704
705 // Record all active view changes.
706 RecordActiveViewsObserver recorder(web_contents);
707 for (auto value : values)
708 send_tab_and_wait_for_value(value);
709
710 // We have covered a total of 6 views, so there should at least be 11 entries
711 // recorded (at least one null between two views).
712 size_t record_count = recorder.active_views()->size();
713 EXPECT_GT(record_count, 10U);
714
715 // Verify we do not have subsequent nullptr or non-nullptrs.
716 for (size_t i = 0; i < record_count - 1U; ++i) {
717 const content::RenderWidgetHostView* current =
718 recorder.active_views()->at(i);
719 const content::RenderWidgetHostView* next =
720 recorder.active_views()->at(i + 1U);
721 EXPECT_TRUE((current != nullptr && next == nullptr) ||
722 (current == nullptr && next != nullptr));
723 }
724 }
725
650 // TODO(ekaramad): The following tests are specifically written for Aura and are 726 // TODO(ekaramad): The following tests are specifically written for Aura and are
651 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 727 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
652 // (crbug.com/602723). 728 // (crbug.com/602723).
653 729
654 // Observes current input method for state changes. 730 // Observes current input method for state changes.
655 class InputMethodObserverBase { 731 class InputMethodObserverBase {
656 public: 732 public:
657 explicit InputMethodObserverBase(content::WebContents* web_contents) 733 explicit InputMethodObserverBase(content::WebContents* web_contents)
658 : success_(false), 734 : success_(false),
659 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { 735 test_observer_(content::TestInputMethodObserver::Create(web_contents)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 EXPECT_FALSE(send_and_check_show_ime()); 825 EXPECT_FALSE(send_and_check_show_ime());
750 826
751 // Set |TextInputState.show_ime_if_needed|. Expect IME. 827 // Set |TextInputState.show_ime_if_needed|. Expect IME.
752 sender.SetShowImeIfNeeded(true); 828 sender.SetShowImeIfNeeded(true);
753 EXPECT_TRUE(send_and_check_show_ime()); 829 EXPECT_TRUE(send_and_check_show_ime());
754 830
755 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 831 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
756 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 832 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
757 EXPECT_FALSE(send_and_check_show_ime()); 833 EXPECT_FALSE(send_and_check_show_ime());
758 } 834 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698