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

Side by Side Diff: chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc

Issue 2571583008: Support tracking focused element for OOPIFs. (Closed)
Patch Set: Do not call ScrollFocusedEditableNodeIntoRect for OOPIFs. Created 4 years 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/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/common/form_field_data.h" 22 #include "content/public/common/form_field_data.h"
23 #include "content/public/test/browser_test_utils.h" 23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/content_browser_test_utils.h" 24 #include "content/public/test/content_browser_test_utils.h"
25 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "content/public/test/text_input_test_utils.h" 26 #include "content/public/test/text_input_test_utils.h"
27 #include "net/dns/mock_host_resolver.h" 27 #include "net/dns/mock_host_resolver.h"
28 #include "net/test/embedded_test_server/embedded_test_server.h" 28 #include "net/test/embedded_test_server/embedded_test_server.h"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data"); 356 embedded_test_server()->ServeFilesFromSourceDirectory("content/test/data");
357 357
358 ASSERT_TRUE(embedded_test_server()->Start()); 358 ASSERT_TRUE(embedded_test_server()->Start());
359 } 359 }
360 360
361 protected: 361 protected:
362 content::WebContents* active_contents() { 362 content::WebContents* active_contents() {
363 return browser()->tab_strip_model()->GetActiveWebContents(); 363 return browser()->tab_strip_model()->GetActiveWebContents();
364 } 364 }
365 365
366 content::RenderViewHost* render_view_host() {
367 return active_contents()->GetRenderViewHost();
368 }
369
366 // static 370 // static
367 // Adds an <input> field to a given frame by executing javascript code. 371 // Adds an <input> field to a given frame by executing javascript code.
368 // The input can be added as the first element or the last element of 372 // The input can be added as the first element or the last element of
369 // |document.body|. The text range defined by |selection_range| will be 373 // |document.body|. The text range defined by |selection_range| will be
370 // marked. 374 // marked.
371 static void AddInputFieldToFrame(content::RenderFrameHost* rfh, 375 static void AddInputFieldToFrame(content::RenderFrameHost* rfh,
372 const std::string& type, 376 const std::string& type,
373 const std::string& value, 377 const std::string& value,
374 bool append_as_first_child) { 378 bool append_as_first_child) {
375 std::string script = base::StringPrintf( 379 std::string script = base::StringPrintf(
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 content::RenderFrameHost* frame = frames[i / 2]; 865 content::RenderFrameHost* frame = frames[i / 2];
862 FocusFormField(frame, values[i]); 866 FocusFormField(frame, values[i]);
863 FormFieldDataVerifier verifier(values[i], placeholders[i]); 867 FormFieldDataVerifier verifier(values[i], placeholders[i]);
864 content::FormFieldDataCallback callback = 868 content::FormFieldDataCallback callback =
865 base::Bind(&FormFieldDataVerifier::Verify, base::Unretained(&verifier)); 869 base::Bind(&FormFieldDataVerifier::Verify, base::Unretained(&verifier));
866 frame->RequestFocusedFormFieldData(callback); 870 frame->RequestFocusedFormFieldData(callback);
867 verifier.Wait(); 871 verifier.Wait();
868 } 872 }
869 } 873 }
870 874
875 // This test makes sure browser correctly tracks focused editable element inside
876 // each RenderFrameHost.
877 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
878 TrackingFocusedElementForAllFrames) {
879 CreateIframePage("a(a, b(a))");
880 std::vector<content::RenderFrameHost*> frames{
881 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
882 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
883 for (size_t i = 0; i < frames.size(); ++i)
884 AddInputFieldToFrame(frames[i], "text", "some text", true);
885
886 // Focus the <input> in |frame| and return if RenderFrameHost thinks there is
887 // a focused editable element in it.
888 auto focus_input_and_return_editable_element_state =
889 [](content::RenderFrameHost* frame) {
890 EXPECT_TRUE(
891 ExecuteScript(frame, "document.querySelector('input').focus();"));
892 return content::DoesFrameHaveFocusedEditableElement(frame);
893 };
894
895 // When focusing an <input> we should receive an update.
896 for (auto* frame : frames)
897 EXPECT_TRUE(focus_input_and_return_editable_element_state(frame));
898
899 // Blur the <input> in |frame| and return if RenderFrameHost thinks there is a
900 // focused editable element in it.
901 auto blur_input_and_return_editable_element_state =
902 [](content::RenderFrameHost* frame) {
903 EXPECT_TRUE(
904 ExecuteScript(frame, "document.querySelector('input').blur();"));
905 return content::DoesFrameHaveFocusedEditableElement(frame);
906 };
907
908 // Similarly, we should receive updates when losing focus.
909 for (auto* frame : frames)
910 EXPECT_FALSE(blur_input_and_return_editable_element_state(frame));
911 }
912
913 // This test tracks page level focused editable element tracking using
914 // RenderViewHost. In a page with multiple frames, a frame is selected and
915 // focused. Then the <input> inside frame is both focused and blurred and and
916 // in both cases the test verifies that RendeViewHost is aware whether or not a
917 // focused editable element exists on the page.
918 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
919 TrackPageFocusEditableElement) {
920 CreateIframePage("a(a, b(a))");
921 std::vector<content::RenderFrameHost*> frames{
922 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
923 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
924 for (size_t i = 0; i < frames.size(); ++i)
925 AddInputFieldToFrame(frames[i], "text", "some text", true);
926
927 auto focus_frame = [](content::RenderFrameHost* frame) {
928 EXPECT_TRUE(ExecuteScript(frame, "window.focus();"));
929 };
930
931 auto set_input_focus = [](content::RenderFrameHost* frame, bool focus) {
932 EXPECT_TRUE(ExecuteScript(
933 frame, base::StringPrintf("document.querySelector('input').%s();",
934 (focus ? "focus" : "blur"))));
935 };
936
937 for (auto* frame : frames) {
938 focus_frame(frame);
939 // Focus the <input>.
940 set_input_focus(frame, true);
941 EXPECT_TRUE(render_view_host()->IsFocusedElementEditable());
942 // No blur <input>.
943 set_input_focus(frame, false);
944 EXPECT_FALSE(render_view_host()->IsFocusedElementEditable());
945 }
946 }
947
948 // TODO(ekaramad): Could this become a unit test instead?
949 // This test focuses <input> elements on the page and verifies that
950 // RenderViewHost knows about the focused editable element. Then it asks the
951 // RenderViewHost to clear focused element and verifies that there is no longer
952 // a focused editable element on the page.
953 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputManagerTest,
954 ClearFocusedElementOnPage) {
955 CreateIframePage("a(a, b(a))");
956 std::vector<content::RenderFrameHost*> frames{
957 GetFrame(IndexVector{}), GetFrame(IndexVector{0}),
958 GetFrame(IndexVector{1}), GetFrame(IndexVector{1, 0})};
959 for (size_t i = 0; i < frames.size(); ++i)
960 AddInputFieldToFrame(frames[i], "text", "some text", true);
961
962 auto focus_frame_and_input = [](content::RenderFrameHost* frame) {
963 EXPECT_TRUE(ExecuteScript(frame,
964 "window.focus();"
965 "document.querySelector('input').focus();"));
966 };
967
968 for (auto* frame : frames) {
969 focus_frame_and_input(frame);
970 EXPECT_TRUE(render_view_host()->IsFocusedElementEditable());
971 render_view_host()->ClearFocusedElement();
972 EXPECT_FALSE(render_view_host()->IsFocusedElementEditable());
973 }
974 }
975
871 // TODO(ekaramad): The following tests are specifically written for Aura and are 976 // TODO(ekaramad): The following tests are specifically written for Aura and are
872 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus 977 // based on InputMethodObserver. Write similar tests for Mac/Android/Mus
873 // (crbug.com/602723). 978 // (crbug.com/602723).
874 #if defined(USE_AURA) 979 #if defined(USE_AURA)
875 // ----------------------------------------------------------------------------- 980 // -----------------------------------------------------------------------------
876 // Input Method Observer Tests 981 // Input Method Observer Tests
877 // 982 //
878 // The following tests will make use of the InputMethodObserver to verify that 983 // The following tests will make use of the InputMethodObserver to verify that
879 // OOPIF pages interact properly with the InputMethod through the tab's view. 984 // OOPIF pages interact properly with the InputMethod through the tab's view.
880 985
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 1347
1243 // Closing this WebContents while we still hold on to our TestBrowserClient. 1348 // Closing this WebContents while we still hold on to our TestBrowserClient.
1244 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt( 1349 EXPECT_TRUE(browser()->tab_strip_model()->CloseWebContentsAt(
1245 1, TabStripModel::CLOSE_USER_GESTURE)); 1350 1, TabStripModel::CLOSE_USER_GESTURE));
1246 1351
1247 // For the cleanup of the original WebContents in tab index 0. 1352 // For the cleanup of the original WebContents in tab index 0.
1248 content::SetBrowserClientForTesting(old_browser_client); 1353 content::SetBrowserClientForTesting(old_browser_client);
1249 } 1354 }
1250 #endif // defined(MAC_OSX) 1355 #endif // defined(MAC_OSX)
1251 #endif // !defined(OS_ANDROID) 1356 #endif // !defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698