Chromium Code Reviews| 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..28c78ff122dea6ee57992bee197e0a736a1e059b 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,36 @@ class PrintPreviewDialogDestroyedObserver : public WebContentsObserver { |
| DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); |
| }; |
| +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) {} |
| @@ -161,7 +201,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 +237,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 +261,61 @@ 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) { |
| + // Print for the first time. |
| + PrintPreview(); |
| + |
| + // Navigate in the initiator tab. |
| + WebContents* preview_dialog = GetPrintPreviewDialog(); |
| + PrintPreviewDialogDestroyedObserver dialog_destroyed_observer(preview_dialog); |
| + ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| + ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed()); |
| + |
| + // Get the PDF plugin info. |
| + content::WebPluginInfo pdf_plugin_info; |
| + ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info)); |
|
Lei Zhang
2015/03/19 02:55:34
This failed on the CrOS bot. I'm pretty sure CrOS
|
| + |
| + // 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)); |
| + |
| + // Print preview again. |
| + PrintPreview(); |
| + |
| + // Check a new print preview dialog got created. |
| + WebContents* new_preview_dialog = GetPrintPreviewDialog(); |
| + ASSERT_TRUE(new_preview_dialog); |
| + ASSERT_NE(initiator(), new_preview_dialog); |
| + |
| + // Wait until the <iframe> in the print preview renderer has loaded. |
| + 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; |
| + new_preview_dialog->ForEachFrame( |
| + base::Bind(&CountFrames, base::Unretained(&frame_count))); |
| + } while (frame_count < 2); |
| + ASSERT_EQ(2, frame_count); |
| + |
| + // Make sure all the frames in the dialog has access to the PDF plugin. |
| + new_preview_dialog->ForEachFrame(base::Bind(&CheckPdfPluginForRenderFrame)); |
| +} |