Index: content/browser/plugin_service_impl_browsertest.cc |
=================================================================== |
--- content/browser/plugin_service_impl_browsertest.cc (revision 180039) |
+++ content/browser/plugin_service_impl_browsertest.cc (working copy) |
@@ -9,6 +9,7 @@ |
#include "base/command_line.h" |
#include "base/path_service.h" |
#include "content/public/browser/browser_context.h" |
+#include "content/public/browser/plugin_service_filter.h" |
#include "content/public/browser/resource_context.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/content_switches.h" |
@@ -36,10 +37,11 @@ |
class MockPluginProcessHostClient : public PluginProcessHost::Client, |
public IPC::Listener { |
public: |
- MockPluginProcessHostClient(ResourceContext* context) |
+ MockPluginProcessHostClient(ResourceContext* context, bool expect_fail) |
: context_(context), |
channel_(NULL), |
- set_plugin_info_called_(false) { |
+ set_plugin_info_called_(false), |
+ expect_fail_(expect_fail) { |
} |
virtual ~MockPluginProcessHostClient() { |
@@ -80,6 +82,8 @@ |
return false; |
} |
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE { |
+ if (expect_fail_) |
+ FAIL(); |
QuitMessageLoop(); |
} |
virtual void OnChannelError() OVERRIDE { |
@@ -96,7 +100,8 @@ |
private: |
void Fail() { |
- FAIL(); |
+ if (!expect_fail_) |
+ FAIL(); |
QuitMessageLoop(); |
} |
@@ -108,9 +113,27 @@ |
ResourceContext* context_; |
IPC::Channel* channel_; |
bool set_plugin_info_called_; |
+ bool expect_fail_; |
DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient); |
}; |
+class MockPluginServiceFilter : public content::PluginServiceFilter { |
+ public: |
+ MockPluginServiceFilter() {} |
+ |
+ virtual bool IsPluginEnabled( |
+ int render_process_id, |
+ int render_view_id, |
+ const void* context, |
+ const GURL& url, |
+ const GURL& policy_url, |
+ webkit::WebPluginInfo* plugin) OVERRIDE { return true; } |
+ |
+ virtual bool CanLoadPlugin( |
+ int render_process_id, |
+ const FilePath& path) OVERRIDE { return false; } |
+}; |
+ |
class PluginServiceTest : public ContentBrowserTest { |
public: |
PluginServiceTest() {} |
@@ -140,13 +163,25 @@ |
IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) { |
if (!webkit::npapi::NPAPIPluginsSupported()) |
return; |
- MockPluginProcessHostClient mock_client(GetResourceContext()); |
+ MockPluginProcessHostClient mock_client(GetResourceContext(), false); |
BrowserThread::PostTask( |
BrowserThread::IO, FROM_HERE, |
base::Bind(&OpenChannel, &mock_client)); |
RunMessageLoop(); |
} |
+IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToDeniedPlugin) { |
+ if (!webkit::npapi::NPAPIPluginsSupported()) |
+ return; |
+ MockPluginServiceFilter filter; |
+ PluginServiceImpl::GetInstance()->SetFilter(&filter); |
+ MockPluginProcessHostClient mock_client(GetResourceContext(), true); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&OpenChannel, &mock_client)); |
+ RunMessageLoop(); |
+} |
+ |
// A strict mock that fails if any of the methods are called. They shouldn't be |
// called since the request should get canceled before then. |
class MockCanceledPluginServiceClient : public PluginProcessHost::Client { |