| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.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/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 17 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
| 17 #include "components/guest_view/browser/test_guest_view_manager.h" | 18 #include "components/guest_view/browser/test_guest_view_manager.h" |
| 18 #include "content/public/browser/interstitial_page.h" | 19 #include "content/public/browser/interstitial_page.h" |
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "content/public/browser/render_widget_host.h" |
| 25 #include "content/public/browser/render_widget_host_view.h" |
| 23 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
| 25 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 26 #include "content/public/test/content_browser_test_utils.h" | 29 #include "content/public/test/content_browser_test_utils.h" |
| 27 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
| 28 #include "extensions/browser/api/extensions_api_client.h" | 31 #include "extensions/browser/api/extensions_api_client.h" |
| 29 #include "net/dns/mock_host_resolver.h" | 32 #include "net/dns/mock_host_resolver.h" |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" | 33 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 34 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 31 #include "ui/display/display_switches.h" | 35 #include "ui/display/display_switches.h" |
| 32 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 33 | 37 |
| 34 class ChromeSitePerProcessTest : public InProcessBrowserTest { | 38 class ChromeSitePerProcessTest : public InProcessBrowserTest { |
| 35 public: | 39 public: |
| 36 ChromeSitePerProcessTest() {} | 40 ChromeSitePerProcessTest() {} |
| 37 ~ChromeSitePerProcessTest() override {} | 41 ~ChromeSitePerProcessTest() override {} |
| 38 | 42 |
| 39 void SetUpCommandLine(base::CommandLine* command_line) override { | 43 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 40 content::IsolateAllSitesForTesting(command_line); | 44 content::IsolateAllSitesForTesting(command_line); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 318 } |
| 315 | 319 |
| 316 private: | 320 private: |
| 317 guest_view::TestGuestViewManagerFactory factory_; | 321 guest_view::TestGuestViewManagerFactory factory_; |
| 318 guest_view::TestGuestViewManager* test_guest_view_manager_; | 322 guest_view::TestGuestViewManager* test_guest_view_manager_; |
| 319 | 323 |
| 320 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessPDFTest); | 324 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessPDFTest); |
| 321 }; | 325 }; |
| 322 | 326 |
| 323 // TODO(ekaramad): This test is flaky on Windows 7. Enable it when the issue is | 327 // TODO(ekaramad): This test is flaky on Windows 7. Enable it when the issue is |
| 324 // fixed ((https://crbug.com/666379). | 328 // fixed (https://crbug.com/666379). |
| 325 #if defined(OS_WIN) | 329 #if defined(OS_WIN) |
| 326 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ | 330 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ |
| 327 DISABLED_EmbeddedPDFInsideCrossOriginFrame | 331 DISABLED_EmbeddedPDFInsideCrossOriginFrame |
| 328 #else | 332 #else |
| 329 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ | 333 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ |
| 330 EmbeddedPDFInsideCrossOriginFrame | 334 EmbeddedPDFInsideCrossOriginFrame |
| 331 #endif | 335 #endif |
| 332 // This test verifies that when navigating an OOPIF to a page with <embed>-ed | 336 // This test verifies that when navigating an OOPIF to a page with <embed>-ed |
| 333 // PDF, the guest is properly created, and by removing the embedder frame, the | 337 // PDF, the guest is properly created, and by removing the embedder frame, the |
| 334 // guest is properly destroyed (https://crbug.com/649856). | 338 // guest is properly destroyed (https://crbug.com/649856). |
| (...skipping 20 matching lines...) Expand all Loading... |
| 355 test_guest_view_manager()->WaitForSingleGuestCreated(); | 359 test_guest_view_manager()->WaitForSingleGuestCreated(); |
| 356 | 360 |
| 357 // Now detach the frame and observe that the guest is destroyed. | 361 // Now detach the frame and observe that the guest is destroyed. |
| 358 content::WebContentsDestroyedWatcher observer(guest_web_contents); | 362 content::WebContentsDestroyedWatcher observer(guest_web_contents); |
| 359 EXPECT_TRUE(ExecuteScript( | 363 EXPECT_TRUE(ExecuteScript( |
| 360 active_web_contents, | 364 active_web_contents, |
| 361 "document.body.removeChild(document.querySelector('iframe'));")); | 365 "document.body.removeChild(document.querySelector('iframe'));")); |
| 362 observer.Wait(); | 366 observer.Wait(); |
| 363 EXPECT_EQ(0U, test_guest_view_manager()->GetNumGuestsActive()); | 367 EXPECT_EQ(0U, test_guest_view_manager()->GetNumGuestsActive()); |
| 364 } | 368 } |
| 369 |
| 370 // This test loads a PDF inside an OOPIF and then verifies that context menu |
| 371 // shows up at the correct position. |
| 372 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessPDFTest, |
| 373 ContextMenuPositionForEmbeddedPDFInCrossOriginFrame) { |
| 374 // Navigate to a page with an <iframe>. |
| 375 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); |
| 376 ui_test_utils::NavigateToURL(browser(), main_url); |
| 377 |
| 378 // Initially, no guests are created. |
| 379 EXPECT_EQ(0U, test_guest_view_manager()->num_guests_created()); |
| 380 |
| 381 // Navigate subframe to a cross-site page with an embedded PDF. |
| 382 content::WebContents* active_web_contents = |
| 383 browser()->tab_strip_model()->GetActiveWebContents(); |
| 384 GURL frame_url = |
| 385 embedded_test_server()->GetURL("b.com", "/page_with_embedded_pdf.html"); |
| 386 |
| 387 // Ensure the page finishes loading without crashing. |
| 388 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); |
| 389 |
| 390 // Wait until the guest for PDF is created. |
| 391 EXPECT_TRUE(test_guest_view_manager()->WaitForSingleGuestCreated()); |
| 392 |
| 393 // Change the position of the <iframe> inside the page. |
| 394 EXPECT_TRUE(ExecuteScript(active_web_contents, |
| 395 "document.querySelector('iframe').style =" |
| 396 " 'margin-left: 100px; margin-top: 100px;';")); |
| 397 |
| 398 // Send a right click to the embedder frame and observe the context menu. |
| 399 auto send_right_mouse_event = [](content::RenderWidgetHost* host, int x, |
| 400 int y, blink::WebInputEvent::Type type) { |
| 401 blink::WebMouseEvent event; |
| 402 event.x = x; |
| 403 event.y = y; |
| 404 event.button = blink::WebMouseEvent::Button::Right; |
| 405 event.type = type; |
| 406 host->ForwardMouseEvent(event); |
| 407 }; |
| 408 |
| 409 content::RenderWidgetHostView* child_view = |
| 410 ChildFrameAt(active_web_contents->GetMainFrame(), 0)->GetView(); |
| 411 |
| 412 ContextMenuWaiter menu_waiter(content::NotificationService::AllSources()); |
| 413 send_right_mouse_event(child_view->GetRenderWidgetHost(), 10, 20, |
| 414 blink::WebInputEvent::MouseDown); |
| 415 send_right_mouse_event(child_view->GetRenderWidgetHost(), 10, 20, |
| 416 blink::WebInputEvent::MouseUp); |
| 417 menu_waiter.WaitForMenuOpenAndClose(); |
| 418 |
| 419 gfx::Point point_in_root_window = |
| 420 child_view->TransformPointToRootCoordSpace(gfx::Point(10, 20)); |
| 421 |
| 422 EXPECT_EQ(point_in_root_window.x(), menu_waiter.params().x); |
| 423 EXPECT_EQ(point_in_root_window.y(), menu_waiter.params().y); |
| 424 } |
| OLD | NEW |