Chromium Code Reviews| 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" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 #include "content/public/browser/download_manager.h" | 41 #include "content/public/browser/download_manager.h" |
| 42 #include "content/public/browser/notification_observer.h" | 42 #include "content/public/browser/notification_observer.h" |
| 43 #include "content/public/browser/notification_registrar.h" | 43 #include "content/public/browser/notification_registrar.h" |
| 44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| 45 #include "content/public/browser/plugin_service.h" | 45 #include "content/public/browser/plugin_service.h" |
| 46 #include "content/public/browser/render_process_host.h" | 46 #include "content/public/browser/render_process_host.h" |
| 47 #include "content/public/browser/render_view_host.h" | 47 #include "content/public/browser/render_view_host.h" |
| 48 #include "content/public/browser/render_widget_host.h" | 48 #include "content/public/browser/render_widget_host.h" |
| 49 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
| 50 #include "content/public/test/browser_test_utils.h" | 50 #include "content/public/test/browser_test_utils.h" |
| 51 #include "content/public/test/test_navigation_observer.h" | |
| 51 #include "extensions/browser/extension_registry.h" | 52 #include "extensions/browser/extension_registry.h" |
| 52 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 53 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
| 53 #include "extensions/test/result_catcher.h" | 54 #include "extensions/test/result_catcher.h" |
| 54 #include "net/dns/mock_host_resolver.h" | 55 #include "net/dns/mock_host_resolver.h" |
| 55 #include "net/test/embedded_test_server/embedded_test_server.h" | 56 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 56 #include "ui/base/resource/resource_bundle.h" | 57 #include "ui/base/resource/resource_bundle.h" |
| 57 #include "url/gurl.h" | 58 #include "url/gurl.h" |
| 58 | 59 |
| 59 #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) | 60 #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) |
| 60 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 61 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 const GURL& url = active_web_contents->GetURL(); | 899 const GURL& url = active_web_contents->GetURL(); |
| 899 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); | 900 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); |
| 900 } | 901 } |
| 901 | 902 |
| 902 // Test that if the plugin tries to load a URL that redirects then it will fail | 903 // Test that if the plugin tries to load a URL that redirects then it will fail |
| 903 // to load. This is to avoid the source origin of the document changing during | 904 // to load. This is to avoid the source origin of the document changing during |
| 904 // the redirect, which can have security implications. https://crbug.com/653749. | 905 // the redirect, which can have security implications. https://crbug.com/653749. |
| 905 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, RedirectsFailInPlugin) { | 906 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, RedirectsFailInPlugin) { |
| 906 RunTestsInFile("redirects_fail_test.js", "test.pdf"); | 907 RunTestsInFile("redirects_fail_test.js", "test.pdf"); |
| 907 } | 908 } |
| 909 | |
| 910 // This test opens a PDF by clicking a link via javascript and verifies that | |
| 911 // the PDF is loaded and functional by clicking a link in the PDF. The link | |
| 912 // click in the PDF opens a new tab. The main page handles the pageShow event | |
| 913 // and updates the history state. | |
| 914 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenPDFOnLinkClickWithReplaceState) { | |
| 915 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | |
| 916 | |
| 917 // Navigate to the main page. | |
| 918 GURL test_url( | |
| 919 embedded_test_server()->GetURL("/pdf/pdf_href_replace_state.html")); | |
| 920 ui_test_utils::NavigateToURL(browser(), test_url); | |
| 921 content::WebContents* web_contents = | |
| 922 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 923 ASSERT_TRUE(web_contents); | |
| 924 | |
| 925 // Click on the link which opens the PDF via JS. | |
| 926 content::TestNavigationObserver navigation_observer(web_contents); | |
| 927 std::string pdf_link_click = "document.getElementById('link').click();"; | |
|
lazyboy
2017/01/05 04:03:14
nit: kPdfLinkClick
ananta
2017/01/05 04:28:57
Done.
| |
| 928 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(), | |
| 929 pdf_link_click)); | |
| 930 navigation_observer.Wait(); | |
| 931 const GURL& current_url = web_contents->GetURL(); | |
| 932 ASSERT_TRUE(current_url.spec().find("pdf/test-link.pdf") != | |
|
lazyboy
2017/01/05 04:03:14
current_url.path() == "/pdf/test-link.pdf"
ananta
2017/01/05 04:28:57
Done.
| |
| 933 std::string::npos); | |
| 934 | |
| 935 ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents)); | |
| 936 | |
| 937 // Now click on the link to example.com in the PDF. This should open up a new | |
| 938 // tab. | |
| 939 content::BrowserPluginGuestManager* guest_manager = | |
| 940 web_contents->GetBrowserContext()->GetGuestManager(); | |
| 941 content::WebContents* guest_contents = | |
| 942 guest_manager->GetFullPageGuest(web_contents); | |
| 943 ASSERT_TRUE(guest_contents); | |
| 944 // The link position of the test-link.pdf in page coordinates is (110, 110). | |
| 945 // Convert the link position from page coordinates to screen coordinates. | |
| 946 gfx::Point link_position(110, 110); | |
| 947 ConvertPageCoordToScreenCoord(guest_contents, &link_position); | |
| 948 | |
| 949 content::WindowedNotificationObserver observer( | |
| 950 chrome::NOTIFICATION_TAB_ADDED, | |
| 951 content::NotificationService::AllSources()); | |
| 952 content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier, | |
| 953 blink::WebMouseEvent::Button::Left, | |
| 954 link_position); | |
| 955 observer.Wait(); | |
| 956 | |
| 957 // We should have two tabs now. One with the PDF and the second for | |
| 958 // example.com | |
| 959 int tab_count = browser()->tab_strip_model()->count(); | |
| 960 ASSERT_EQ(2, tab_count); | |
| 961 | |
| 962 content::WebContents* active_web_contents = | |
| 963 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 964 ASSERT_EQ(web_contents, active_web_contents); | |
| 965 | |
| 966 content::WebContents* new_web_contents = | |
| 967 browser()->tab_strip_model()->GetWebContentsAt(1); | |
| 968 ASSERT_TRUE(new_web_contents); | |
| 969 ASSERT_NE(web_contents, new_web_contents); | |
| 970 | |
| 971 const GURL& url = new_web_contents->GetURL(); | |
| 972 ASSERT_EQ(std::string("http://www.example.com/"), url.spec()); | |
|
lazyboy
2017/01/05 04:03:14
nit: Maybe ASSERT_EQ(GURL("http://www.example.com"
ananta
2017/01/05 04:28:57
Done.
| |
| 973 } | |
| OLD | NEW |