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

Side by Side Diff: chrome/browser/site_per_process_interactive_browsertest.cc

Issue 2544223002: Fix the position of context menu for BrowserPlugins inside OOPIF (Closed)
Patch Set: Fix compile issue + Observing navigation start as opposed to end 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
« no previous file with comments | « no previous file | content/browser/browser_plugin/browser_plugin_guest.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 "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 "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
7 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h" 9 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/interactive_test_utils.h" 13 #include "chrome/test/base/interactive_test_utils.h"
13 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "components/guest_view/browser/guest_view_manager_delegate.h"
16 #include "components/guest_view/browser/test_guest_view_manager.h"
17 #include "content/public/browser/navigation_handle.h"
14 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/browser/render_widget_host.h"
15 #include "content/public/browser/render_widget_host_view.h" 20 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
17 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
18 #include "content/public/test/content_browser_test_utils.h" 23 #include "content/public/test/content_browser_test_utils.h"
19 #include "content/public/test/test_navigation_observer.h" 24 #include "content/public/test/test_navigation_observer.h"
20 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "extensions/browser/api/extensions_api_client.h"
27 #include "extensions/common/constants.h"
21 #include "net/dns/mock_host_resolver.h" 28 #include "net/dns/mock_host_resolver.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h" 29 #include "net/test/embedded_test_server/embedded_test_server.h"
23 #include "ui/display/display.h" 30 #include "ui/display/display.h"
24 #include "ui/display/screen.h" 31 #include "ui/display/screen.h"
25 #include "url/gurl.h" 32 #include "url/gurl.h"
26 33
27 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { 34 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest {
28 public: 35 public:
29 SitePerProcessInteractiveBrowserTest() {} 36 SitePerProcessInteractiveBrowserTest() {}
30 ~SitePerProcessInteractiveBrowserTest() override {} 37 ~SitePerProcessInteractiveBrowserTest() override {}
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 "document.pointerLockElement)", 771 "document.pointerLockElement)",
765 &mouse_locked)); 772 &mouse_locked));
766 EXPECT_TRUE(mouse_locked); 773 EXPECT_TRUE(mouse_locked);
767 EXPECT_TRUE(main_frame->GetView()->IsMouseLocked()); 774 EXPECT_TRUE(main_frame->GetView()->IsMouseLocked());
768 775
769 EXPECT_TRUE(ExecuteScript(main_frame, 776 EXPECT_TRUE(ExecuteScript(main_frame,
770 "document.querySelector('iframe').parentNode." 777 "document.querySelector('iframe').parentNode."
771 "removeChild(document.querySelector('iframe'))")); 778 "removeChild(document.querySelector('iframe'))"));
772 EXPECT_FALSE(main_frame->GetView()->IsMouseLocked()); 779 EXPECT_FALSE(main_frame->GetView()->IsMouseLocked());
773 } 780 }
781
782 // Base test class for interactive tests which load and test PDF files.
783 class SitePerProcessInteractivePDFTest
784 : public SitePerProcessInteractiveBrowserTest {
785 public:
786 SitePerProcessInteractivePDFTest() : test_guest_view_manager_(nullptr) {}
787 ~SitePerProcessInteractivePDFTest() override {}
788
789 void SetUpOnMainThread() override {
790 SitePerProcessInteractiveBrowserTest::SetUpOnMainThread();
791 guest_view::GuestViewManager::set_factory_for_testing(&factory_);
792 test_guest_view_manager_ = static_cast<guest_view::TestGuestViewManager*>(
793 guest_view::GuestViewManager::CreateWithDelegate(
794 browser()->profile(),
795 extensions::ExtensionsAPIClient::Get()
796 ->CreateGuestViewManagerDelegate(browser()->profile())));
797 }
798
799 protected:
800 guest_view::TestGuestViewManager* test_guest_view_manager() const {
801 return test_guest_view_manager_;
802 }
803
804 private:
805 guest_view::TestGuestViewManagerFactory factory_;
806 guest_view::TestGuestViewManager* test_guest_view_manager_;
807
808 DISALLOW_COPY_AND_ASSIGN(SitePerProcessInteractivePDFTest);
809 };
810
811 // This class observers a WebContents for a navigation to an extension scheme to
Charlie Reis 2016/12/13 19:20:49 nit: observes
EhsanK 2016/12/13 20:32:00 Done.
812 // start.
813 class NavigationToExtensionSchemeObserver
814 : public content::WebContentsObserver {
815 public:
816 explicit NavigationToExtensionSchemeObserver(content::WebContents* contents)
817 : content::WebContentsObserver(contents),
818 extension_loaded_(contents->GetLastCommittedURL().SchemeIs(
819 extensions::kExtensionScheme)) {}
820
821 void Wait() {
822 if (extension_loaded_)
823 return;
824 message_loop_runner_ = new content::MessageLoopRunner();
825 message_loop_runner_->Run();
826 }
827
828 private:
829 void DidStartNavigation(content::NavigationHandle* handle) override {
EhsanK 2016/12/13 01:36:27 DidEndNavigation will cause test failures on win_c
Charlie Reis 2016/12/13 19:20:49 I assume you mean DidFinishNavigation? Anyway, th
EhsanK 2016/12/13 20:32:00 Yes.
Charlie Reis 2016/12/15 23:07:19 I'm not thrilled with using navigation start as th
830 if (!handle->GetURL().SchemeIs(extensions::kExtensionScheme))
831 return;
832 extension_loaded_ = true;
833 message_loop_runner_->Quit();
834 }
835
836 bool extension_loaded_;
837 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
838
839 DISALLOW_COPY_AND_ASSIGN(NavigationToExtensionSchemeObserver);
840 };
841
842 // This test loads a PDF inside an OOPIF and then verifies that context menu
843 // shows up at the correct position.
844 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractivePDFTest,
845 ContextMenuPositionForEmbeddedPDFInCrossOriginFrame) {
846 // Navigate to a page with an <iframe>.
847 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html"));
848 ui_test_utils::NavigateToURL(browser(), main_url);
849
850 // Initially, no guests are created.
851 EXPECT_EQ(0U, test_guest_view_manager()->num_guests_created());
852
853 // Navigate subframe to a cross-site page with an embedded PDF.
854 content::WebContents* active_web_contents =
855 browser()->tab_strip_model()->GetActiveWebContents();
856 GURL frame_url =
857 embedded_test_server()->GetURL("b.com", "/page_with_embedded_pdf.html");
858
859 // Ensure the page finishes loading without crashing.
860 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url));
861
862 // Wait until the guest contents for PDF is created.
863 content::WebContents* guest_contents =
864 test_guest_view_manager()->WaitForSingleGuestCreated();
865
866 // Observe navigations in guest to find out when navigation to the (PDF)
867 // extension starts. It will be used as an indicator that BrowserPluing
Charlie Reis 2016/12/13 19:20:49 nit: BrowserPlugin
EhsanK 2016/12/13 20:32:00 Done.
868 // has attached.
869 NavigationToExtensionSchemeObserver navigation_observer(guest_contents);
870
871 // Change the position of the <iframe> inside the page.
872 EXPECT_TRUE(ExecuteScript(active_web_contents,
873 "document.querySelector('iframe').style ="
874 " 'margin-left: 100px; margin-top: 100px;';"));
875
876 // Send a right click to the embedder frame and observe the context menu.
877 auto send_right_mouse_event = [](content::RenderWidgetHost* host, int x,
878 int y, blink::WebInputEvent::Type type) {
879 blink::WebMouseEvent event;
880 event.x = x;
881 event.y = y;
882 event.button = blink::WebMouseEvent::Button::Right;
883 event.type = type;
884 host->ForwardMouseEvent(event);
885 };
886
887 // Before sending the mouse clicks, make sure the extension navigation is
888 // complete. This means the BrowserPlugin is attached and the
Charlie Reis 2016/12/13 19:20:49 But it's not complete, given how the observer is w
EhsanK 2016/12/13 20:32:00 Sorry. 'complete' is incorrect. And we are probabl
Charlie Reis 2016/12/15 23:07:19 I would be worried about that leading to fragile o
EhsanK 2017/01/25 18:48:50 Coming back to this CL I am finding myself agreein
889 // BrowserPluginGuest has updated window rects for the guest.
890 navigation_observer.Wait();
891
892 content::RenderWidgetHostView* child_view =
893 ChildFrameAt(active_web_contents->GetMainFrame(), 0)->GetView();
894
895 ContextMenuWaiter menu_waiter(content::NotificationService::AllSources());
896 send_right_mouse_event(child_view->GetRenderWidgetHost(), 10, 20,
897 blink::WebInputEvent::MouseDown);
898 send_right_mouse_event(child_view->GetRenderWidgetHost(), 10, 20,
899 blink::WebInputEvent::MouseUp);
900 menu_waiter.WaitForMenuOpenAndClose();
901
902 gfx::Point point_in_root_window =
903 child_view->TransformPointToRootCoordSpace(gfx::Point(10, 20));
904
905 EXPECT_EQ(point_in_root_window.x(), menu_waiter.params().x);
906 EXPECT_EQ(point_in_root_window.y(), menu_waiter.params().y);
907 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/browser_plugin/browser_plugin_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698