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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc
diff --git a/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc b/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc
index 8cd594b17a96f4c99ca44d3d979198f62d27ef55..95257aa6b9602f22f1e38054e75593034674831e 100644
--- a/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc
+++ b/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc
@@ -265,6 +265,35 @@ class ViewTextSelectionObserver : public TextInputManagerObserverBase {
DISALLOW_COPY_AND_ASSIGN(ViewTextSelectionObserver);
};
+// This class monitors all the changes in TextInputState and keeps a record of
+// the active views. There is no waiting and the recording process is
+// continuous.
+class RecordActiveViewsObserver {
+ public:
+ explicit RecordActiveViewsObserver(content::WebContents* web_contents)
+ : tester_(new content::TextInputManagerTester(web_contents)) {
+ tester_->SetUpdateTextInputStateCalledCallback(base::Bind(
+ &RecordActiveViewsObserver::RecordActiveView, base::Unretained(this)));
+ }
+
+ const std::vector<const content::RenderWidgetHostView*>* active_views()
+ const {
+ return &active_views_;
+ }
+
+ private:
+ void RecordActiveView() {
+ if (!tester_->IsTextInputStateChanged())
+ return;
+ active_views_.push_back(tester_->GetActiveView());
+ }
+
+ std::unique_ptr<content::TextInputManagerTester> tester_;
+ std::vector<const content::RenderWidgetHostView*> active_views_;
+
+ DISALLOW_COPY_AND_ASSIGN(RecordActiveViewsObserver);
+};
+
} // namespace
// Main class for all TextInputState and IME related tests.
@@ -647,6 +676,53 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
send_tab_and_wait_for_selection_change(frames[i], input_text[i].size());
}
+// The following test verifies that when the active widget changes value, it is
+// always from nullptr to non-null or vice versa.
+IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
+ ResetTextInputStateOnActiveWidgetChange) {
+ CreateIframePage("a(b,c(a,b),d)");
+ std::vector<content::RenderFrameHost*> frames{
+ GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
+ GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0}),
+ GetFrame(IndexVector{1, 1}), GetFrame(IndexVector{2})};
+ std::vector<content::RenderWidgetHostView*> views;
+ for (auto frame : frames)
+ views.push_back(frame->GetView());
+ std::vector<std::string> values{"a", "ab", "ac", "aca", "acb", "acd"};
+ for (size_t i = 0; i < frames.size(); ++i)
+ AddInputFieldToFrame(frames[i], "text", values[i], true);
+
+ content::WebContents* web_contents = active_contents();
+
+ auto send_tab_and_wait_for_value =
+ [&web_contents](const std::string& expected_value) {
+ TextInputManagerValueObserver observer(web_contents, expected_value);
+ SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB,
+ ui::VKEY_TAB, false, false, false, false);
+ observer.Wait();
+ };
+
+ // Record all active view changes.
+ RecordActiveViewsObserver recorder(web_contents);
+ for (auto value : values)
+ send_tab_and_wait_for_value(value);
+
+ // We have covered a total of 6 views, so there should at least be 11 entries
+ // recorded (at least one null between two views).
+ size_t record_count = recorder.active_views()->size();
+ EXPECT_GT(record_count, 10U);
+
+ // Verify we do not have subsequent nullptr or non-nullptrs.
+ for (size_t i = 0; i < record_count - 1U; ++i) {
+ const content::RenderWidgetHostView* current =
+ recorder.active_views()->at(i);
+ const content::RenderWidgetHostView* next =
+ recorder.active_views()->at(i + 1U);
+ EXPECT_TRUE((current != nullptr && next == nullptr) ||
+ (current == nullptr && next != nullptr));
+ }
+}
+
// TODO(ekaramad): The following tests are specifically written for Aura and are
// based on InputMethodObserver. Write similar tests for Mac/Android/Mus
// (crbug.com/602723).

Powered by Google App Engine
This is Rietveld 408576698