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

Side by Side Diff: chrome/browser/pdf/pdf_extension_test.cc

Issue 2149153003: Links in PDF should be opened in new background tabs when ctrl + left clicked. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Links in PDF should be opened in new background tabs when ctrl + left clicked. Created 4 years, 5 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/browser/resources/pdf/navigator.js » ('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 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 " if (event.data == 'flush')" 224 " if (event.data == 'flush')"
225 " window.domAutomationController.send(false);" 225 " window.domAutomationController.send(false);"
226 " if (event.data.type == 'getSelectedTextReply')" 226 " if (event.data.type == 'getSelectedTextReply')"
227 " window.domAutomationController.send(true);" 227 " window.domAutomationController.send(true);"
228 "});" 228 "});"
229 "document.getElementsByTagName('embed')[0].postMessage(" 229 "document.getElementsByTagName('embed')[0].postMessage("
230 " {type: 'getSelectedText'});", 230 " {type: 'getSelectedText'});",
231 &success)); 231 &success));
232 ASSERT_EQ(expect_success, success); 232 ASSERT_EQ(expect_success, success);
233 } 233 }
234
235 void ConvertPageCoordToScreenCoord(content::WebContents* contents,
236 const gfx::Point& page_coord,
237 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
238 ASSERT_TRUE(contents);
239 ASSERT_TRUE(content::ExecuteScript(contents,
240 "var visiblePage = viewer.viewport.getMostVisiblePage();"
241 "var visiblePageDimensions ="
242 " viewer.viewport.getPageScreenRect(visiblePage);"
243 "var viewportPosition = viewer.viewport.position;"
244 "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;"
245 "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;"
246 "var linkScreenPositionX ="
247 " Math.floor(" + std::to_string(page_coord.x()) + " +"
248 " screenOffsetX);"
249 "var linkScreenPositionY ="
250 " Math.floor(" + std::to_string(page_coord.y()) + " +"
251 " screenOffsetY);"));
252
253 int x;
254 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
255 contents,
256 "window.domAutomationController.send(linkScreenPositionX);",
257 &x));
258
259 int y;
260 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
261 contents,
262 "window.domAutomationController.send(linkScreenPositionY);",
263 &y));
264
265 screen_coord.SetPoint(x, y);
266 }
267
234 }; 268 };
235 269
236 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { 270 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
237 #if defined(GOOGLE_CHROME_BUILD) 271 #if defined(GOOGLE_CHROME_BUILD)
238 // Load private PDFs. 272 // Load private PDFs.
239 LoadAllPdfsTest("pdf_private", GetParam()); 273 LoadAllPdfsTest("pdf_private", GetParam());
240 #endif 274 #endif
241 // Load public PDFs. 275 // Load public PDFs.
242 LoadAllPdfsTest("pdf", GetParam()); 276 LoadAllPdfsTest("pdf", GetParam());
243 } 277 }
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 " staticText '3'\n" 615 " staticText '3'\n"
582 " inlineTextBox '3'\n"; 616 " inlineTextBox '3'\n";
583 617
584 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ 618 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ
585 // in order to print a more readable message if the strings differ. 619 // in order to print a more readable message if the strings differ.
586 ASSERT_TRUE(expected_ax_tree == ax_tree_dump) 620 ASSERT_TRUE(expected_ax_tree == ax_tree_dump)
587 << "Expected:\n" << expected_ax_tree 621 << "Expected:\n" << expected_ax_tree
588 << "\n\nActual:\n" << ax_tree_dump; 622 << "\n\nActual:\n" << ax_tree_dump;
589 } 623 }
590 624
625 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) {
626 host_resolver()->AddRule("www.example.com", "127.0.0.1");
627 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
628 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
629 ASSERT_TRUE(guest_contents);
630
631 // The link position of the test-link.pdf in page coordinates is (110, 110).
632 // Convert the link position from page coordinates to screen coordinates.
633 gfx::Point link_position;
634 ConvertPageCoordToScreenCoord(guest_contents, gfx::Point(110, 110),
635 link_position);
636
637 content::WebContents* web_contents =
638 browser()->tab_strip_model()->GetActiveWebContents();
639
640 content::WindowedNotificationObserver observer(
641 chrome::NOTIFICATION_TAB_ADDED,
642 content::NotificationService::AllSources());
643 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ControlKey,
644 blink::WebMouseEvent::ButtonLeft, link_position);
645 observer.Wait();
646
647 int tab_count = browser()->tab_strip_model()->count();
648 ASSERT_EQ(2, tab_count);
649
650 content::WebContents* active_web_contents =
651 browser()->tab_strip_model()->GetActiveWebContents();
652 ASSERT_EQ(web_contents, active_web_contents);
653
654 content::WebContents* new_web_contents =
655 browser()->tab_strip_model()->GetWebContentsAt(1);
656 ASSERT_TRUE(new_web_contents);
657 ASSERT_NE(web_contents, new_web_contents);
658
659 const GURL& url = new_web_contents->GetURL();
660 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
661 }
662
591 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { 663 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) {
592 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 664 host_resolver()->AddRule("www.example.com", "127.0.0.1");
593 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); 665 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
594 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 666 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
595 ASSERT_TRUE(guest_contents); 667 ASSERT_TRUE(guest_contents);
596 668
597 // The link position of the test-link.pdf in page coordinates is (110, 110). 669 // The link position of the test-link.pdf in page coordinates is (110, 110).
598 // Convert the link position from page coordinates to screen coordinates. 670 // Convert the link position from page coordinates to screen coordinates.
599 ASSERT_TRUE(content::ExecuteScript(guest_contents, 671 gfx::Point link_position;
600 "var visiblePage = viewer.viewport.getMostVisiblePage();" 672 ConvertPageCoordToScreenCoord(guest_contents, gfx::Point(110, 110),
601 "var visiblePageDimensions =" 673 link_position);
602 " viewer.viewport.getPageScreenRect(visiblePage);"
603 "var viewportPosition = viewer.viewport.position;"
604 "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;"
605 "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;"
606 "var linkScreenPositionX = Math.floor(110 + screenOffsetX);"
607 "var linkScreenPositionY = Math.floor(110 + screenOffsetY);"));
608 674
609 int x;
610 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
611 guest_contents,
612 "window.domAutomationController.send(linkScreenPositionX);",
613 &x));
614
615 int y;
616 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
617 guest_contents,
618 "window.domAutomationController.send(linkScreenPositionY);",
619 &y));
620
621 gfx::Point point(x, y);
622 content::WebContents* web_contents = 675 content::WebContents* web_contents =
623 browser()->tab_strip_model()->GetActiveWebContents(); 676 browser()->tab_strip_model()->GetActiveWebContents();
624 677
625 content::WindowedNotificationObserver observer( 678 content::WindowedNotificationObserver observer(
626 chrome::NOTIFICATION_TAB_ADDED, 679 chrome::NOTIFICATION_TAB_ADDED,
627 content::NotificationService::AllSources()); 680 content::NotificationService::AllSources());
628 content::SimulateMouseClickAt(web_contents, 0, 681 content::SimulateMouseClickAt(web_contents, 0,
629 blink::WebMouseEvent::ButtonMiddle, point); 682 blink::WebMouseEvent::ButtonMiddle, link_position);
630 observer.Wait(); 683 observer.Wait();
631 684
632 int tab_count = browser()->tab_strip_model()->count(); 685 int tab_count = browser()->tab_strip_model()->count();
633 ASSERT_EQ(2, tab_count); 686 ASSERT_EQ(2, tab_count);
634 687
635 // TODO(jaepark): Middle mouse clicking on a link should not change 688 content::WebContents* active_web_contents =
636 // the focus of the tab. See http://crbug.com/628054. 689 browser()->tab_strip_model()->GetActiveWebContents();
690 ASSERT_EQ(web_contents, active_web_contents);
691
637 content::WebContents* new_web_contents = 692 content::WebContents* new_web_contents =
638 browser()->tab_strip_model()->GetActiveWebContents(); 693 browser()->tab_strip_model()->GetWebContentsAt(1);
694 ASSERT_TRUE(new_web_contents);
639 ASSERT_NE(web_contents, new_web_contents); 695 ASSERT_NE(web_contents, new_web_contents);
640 696
641 const GURL& url = new_web_contents->GetURL(); 697 const GURL& url = new_web_contents->GetURL();
642 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); 698 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
643 } 699 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/navigator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698