Chromium Code Reviews| Index: chrome/browser/pdf/pdf_extension_test.cc |
| diff --git a/chrome/browser/pdf/pdf_extension_test.cc b/chrome/browser/pdf/pdf_extension_test.cc |
| index 03e31b51bde9ee73a924cd5b5c8d0e1ad9a9c00f..be1131980535b4c4172835679e38253e567c166d 100644 |
| --- a/chrome/browser/pdf/pdf_extension_test.cc |
| +++ b/chrome/browser/pdf/pdf_extension_test.cc |
| @@ -231,6 +231,40 @@ class PDFExtensionTest : public ExtensionApiTest, |
| &success)); |
| ASSERT_EQ(expect_success, success); |
| } |
| + |
| + void ConvertPageCoordToScreenCoord(content::WebContents* contents, |
| + const gfx::Point& page_coord, |
| + gfx::Point& screen_coord) { |
|
Lei Zhang
2016/07/15 00:34:22
Can't pass by non-const ref. Pass in a pointer ins
jaepark
2016/07/15 00:46:06
Done. I used a single pointer as an in-out paramet
|
| + ASSERT_TRUE(contents); |
| + ASSERT_TRUE(content::ExecuteScript(contents, |
| + "var visiblePage = viewer.viewport.getMostVisiblePage();" |
| + "var visiblePageDimensions =" |
| + " viewer.viewport.getPageScreenRect(visiblePage);" |
| + "var viewportPosition = viewer.viewport.position;" |
| + "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;" |
| + "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;" |
| + "var linkScreenPositionX =" |
| + " Math.floor(" + std::to_string(page_coord.x()) + " +" |
| + " screenOffsetX);" |
| + "var linkScreenPositionY =" |
| + " Math.floor(" + std::to_string(page_coord.y()) + " +" |
| + " screenOffsetY);")); |
| + |
| + int x; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| + contents, |
| + "window.domAutomationController.send(linkScreenPositionX);", |
| + &x)); |
| + |
| + int y; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| + contents, |
| + "window.domAutomationController.send(linkScreenPositionY);", |
| + &y)); |
| + |
| + screen_coord.SetPoint(x, y); |
| + } |
| + |
| }; |
| IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { |
| @@ -588,6 +622,44 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PdfAccessibility) { |
| << "\n\nActual:\n" << ax_tree_dump; |
| } |
| +IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) { |
| + host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| + GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); |
| + content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| + ASSERT_TRUE(guest_contents); |
| + |
| + // The link position of the test-link.pdf in page coordinates is (110, 110). |
| + // Convert the link position from page coordinates to screen coordinates. |
| + gfx::Point link_position; |
| + ConvertPageCoordToScreenCoord(guest_contents, gfx::Point(110, 110), |
| + link_position); |
| + |
| + content::WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + |
| + content::WindowedNotificationObserver observer( |
| + chrome::NOTIFICATION_TAB_ADDED, |
| + content::NotificationService::AllSources()); |
| + content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ControlKey, |
| + blink::WebMouseEvent::ButtonLeft, link_position); |
| + observer.Wait(); |
| + |
| + int tab_count = browser()->tab_strip_model()->count(); |
| + ASSERT_EQ(2, tab_count); |
| + |
| + content::WebContents* active_web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + ASSERT_EQ(web_contents, active_web_contents); |
| + |
| + content::WebContents* new_web_contents = |
| + browser()->tab_strip_model()->GetWebContentsAt(1); |
| + ASSERT_TRUE(new_web_contents); |
| + ASSERT_NE(web_contents, new_web_contents); |
| + |
| + const GURL& url = new_web_contents->GetURL(); |
| + ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { |
| host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); |
| @@ -596,29 +668,10 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { |
| // The link position of the test-link.pdf in page coordinates is (110, 110). |
| // Convert the link position from page coordinates to screen coordinates. |
| - ASSERT_TRUE(content::ExecuteScript(guest_contents, |
| - "var visiblePage = viewer.viewport.getMostVisiblePage();" |
| - "var visiblePageDimensions =" |
| - " viewer.viewport.getPageScreenRect(visiblePage);" |
| - "var viewportPosition = viewer.viewport.position;" |
| - "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;" |
| - "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;" |
| - "var linkScreenPositionX = Math.floor(110 + screenOffsetX);" |
| - "var linkScreenPositionY = Math.floor(110 + screenOffsetY);")); |
| - |
| - int x; |
| - ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| - guest_contents, |
| - "window.domAutomationController.send(linkScreenPositionX);", |
| - &x)); |
| - |
| - int y; |
| - ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| - guest_contents, |
| - "window.domAutomationController.send(linkScreenPositionY);", |
| - &y)); |
| - |
| - gfx::Point point(x, y); |
| + gfx::Point link_position; |
| + ConvertPageCoordToScreenCoord(guest_contents, gfx::Point(110, 110), |
| + link_position); |
| + |
| content::WebContents* web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| @@ -626,16 +679,19 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { |
| chrome::NOTIFICATION_TAB_ADDED, |
| content::NotificationService::AllSources()); |
| content::SimulateMouseClickAt(web_contents, 0, |
| - blink::WebMouseEvent::ButtonMiddle, point); |
| + blink::WebMouseEvent::ButtonMiddle, link_position); |
| observer.Wait(); |
| int tab_count = browser()->tab_strip_model()->count(); |
| ASSERT_EQ(2, tab_count); |
| - // TODO(jaepark): Middle mouse clicking on a link should not change |
| - // the focus of the tab. See http://crbug.com/628054. |
| - content::WebContents* new_web_contents = |
| + content::WebContents* active_web_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| + ASSERT_EQ(web_contents, active_web_contents); |
| + |
| + content::WebContents* new_web_contents = |
| + browser()->tab_strip_model()->GetWebContentsAt(1); |
| + ASSERT_TRUE(new_web_contents); |
| ASSERT_NE(web_contents, new_web_contents); |
| const GURL& url = new_web_contents->GetURL(); |