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

Side by Side 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: Fix redness. 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 unified diff | 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 »
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 30 matching lines...) Expand all
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 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 ASSERT_NE(web_contents, active_web_contents); 926 ASSERT_NE(web_contents, active_web_contents);
926 927
927 ASSERT_TRUE(content::ExecuteScript( 928 ASSERT_TRUE(content::ExecuteScript(
928 guest_contents, 929 guest_contents,
929 "viewer.navigator_.navigate(" 930 "viewer.navigator_.navigate("
930 " 'www.example.com', Navigator.WindowOpenDisposition.CURRENT_TAB);")); 931 " 'www.example.com', Navigator.WindowOpenDisposition.CURRENT_TAB);"));
931 932
932 EXPECT_TRUE(web_contents->GetController().GetPendingEntry()); 933 EXPECT_TRUE(web_contents->GetController().GetPendingEntry());
933 EXPECT_FALSE(active_web_contents->GetController().GetPendingEntry()); 934 EXPECT_FALSE(active_web_contents->GetController().GetPendingEntry());
934 } 935 }
936
937 // This test opens a PDF by clicking a link via javascript and verifies that
938 // the PDF is loaded and functional by clicking a link in the PDF. The link
939 // click in the PDF opens a new tab. The main page handles the pageShow event
940 // and updates the history state.
941 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, OpenPDFOnLinkClickWithReplaceState) {
942 host_resolver()->AddRule("www.example.com", "127.0.0.1");
943
944 // Navigate to the main page.
945 GURL test_url(
946 embedded_test_server()->GetURL("/pdf/pdf_href_replace_state.html"));
947 ui_test_utils::NavigateToURL(browser(), test_url);
948 content::WebContents* web_contents =
949 browser()->tab_strip_model()->GetActiveWebContents();
950 ASSERT_TRUE(web_contents);
951
952 // Click on the link which opens the PDF via JS.
953 content::TestNavigationObserver navigation_observer(web_contents);
954 const char kPdfLinkClick[] = "document.getElementById('link').click();";
955 ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
956 kPdfLinkClick));
957 navigation_observer.Wait();
958 const GURL& current_url = web_contents->GetURL();
959 ASSERT_TRUE(current_url.path() == "/pdf/test-link.pdf");
960
961 ASSERT_TRUE(pdf_extension_test_util::EnsurePDFHasLoaded(web_contents));
962
963 // Now click on the link to example.com in the PDF. This should open up a new
964 // tab.
965 content::BrowserPluginGuestManager* guest_manager =
966 web_contents->GetBrowserContext()->GetGuestManager();
967 content::WebContents* guest_contents =
968 guest_manager->GetFullPageGuest(web_contents);
969 ASSERT_TRUE(guest_contents);
970 // The link position of the test-link.pdf in page coordinates is (110, 110).
971 // Convert the link position from page coordinates to screen coordinates.
972 gfx::Point link_position(110, 110);
973 ConvertPageCoordToScreenCoord(guest_contents, &link_position);
974
975 content::WindowedNotificationObserver observer(
976 chrome::NOTIFICATION_TAB_ADDED,
977 content::NotificationService::AllSources());
978 content::SimulateMouseClickAt(web_contents, kDefaultKeyModifier,
979 blink::WebMouseEvent::Button::Left,
980 link_position);
981 observer.Wait();
982
983 // We should have two tabs now. One with the PDF and the second for
984 // example.com
985 int tab_count = browser()->tab_strip_model()->count();
986 ASSERT_EQ(2, tab_count);
987
988 content::WebContents* active_web_contents =
989 browser()->tab_strip_model()->GetActiveWebContents();
990 ASSERT_EQ(web_contents, active_web_contents);
991
992 content::WebContents* new_web_contents =
993 browser()->tab_strip_model()->GetWebContentsAt(1);
994 ASSERT_TRUE(new_web_contents);
995 ASSERT_NE(web_contents, new_web_contents);
996
997 const GURL& url = new_web_contents->GetURL();
998 ASSERT_EQ(GURL("http://www.example.com"), url);
999 }
OLDNEW
« 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