Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
| 7 #include "base/test/scoped_feature_list.h" | 7 #include "base/test/scoped_feature_list.h" |
| 8 #include "base/time/time.h" | |
| 8 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 9 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 9 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" | 13 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/interactive_test_utils.h" | 16 #include "chrome/test/base/interactive_test_utils.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/autofill/core/browser/autofill_client.h" | 18 #include "components/autofill/core/browser/autofill_client.h" |
| 18 #include "components/autofill/core/browser/test_autofill_client.h" | 19 #include "components/autofill/core/browser/test_autofill_client.h" |
| 19 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 20 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
| 20 #include "components/guest_view/browser/test_guest_view_manager.h" | 21 #include "components/guest_view/browser/test_guest_view_manager.h" |
| 21 #include "components/security_state/core/security_state.h" | 22 #include "components/security_state/core/security_state.h" |
| 23 #include "content/public/browser/browser_thread.h" | |
| 22 #include "content/public/browser/focused_node_details.h" | 24 #include "content/public/browser/focused_node_details.h" |
| 23 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
| 24 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 26 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
| 27 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 29 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
| 30 #include "content/public/browser/render_widget_host.h" | 32 #include "content/public/browser/render_widget_host.h" |
| 31 #include "content/public/browser/render_widget_host_view.h" | 33 #include "content/public/browser/render_widget_host_view.h" |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 | 1063 |
| 1062 private: | 1064 private: |
| 1063 content::NotificationRegistrar registrar_; | 1065 content::NotificationRegistrar registrar_; |
| 1064 bool observed_; | 1066 bool observed_; |
| 1065 gfx::Point focused_node_bounds_in_screen_; | 1067 gfx::Point focused_node_bounds_in_screen_; |
| 1066 scoped_refptr<content::MessageLoopRunner> loop_runner_; | 1068 scoped_refptr<content::MessageLoopRunner> loop_runner_; |
| 1067 | 1069 |
| 1068 DISALLOW_COPY_AND_ASSIGN(FocusedEditableNodeChangedObserver); | 1070 DISALLOW_COPY_AND_ASSIGN(FocusedEditableNodeChangedObserver); |
| 1069 }; | 1071 }; |
| 1070 | 1072 |
| 1073 // Waits until transforming |sample_point| from |render_frame_host| coordinates | |
| 1074 // to its root frame's view's coordinates matches |transformed_point| within a | |
| 1075 // reasonable error margin less than or equal to |bound|. This method is used to | |
| 1076 // verify CSS changes on OOPIFs have been applied properly and the corresponding | |
| 1077 // compositor frame is updated as well. This way we can rest assured that the | |
| 1078 // future transformed and reported bounds for the elements inside | |
| 1079 // |render_frame_host| are correct. | |
| 1080 void WaitForFramePositionUpdated(content::RenderFrameHost* render_frame_host, | |
| 1081 const gfx::Point& sample_point, | |
| 1082 const gfx::Point& transformed_point, | |
| 1083 float bound) { | |
| 1084 const int64_t kCheckAgainDelay = 60U; | |
| 1085 while ((transformed_point - | |
| 1086 render_frame_host->GetView()->TransformPointToRootCoordSpace( | |
| 1087 sample_point)) | |
| 1088 .Length() > bound) { | |
| 1089 scoped_refptr<content::MessageLoopRunner> loop_runner_ = | |
|
alexmos
2017/03/28 18:54:25
content::MessageLoopRunner is marked as deprecated
EhsanK
2017/03/28 19:37:46
Sure. Thanks for pointing this out. Done.
| |
| 1090 new content::MessageLoopRunner(); | |
| 1091 content::BrowserThread::PostDelayedTask( | |
| 1092 content::BrowserThread::IO, FROM_HERE, loop_runner_->QuitClosure(), | |
| 1093 base::TimeDelta::FromMilliseconds(kCheckAgainDelay)); | |
|
alexmos
2017/03/28 18:54:25
nit: you can use TestTimeouts::tiny_timeout()
EhsanK
2017/03/28 19:37:46
Done.
| |
| 1094 loop_runner_->Run(); | |
| 1095 } | |
| 1096 } | |
| 1071 // This test verifies that displacements (margin, etc) in the position of an | 1097 // This test verifies that displacements (margin, etc) in the position of an |
| 1072 // OOPIF is considered when showing an AutofillClient warning pop-up for | 1098 // OOPIF is considered when showing an AutofillClient warning pop-up for |
| 1073 // unsecure web sites. | 1099 // unsecure web sites. |
| 1074 IN_PROC_BROWSER_TEST_F(SitePerProcessAutofillTest, | 1100 IN_PROC_BROWSER_TEST_F(SitePerProcessAutofillTest, |
| 1075 PasswordAutofillPopupPositionInsideOOPIF) { | 1101 PasswordAutofillPopupPositionInsideOOPIF) { |
| 1076 SetupMainTab(); | 1102 SetupMainTab(); |
| 1077 ASSERT_TRUE( | 1103 ASSERT_TRUE( |
| 1078 base::FeatureList::IsEnabled(security_state::kHttpFormWarningFeature)); | 1104 base::FeatureList::IsEnabled(security_state::kHttpFormWarningFeature)); |
| 1079 | 1105 |
| 1080 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); | 1106 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); |
| 1081 ui_test_utils::NavigateToURL(browser(), main_url); | 1107 ui_test_utils::NavigateToURL(browser(), main_url); |
| 1082 content::WebContents* active_web_contents = | 1108 content::WebContents* active_web_contents = |
| 1083 browser()->tab_strip_model()->GetActiveWebContents(); | 1109 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1084 | 1110 |
| 1085 // Add some displacement for <iframe>. | 1111 // Add some displacement for <iframe>. |
| 1086 ASSERT_TRUE(content::ExecuteScript( | 1112 ASSERT_TRUE(content::ExecuteScript( |
| 1087 active_web_contents, | 1113 active_web_contents, |
| 1088 base::StringPrintf("var iframe = document.querySelector('iframe');" | 1114 base::StringPrintf("var iframe = document.querySelector('iframe');" |
| 1089 "iframe.style.marginTop = '%dpx';" | 1115 "iframe.style.position = 'fixed';" |
| 1090 "iframe.style.marginLeft = '%dpx';", | 1116 "iframe.style.border = 'none';" |
| 1117 "iframe.style.top = '%dpx';" | |
| 1118 "iframe.style.left = '%dpx';", | |
|
alexmos
2017/03/28 18:54:24
I wonder if declaring the CSS statically before na
EhsanK
2017/03/28 19:37:46
It might stop flaking but we are not removing the
alexmos
2017/03/28 19:48:13
Acknowledged.
| |
| 1091 kIframeTopDisplacement, kIframeLeftDisplacement))); | 1119 kIframeTopDisplacement, kIframeLeftDisplacement))); |
| 1092 | 1120 |
| 1093 // Navigate the <iframe> to a simple page. | 1121 // Navigate the <iframe> to a simple page. |
| 1094 GURL frame_url = embedded_test_server()->GetURL("b.com", "/title1.html"); | 1122 GURL frame_url = embedded_test_server()->GetURL("b.com", "/title1.html"); |
| 1095 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); | 1123 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); |
| 1096 content::RenderFrameHost* child_frame = content::FrameMatchingPredicate( | 1124 content::RenderFrameHost* child_frame = content::FrameMatchingPredicate( |
| 1097 active_web_contents, base::Bind(&content::FrameIsChildOfMainFrame)); | 1125 active_web_contents, base::Bind(&content::FrameIsChildOfMainFrame)); |
| 1098 | 1126 |
| 1127 WaitForFramePositionUpdated( | |
| 1128 child_frame, gfx::Point(), | |
| 1129 gfx::Point(kIframeLeftDisplacement, kIframeTopDisplacement), 1.4143f); | |
| 1130 | |
| 1099 // We will need to listen to focus changes to find out about the container | 1131 // We will need to listen to focus changes to find out about the container |
| 1100 // bounds of any focused <input> elements on the page. | 1132 // bounds of any focused <input> elements on the page. |
| 1101 FocusedEditableNodeChangedObserver focus_observer; | 1133 FocusedEditableNodeChangedObserver focus_observer; |
| 1102 | 1134 |
| 1103 // Focus the child frame, add an <input> with type "password", and focus it. | 1135 // Focus the child frame, add an <input> with type "password", and focus it. |
| 1104 ASSERT_TRUE(ExecuteScript(child_frame, | 1136 ASSERT_TRUE(ExecuteScript(child_frame, |
| 1105 "window.focus();" | 1137 "window.focus();" |
| 1106 "var input = document.createElement('input');" | 1138 "var input = document.createElement('input');" |
| 1107 "input.type = 'password';" | 1139 "input.type = 'password';" |
| 1108 "document.body.appendChild(input);" | 1140 "document.body.appendChild(input);" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1130 | 1162 |
| 1131 // Ideally, the length of the error vector should be 0.0f. But due to | 1163 // Ideally, the length of the error vector should be 0.0f. But due to |
| 1132 // potential rounding errors, we assume a larger limit (which is slightly | 1164 // potential rounding errors, we assume a larger limit (which is slightly |
| 1133 // larger than square root of 2). | 1165 // larger than square root of 2). |
| 1134 EXPECT_LT(error.Length(), 1.4143f) | 1166 EXPECT_LT(error.Length(), 1.4143f) |
| 1135 << "Origin of bounds from focused node changed event is '" | 1167 << "Origin of bounds from focused node changed event is '" |
| 1136 << focus_observer.focused_node_bounds_in_screen().ToString() | 1168 << focus_observer.focused_node_bounds_in_screen().ToString() |
| 1137 << "' but AutofillClient is reporting '" << bounds_origin.ToString() | 1169 << "' but AutofillClient is reporting '" << bounds_origin.ToString() |
| 1138 << "'"; | 1170 << "'"; |
| 1139 } | 1171 } |
| OLD | NEW |