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

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