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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc

Issue 2862583010: [Reland 1] Save pdf file instead of web page through context menu for embedded pdf file (Closed)
Patch Set: fix file path Created 3 years, 7 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
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 "chrome/browser/renderer_context_menu/render_view_context_menu.h" 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/profiles/profile_attributes_entry.h" 27 #include "chrome/browser/profiles/profile_attributes_entry.h"
28 #include "chrome/browser/profiles/profile_attributes_storage.h" 28 #include "chrome/browser/profiles/profile_attributes_storage.h"
29 #include "chrome/browser/profiles/profile_window.h" 29 #include "chrome/browser/profiles/profile_window.h"
30 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 30 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
31 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 31 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
32 #include "chrome/browser/search_engines/template_url_service_factory.h" 32 #include "chrome/browser/search_engines/template_url_service_factory.h"
33 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
35 #include "chrome/common/render_messages.h" 35 #include "chrome/common/render_messages.h"
36 #include "chrome/common/thumbnail_capturer.mojom.h" 36 #include "chrome/common/thumbnail_capturer.mojom.h"
37 #include "chrome/grit/generated_resources.h"
37 #include "chrome/test/base/in_process_browser_test.h" 38 #include "chrome/test/base/in_process_browser_test.h"
38 #include "chrome/test/base/search_test_utils.h" 39 #include "chrome/test/base/search_test_utils.h"
39 #include "chrome/test/base/ui_test_utils.h" 40 #include "chrome/test/base/ui_test_utils.h"
40 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 41 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
41 #include "components/search_engines/template_url_data.h" 42 #include "components/search_engines/template_url_data.h"
42 #include "components/search_engines/template_url_service.h" 43 #include "components/search_engines/template_url_service.h"
43 #include "content/public/browser/browser_message_filter.h" 44 #include "content/public/browser/browser_message_filter.h"
45 #include "content/public/browser/browser_plugin_guest_manager.h"
44 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
45 #include "content/public/browser/navigation_controller.h" 47 #include "content/public/browser/navigation_controller.h"
46 #include "content/public/browser/navigation_entry.h" 48 #include "content/public/browser/navigation_entry.h"
47 #include "content/public/browser/notification_service.h" 49 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/render_frame_host.h" 50 #include "content/public/browser/render_frame_host.h"
49 #include "content/public/browser/render_process_host.h" 51 #include "content/public/browser/render_process_host.h"
50 #include "content/public/browser/render_view_host.h" 52 #include "content/public/browser/render_view_host.h"
51 #include "content/public/browser/render_widget_host.h" 53 #include "content/public/browser/render_widget_host.h"
52 #include "content/public/browser/web_contents.h" 54 #include "content/public/browser/web_contents.h"
53 #include "content/public/test/browser_test_utils.h" 55 #include "content/public/test/browser_test_utils.h"
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 thumbnail_capturer->RequestThumbnailForContextNode( 666 thumbnail_capturer->RequestThumbnailForContextNode(
665 0, gfx::Size(2048, 2048), 667 0, gfx::Size(2048, 2048),
666 base::Bind(callback, &response_received, run_loop.QuitClosure())); 668 base::Bind(callback, &response_received, run_loop.QuitClosure()));
667 run_loop.Run(); 669 run_loop.Run();
668 670
669 // The browser should receive a response from the renderer, because the 671 // The browser should receive a response from the renderer, because the
670 // renderer should not crash. 672 // renderer should not crash.
671 ASSERT_TRUE(response_received); 673 ASSERT_TRUE(response_received);
672 } 674 }
673 675
676 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, FullPagePdfHasPageItems) {
677 // Load a pdf page.
678 GURL page_url =
679 ui_test_utils::GetTestUrl(base::FilePath(FILE_PATH_LITERAL("pdf")),
680 base::FilePath(FILE_PATH_LITERAL("test.pdf")));
681 ui_test_utils::NavigateToURL(browser(), page_url);
682
683 // Get the pdf plugin's WebContents and its main frame.
684 WebContents* web_contents =
685 browser()->tab_strip_model()->GetActiveWebContents();
686 content::BrowserPluginGuestManager* guest_manager =
687 web_contents->GetBrowserContext()->GetGuestManager();
688 WebContents* guest_contents = guest_manager->GetFullPageGuest(web_contents);
689 ASSERT_TRUE(guest_contents);
690 content::RenderFrameHost* frame = guest_contents->GetMainFrame();
691 ASSERT_TRUE(frame);
692 ASSERT_NE(frame, web_contents->GetMainFrame());
693
694 content::ContextMenuParams params;
695 params.page_url = page_url;
696 params.frame_url = frame->GetLastCommittedURL();
697 params.frame_page_state = content::PageState::CreateFromURL(params.frame_url);
698 params.media_type = blink::WebContextMenuData::kMediaTypePlugin;
699 TestRenderViewContextMenu menu(frame, params);
700 menu.Init();
701
702 // The full page related items such as 'back' should be there.
703 ASSERT_TRUE(menu.IsItemPresent(IDC_BACK));
704 }
705
706 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, EmbeddedPdfHasNoPageItems) {
707 // Load a page with an embedded pdf.
708 GURL page_url = ui_test_utils::GetTestUrl(
709 base::FilePath(FILE_PATH_LITERAL("pdf")),
710 base::FilePath(FILE_PATH_LITERAL("test-embedded-pdf.html")));
711 ui_test_utils::NavigateToURL(browser(), page_url);
712
713 WebContents* web_contents =
714 browser()->tab_strip_model()->GetActiveWebContents();
715 // Observe loading the pdf plugin.
716 content::WebContentsAddedObserver web_contents_added_observer;
717 ASSERT_TRUE(ExecuteScript(web_contents,
718 "var l = document.getElementById('link1');"
719 "l.click();"));
720 // Get the embedded pdf plugin's WebContents and its main frame.
721 WebContents* inner_contents = web_contents_added_observer.GetWebContents();
lazyboy 2017/05/11 18:15:17 Do you need to ASSERT_TRUE(content::WaitForLoadSto
Wei Li 2017/05/17 05:37:09 Turned out that I do need some kind of wait() to m
lazyboy 2017/05/17 16:34:44 I can't find where you've added the wait in the ne
722 ASSERT_TRUE(inner_contents);
723 content::RenderFrameHost* frame = inner_contents->GetMainFrame();
724
725 content::ContextMenuParams params;
726 params.page_url = page_url;
727 params.frame_url = frame->GetLastCommittedURL();
728 params.frame_page_state = content::PageState::CreateFromURL(params.frame_url);
729 params.media_type = blink::WebContextMenuData::kMediaTypePlugin;
730 TestRenderViewContextMenu menu(frame, params);
731 menu.Init();
732
733 // The full page related items such as 'back' should not be displayed.
734 ASSERT_FALSE(menu.IsItemPresent(IDC_BACK));
lazyboy 2017/05/11 18:15:17 Here and above, back could be unavailable for othe
Wei Li 2017/05/17 05:37:09 I agree that enabled or not doesn't matter for thi
735 }
736
674 class LoadImageRequestInterceptor : public net::URLRequestInterceptor { 737 class LoadImageRequestInterceptor : public net::URLRequestInterceptor {
675 public: 738 public:
676 LoadImageRequestInterceptor() : num_requests_(0), 739 LoadImageRequestInterceptor() : num_requests_(0),
677 requests_to_wait_for_(-1), 740 requests_to_wait_for_(-1),
678 weak_factory_(this) { 741 weak_factory_(this) {
679 } 742 }
680 743
681 ~LoadImageRequestInterceptor() override {} 744 ~LoadImageRequestInterceptor() override {}
682 745
683 // net::URLRequestInterceptor implementation 746 // net::URLRequestInterceptor implementation
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { 854 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) {
792 static const char kValidImage[] = "/load_image/image.png"; 855 static const char kValidImage[] = "/load_image/image.png";
793 SetupAndLoadImagePage(kValidImage); 856 SetupAndLoadImagePage(kValidImage);
794 AddLoadImageInterceptor(kValidImage); 857 AddLoadImageInterceptor(kValidImage);
795 AttemptLoadImage(); 858 AttemptLoadImage();
796 interceptor_->WaitForRequests(1); 859 interceptor_->WaitForRequests(1);
797 EXPECT_EQ(1, interceptor_->num_requests()); 860 EXPECT_EQ(1, interceptor_->num_requests());
798 } 861 }
799 862
800 } // namespace 863 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698