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

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: Fix the failing test on ASAN bots 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 "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
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 monitors all the changes in TextInputState and keeps a record of
239 // the active views. There is no waiting and the recording process is
240 // continuous.
241 class RecordActiveViewsObserver {
242 public:
243 explicit RecordActiveViewsObserver(content::WebContents* web_contents)
244 : tester_(new content::TextInputManagerTester(web_contents)) {
245 tester_->SetUpdateTextInputStateCalledCallback(base::Bind(
246 &RecordActiveViewsObserver::RecordActiveView, base::Unretained(this)));
247 }
248
249 const std::vector<const content::RenderWidgetHostView*>* active_views()
250 const {
251 return &active_views_;
252 }
253
254 private:
255 void RecordActiveView() {
256 if (!tester_->IsTextInputStateChanged())
257 return;
258 active_views_.push_back(tester_->GetActiveView());
259 }
260
261 std::unique_ptr<content::TextInputManagerTester> tester_;
262 std::vector<const content::RenderWidgetHostView*> active_views_;
263
264 DISALLOW_COPY_AND_ASSIGN(RecordActiveViewsObserver);
265 };
266
238 } // namespace 267 } // namespace
239 268
240 // Main class for all TextInputState and IME related tests. 269 // Main class for all TextInputState and IME related tests.
241 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest { 270 class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
242 public: 271 public:
243 SitePerProcessTextInputManagerTest() {} 272 SitePerProcessTextInputManagerTest() {}
244 ~SitePerProcessTextInputManagerTest() override {} 273 ~SitePerProcessTextInputManagerTest() override {}
245 274
246 void SetUpCommandLine(base::CommandLine* command_line) override { 275 void SetUpCommandLine(base::CommandLine* command_line) override {
247 content::IsolateAllSitesForTesting(command_line); 276 content::IsolateAllSitesForTesting(command_line);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 content::SetCompositionForRenderWidgetHost( 604 content::SetCompositionForRenderWidgetHost(
576 view->GetRenderWidgetHost(), base::ASCIIToUTF16("text"), 605 view->GetRenderWidgetHost(), base::ASCIIToUTF16("text"),
577 {ui::CompositionUnderline()}, gfx::Range::InvalidRange(), 0, 0); 606 {ui::CompositionUnderline()}, gfx::Range::InvalidRange(), 0, 0);
578 range_observer.Wait(); 607 range_observer.Wait();
579 }; 608 };
580 609
581 for (auto view : views) 610 for (auto view : views)
582 send_tab_set_composition_wait_for_bounds_change(view); 611 send_tab_set_composition_wait_for_bounds_change(view);
583 } 612 }
584 613
614 // The following test verifies that when the active widget changes value, it is
615 // always from nullptr to non-null or vice versa.
616 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
617 ResetTextInputStateOnActiveWidgetChange) {
618 CreateIframePage("a(b,c(a,b),d)");
619 std::vector<content::RenderFrameHost*> frames{
620 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
621 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
622 GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
623 std::vector<content::RenderWidgetHostView*> views;
624 for (auto frame : frames)
625 views.push_back(frame->GetView());
626 std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"};
627 for (size_t i = 0; i < frames.size(); ++i)
628 AddInputFieldToFrame(frames[i], "text", values[i], true);
629
630 content::WebContents* web_contents = active_contents();
631
632 auto send_tab_and_wait_for_value =
633 [&web_contents](const std::string& expected_value) {
634 TextInputManagerValueObserver observer(web_contents, expected_value);
635 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
636 ui::VKEY_TAB, false, false, false, false);
637 observer.Wait();
638 };
639
640 // Record all active view changes.
641 RecordActiveViewsObserver recorder(web_contents);
642 for (auto value : values)
643 send_tab_and_wait_for_value(value);
644
645 // We have covered a total of 6 views, so there should at least be 11 entries
646 // recorded (at least one null between two views).
647 size_t record_count = recorder.active_views()->size();
648 EXPECT_GT(record_count, 10U);
649
650 // Verify we do not have subsequent nullptr or non-nullptrs.
651 for (size_t i = 0; i < record_count - 1U; ++i) {
652 const content::RenderWidgetHostView* current =
653 recorder.active_views()->at(i);
654 const content::RenderWidgetHostView* next =
655 recorder.active_views()->at(i + 1U);
656 EXPECT_TRUE((current != nullptr && next == nullptr) ||
657 (current == nullptr && next != nullptr));
658 }
659 }
660
585 // TODO(ekaramad): The following tests are specifically written for Aura and are 661 // TODO(ekaramad): The following tests are specifically written for Aura and are
586 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 662 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
587 // (crbug.com/602723). 663 // (crbug.com/602723).
588 664
589 // Observes current input method for state changes. 665 // Observes current input method for state changes.
590 class InputMethodObserverBase { 666 class InputMethodObserverBase {
591 public: 667 public:
592 explicit InputMethodObserverBase(content::WebContents* web_contents) 668 explicit InputMethodObserverBase(content::WebContents* web_contents)
593 : success_(false), 669 : success_(false),
594 test_observer_(content::TestInputMethodObserver::Create(web_contents)) { 670 test_observer_(content::TestInputMethodObserver::Create(web_contents)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 EXPECT_FALSE(send_and_check_show_ime()); 760 EXPECT_FALSE(send_and_check_show_ime());
685 761
686 // Set |TextInputState.show_ime_if_needed|. Expect IME. 762 // Set |TextInputState.show_ime_if_needed|. Expect IME.
687 sender.SetShowImeIfNeeded(true); 763 sender.SetShowImeIfNeeded(true);
688 EXPECT_TRUE(send_and_check_show_ime()); 764 EXPECT_TRUE(send_and_check_show_ime());
689 765
690 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME. 766 // Set |TextInputState.type| to ui::TEXT_INPUT_TYPE_NONE. Expect no IME.
691 sender.SetType(ui::TEXT_INPUT_TYPE_NONE); 767 sender.SetType(ui::TEXT_INPUT_TYPE_NONE);
692 EXPECT_FALSE(send_and_check_show_ime()); 768 EXPECT_FALSE(send_and_check_show_ime());
693 } 769 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698