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

Side by Side 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 unified diff | 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 »
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/chrome_content_browser_client.h" 9 #include "chrome/browser/chrome_content_browser_client.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/interactive_test_utils.h" 13 #include "chrome/test/base/interactive_test_utils.h"
14 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/browser_message_filter.h"
16 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
17 #include "content/public/browser/render_frame_host.h" 16 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/render_widget_host_view.h" 19 #include "content/public/browser/render_widget_host_view.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/content_client.h" 21 #include "content/public/common/content_client.h"
22 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
23 #include "content/public/test/content_browser_test_utils.h" 23 #include "content/public/test/content_browser_test_utils.h"
24 #include "content/public/test/test_utils.h" 24 #include "content/public/test/test_utils.h"
25 #include "content/public/test/text_input_test_utils.h" 25 #include "content/public/test/text_input_test_utils.h"
26 #include "net/dns/mock_host_resolver.h" 26 #include "net/dns/mock_host_resolver.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
28 #include "ui/base/ime/composition_underline.h" 28 #include "ui/base/ime/composition_underline.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); 324 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
325 325
326 ASSERT_TRUE(embedded_test_server()->Start()); 326 ASSERT_TRUE(embedded_test_server()->Start());
327 } 327 }
328 328
329 protected: 329 protected:
330 content::WebContents* active_contents() { 330 content::WebContents* active_contents() {
331 return browser()->tab_strip_model()->GetActiveWebContents(); 331 return browser()->tab_strip_model()->GetActiveWebContents();
332 } 332 }
333 333
334 content::RenderViewHost* render_view_host() {
335 return active_contents()->GetRenderViewHost();
336 }
337
334 // static 338 // static
335 // Adds an <input> field to a given frame by executing javascript code. 339 // Adds an <input> field to a given frame by executing javascript code.
336 // The input can be added as the first element or the last element of 340 // The input can be added as the first element or the last element of
337 // |document.body|. The text range defined by |selection_range| will be 341 // |document.body|. The text range defined by |selection_range| will be
338 // marked. 342 // marked.
339 static void AddInputFieldToFrame(content::RenderFrameHost* rfh, 343 static void AddInputFieldToFrame(content::RenderFrameHost* rfh,
340 const std::string& type, 344 const std::string& type,
341 const std::string& value, 345 const std::string& value,
342 bool append_as_first_child) { 346 bool append_as_first_child) {
343 std::string script = base::StringPrintf( 347 std::string script = base::StringPrintf(
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 for (size_t i = 0; i < record_count - 1U; ++i) { 746 for (size_t i = 0; i < record_count - 1U; ++i) {
743 const content::RenderWidgetHostView* current = 747 const content::RenderWidgetHostView* current =
744 recorder.active_views()->at(i); 748 recorder.active_views()->at(i);
745 const content::RenderWidgetHostView* next = 749 const content::RenderWidgetHostView* next =
746 recorder.active_views()->at(i + 1U); 750 recorder.active_views()->at(i + 1U);
747 EXPECT_TRUE((current != nullptr && next == nullptr) || 751 EXPECT_TRUE((current != nullptr && next == nullptr) ||
748 (current == nullptr && next != nullptr)); 752 (current == nullptr && next != nullptr));
749 } 753 }
750 } 754 }
751 755
756 // This test makes sure browser correctly tracks focused editable element inside
757 // each RenderFrameHost.
758 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
759 TrackingFocusedElementForAllFrames) {
760 CreateIframePage("a(a, b(a))");
761 std::vector<content::RenderFrameHost*> frames{
762 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
763 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
764 for (size_t i = 0; i < frames.size(); ++i)
765 AddInputFieldToFrame(frames[i], "text", "some text", true);
766
767 // Focus the <input> in |frame| and return if RenderFrameHost thinks there is
768 // a focused editable element in it.
769 auto focus_input_and_return_editable_element_state =
770 [](content::RenderFrameHost* frame) {
771 EXPECT_TRUE(
772 ExecuteScript(frame, "document.querySelector('input').focus();"));
773 return content::DoesFrameHaveFocusedEditableElement(frame);
774 };
775
776 // When focusing an <input> we should receive an update.
777 for (auto* frame : frames)
778 EXPECT_TRUE(focus_input_and_return_editable_element_state(frame));
779
780 // Blur the <input> in |frame| and return if RenderFrameHost thinks there is a
781 // focused editable element in it.
782 auto blur_input_and_return_editable_element_state =
783 [](content::RenderFrameHost* frame) {
784 EXPECT_TRUE(
785 ExecuteScript(frame, "document.querySelector('input').blur();"));
786 return content::DoesFrameHaveFocusedEditableElement(frame);
787 };
788
789 // Similarly, we should receive updates when losing focus.
790 for (auto* frame : frames)
791 EXPECT_FALSE(blur_input_and_return_editable_element_state(frame));
792 }
793
794 // This test tracks page level focused editable element tracking using
795 // RenderViewHost. In a page with multiple frames, a frame is selected and
796 // focused. Then the <input> inside frame is both focused and blurred and and
797 // in both cases the test verifies that RendeViewHost is aware whether or not a
798 // focused editable element exists on the page.
799 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
800 TrackPageFocusEditableElement) {
801 CreateIframePage("a(a, b(a))");
802 std::vector<content::RenderFrameHost*> frames{
803 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
804 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
805 for (size_t i = 0; i < frames.size(); ++i)
806 AddInputFieldToFrame(frames[i], "text", "some text", true);
807
808 auto focus_frame = [](content::RenderFrameHost* frame) {
809 EXPECT_TRUE(ExecuteScript(frame, "window.focus();"));
810 };
811
812 auto set_input_focus = [](content::RenderFrameHost* frame, bool focus) {
813 EXPECT_TRUE(ExecuteScript(
814 frame, base::StringPrintf("document.querySelector('input').%s();",
815 (focus ? "focus" : "blur"))));
816 };
817
818 for (auto* frame : frames) {
819 focus_frame(frame);
820 // Focus the <input>.
821 set_input_focus(frame, true);
822 EXPECT_TRUE(render_view_host()->IsFocusedElementEditable());
823 // No blur <input>.
824 set_input_focus(frame, false);
825 EXPECT_FALSE(render_view_host()->IsFocusedElementEditable());
826 }
827 }
828
829 // TODO(ekaramad): Could this become a unit test instead?
830 // This test focuses <input> elements on the page and verifies that
831 // RenderViewHost knows about the focused editable element. Then it asks the
832 // RenderViewHost to clear focused element and verifies that there is no longer
833 // a focused editable element on the page.
834 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
835 ClearFocusedElementOnPage) {
836 CreateIframePage("a(a, b(a))");
837 std::vector<content::RenderFrameHost*> frames{
838 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
839 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
840 for (size_t i = 0; i < frames.size(); ++i)
841 AddInputFieldToFrame(frames[i], "text", "some text", true);
842
843 auto focus_frame_and_input = [](content::RenderFrameHost* frame) {
844 EXPECT_TRUE(ExecuteScript(frame,
845 "window.focus();"
846 "document.querySelector('input').focus();"));
847 };
848
849 for (auto* frame : frames) {
850 focus_frame_and_input(frame);
851 EXPECT_TRUE(render_view_host()->IsFocusedElementEditable());
852 render_view_host()->ClearFocusedElement();
853 EXPECT_FALSE(render_view_host()->IsFocusedElementEditable());
854 }
855 }
856
752 // TODO(ekaramad): The following tests are specifically written for Aura and are 857 // TODO(ekaramad): The following tests are specifically written for Aura and are
753 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 858 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
754 // (crbug.com/602723). 859 // (crbug.com/602723).
755 860
756 #if defined(USE_AURA) 861 #if defined(USE_AURA)
757 // ----------------------------------------------------------------------------- 862 // -----------------------------------------------------------------------------
758 // Input Method Observer Tests 863 // Input Method Observer Tests
759 // 864 //
760 // The following tests will make use of the InputMethodObserver to verify that 865 // The following tests will make use of the InputMethodObserver to verify that
761 // OOPIF pages interact properly with the InputMethod through the tab's view. 866 // OOPIF pages interact properly with the InputMethod through the tab's view.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 // Test ends here. The rest is cleanup. 1228 // Test ends here. The rest is cleanup.
1124 1229
1125 // Closing this WebContents while we still hold on to our TestBrowserClient. 1230 // Closing this WebContents while we still hold on to our TestBrowserClient.
1126 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( 1231 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1127 1, TabStripModel::CLOSE_USER_GESTURE)); 1232 1, TabStripModel::CLOSE_USER_GESTURE));
1128 1233
1129 // For the cleanup of the original WebContents in tab index 0. 1234 // For the cleanup of the original WebContents in tab index 0.
1130 content::SetBrowserClientForTesting(old_browser_client); 1235 content::SetBrowserClientForTesting(old_browser_client);
1131 } 1236 }
1132 #endif 1237 #endif
OLDNEW
« 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