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

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 gfx::Point* point) {
237 ASSERT_TRUE(contents);
238 ASSERT_TRUE(content::ExecuteScript(contents,
239 "var visiblePage = viewer.viewport.getMostVisiblePage();"
240 "var visiblePageDimensions ="
241 " viewer.viewport.getPageScreenRect(visiblePage);"
242 "var viewportPosition = viewer.viewport.position;"
243 "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;"
244 "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;"
245 "var linkScreenPositionX ="
246 " Math.floor(" + std::to_string(point->x()) + " + screenOffsetX);"
Lei Zhang 2016/07/15 00:51:28 https://chromium-cpp.appspot.com/ says we can't qu
jaepark 2016/07/15 01:01:18 Done.
247 "var linkScreenPositionY ="
248 " Math.floor(" + std::to_string(point->y()) + " + screenOffsetY);"));
249
250 int x;
251 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
252 contents,
253 "window.domAutomationController.send(linkScreenPositionX);",
254 &x));
255
256 int y;
257 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
258 contents,
259 "window.domAutomationController.send(linkScreenPositionY);",
260 &y));
261
262 point->SetPoint(x, y);
263 }
264
234 }; 265 };
235 266
236 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { 267 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
237 #if defined(GOOGLE_CHROME_BUILD) 268 #if defined(GOOGLE_CHROME_BUILD)
238 // Load private PDFs. 269 // Load private PDFs.
239 LoadAllPdfsTest("pdf_private", GetParam()); 270 LoadAllPdfsTest("pdf_private", GetParam());
240 #endif 271 #endif
241 // Load public PDFs. 272 // Load public PDFs.
242 LoadAllPdfsTest("pdf", GetParam()); 273 LoadAllPdfsTest("pdf", GetParam());
243 } 274 }
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 " staticText '3'\n" 612 " staticText '3'\n"
582 " inlineTextBox '3'\n"; 613 " inlineTextBox '3'\n";
583 614
584 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ 615 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ
585 // in order to print a more readable message if the strings differ. 616 // in order to print a more readable message if the strings differ.
586 ASSERT_TRUE(expected_ax_tree == ax_tree_dump) 617 ASSERT_TRUE(expected_ax_tree == ax_tree_dump)
587 << "Expected:\n" << expected_ax_tree 618 << "Expected:\n" << expected_ax_tree
588 << "\n\nActual:\n" << ax_tree_dump; 619 << "\n\nActual:\n" << ax_tree_dump;
589 } 620 }
590 621
622 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) {
623 host_resolver()->AddRule("www.example.com", "127.0.0.1");
624 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
625 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
626 ASSERT_TRUE(guest_contents);
627
628 // The link position of the test-link.pdf in page coordinates is (110, 110).
629 // Convert the link position from page coordinates to screen coordinates.
630 gfx::Point link_position(110, 110);
631 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
632
633 content::WebContents* web_contents =
634 browser()->tab_strip_model()->GetActiveWebContents();
635
636 content::WindowedNotificationObserver observer(
637 chrome::NOTIFICATION_TAB_ADDED,
638 content::NotificationService::AllSources());
639 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ControlKey,
640 blink::WebMouseEvent::ButtonLeft, link_position);
641 observer.Wait();
642
643 int tab_count = browser()->tab_strip_model()->count();
644 ASSERT_EQ(2, tab_count);
645
646 content::WebContents* active_web_contents =
647 browser()->tab_strip_model()->GetActiveWebContents();
648 ASSERT_EQ(web_contents, active_web_contents);
649
650 content::WebContents* new_web_contents =
651 browser()->tab_strip_model()->GetWebContentsAt(1);
652 ASSERT_TRUE(new_web_contents);
653 ASSERT_NE(web_contents, new_web_contents);
654
655 const GURL& url = new_web_contents->GetURL();
656 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
657 }
658
591 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { 659 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) {
592 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 660 host_resolver()->AddRule("www.example.com", "127.0.0.1");
593 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); 661 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf"));
594 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); 662 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
595 ASSERT_TRUE(guest_contents); 663 ASSERT_TRUE(guest_contents);
596 664
597 // The link position of the test-link.pdf in page coordinates is (110, 110). 665 // 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. 666 // Convert the link position from page coordinates to screen coordinates.
599 ASSERT_TRUE(content::ExecuteScript(guest_contents, 667 gfx::Point link_position(110, 110);
600 "var visiblePage = viewer.viewport.getMostVisiblePage();" 668 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
601 "var visiblePageDimensions ="
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 669
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 = 670 content::WebContents* web_contents =
623 browser()->tab_strip_model()->GetActiveWebContents(); 671 browser()->tab_strip_model()->GetActiveWebContents();
624 672
625 content::WindowedNotificationObserver observer( 673 content::WindowedNotificationObserver observer(
626 chrome::NOTIFICATION_TAB_ADDED, 674 chrome::NOTIFICATION_TAB_ADDED,
627 content::NotificationService::AllSources()); 675 content::NotificationService::AllSources());
628 content::SimulateMouseClickAt(web_contents, 0, 676 content::SimulateMouseClickAt(web_contents, 0,
629 blink::WebMouseEvent::ButtonMiddle, point); 677 blink::WebMouseEvent::ButtonMiddle, link_position);
630 observer.Wait(); 678 observer.Wait();
631 679
632 int tab_count = browser()->tab_strip_model()->count(); 680 int tab_count = browser()->tab_strip_model()->count();
633 ASSERT_EQ(2, tab_count); 681 ASSERT_EQ(2, tab_count);
634 682
635 // TODO(jaepark): Middle mouse clicking on a link should not change 683 content::WebContents* active_web_contents =
636 // the focus of the tab. See http://crbug.com/628054. 684 browser()->tab_strip_model()->GetActiveWebContents();
685 ASSERT_EQ(web_contents, active_web_contents);
686
637 content::WebContents* new_web_contents = 687 content::WebContents* new_web_contents =
638 browser()->tab_strip_model()->GetActiveWebContents(); 688 browser()->tab_strip_model()->GetWebContentsAt(1);
689 ASSERT_TRUE(new_web_contents);
639 ASSERT_NE(web_contents, new_web_contents); 690 ASSERT_NE(web_contents, new_web_contents);
640 691
641 const GURL& url = new_web_contents->GetURL(); 692 const GURL& url = new_web_contents->GetURL();
642 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); 693 ASSERT_EQ(std::string("http://www.example.com/"), url.spec());
643 } 694 }
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