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

Unified Diff: chrome/browser/pdf/pdf_extension_test.cc

Issue 2611643004: Don't abort the PDF stream if a navigation is intiated within the same page. (Closed)
Patch Set: Update test Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/pdf/pdf_href_replace_state.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/pdf/pdf_extension_test.cc
diff --git a/chrome/browser/pdf/pdf_extension_test.cc b/chrome/browser/pdf/pdf_extension_test.cc
index 8220c234d88aaa73165586d9e4c8542b93f44e91..06f6454409836873c6a07904e1218cc878e8aa7d 100644
--- a/chrome/browser/pdf/pdf_extension_test.cc
+++ b/chrome/browser/pdf/pdf_extension_test.cc
@@ -48,6 +48,7 @@
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/manifest_handlers/mime_types_handler.h"
#include "extensions/test/result_catcher.h"
@@ -905,3 +906,68 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, LinkShiftLeftClick) {
IN_PROC_BROWSER_TEST_F(PDFExtensionTest, RedirectsFailInPlugin) {
RunTestsInFile("redirects_fail_test.js", "test.pdf");
}
+
+// This test opens a PDF by clicking a link via javascript and verifies that
+// the PDF is loaded and functional by clicking a link in the PDF. The link
+// click in the PDF opens a new tab. The main page handles the pageShow event
+// and updates the history state.
+IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenPDFOnLinkClickWithReplaceState) {
+ host_resolver()->AddRule("www.example.com", "127.0.0.1");
+
+ // Navigate to the main page.
+ GURL test_url(
+ embedded_test_server()->GetURL("/pdf/pdf_href_replace_state.html"));
+ ui_test_utils::NavigateToURL(browser(), test_url);
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_TRUE(web_contents);
+
+ // Click on the link which opens the PDF via JS.
+ content::TestNavigationObserver navigation_observer(web_contents);
+ 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.
+ ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
+ pdf_link_click));
+ navigation_observer.Wait();
+ const GURL& current_url = web_contents->GetURL();
+ 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.
+ std::string::npos);
+
+ ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
+
+ // Now click on the link to example.com in the PDF. This should open up a new
+ // tab.
+ content::BrowserPluginGuestManager* guest_manager =
+ web_contents->GetBrowserContext()->GetGuestManager();
+ content::WebContents* guest_contents =
+ guest_manager->GetFullPageGuest(web_contents);
+ ASSERT_TRUE(guest_contents);
+ // The link position of the test-link.pdf in page coordinates is (110, 110).
+ // Convert the link position from page coordinates to screen coordinates.
+ gfx::Point link_position(110, 110);
+ ConvertPageCoordToScreenCoord(guest_contents, &link_position);
+
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_TAB_ADDED,
+ content::NotificationService::AllSources());
+ content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier,
+ blink::WebMouseEvent::Button::Left,
+ link_position);
+ observer.Wait();
+
+ // We should have two tabs now. One with the PDF and the second for
+ // example.com
+ int tab_count = browser()->tab_strip_model()->count();
+ ASSERT_EQ(2, tab_count);
+
+ content::WebContents* active_web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ ASSERT_EQ(web_contents, active_web_contents);
+
+ content::WebContents* new_web_contents =
+ browser()->tab_strip_model()->GetWebContentsAt(1);
+ ASSERT_TRUE(new_web_contents);
+ ASSERT_NE(web_contents, new_web_contents);
+
+ const GURL& url = new_web_contents->GetURL();
+ 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.
+}
« no previous file with comments | « no previous file | chrome/test/data/pdf/pdf_href_replace_state.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698