| 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 <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" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/hash.h" | 12 #include "base/hash.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/threading/platform_thread.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/extensions/component_loader.h" | 21 #include "chrome/browser/extensions/component_loader.h" |
| 21 #include "chrome/browser/extensions/extension_apitest.h" | 22 #include "chrome/browser/extensions/extension_apitest.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/pdf/pdf_extension_test_util.h" | 24 #include "chrome/browser/pdf/pdf_extension_test_util.h" |
| 24 #include "chrome/browser/pdf/pdf_extension_util.h" | |
| 25 #include "chrome/browser/plugins/plugin_prefs.h" | 25 #include "chrome/browser/plugins/plugin_prefs.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 29 #include "chrome/common/chrome_content_client.h" | 29 #include "chrome/common/chrome_content_client.h" |
| 30 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
| 31 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "components/pdf/browser/pdf_web_contents_helper.h" |
| 34 #include "components/pdf/browser/pdf_web_contents_helper_client.h" |
| 33 #include "components/zoom/page_zoom.h" | 35 #include "components/zoom/page_zoom.h" |
| 34 #include "components/zoom/test/zoom_test_utils.h" | 36 #include "components/zoom/test/zoom_test_utils.h" |
| 35 #include "components/zoom/zoom_controller.h" | 37 #include "components/zoom/zoom_controller.h" |
| 36 #include "content/public/browser/browser_accessibility_state.h" | 38 #include "content/public/browser/browser_accessibility_state.h" |
| 37 #include "content/public/browser/browser_plugin_guest_manager.h" | 39 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 38 #include "content/public/browser/download_item.h" | 40 #include "content/public/browser/download_item.h" |
| 39 #include "content/public/browser/download_manager.h" | 41 #include "content/public/browser/download_manager.h" |
| 40 #include "content/public/browser/notification_observer.h" | 42 #include "content/public/browser/notification_observer.h" |
| 41 #include "content/public/browser/notification_registrar.h" | 43 #include "content/public/browser/notification_registrar.h" |
| 42 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/browser/plugin_service.h" | 45 #include "content/public/browser/plugin_service.h" |
| 44 #include "content/public/browser/render_process_host.h" | 46 #include "content/public/browser/render_process_host.h" |
| 45 #include "content/public/browser/render_view_host.h" | 47 #include "content/public/browser/render_view_host.h" |
| 46 #include "content/public/browser/render_widget_host.h" | 48 #include "content/public/browser/render_widget_host.h" |
| 47 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 48 #include "content/public/test/browser_test_utils.h" | 50 #include "content/public/test/browser_test_utils.h" |
| 49 #include "extensions/browser/extension_registry.h" | 51 #include "extensions/browser/extension_registry.h" |
| 50 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 52 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| 51 #include "extensions/test/result_catcher.h" | 53 #include "extensions/test/result_catcher.h" |
| 52 #include "net/dns/mock_host_resolver.h" | 54 #include "net/dns/mock_host_resolver.h" |
| 53 #include "net/test/embedded_test_server/embedded_test_server.h" | 55 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 54 #include "ui/base/resource/resource_bundle.h" | 56 #include "ui/base/resource/resource_bundle.h" |
| 55 #include "url/gurl.h" | 57 #include "url/gurl.h" |
| 56 | 58 |
| 57 #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) | 59 #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) |
| 58 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 60 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 63 namespace { |
| 64 |
| 61 const int kNumberLoadTestParts = 10; | 65 const int kNumberLoadTestParts = 10; |
| 62 | 66 |
| 63 #if defined(OS_MACOSX) | 67 #if defined(OS_MACOSX) |
| 64 const int kDefaultKeyModifier = blink::WebInputEvent::MetaKey; | 68 const int kDefaultKeyModifier = blink::WebInputEvent::MetaKey; |
| 65 #else | 69 #else |
| 66 const int kDefaultKeyModifier = blink::WebInputEvent::ControlKey; | 70 const int kDefaultKeyModifier = blink::WebInputEvent::ControlKey; |
| 67 #endif | 71 #endif |
| 68 | 72 |
| 69 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ | 73 // Using ASSERT_TRUE deliberately instead of ASSERT_EQ or ASSERT_STREQ |
| 70 // in order to print a more readable message if the strings differ. | 74 // in order to print a more readable message if the strings differ. |
| 71 #define ASSERT_MULTILINE_STREQ(expected, actual) \ | 75 #define ASSERT_MULTILINE_STREQ(expected, actual) \ |
| 72 ASSERT_TRUE(expected == actual) \ | 76 ASSERT_TRUE(expected == actual) \ |
| 73 << "Expected:\n" << expected \ | 77 << "Expected:\n" << expected \ |
| 74 << "\n\nActual:\n" << actual | 78 << "\n\nActual:\n" << actual |
| 75 | 79 |
| 76 bool GetGuestCallback(content::WebContents** guest_out, | 80 bool GetGuestCallback(content::WebContents** guest_out, |
| 77 content::WebContents* guest) { | 81 content::WebContents* guest) { |
| 78 EXPECT_FALSE(*guest_out); | 82 EXPECT_FALSE(*guest_out); |
| 79 *guest_out = guest; | 83 *guest_out = guest; |
| 80 // Return false so that we iterate through all the guests and verify there is | 84 // Return false so that we iterate through all the guests and verify there is |
| 81 // only one. | 85 // only one. |
| 82 return false; | 86 return false; |
| 83 } | 87 } |
| 84 | 88 |
| 89 class TestPDFWebContentsHelperClient : public pdf::PDFWebContentsHelperClient { |
| 90 public: |
| 91 explicit TestPDFWebContentsHelperClient(content::WebContents* contents) |
| 92 : contents_(contents) {} |
| 93 ~TestPDFWebContentsHelperClient() override {} |
| 94 |
| 95 int save_url_count() const { return save_url_count_; } |
| 96 |
| 97 private: |
| 98 // PDFWebContentsHelperClient: |
| 99 void UpdateLocationBar(content::WebContents* contents) override {} |
| 100 void UpdateContentRestrictions(content::WebContents* contents, |
| 101 int content_restrictions) override {} |
| 102 void OnPDFHasUnsupportedFeature(content::WebContents* contents) override {} |
| 103 void OnSaveURL(content::WebContents* contents) override { |
| 104 EXPECT_EQ(contents_, contents); |
| 105 ++save_url_count_; |
| 106 } |
| 107 |
| 108 int save_url_count_ = 0; |
| 109 content::WebContents* const contents_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(TestPDFWebContentsHelperClient); |
| 112 }; |
| 113 |
| 114 } // namespace |
| 115 |
| 85 class PDFExtensionTest : public ExtensionApiTest, | 116 class PDFExtensionTest : public ExtensionApiTest, |
| 86 public testing::WithParamInterface<int> { | 117 public testing::WithParamInterface<int> { |
| 87 public: | 118 public: |
| 88 ~PDFExtensionTest() override {} | 119 ~PDFExtensionTest() override {} |
| 89 | 120 |
| 90 void SetUpCommandLine(base::CommandLine* command_line) override { | 121 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 91 content::IsolateAllSitesForTesting(command_line); | 122 content::IsolateAllSitesForTesting(command_line); |
| 92 } | 123 } |
| 93 | 124 |
| 94 void SetUpOnMainThread() override { | 125 void SetUpOnMainThread() override { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 " window.domAutomationController.send(false);" | 275 " window.domAutomationController.send(false);" |
| 245 " if (event.data.type == 'getSelectedTextReply')" | 276 " if (event.data.type == 'getSelectedTextReply')" |
| 246 " window.domAutomationController.send(true);" | 277 " window.domAutomationController.send(true);" |
| 247 "});" | 278 "});" |
| 248 "document.getElementsByTagName('embed')[0].postMessage(" | 279 "document.getElementsByTagName('embed')[0].postMessage(" |
| 249 " {type: 'getSelectedText'});", | 280 " {type: 'getSelectedText'});", |
| 250 &success)); | 281 &success)); |
| 251 ASSERT_EQ(expect_success, success); | 282 ASSERT_EQ(expect_success, success); |
| 252 } | 283 } |
| 253 | 284 |
| 285 content::WebContents* SetUpForLinkClickTest() { |
| 286 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 287 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); |
| 288 return LoadPdfGetGuestContents(test_pdf_url); |
| 289 } |
| 290 |
| 254 void ConvertPageCoordToScreenCoord(content::WebContents* contents, | 291 void ConvertPageCoordToScreenCoord(content::WebContents* contents, |
| 255 gfx::Point* point) { | 292 gfx::Point* point) { |
| 256 ASSERT_TRUE(contents); | 293 ASSERT_TRUE(contents); |
| 257 ASSERT_TRUE(content::ExecuteScript(contents, | 294 ASSERT_TRUE(content::ExecuteScript(contents, |
| 258 "var visiblePage = viewer.viewport.getMostVisiblePage();" | 295 "var visiblePage = viewer.viewport.getMostVisiblePage();" |
| 259 "var visiblePageDimensions =" | 296 "var visiblePageDimensions =" |
| 260 " viewer.viewport.getPageScreenRect(visiblePage);" | 297 " viewer.viewport.getPageScreenRect(visiblePage);" |
| 261 "var viewportPosition = viewer.viewport.position;" | 298 "var viewportPosition = viewer.viewport.position;" |
| 262 "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;" | 299 "var screenOffsetX = visiblePageDimensions.x - viewportPosition.x;" |
| 263 "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;" | 300 "var screenOffsetY = visiblePageDimensions.y - viewportPosition.y;" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 274 &x)); | 311 &x)); |
| 275 | 312 |
| 276 int y; | 313 int y; |
| 277 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 314 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| 278 contents, | 315 contents, |
| 279 "window.domAutomationController.send(linkScreenPositionY);", | 316 "window.domAutomationController.send(linkScreenPositionY);", |
| 280 &y)); | 317 &y)); |
| 281 | 318 |
| 282 point->SetPoint(x, y); | 319 point->SetPoint(x, y); |
| 283 } | 320 } |
| 284 | |
| 285 }; | 321 }; |
| 286 | 322 |
| 287 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { | 323 IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { |
| 288 #if defined(GOOGLE_CHROME_BUILD) | 324 #if defined(GOOGLE_CHROME_BUILD) |
| 289 // Load private PDFs. | 325 // Load private PDFs. |
| 290 LoadAllPdfsTest("pdf_private", GetParam()); | 326 LoadAllPdfsTest("pdf_private", GetParam()); |
| 291 #endif | 327 #endif |
| 292 // Load public PDFs. | 328 // Load public PDFs. |
| 293 LoadAllPdfsTest("pdf", GetParam()); | 329 LoadAllPdfsTest("pdf", GetParam()); |
| 294 } | 330 } |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 base::Bind(&RetrieveGuestContents, | 749 base::Bind(&RetrieveGuestContents, |
| 714 &guest_contents)); | 750 &guest_contents)); |
| 715 ASSERT_TRUE(guest_contents); | 751 ASSERT_TRUE(guest_contents); |
| 716 | 752 |
| 717 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); | 753 ui::AXTreeUpdate ax_tree = GetAccessibilityTreeSnapshot(guest_contents); |
| 718 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); | 754 std::string ax_tree_dump = DumpPdfAccessibilityTree(ax_tree); |
| 719 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); | 755 ASSERT_MULTILINE_STREQ(kExpectedPDFAXTree, ax_tree_dump); |
| 720 } | 756 } |
| 721 | 757 |
| 722 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) { | 758 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlLeftClick) { |
| 723 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 759 content::WebContents* guest_contents = SetUpForLinkClickTest(); |
| 724 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); | |
| 725 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | |
| 726 ASSERT_TRUE(guest_contents); | 760 ASSERT_TRUE(guest_contents); |
| 727 | 761 |
| 728 // The link position of the test-link.pdf in page coordinates is (110, 110). | 762 // The link position of the test-link.pdf in page coordinates is (110, 110). |
| 729 // Convert the link position from page coordinates to screen coordinates. | 763 // Convert the link position from page coordinates to screen coordinates. |
| 730 gfx::Point link_position(110, 110); | 764 gfx::Point link_position(110, 110); |
| 731 ConvertPageCoordToScreenCoord(guest_contents, &link_position); | 765 ConvertPageCoordToScreenCoord(guest_contents, &link_position); |
| 732 | 766 |
| 733 content::WebContents* web_contents = | 767 content::WebContents* web_contents = |
| 734 browser()->tab_strip_model()->GetActiveWebContents(); | 768 browser()->tab_strip_model()->GetActiveWebContents(); |
| 735 | 769 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 750 content::WebContents* new_web_contents = | 784 content::WebContents* new_web_contents = |
| 751 browser()->tab_strip_model()->GetWebContentsAt(1); | 785 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 752 ASSERT_TRUE(new_web_contents); | 786 ASSERT_TRUE(new_web_contents); |
| 753 ASSERT_NE(web_contents, new_web_contents); | 787 ASSERT_NE(web_contents, new_web_contents); |
| 754 | 788 |
| 755 const GURL& url = new_web_contents->GetURL(); | 789 const GURL& url = new_web_contents->GetURL(); |
| 756 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); | 790 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); |
| 757 } | 791 } |
| 758 | 792 |
| 759 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { | 793 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkMiddleClick) { |
| 760 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 794 content::WebContents* guest_contents = SetUpForLinkClickTest(); |
| 761 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); | |
| 762 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | |
| 763 ASSERT_TRUE(guest_contents); | 795 ASSERT_TRUE(guest_contents); |
| 764 | 796 |
| 765 // The link position of the test-link.pdf in page coordinates is (110, 110). | 797 // The link position of the test-link.pdf in page coordinates is (110, 110). |
| 766 // Convert the link position from page coordinates to screen coordinates. | 798 // Convert the link position from page coordinates to screen coordinates. |
| 767 gfx::Point link_position(110, 110); | 799 gfx::Point link_position(110, 110); |
| 768 ConvertPageCoordToScreenCoord(guest_contents, &link_position); | 800 ConvertPageCoordToScreenCoord(guest_contents, &link_position); |
| 769 | 801 |
| 770 content::WebContents* web_contents = | 802 content::WebContents* web_contents = |
| 771 browser()->tab_strip_model()->GetActiveWebContents(); | 803 browser()->tab_strip_model()->GetActiveWebContents(); |
| 772 | 804 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 787 content::WebContents* new_web_contents = | 819 content::WebContents* new_web_contents = |
| 788 browser()->tab_strip_model()->GetWebContentsAt(1); | 820 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 789 ASSERT_TRUE(new_web_contents); | 821 ASSERT_TRUE(new_web_contents); |
| 790 ASSERT_NE(web_contents, new_web_contents); | 822 ASSERT_NE(web_contents, new_web_contents); |
| 791 | 823 |
| 792 const GURL& url = new_web_contents->GetURL(); | 824 const GURL& url = new_web_contents->GetURL(); |
| 793 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); | 825 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); |
| 794 } | 826 } |
| 795 | 827 |
| 796 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlShiftLeftClick) { | 828 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkCtrlShiftLeftClick) { |
| 797 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 829 content::WebContents* guest_contents = SetUpForLinkClickTest(); |
| 798 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); | |
| 799 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | |
| 800 ASSERT_TRUE(guest_contents); | 830 ASSERT_TRUE(guest_contents); |
| 801 | 831 |
| 802 // The link position of the test-link.pdf in page coordinates is (110, 110). | 832 // The link position of the test-link.pdf in page coordinates is (110, 110). |
| 803 // Convert the link position from page coordinates to screen coordinates. | 833 // Convert the link position from page coordinates to screen coordinates. |
| 804 gfx::Point link_position(110, 110); | 834 gfx::Point link_position(110, 110); |
| 805 ConvertPageCoordToScreenCoord(guest_contents, &link_position); | 835 ConvertPageCoordToScreenCoord(guest_contents, &link_position); |
| 806 | 836 |
| 807 content::WebContents* web_contents = | 837 content::WebContents* web_contents = |
| 808 browser()->tab_strip_model()->GetActiveWebContents(); | 838 browser()->tab_strip_model()->GetActiveWebContents(); |
| 809 | 839 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 821 | 851 |
| 822 content::WebContents* active_web_contents = | 852 content::WebContents* active_web_contents = |
| 823 browser()->tab_strip_model()->GetActiveWebContents(); | 853 browser()->tab_strip_model()->GetActiveWebContents(); |
| 824 ASSERT_NE(web_contents, active_web_contents); | 854 ASSERT_NE(web_contents, active_web_contents); |
| 825 | 855 |
| 826 const GURL& url = active_web_contents->GetURL(); | 856 const GURL& url = active_web_contents->GetURL(); |
| 827 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); | 857 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); |
| 828 } | 858 } |
| 829 | 859 |
| 830 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftMiddleClick) { | 860 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftMiddleClick) { |
| 831 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 861 content::WebContents* guest_contents = SetUpForLinkClickTest(); |
| 832 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test-link.pdf")); | |
| 833 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); | |
| 834 ASSERT_TRUE(guest_contents); | 862 ASSERT_TRUE(guest_contents); |
| 835 | 863 |
| 836 // The link position of the test-link.pdf in page coordinates is (110, 110). | 864 // The link position of the test-link.pdf in page coordinates is (110, 110). |
| 837 // Convert the link position from page coordinates to screen coordinates. | 865 // Convert the link position from page coordinates to screen coordinates. |
| 838 gfx::Point link_position(110, 110); | 866 gfx::Point link_position(110, 110); |
| 839 ConvertPageCoordToScreenCoord(guest_contents, &link_position); | 867 ConvertPageCoordToScreenCoord(guest_contents, &link_position); |
| 840 | 868 |
| 841 content::WebContents* web_contents = | 869 content::WebContents* web_contents = |
| 842 browser()->tab_strip_model()->GetActiveWebContents(); | 870 browser()->tab_strip_model()->GetActiveWebContents(); |
| 843 | 871 |
| 844 content::WindowedNotificationObserver observer( | 872 content::WindowedNotificationObserver observer( |
| 845 chrome::NOTIFICATION_TAB_ADDED, | 873 chrome::NOTIFICATION_TAB_ADDED, |
| 846 content::NotificationService::AllSources()); | 874 content::NotificationService::AllSources()); |
| 847 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ShiftKey, | 875 content::SimulateMouseClickAt(web_contents, blink::WebInputEvent::ShiftKey, |
| 848 blink::WebMouseEvent::ButtonMiddle, link_position); | 876 blink::WebMouseEvent::ButtonMiddle, link_position); |
| 849 observer.Wait(); | 877 observer.Wait(); |
| 850 | 878 |
| 851 int tab_count = browser()->tab_strip_model()->count(); | 879 int tab_count = browser()->tab_strip_model()->count(); |
| 852 ASSERT_EQ(2, tab_count); | 880 ASSERT_EQ(2, tab_count); |
| 853 | 881 |
| 854 content::WebContents* active_web_contents = | 882 content::WebContents* active_web_contents = |
| 855 browser()->tab_strip_model()->GetActiveWebContents(); | 883 browser()->tab_strip_model()->GetActiveWebContents(); |
| 856 ASSERT_NE(web_contents, active_web_contents); | 884 ASSERT_NE(web_contents, active_web_contents); |
| 857 | 885 |
| 858 const GURL& url = active_web_contents->GetURL(); | 886 const GURL& url = active_web_contents->GetURL(); |
| 859 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); | 887 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); |
| 860 } | 888 } |
| 889 |
| 890 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DownloadPDFButton) { |
| 891 GURL test_pdf_url(embedded_test_server()->GetURL("/pdf/test.pdf")); |
| 892 content::WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); |
| 893 ASSERT_TRUE(guest_contents); |
| 894 |
| 895 auto* helper = pdf::PDFWebContentsHelper::FromWebContents(guest_contents); |
| 896 ASSERT_TRUE(helper); |
| 897 |
| 898 // Pass ownership to |helper| but retain a raw pointer to check test results. |
| 899 // |client| is alive for the duration of this test. |
| 900 auto* client = new TestPDFWebContentsHelperClient(guest_contents); |
| 901 helper->SetClientForTest(base::WrapUnique(client)); |
| 902 |
| 903 const char kScript[] = "$('toolbar').fire('save');"; |
| 904 ASSERT_TRUE(content::ExecuteScript(guest_contents, kScript)); |
| 905 |
| 906 // Wait to get the save count. If it never arrives and the test hangs, then |
| 907 // the test has failed. Unfortunately with multiple processes in the PDF |
| 908 // Viewer, it is too hard for the test to be event driven. |
| 909 while (!client->save_url_count()) |
| 910 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 911 EXPECT_EQ(1, client->save_url_count()); |
| 912 } |
| OLD | NEW |