| 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 9cfc8da82af0699c507fb4813cd517995dde3313..24495e9cca132eba1b1e12edd128cdbc75d1adc0 100644
|
| --- a/chrome/browser/pdf/pdf_extension_test.cc
|
| +++ b/chrome/browser/pdf/pdf_extension_test.cc
|
| @@ -7,14 +7,18 @@
|
| #include "base/files/file_util.h"
|
| #include "base/hash.h"
|
| #include "base/path_service.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/extensions/component_loader.h"
|
| #include "chrome/browser/extensions/extension_apitest.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/plugins/plugin_prefs.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/common/chrome_content_client.h"
|
| #include "chrome/common/chrome_paths.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| #include "content/public/browser/browser_plugin_guest_manager.h"
|
| +#include "content/public/browser/download_manager.h"
|
| #include "content/public/browser/plugin_service.h"
|
| #include "content/public/test/browser_test_utils.h"
|
| #include "extensions/browser/extension_registry.h"
|
| @@ -162,6 +166,58 @@ IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
|
| LoadAllPdfsTest("pdf", GetParam());
|
| }
|
|
|
| +class TestDownloadObserver : public content::DownloadManager::Observer {
|
| + public:
|
| + TestDownloadObserver() {}
|
| + virtual ~TestDownloadObserver() {}
|
| +
|
| + GURL GetAndClearLastUrl() {
|
| + GURL result = url_;
|
| + url_ = GURL();
|
| + return result;
|
| + }
|
| +
|
| + void OnDownloadCreated(content::DownloadManager* manager,
|
| + content::DownloadItem* item) override {
|
| + CHECK(url_.is_empty());
|
| + url_ = item->GetURL();
|
| + CHECK(!url_.is_empty());
|
| + }
|
| +
|
| + private:
|
| + GURL url_;
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) {
|
| + // Disable the PDF plugin.
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + content::BrowserContext* browser_context = web_contents->GetBrowserContext();
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + scoped_refptr<PluginPrefs> prefs(PluginPrefs::GetForProfile(profile));
|
| + ASSERT_TRUE(prefs.get());
|
| + prefs->EnablePluginGroup(false,
|
| + base::UTF8ToUTF16(ChromeContentClient::kPDFPluginName));
|
| +
|
| + // Register a download observer.
|
| + content::DownloadManager* download_manager =
|
| + content::BrowserContext::GetDownloadManager(browser_context);
|
| + TestDownloadObserver download_observer;
|
| + download_manager->AddObserver(&download_observer);
|
| +
|
| + // Navigate to a PDF and test that it is downloaded.
|
| + GURL url(embedded_test_server()->GetURL("/pdf/test.pdf"));
|
| + ui_test_utils::NavigateToURL(browser(), url);
|
| + ASSERT_EQ(url, download_observer.GetAndClearLastUrl());
|
| +
|
| + // Cancel the download to shutdown cleanly.
|
| + download_manager->RemoveObserver(&download_observer);
|
| + std::vector<content::DownloadItem*> downloads;
|
| + download_manager->GetAllDownloads(&downloads);
|
| + ASSERT_EQ(1u, downloads.size());
|
| + downloads[0]->Cancel(false);
|
| +}
|
| +
|
| // We break PDFTest.Load up into kNumberLoadTestParts.
|
| INSTANTIATE_TEST_CASE_P(PDFTestFiles,
|
| PDFExtensionTest,
|
|
|