Commit f84d7228 authored by Tom Sepez's avatar Tom Sepez Committed by Commit Bot

Add mechanism to count PDF PPAPI processes in browser tests

Call it as appropriate in pdf_extension_test.cc

Split off from https://chromium-review.googlesource.com/c/chromium/src/+/922727
so as to get a baseline before making further changes.

Bug: 809614
Change-Id: I85e947230fd4f87547dac169e2271c2510c41b29
Reviewed-on: https://chromium-review.googlesource.com/953712
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541866}
parent 9fb999ee
...@@ -314,6 +314,25 @@ class PDFExtensionTest : public ExtensionApiTest, ...@@ -314,6 +314,25 @@ class PDFExtensionTest : public ExtensionApiTest,
WebContents* GetActiveWebContents() { WebContents* GetActiveWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents(); return browser()->tab_strip_model()->GetActiveWebContents();
} }
int CountPDFProcesses() {
int result = -1;
base::RunLoop run_loop;
content::BrowserThread::PostTaskAndReply(
content::BrowserThread::IO, FROM_HERE,
base::BindOnce(&PDFExtensionTest::CountPDFProcessesOnIOThread,
base::Unretained(this), base::Unretained(&result)),
run_loop.QuitClosure());
run_loop.Run();
return result;
}
void CountPDFProcessesOnIOThread(int* result) {
auto* service = content::PluginService::GetInstance();
*result = service->CountPpapiPluginProcessesForProfile(
base::FilePath::FromUTF8Unsafe(ChromeContentClient::kPDFPluginPath),
browser()->profile()->GetPath());
}
}; };
IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) { IN_PROC_BROWSER_TEST_P(PDFExtensionTest, Load) {
...@@ -372,6 +391,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) { ...@@ -372,6 +391,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, DisablePlugin) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_EQ(url, helper.GetLastUrl()); ASSERT_EQ(url, helper.GetLastUrl());
// Didn't launch a PPAPI process.
EXPECT_EQ(0, CountPDFProcesses());
// Cancel the download to shutdown cleanly. // Cancel the download to shutdown cleanly.
download_manager->RemoveObserver(&helper); download_manager->RemoveObserver(&helper);
std::vector<download::DownloadItem*> downloads; std::vector<download::DownloadItem*> downloads;
...@@ -387,6 +409,9 @@ INSTANTIATE_TEST_CASE_P(PDFTestFiles, ...@@ -387,6 +409,9 @@ INSTANTIATE_TEST_CASE_P(PDFTestFiles,
IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) {
RunTestsInFile("basic_test.js", "test.pdf"); RunTestsInFile("basic_test.js", "test.pdf");
// Ensure it loaded in a PPAPI process.
EXPECT_EQ(1, CountPDFProcesses());
} }
IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) {
...@@ -504,6 +529,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BlockDirectAccess) { ...@@ -504,6 +529,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BlockDirectAccess) {
ui_test_utils::NavigateToURL(browser(), forbiddenUrl); ui_test_utils::NavigateToURL(browser(), forbiddenUrl);
console_delegate->Wait(); console_delegate->Wait();
// Didn't launch a PPAPI process.
EXPECT_EQ(0, CountPDFProcesses());
} }
// This test ensures that PDF can be loaded from local file // This test ensures that PDF can be loaded from local file
...@@ -520,6 +548,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsurePDFFromLocalFileLoads) { ...@@ -520,6 +548,9 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsurePDFFromLocalFileLoads) {
} }
WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url); WebContents* guest_contents = LoadPdfGetGuestContents(test_pdf_url);
ASSERT_TRUE(guest_contents); ASSERT_TRUE(guest_contents);
// Did launch a PPAPI process.
EXPECT_EQ(1, CountPDFProcesses());
} }
// This test ensures that link permissions are enforced properly in PDFs. // This test ensures that link permissions are enforced properly in PDFs.
......
...@@ -88,6 +88,9 @@ class CONTENT_EXPORT PluginServiceImpl : public PluginService { ...@@ -88,6 +88,9 @@ class CONTENT_EXPORT PluginServiceImpl : public PluginService {
void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override; void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override;
bool PpapiDevChannelSupported(BrowserContext* browser_context, bool PpapiDevChannelSupported(BrowserContext* browser_context,
const GURL& document_url) override; const GURL& document_url) override;
int CountPpapiPluginProcessesForProfile(
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory) override;
// Returns the plugin process host corresponding to the plugin process that // Returns the plugin process host corresponding to the plugin process that
// has been started by this service. This will start a process to host the // has been started by this service. This will start a process to host the
...@@ -150,10 +153,6 @@ class CONTENT_EXPORT PluginServiceImpl : public PluginService { ...@@ -150,10 +153,6 @@ class CONTENT_EXPORT PluginServiceImpl : public PluginService {
PpapiPluginProcessHost* FindPpapiBrokerProcess( PpapiPluginProcessHost* FindPpapiBrokerProcess(
const base::FilePath& broker_path); const base::FilePath& broker_path);
int CountPpapiPluginProcessesForProfile(
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory);
void RegisterPepperPlugins(); void RegisterPepperPlugins();
// Loads the plugins synchronously in a thread pool. // Loads the plugins synchronously in a thread pool.
......
...@@ -35,22 +35,21 @@ struct WebPluginInfo; ...@@ -35,22 +35,21 @@ struct WebPluginInfo;
// thread. This is an asynchronous wrapper around the PluginList interface for // thread. This is an asynchronous wrapper around the PluginList interface for
// querying plugin information. This must be used instead of that to avoid // querying plugin information. This must be used instead of that to avoid
// doing expensive disk operations on the IO/UI threads. // doing expensive disk operations on the IO/UI threads.
class PluginService { class CONTENT_EXPORT PluginService {
public: public:
using GetPluginsCallback = using GetPluginsCallback =
base::OnceCallback<void(const std::vector<WebPluginInfo>&)>; base::OnceCallback<void(const std::vector<WebPluginInfo>&)>;
// Returns the PluginService singleton. // Returns the PluginService singleton.
CONTENT_EXPORT static PluginService* GetInstance(); static PluginService* GetInstance();
// Tells all the renderer processes associated with the given browser context // Tells all the renderer processes associated with the given browser context
// to throw away their cache of the plugin list, and optionally also reload // to throw away their cache of the plugin list, and optionally also reload
// all the pages with plugins. If |browser_context| is nullptr, purges the // all the pages with plugins. If |browser_context| is nullptr, purges the
// cache in all renderers. // cache in all renderers.
// NOTE: can only be called on the UI thread. // NOTE: can only be called on the UI thread.
CONTENT_EXPORT static void PurgePluginListCache( static void PurgePluginListCache(BrowserContext* browser_context,
BrowserContext* browser_context, bool reload_pages);
bool reload_pages);
virtual ~PluginService() {} virtual ~PluginService() {}
...@@ -132,6 +131,12 @@ class PluginService { ...@@ -132,6 +131,12 @@ class PluginService {
// Returns true iff PPAPI "dev channel" methods are supported. // Returns true iff PPAPI "dev channel" methods are supported.
virtual bool PpapiDevChannelSupported(BrowserContext* browser_context, virtual bool PpapiDevChannelSupported(BrowserContext* browser_context,
const GURL& document_url) = 0; const GURL& document_url) = 0;
// Determine the number of PPAPI processes currently tracked by the service.
// Exposed primarily for testing purposes.
virtual int CountPpapiPluginProcessesForProfile(
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory) = 0;
}; };
} // namespace content } // namespace content
......
...@@ -88,4 +88,10 @@ bool FakePluginService::PpapiDevChannelSupported( ...@@ -88,4 +88,10 @@ bool FakePluginService::PpapiDevChannelSupported(
return false; return false;
} }
int FakePluginService::CountPpapiPluginProcessesForProfile(
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory) {
return 0;
}
} // namespace content } // namespace content
...@@ -53,6 +53,9 @@ class FakePluginService : public PluginService { ...@@ -53,6 +53,9 @@ class FakePluginService : public PluginService {
void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override; void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override;
bool PpapiDevChannelSupported(BrowserContext* browser_context, bool PpapiDevChannelSupported(BrowserContext* browser_context,
const GURL& document_url) override; const GURL& document_url) override;
int CountPpapiPluginProcessesForProfile(
const base::FilePath& plugin_path,
const base::FilePath& profile_data_directory) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(FakePluginService); DISALLOW_COPY_AND_ASSIGN(FakePluginService);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment