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

Side by Side Diff: content/browser/plugin_service_browsertest.cc

Issue 7477044: Use PluginPrefs in ChromePluginServiceFilter to check whether a plugin is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/plugin_service.cc ('k') | content/browser/plugin_service_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/plugin_service.h" 5 #include "content/browser/plugin_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/browser/browser_thread.h" 11 #include "content/browser/browser_thread.h"
12 #include "content/browser/resource_context.h"
12 #include "content/common/content_switches.h" 13 #include "content/common/content_switches.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "webkit/plugins/npapi/plugin_list.h" 15 #include "webkit/plugins/npapi/plugin_list.h"
15 16
16 namespace { 17 namespace {
17 18
18 const char* kNPAPITestPluginMimeType = "application/vnd.npapi-test"; 19 const char* kNPAPITestPluginMimeType = "application/vnd.npapi-test";
19 20
21 class MockResourceContext : public content::ResourceContext {
22 public:
23 MockResourceContext() {}
24 virtual ~MockResourceContext() {}
25
26 private:
27 virtual void EnsureInitialized() const OVERRIDE {}
28 };
29
20 // Mock up of the Client and the Listener classes that would supply the 30 // Mock up of the Client and the Listener classes that would supply the
21 // communication channel with the plugin. 31 // communication channel with the plugin.
22 class MockPluginProcessHostClient : public PluginProcessHost::Client, 32 class MockPluginProcessHostClient : public PluginProcessHost::Client,
23 public IPC::Channel::Listener { 33 public IPC::Channel::Listener {
24 public: 34 public:
25 MockPluginProcessHostClient() 35 MockPluginProcessHostClient()
26 : channel_(NULL), 36 : channel_(NULL),
27 set_plugin_info_called_(false) { 37 set_plugin_info_called_(false) {
28 } 38 }
29 39
30 virtual ~MockPluginProcessHostClient() { 40 virtual ~MockPluginProcessHostClient() {
31 if (channel_) 41 if (channel_)
32 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_); 42 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, channel_);
33 } 43 }
34 44
35 // Client implementation. 45 // Client implementation.
36 int ID() { return 42; } 46 virtual int ID() OVERRIDE { return 42; }
37 bool OffTheRecord() { return false; } 47 virtual bool OffTheRecord() OVERRIDE { return false; }
48 virtual const content::ResourceContext& GetResourceContext() OVERRIDE {
49 return context_;
50 }
38 51
39 void OnChannelOpened(const IPC::ChannelHandle& handle) { 52 void OnChannelOpened(const IPC::ChannelHandle& handle) {
40 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 53 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
41 ASSERT_TRUE(set_plugin_info_called_); 54 ASSERT_TRUE(set_plugin_info_called_);
42 ASSERT_TRUE(!channel_); 55 ASSERT_TRUE(!channel_);
43 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this); 56 channel_ = new IPC::Channel(handle, IPC::Channel::MODE_CLIENT, this);
44 ASSERT_TRUE(channel_->Connect()); 57 ASSERT_TRUE(channel_->Connect());
45 } 58 }
46 59
47 void SetPluginInfo(const webkit::npapi::WebPluginInfo& info) { 60 void SetPluginInfo(const webkit::npapi::WebPluginInfo& info) {
48 ASSERT_TRUE(info.mime_types.size()); 61 ASSERT_TRUE(info.mime_types.size());
49 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type); 62 ASSERT_EQ(kNPAPITestPluginMimeType, info.mime_types[0].mime_type);
50 set_plugin_info_called_ = true; 63 set_plugin_info_called_ = true;
51 } 64 }
52 65
53 MOCK_METHOD0(OnError, void()); 66 MOCK_METHOD0(OnError, void());
54 67
55 // Listener implementation. 68 // Listener implementation.
56 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message)); 69 MOCK_METHOD1(OnMessageReceived, bool(const IPC::Message& message));
57 void OnChannelConnected(int32 peer_pid) { 70 void OnChannelConnected(int32 peer_pid) {
58 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 71 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
59 new MessageLoop::QuitTask()); 72 new MessageLoop::QuitTask());
60 } 73 }
61 MOCK_METHOD0(OnChannelError, void()); 74 MOCK_METHOD0(OnChannelError, void());
62 MOCK_METHOD0(OnChannelDenied, void()); 75 MOCK_METHOD0(OnChannelDenied, void());
63 MOCK_METHOD0(OnChannelListenError, void()); 76 MOCK_METHOD0(OnChannelListenError, void());
64 77
65 private: 78 private:
79 MockResourceContext context_;
66 IPC::Channel* channel_; 80 IPC::Channel* channel_;
67 bool set_plugin_info_called_; 81 bool set_plugin_info_called_;
68 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient); 82 DISALLOW_COPY_AND_ASSIGN(MockPluginProcessHostClient);
69 }; 83 };
70 84
71 } // namespace 85 } // namespace
72 86
73 class PluginServiceTest : public InProcessBrowserTest { 87 class PluginServiceTest : public InProcessBrowserTest {
74 public: 88 public:
75 PluginServiceTest() : InProcessBrowserTest() { } 89 PluginServiceTest() : InProcessBrowserTest() { }
76 90
77 virtual void SetUpCommandLine(CommandLine* command_line) { 91 virtual void SetUpCommandLine(CommandLine* command_line) {
78 #ifdef OS_MACOSX 92 #ifdef OS_MACOSX
79 FilePath browser_directory; 93 FilePath browser_directory;
80 PathService::Get(base::DIR_MODULE, &browser_directory); 94 PathService::Get(base::DIR_MODULE, &browser_directory);
81 command_line->AppendSwitchPath(switches::kExtraPluginDir, 95 command_line->AppendSwitchPath(switches::kExtraPluginDir,
82 browser_directory.AppendASCII("plugins")); 96 browser_directory.AppendASCII("plugins"));
83 #endif 97 #endif
84 } 98 }
99
100 static void OpenChannelOnIOThread(PluginProcessHost::Client* client) {
101 PluginService::GetInstance()->OpenChannelToNpapiPlugin(
102 0, 0, GURL(), GURL(), kNPAPITestPluginMimeType, client);
103 }
85 }; 104 };
86 105
87 // Try to open a channel to the test plugin. Minimal plugin process spawning 106 // Try to open a channel to the test plugin. Minimal plugin process spawning
88 // test for the PluginService interface. 107 // test for the PluginService interface.
89 IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) { 108 IN_PROC_BROWSER_TEST_F(PluginServiceTest, OpenChannelToPlugin) {
90 MockPluginProcessHostClient mock_client; 109 ::testing::StrictMock<MockPluginProcessHostClient> mock_client;
91 PluginService::GetInstance()->OpenChannelToNpapiPlugin( 110 BrowserThread::PostTask(
92 0, 0, GURL(), kNPAPITestPluginMimeType, &mock_client); 111 BrowserThread::IO, FROM_HERE,
112 NewRunnableFunction(&PluginServiceTest::OpenChannelOnIOThread,
113 &mock_client));
93 ui_test_utils::RunMessageLoop(); 114 ui_test_utils::RunMessageLoop();
94 } 115 }
OLDNEW
« no previous file with comments | « content/browser/plugin_service.cc ('k') | content/browser/plugin_service_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698