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

Unified Diff: chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc

Issue 2623483003: Support tracking focused node element for OOPIFs. (Closed)
Patch Set: Added the missing forward declaration Created 3 years, 11 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
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bb73b4fe9207709e5c618f3918288c9d45948e4e..8cd77bf2fc02d59d91a87e440f16e606cfab12c1 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
@@ -12,10 +12,10 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
-#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
@@ -331,6 +331,10 @@ class SitePerProcessTextInputManagerTest : public InProcessBrowserTest {
return browser()->tab_strip_model()->GetActiveWebContents();
}
+ content::RenderViewHost* render_view_host() {
+ return active_contents()->GetRenderViewHost();
+ }
+
// static
// Adds an <input> field to a given frame by executing javascript code.
// The input can be added as the first element or the last element of
@@ -749,6 +753,107 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
}
}
+// This test makes sure browser correctly tracks focused editable element inside
+// each RenderFrameHost.
+IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
+ TrackingFocusedElementForAllFrames) {
+ CreateIframePage("a(a, b(a))");
+ std::vector<content::RenderFrameHost*> frames{
+ GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
+ GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
+ for (size_t i = 0; i < frames.size(); ++i)
+ AddInputFieldToFrame(frames[i], "text", "some text", true);
+
+ // Focus the <input> in |frame| and return if RenderFrameHost thinks there is
+ // a focused editable element in it.
+ auto focus_input_and_return_editable_element_state =
+ [](content::RenderFrameHost* frame) {
+ EXPECT_TRUE(
+ ExecuteScript(frame, "document.querySelector('input').focus();"));
+ return content::DoesFrameHaveFocusedEditableElement(frame);
+ };
+
+ // When focusing an <input> we should receive an update.
+ for (auto* frame : frames)
+ EXPECT_TRUE(focus_input_and_return_editable_element_state(frame));
+
+ // Blur the <input> in |frame| and return if RenderFrameHost thinks there is a
+ // focused editable element in it.
+ auto blur_input_and_return_editable_element_state =
+ [](content::RenderFrameHost* frame) {
+ EXPECT_TRUE(
+ ExecuteScript(frame, "document.querySelector('input').blur();"));
+ return content::DoesFrameHaveFocusedEditableElement(frame);
+ };
+
+ // Similarly, we should receive updates when losing focus.
+ for (auto* frame : frames)
+ EXPECT_FALSE(blur_input_and_return_editable_element_state(frame));
+}
+
+// This test tracks page level focused editable element tracking using
+// RenderViewHost. In a page with multiple frames, a frame is selected and
+// focused. Then the <input> inside frame is both focused and blurred and and
+// in both cases the test verifies that RendeViewHost is aware whether or not a
+// focused editable element exists on the page.
+IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
+ TrackPageFocusEditableElement) {
+ CreateIframePage("a(a, b(a))");
+ std::vector<content::RenderFrameHost*> frames{
+ GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
+ GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
+ for (size_t i = 0; i < frames.size(); ++i)
+ AddInputFieldToFrame(frames[i], "text", "some text", true);
+
+ auto focus_frame = [](content::RenderFrameHost* frame) {
+ EXPECT_TRUE(ExecuteScript(frame, "window.focus();"));
+ };
+
+ auto set_input_focus = [](content::RenderFrameHost* frame, bool focus) {
+ EXPECT_TRUE(ExecuteScript(
+ frame, base::StringPrintf("document.querySelector('input').%s();",
+ (focus ? "focus" : "blur"))));
+ };
+
+ for (auto* frame : frames) {
+ focus_frame(frame);
+ // Focus the <input>.
+ set_input_focus(frame, true);
+ EXPECT_TRUE(render_view_host()->IsFocusedElementEditable());
+ // No blur <input>.
+ set_input_focus(frame, false);
+ EXPECT_FALSE(render_view_host()->IsFocusedElementEditable());
+ }
+}
+
+// TODO(ekaramad): Could this become a unit test instead?
+// This test focuses <input> elements on the page and verifies that
+// RenderViewHost knows about the focused editable element. Then it asks the
+// RenderViewHost to clear focused element and verifies that there is no longer
+// a focused editable element on the page.
+IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
+ ClearFocusedElementOnPage) {
+ CreateIframePage("a(a, b(a))");
+ std::vector<content::RenderFrameHost*> frames{
+ GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
+ GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
+ for (size_t i = 0; i < frames.size(); ++i)
+ AddInputFieldToFrame(frames[i], "text", "some text", true);
+
+ auto focus_frame_and_input = [](content::RenderFrameHost* frame) {
+ EXPECT_TRUE(ExecuteScript(frame,
+ "window.focus();"
+ "document.querySelector('input').focus();"));
+ };
+
+ for (auto* frame : frames) {
+ focus_frame_and_input(frame);
+ EXPECT_TRUE(render_view_host()->IsFocusedElementEditable());
+ render_view_host()->ClearFocusedElement();
+ EXPECT_FALSE(render_view_host()->IsFocusedElementEditable());
+ }
+}
+
// 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).
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698