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

Unified Diff: chrome/browser/printing/print_preview_dialog_controller_browsertest.cc

Issue 1022673002: Enable PDF plugin for iframes within the print preview dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better comments Created 5 years, 9 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
Index: chrome/browser/printing/print_preview_dialog_controller_browsertest.cc
diff --git a/chrome/browser/printing/print_preview_dialog_controller_browsertest.cc b/chrome/browser/printing/print_preview_dialog_controller_browsertest.cc
index 06817a289ae45b1e5d1317eb60fc13bc39216470..fbf356a34eff9c9a2e777f118c47d7c1f1f35008 100644
--- a/chrome/browser/printing/print_preview_dialog_controller_browsertest.cc
+++ b/chrome/browser/printing/print_preview_dialog_controller_browsertest.cc
@@ -2,16 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/bind_helpers.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
+#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/printing/print_preview_dialog_controller.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_content_client.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/printing/common/print_messages.h"
+#include "content/public/browser/plugin_service.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/test/browser_test_utils.h"
#include "ipc/ipc_message_macros.h"
@@ -20,6 +28,8 @@
using content::WebContents;
using content::WebContentsObserver;
+namespace {
+
class RequestPrintPreviewObserver : public WebContentsObserver {
public:
explicit RequestPrintPreviewObserver(WebContents* dialog)
@@ -95,6 +105,42 @@ class PrintPreviewDialogDestroyedObserver : public WebContentsObserver {
DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver);
};
+void PluginsLoadedCallback(
+ const base::Closure& quit_closure,
+ const std::vector<content::WebPluginInfo>& /* info */) {
+ quit_closure.Run();
+}
+
+bool GetPdfPluginInfo(content::WebPluginInfo* info) {
+ base::FilePath pdf_plugin_path = base::FilePath::FromUTF8Unsafe(
+ ChromeContentClient::kPDFPluginPath);
+ return content::PluginService::GetInstance()->GetPluginInfoByPath(
+ pdf_plugin_path, info);
+}
+
+const char kDummyPrintUrl[] = "chrome://print/dummy.pdf";
+
+void CountFrames(int* frame_count,
+ content::RenderFrameHost* frame) {
+ ++(*frame_count);
+}
+
+void CheckPdfPluginForRenderFrame(content::RenderFrameHost* frame) {
+ content::WebPluginInfo pdf_plugin_info;
+ ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info));
+
+ ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance();
+ EXPECT_TRUE(filter->IsPluginAvailable(
+ frame->GetProcess()->GetID(),
+ frame->GetRoutingID(),
+ nullptr,
+ GURL(kDummyPrintUrl),
+ GURL(),
+ &pdf_plugin_info));
+}
+
+} // namespace
+
class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest {
public:
PrintPreviewDialogControllerBrowserTest() : initiator_(NULL) {}
@@ -134,6 +180,9 @@ class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest {
initiator_ = browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(initiator_);
ASSERT_NE(first_tab, initiator_);
+
+ content::PluginService::GetInstance()->Init();
+ content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
}
void TearDownOnMainThread() override {
@@ -161,7 +210,7 @@ class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest {
#endif
IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
MAYBE_NavigateFromInitiatorTab) {
- // print for the first time.
+ // Print for the first time.
PrintPreview();
// Get the preview dialog for the initiator tab.
@@ -197,7 +246,7 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
#endif
IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
MAYBE_ReloadInitiatorTab) {
- // print for the first time.
+ // Print for the first time.
PrintPreview();
WebContents* preview_dialog = GetPrintPreviewDialog();
@@ -221,3 +270,60 @@ IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
WebContents* new_preview_dialog = GetPrintPreviewDialog();
EXPECT_TRUE(new_preview_dialog);
}
+
+// Test to verify that after print preview works even when the PDF plugin is
+// disabled for webpages.
+IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
+ PdfPluginDisabled) {
+ // Make sure plugins are loaded.
+ {
+ base::RunLoop run_loop;
+ content::PluginService::GetInstance()->GetPlugins(
+ base::Bind(&PluginsLoadedCallback, run_loop.QuitClosure()));
+ run_loop.Run();
+ }
+ // Get the PDF plugin info.
+ content::WebPluginInfo pdf_plugin_info;
+ ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info));
+
+ // Disable the PDF plugin.
+ PluginPrefs::GetForProfile(browser()->profile())->EnablePluginGroup(
+ false, base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName));
+
+ // Make sure it is actually disabled for webpages.
+ ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance();
+ content::WebPluginInfo dummy_pdf_plugin_info = pdf_plugin_info;
+ EXPECT_FALSE(filter->IsPluginAvailable(
+ initiator()->GetRenderProcessHost()->GetID(),
+ initiator()->GetMainFrame()->GetRoutingID(),
+ nullptr,
+ GURL("http://google.com"),
+ GURL(),
+ &dummy_pdf_plugin_info));
+
+ PrintPreview();
+
+ // Check a new print preview dialog got created.
+ WebContents* preview_dialog = GetPrintPreviewDialog();
+ ASSERT_TRUE(preview_dialog);
+ ASSERT_NE(initiator(), preview_dialog);
+
+ // Wait until the <iframe> in the print preview renderer has loaded.
+ // |frame_count| should be 2. The other frame is the main frame.
+ const int kExpectedFrameCount = 2;
+ int frame_count;
+ do {
+ base::RunLoop run_loop;
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(1));
+ run_loop.Run();
+
+ frame_count = 0;
+ preview_dialog->ForEachFrame(
+ base::Bind(&CountFrames, base::Unretained(&frame_count)));
+ } while (frame_count < kExpectedFrameCount);
+ ASSERT_EQ(kExpectedFrameCount, frame_count);
+
+ // Make sure all the frames in the dialog has access to the PDF plugin.
+ preview_dialog->ForEachFrame(base::Bind(&CheckPdfPluginForRenderFrame));
+}
« no previous file with comments | « chrome/browser/printing/print_preview_dialog_controller.cc ('k') | chrome/browser/printing/print_view_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698