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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc

Issue 1293963002: Fixing the Position of Context Menu for BrowserPlugin (<webview>) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Test Name Created 5 years, 3 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
OLDNEW
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
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 // Needed for the WebViewTest.ContextMenuPositionAfterCSSTransforms
291 gfx::Rect rect = rwh->GetView()->GetViewBounds();
292 mouse_event.globalX = x + rwh->GetView()->GetViewBounds().x();
lazyboy 2015/09/01 19:45:46 You want to use rect.x() and rect.y() here.
Ehsaan 2015/09/02 15:18:20 Done.
293 mouse_event.globalY = y + rwh->GetView()->GetViewBounds().y();
290 294
291 mouse_event.type = blink::WebInputEvent::MouseDown; 295 mouse_event.type = blink::WebInputEvent::MouseDown;
292 rwh->ForwardMouseEvent(mouse_event); 296 rwh->ForwardMouseEvent(mouse_event);
293 mouse_event.type = blink::WebInputEvent::MouseUp; 297 mouse_event.type = blink::WebInputEvent::MouseUp;
294 rwh->ForwardMouseEvent(mouse_event); 298 rwh->ForwardMouseEvent(mouse_event);
295 } 299 }
296 300
297 class PopupCreatedObserver { 301 class PopupCreatedObserver {
298 public: 302 public:
299 PopupCreatedObserver() 303 PopupCreatedObserver()
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 846
843 ContextMenuWaiter menu_observer(content::NotificationService::AllSources()); 847 ContextMenuWaiter menu_observer(content::NotificationService::AllSources());
844 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(), 848 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(),
845 blink::WebMouseEvent::ButtonRight, 10, 20); 849 blink::WebMouseEvent::ButtonRight, 10, 20);
846 // Wait until the context menu is opened and closed. 850 // Wait until the context menu is opened and closed.
847 menu_observer.WaitForMenuOpenAndClose(); 851 menu_observer.WaitForMenuOpenAndClose();
848 ASSERT_EQ(10, menu_observer.params().x); 852 ASSERT_EQ(10, menu_observer.params().x);
849 ASSERT_EQ(20, menu_observer.params().y); 853 ASSERT_EQ(20, menu_observer.params().y);
850 } 854 }
851 855
856 // Tests whether <webview> context menu sees <webview> local coordinates in its
857 // RenderViewContextMenu params, when it is subject to CSS transforms.
858 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
859 ContextMenuParamsAfterCSSTransforms) {
860 LoadAndLaunchPlatformApp("web_view/context_menus/coordinates_with_transforms",
861 "Launched");
862
863 if (embedder_web_contents_ == nullptr)
lazyboy 2015/09/01 19:45:47 nit: if (!embedder_web_contents_)
Ehsaan 2015/09/02 15:18:20 Done.
864 embedder_web_contents_ = GetFirstAppWindowWebContents();
865 EXPECT_TRUE(embedder_web_contents() != nullptr);
866
867 if (guest_web_contents_ == nullptr)
868 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated();
869 EXPECT_TRUE(guest_web_contents());
870
871 // We will send the input event to the embedder rather than the guest. This
872 // is a more realistic model of what happens in reality. We need to do this
873 // to make sure the MouseDown event is received at the
874 // RenderWidgetHostViewGuest for the embedder so that the
lazyboy 2015/09/01 19:45:47 embedder shouldn't have RWHVGuest, you mean just R
Ehsaan 2015/09/02 15:18:20 I mean, the View which takes BrowserPlugin's IPC f
875 // ChromeWebViewGuestDelegate is notified about the potential position of the
876 // context menu.
877 std::vector<std::string> transforms = {"rotate(20deg)", "scale(1.5, 2.0)",
878 "translate(20px, 30px)", "NONE"};
879 for (size_t index = 0; index < transforms.size(); ++index) {
880 std::string command =
881 base::StringPrintf("setTransform('%s')", transforms[index].c_str());
882 scoped_ptr<ExtensionTestMessageListener> transform_set_listener(
lazyboy 2015/09/01 19:45:47 scoped_ptr seems unnecessary here, you can just us
Ehsaan 2015/09/02 15:18:20 Done.
883 new ExtensionTestMessageListener("TRANSFORM_SET", false));
884 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents(), command));
885 ASSERT_TRUE(transform_set_listener->WaitUntilSatisfied());
886 gfx::Rect embedder_view_bounds =
887 embedder_web_contents()->GetRenderWidgetHostView()->GetViewBounds();
888 gfx::Rect guest_view_bounds =
889 guest_web_contents()->GetRenderWidgetHostView()->GetViewBounds();
890
891 int windowX = 150, windowY = 150;
lazyboy 2015/09/01 19:45:46 nit: window_x, window_y, better set it as point gf
Ehsaan 2015/09/02 15:18:20 Done.
892 ContextMenuWaiter menu_observer(content::NotificationService::AllSources());
893 SimulateRWHMouseClick(
894 embedder_web_contents()->GetRenderViewHost(),
895 blink::WebMouseEvent::ButtonRight,
896 /* Using window coordinates for the embedder */
897 windowX + guest_view_bounds.x() - embedder_view_bounds.x(),
898 windowY + guest_view_bounds.y() - embedder_view_bounds.y());
899
900 menu_observer.WaitForMenuOpenAndClose();
901 EXPECT_EQ(menu_observer.params().x, windowX);
902 EXPECT_EQ(menu_observer.params().y, windowY);
903 }
904 }
905
852 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) { 906 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) {
853 ASSERT_TRUE(RunPlatformAppTestWithArg( 907 ASSERT_TRUE(RunPlatformAppTestWithArg(
854 "platform_apps/web_view/common", "execute_code")) << message_; 908 "platform_apps/web_view/common", "execute_code")) << message_;
855 } 909 }
856 910
857 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) { 911 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) {
858 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER); 912 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER);
859 ASSERT_TRUE(guest_web_contents()); 913 ASSERT_TRUE(guest_web_contents());
860 PopupTestHelper(gfx::Point()); 914 PopupTestHelper(gfx::Point());
861 915
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 1205
1152 // Now verify that the selection text propagates properly to RWHV. 1206 // Now verify that the selection text propagates properly to RWHV.
1153 content::RenderWidgetHostView* guest_rwhv = 1207 content::RenderWidgetHostView* guest_rwhv =
1154 guest_web_contents()->GetRenderWidgetHostView(); 1208 guest_web_contents()->GetRenderWidgetHostView();
1155 ASSERT_TRUE(guest_rwhv); 1209 ASSERT_TRUE(guest_rwhv);
1156 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); 1210 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText());
1157 ASSERT_TRUE(selected_text.size() >= 10u); 1211 ASSERT_TRUE(selected_text.size() >= 10u);
1158 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); 1212 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
1159 } 1213 }
1160 #endif 1214 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698