OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/location.h" | 5 #include "base/location.h" |
6 #include "base/single_thread_task_runner.h" | 6 #include "base/single_thread_task_runner.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 280 |
281 void SimulateRWHMouseClick(content::RenderWidgetHost* rwh, | 281 void SimulateRWHMouseClick(content::RenderWidgetHost* rwh, |
282 blink::WebMouseEvent::Button button, | 282 blink::WebMouseEvent::Button button, |
283 int x, | 283 int x, |
284 int y) { | 284 int y) { |
285 blink::WebMouseEvent mouse_event; | 285 blink::WebMouseEvent mouse_event; |
286 mouse_event.button = button; | 286 mouse_event.button = button; |
287 mouse_event.x = mouse_event.windowX = x; | 287 mouse_event.x = mouse_event.windowX = x; |
288 mouse_event.y = mouse_event.windowY = y; | 288 mouse_event.y = mouse_event.windowY = y; |
289 mouse_event.modifiers = 0; | 289 mouse_event.modifiers = 0; |
290 | 290 // Needed for the WebViewTest.ContextMenuPositionAfterCSSTransforms |
| 291 gfx::Rect rect = rwh->GetView()->GetViewBounds(); |
| 292 mouse_event.globalX = x + rect.x(); |
| 293 mouse_event.globalY = y + rect.y(); |
291 mouse_event.type = blink::WebInputEvent::MouseDown; | 294 mouse_event.type = blink::WebInputEvent::MouseDown; |
292 rwh->ForwardMouseEvent(mouse_event); | 295 rwh->ForwardMouseEvent(mouse_event); |
293 mouse_event.type = blink::WebInputEvent::MouseUp; | 296 mouse_event.type = blink::WebInputEvent::MouseUp; |
294 rwh->ForwardMouseEvent(mouse_event); | 297 rwh->ForwardMouseEvent(mouse_event); |
295 } | 298 } |
296 | 299 |
297 class PopupCreatedObserver { | 300 class PopupCreatedObserver { |
298 public: | 301 public: |
299 PopupCreatedObserver() | 302 PopupCreatedObserver() |
300 : initial_widget_count_(0), | 303 : initial_widget_count_(0), |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 | 845 |
843 ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); | 846 ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); |
844 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(), | 847 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(), |
845 blink::WebMouseEvent::ButtonRight, 10, 20); | 848 blink::WebMouseEvent::ButtonRight, 10, 20); |
846 // Wait until the context menu is opened and closed. | 849 // Wait until the context menu is opened and closed. |
847 menu_observer.WaitForMenuOpenAndClose(); | 850 menu_observer.WaitForMenuOpenAndClose(); |
848 ASSERT_EQ(10, menu_observer.params().x); | 851 ASSERT_EQ(10, menu_observer.params().x); |
849 ASSERT_EQ(20, menu_observer.params().y); | 852 ASSERT_EQ(20, menu_observer.params().y); |
850 } | 853 } |
851 | 854 |
| 855 // Tests whether <webview> context menu sees <webview> local coordinates in its |
| 856 // RenderViewContextMenu params, when it is subject to CSS transforms. |
| 857 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, |
| 858 ContextMenuParamsAfterCSSTransforms) { |
| 859 LoadAndLaunchPlatformApp("web_view/context_menus/coordinates_with_transforms", |
| 860 "Launched"); |
| 861 |
| 862 if (!embedder_web_contents_) |
| 863 embedder_web_contents_ = GetFirstAppWindowWebContents(); |
| 864 EXPECT_TRUE(embedder_web_contents()); |
| 865 |
| 866 if (!guest_web_contents_) |
| 867 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated(); |
| 868 EXPECT_TRUE(guest_web_contents()); |
| 869 |
| 870 // We will send the input event to the embedder rather than the guest; which |
| 871 // is more realistic. We need to do this to make sure that the MouseDown event |
| 872 // is received forwarded by the BrowserPlugin to the RWHVG and eventually back |
| 873 // to the guest. The RWHVG will in turn notify the ChromeWVGDelegate of the |
| 874 // newly observed mouse down (potentially a context menu). |
| 875 const std::string transforms[] = {"rotate(20deg)", "scale(1.5, 2.0)", |
| 876 "translate(20px, 30px)", "NONE"}; |
| 877 for (size_t index = 0; index < 4; ++index) { |
| 878 std::string command = |
| 879 base::StringPrintf("setTransform('%s')", transforms[index].c_str()); |
| 880 ExtensionTestMessageListener transform_set_listener("TRANSFORM_SET", false); |
| 881 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents(), command)); |
| 882 ASSERT_TRUE(transform_set_listener.WaitUntilSatisfied()); |
| 883 |
| 884 gfx::Rect embedder_view_bounds = |
| 885 embedder_web_contents()->GetRenderWidgetHostView()->GetViewBounds(); |
| 886 gfx::Rect guest_view_bounds = |
| 887 guest_web_contents()->GetRenderWidgetHostView()->GetViewBounds(); |
| 888 ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); |
| 889 gfx::Point guest_window_point(150, 150); |
| 890 gfx::Point embedder_window_point = guest_window_point; |
| 891 embedder_window_point += guest_view_bounds.OffsetFromOrigin(); |
| 892 embedder_window_point -= embedder_view_bounds.OffsetFromOrigin(); |
| 893 SimulateRWHMouseClick(embedder_web_contents()->GetRenderViewHost(), |
| 894 blink::WebMouseEvent::ButtonRight, |
| 895 /* Using window coordinates for the embedder */ |
| 896 embedder_window_point.x(), embedder_window_point.y()); |
| 897 |
| 898 menu_observer.WaitForMenuOpenAndClose(); |
| 899 EXPECT_EQ(menu_observer.params().x, guest_window_point.x()); |
| 900 EXPECT_EQ(menu_observer.params().y, guest_window_point.y()); |
| 901 } |
| 902 } |
| 903 |
852 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) { | 904 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) { |
853 ASSERT_TRUE(RunPlatformAppTestWithArg( | 905 ASSERT_TRUE(RunPlatformAppTestWithArg( |
854 "platform_apps/web_view/common", "execute_code")) << message_; | 906 "platform_apps/web_view/common", "execute_code")) << message_; |
855 } | 907 } |
856 | 908 |
857 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) { | 909 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) { |
858 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER); | 910 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER); |
859 ASSERT_TRUE(guest_web_contents()); | 911 ASSERT_TRUE(guest_web_contents()); |
860 PopupTestHelper(gfx::Point()); | 912 PopupTestHelper(gfx::Point()); |
861 | 913 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 | 1209 |
1158 // Now verify that the selection text propagates properly to RWHV. | 1210 // Now verify that the selection text propagates properly to RWHV. |
1159 content::RenderWidgetHostView* guest_rwhv = | 1211 content::RenderWidgetHostView* guest_rwhv = |
1160 guest_web_contents()->GetRenderWidgetHostView(); | 1212 guest_web_contents()->GetRenderWidgetHostView(); |
1161 ASSERT_TRUE(guest_rwhv); | 1213 ASSERT_TRUE(guest_rwhv); |
1162 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); | 1214 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); |
1163 ASSERT_TRUE(selected_text.size() >= 10u); | 1215 ASSERT_TRUE(selected_text.size() >= 10u); |
1164 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); | 1216 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); |
1165 } | 1217 } |
1166 #endif | 1218 #endif |
OLD | NEW |