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

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

Issue 2695103003: Fix the position of context menu for BrowserPlugins inside OOPIF (Merge to M-57) (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | chrome/test/data/page_with_embedded_pdf.html » ('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 observes a WebContents for a navigation to an extension scheme to
812 // finish.
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 DidFinishNavigation(content::NavigationHandle* handle) override {
830 if (!handle->GetURL().SchemeIs(extensions::kExtensionScheme) ||
831 !handle->HasCommitted() || handle->IsErrorPage())
832 return;
833 extension_loaded_ = true;
834 message_loop_runner_->Quit();
835 }
836
837 bool extension_loaded_;
838 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
839
840 DISALLOW_COPY_AND_ASSIGN(NavigationToExtensionSchemeObserver);
841 };
842
843 // This test loads a PDF inside an OOPIF and then verifies that context menu
844 // shows up at the correct position.
845 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractivePDFTest,
846 ContextMenuPositionForEmbeddedPDFInCrossOriginFrame) {
847 // Navigate to a page with an <iframe>.
848 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html"));
849 ui_test_utils::NavigateToURL(browser(), main_url);
850
851 // Initially, no guests are created.
852 EXPECT_EQ(0U, test_guest_view_manager()->num_guests_created());
853
854 content::WebContents* active_web_contents =
855 browser()->tab_strip_model()->GetActiveWebContents();
856
857 // Change the position of the <iframe> inside the page.
858 EXPECT_TRUE(ExecuteScript(active_web_contents,
859 "document.querySelector('iframe').style ="
860 " 'margin-left: 100px; margin-top: 100px;';"));
861
862 // Navigate subframe to a cross-site page with an embedded PDF.
863 GURL frame_url =
864 embedded_test_server()->GetURL("b.com", "/page_with_embedded_pdf.html");
865
866 // Ensure the page finishes loading without crashing.
867 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url));
868
869 // Wait until the guest contents for PDF is created.
870 content::WebContents* guest_contents =
871 test_guest_view_manager()->WaitForSingleGuestCreated();
872
873 // Observe navigations in guest to find out when navigation to the (PDF)
874 // extension commits. It will be used as an indicator that BrowserPlugin
875 // has attached.
876 NavigationToExtensionSchemeObserver navigation_observer(guest_contents);
877
878 // Before sending the mouse clicks, we need to make sure the BrowserPlugin has
879 // attached, which happens before navigating the guest to the PDF extension.
880 // When attached, the window rects are updated and the context menu position
881 // can be properly calculated.
882 navigation_observer.Wait();
883
884 content::RenderWidgetHostView* child_view =
885 ChildFrameAt(active_web_contents->GetMainFrame(), 0)->GetView();
886
887 ContextMenuWaiter menu_waiter(content::NotificationService::AllSources());
888
889 // Declaring a lambda to send a right-button mouse event to the embedder
890 // frame.
891 auto send_right_mouse_event = [](content::RenderWidgetHost* host, int x,
892 int y, blink::WebInputEvent::Type type) {
893 blink::WebMouseEvent event;
894 event.x = x;
895 event.y = y;
896 event.button = blink::WebMouseEvent::Button::Right;
897 event.setType(type);
898 host->ForwardMouseEvent(event);
899 };
900
901 send_right_mouse_event(child_view->GetRenderWidgetHost(), 10, 20,
902 blink::WebInputEvent::MouseDown);
903 send_right_mouse_event(child_view->GetRenderWidgetHost(), 10, 20,
904 blink::WebInputEvent::MouseUp);
905 menu_waiter.WaitForMenuOpenAndClose();
906
907 gfx::Point point_in_root_window =
908 child_view->TransformPointToRootCoordSpace(gfx::Point(10, 20));
909
910 EXPECT_EQ(point_in_root_window.x(), menu_waiter.params().x);
911 EXPECT_EQ(point_in_root_window.y(), menu_waiter.params().y);
912 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/page_with_embedded_pdf.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698